changeset 1204:d7be5b6e0a8d

Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
author Michael Pavone <pavone@retrodev.com>
date Thu, 26 Jan 2017 20:07:17 -0800
parents 4cbb6efb9120
children 3d3bad51183d
files default.cfg genesis.c
diffstat 2 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/default.cfg	Thu Jan 26 09:08:23 2017 -0800
+++ b/default.cfg	Thu Jan 26 20:07:17 2017 -0800
@@ -169,5 +169,9 @@
 	rom menu.bin
 }
 
-default_region U
+system {
+	ram_init zero
+	default_region U
+}
 
+
--- a/genesis.c	Thu Jan 26 09:08:23 2017 -0800
+++ b/genesis.c	Thu Jan 26 20:07:17 2017 -0800
@@ -7,6 +7,7 @@
 #include "blastem.h"
 #include <stdlib.h>
 #include <ctype.h>
+#include <time.h>
 #include "render.h"
 #include "gst.h"
 #include "util.h"
@@ -766,8 +767,8 @@
 void set_region(genesis_context *gen, rom_info *info, uint8_t region)
 {
 	if (!region) {
-		char * def_region = tern_find_ptr(config, "default_region");
-		if (def_region && (!info->regions || (info->regions & translate_region_char(toupper(*def_region))))) {
+		char * def_region = tern_find_path_default(config, "system\0default_region\0", (tern_val){.ptrval = "U"}).ptrval;
+		if (!info->regions || (info->regions & translate_region_char(toupper(*def_region)))) {
 			region = translate_region_char(toupper(*def_region));
 		} else {
 			region = info->regions;
@@ -953,6 +954,30 @@
 	gen->cart = main_rom;
 	gen->lock_on = lock_on;
 	gen->work_ram = calloc(2, RAM_WORDS);
+	if (!strcmp("random", tern_find_path_default(config, "system\0ram_init\0", (tern_val){.ptrval = "zero"}).ptrval))
+	{
+		srand(time(NULL));
+		for (int i = 0; i < RAM_WORDS; i++)
+		{
+			gen->work_ram[i] = rand();
+		}
+		for (int i = 0; i < Z80_RAM_BYTES; i++)
+		{
+			gen->zram[i] = rand();
+		}
+		for (int i = 0; i < VRAM_SIZE; i++)
+		{
+			write_vram_byte(gen->vdp, i, rand());
+		}
+		for (int i = 0; i < CRAM_SIZE; i++)
+		{
+			write_cram(gen->vdp, i, rand());
+		}
+		for (int i = 0; i < VSRAM_SIZE; i++)
+		{
+			gen->vdp->vsram[i] = rand();
+		}
+	}
 	setup_io_devices(config, rom, &gen->io);
 
 	gen->save_type = rom->save_type;