cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

rand.s (1007B)


      1        .module Random
      2
      3        .area   _DATA
      4
      5___rand_seed::
      6.randval:
      7        .ds     0x02
      8
      9        .area   _CODE
     10
     11_rand::	
     12_randw::
     13
     14        LD HL, (.randval)
     15        EX DE, HL
     16        LD L, E
     17        LD A, D
     18
     19        SLA L                   ; * 16
     20        RLA
     21        SLA L
     22        RLA
     23        SLA L
     24        RLA
     25        SLA L
     26        RLA
     27        LD H, A                 ; Save randhi*16
     28
     29        LD A, E                 ; Old randlo
     30        ADD A, L                ; Add randlo*16
     31        LD L, A                 ; Save randlo*17
     32
     33        LD A, H                 ; randhi*16
     34        ADC A, D                ; Add old randhi
     35        LD H, A                 ; Save randhi*17
     36
     37        LD A, L                 ; randlo*17
     38        ADD A, #0x93
     39        LD L, A
     40        LD A, H                 ; randhi*17
     41        ADC A, #0x5c
     42        LD H, A
     43        LD (.randval), HL
     44        LD H, L
     45        LD L, A
     46
     47        RET
     48
     49_initrand::                     ; Non banked
     50.initrand::
     51        LD (.randval), HL
     52        RET