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/targets/z80/delay.s

      1         .include        "global.s"
      2 
      3         .title  "Delay"
      4         .module delay
      5 
      6         .area _CODE
      7 
      8 ;; hl must contain amount of tstates, which must be >= 141
      9 wait_hl_tstates::
     10         ld bc, #-141
     11         add hl, bc
     12         ld bc, #-23
     13 1$:
     14         add hl,bc
     15         jr c, 1$
     16         ld a, l
     17         add a, #15
     18         jr nc, 2$
     19         cp #8
     20         jr c, 3$
     21         or #0
     22 2$:
     23         inc hl
     24 3$:
     25         rra
     26         jr c, 4$
     27         nop
     28 4$:
     29         rra
     30         jr nc, 5$   
     31         or #0
     32 5$:
     33         rra
     34         ret nc
     35         ret
     36 
     37 ;; hl = milliseconds (0 = 65536)
     38 _delay::
     39         ld e, l
     40         ld d, h
     41 1$:
     42         dec de
     43         ld a,d
     44         or e
     45         jr z, 2$
     46 
     47         ld hl,#((.CPU_CLOCK / 1000) - 43)
     48         call wait_hl_tstates
     49         jr 1$
     50 2$:
     51         ld hl,#((.CPU_CLOCK / 1000) - 54)
     52         jp wait_hl_tstates
     53         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.