Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add words to define interrupt handlers #333

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion examples/hello-world/hello.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ title: EXAMPLE

require ibm-font.fs
require term.fs
require interrupt.fs

variable num
: num? 3 8 at-xy num c@ . space ;
: num++ num c@ 1+ num c! ;

p10-interrupt: num++

: main
install-font
init-term
3 7 at-xy
." Hello World !" ;
." Hello World !"
0 num !
enable-key-interrupts
begin num? again ;
53 changes: 53 additions & 0 deletions lib/interrupt.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require gbhw.fs

[asm]
:m vblank-interrupt:
' rom here swap
$0040 ==> ( xt ) # call, reti,
( here ) ==> ;

:m lcd-interrupt:
' rom here swap
$0048 ==> ( xt ) # call, reti,
( here ) ==> ;

:m timer-interrupt:
' rom here swap
$0050 ==> ( xt ) # call, reti,
( here ) ==> ;

:m serial-interrupt:
' rom here swap
$0058 ==> ( xt ) # call, reti,
( here ) ==> ;

:m p10-interrupt:
' rom here swap
$0060 ==> ( xt ) # call, reti,
( here ) ==> ;

:m p11-interrupt:
' rom here swap
$0068 ==> ( xt ) # call, reti,
( here ) ==> ;

:m p12-interrupt:
' rom here swap
$0070 ==> ( xt ) # call, reti,
( here ) ==> ;

:m p13-interrupt:
' rom here swap
$0078 ==> ( xt ) # call, reti,
( here ) ==> ;
[endasm]

: ief! ( c -- )
0 rIF c!
rIE c@ or rIE c! ;

: enable-vblank-interrupts IEF_VBLANK ief! ; \ $0040
: enable-lcd-interrupts IEF_LCDC ief! ; \ $0048
: enable-timer-interrupts IEF_TIMER ief! ; \ $0050
: enable-serial-interrupts IEF_SERIAL ief! ; \ $0058
: enable-key-interrupts IEF_HILO ief! ; \ $0060 $0068 $0070 $0078