buggy port of gfx/cd, silpheed started working?

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@73 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-03-21 22:59:44 +00:00
parent 48e8482fc2
commit a403080104
9 changed files with 310 additions and 32 deletions

View file

@ -52,6 +52,8 @@ int PicoAreaPackCpu(unsigned char *cpu, int is_sub)
*(unsigned char *)(cpu+0x44)=(unsigned char)M68000_regs.ccr;
*(unsigned char *)(cpu+0x45)=(unsigned char)M68000_regs.srh;
*(unsigned int *)(cpu+0x48)=M68000_regs.isp;
cpu[0x4c] = M68000_regs.irq;
// stop flag?
#endif
#ifdef EMU_C68K
@ -60,6 +62,8 @@ int PicoAreaPackCpu(unsigned char *cpu, int is_sub)
pc=context->pc-context->membase;
*(unsigned int *)(cpu+0x44)=CycloneGetSr(context);
*(unsigned int *)(cpu+0x48)=context->osp;
cpu[0x4c] = context->irq;
cpu[0x4d] = context->stopped;
#endif
#ifdef EMU_M68K
@ -69,6 +73,8 @@ int PicoAreaPackCpu(unsigned char *cpu, int is_sub)
pc=m68ki_cpu_p->pc;
*(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR);
*(unsigned int *)(cpu+0x48)=m68ki_cpu_p->sp[0];
cpu[0x4c] = CPU_INT_LEVEL>>8;
cpu[0x4d] = CPU_STOPPED;
m68k_set_context(oldcontext);
#endif
@ -84,6 +90,8 @@ int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub)
M68000_regs.ccr=*(unsigned char *)(cpu+0x44);
M68000_regs.srh=*(unsigned char *)(cpu+0x45);
M68000_regs.isp=*(unsigned int *)(cpu+0x48);
M68000_regs.irq = cpu[0x4c];
// stop flag?
#endif
#ifdef EMU_C68K
@ -93,6 +101,8 @@ int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub)
memcpy(context->d,cpu,0x40);
context->membase=0;
context->pc = context->checkpc(*(unsigned int *)(cpu+0x40)); // Base pc
context->irq = cpu[0x4c];
context->stopped = cpu[0x4d];
#endif
#ifdef EMU_M68K
@ -102,6 +112,8 @@ int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub)
m68ki_cpu_p->pc=*(unsigned int *)(cpu+0x40);
m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44));
m68ki_cpu_p->sp[0]=*(unsigned int *)(cpu+0x48);
CPU_INT_LEVEL = cpu[0x4c] << 8;
CPU_STOPPED = cpu[0x4d];
m68k_set_context(oldcontext);
#endif
return 0;

View file

@ -991,6 +991,7 @@ static u32 PicoReadS68k32(u32 a)
#endif
#ifndef _ASM_CD_MEMORY_C
/* check: jaguar xj 220 (draws entire world using decode) */
static void decode_write8(u32 a, u8 d, int r3)
{
@ -1043,7 +1044,7 @@ static void decode_write16(u32 a, u16 d, int r3)
//dprintf("FIXME: decode");
}
#endif
// -----------------------------------------------------------------

View file

@ -31,12 +31,12 @@ void PicoExitMCD(void)
int PicoResetMCD(int hard)
{
if (hard) {
int fmt_size = sizeof(formatted_bram);
memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M));
memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size);
int fmt_size = sizeof(formatted_bram);
memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M));
memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size);
}
memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs));
memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm));
@ -90,7 +90,9 @@ static __inline void SekRunS68k(int cyc)
#define PS_STEP_M68K ((488<<16)/20) // ~24
//#define PS_STEP_S68K 13
#ifndef _ASM_CD_PICO_C
#ifdef _ASM_CD_PICO_C
void SekRunPS(int cyc_m68k, int cyc_s68k);
#else
static __inline void SekRunPS(int cyc_m68k, int cyc_s68k)
{
int cycn, cycn_s68k, cyc_do;
@ -133,8 +135,6 @@ static __inline void SekRunPS(int cyc_m68k, int cyc_s68k)
//fprintf(stderr, "== end %3i/%3i ==\n", d_cm, d_cs);
}
#else
void SekRunPS(int cyc_m68k, int cyc_s68k);
#endif

View file

@ -44,14 +44,14 @@ typedef struct
unsigned int Stamp_Map_Adr;
unsigned int Buffer_Adr;
unsigned int Vector_Adr;
unsigned int Jmp_Adr;
unsigned int Function; // Jmp_Adr;
unsigned int Float_Part;
unsigned int Draw_Speed;
unsigned int XS;
unsigned int YS;
unsigned int DXS;
unsigned int DYS;
/*unsigned*/ int DXS;
/*unsigned*/ int DYS;
unsigned int XD;
unsigned int YD;
unsigned int XD_Mul;
@ -65,13 +65,34 @@ static void gfx_cd_start(void)
dprintf("gfx_cd_start()");
rot_comp.XD_Mul = ((rot_comp.Reg_5C & 0x1f) + 1) * 4;
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;
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;
}
gfx_cd_update();
}
@ -88,9 +109,249 @@ static void gfx_completed(void)
}
//static void gfx_do(void)
//{
//}
static void gfx_do(void)
{
unsigned int eax, ebx, ecx, edx, esi, edi, pixel = 0;
unsigned int func = rot_comp.Function;
unsigned short *ptrs;
rot_comp.XD = rot_comp.Reg_60 & 7;
rot_comp.Buffer_Adr = ((rot_comp.Reg_5E & 0xfff8) + rot_comp.YD) << 2;
rot_comp.H_Dot = rot_comp.Reg_62 & 0x1ff;
ecx = *(unsigned int *)(Pico_mcd->word_ram2M + rot_comp.Vector_Adr);
edx = ecx >> 16;
ecx = (ecx & 0xffff) << 8;
edx <<= 8;
rot_comp.DXS = *(int *)(Pico_mcd->word_ram2M + rot_comp.Vector_Adr + 4);
rot_comp.DYS = rot_comp.DXS >> 16;
rot_comp.DXS = (rot_comp.DXS << 16) >> 16; // sign extend
rot_comp.Vector_Adr += 8;
//if ((rot_comp.H_Dot & 0x1ff) == 0)
// goto nothing_to_draw;
// MAKE_IMAGE_LINE
while (rot_comp.H_Dot)
{
if (func & 2) // mode 32x32 dot
{
if (func & 4) // 16x16 screen
{
eax = (ecx >> (11+5)) & 0x7f;
ebx = (edx >> (11-2)) & 0x3f80;
}
else // 1x1 screen
{
eax = (ecx >> (11+5)) & 0x0f;
ebx = (edx >> (11+2)) & 0x38;
}
}
else // mode 16x16 dot
{
if (func & 4) // 16x16 screen
{
eax = (ecx >> (11+4)) & 0xff;
ebx = (edx >> (11-4)) & 0xff00;
}
else // 1x1 screen
{
eax = (ecx >> (11+4)) & 0x0f;
ebx = (edx >> (11+0)) & 0xf0;
}
}
ebx += eax;
esi = rot_comp.Stamp_Map_Adr;
ptrs = (unsigned short *) (Pico_mcd->word_ram2M + rot_comp.Stamp_Map_Adr + ebx*2);
edi = ptrs[0] | (ptrs[1] << 16);
// MAKE_IMAGE_PIXEL
if (!(func & 1)) // NOT TILED
{
if (func & 4) // 16x16 screen
{
if ((edx & 0x00800000) || (ecx & 0x00800000)) goto Pixel_Out;
}
else // 1x1 screen
{
if ((edx & 0x00f80000) || (ecx & 0x00f80000)) goto Pixel_Out;
}
}
esi = edi;
edi >>= (11+1);
esi = (esi & 0x7ff) << 7;
if (!esi) goto Pixel_Out;
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;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x01: // No_Flip_0, 32x32 dots
ebx = (ebx >> 9) & 0x7c;
ebx += esi;
edi = (eax & 0x3800) ^ 0x1000; // bswap
eax = ((eax >> 7) & 0x180) + ebx;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x02: // No_Flip_90, 16x16 dots
eax = (eax >> 9) & 0x3c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x2800; // bswap
eax += ((ebx >> 8) & 0x40) ^ 0x40;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x03: // No_Flip_90, 32x32 dots
eax = (eax >> 9) & 0x7c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x2800; // bswap
eax += (ebx >> 7) & 0x180;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
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;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
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;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x06: // No_Flip_270, 16x16 dots
eax = ((eax >> 9) & 0x3c) ^ 0x3c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x1000; // bswap
eax += (ebx >> 8) & 0x40;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x07: // No_Flip_270, 32x32 dots
eax = ((eax >> 9) & 0x7c) ^ 0x7c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x1000; // bswap
eax += (ebx >> 7) & 0x180;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x08: // Flip_0, 16x16 dots
ebx = ((ebx >> 9) & 0x3c) ^ 0x3c;
ebx += esi;
edi = (eax & 0x3800) ^ 0x2800; // bswap, flip
eax = (((eax >> 8) & 0x40) ^ 0x40) + ebx;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x09: // Flip_0, 32x32 dots
ebx = ((ebx >> 9) & 0x7c) ^ 0x7c;
ebx += esi;
edi = (eax & 0x3800) ^ 0x2800; // bswap, flip
eax = (((eax >> 7) & 0x180) ^ 0x180) + ebx;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
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;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
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;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x0c: // Flip_180, 16x16 dots
ebx = ((ebx >> 9) & 0x3c) ^ 0x3c;
ebx += esi;
edi = (eax & 0x3800) ^ 0x1000; // bswap
eax = ((eax >> 8) & 0x40) + ebx;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x0d: // Flip_180, 32x32 dots
ebx = ((ebx >> 9) & 0x7c) ^ 0x7c;
ebx += esi;
edi = (eax & 0x3800) ^ 0x1000; // bswap
eax = ((eax >> 7) & 0x180) + ebx;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x0e: // Flip_270, 16x16 dots
eax = (eax >> 9) & 0x3c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x1000; // bswap, flip
eax += (ebx >> 8) & 0x40;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
case 0x0f: // Flip_270, 32x32 dots
eax = (eax >> 9) & 0x7c;
eax += esi;
edi = (ebx & 0x3800) ^ 0x1000; // bswap, flip
eax += (ebx >> 7) & 0x180;
pixel = *(Pico_mcd->word_ram2M + (edi >> 12) + eax);
if (!(edi & 0x800)) pixel >>= 4;
break;
}
Pixel_Out:
// pixel = 0;
//Finish:
pixel &= 0x0f;
if (!pixel && (func & 0x18)) goto Next_Pixel;
esi = rot_comp.Buffer_Adr + ((rot_comp.XD>>1)^1); // pixel addr
eax = *(Pico_mcd->word_ram2M + esi); // old pixel
if (rot_comp.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 += rot_comp.DXS;
edx += rot_comp.DYS;
rot_comp.XD++;
if (rot_comp.XD >= 8)
{
rot_comp.Buffer_Adr += ((rot_comp.Reg_5C & 0x1f) + 1) << 5;
rot_comp.XD = 0;
}
rot_comp.H_Dot--;
}
//nothing_to_draw:
rot_comp.YD++;
// rot_comp.V_Dot--; // will be done by caller
}
void gfx_cd_update(void)
@ -102,7 +363,6 @@ void gfx_cd_update(void)
if (!*V_Dot)
{
// ...
gfx_completed();
return;
}
@ -120,8 +380,10 @@ void gfx_cd_update(void)
while (jobs--)
{
// jmp [Jmp_Adr]:
(*V_Dot)--; // dec byte [V_Dot]
if (PicoOpt & 0x1000)
gfx_do(); // jmp [Jmp_Adr]:
(*V_Dot)--; // dec byte [V_Dot]
if (!*V_Dot)
{

View file

@ -4,19 +4,19 @@
typedef struct
{
unsigned int Reg_58; // Stamp_Size
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_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 Function; // Jmp_Adr;
unsigned int Float_Part;
unsigned int Draw_Speed;

View file

@ -744,8 +744,9 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3
gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4
gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5
gp2x_text_out8(tl_x, (y+=10), "Better sync (slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6
gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer %s", ra_buff); // 7
gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer %s", ra_buff); // 6
gp2x_text_out8(tl_x, (y+=10), "Scale/Rot. fx (buggy,slow) %s", (currentConfig.PicoOpt&0x1000)?"ON":"OFF"); // 7
gp2x_text_out8(tl_x, (y+=10), "Better sync (slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 8
gp2x_text_out8(tl_x, (y+=10), "Done");
// draw cursor
@ -761,7 +762,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
static void cd_menu_loop_options(void)
{
int menu_sel = 0, menu_sel_max = 8;
int menu_sel = 0, menu_sel_max = 9;
unsigned long inp = 0;
char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;
@ -791,8 +792,7 @@ static void cd_menu_loop_options(void)
case 3: currentConfig.EmuOpt ^=0x0400; break;
case 4: currentConfig.PicoOpt^=0x0800; break;
case 5: currentConfig.PicoOpt^=0x0400; break;
case 6: currentConfig.PicoOpt^=0x2000; break;
case 7:
case 6:
if (inp & GP2X_LEFT) {
PicoCDBuffers >>= 1;
if (PicoCDBuffers < 64) PicoCDBuffers = 0;
@ -802,7 +802,9 @@ static void cd_menu_loop_options(void)
if (PicoCDBuffers > 4096) PicoCDBuffers = 4096;
}
break;
case 8: return;
case 7: currentConfig.PicoOpt^=0x1000; break;
case 8: currentConfig.PicoOpt^=0x2000; break;
case 9: return;
}
}
if(inp & (GP2X_X|GP2X_A)) return;

View file

@ -66,7 +66,7 @@ tidy:
PicoDrive : $(OBJS)
@echo $@
@$(GCC) $(COPT) $(OBJS) ../gp2x/helix/helix_mp3_x86.a $(LDFLAGS) -lm -o $@
@$(GCC) $(COPT) $(OBJS) ../gp2x/helix/helix_mp3_x86.a $(LDFLAGS) -lm -Wl,-Map=PicoDrive.map -o $@
../../cpu/mz80/mz80.o : ../../cpu/mz80/mz80.asm

View file

@ -12,8 +12,8 @@
// pico.c
#define CAN_HANDLE_240_LINES 1
#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
//#define dprintf(x...)
//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
#define dprintf(x...)
#endif //PORT_CONFIG_H

View file

@ -221,6 +221,7 @@ Changelog
* Fixed a bug related to game specific config saving.
* Frameskipper was skipping sound processing, what caused some audio desyncs. Fixed.
* Fixed reset not working for some games.
+ New assembly optimized memory handlers for CD (gives at least a few fps).
1.201
+ Added basic cheat support (GameGenie and Genecyst patches).