X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=pico%2Fsms.c;h=dfe7769ee40f370036263d3d0ec234018a8902aa;hb=274f95a9a9e5a889ee137a7cbd764a384a7ac2dd;hp=5416845c34d0a2de7b52383d3de50c54dde52816;hpb=2ec9bec58b89831cdead4cdec8f593c5b99d2715;p=picodrive.git diff --git a/pico/sms.c b/pico/sms.c index 5416845..dfe7769 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -1,4 +1,15 @@ +/* + * TODO: + * - start in a state as if BIOS ran + * - remaining status flags (OVR/COL) + * - RAM support in mapper + * - region support + * - Pause button (NMI) + * - SN76496 DAC-like usage + * - H counter + */ #include "pico_int.h" +#include "memory.h" #include "sound/sn76496.h" static unsigned char vdp_data_read(void) @@ -28,11 +39,11 @@ static void vdp_data_write(unsigned char d) if (pv->type == 3) { Pico.cram[pv->addr & 0x1f] = d; + Pico.m.dirtyPal = 1; } else { Pico.vramb[pv->addr] = d; } pv->addr = (pv->addr + 1) & 0x3fff; - elprintf(EL_ANOMALY, " addr=%04x", pv->addr); pv->pending = 0; } @@ -44,7 +55,7 @@ static void vdp_ctl_write(unsigned char d) if (pv->pending) { if ((d >> 6) == 2) { pv->reg[d & 0x0f] = pv->addr; - elprintf(EL_ANOMALY, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff); + elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff); } pv->type = d >> 6; pv->addr &= 0x00ff; @@ -60,7 +71,7 @@ static unsigned char z80_sms_in(unsigned short a) { unsigned char d = 0; - elprintf(EL_ANOMALY, "z80 port %04x read", a); + elprintf(EL_IO, "z80 port %04x read", a); a &= 0xc1; switch (a) { @@ -71,10 +82,12 @@ static unsigned char z80_sms_in(unsigned short a) case 0x40: /* V counter */ d = Pico.video.v_counter; + elprintf(EL_HVCNT, "V counter read: %02x", d); break; case 0x41: /* H counter */ d = Pico.m.rotate++; + elprintf(EL_HVCNT, "H counter read: %02x", d); break; case 0x80: @@ -95,13 +108,13 @@ static unsigned char z80_sms_in(unsigned short a) break; } - elprintf(EL_ANOMALY, "ret = %02x", d); + elprintf(EL_IO, "ret = %02x", d); return d; } static void z80_sms_out(unsigned short a, unsigned char d) { - elprintf(EL_ANOMALY, "z80 port %04x write %02x", a, d); + elprintf(EL_IO, "z80 port %04x write %02x", a, d); a &= 0xc1; switch (a) { @@ -125,24 +138,29 @@ static void z80_sms_out(unsigned short a, unsigned char d) } } +static int bank_mask; + static void write_bank(unsigned short a, unsigned char d) { - d &= 0x3f; // XXX + elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc()); switch (a & 0x0f) { case 0x0c: + elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d); break; case 0x0d: if (d != 0) elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d); break; case 0x0e: + d &= bank_mask; z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0); #ifdef _USE_CZ80 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (UINT32)Pico.rom + (d << 14)); #endif break; case 0x0f: + d &= bank_mask; z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0); #ifdef _USE_CZ80 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (UINT32)Pico.rom + (d << 14)); @@ -151,15 +169,9 @@ static void write_bank(unsigned short a, unsigned char d) } } -static unsigned char MEMH_FUNC xread(unsigned short a) -{ - elprintf(EL_ANOMALY, "z80 read [%04x]", a); - return Pico.zram[a & 0x1fff]; -} - static void MEMH_FUNC xwrite(unsigned int a, unsigned char d) { - elprintf(EL_ANOMALY, "z80 write [%04x] %02x", a, d); + elprintf(EL_IO, "z80 write [%04x] %02x", a, d); if (a >= 0xc000) Pico.zram[a & 0x1fff] = d; if (a >= 0xfff0) @@ -174,11 +186,23 @@ void PicoResetMS(void) void PicoPowerMS(void) { + int s, tmp; + memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); Pico.m.pal = 0; + // calculate a mask for bank writes. + // ROM loader has aligned the size for us, so this is safe. + s = 0; tmp = Pico.romsize; + while ((tmp >>= 1) != 0) + s++; + if (Pico.romsize > (1 << s)) + s++; + tmp = 1 << s; + bank_mask = (tmp - 1) >> 14; + PicoReset(); } @@ -186,7 +210,7 @@ void PicoMemSetupMS(void) { z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0); z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0); - z80_map_set(z80_read_map, 0xe000, 0xffff, xread, 1); + z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0); z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1); z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0); @@ -212,16 +236,36 @@ void PicoFrameMS(void) int lines = is_pal ? 313 : 262; int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */ int cycles_done = 0, cycles_aim = 0; + int skip = PicoSkipFrame; int lines_vis = 192; + int hint; // Hint counter int y; + PicoFrameStartMode4(); + hint = pv->reg[0x0a]; + for (y = 0; y < lines; y++) { pv->v_counter = Pico.m.scanline = y; - if (y == lines_vis + 1) { - Pico.video.pending_ints |= 1; - if (Pico.video.reg[1] & 0x20) { + if (y < lines_vis && !skip) + PicoLineMode4(y); + + if (y <= lines_vis) + { + if (--hint < 0) + { + hint = pv->reg[0x0a]; + pv->pending_ints |= 2; + if (pv->reg[0] & 0x10) { + elprintf(EL_INTS, "hint"); + z80_int(); + } + } + } + else if (y == lines_vis + 1) { + pv->pending_ints |= 1; + if (pv->reg[1] & 0x20) { elprintf(EL_INTS, "vint"); z80_int(); } @@ -231,7 +275,18 @@ void PicoFrameMS(void) cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8; } - PsndGetSamplesMS(); - elprintf(EL_ANOMALY, "frame end"); + if (PsndOut) + PsndGetSamplesMS(); +} + +void PicoFrameDrawOnlyMS(void) +{ + int lines_vis = 192; + int y; + + PicoFrameStartMode4(); + + for (y = 0; y < lines_vis; y++) + PicoLineMode4(y); }