gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit adc683f778fed0c477bd6cf53cf3ca3f54b57b7d parent 42875e72fea3f6d3addff3799136212e49d611fe Author: Toxa <untoxa@mail.ru> Date: Sat, 4 Sep 2021 12:36:31 +0300 SMS/GG: delay() Diffstat:
| M | gbdk-lib/include/gb/gb.h | 2 | +- |
| M | gbdk-lib/include/sms/sms.h | 7 | +++++++ |
| A | gbdk-lib/libc/targets/z80/delay.s | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/gg/Makefile | 1 | + |
| M | gbdk-lib/libc/targets/z80/gg/global.s | 2 | ++ |
| M | gbdk-lib/libc/targets/z80/sms/Makefile | 1 | + |
| M | gbdk-lib/libc/targets/z80/sms/global.s | 2 | ++ |
7 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -503,7 +503,7 @@ __endasm; \ /** Delays the given number of milliseconds. Uses no timers or interrupts, and can be called with - interrupts disabled (why nobody knows :) + interrupts disabled */ void delay(uint16_t d) NONBANKED; diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -349,6 +349,13 @@ __endasm; \ #define DISABLE_RAM RAM_CONTROL&=(~RAMCTL_RAM) +/** Delays the given number of milliseconds. + Uses no timers or interrupts, and can be called with + interrupts disabled + */ +void delay(uint16_t d) __z88dk_fastcall; + + /** Reads and returns the current state of the joypad. */ uint8_t joypad(void) __preserves_regs(b, c, d, e, h, iyh, iyl); diff --git a/gbdk-lib/libc/targets/z80/delay.s b/gbdk-lib/libc/targets/z80/delay.s @@ -0,0 +1,53 @@ + .include "global.s" + + .title "Delay" + .module delay + + .area _CODE + +;; hl must contain amount of tstates, which must be >= 141 +wait_hl_tstates:: + ld bc, #-141 + add hl, bc + ld bc, #-23 +1$: + add hl,bc + jr c, 1$ + ld a, l + add a, #15 + jr nc, 2$ + cp #8 + jr c, 3$ + or #0 +2$: + inc hl +3$: + rra + jr c, 4$ + nop +4$: + rra + jr nc, 5$ + or #0 +5$: + rra + ret nc + ret + +;; hl = milliseconds (0 = 65536) +_delay:: + ld e, l + ld d, h +1$: + dec de + ld a,d + or e + jr z, 2$ + + ld hl,#((.CPU_CLOCK / 1000) - 43) + call wait_hl_tstates + jr 1$ +2$: + ld hl,#((.CPU_CLOCK / 1000) - 54) + jp wait_hl_tstates + ret + diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -25,6 +25,7 @@ ASSRC = set_interrupts.s \ pad.s pad_ex.s \ int.s nmi.s \ mode.s \ + delay.s \ memset_small.s \ far_ptr.s \ __sdcc_bcall.s \ diff --git a/gbdk-lib/libc/targets/z80/gg/global.s b/gbdk-lib/libc/targets/z80/gg/global.s @@ -162,6 +162,8 @@ .SYSTEM_PAL = 0x00 .SYSTEM_NTSC = 0x01 + .CPU_CLOCK = 3574000 + ;; GBDK library screen modes .T_MODE = 0x02 ; Text mode (bit 2) diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -25,6 +25,7 @@ ASSRC = set_interrupts.s \ pad.s pad_ex.s \ int.s nmi.s \ mode.s \ + delay.s \ memset_small.s \ far_ptr.s \ __sdcc_bcall.s \ diff --git a/gbdk-lib/libc/targets/z80/sms/global.s b/gbdk-lib/libc/targets/z80/sms/global.s @@ -162,6 +162,8 @@ .SYSTEM_PAL = 0x00 .SYSTEM_NTSC = 0x01 + .CPU_CLOCK = 3574000 + ;; GBDK library screen modes .T_MODE = 0x02 ; Text mode (bit 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.