# HG changeset patch # User Michael Pavone # Date 1485490037 28800 # Node ID d7be5b6e0a8dd1feaf92d0f39c4ecbb1d44de3a2 # Parent 4cbb6efb9120c803fe3647295e1abe34e096194c Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config diff -r 4cbb6efb9120 -r d7be5b6e0a8d default.cfg --- 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 +} + diff -r 4cbb6efb9120 -r d7be5b6e0a8d genesis.c --- 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 #include +#include #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;