diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-11-26 19:55:02 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-11-26 19:55:02 +0100 |
commit | 3d77f3f5ad41e931117425f58c74f49c9503bf7b (patch) | |
tree | 8165c8f10a1b3b3cec27cfb283ee218e7af3a519 /emu/memory.c | |
parent | 394c9fbb6cc243e46b32aa9e7221b0e6cadd4c13 (diff) | |
download | 6502-3d77f3f5ad41e931117425f58c74f49c9503bf7b.tar.gz 6502-3d77f3f5ad41e931117425f58c74f49c9503bf7b.tar.bz2 |
more work on emulator, mainly debug and 7seg stuff
Diffstat (limited to 'emu/memory.c')
-rw-r--r-- | emu/memory.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/emu/memory.c b/emu/memory.c index c9d953b..408e621 100644 --- a/emu/memory.c +++ b/emu/memory.c @@ -2,25 +2,51 @@ #include <stdio.h> -void memory_init( memory_t *memory ) +void memory_init( memory_t *memory, seg7_t *seg ) { memory->read = memory_read; memory->write = memory_write; + memory->seg = seg; } uint8_t memory_read( memory_t *memory, uint16_t addr ) { - return memory->cell[addr]; + if( addr <= 0x3FFF ) { + // RAM access + return memory->cell[addr]; + } else if( addr <= 0x8000 ) { + return seg7_read( memory->seg, addr ); + } else { + // ROM access + return memory->cell[addr]; + } } void memory_write( memory_t *memory, uint16_t addr, uint8_t data ) -{ - memory->cell[addr] = data; +{ + if( addr <= 0x3FFF ) { + // RAM access + memory->cell[addr] = data; + } else if( addr <= 0x8000 ) { + seg7_write( memory->seg, addr, data ); + } else { + // ignore writes to ROM + } } void memory_load( memory_t *memory, uint16_t addr, uint16_t size, const char *filename ) { - FILE *f = fopen( filename, "rb" ); - fread( &memory->cell[addr], size, 1, f ); - fclose( f ); + if( addr >= 0x8000 ) { + FILE *f = fopen( filename, "rb" ); + if( f == NULL ) { + fprintf( stderr, "ERROR: Unable to open ROM file '%s'\n", filename ); + exit( EXIT_FAILURE ); + } + fread( &memory->cell[addr], size, 1, f ); + fclose( f ); + fprintf( stderr, "INFO: Loaded firware from '%s' of size %d starting on address %04X\n", + filename, size, addr ); + } else { + fprintf( stderr, "ERROR: Cannot load firmware into RAM at address %04X\n", addr ); + } } |