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/sm83/hblankcpy.s

      1 .include "global.s"
      2 
      3 .area _CODE
      4 
      5 ; de : source
      6 ; a  : count
      7 ; (hblank_copy_destination) : destination
      8 _hblank_copy_vram::
      9         ld hl, #rIE
     10         ld c, (hl)
     11         ld (hl), #IEF_STAT
     12         ld hl, #rSTAT
     13         ld b, (hl)
     14         ld (hl), #STATF_MODE00
     15         push bc
     16         ld bc, #_hblank_copy_vram_tail
     17         push bc
     18 
     19 ; de : source
     20 ; a  : count
     21 ; (hblank_copy_destination) : destination
     22 _hblank_cpy_vram::
     23         ld h, d
     24         ld l, e
     25         ld (stack_save), sp
     26 
     27         ld sp, #_hblank_copy_destination
     28         pop de
     29 
     30         ld sp, hl               ; sp = sour
     31         ld h, d
     32         ld l, e                 ; hl = dest
     33 
     34 1$:
     35         ld (vram_cpy_counter), a
     36 
     37         pop de                  ; prefetch
     38         pop bc                  ; prefetch
     39         xor a
     40         ldh (rIF), a            ; reset pending interrupts
     41         ld a, e                 ; prepare the first byte
     42 
     43         halt
     44         nop                     ; in case the halt bug is triggered
     45 
     46         ld (hl+), a             ; copy two bytes
     47         ld a, d
     48         ld (hl+), a
     49         ld a, c
     50         ld (hl+), a             ; copy two bytes
     51         ld a, b
     52         ld (hl+), a
     53 .rept 5
     54             pop de              ; copy ten bytes
     55             ld a, e
     56             ld (hl+), a
     57             ld a, d
     58             ld (hl+), a
     59 .endm
     60         pop de                  ; copy two bytes
     61         ld a, e
     62         ld (hl+), a
     63         ld (hl), d
     64         inc hl
     65 
     66         ld a, (vram_cpy_counter)
     67         dec a
     68         jr nz, 1$
     69 
     70         ld sp, #stack_save
     71         pop hl
     72         ld sp, hl
     73         ret
     74 
     75 _hblank_copy_vram_tail:
     76         pop bc
     77         ld a, b
     78         ldh (rSTAT), a
     79         ld a, c
     80         ldh (rIE), a
     81         xor a
     82         ldh (rIF), a            ; reset pending interrupts
     83         ret
     84 
     85 
     86 .area _DATA
     87 
     88 vram_cpy_counter:
     89     .ds 1
     90 stack_save:
     91     .ds 2
     92 _hblank_copy_destination::
     93     .ds 2

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