diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-05 18:49:02 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-03-05 18:49:02 +0100 |
| commit | 0de830d9ac786fbbf32e9abebf3975e909b1a5e7 (patch) | |
| tree | 8a5d1ad9ec7aacb29de5a2cde3524bdd22e577a7 | |
| parent | 95dee49559d78a3d1c458ad98c277ef7dbee473e (diff) | |
| download | jetpac.nes-0de830d9ac786fbbf32e9abebf3975e909b1a5e7.tar.gz jetpac.nes-0de830d9ac786fbbf32e9abebf3975e909b1a5e7.zip | |
Make randomness a bit more random
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | bin/rand.rb | 5 | ||||
| -rw-r--r-- | src/interrupts.s | 6 | ||||
| -rw-r--r-- | src/prng.s | 32 |
3 files changed, 23 insertions, 20 deletions
diff --git a/bin/rand.rb b/bin/rand.rb index a3e7e41..345cb4d 100644 --- a/bin/rand.rb +++ b/bin/rand.rb @@ -18,10 +18,13 @@ GROUND_Y_COORD = 0xC8 - 64 # The available values for the Y axis for enemies are above ground, below the # sky, and avoiding the left-most and right-most platforms. available = (UPPER_MARGIN_Y_COORD..GROUND_Y_COORD).to_a - (0x58..0x69).to_a - (0x40..0x50).to_a +available = available.shuffle # With this produce the array containing a randomized sample from the # 'available' values. -random_byte_array = Array.new(256) { format('$%02X', available.sample) } +random_byte_array = (0...256).map do |i| + format('$%02X', available[i % available.length]) +end # And now print it in the assembler format. random_byte_array.each_slice(16) do |row| diff --git a/src/interrupts.s b/src/interrupts.s index b5120b4..522ee9e 100644 --- a/src/interrupts.s +++ b/src/interrupts.s @@ -24,6 +24,9 @@ lda #$02 sta OAM::m_dma + ;; Increase the random seed. + inc Prng::zp_rand + ;; Are we paused? If so skip timers, PAL handler and the likes. lda #%00001000 and Globals::zp_flags @@ -61,9 +64,6 @@ and #%00000001 bne @ppu_registers - ;; Increase the random seed. - inc Prng::zp_rand - ;; Decrease title timer. lda Title::zp_title_timer beq @ppu_registers @@ -28,19 +28,19 @@ ;; ;; NOTE: generated via bin/rand.rb; read more on this there. valid_y_rand_table: - .byte $73, $54, $7E, $3F, $76, $77, $55, $72, $83, $6A, $81, $53, $52, $74, $80, $3A - .byte $86, $3C, $87, $74, $3D, $88, $7A, $82, $54, $72, $7B, $77, $77, $75, $88, $52 - .byte $86, $6D, $80, $54, $79, $7A, $85, $7E, $82, $88, $7E, $7B, $74, $84, $71, $70 - .byte $3F, $3A, $82, $70, $75, $3D, $74, $7F, $88, $86, $83, $75, $86, $70, $55, $7A - .byte $73, $6E, $88, $85, $6F, $7C, $3D, $3E, $55, $3B, $6C, $6D, $54, $76, $3E, $3B - .byte $6F, $51, $7D, $73, $83, $52, $82, $7F, $72, $3A, $55, $78, $85, $3B, $86, $6A - .byte $70, $82, $6A, $77, $3C, $76, $7C, $85, $51, $6A, $71, $6A, $78, $86, $3E, $3F - .byte $84, $7F, $3C, $53, $73, $6C, $7E, $3A, $86, $84, $7E, $75, $53, $3B, $78, $3B - .byte $56, $7A, $7A, $77, $85, $6E, $76, $86, $52, $85, $3B, $3D, $87, $81, $7B, $83 - .byte $86, $3E, $7F, $3E, $6A, $57, $85, $73, $88, $6A, $7B, $6E, $81, $77, $3B, $3F - .byte $84, $3E, $55, $83, $88, $81, $55, $76, $7A, $57, $76, $7B, $6F, $7C, $76, $3E - .byte $55, $82, $75, $75, $3F, $3E, $7E, $6C, $3F, $81, $6C, $6C, $71, $3D, $3B, $3E - .byte $87, $7C, $85, $3E, $74, $80, $83, $3E, $80, $3B, $71, $51, $51, $6E, $53, $7B - .byte $3D, $3D, $56, $79, $3B, $54, $7E, $6D, $3A, $81, $3E, $85, $88, $6C, $57, $85 - .byte $52, $87, $7A, $86, $82, $7D, $87, $73, $7A, $83, $70, $70, $88, $52, $80, $86 - .byte $80, $7B, $55, $53, $6A, $81, $6B, $3F, $86, $3E, $7F, $84, $55, $53, $6B, $86 + .byte $84, $76, $85, $80, $55, $7E, $7C, $73, $7F, $52, $79, $81, $53, $75, $3D, $51 + .byte $54, $6C, $88, $3C, $87, $6E, $57, $82, $77, $3E, $6B, $86, $6A, $3A, $3F, $83 + .byte $78, $7A, $72, $70, $7D, $6F, $6D, $71, $7B, $74, $3B, $56, $84, $76, $85, $80 + .byte $55, $7E, $7C, $73, $7F, $52, $79, $81, $53, $75, $3D, $51, $54, $6C, $88, $3C + .byte $87, $6E, $57, $82, $77, $3E, $6B, $86, $6A, $3A, $3F, $83, $78, $7A, $72, $70 + .byte $7D, $6F, $6D, $71, $7B, $74, $3B, $56, $84, $76, $85, $80, $55, $7E, $7C, $73 + .byte $7F, $52, $79, $81, $53, $75, $3D, $51, $54, $6C, $88, $3C, $87, $6E, $57, $82 + .byte $77, $3E, $6B, $86, $6A, $3A, $3F, $83, $78, $7A, $72, $70, $7D, $6F, $6D, $71 + .byte $7B, $74, $3B, $56, $84, $76, $85, $80, $55, $7E, $7C, $73, $7F, $52, $79, $81 + .byte $53, $75, $3D, $51, $54, $6C, $88, $3C, $87, $6E, $57, $82, $77, $3E, $6B, $86 + .byte $6A, $3A, $3F, $83, $78, $7A, $72, $70, $7D, $6F, $6D, $71, $7B, $74, $3B, $56 + .byte $84, $76, $85, $80, $55, $7E, $7C, $73, $7F, $52, $79, $81, $53, $75, $3D, $51 + .byte $54, $6C, $88, $3C, $87, $6E, $57, $82, $77, $3E, $6B, $86, $6A, $3A, $3F, $83 + .byte $78, $7A, $72, $70, $7D, $6F, $6D, $71, $7B, $74, $3B, $56, $84, $76, $85, $80 + .byte $55, $7E, $7C, $73, $7F, $52, $79, $81, $53, $75, $3D, $51, $54, $6C, $88, $3C + .byte $87, $6E, $57, $82, $77, $3E, $6B, $86, $6A, $3A, $3F, $83, $78, $7A, $72, $70 |
