Further steps to implement Shadow Memory

This commit is contained in:
tudnai 2020-04-30 19:33:59 -07:00
parent 1b95e22568
commit fc32252815
3 changed files with 91 additions and 36 deletions

View File

@ -886,14 +886,14 @@ void rom_loadFile( const char * bundlePath, const char * filename ) {
else if ( flen == 16 * KB ) {
read_rom( bundlePath, filename, Apple2_16K_ROM, 0);
// memcpy(Apple2_64K_MEM + 0xC000, Apple2_16K_ROM, 16 * KB);
memcpy(Apple2_64K_MEM + 0xC000, Apple2_16K_ROM, 16 * KB);
// SWITCH_CX_ROM( RAM_PG_RD_TBL, 0xC0, Apple2_16K_ROM, 0x00);
}
else if ( flen == 12 * KB ) {
read_rom( bundlePath, filename, Apple2_16K_ROM, 0x1000);
// memcpy(Apple2_64K_MEM + 0xD000, Apple2_16K_ROM + 0x1000, 12 * KB);
memcpy(Apple2_64K_MEM + 0xD000, Apple2_16K_ROM + 0x1000, 12 * KB);
}
}
@ -944,7 +944,9 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) {
rom_loadFile(bundlePath, romFileName);
// Disk ][ ROM in Slot 6
read_rom( bundlePath, "DISK_II_C600.ROM", Apple2_64K_MEM, 0xC600);
read_rom( bundlePath, "DISK_II_C600.ROM", Apple2_64K_RAM, 0xC600);
memcpy(Apple2_64K_MEM + 0xC600, Apple2_64K_RAM + 0xC600, 0x100);
// read_rom( "/Users/trudnai/Library/Containers/com.gamealloy.A2Mac/Data/", "DISK_II_C600.ROM", Apple2_64K_MEM, 0xC600);
m6502.A = m6502.X = m6502.Y = 0xFF;

View File

@ -20,7 +20,8 @@ INLINE void PUSH( uint8_t src ) {
INLINE uint8_t POP() {
// return RAM[ stack_base_addr | ++m6502.SP ];
return *( RAM_PG_WR_TBL[ stack_base_addr >> 8 ] + ++m6502.SP );
// return *( RAM_PG_RD_TBL[ stack_base_addr >> 8 ] + ++m6502.SP );
return RDLOMEM[ stack_base_addr | ++m6502.SP ];
}

View File

@ -39,7 +39,13 @@ uint8_t Apple2_64K_MEM[ 64 * KB ] = {0}; // Shadow Copy of Memory (or cur
//uint8_t * AUX_VID_RAM = Apple2_VID_AUX; // Pointer to Auxiliary Video Memory
uint8_t * const AUX = Apple2_64K_AUX; // Pointer to the Auxiliary Memory so we can use this from Swift
uint8_t * const RAM = Apple2_64K_RAM; // Pointer to the Main Memory so we can use this from Swift
uint8_t * const MEM = Apple2_64K_MEM; // Pointer to the Shadow Memory so we can use this from Swift
uint8_t * const MEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift
uint8_t * const RDLOMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift
uint8_t * const WRLOMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift
uint8_t * const RDHIMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift
uint8_t * const WRHIMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory Map so we can use this from Swift
#define DEF_RAM_PAGE(mem,pg) \
@ -184,20 +190,20 @@ uint8_t * const MEM = Apple2_64K_MEM; // Pointer to the Shadow Memory
uint8_t * RAM_PG_RD_TBL[256] = {
// 48K main memory
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x00),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x10),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x20),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x30),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x40),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x50),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x60),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x70),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x80),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x90),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xA0),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xB0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x00),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x10),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x20),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x30),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x40),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x50),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x60),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x70),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x80),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x90),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xA0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xB0),
// I/O Addresses
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xC0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xC0),
// Reading from the ROM
DEF_RAM_PAGE16( Apple2_16K_ROM, 0x10), // D0
DEF_RAM_PAGE16( Apple2_16K_ROM, 0x20), // E0
@ -206,22 +212,22 @@ uint8_t * RAM_PG_RD_TBL[256] = {
uint8_t * RAM_PG_WR_TBL[256] = {
// 48K main memory
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x00),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x10),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x20),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x30),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x40),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x50),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x60),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x70),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x80),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0x90),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xA0),
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xB0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x00),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x10),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x20),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x30),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x40),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x50),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x60),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x70),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x80),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0x90),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xA0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xB0),
// I/O Addresses
// DEF_RAM_DUMMY16,
DEF_RAM_PAGE16( Apple2_64K_RAM, 0xC0),
DEF_RAM_PAGE16( Apple2_64K_MEM, 0xC0),
// DEF_RAM_PAGE(Apple2_64K_RAM, 0xC0),
// // SLOT ROM is non-writeable
@ -415,6 +421,7 @@ void resetMemory() {
memset( Apple2_64K_AUX, 0, sizeof(Apple2_64K_AUX) );
// 64K Main Memory Area
memset( Apple2_64K_RAM, 0, sizeof(Apple2_64K_RAM) );
memset( Apple2_64K_MEM, 0, sizeof(Apple2_64K_MEM) );
// I/O area should be 0 -- just in case we decide to init RAM with a different pattern...
memset( Apple2_64K_RAM + 0xC000, 0, 0x1000 );
}
@ -430,6 +437,9 @@ void textPageSelect() {
// save the content of Shadow Memory
memcpy(Apple2_64K_RAM + 0x400, shadow, 0x400);
// load the content of Video Page 2
memcpy(Apple2_64K_MEM + 0x400, Apple2_64K_AUX, 0x400);
SWITCH_VIDEO_RAM( RAM_PG_RD_TBL, 0x04, Apple2_64K_AUX, 0x04)
SWITCH_VIDEO_RAM( RAM_PG_WR_TBL, 0x04, Apple2_64K_AUX, 0x04)
}
@ -439,6 +449,9 @@ void textPageSelect() {
// save the content of Shadow Memory
memcpy(Apple2_64K_AUX + 0x400, shadow, 0x400);
// load the content of Video Page 2
memcpy(Apple2_64K_MEM + 0x400, Apple2_64K_RAM, 0x400);
SWITCH_VIDEO_RAM( RAM_PG_RD_TBL, 0x04, Apple2_64K_RAM, 0x04)
SWITCH_VIDEO_RAM( RAM_PG_WR_TBL, 0x04, Apple2_64K_RAM, 0x04)
}
@ -459,6 +472,9 @@ void auxMemorySelect() {
// save the content of Shadow Memory
memcpy(Apple2_64K_RAM + 0x200, shadow, 0xA00);
// load the content of Aux Memory
memcpy(Apple2_64K_MEM + 0x200, Apple2_64K_AUX, 0xA00);
SWITCH_AUX_MEM( RAM_PG_RD_TBL, Apple2_64K_AUX );
}
else {
@ -467,6 +483,9 @@ void auxMemorySelect() {
// save the content of Shadow Memory
memcpy(Apple2_64K_AUX + 0x200, shadow, 0xA00);
// load the content of Int Memory
memcpy(Apple2_64K_MEM + 0x200, Apple2_64K_RAM, 0xA00);
SWITCH_AUX_MEM( RAM_PG_RD_TBL, Apple2_64K_RAM );
}
@ -623,6 +642,13 @@ INLINE uint8_t ioRead( uint16_t addr ) {
case io_MEM_RDRAM_NOWR_1:
case io_MEM_RDRAM_WRAM_1:
MEMcfg.RD_RAM = 1;
uint8_t * shadow = Apple2_64K_MEM + 0xD000;
// save the content of Shadow Memory
memcpy(Apple2_64K_RAM + 0xD000, shadow, 0x3000);
// load the content of Aux Memory
memcpy(Apple2_64K_MEM + 0xD000, Apple2_64K_AUX, 0x3000);
// set the RAM extension to read on the upper memory area
SWITCH_RAM_PAGE16( RAM_PG_RD_TBL, 0xD0, RAM_BANK, 0x00 );
SWITCH_RAM_PAGE16( RAM_PG_RD_TBL, 0xE0, Apple2_64K_AUX, 0xE0 );
@ -631,6 +657,13 @@ INLINE uint8_t ioRead( uint16_t addr ) {
default:
MEMcfg.RD_RAM = 0;
shadow = Apple2_64K_MEM + 0xD000;
// save the content of Shadow Memory
memcpy(Apple2_64K_AUX + 0xD000, shadow, 0x3000);
// load the content of ROM Memory
memcpy(Apple2_64K_MEM + 0xD000, Apple2_16K_ROM + 0x1000, 0x3000);
// set the ROM to read on the upper memory area
SWITCH_RAM_PAGE16( RAM_PG_RD_TBL, 0xD0, Apple2_16K_ROM, 0x10 );
SWITCH_RAM_PAGE16( RAM_PG_RD_TBL, 0xE0, Apple2_16K_ROM, 0x20 );
@ -882,10 +915,23 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) {
/**
Naive implementation of RAM read from address
**/
INLINE uint8_t memread8( uint16_t addr ) {
INLINE uint8_t memread8_paged( uint16_t addr ) {
return * ( RAM_PG_RD_TBL[addr >> 8] + (addr & 0xFF) );
// return RAM[addr];
}
INLINE uint8_t memread8_low( uint16_t addr ) {
return RDLOMEM[addr];
}
INLINE uint8_t memread8_high( uint16_t addr ) {
return RDHIMEM[addr];
}
INLINE uint8_t memread8( uint16_t addr ) {
if (addr >= 0xC000) {
return memread8_high(addr);
}
return memread8_low(addr);
}
/**
Naive implementation of RAM read from address
**/
@ -895,11 +941,17 @@ INLINE uint16_t memread16( uint16_t addr ) {
}
INLINE uint8_t memread( uint16_t addr ) {
if ( (addr >= 0xC000) && (addr <= 0xC0FF) ) {
return ioRead(addr);
if (addr >= 0xC000) {
if (addr <= 0xC0FF) {
return ioRead(addr);
}
return memread8_high(addr);
}
return memread8(addr);
return memread8_low(addr);
// return memread8(addr);
}
/**