texture mapping in ps2 test

This commit is contained in:
aap 2015-06-18 23:05:37 +02:00
parent df419c63ef
commit c6589f55de
17 changed files with 170 additions and 100 deletions

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>
#include "rw.h"
@ -34,8 +33,6 @@ main(int argc, char *argv[])
rw::Clump *c;
// ifstream in(argv[1], ios::binary);
// rw::StreamFile in;
// in.open(argv[1], "rb");

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>
@ -347,7 +346,7 @@ static int32
getSizeEnvMat(void *object, int32 offset, int32)
{
EnvMat *env = *PLUGINOFFSET(EnvMat*, object, offset);
return env ? sizeof(EnvStream) : -1;
return env ? (int)sizeof(EnvStream) : -1;
}
// Specular mat
@ -417,7 +416,7 @@ static int32
getSizeSpecMat(void *object, int32 offset, int32)
{
SpecMat *spec = *PLUGINOFFSET(SpecMat*, object, offset);
return spec ? sizeof(SpecStream) : -1;
return spec ? (int)sizeof(SpecStream) : -1;
}
void

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>
@ -10,12 +9,6 @@
#include "rwplugin.h"
#include "rwobjects.h"
#ifdef __linux__
#define PACKED_STRUCT __attribute__((__packed__))
#else
#define PACKED_STRUCT
#endif
using namespace std;
namespace rw {
@ -291,6 +284,9 @@ Image::getFilename(const char *name)
#ifndef RW_PS2
#pragma pack(push)
#pragma pack(1)
#define PACKED_STRUCT
#else
#define PACKED_STRUCT __attribute__((__packed__))
#endif
struct PACKED_STRUCT TGAHeader
{
@ -319,9 +315,12 @@ readTGA(const char *afilename)
filename = Image::getFilename(afilename);
if(filename == NULL)
return NULL;
StreamFile file;
assert(file.open(filename, "rb") != NULL);
uint32 length;
uint8 *data = getFileContents(filename, &length);
assert(data != NULL);
free(filename);
StreamMemory file;
file.open(data, length);
file.read(&header, sizeof(header));
assert(header.imageType == 1 || header.imageType == 2);
@ -380,6 +379,7 @@ readTGA(const char *afilename)
}
file.close();
delete[] data;
return image;
}

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>
#include <new>
@ -311,4 +310,18 @@ found:
return i;
}
uint8*
getFileContents(char *name, uint32 *len)
{
FILE *cf = fopen(name, "rb");
assert(cf != NULL);
fseek(cf, 0, SEEK_END);
*len = ftell(cf);
fseek(cf, 0, SEEK_SET);
uint8 *data = new uint8[*len];
fread(data, *len, 1, cf);
fclose(cf);
return data;
}
}

View File

@ -1,15 +1,31 @@
#ifndef RW_PS2
#include <stdint.h>
#endif
namespace rw {
/* get rid of the stupid _t */
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef uintptr_t uintptr;
#ifdef RW_PS2
typedef char int8;
typedef short int16;
typedef int int32;
typedef long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
typedef unsigned int uintptr;
#else
/* get rid of the stupid _t */
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef uintptr_t uintptr;
#endif
typedef float float32;
typedef int32 bool32;
@ -165,4 +181,5 @@ bool readChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header);
bool findChunk(Stream *s, uint32 type, uint32 *length, uint32 *version);
int32 findPointer(void *p, void **list, int32 num);
uint8 *getFileContents(char *name, uint32 *len);
}

View File

@ -9,7 +9,7 @@ LIBPATH=-L$(PS2SDK)/ee/lib
INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I../..
LIBS=../../librw-ps2.a -lc -lc -lkernel -lmf # g++ throws one -lc away, why? (unless -nostdlib)
CFLAGS = -c -Wall -nostdlib -fno-common -DPS2_EE $(INCPATH)
CFLAGS = -c -Wall -nostdlib -fno-common -DRW_PS2 -DPS2_EE $(INCPATH)
ASFLAGS = -c -xassembler-with-cpp
LDFLAGS = -mno-crt0 $(LIBPATH)
OUT=test
@ -19,7 +19,7 @@ C_SRC=main.cpp gs.cpp dma.cpp math.cpp
HEADER=dma.h ee_regs.h gif.h gs.h mips_regs.h ps2.h math.h mesh.h
OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o
$(OUT).elf: $(OBJ) $(HEADER)
$(OUT).elf: $(OBJ) ../../librw-ps2.a $(HEADER)
$(LD) $(LDFLAGS) $(LINK) $(PS2SDK)/ee/startup/crt0.o \
$(OBJ) $(LIBS) -o $(OUT).elf

View File

@ -47,35 +47,36 @@ Cnt:
Loop:
NOP LQI VF01, (VI02++) ; vertex
NOP LQI VF02, (VI02++) ; UV - ignore
NOP LQI VF02, (VI02++) ; color
NOP LQI VF03, (VI02++) ; normal
NOP LQI VF02, (VI02++) ; UV
NOP LQI VF03, (VI02++) ; color
NOP LQI VF04, (VI02++) ; normal
MULAw.xyzw ACC, VF31, VF00w NOP ; transform vertex
MADDAx.xyzw ACC, VF28, VF01x NOP
MADDAy.xyzw ACC, VF29, VF01y NOP
MADDz.xyzw VF01, VF30, VF01z NOP
ITOF0 VF02, VF02 NOP
ITOF0[I] VF03, VF03 LOI 0.0078125 ; - normal scale
ITOF0 VF03, VF03 NOP
ITOF0[I] VF04, VF04 LOI 0.0078125 ; - normal scale
NOP NOP
NOP DIV Q, VF00w, VF01w
NOP WAITQ
MULq VF01, VF01, Q NOP ; perspective division
MULi VF03, VF03, I NOP ; scale normal
NOP NOP
MULi VF04, VF04, I NOP ; scale normal
NOP MR32.z VF02, VF00
NOP NOP
SUB.w VF01, VF01, VF01 NOP
MULAx.xyz ACC, VF18, VF03x NOP ; transform normal
MADDAy.xyz ACC, VF19, VF03y NOP
MADDz.xyz VF03, VF20, VF03z NOP
MULAx.xyz ACC, VF18, VF04x NOP ; transform normal
MADDAy.xyz ACC, VF19, VF04y NOP
MADDz.xyz VF04, VF20, VF04z NOP
ADD.xy VF01, VF01, VF25 NOP
MULq VF02, VF02, Q NOP
NOP NOP
NOP NOP
FTOI0 VF02, VF02 NOP
FTOI0 VF03, VF03 NOP
FTOI4 VF01, VF01 NOP
NOP SQ VF03, -1(VI02) ; store normal
NOP SQ VF04, -1(VI02) ; store normal
NOP IADDI VI01, VI01, -1
NOP SQI VF02, (VI03++) ; color
NOP SQI VF02, (VI03++) ; STQ
NOP SQI VF03, (VI03++) ; color
NOP SQI VF01, (VI03++) ; vertex
NOP IBNE VI01, VI00, Loop
NOP NOP

View File

@ -200,7 +200,7 @@ void drawrect(uint16 x1, uint16 y1, uint16 x2, uint16 y2, uint32 col);
BIT64(CPSM, 51) | \
BIT64(CSM, 55) | \
BIT64(CSA, 56) | \
BIT64(CSD, 61))
BIT64(CLD, 61))
#define MAKE_GS_CLAMP(WMS,WMT,MINU,MAXU,MINV,MAXV) \
(BIT64(WMS, 0) | \

View File

@ -1,7 +1,7 @@
; Ambient light:
NOP LQ VF26, ambientLight(VI00)
NOP XITOP VI01
NOP IADDIU VI03, VI12, 1
NOP IADDIU VI03, VI12, 2
Ambloop:
NOP LQ VF03, 0(VI03) ; output color
NOP NOP
@ -17,16 +17,16 @@ Ambloop:
NOP NOP
FTOI0 VF03, VF03 NOP
NOP IADDI VI01, VI01, -1
NOP IADDIU VI03, VI03, 2 ; numOutAttribs
NOP IADDIU VI03, VI03, numOutAttribs
NOP IBNE VI01, VI00, Ambloop
NOP SQ VF03, -2(VI03) ; numOutAttribs
NOP SQ VF03, -numOutAttribs(VI03)
; end amblight
; Direct Light
NOP LQ VF26, lightDir(VI00)
NOP XITOP VI01
NOP XTOP VI02
NOP IADDIU VI03, VI12, 1
NOP IADDIU VI03, VI12, 2
SUB.xyz VF26, VF00, VF26 NOP
Dirloop:
NOP LQ VF01, 3(VI02); ; normal
@ -60,15 +60,15 @@ Dirloop:
FTOI0 VF02, VF02 NOP
NOP IADDI VI01, VI01, -1
NOP IADDIU VI02, VI02, numInAttribs
NOP IADDIU VI03, VI03, 2 ; numOutAttribs
NOP IADDIU VI03, VI03, numOutAttribs
NOP IBNE VI01, VI00, Dirloop
NOP SQ VF02, -2(VI03) ; numOutAttribs
NOP SQ VF02, -numOutAttribs(VI03)
; end dirlight
; Material color and clamp
NOP LQ VF27, matColor(VI00)
NOP XITOP VI01
NOP IADDIU VI03, VI12, 1
NOP IADDIU VI03, VI12, 2
Colorloop:
NOP LQ VF03, 0(VI03)
NOP NOP
@ -88,7 +88,7 @@ Colorloop:
NOP NOP
FTOI0 VF03, VF03 NOP
NOP IADDI VI01, VI01, -1
NOP IADDIU VI03, VI03, 2 ; numOutAttribs
NOP IADDIU VI03, VI03, numOutAttribs
NOP IBNE VI01, VI00, Colorloop
NOP SQ VF03, -2(VI03) ; numOutAttribs
NOP SQ VF03, -numOutAttribs(VI03)
; end material color

View File

@ -48,19 +48,23 @@ drawAtomic(rw::Atomic *atomic)
matCopy(vuLightMat, atomic->frame->ltm);
matMult(vuMat, atomic->frame->ltm);
rw::Skin *skin = *PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
for(int i = 0; i < instData->numMeshes; i++){
for(uint i = 0; i < instData->numMeshes; i++){
if(instData->instanceMeshes[i].arePointersFixed == 0)
rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
geometryCall[1] = (uint32)instData->instanceMeshes[i].data;
mesh = &meshHeader->mesh[i];
color = mesh->material->color;
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC,0,2);
vuGIFtag[1] = 0x41;
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC|0x10,0,3);
vuGIFtag[1] = 0x412;
vuMatcolor[0] = color[0]/255.0f;
vuMatcolor[1] = color[1]/255.0f;
vuMatcolor[2] = color[2]/255.0f;
vuMatcolor[3] = color[3]/2.0f/255.0f;
// only when modulating textures actually
vuMatcolor[0] /= 2.0f;
vuMatcolor[1] /= 2.0f;
vuMatcolor[2] /= 2.0f;
if(rw::skinGlobals.offset && skin){
geometryCall[3] = 0x020000DC;
mpgCall[1] = (uint32)skinPipe;
@ -112,6 +116,60 @@ draw(void)
rot -= 2*M_PI;
}
GIF_DECLARE_PACKET(gifDmaBuf2, 256)
uint32
uploadTGA(rw::Image *tga)
{
GsState *g = gsCurState;
uint32 destAddr = g->currentMemPtr;
uint32 size = tga->width*tga->height*4;
g->currentMemPtr += size;
printf("image @ %x\n", destAddr);
GIF_BEGIN_PACKET(gifDmaBuf2);
GIF_TAG(gifDmaBuf2, 4, 1, 0, 0, 0, 1, 0x0e);
GIF_DATA_AD(gifDmaBuf2, GS_BITBLTBUF,
MAKE_GS_BITBLTBUF(0, 0, 0,
destAddr/4/64, tga->width/64, PSMCT32));
GIF_DATA_AD(gifDmaBuf2, GS_TRXPOS,
MAKE_GS_TRXPOS(0, 0, 0, 0, 0));
GIF_DATA_AD(gifDmaBuf2, GS_TRXREG,
MAKE_GS_TRXREG(tga->width, tga->height));
GIF_DATA_AD(gifDmaBuf2, GS_TRXDIR, 0);
GIF_SEND_PACKET(gifDmaBuf2);
GIF_BEGIN_PACKET(gifDmaBuf2);
GIF_TAG(gifDmaBuf2, size/0x10, 1, 0, 0, 2, 0, 0);
GIF_SEND_PACKET(gifDmaBuf2);
FlushCache(0);
SET_REG32(D2_QWC, MAKE_DN_QWC(size/0x10));
SET_REG32(D2_MADR, MAKE_DN_MADR(tga->pixels, 0));
SET_REG32(D2_CHCR, MAKE_DN_CHCR(1, 0, 0, 0, 0, 1));
DMA_WAIT(D2_CHCR);
int logw = 0, logh = 0;
int s;
for(s = 1; s < tga->width; s *= 2)
logw++;
for(s = 1; s < tga->height; s *= 2)
logh++;
GIF_BEGIN_PACKET(gifDmaBuf2);
GIF_TAG(gifDmaBuf2, 3, 1, 0, 0, 0, 1, 0x0e);
GIF_DATA_AD(gifDmaBuf2, GS_TEXFLUSH, 1);
GIF_DATA_AD(gifDmaBuf2, GS_TEX0_1,
MAKE_GS_TEX0(destAddr/4/64, tga->width/64, PSMCT32,
logw, logh, 0, 0, 0, 0, 0, 0, 0));
GIF_DATA_AD(gifDmaBuf2, GS_TEX1_1,
MAKE_GS_TEX1(0, 0, 1, 1, 0, 0, 0));
GIF_SEND_PACKET(gifDmaBuf2);
return destAddr;
}
int
main()
{
@ -141,29 +199,15 @@ main()
// rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin();
// rw::StreamFile in;
// in.open("host:player-vc-ps2.dff", "rb");
FILE *cf = fopen("host:player-vc-ps2.dff", "rb");
// FILE *cf = fopen("host:od_newscafe_dy-ps2.dff", "rb");
// FILE *cf = fopen("host:admiral-ps2.dff", "rb");
assert(cf != NULL);
fseek(cf, 0, SEEK_END);
rw::uint32 len = ftell(cf);
fseek(cf, 0, SEEK_SET);
rw::uint8 *data = new rw::uint8[len];
fread(data, len, 1, cf);
fclose(cf);
rw::uint32 len;
rw::uint8 *data = rw::getFileContents("host:player-vc-ps2.dff", &len);
// rw::uint8 *data = rw::getFileContents("host:od_newscafe_dy-ps2.dff", &len);
// rw::uint8 *data = rw::getFileContents("host:admiral-ps2.dff", &len);
rw::StreamMemory in;
in.open(data, len);
printf("opened file\n");
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
printf("found chunk\n");
clump = rw::Clump::streamRead(&in);
printf("read file\n");
in.close();
printf("closed file\n");
delete[] data;
data = new rw::uint8[256*1024];
@ -177,12 +221,15 @@ main()
out.close();
delete[] data;
// rw::StreamFile out;
// out.open("host:out-ps2.dff", "wb");
// c->streamWrite(&out);
// out.close();
//
// printf("wrote file\n");
rw::Image *tga = rw::readTGA("host:player_.tga");
printf("read tga\n");
uint32 destAddr = uploadTGA(tga);
/*
rw::writeTGA(tga, "host:out.tga");
printf("wrote tga\n");
*/
vuOffset[0] = 2048.0f;
vuOffset[1] = 2048.0f;

View File

@ -47,36 +47,37 @@ Cnt:
Loop:
NOP LQI VF01, (VI02++) ; vertex
NOP LQI VF02, (VI02++) ; UV - skip
NOP LQI VF02, (VI02++) ; color
NOP LQI VF03, (VI02++) ; normal
NOP LQI VF02, (VI02++) ; UV
NOP LQI VF03, (VI02++) ; color
NOP LQI VF04, (VI02++) ; normal
NOP IADDIU VI02, VI02, 1 ; skip weights
MULAw.xyzw ACC, VF31, VF00w NOP
MULAw.xyzw ACC, VF31, VF00w NOP ; transform vertex
MADDAx.xyzw ACC, VF28, VF01x NOP
MADDAy.xyzw ACC, VF29, VF01y NOP
MADDz.xyzw VF01, VF30, VF01z NOP
ITOF0 VF02, VF02 NOP
ITOF0[I] VF03, VF03 LOI 0.0078125 ; - normal scale
ITOF0 VF03, VF03 NOP
ITOF0[I] VF04, VF04 LOI 0.0078125 ; - normal scale
NOP NOP
NOP DIV Q, VF00w, VF01w
NOP WAITQ
MULq VF01, VF01, Q NOP ; perspective division
MULi VF03, VF03, I NOP ; scale normal
NOP NOP
MULi VF04, VF04, I NOP ; scale normal
NOP MR32.z VF02, VF00
NOP NOP
SUB.w VF01, VF01, VF01 NOP
MULAx.xyz ACC, VF18, VF03x NOP ; transform normal
MADDAy.xyz ACC, VF19, VF03y NOP
MADDz.xyz VF03, VF20, VF03z NOP
MULAx.xyz ACC, VF18, VF04x NOP ; transform normal
MADDAy.xyz ACC, VF19, VF04y NOP
MADDz.xyz VF04, VF20, VF04z NOP
ADD.xy VF01, VF01, VF25 NOP
MULq VF02, VF02, Q NOP
NOP NOP
NOP NOP
FTOI0 VF02, VF02 NOP
FTOI0 VF03, VF03 NOP
FTOI4 VF01, VF01 NOP
NOP SQ VF03, -2(VI02) ; store normal
NOP SQ VF04, -2(VI02) ; store normal
NOP IADDI VI01, VI01, -1
NOP SQI VF02, (VI03++) ; color
NOP SQI VF02, (VI03++) ; STQ
NOP SQI VF03, (VI03++) ; color
NOP SQI VF01, (VI03++) ; vertex
NOP IBNE VI01, VI00, Loop
NOP NOP

View File

@ -42,7 +42,7 @@ vuMat:
vuOffset:
.float 0.0, 0.0, 0.0, 0.0
vuGIFtag:
.int 0x00008000, 0x2005C000, 0x0000000041, 0x00000000
.int 0x00008000, 0x3005C000, 0x0000000412, 0x00000000
vuMatcolor:
.float 1.0, 1.0, 1.0, 0.5
vuSurfProps: