From f235dd6d7c4de97a732db4d7efe2fec220b78974 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 11 Nov 2018 08:00:43 -0800 Subject: [PATCH] Introduce some one-off memory fixes for poorly-written kracks --- src/misc.c | 1 + src/vm.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/misc.c b/src/misc.c index a365922b..7ec44d26 100644 --- a/src/misc.c +++ b/src/misc.c @@ -41,6 +41,7 @@ CrashHandler_s *crashHandler = NULL; static void _init_common(void) { data_dir = STRDUP(CONFIG_DATADIR PATH_SEPARATOR PACKAGE_NAME); log_init(); + srandom((unsigned int)time(NULL)); LOG("Initializing common..."); } diff --git a/src/vm.c b/src/vm.c index 61d658e0..8b1da949 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1090,13 +1090,39 @@ static void _initialize_apple_ii_memory(void) { } // Stripe words of main memory on machine reset ... - // NOTE: cracked version of J---- will lock up without this + // NOTE: cracked version of Joust will lock up without this for (unsigned int i = 0; i < 0xC000;) { apple_ii_64k[0][i++] = 0xFF; apple_ii_64k[0][i++] = 0xFF; i += 2; } +#if !CPU_TRACING && !VIDEO_TRACING + // certain memory locations randomized at cold-boot ... + for (uint16_t addr = 0x0000; addr < 0xC000; addr += 0x200) + { + uint16_t word; + + word = random(); + apple_ii_64k[0][addr + 0x28] = (word >> 0) & 0xFF; + apple_ii_64k[0][addr + 0x29] = (word >> 8) & 0xFF; + + word = random(); + apple_ii_64k[0][addr + 0x68] = (word >> 0) & 0xFF; + apple_ii_64k[0][addr + 0x69] = (word >> 8) & 0xFF; + } + + // memory initialization workarounds ... + { + // https://github.com/AppleWin/AppleWin/issues/206 + // work around cold-booting bug in "Pooyan" which expects RNDL and RNDH to be non-zero + // "Dung Beetles, Ms. PacMan, Pooyan, Star Cruiser, Star Thief, Invas. Force.dsk" + uint16_t word = (uint16_t)random(); + apple_ii_64k[0][0x4E] = 0x20 | ((word >> 0) & 0xFF); + apple_ii_64k[0][0x4F] = 0x20 | ((word >> 8) & 0xFF); + } +#endif + for (unsigned int i = 0; i < 8192; i++) { language_card[0][i] = language_card[1][i] = 0; }