diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-11-28 11:20:03 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-11-28 11:20:03 +0100 |
commit | aca930d803177cb6ea8ebadd77b6ef09ab2b5b49 (patch) | |
tree | e35da8c68588a28534ae51c47025214fe5450e17 /emu/memory.c | |
parent | f829f6893d94ed52044bf007bc447526c9d5e653 (diff) | |
download | 6502-aca930d803177cb6ea8ebadd77b6ef09ab2b5b49.tar.gz 6502-aca930d803177cb6ea8ebadd77b6ef09ab2b5b49.tar.bz2 |
addressed initializiation of components and valgrindified
Diffstat (limited to 'emu/memory.c')
-rw-r--r-- | emu/memory.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/emu/memory.c b/emu/memory.c index 52332e3..c3f49a4 100644 --- a/emu/memory.c +++ b/emu/memory.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> static device_vtable_t const memory_vtable = { memory_read, @@ -9,7 +10,7 @@ static device_vtable_t const memory_vtable = { memory_deinit }; -void memory_init( memory_t *memory, memory_type_t type, uint16_t addr, uint16_t size ) +void memory_init( memory_t *memory, memory_type_t type, uint16_t addr, uint16_t size, bool initialize ) { device_init( &memory->base, ( type == MEMORY_ROM ) ? "ROM" : "RAM" ); @@ -17,6 +18,10 @@ void memory_init( memory_t *memory, memory_type_t type, uint16_t addr, uint16_t memory->addr = addr; memory->size = size; memory->cell = malloc( memory->size ); + if( initialize ) { + memset( memory->cell, 0, memory->size ); + } + memory->base.vtable = (device_vtable_t *)&memory_vtable; } @@ -58,6 +63,8 @@ void memory_write( void *obj, uint16_t addr, uint8_t data ) void memory_deinit( void *obj ) { memory_t *memory = (memory_t *)obj; + + free( memory->cell ); device_deinit( &memory->base ); } |