Browse Source

fix prng for gb-interceptor

Thomas B 1 week ago
parent
commit
83f6fe72b9
3 changed files with 8 additions and 8 deletions
  1. 1
    0
      src/config.ba0.c
  2. 1
    0
      src/config.h
  3. 6
    8
      src/main.c

+ 1
- 0
src/config.ba0.c View File

27
 #include "config.h"
27
 #include "config.h"
28
 
28
 
29
 struct config_mem mem;
29
 struct config_mem mem;
30
+uint16_t prng_seed;
30
 
31
 
31
 BANKREF(config)
32
 BANKREF(config)
32
 
33
 

+ 1
- 0
src/config.h View File

73
 };
73
 };
74
 
74
 
75
 extern struct config_mem mem;
75
 extern struct config_mem mem;
76
+extern uint16_t prng_seed;
76
 
77
 
77
 #define conf_get()    (&mem.config)
78
 #define conf_get()    (&mem.config)
78
 #define conf_scores() (mem.scores)
79
 #define conf_scores() (mem.scores)

+ 6
- 8
src/main.c View File

45
 #include "table_speed_shot.h"
45
 #include "table_speed_shot.h"
46
 #include "main.h"
46
 #include "main.h"
47
 
47
 
48
-/*
49
- * TODO: The gb-interceptor has problems emulating the
50
- * DIV register properly. When using it to initialize
51
- * our random number generator seed, the emulation
52
- * runs out-of-sync with the real hardware.
53
- * Using a constant seed 'fixes' this.
54
- */
55
 //#define CONSTANT_SEED 42
48
 //#define CONSTANT_SEED 42
56
 
49
 
57
 uint8_t debug_menu_index = 0;
50
 uint8_t debug_menu_index = 0;
675
     waitpadup();
668
     waitpadup();
676
     seed |= ((uint16_t)DIV_REG) << 8;
669
     seed |= ((uint16_t)DIV_REG) << 8;
677
 #endif
670
 #endif
678
-    initarand(seed);
671
+
672
+    // store in an SRAM variable, so the
673
+    // value goes over the cartridge bus.
674
+    // gives gb-interceptor a chance to see it.
675
+    prng_seed = seed;
676
+    initarand(prng_seed);
679
 
677
 
680
     while (1) {
678
     while (1) {
681
         if (conf_state()->in_progress && ask_continue()) {
679
         if (conf_state()->in_progress && ask_continue()) {

Loading…
Cancel
Save