summaryrefslogtreecommitdiff
path: root/emu/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'emu/memory.c')
-rw-r--r--emu/memory.c9
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 );
}