X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2Fgfx_cd.c;h=120b0ddddaf3acf6b7a55b6887a4d2b1df8f6b30;hb=c008977e8ec74b68cbccc017620a156cc39b79b2;hp=e013aaa78cb8317af2f6b211c777c7d131152da2;hpb=913ef4b7a30287581cce120a643fbed1b4a418b3;p=picodrive.git diff --git a/Pico/cd/gfx_cd.c b/Pico/cd/gfx_cd.c index e013aaa..120b0dd 100644 --- a/Pico/cd/gfx_cd.c +++ b/Pico/cd/gfx_cd.c @@ -1,6 +1,4 @@ -// TODO... -// #include #include "../PicoInt.h" #define rot_comp Pico_mcd->rot_comp @@ -29,49 +27,40 @@ static const int Table_Rot_Time[] = }; -#if 1*0 -typedef struct -{ - unsigned int Reg_58; // Stamp_Size - unsigned int Reg_5A; - unsigned int Reg_5C; - unsigned int Reg_5E; - unsigned int Reg_60; - unsigned int Reg_62; - unsigned int Reg_64; // V_Dot - unsigned int Reg_66; - - unsigned int Stamp_Map_Adr; - unsigned int Buffer_Adr; - unsigned int Vector_Adr; - unsigned int Jmp_Adr; - unsigned int Float_Part; - unsigned int Draw_Speed; - - unsigned int XS; - unsigned int YS; - unsigned int DXS; - unsigned int DYS; - unsigned int XD; - unsigned int YD; - unsigned int XD_Mul; - unsigned int H_Dot; -} Rot_Comp; -#endif - static void gfx_cd_start(void) { int upd_len; - dprintf("gfx_cd_start()"); + // rot_comp.XD_Mul = ((rot_comp.Reg_5C & 0x1f) + 1) * 4; // unused + rot_comp.Function = (rot_comp.Reg_58 & 7) | (Pico_mcd->s68k_regs[3] & 0x18); // Jmp_Adr + // rot_comp.Buffer_Adr = (rot_comp.Reg_5E & 0xfff8) << 2; // unused? + rot_comp.YD = (rot_comp.Reg_60 >> 3) & 7; + rot_comp.Vector_Adr = (rot_comp.Reg_66 & 0xfffe) << 2; upd_len = (rot_comp.Reg_62 >> 3) & 0x3f; upd_len = Table_Rot_Time[upd_len]; - rot_comp.Draw_Speed = rot_comp.Float_Part = upd_len; rot_comp.Reg_58 |= 0x8000; // Stamp_Size, we start a new GFX operation + switch (rot_comp.Reg_58 & 6) // Scr_16? + { + case 0: // ? + rot_comp.Stamp_Map_Adr = (rot_comp.Reg_5A & 0xff80) << 2; + break; + case 2: // .Dot_32 + rot_comp.Stamp_Map_Adr = (rot_comp.Reg_5A & 0xffe0) << 2; + break; + case 4: // .Scr_16 + rot_comp.Stamp_Map_Adr = 0x20000; + break; + case 6: // .Scr_16_Dot_32 + rot_comp.Stamp_Map_Adr = (rot_comp.Reg_5A & 0xe000) << 2; + break; + } + + dprintf("gfx_cd_start, stamp_map_addr=%06x", rot_comp.Stamp_Map_Adr); + gfx_cd_update(); } @@ -88,21 +77,220 @@ static void gfx_completed(void) } -//static void gfx_do(void) -//{ -//} +static void gfx_do(unsigned int func, unsigned short *stamp_base, unsigned int H_Dot) +{ + unsigned int eax, ebx, ecx, edx, esi, edi, pixel; + unsigned int XD, Buffer_Adr; + int DYXS; + + XD = rot_comp.Reg_60 & 7; + Buffer_Adr = ((rot_comp.Reg_5E & 0xfff8) + rot_comp.YD) << 2; + ecx = *(unsigned int *)(Pico_mcd->word_ram2M + rot_comp.Vector_Adr); + edx = ecx >> 16; + ecx = (ecx & 0xffff) << 8; + edx <<= 8; + DYXS = *(int *)(Pico_mcd->word_ram2M + rot_comp.Vector_Adr + 4); + rot_comp.Vector_Adr += 8; + + // MAKE_IMAGE_LINE + while (H_Dot) + { + // MAKE_IMAGE_PIXEL + if (!(func & 1)) // NOT TILED + { + int mask = (func & 4) ? 0x00800000 : 0x00f80000; + if ((ecx | edx) & mask) + { + if (func & 0x18) goto Next_Pixel; + pixel = 0; + goto Pixel_Out; + } + } + + if (func & 2) // mode 32x32 dot + { + if (func & 4) // 16x16 screen + { + ebx = ((ecx >> (11+5)) & 0x007f) | + ((edx >> (11-2)) & 0x3f80); + } + else // 1x1 screen + { + ebx = ((ecx >> (11+5)) & 0x07) | + ((edx >> (11+2)) & 0x38); + } + } + else // mode 16x16 dot + { + if (func & 4) // 16x16 screen + { + ebx = ((ecx >> (11+4)) & 0x00ff) | + ((edx >> (11-4)) & 0xff00); + } + else // 1x1 screen + { + ebx = ((ecx >> (11+4)) & 0x0f) | + ((edx >> (11+0)) & 0xf0); + } + } + + edi = stamp_base[ebx]; + esi = (edi & 0x7ff) << 7; + if (!esi) { pixel = 0; goto Pixel_Out; } + edi >>= (11+1); + edi &= (0x1c>>1); + eax = ecx; + ebx = edx; + if (func & 2) edi |= 1; // 32 dots? + switch (edi) + { + case 0x00: // No_Flip_0, 16x16 dots + ebx = (ebx >> 9) & 0x3c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x1000; // bswap + eax = ((eax >> 8) & 0x40) + ebx; + break; + case 0x01: // No_Flip_0, 32x32 dots + ebx = (ebx >> 9) & 0x7c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x1000; // bswap + eax = ((eax >> 7) & 0x180) + ebx; + break; + case 0x02: // No_Flip_90, 16x16 dots + eax = (eax >> 9) & 0x3c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x2800; // bswap + eax += ((ebx >> 8) & 0x40) ^ 0x40; + break; + case 0x03: // No_Flip_90, 32x32 dots + eax = (eax >> 9) & 0x7c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x2800; // bswap + eax += ((ebx >> 7) & 0x180) ^ 0x180; + break; + case 0x04: // No_Flip_180, 16x16 dots + ebx = ((ebx >> 9) & 0x3c) ^ 0x3c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x2800; // bswap and flip + eax = (((eax >> 8) & 0x40) ^ 0x40) + ebx; + break; + case 0x05: // No_Flip_180, 32x32 dots + ebx = ((ebx >> 9) & 0x7c) ^ 0x7c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x2800; // bswap and flip + eax = (((eax >> 7) & 0x180) ^ 0x180) + ebx; + break; + case 0x06: // No_Flip_270, 16x16 dots + eax = ((eax >> 9) & 0x3c) ^ 0x3c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x1000; // bswap + eax += (ebx >> 8) & 0x40; + break; + case 0x07: // No_Flip_270, 32x32 dots + eax = ((eax >> 9) & 0x7c) ^ 0x7c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x1000; // bswap + eax += (ebx >> 7) & 0x180; + break; + case 0x08: // Flip_0, 16x16 dots + ebx = (ebx >> 9) & 0x3c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x2800; // bswap, flip + eax = (((eax >> 8) & 0x40) ^ 0x40) + ebx; + break; + case 0x09: // Flip_0, 32x32 dots + ebx = (ebx >> 9) & 0x7c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x2800; // bswap, flip + eax = (((eax >> 7) & 0x180) ^ 0x180) + ebx; + break; + case 0x0a: // Flip_90, 16x16 dots + eax = ((eax >> 9) & 0x3c) ^ 0x3c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x2800; // bswap, flip + eax += ((ebx >> 8) & 0x40) ^ 0x40; + break; + case 0x0b: // Flip_90, 32x32 dots + eax = ((eax >> 9) & 0x7c) ^ 0x7c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x2800; // bswap, flip + eax += ((ebx >> 7) & 0x180) ^ 0x180; + break; + case 0x0c: // Flip_180, 16x16 dots + ebx = ((ebx >> 9) & 0x3c) ^ 0x3c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x1000; // bswap + eax = ((eax >> 8) & 0x40) + ebx; + break; + case 0x0d: // Flip_180, 32x32 dots + ebx = ((ebx >> 9) & 0x7c) ^ 0x7c; + ebx += esi; + edi = (eax & 0x3800) ^ 0x1000; // bswap + eax = ((eax >> 7) & 0x180) + ebx; + break; + case 0x0e: // Flip_270, 16x16 dots + eax = (eax >> 9) & 0x3c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x1000; // bswap, flip + eax += (ebx >> 8) & 0x40; + break; + case 0x0f: // Flip_270, 32x32 dots + eax = (eax >> 9) & 0x7c; + eax += esi; + edi = (ebx & 0x3800) ^ 0x1000; // bswap, flip + eax += (ebx >> 7) & 0x180; + break; + } + + pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax); + if (!(edi & 0x800)) pixel >>= 4; + else pixel &= 0x0f; + +Pixel_Out: + if (!pixel && (func & 0x18)) goto Next_Pixel; + esi = Buffer_Adr + ((XD>>1)^1); // pixel addr + eax = *(Pico_mcd->word_ram2M + esi); // old pixel + if (XD & 1) + { + if ((eax & 0x0f) && (func & 0x18) == 0x08) goto Next_Pixel; // underwrite + *(Pico_mcd->word_ram2M + esi) = pixel | (eax & 0xf0); + } + else + { + if ((eax & 0xf0) && (func & 0x18) == 0x08) goto Next_Pixel; // underwrite + *(Pico_mcd->word_ram2M + esi) = (pixel << 4) | (eax & 0xf); + } + + +Next_Pixel: + ecx += (DYXS << 16) >> 16; // rot_comp.DXS; + edx += DYXS >> 16; // rot_comp.DYS; + XD++; + if (XD >= 8) + { + Buffer_Adr += ((rot_comp.Reg_5C & 0x1f) + 1) << 5; + XD = 0; + } + H_Dot--; + } + // end while + + +// nothing_to_draw: + rot_comp.YD++; + // rot_comp.V_Dot--; // will be done by caller +} void gfx_cd_update(void) { - unsigned char *V_Dot = (unsigned char *) &rot_comp.Reg_64; + int V_Dot = rot_comp.Reg_64 & 0xff; int jobs; dprintf("gfx_cd_update, Reg_64 = %04x", rot_comp.Reg_64); - if (!*V_Dot) + if (!V_Dot) { - // ... gfx_completed(); return; } @@ -118,18 +306,36 @@ void gfx_cd_update(void) rot_comp.Float_Part &= 0xffff; rot_comp.Float_Part += rot_comp.Draw_Speed; - while (jobs--) + if (PicoOpt & 0x1000) // scale/rot enabled { - // jmp [Jmp_Adr]: - (*V_Dot)--; // dec byte [V_Dot] + unsigned int func = rot_comp.Function; + unsigned int H_Dot = rot_comp.Reg_62 & 0x1ff; + unsigned short *stamp_base = (unsigned short *) (Pico_mcd->word_ram2M + rot_comp.Stamp_Map_Adr); - if (!*V_Dot) + while (jobs--) + { + gfx_do(func, stamp_base, H_Dot); // jmp [Jmp_Adr]: + + V_Dot--; // dec byte [V_Dot] + if (V_Dot == 0) + { + // GFX_Completed: + gfx_completed(); + return; + } + } + } + else + { + if (jobs >= V_Dot) { - // GFX_Completed: gfx_completed(); return; } + V_Dot -= jobs; } + + rot_comp.Reg_64 = V_Dot; } @@ -151,12 +357,12 @@ unsigned int gfx_cd_read(unsigned int a) dprintf("gfx_cd_read(%02x) = %04x", a, d); - return 0; + return d; } -void gfx_cd_write(unsigned int a, unsigned int d) +void gfx_cd_write16(unsigned int a, unsigned int d) { - dprintf("gfx_cd_write(%x, %04x)", a, d); + dprintf("gfx_cd_write16(%x, %04x)", a, d); switch (a) { case 0x58: // .Reg_Stamp_Size @@ -193,7 +399,7 @@ void gfx_cd_write(unsigned int a, unsigned int d) gfx_cd_start(); return; - default: dprintf("gfx_cd_write FIXME: unexpected address: %02x", a); return; + default: dprintf("gfx_cd_write16 FIXME: unexpected address: %02x", a); return; } } @@ -210,7 +416,7 @@ void gfx_cd_reset(void) typedef unsigned short u16; -// check: Heart of the alien +// check: Heart of the alien, jaguar xj 220 void DmaSlowCell(unsigned int source, unsigned int a, int len, unsigned char inc) { unsigned char *base;