gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 06dee0fbad8e615a548db28a2dc7028a3f538eeb parent 112036a6d9aee53b858794a5f43ee432dc72b648 Author: toxa <untoxa@mail.ru> Date: Wed, 28 Oct 2020 00:56:03 +0300 wait_int_handler fixed; set_*_data function sources cleanup Diffstat:
| M | gbdk-lib/libc/gb/crt0.s | 6 | ++++-- |
| M | gbdk-lib/libc/gb/lcd.s | 3 | ++- |
| M | gbdk-lib/libc/gb/nowait.s | 16 | ---------------- |
| M | gbdk-lib/libc/gb/set_1bit_data.s | 9 | ++++----- |
| M | gbdk-lib/libc/gb/set_data.s | 96 | ++++++++++++++++++------------------------------------------------------------- |
5 files changed, 32 insertions(+), 98 deletions(-)
diff --git a/gbdk-lib/libc/gb/crt0.s b/gbdk-lib/libc/gb/crt0.s @@ -64,7 +64,7 @@ 1$: LD A,(HL+) OR (HL) - JR Z,2$ + JR Z,.int_tail PUSH HL LD A,(HL-) LD L,(HL) @@ -73,7 +73,9 @@ POP HL INC HL JR 1$ -2$: +_wait_int_handler:: + ADD SP,#4 +.int_tail: POP DE POP BC POP HL diff --git a/gbdk-lib/libc/gb/lcd.s b/gbdk-lib/libc/gb/lcd.s @@ -26,7 +26,8 @@ LD A,(HL+) LD H,(HL) LD L,A - ; don't need to check the first one: if 0, then call an empty handler + OR H + JR Z, 1$ RST 0x20 ; .call_hl LD HL, #.int_0x48 + 2 LD A,(HL+) diff --git a/gbdk-lib/libc/gb/nowait.s b/gbdk-lib/libc/gb/nowait.s @@ -8,19 +8,3 @@ _nowait_int_handler:: POP HL POP AF RETI - -_wait_int_handler:: - ADD SP,#4 - POP DE - POP BC - POP HL -1$: - LDH A,(#_STAT_REG) - AND #0X02 - JR Z,1$ -2$: - LDH A, (#_STAT_REG) - AND #0X02 - JR NZ, 2$ - POP AF - RETI diff --git a/gbdk-lib/libc/gb/set_1bit_data.s b/gbdk-lib/libc/gb/set_1bit_data.s @@ -38,17 +38,16 @@ _set_sprite_1bit_data:: ld a, e and #0xF0 ; Get low bits only ld e, a - 1$: ; Wrap from past $97FF to $8800 onwards ; This can be reduced to "bit 4 must be clear if bit 3 is set" bit 3, d jr z, 2$ res 4, d -2$: - .rept 3 ; Repeat this 4 more times to copy 16 bytes... +2$: + .rept 3 ; Repeat this 3 times to copy 12 bytes... WAIT_STAT - ; We have 16 cycles free to access VRAM, during which we can copy 3 bytes + ; We have 16 cycles free to access VRAM, during which we can expand 2 bytes into 4 bytes ld a, (hl+) ld (de), a inc e ; inc de @@ -61,7 +60,7 @@ _set_sprite_1bit_data:: inc e ; inc de .endm WAIT_STAT - ; We have 16 cycles free to access VRAM, during which we can copy 3 bytes + ; We have 16 cycles free to access VRAM, during which we can expand 2 bytes into 4 byte ld a, (hl+) ld (de), a inc e ; inc de diff --git a/gbdk-lib/libc/gb/set_data.s b/gbdk-lib/libc/gb/set_data.s @@ -5,6 +5,12 @@ ;; BANKED: checked .area _BASE +.macro WAIT_STAT ?lbl +lbl: ldh a, (.STAT) + and #2 ; Check if in LCD modes 0 or 1 + jr nz, lbl +.endm + _set_bkg_data:: _set_win_data:: ld d, #0x90 @@ -33,90 +39,32 @@ _set_sprite_data:: ld a, e and #0xF0 ; Get low bits only ld e, a - -copy_tile$: +2$: ; Wrap from past $97FF to $8800 onwards ; This can be reduced to "bit 4 must be clear if bit 3 is set" bit 3, d jr z, 1$ res 4, d 1$: - ldh a, (.STAT) - and #2 ; Check if in LCD modes 0 or 1 - jr nz, 1$ - ; We have 16 cycles free to access VRAM, during which we can copy 3 bytes - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ; Repeat this 4 more times to copy 15 of the 16 bytes... -2$: - ldh a, (.STAT) - and #2 - jr nz, 2$ - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de -3$: - ldh a, (.STAT) - and #2 - jr nz, 3$ - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de -4$: - ldh a, (.STAT) - and #2 - jr nz, 4$ - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de -5$: - ldh a, (.STAT) - and #2 - jr nz, 5$ - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ld a, (hl+) - ld (de), a - inc e ; inc de - ; Now, copy the final byte, wherein we will increment `de` in full -6$: - ldh a, (.STAT) - and #2 - jr nz, 6$ + .rept 5 + WAIT_STAT + ld a, (hl+) + ld (de), a + inc e ; inc de + ld a, (hl+) + ld (de), a + inc e ; inc de + ld a, (hl+) + ld (de), a + inc e ; inc de + .endm + WAIT_STAT ld a, (hl+) ld (de), a inc de ; This actually can overflow into the high byte + dec c - jr nz, copy_tile$ + jr nz, 2$ pop bc 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.