sms, autodetection for sg-1000 ram extension

This commit is contained in:
kub 2022-02-27 09:40:04 +00:00
parent 171fb8cc14
commit 3611781e65
4 changed files with 40 additions and 26 deletions

View file

@ -57,7 +57,7 @@ static void vdp_data_write(unsigned char d)
if (pv->type == 3) {
// cram. 32 on SMS, but 64 on MD. Fill 2nd half of cram for prio bit mirror
if (Pico.m.hardware & 0x1) { // GG, same layout as MD
if (Pico.m.hardware & PMS_HW_GG) { // GG, same layout as MD
unsigned a = pv->addr & 0x3f;
if (a & 0x1) { // write complete color on high byte write
u16 c = ((d&0x0f) << 8) | Pico.ms.vdp_buffer;
@ -160,7 +160,7 @@ static unsigned char z80_sms_in(unsigned short a)
{
case 0x00:
case 0x01:
if ((Pico.m.hardware & 0x1) && a < 0x8) { // GG I/O area
if ((Pico.m.hardware & PMS_HW_GG) && a < 0x8) { // GG I/O area
switch (a) {
case 0: d = 0xff & ~(PicoIn.pad[0] & 0x80); break;
case 1: d = Pico.ms.io_gg[1] | (Pico.ms.io_gg[2] & 0x7f); break;
@ -232,11 +232,11 @@ static void z80_sms_out(unsigned short a, unsigned char d)
switch (a & 0xc1)
{
case 0x00:
if ((Pico.m.hardware & 0x1) && a < 0x8) // GG I/O area
if ((Pico.m.hardware & PMS_HW_GG) && a < 0x8) // GG I/O area
Pico.ms.io_gg[a] = d;
break;
case 0x01:
if ((Pico.m.hardware & 0x1) && a < 0x8) { // GG I/O area
if ((Pico.m.hardware & PMS_HW_GG) && a < 0x8) { // GG I/O area
Pico.ms.io_gg[a] = d;
} else {
// pad. latch hcounter if one of the TH lines is switched to 1
@ -454,13 +454,15 @@ static void write_bank_jang(unsigned short a, unsigned char d)
}
}
// SG-1000 8KB RAM Adaptor mapper. 8KB RAM at address 0x2000
static void write_bank_x8k(unsigned short a, unsigned char d)
{
// 8KB address range @ 0x2000
if ((a&0xe000) != 0x2000) return;
// never autodetected, selectable only via config
if (Pico.ms.mapper != PMS_MAP_8KBRAM) return;
// this is only available on SG-1000
if (Pico.ms.mapper != PMS_MAP_8KBRAM && (Pico.ms.mapper || !(Pico.m.hardware & PMS_HW_SG))) return;
elprintf(EL_Z80BNK, "bank x8k %04x %02x @ %04x", a, d, z80_pc());
Pico.ms.mapper = PMS_MAP_8KBRAM;
((unsigned char *)PicoMem.vram)[a+0x6000] = d;
z80_map_set(z80_read_map, 0x2000, 0x3fff, PicoMem.vram+0x4000, 0);
@ -488,6 +490,7 @@ static void xwrite(unsigned int a, unsigned char d)
case PMS_MAP_AUTO:
// NB the sequence of mappers is crucial for the auto detection
write_bank_x8k(a, d);
write_bank_n32k(a, d);
write_bank_sega(a, d);
write_bank_msx(a, d);
@ -517,27 +520,29 @@ void PicoResetMS(void)
// set preselected hw/mapper from config
if (PicoIn.hwSelect) {
switch (PicoIn.hwSelect) {
case PHWS_GG: Pico.m.hardware |= 0x1; break;
default: Pico.m.hardware &= ~0x1; break;
case PHWS_GG: Pico.m.hardware |= PMS_HW_GG; break;
default: Pico.m.hardware &= ~PMS_HW_GG; break;
}
}
if (PicoIn.mapper)
Pico.ms.mapper = PicoIn.mapper;
Pico.m.hardware |= 0x4; // default region Japan if no TMR header
Pico.m.hardware |= PMS_HW_JAP; // default region Japan if no TMR header
Pico.m.hardware |= PMS_HW_SG; // default to SG-1000 if no TMR header
// check if the ROM header contains more system information
for (tmr = 0x2000; tmr < 0xbfff && tmr <= Pico.romsize; tmr *= 2) {
if (!memcmp(Pico.rom + tmr-16, "TMR SEGA", 8)) {
Pico.m.hardware &= ~PMS_HW_SG; // not SG-1000
hw = Pico.rom[tmr-1] >> 4;
if (!PicoIn.hwSelect) {
Pico.m.hardware &= ~0x1;
Pico.m.hardware &= ~PMS_HW_GG;
if (hw >= 0x5 && hw < 0x8)
Pico.m.hardware |= 0x1; // GG cartridge detected
Pico.m.hardware |= PMS_HW_GG; // GG cartridge detected
}
if (!PicoIn.regionOverride) {
Pico.m.hardware &= ~0x4;
Pico.m.hardware &= ~PMS_HW_JAP;
if (hw == 0x5 || hw == 0x3)
Pico.m.hardware |= 0x4; // region Japan
Pico.m.hardware |= PMS_HW_JAP; // region Japan
}
id = CPU_LE4(*(u32 *)&Pico.rom[tmr-4]) & 0xf0f0ffff;
for (i = 0; i < sizeof(region_pal)/sizeof(*region_pal); i++)
@ -571,7 +576,8 @@ void PicoResetMS(void)
Pico.video.reg[10] = 0xff;
// BIOS, clear zram (unitialized on Mark-III, cf src/mame/drivers/sms.cpp)
memset(PicoMem.zram, (Pico.m.hardware&5) == 4 ? 0xf0:0, sizeof(PicoMem.zram));
i = (Pico.m.hardware & (PMS_HW_JAP|PMS_HW_GG)) == PMS_HW_JAP ? 0xf0 : 0x00;
memset(PicoMem.zram, i, sizeof(PicoMem.zram));
}
void PicoPowerMS(void)
@ -698,7 +704,7 @@ void PicoFrameMS(void)
// for SMS the pause button generates an NMI, for GG ths is not the case
nmi = (PicoIn.pad[0] >> 7) & 1;
if (!(Pico.m.hardware & 0x1) && !Pico.ms.nmi_state && nmi)
if (!(Pico.m.hardware & PMS_HW_GG) && !Pico.ms.nmi_state && nmi)
z80_nmi();
Pico.ms.nmi_state = nmi;