git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/asm/z80/arand.s

      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
     26 1$:
     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
     37 2$:
     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
     57 1$:
     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

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.