git.y1.nz

gbdk-2020

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

commit 389f13e0a9301bc9364eb269f8079867b4dc1313
parent 3872f632c5b53dd171d8766b938d3191a91a6575
Author: Toxa <untoxa@mail.ru>
Date:   Tue,  4 Jan 2022 17:15:55 +0300

GB: add_low_priority_TIM() function that install timer interrupt handlers which allow nesting

Diffstat:
Mgbdk-lib/include/gb/gb.h19+++++++++++++++----
Mgbdk-lib/libc/targets/gbz80/ap/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/duck/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/gb/Makefile2+-
Mgbdk-lib/libc/targets/gbz80/tim.s58++++++++++++++++++----------------------------------------
Agbdk-lib/libc/targets/gbz80/tim_common.s28++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/gbz80/tim_nested.s29+++++++++++++++++++++++++++++
7 files changed, 93 insertions(+), 47 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -221,7 +221,6 @@ void add_VBL(int_handler h) OLDCALL; Called when the LCD interrupt occurs, which is normally when @ref LY_REG == @ref LYC_REG. - From pan/k0Pa: There are various reasons for this interrupt to occur as described by the @ref STAT_REG register ($FF41). One very popular reason is to indicate to the user when the @@ -236,7 +235,8 @@ void add_LCD(int_handler h) OLDCALL; /** Adds a timer interrupt handler. - From pan/k0Pa: + Can not be used together with @ref add_low_priority_TIM + This interrupt occurs when the @ref TIMA_REG register ($FF05) changes from $FF to $00. @@ -245,10 +245,22 @@ void add_LCD(int_handler h) OLDCALL; */ void add_TIM(int_handler h) OLDCALL; +/** Adds a timer interrupt handler, that could be + interrupted by the other interrupts, + as well as itself, if it runs too slow. + + Can not be used together with @ref add_TIM + + This interrupt occurs when the @ref TIMA_REG + register ($FF05) changes from $FF to $00. + + @see add_VBL + @see set_interrupts() with TIM_IFLAG +*/ +void add_low_priority_TIM(int_handler h) OLDCALL; /** Adds a Serial Link transmit complete interrupt handler. - From pan/k0Pa: This interrupt occurs when a serial transfer has completed on the game link port. @@ -260,7 +272,6 @@ void add_SIO(int_handler h) OLDCALL; /** Adds a joypad button change interrupt handler. - From pan/k0Pa: This interrupt occurs on a transition of any of the keypad input lines from high to low. Due to the fact that keypad "bounce" is virtually always present, diff --git a/gbdk-lib/libc/targets/gbz80/ap/Makefile b/gbdk-lib/libc/targets/gbz80/ap/Makefile @@ -22,7 +22,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ sgb.s font.s font_color.s delay.s \ bgb_emu.s bgb_emu_printf.s \ nowait.s far_ptr.s \ - lcd.s joy.s tim.s \ + lcd.s joy.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ mv_spr.s \ diff --git a/gbdk-lib/libc/targets/gbz80/duck/Makefile b/gbdk-lib/libc/targets/gbz80/duck/Makefile @@ -22,7 +22,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ sgb.s font.s font_color.s delay.s \ bgb_emu.s bgb_emu_printf.s \ nowait.s far_ptr.s \ - lcd.s joy.s tim.s \ + lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ mv_spr.s \ diff --git a/gbdk-lib/libc/targets/gbz80/gb/Makefile b/gbdk-lib/libc/targets/gbz80/gb/Makefile @@ -22,7 +22,7 @@ ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ sgb.s font.s font_color.s delay.s \ bgb_emu.s bgb_emu_printf.s \ nowait.s far_ptr.s \ - lcd.s joy.s tim.s \ + lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ crash_handler.s \ ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ mv_spr.s \ diff --git a/gbdk-lib/libc/targets/gbz80/tim.s b/gbdk-lib/libc/targets/gbz80/tim.s @@ -1,47 +1,25 @@ - .include "global.s" + .include "global.s" - .globl .int + .globl .int, .int_0x50 + .globl .add_TIM - .area _HEADER_TIM (ABS) + .area _HEADER_TIM (ABS) - .org 0x50 ; TIM + .org 0x50 ; TIM .int_TIM: - PUSH AF - PUSH HL - LD HL,#.int_0x50 - JP .int + PUSH AF + PUSH HL + LD HL,#.int_0x50 + JP .int - .area _HOME + .area _HOME _add_TIM:: - PUSH BC - LDA HL,4(SP) ; Skip return address and registers - LD C,(HL) - INC HL - LD B,(HL) - CALL .add_TIM - POP BC - RET - -.add_TIM:: - LD HL,#.int_0x50 - JP .add_int - -_remove_TIM:: - PUSH BC - LDA HL,4(SP) ; Skip return address and registers - LD C,(HL) - INC HL - LD B,(HL) - CALL .remove_TIM - POP BC - RET - -.remove_TIM:: - LD HL,#.int_0x50 - JP .remove_int - - .area _DATA - -.int_0x50:: - .blkw 0x08 + PUSH BC + LDA HL,4(SP) ; Skip return address and registers + LD C,(HL) + INC HL + LD B,(HL) + CALL .add_TIM + POP BC + RET diff --git a/gbdk-lib/libc/targets/gbz80/tim_common.s b/gbdk-lib/libc/targets/gbz80/tim_common.s @@ -0,0 +1,28 @@ + .include "global.s" + + .globl .int, .add_int, .remove_int + + .area _HOME + +.add_TIM:: + LD HL,#.int_0x50 + JP .add_int + +_remove_TIM:: + PUSH BC + LDA HL,4(SP) ; Skip return address and registers + LD C,(HL) + INC HL + LD B,(HL) + CALL .remove_TIM + POP BC + RET + +.remove_TIM:: + LD HL,#.int_0x50 + JP .remove_int + + .area _DATA + +.int_0x50:: + .blkw 0x08 diff --git a/gbdk-lib/libc/targets/gbz80/tim_nested.s b/gbdk-lib/libc/targets/gbz80/tim_nested.s @@ -0,0 +1,29 @@ + .include "global.s" + + .globl .int, .int_0x50 + .globl .add_TIM + + .area _HEADER_NESTED_TIM (ABS) + + .org 0x50 ; TIM +.int_TIM_nested: + EI + PUSH AF + PUSH HL + JP .tim_isr_jump + + .area _HOME + +.tim_isr_jump: + LD HL, #.int_0x50 + JP .int + +_add_low_priority_TIM:: + PUSH BC + LDA HL, 4(SP) ; Skip return address and registers + LD C, (HL) + INC HL + LD B,(HL) + CALL .add_TIM + 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.