git.y1.nz

gbdk-2020

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

commit df9112a7c4657af4975dcf3006c97c2a312118ff
parent 9dd685cb3c61af89af71b71b6297416603a6e16e
Author: Toxa <untoxa@mail.ru>
Date:   Fri, 27 Jan 2023 19:04:01 +0300

GB: new faster vmemcpy()/set_data()/get_data()

Diffstat:
Mgbdk-lib/include/gb/gb.h6+++---
Mgbdk-lib/libc/targets/sm83/cpy_data.s95+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
2 files changed, 60 insertions(+), 41 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -1843,7 +1843,7 @@ inline void hide_sprite(uint8_t nb) { @see set_bkg_data, set_win_data, set_bkg_tiles, set_win_tiles, set_tile_data, set_tiles */ -void set_data(uint8_t *vram_addr, const uint8_t *data, uint16_t len) OLDCALL PRESERVES_REGS(b, c); +void set_data(uint8_t *vram_addr, const uint8_t *data, uint16_t len); /** Copies arbitrary data from an address in VRAM into a buffer @@ -1861,7 +1861,7 @@ void set_data(uint8_t *vram_addr, const uint8_t *data, uint16_t len) OLDCALL PRE @see get_bkg_data, get_win_data, get_bkg_tiles, get_win_tiles, get_tiles */ -void get_data(uint8_t *data, uint8_t *vram_addr, uint16_t len) OLDCALL PRESERVES_REGS(b, c); +void get_data(uint8_t *data, uint8_t *vram_addr, uint16_t len); /** Copies arbitrary data from an address in VRAM into a buffer @@ -1875,7 +1875,7 @@ void get_data(uint8_t *data, uint8_t *vram_addr, uint16_t len) OLDCALL PRESERVES \li VBK_REG = @ref VBK_BANK_0 indicates the first bank \li VBK_REG = @ref VBK_BANK_1 indicates the second */ -void vmemcpy(uint8_t *dest, uint8_t *sour, uint16_t len) OLDCALL PRESERVES_REGS(b, c); +void vmemcpy(uint8_t *dest, uint8_t *sour, uint16_t len); diff --git a/gbdk-lib/libc/targets/sm83/cpy_data.s b/gbdk-lib/libc/targets/sm83/cpy_data.s @@ -1,44 +1,63 @@ - .include "global.s" + .include "global.s" - .area _HOME + .area _CODE - ;; Copy part (size = DE) of the VRAM from (BC) to (HL) -.copy_vram:: - INC D - INC E - JR 2$ -1$: - WAIT_STAT + .globl _vmemcpy2, _set_data2, _get_data2 - LD A,(BC) - LD (HL+),A - INC BC -2$: - DEC E - JR NZ, 1$ - DEC D - JR NZ, 1$ - RET +_vmemcpy2:: +_set_data2:: +_get_data2:: + ;dest in de + ;src in bc + ;n in sp+2,sp+3 + ldhl sp, #3 + ld a, (hl-) + ld l, (hl) + ld h, b + ld b, a + ld a, l + ld l, c + srl b + rra + ld c, a -_vmemcpy:: -_set_data:: -_get_data:: - PUSH BC + ;dest in de (backup in sp+0,sp+1) + ;src in hl + ;n/2 in bc + ;LSB of bc in carry + jr nc, skip_one - LDA HL,9(SP) ; Skip return address and registers - LD A,(HL-) ; DE = len - LD D, A - LD A,(HL-) - LD E, A - LD A,(HL-) ; BC = src - LD B, A - LD A,(HL-) - LD C, A - LD A,(HL-) ; HL = dst - LD L,(HL) - LD H,A + WAIT_STAT + ld a, (hl+) + ld (de), a + inc de +skip_one: + ;n/2 in bc + ;shift second LSB to carry + srl b + rr c + ;n/4 in bc + inc b + inc c + jr nc, test + jr copy_two +.irp idx,copy_four,copy_two + idx: + .rept 2 + WAIT_STAT + ld a, (hl+) + ld (de), a + inc de + .endm +.endm +test: +.irp idx,c,b + dec idx + jr nz, copy_four +.endm - CALL .copy_vram - - POP BC - RET + ;get return address + pop hl + ;throw away n + pop af + jp (hl)

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