From aca930d803177cb6ea8ebadd77b6ef09ab2b5b49 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 28 Nov 2020 11:20:03 +0100 Subject: addressed initializiation of components and valgrindified --- emu/memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'emu/memory.c') 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 #include +#include 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 ); } -- cgit v1.2.3-54-g00ecf