← BBA4 Blit dirty cells to the display and age their counters Map BC01 → Horizontally mirror the object sprite bank in place
BBE2: Draw the next pseudo-random byte
Returns the next pseudo-random byte and advances the 16-bit seed. The game's general random source.
Output
A the next pseudo-random byte
next_random BBE2 PUSH HL Preserve the caller's HL and DE.
BBE3 PUSH DE
BBE4 LD HL,(rng_seed) Advance the seed: add its own low byte to its high byte, add a constant, and write it back.
BBE7 LD D,L
BBE8 LD E,$00
BBEA ADD HL,DE
BBEB LD DE,$0029
BBEE ADD HL,DE
BBEF LD (rng_seed),HL
BBF2 LD H,$00 Index the entropy window by the new seed's low byte.
BBF4 LD DE,spr_visor_1
BBF7 ADD HL,DE
BBF8 LD A,R Mix the Z80 refresh register, the seed's low byte and the window byte into A. The refresh register and the memory byte add entropy from when the draw happens.
BBFA XOR L
BBFB XOR (HL)
BBFC POP DE
BBFD POP HL
BBFE RET
rng_seed BBFF DEFB $00,$00 The 16-bit seed
← BBA4 Blit dirty cells to the display and age their counters Map BC01 → Horizontally mirror the object sprite bank in place
Fork me on GitHub