diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 11:14:51 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 11:14:51 +0100 |
| commit | 08ca71f289cd63090edea06ce9fe1803c20d799b (patch) | |
| tree | bc440579395021a652f608475db14996f1470071 /libpsx/src | |
| parent | f3df02b0d0a5d3a80c1bdefca78e9bd325f9f4d4 (diff) | |
| download | psxsdk-08ca71f289cd63090edea06ce9fe1803c20d799b.tar.gz | |
Solved const-correctness issues
Diffstat (limited to 'libpsx/src')
| -rw-r--r-- | libpsx/src/gpu.c | 426 | ||||
| -rw-r--r-- | libpsx/src/spu.c | 72 |
2 files changed, 249 insertions, 249 deletions
diff --git a/libpsx/src/gpu.c b/libpsx/src/gpu.c index 7e097c6..66251df 100644 --- a/libpsx/src/gpu.c +++ b/libpsx/src/gpu.c @@ -79,10 +79,10 @@ int gs_calculate_scaled_size(int size, int scale) return size * scale; else if(scale > -8) return size / (scale * -1); - + return (size * SCALE_ONE) / -scale; -} - +} + void GsSetList(unsigned int *listptr) { linked_list = listptr; @@ -97,7 +97,7 @@ void GsDrawList() GsDrawListPIO(); return; } - + //int x = 0; /* Put a terminator, so the link listed ends. */ @@ -110,14 +110,14 @@ void GsDrawList() while(!(GPU_CONTROL_PORT & (1<<0x1a))); /* Wait for the GPU to finish * drawing primitives. */ while(!(GPU_CONTROL_PORT & (1<<0x1c))); /* Wait for the GPU to be free */ - + gpu_ctrl(4, 2); // DMA CPU->GPU mode D2_MADR = (unsigned int)linked_list; D2_BCR = 0; D2_CHCR = (1<<0xa)|1|(1<<0x18); - + linked_list_pos = 0; - + //if(PSX_GetInitFlags() & PSX_INIT_NOBIOS) // __psxsdk_gpu_dma_finished = 0; @@ -131,24 +131,24 @@ void GsDrawListPIO() int pos = 0; int sz = 0; int x; - + while(!(GPU_CONTROL_PORT & (1<<0x1c))); // Disable DMA GPU_CONTROL_PORT = 0x04000000; - - + + while(pos < linked_list_pos) { while(!(GPU_CONTROL_PORT & (1<<0x1c))); GPU_DATA_PORT = 0x01000000; // Reset data port - + sz = linked_list[pos++] >> 24; - + for(x = 0; x < sz; x++) GPU_DATA_PORT = linked_list[pos++]; } - + linked_list_pos = 0; // GPU_DATA_PORT = 0xE6000000; // Disable masking stuff // gpu_data_ctrl(2, ((b&0xff)<<16)|((g&0xff)<<8)|r); @@ -157,42 +157,42 @@ void GsDrawListPIO() if(__gs_autowait) while(GsIsDrawing()); } - + void GsSortPoly3(GsPoly3 *poly3) { int orig_pos = linked_list_pos; int x; unsigned char pkt = 0x20; unsigned int md; - + md = setup_attribs(0, poly3->attribute, &pkt); - + linked_list[linked_list_pos++] = 0x05000000; linked_list[linked_list_pos++] = md; linked_list[linked_list_pos++] = (pkt<<24)|(poly3->b<<16)|(poly3->g<<8)|(poly3->r); - + for(x = 0; x < 3; x++) linked_list[linked_list_pos++] = ((poly3->y[x]&0x7ff)<<16)|(poly3->x[x]&0x7ff); - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } - + void GsSortPoly4(GsPoly4 *poly4) { int orig_pos = linked_list_pos; int x; unsigned char pkt = 0x28; unsigned int md; - + md = setup_attribs(0, poly4->attribute, &pkt); - + linked_list[linked_list_pos++] = 0x06000000; linked_list[linked_list_pos++] = md; linked_list[linked_list_pos++] = (pkt<<24)|(poly4->b<<16)|(poly4->g<<8)|(poly4->r); - + for(x = 0; x < 4; x++) linked_list[linked_list_pos++] = ((poly4->y[x]&0x7ff)<<16)|(poly4->x[x]&0x7ff); - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -204,18 +204,18 @@ void GsSortGPoly3(GsGPoly3 *poly3) int x; unsigned char pkt = 0x30; unsigned int md; - + md = setup_attribs(0, poly3->attribute, &pkt); - + linked_list[linked_list_pos++] = 0x07000000; linked_list[linked_list_pos++] = md; - + for(x = 0; x < 3; x++) { linked_list[linked_list_pos++] = (poly3->b[x]<<16)|(poly3->g[x]<<8)|(poly3->r[x]) | ((x == 0)?(pkt<<24):0); linked_list[linked_list_pos++] = ((poly3->y[x]&0x7ff)<<16)|(poly3->x[x]&0x7ff); } - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -227,39 +227,39 @@ void GsSortGPoly4(GsGPoly4 *poly4) int x; unsigned char pkt = 0x38; unsigned int md; - - md = setup_attribs(0, poly4->attribute, &pkt); - + + md = setup_attribs(0, poly4->attribute, &pkt); + linked_list[linked_list_pos++] = 0x09000000; linked_list[linked_list_pos++] = md; - + for(x = 0; x < 4; x++) { linked_list[linked_list_pos++] = (poly4->b[x]<<16)|(poly4->g[x]<<8)|(poly4->r[x]) | ((x == 0)?(pkt<<24):0); linked_list[linked_list_pos++] = ((poly4->y[x]&0x7ff)<<16)|(poly4->x[x]&0x7ff); } - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } void GsSortLine(GsLine *line) { // PKT 0x40 - + int orig_pos = linked_list_pos; int x; unsigned char pkt = 0x40; unsigned int md; - - md = setup_attribs(0, line->attribute, &pkt); - + + md = setup_attribs(0, line->attribute, &pkt); + linked_list[linked_list_pos++] = 0x04000000; linked_list[linked_list_pos++] = md; linked_list[linked_list_pos++] = (pkt<<24)|(line->b<<16)|(line->g<<8)|(line->r); - + for(x = 0; x < 2; x++) linked_list[linked_list_pos++] = ((line->y[x]&0x7ff)<<16)|(line->x[x]&0x7ff); - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -271,18 +271,18 @@ void GsSortGLine(GsGLine *line) int x; unsigned char pkt = 0x50; unsigned int md; - - md = setup_attribs(0, line->attribute, &pkt); - + + md = setup_attribs(0, line->attribute, &pkt); + linked_list[linked_list_pos++] = 0x05000000; linked_list[linked_list_pos++] = md; - + for(x=0;x<2;x++) { linked_list[linked_list_pos++] = (line->b[x]<<16)|(line->g[x]<<8)|(line->r[x])|((x == 0)?(pkt<<24):0); linked_list[linked_list_pos++] = ((line->y[x]&0x7ff)<<16)|(line->x[x] & 0x7ff); } - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -293,14 +293,14 @@ void GsSortDot(GsDot *dot) int orig_pos = linked_list_pos; unsigned char pkt = 0x68; unsigned int md; - - md = setup_attribs(0, dot->attribute, &pkt); - + + md = setup_attribs(0, dot->attribute, &pkt); + linked_list[linked_list_pos++] = 0x03000000; linked_list[linked_list_pos++] = md; linked_list[linked_list_pos++] = (pkt<<24)|(dot->b<<16)|(dot->g<<8)|(dot->r); linked_list[linked_list_pos++] = ((dot->y&0x7ff)<<16)|(dot->x&0x7ff); - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -314,13 +314,13 @@ void GsSortSprite(GsSprite *sprite) /*if(sprite->w > 256) sprite->w = 256; - + if(sprite->h > 256) sprite->h = 256;*/ // If "sprite" has no flipping and no scaling use sprite primitive // otherwise manipulate a 4 point textured polygon primitive - + if(sprite->rotate != 0) { tpoly4.u[0] = sprite->u; @@ -355,7 +355,7 @@ void GsSortSprite(GsSprite *sprite) for(x = 0; x < 4; x++) { gs_internal_vector_rotate(0, 0, sprite->rotate, gs_vbuf[x], gs_vbuf[x]); - tpoly4.x[x] = mcx + gs_vbuf[x][0]; + tpoly4.x[x] = mcx + gs_vbuf[x][0]; tpoly4.y[x] = mcy + gs_vbuf[x][1]; } @@ -369,15 +369,15 @@ void GsSortSprite(GsSprite *sprite) GsSortTPoly4(&tpoly4); } - else if((sprite->attribute & (H_FLIP|V_FLIP)) || + else if((sprite->attribute & (H_FLIP|V_FLIP)) || sprite->scalex != 0 || sprite->scaley != 0) { x = sprite->w; if(x>256)x=256; - + y = sprite->h; if(y>256)y=256; - + if(sprite->scalex > 8) { x *= sprite->scalex; @@ -390,7 +390,7 @@ void GsSortSprite(GsSprite *sprite) else if(sprite->scalex <= -2) x/=-sprite->scalex; } - + if(sprite->scaley > 8) { y *= sprite->scaley; @@ -403,12 +403,12 @@ void GsSortSprite(GsSprite *sprite) else if(sprite->scaley <= -2) y/=-sprite->scaley; } - + tpoly4.x[0] = tpoly4.x[1] = sx; tpoly4.x[2] = tpoly4.x[3] = (sx + x); tpoly4.y[0] = tpoly4.y[2] = sy; tpoly4.y[1] = tpoly4.y[3] = (sy + y); - + if(sprite->attribute & H_FLIP) { tpoly4.u[0] = tpoly4.u[1] = (sprite->u + sprite->w) - 1; @@ -418,8 +418,8 @@ void GsSortSprite(GsSprite *sprite) { tpoly4.u[0] = tpoly4.u[1] = sprite->u; tpoly4.u[2] = tpoly4.u[3] = (sprite->u + sprite->w); - } - + } + if(sprite->attribute & V_FLIP) { tpoly4.v[0] = tpoly4.v[2] = (sprite->v + sprite->h) - 1; @@ -438,7 +438,7 @@ void GsSortSprite(GsSprite *sprite) tpoly4.tpage = sprite->tpage; tpoly4.cx = sprite->cx; tpoly4.cy = sprite->cy; - + GsSortTPoly4(&tpoly4); } else @@ -461,7 +461,7 @@ void GsSortSimpleSprite(GsSprite *sprite) linked_list[linked_list_pos++] = ((sprite->y&0x7ff)<<16)|(sprite->x&0x7ff); linked_list[linked_list_pos++] = (get_clutid(sprite->cx,sprite->cy)<<16)|(sprite->v<<8)|sprite->u; linked_list[linked_list_pos++] = (sprite->h<<16)|sprite->w; - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -470,7 +470,7 @@ void GsSortRectangle(GsRectangle *rectangle) unsigned int orig_pos = linked_list_pos; unsigned char pkt = 0x60; unsigned int md; - + md = setup_attribs(0, rectangle->attribute, &pkt); linked_list[linked_list_pos++] = 0x04000000; @@ -478,7 +478,7 @@ void GsSortRectangle(GsRectangle *rectangle) linked_list[linked_list_pos++] = (pkt<<24)|(rectangle->b<<16)|(rectangle->g<<8)|(rectangle->r); linked_list[linked_list_pos++] = ((rectangle->y&0x7ff)<<16)|(rectangle->x&0x7ff); linked_list[linked_list_pos++] = (rectangle->h<<16)|rectangle->w; - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -487,11 +487,11 @@ void GsSortTPoly4(GsTPoly4 *tpoly4) unsigned int orig_pos = linked_list_pos; unsigned char pkt = 0x2c; unsigned int md; - + /*md = setup_attribs(tpoly4->tpage, tpoly4->attribute, &pkt);*/ - + //printf("tpoly4->tpage = %d\n", tpoly4->tpage); - + md = setup_attribs(tpoly4->tpage, tpoly4->attribute, &pkt); //printf("pkt = %x\n", pkt); @@ -500,7 +500,7 @@ void GsSortTPoly4(GsTPoly4 *tpoly4) //linked_list[linked_list_pos++] = md; //linked_list[linked_list_pos++] = 0xe0000000; //linked_list[linked_list_pos++] = 0xe1000105; - + //printf("tpoly4 md: %08x\n", md); linked_list[linked_list_pos++] = (pkt<<24)|(tpoly4->b<<16)|(tpoly4->g<<8)|(tpoly4->r); linked_list[linked_list_pos++] = ((tpoly4->y[0]&0x7ff)<<16)|(tpoly4->x[0]&0x7ff); @@ -511,7 +511,7 @@ void GsSortTPoly4(GsTPoly4 *tpoly4) linked_list[linked_list_pos++] = (tpoly4->v[2]<<8)|tpoly4->u[2]; linked_list[linked_list_pos++] = ((tpoly4->y[3]&0x7ff)<<16)|(tpoly4->x[3]&0x7ff); linked_list[linked_list_pos++] = (tpoly4->v[3]<<8)|tpoly4->u[3]; - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -521,22 +521,22 @@ void GsSortTPoly3(GsTPoly3 *tpoly3) int x; unsigned char pkt = 0x24; unsigned int md; - + md = setup_attribs(tpoly3->tpage, tpoly3->attribute, &pkt); - + linked_list[linked_list_pos++] = 0x07000000; linked_list[linked_list_pos++] = (pkt<<24)|(tpoly3->b<<16)|(tpoly3->g<<8)|(tpoly3->r); - + for(x = 0; x < 3; x++) { linked_list[linked_list_pos++] = ((tpoly3->y[x]&0x7ff)<<16)|(tpoly3->x[x]&0x7ff); linked_list[linked_list_pos] = (tpoly3->u[x]<<8)|tpoly3->v[x]; - + switch(x) { case 0: - linked_list[linked_list_pos++] |= + linked_list[linked_list_pos++] |= get_clutid(tpoly3->cx, tpoly3->cy) << 16; break; case 1: @@ -548,7 +548,7 @@ void GsSortTPoly3(GsTPoly3 *tpoly3) break; } } - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -559,7 +559,7 @@ void MoveImage(int src_x, int src_y, int dst_x, int dst_y, int w, int h) */ while(!(GPU_CONTROL_PORT & (1<<0x1c))); - + GPU_CONTROL_PORT = 0x04000000; GPU_DATA_PORT = 0x01000000; // Reset command buffer GPU_DATA_PORT = 0xE6000000; @@ -571,35 +571,35 @@ void MoveImage(int src_x, int src_y, int dst_x, int dst_y, int w, int h) /* * Add a method to add arbitrary data to the packet list - */ - -void LoadImage(void *img, int x, int y, int w, int h) + */ + +void LoadImage(const void *img, int x, int y, int w, int h) { unsigned short *image = (unsigned short*)img; int a, l; - + //printf("LoadImage: %d, %d, %d, %d\n", x, y, w, h); - + while(!(GPU_CONTROL_PORT & (1<<0x1c))); - + GPU_CONTROL_PORT = 0x04000000; // Disable DMA - + // Reset should be on data port ! otherwise we won't be able -// to write CLUTs for some time after they've been used! -// (why??) - +// to write CLUTs for some time after they've been used! +// (why??) + GPU_DATA_PORT = 0x01000000; GPU_DATA_PORT = 0xE6000000; // disable masking stuff !! GPU_DATA_PORT = 0xA0000000; GPU_DATA_PORT = (y<<16)|x; GPU_DATA_PORT = (h<<16)|w; - + l = w*h; if(l&1)l++; - + for(a = 0; a < l; a+=2) GPU_DATA_PORT = image[a]|(image[a+1]<<16); - + GPU_CONTROL_PORT = 0x01000000; // while(!(GPU_CONTROL_PORT & (1<<0x1c))); } @@ -607,24 +607,24 @@ void LoadImage(void *img, int x, int y, int w, int h) /*void LoadImage(void *img, int x, int y, int w, int h) { GPU_dw(x, y, w, h, img); - + int l; - + printf("LoadImage: %d, %d, %d, %d\n", x, y, w, h); - + l = w*h; if(l&1)l++; l/=2; - - while(!(GPU_CONTROL_PORT & (1<<0x1c))); // Wait for the GPU to be free - + + while(!(GPU_CONTROL_PORT & (1<<0x1c))); // Wait for the GPU to be free + gpu_ctrl(4, 2); // DMA CPU->GPU mode D2_MADR = (unsigned int)img; D2_BCR = (l << 16) | 1; D2_CHCR = 0x01000201; - + // Wait for DMA to finish - + while(D2_CHCR & (1<<0x18)); //}*/ @@ -639,26 +639,26 @@ void GsSetDrawEnv(GsDrawEnv *drawenv) */ draw_mode_packet = (0xe1<<24)|(drawenv->draw_on_display>=1)<<10| - (drawenv->dither>=1)<<9; + (drawenv->dither>=1)<<9; - gpu_data_ctrl(0xe1, draw_mode_packet); + gpu_data_ctrl(0xe1, draw_mode_packet); gpu_data_ctrl(0xe2, 0); gpu_data_ctrl(0xe3, (drawenv->y<<10)|drawenv->x); - + end_x = (drawenv->x + drawenv->w)-1; end_y = (drawenv->y + drawenv->h)-1; - + gpu_data_ctrl(0xe4, (end_y<<10)|end_x); - + //#warning "Check drawing offset better." gpu_data_ctrl(0xe5, (drawenv->y<<11)|drawenv->x); //gpu_data_ctrl(0xe5, 0); - - + + mf = 0; if(drawenv->set_mask) mf|=MASK_SET; if(drawenv->ignore_mask) mf|=MASK_IGNORE; - + GsSetMasking(mf); GsCurDrawEnvW = drawenv->w; @@ -673,7 +673,7 @@ void GsSetDispEnv(GsDispEnv *dispenv) void gpu_ctrl(unsigned int command, unsigned int param) { unsigned int doubleword = (command << 0x18) | param; - + GPU_CONTROL_PORT = 0x01000000; GPU_CONTROL_PORT = doubleword; } @@ -686,7 +686,7 @@ void gpu_data(unsigned int data) void gpu_data_ctrl(unsigned int command, unsigned int param) { unsigned int doubleword = (command << 0x18) | param; - + GPU_CONTROL_PORT = 0x01000000; GPU_DATA_PORT = doubleword; } @@ -697,7 +697,7 @@ unsigned int setup_attribs(unsigned char tpage, unsigned int attribute, unsigned //printf("tpage = %d, attribute = %x, packet = %x\n", tpage, attribute, packet); //while(1);*/ - + /* * First, setup draw mode setting. */ @@ -714,7 +714,7 @@ unsigned int setup_attribs(unsigned char tpage, unsigned int attribute, unsigned *packet|=2; //printf("sprite_mode_packet = %08x\n", sprite_mode_packet); - + return sprite_mode_packet; } @@ -737,15 +737,15 @@ void GsInitEx(unsigned int flags) { //gpu_ctrl(0, 0); // Reset GPU GsReset(); // Reset GPU - + DPCR |= (1<<0xb); // Enable dma channel 2 gpu_ctrl(4, 2); // DMA CPU->GPU mode - + //gpu_ctrl(3, 1); // Disable display GsEnableDisplay(0); // Disable display - + GPU_DATA_PORT = 0x01000000; // Reset data port - + /*gpu_ctrl(6, 0xc40240); // Horizontal start end gpu_ctrl(7, 0x049025); // Vertical start end*/ //DrawFBRect(0, 0, 1023, 511, 0, 0, 0); @@ -764,7 +764,7 @@ void GsInit() IMASK|=8; // Enable VBLANK interrupt eventid = openevent(0xf0000001, 2, 0x1000, vblank_handler); - + if(eventid == -1) { printf("SetVBlankHandler: Failed to open event!\n"); @@ -772,7 +772,7 @@ void GsInit() } else printf("SetVBlankHandler: Event opened successfully!\n"); - + if(enableevent(eventid) == 0) { printf("SetVBlankHandler: Failed to enable event!\n"); @@ -781,7 +781,7 @@ void GsInit() } else printf("SetVBlankHandler: Event enabled successfully!\n"); - + ExitCriticalSection(); }*/ @@ -795,9 +795,9 @@ int GsSetVideoModeEx(int width, int height, int video_mode, int rgb24, int inter, int reverse) { unsigned char mode = 0; - + GsEnableDisplay(0); - + if(video_mode == VMODE_NTSC) { gpu_ctrl(6, 0xC4E24E); // Horizontal screen range @@ -808,7 +808,7 @@ int GsSetVideoModeEx(int width, int height, int video_mode, int rgb24, gpu_ctrl(6, 0xC62262); // Horizontal screen range gpu_ctrl(7, 0x04B42D); // Vertical screen range } - + switch(height) { case 240: @@ -820,7 +820,7 @@ int GsSetVideoModeEx(int width, int height, int video_mode, int rgb24, printf("%s: error, unknown width %d!\n", __FUNCTION__, width); return 0; } - + switch(width) { case 256: @@ -841,19 +841,19 @@ int GsSetVideoModeEx(int width, int height, int video_mode, int rgb24, printf("%s: error, unknown height %d!\n", __FUNCTION__, height); return 0; } - + if(video_mode)mode|=8; // Set PAL if(rgb24)mode|=16; // Set unaccellerated 24-bit mode if(inter)mode|=32; // Set interlaced video mode if(reverse)mode|=128; // Set reverse flag (?) - + gpu_ctrl(8, mode); GsEnableDisplay(1); - + GsScreenW = width; GsScreenH = height; GsScreenM = video_mode; - + return 1; } @@ -863,7 +863,7 @@ void DrawFBRect(int x, int y, int w, int h, int r, int g, int b) // Disable DMA GPU_CONTROL_PORT = 0x04000000; - + GPU_DATA_PORT = 0x01000000; // Reset data port GPU_DATA_PORT = 0xE6000000; // Disable masking stuff gpu_data_ctrl(2, ((b&0xff)<<16)|((g&0xff)<<8)|r); @@ -875,7 +875,7 @@ void GsClearMem() { // "Clears" the entire video memory by using DrawFBRect // and waits that it has finished drawing... - + DrawFBRect(0,0,1023,511,0,0,0); while(GsIsDrawing()); DrawFBRect(0,511,1023,1,0,0,0); @@ -884,27 +884,27 @@ void GsClearMem() while(GsIsDrawing()); } -int GsImageFromTim(GsImage *image, void *timdata) +int GsImageFromTim(GsImage *image, const void *timdata) { - unsigned int *timdata_i = (unsigned int*)timdata; - unsigned short *timdata_s = (unsigned short*)timdata; + const unsigned int *timdata_i = (unsigned int*)timdata; + const unsigned short *timdata_s = (unsigned short*)timdata; unsigned int pdata_pos; unsigned int pdata_pos_s; - + //printf("timdata_i[0] = %08x\n", timdata_i[0]); - + if(timdata_i[0] != 0x10) { //printf("timdata_i[0] = %08x\n", timdata_i[0]); return 0; // Unknown version or ID } - + image->pmode = timdata_i[1] & 7; - + //printf("image->pmode = %d\n", image->pmode); - + image->has_clut = (timdata_i[1] & 8) ? 1 : 0; - + if(!image->has_clut) pdata_pos = 8; else @@ -915,21 +915,21 @@ int GsImageFromTim(GsImage *image, void *timdata) image->clut_w = timdata_s[8]; image->clut_h = timdata_s[9]; image->clut_data = &timdata_s[10]; - + /*printf("image->clut_y = %d\n", image->clut_y); printf("image->clut_x = %d\n", image->clut_x); printf("image->clut_h = %d\n", image->clut_h); printf("image->clut_w = %d\n", image->clut_w);*/ } - + pdata_pos_s = pdata_pos / 2; - + image->x = timdata_s[pdata_pos_s + 2]; image->y = timdata_s[pdata_pos_s + 3]; image->w = timdata_s[pdata_pos_s + 4]; image->h = timdata_s[pdata_pos_s + 5]; image->data = &timdata_s[pdata_pos_s + 6]; - + /*printf("image->y = %d\n", image->y); printf("image->x = %d\n", image->x); printf("image->h = %d\n", image->h); @@ -943,7 +943,7 @@ void GsUploadImage(GsImage *image) if(image->has_clut) LoadImage(image->clut_data, image->clut_x, image->clut_y, image->clut_w, image->clut_h); - + LoadImage(image->data, image->x, image->y, image->w, image->h); } @@ -951,21 +951,21 @@ int GsSpriteFromImage(GsSprite *sprite, GsImage *image, int do_upload) { if(do_upload) GsUploadImage(image); - + bzero(sprite, sizeof(GsSprite)); - + sprite->tpage = (image->x / 64) + ((image->y/256)*16); sprite->u = image->x & 0x3f; sprite->v = image->y & 0xff; - + sprite->cx = image->clut_x; sprite->cy = image->clut_y; - + if(image->pmode == 0) // 4-bit pixel mode sprite->u*=4; else if(image->pmode == 1) // 8-bit pixel mode sprite->u*=2; - + switch(image->pmode) { case 0: @@ -981,11 +981,11 @@ int GsSpriteFromImage(GsSprite *sprite, GsImage *image, int do_upload) sprite->w = image->w + (image->w / 2); break; } - + sprite->h = image->h; sprite->attribute = COLORMODE(image->pmode); sprite->r = sprite->g = sprite->b = NORMAL_LUMINANCE; - + return 1; } @@ -997,16 +997,16 @@ void GsSetMasking(unsigned char flag) int GsIsDrawing() { /*int x; - + if(PSX_GetInitFlags() & PSX_INIT_NOBIOS) { int r = (!(GPU_CONTROL_PORT & (1<<0x1a))) || (!__psxsdk_gpu_dma_finished); - + for(x = 0; x < 1000; x++); - + return r; }*/ - + return !(GPU_CONTROL_PORT & (1<<0x1a)) ; } @@ -1018,7 +1018,7 @@ int GsIsDrawing() void GsSetDrawEnvSimple(int x, int y, int w, int h) { GsDrawEnv env; - + env.dither = 0; env.draw_on_display = 1; env.x = x; @@ -1027,17 +1027,17 @@ void GsSetDrawEnvSimple(int x, int y, int w, int h) env.h = h; env.ignore_mask = 0; env.set_mask = 0; - + GsSetDrawEnv(&env); } void GsSetDispEnvSimple(int x, int y) { GsDispEnv env; - + env.x = x; env.y = y; - + GsSetDispEnv(&env); } @@ -1046,20 +1046,20 @@ void GsSetDispEnvSimple(int x, int y) void GsLoadFont(int fb_x, int fb_y, int cx, int cy) { unsigned short pal[2] = {0x0, 0x7fff}; - + LoadImage(psxsdk_font_data, fb_x, fb_y, 16, 128); while(GsIsDrawing()); - + if(cx != -1 && cy != -1) { LoadImage(pal, cx, cy, 16, 1); - + fb_font_cx = cx; fb_font_cy = cy; - + while(GsIsDrawing()); } - + fb_font_x = fb_x; fb_font_y = fb_y; } @@ -1076,11 +1076,11 @@ unsigned int GsPrintFont_Draw(int x, int y, int scalex, int scaley) va_start(ap, fmt);*/ // r = vsnprintf(gpu_stringbuf, 512, fmt, ap); - + // va_end(ap); fw = gs_calculate_scaled_size(8, scalex);//(8*scalex)/4096; fh = gs_calculate_scaled_size(8, scaley);//(8*scaley)/4096; - + spr.x = x; spr.y = y; spr.r = prfont_rl; @@ -1094,9 +1094,9 @@ unsigned int GsPrintFont_Draw(int x, int y, int scalex, int scaley) spr.h = 8; spr.scalex = scalex; spr.scaley = scaley; - + string = gpu_stringbuf; - + while(*string) { if(prfont_flags & PRFONT_WRAP) @@ -1107,7 +1107,7 @@ unsigned int GsPrintFont_Draw(int x, int y, int scalex, int scaley) spr.y += fh; } } - + if(*string >= ' ' && *string <= '~') { spr.u = ((fb_font_x & 0x3f)*4)+((*string & 7) << 3); @@ -1116,19 +1116,19 @@ unsigned int GsPrintFont_Draw(int x, int y, int scalex, int scaley) if((spr.x < GsCurDrawEnvW && (spr.x+fw)>=0) && (spr.y < GsCurDrawEnvH && (spr.y+fh)>=0)) { - + if((scalex == 0 || scalex == 1) && (scaley == 0 || scaley == 1)) GsSortSimpleSprite(&spr); else GsSortSprite(&spr); } - + spr.x += fw; } - + if(*string == '\r') spr.x = 0; - + if(*string == '\n') { spr.x = (prfont_flags & PRFONT_UNIXLF)? 0 : x; @@ -1137,10 +1137,10 @@ unsigned int GsPrintFont_Draw(int x, int y, int scalex, int scaley) if(*string == '\t') spr.x += fw * 8; - + string++; } - + return (spr.y << 16) | spr.x; } @@ -1152,7 +1152,7 @@ unsigned int GsVPrintFont(int x, int y, const char *fmt, va_list ap) int fw = gs_calculate_scaled_size(8, prfont_scale_x); r = vsnprintf(gpu_stringbuf, 512, fmt, ap); - + if(prfont_flags & PRFONT_WRAP) r = GsPrintFont_Draw(x, y, prfont_scale_x, prfont_scale_y); else if(prfont_flags & PRFONT_CENTER) @@ -1161,22 +1161,22 @@ unsigned int GsVPrintFont(int x, int y, const char *fmt, va_list ap) r = GsPrintFont_Draw(x - (r * fw), y, prfont_scale_x, prfont_scale_y); else r = GsPrintFont_Draw(x, y, prfont_scale_x, prfont_scale_y); - + return r; } unsigned int GsPrintFont(int x, int y, const char *fmt, ...) { int r; - + va_list ap; - + va_start(ap, fmt); r = GsVPrintFont(x, y, fmt, ap); va_end(ap); - + return r; } @@ -1198,7 +1198,7 @@ void GsSetFont(int fb_x, int fb_y, int cx, int cy) void GsSetFontAttrib(unsigned int flags) { prfont_flags = flags; - + if(prfont_flags == 0) { PRFONT_SCALEX(0); @@ -1304,13 +1304,13 @@ void GsSetAutoWait() void GsRotateVector(int x_a, int y_a, int z_a, double *v, double *n) { - gs_internal_vector_rotate(x_a, y_a, z_a, v, n); + gs_internal_vector_rotate(x_a, y_a, z_a, v, n); } /*void GsSortSimpleMap(GsMap *map) { unsigned int orig_pos = linked_list_pos; - //unsigned int + //unsigned int unsigned char pkt = 0x64; unsigned int md; unsigned char curCount = 0; @@ -1328,9 +1328,9 @@ void GsRotateVector(int x_a, int y_a, int z_a, double *v, double *n) orig_pos = linked_list_pos; linked_list[linked_list_pos++] = 0x00000000; - + remaining = map->w * map->h; - + for(y = 0; y < map->h; y++) { for(x = 0; x < map->w; x++) @@ -1347,35 +1347,35 @@ void GsRotateVector(int x_a, int y_a, int z_a, double *v, double *n) tn = ((unsigned int*)map->data)[(y * map->l) + x]; break; } - + tn &= ~map->tmask; - + tu = (tn * map->tw) % map->tmw; tv = ((tn * map->tw) / map->tmw) * map->th; - + linked_list[linked_list_pos++] = (pkt<<24)|(map->b<<16)|(map->g<<8)|map->r; linked_list[linked_list_pos++] = (((map->y+(y*map->th))&0x7ff)<<16)|((map->x+(x*map->tw))&0x7ff); linked_list[linked_list_pos++] = (get_clutid(map->cx,map->cy)<<16)|((tv+map->v)<<8)| (tu+map->u); linked_list[linked_list_pos++] = (map->th<<16)|map->tw; - + curCount++; - + if(curCount == 252) { linked_list[orig_pos] = (252 << 24) | (((unsigned int)&linked_list[linked_list_pos]) & 0xffffff); orig_pos = linked_list_pos; - + remaining -= curCount; - + if(remaining > 0) linked_list_pos++; - + curCount = 0; } } } - + if(curCount > 0) linked_list[orig_pos] = (curCount << 24) | (((unsigned int)&linked_list[linked_list_pos]) & 0xffffff); }*/ @@ -1389,23 +1389,23 @@ void GsSetListEx(unsigned int *listptr, unsigned int listpos) void GsSortPolyLine(GsPolyLine *line) { // PKT 0x48 - + int orig_pos = linked_list_pos; int x; unsigned char pkt = 0x48; unsigned int md; - - md = setup_attribs(0, line->attribute, &pkt); - + + md = setup_attribs(0, line->attribute, &pkt); + linked_list_pos++; // skip this word, we will replace it later linked_list[linked_list_pos++] = md; linked_list[linked_list_pos++] = (pkt<<24)|(line->b<<16)|(line->g<<8)|(line->r); - + for(x = 0; x < line->npoints; x++) linked_list[linked_list_pos++] = ((line->y[x]&0x7ff)<<16)|(line->x[x]&0x7ff); - + linked_list[linked_list_pos++] = 0x55555555; // termination code - + linked_list[orig_pos] = ((line->npoints+3) << 24) | (((unsigned int)&linked_list[linked_list_pos]) & 0xffffff); } @@ -1417,20 +1417,20 @@ void GsSortGPolyLine(GsGPolyLine *line) int x; unsigned char pkt = 0x58; unsigned int md; - - md = setup_attribs(0, line->attribute, &pkt); - + + md = setup_attribs(0, line->attribute, &pkt); + linked_list_pos++; // skip this word, we will replace it later linked_list[linked_list_pos++] = md; - + for(x=0; x < line->npoints;x++) { linked_list[linked_list_pos++] = (line->b[x]<<16)|(line->g[x]<<8)|(line->r[x])|((x == 0)?(pkt<<24):0); linked_list[linked_list_pos++] = ((line->y[x]&0x7ff)<<16)|(line->x[x] & 0x7ff); } - + linked_list[linked_list_pos++] = 0x55555555; // termination code - + linked_list[orig_pos] = (((line->npoints*2)+2) << 24) | (((unsigned int)&linked_list[linked_list_pos]) & 0xffffff); } @@ -1439,11 +1439,11 @@ void GsSortGTPoly4(GsGTPoly4 *tpoly4) unsigned int orig_pos = linked_list_pos; unsigned char pkt = 0x3c; unsigned int md; - + /*md = setup_attribs(tpoly4->tpage, tpoly4->attribute, &pkt);*/ - + //printf("tpoly4->tpage = %d\n", tpoly4->tpage); - + md = setup_attribs(tpoly4->tpage, tpoly4->attribute, &pkt); //printf("pkt = %x\n", pkt); @@ -1452,7 +1452,7 @@ void GsSortGTPoly4(GsGTPoly4 *tpoly4) //linked_list[linked_list_pos++] = md; //linked_list[linked_list_pos++] = 0xe0000000; //linked_list[linked_list_pos++] = 0xe1000105; - + //printf("tpoly4 md: %08x\n", md); linked_list[linked_list_pos++] = (pkt<<24)|(tpoly4->b[0]<<16)|(tpoly4->g[0]<<8)|(tpoly4->r[0]); linked_list[linked_list_pos++] = ((tpoly4->y[0]&0x7ff)<<16)|(tpoly4->x[0]&0x7ff); @@ -1466,7 +1466,7 @@ void GsSortGTPoly4(GsGTPoly4 *tpoly4) linked_list[linked_list_pos++] = (tpoly4->b[2]<<16)|(tpoly4->g[2]<<8)|tpoly4->r[2]; linked_list[linked_list_pos++] = ((tpoly4->y[3]&0x7ff)<<16)|(tpoly4->x[3]&0x7ff); linked_list[linked_list_pos++] = (tpoly4->v[3]<<8)|tpoly4->u[3]; - + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } @@ -1476,22 +1476,22 @@ void GsSortGTPoly3(GsGTPoly3 *tpoly3) int x; unsigned char pkt = 0x34; unsigned int md; - + md = setup_attribs(tpoly3->tpage, tpoly3->attribute, &pkt); - + linked_list[linked_list_pos++] = 0x09000000; - + for(x = 0; x < 3; x++) { linked_list[linked_list_pos++] = ((x==0)?(pkt<<24):0)|(tpoly3->b[x]<<16)|(tpoly3->g[x]<<8)|(tpoly3->r[x]); linked_list[linked_list_pos++] = ((tpoly3->y[x]&0x7ff)<<16)|(tpoly3->x[x]&0x7ff); linked_list[linked_list_pos] = (tpoly3->u[x]<<8)|tpoly3->v[x]; - + switch(x) { case 0: - linked_list[linked_list_pos++] |= + linked_list[linked_list_pos++] |= get_clutid(tpoly3->cx, tpoly3->cy) << 16; break; case 1: @@ -1501,7 +1501,7 @@ void GsSortGTPoly3(GsGTPoly3 *tpoly3) default: linked_list_pos++; } - } - + } + linked_list[orig_pos] |= ((unsigned int)&linked_list[linked_list_pos]) & 0xffffff; } diff --git a/libpsx/src/spu.c b/libpsx/src/spu.c index 441acb6..53ddf2d 100644 --- a/libpsx/src/spu.c +++ b/libpsx/src/spu.c @@ -22,17 +22,17 @@ void SsVoiceVol(int voice, unsigned short left, unsigned short right) void SsVoicePitch(int voice, unsigned short pitch) { unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice); - + a[2] = pitch; } void SsVoiceStartAddr(int voice, unsigned int addr) { -// address given is real address, then it is divided by eight when written to the register +// address given is real address, then it is divided by eight when written to the register // example: SSVoiceStartAddr(0, 0x1008) , writes 0x201 on the register which means 0x1008 - + unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice); - + a[3] = (addr >> 3); } @@ -50,17 +50,17 @@ void SsVoiceRepeatAddr(int voice, unsigned int addr) // the explanation for SSVoiceStartAddr() is valid for this function as well unsigned short *a = (unsigned short*)SPU_VOICE_BASE_ADDR(voice); - + a[7] = (addr >> 3); } void SsKeyOn(int voice) { unsigned int i = 1 << voice; - + SPU_KEY_ON1 = i & 0xffff; SPU_KEY_ON2 = i >> 16; - + /* while(SPU_KEY_ON1 != (i & 0xffff)); while(SPU_KEY_ON2 != (i >> 16)); */ @@ -69,7 +69,7 @@ void SsKeyOn(int voice) void SsKeyOff(int voice) { unsigned int i = 1 << voice; - + SPU_KEY_OFF1 = i & 0xffff; SPU_KEY_OFF2 = i >> 16; } @@ -98,11 +98,11 @@ void SsInit() int x; printf("Initializing SPU (Sound Synthesizer)...\n"); - + DPCR |= 0xB0000; - + SPU_MVOL_L = 0x3fff; - SPU_MVOL_R = 0x3fff; + SPU_MVOL_R = 0x3fff; SPU_CONTROL = 0x0; SsWait(); @@ -110,7 +110,7 @@ void SsInit() SPU_STATUS = 0x4; // Must be done, but not totally understood while(SPU_STATUS2 & 0x7ff); - + SPU_REVERB_L = 0x0; SPU_REVERB_R = 0x0; @@ -136,10 +136,10 @@ void SsInit() SPU_EXT_VOL_R = 0x0; // set volume of all voices to 0 and adsr to 0,0 - + for(x = 0; x < 24; x++) { - SsVoiceVol(x, 0, 0); + SsVoiceVol(x, 0, 0); SsVoiceADSRRaw(x, 0, 0); } @@ -149,40 +149,40 @@ void SsInit() SPU_REVERB_WORK_ADDR = 0xFFFE; // Reverb work address in SPU memory, 0x1fff * 8 = 0xFFF8 ss_vag_addr = SPU_DATA_BASE_ADDR; - + printf("SPU/SS Initialized.\n"); } -// This implementation of SsUpload() was contributed by Shendo +// This implementation of SsUpload() was contributed by Shendo // It waits either for a period of time or for the status flags to be raised, whichever comes first. // This makes it work also on ePSXe, which never raises the status flags. -void SsUpload(void *addr, int size, int spu_addr) +void SsUpload(const void *addr, int size, int spu_addr) { - unsigned short *ptr = addr; + const unsigned short *ptr = addr; int i; - + while(size > 0) - { + { SPU_STATUS = 4; // Sound RAM Data Transfer Control SPU_CONTROL = SPU_CONTROL & ~0x30; // SPUCNT.transfer_mode = 0 (STOP) - - + + for(i = 0; i < 100; i++) if(((SPU_STATUS2 >> 4) & 3) == 0)break; // wait until SPUSTAT.transfer is 0 (STOP) - + SPU_ADDR = spu_addr >> 3; for(i = 0; i < 32; i++) SPU_DATA = ptr[i]; - + SPU_CONTROL = (SPU_CONTROL & ~0x30) | 16; // SPUCNT.transfer_mode = 1 (MANUAL) - + for(i = 0; i < 100; i++) if(((SPU_STATUS2 >> 4) & 3) == 1)break; // wait until SPUSTAT.transfer is 1 (MANUAL) - + while(SPU_STATUS2 & 0x400); // wait for transfer busy bit to be cleared - + spu_addr += 64; ptr += 32; size-=64; @@ -194,24 +194,24 @@ unsigned short SsFreqToPitch(int hz) // Converts a normal samples per second frequency value in Hz // in a pitch value -// i.e. 44100 -> 0x1000, 22050 -> 0x800 - +// i.e. 44100 -> 0x1000, 22050 -> 0x800 + return (hz << 12) / 44100; } -int SsReadVag(SsVag *vag, void *data) +int SsReadVag(SsVag *vag, const void *data) { - unsigned char *i = data; - + const unsigned char *i = data; + if(strncmp(data, "VAGp", 4) != 0) return 0; - + vag->version = (i[4]<<24)|(i[5]<<16)|(i[6]<<8)|i[7]; vag->data_size = (i[12]<<24)|(i[13]<<16)|(i[14]<<8)|i[15]; vag->sample_rate = (i[16]<<24)|(i[17]<<16)|(i[18]<<8)|i[19]; memcpy(vag->name, &i[32], 16); vag->data = &i[48]; - + return 1; } @@ -229,14 +229,14 @@ void SsUploadVag(SsVag *vag) ss_vag_addr += vag->data_size; } -void SsPlayVag(SsVag *vag, unsigned char voice, unsigned short vl, +void SsPlayVag(SsVag *vag, unsigned char voice, unsigned short vl, unsigned short vr) { SsVoicePitch(voice, SsFreqToPitch(vag->sample_rate)); SsVoiceStartAddr(voice, vag->spu_addr); SsVoiceVol(voice, vl, vr); SsKeyOn(voice); - + vag->cur_voice = voice; } |
