arand.s (1326B)
1 .module Random 2 3 .globl .initrand 4 .globl _rand 5 6 .area _DATA 7 8.randarr: 9 .ds 55 10.raxj: 11 .ds 0x01 12.raxk: 13 .ds 0x01 14 15 .area _CODE 16 17_arand:: ; Banked 18 PUSH BC 19 LD D, #0 20 LD HL, #(.randarr - 1) 21 LD A, (.raxj) 22 LD E, A 23 DEC A ; Decrease the pointer 24 JR NZ, 1$ 25 LD A, #55 261$: 27 LD (.raxj), A 28 ADD HL, DE 29 LD B, (HL) 30 31 LD HL, #(.randarr - 1) ; Ooh... 32 LD A, (.raxk) 33 LD E, A 34 DEC A ; Decrease the pointer 35 JR NZ, 2$ 36 LD A, #55 372$: 38 LD (.raxk), A 39 ADD HL, DE 40 LD A, (HL) 41 42 ADD B 43 LD (HL), A ; Store new value 44 45 POP BC 46 47 LD H, #0 48 LD L, A 49 50 RET 51 52_initarand:: ; Banked 53 CALL .initrand 54 55 LD A, #55 56 LD HL, #.randarr 571$: 58 DEC A 59 LD (.raxj), A 60 LD B, H 61 LD C, L 62 CALL _rand 63 LD H, B 64 LD L, C 65 66 LD (HL), E 67 INC HL 68 69 LD A, (.raxj) 70 CP #0 71 JP NZ, 1$ 72 73 LD A, #24 ; Now the array has been filled,set the pointers 74 LD (.raxj), A 75 LD A, #55 76 LD (.raxk), A 77 78 RET