X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsms.c;h=58905bdeb08a863e56ee7cf6ce6c39d602f2c78f;hb=cff531af94bd9c9c89ae162e80f48ddc26a4e504;hp=6cc6f3caa967cd8faac8a58d48980a53fa97e2d2;hpb=460603fa8119a41192ebdc7012d120f6263a2bce;p=picodrive.git diff --git a/pico/sms.c b/pico/sms.c index 6cc6f3c..58905bd 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -1,3 +1,10 @@ +/* + * SMS emulation + * (C) notaz, 2009-2010 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ /* * TODO: * - start in a state as if BIOS ran @@ -9,6 +16,7 @@ * - H counter */ #include "pico_int.h" +#include "memory.h" #include "sound/sn76496.h" static unsigned char vdp_data_read(void) @@ -102,7 +110,7 @@ static unsigned char z80_sms_in(unsigned short a) break; case 0xc1: /* I/O port B and miscellaneous */ - d = (Pico.sms_io_ctl & 0x80) | ((Pico.sms_io_ctl << 1) & 0x40) | 0x30; + d = (Pico.ms.io_ctl & 0x80) | ((Pico.ms.io_ctl << 1) & 0x40) | 0x30; d |= ~(PicoPad[1] >> 2) & 0x0f; break; } @@ -118,7 +126,7 @@ static void z80_sms_out(unsigned short a, unsigned char d) switch (a) { case 0x01: - Pico.sms_io_ctl = d; + Pico.ms.io_ctl = d; break; case 0x40: @@ -155,25 +163,26 @@ static void write_bank(unsigned short a, unsigned char d) 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)); + Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)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)); + Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14)); #endif break; } + Pico.ms.carthw[a & 0x0f] = d; } -static void MEMH_FUNC xwrite(unsigned int a, unsigned char d) +static void xwrite(unsigned int a, unsigned char d) { elprintf(EL_IO, "z80 write [%04x] %02x", a, d); if (a >= 0xc000) Pico.zram[a & 0x1fff] = d; - if (a >= 0xfff0) + if (a >= 0xfff8) write_bank(a, d); } @@ -187,7 +196,7 @@ void PicoPowerMS(void) { int s, tmp; - memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); + memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); Pico.m.pal = 0; @@ -202,6 +211,9 @@ void PicoPowerMS(void) tmp = 1 << s; bank_mask = (tmp - 1) >> 14; + Pico.ms.carthw[0x0e] = 1; + Pico.ms.carthw[0x0f] = 2; + PicoReset(); } @@ -220,14 +232,20 @@ void PicoMemSetupMS(void) drZ80.z80_out = z80_sms_out; #endif #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (UINT32)Pico.rom); - Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (UINT32)Pico.zram); - Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (UINT32)Pico.zram); + Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom); + Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram); + Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram); Cz80_Set_INPort(&CZ80, z80_sms_in); Cz80_Set_OUTPort(&CZ80, z80_sms_out); #endif } +void PicoStateLoadedMS(void) +{ + write_bank(0xfffe, Pico.ms.carthw[0x0e]); + write_bank(0xffff, Pico.ms.carthw[0x0f]); +} + void PicoFrameMS(void) { struct PicoVideo *pv = &Pico.video; @@ -235,6 +253,7 @@ 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; @@ -245,8 +264,10 @@ void PicoFrameMS(void) for (y = 0; y < lines; y++) { pv->v_counter = Pico.m.scanline = y; + if (y > 218) + pv->v_counter = y - 6; - if (y < lines_vis) + if (y < lines_vis && !skip) PicoLineMode4(y); if (y <= lines_vis)