56420c3a12
Includes:
- Partial Expansion Module (XM) support
- XRAM
- XPokey (limited to single Pokey)
- Added support for cartridges with sizes greater than 144k
- Additional bank switching modes and cartridge types
- Multiple bank switching fixes
- Reworked cartridge header detection
- Now properly detects bank switching, RAM, etc.
- Detects Expansion Module (XM)
- Detects High score cartridge
- Detects Pokey at $0450
- Cartridge database
- Added several new cartridge properties
- Pokey at $0450
- Default difficulty switch settings
- Expansion Module (XM) enabled/disabled
- High score cartridge enabled/disabled
- Database content
- Fixed incorrect controller settings for Sirius, Crossbow,
and Alien Brigade
- Added many homebrew cartridges
- Fixed issue occurring when Kangaroo and Holey were enabled (caused
background to be displayed, resulting in large black squares)
Missing:
- High Score Cartridge support
217 lines
6.8 KiB
C++
Executable File
217 lines
6.8 KiB
C++
Executable File
// ----------------------------------------------------------------------------
|
|
// ___ ___ ___ ___ ___ ____ ___ _ _
|
|
// /__/ /__/ / / /__ /__/ /__ / /_ / |/ /
|
|
// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// Copyright 2005 Greg Stanton
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
// ----------------------------------------------------------------------------
|
|
// Memory.cpp
|
|
// ----------------------------------------------------------------------------
|
|
#include "Memory.h"
|
|
#include "ExpansionModule.h"
|
|
|
|
byte memory_ram[MEMORY_SIZE] = {0};
|
|
byte memory_rom[MEMORY_SIZE] = {0};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Reset
|
|
// ----------------------------------------------------------------------------
|
|
void memory_Reset( ) {
|
|
uint index;
|
|
for(index = 0; index < MEMORY_SIZE; index++) {
|
|
memory_ram[index] = 0;
|
|
memory_rom[index] = 1;
|
|
}
|
|
for(index = 0; index < 16384; index++) {
|
|
memory_rom[index] = 0;
|
|
}
|
|
}
|
|
// ----------------------------------------------------------------------------
|
|
// Read
|
|
// ----------------------------------------------------------------------------
|
|
byte memory_Read(word address) {
|
|
byte tmp_byte;
|
|
|
|
if (cartridge_xm) {
|
|
if ((address >= 0x0470 && address < 0x0480) ||
|
|
(xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) ||
|
|
(xm_mem_enabled && (address >= 0x4000 && address < 0x8000))) {
|
|
return xm_Read(address);
|
|
}
|
|
}
|
|
|
|
if (cartridge_pokey && (
|
|
(!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) ||
|
|
(cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) {
|
|
return pokey_GetRegister(
|
|
cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address);
|
|
}
|
|
|
|
switch ( address ) {
|
|
case INTIM:
|
|
case INTIM | 0x2:
|
|
memory_ram[INTFLG] &= 0x7f;
|
|
return memory_ram[INTIM];
|
|
break;
|
|
case INTFLG:
|
|
case INTFLG | 0x2:
|
|
tmp_byte = memory_ram[INTFLG];
|
|
memory_ram[INTFLG] &= 0x7f;
|
|
return tmp_byte;
|
|
break;
|
|
default:
|
|
return memory_ram[address];
|
|
break;
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Write
|
|
// ----------------------------------------------------------------------------
|
|
void memory_Write(word address, byte data) {
|
|
if (cartridge_xm &&
|
|
((address >= 0x0470 && address < 0x0480) ||
|
|
((xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) ||
|
|
(xm_mem_enabled && (address >= 0x4000 && address < 0x8000))))) {
|
|
xm_Write(address, data);
|
|
return;
|
|
}
|
|
|
|
if (cartridge_pokey && (
|
|
(!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) ||
|
|
(cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) {
|
|
pokey_SetRegister(
|
|
(cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address), data);
|
|
return;
|
|
}
|
|
|
|
if(!memory_rom[address]) {
|
|
switch(address) {
|
|
case WSYNC:
|
|
if(!(cartridge_flags & 128)) {
|
|
memory_ram[WSYNC] = true;
|
|
}
|
|
break;
|
|
case INPTCTRL:
|
|
if(data == 22 && cartridge_IsLoaded( )) {
|
|
cartridge_Store( );
|
|
}
|
|
else if(data == 2 && bios_enabled) {
|
|
bios_Store( );
|
|
}
|
|
break;
|
|
case INPT0:
|
|
break;
|
|
case INPT1:
|
|
break;
|
|
case INPT2:
|
|
break;
|
|
case INPT3:
|
|
break;
|
|
case INPT4:
|
|
break;
|
|
case INPT5:
|
|
break;
|
|
case AUDC0:
|
|
tia_SetRegister(AUDC0, data);
|
|
break;
|
|
case AUDC1:
|
|
tia_SetRegister(AUDC1, data);
|
|
break;
|
|
case AUDF0:
|
|
tia_SetRegister(AUDF0, data);
|
|
break;
|
|
case AUDF1:
|
|
tia_SetRegister(AUDF1, data);
|
|
break;
|
|
case AUDV0:
|
|
tia_SetRegister(AUDV0, data);
|
|
break;
|
|
case AUDV1:
|
|
tia_SetRegister(AUDV1, data);
|
|
break;
|
|
case SWCHA: /*gdement: Writing here actually writes to DRA inside the RIOT chip.
|
|
This value only indirectly affects output of SWCHA. Ditto for SWCHB.*/
|
|
riot_SetDRA(data);
|
|
break;
|
|
case SWCHB:
|
|
riot_SetDRB(data);
|
|
break;
|
|
case TIM1T:
|
|
case TIM1T | 0x8:
|
|
riot_SetTimer(TIM1T, data);
|
|
break;
|
|
case TIM8T:
|
|
case TIM8T | 0x8:
|
|
riot_SetTimer(TIM8T, data);
|
|
break;
|
|
case TIM64T:
|
|
case TIM64T | 0x8:
|
|
riot_SetTimer(TIM64T, data);
|
|
break;
|
|
case T1024T:
|
|
case T1024T | 0x8:
|
|
riot_SetTimer(T1024T, data);
|
|
break;
|
|
default:
|
|
memory_ram[address] = data;
|
|
if(address >= 8256 && address <= 8447) {
|
|
memory_ram[address - 8192] = data;
|
|
}
|
|
else if(address >= 8512 && address <= 8702) {
|
|
memory_ram[address - 8192] = data;
|
|
}
|
|
else if(address >= 64 && address <= 255) {
|
|
memory_ram[address + 8192] = data;
|
|
}
|
|
else if(address >= 320 && address <= 511) {
|
|
memory_ram[address + 8192] = data;
|
|
}
|
|
break;
|
|
/*TODO: gdement: test here for debug port. Don't put it in the switch because that will change behavior.*/
|
|
}
|
|
}
|
|
else {
|
|
cartridge_Write(address, data);
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// WriteROM
|
|
// ----------------------------------------------------------------------------
|
|
void memory_WriteROM(word address, uint size, const byte* data) {
|
|
if((address + size) <= MEMORY_SIZE && data != NULL) {
|
|
for(uint index = 0; index < size; index++) {
|
|
memory_ram[address + index] = data[index];
|
|
memory_rom[address + index] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ClearROM
|
|
// ----------------------------------------------------------------------------
|
|
void memory_ClearROM(word address, uint size) {
|
|
if((address + size) <= MEMORY_SIZE) {
|
|
for(uint index = 0; index < size; index++) {
|
|
memory_ram[address + index] = 0;
|
|
memory_rom[address + index] = 0;
|
|
}
|
|
}
|
|
}
|