diff --git a/examples/hello-world/hello.fs b/examples/hello-world/hello.fs index a4dce2d6..d2278129 100644 --- a/examples/hello-world/hello.fs +++ b/examples/hello-world/hello.fs @@ -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 ; diff --git a/lib/interrupt.fs b/lib/interrupt.fs new file mode 100644 index 00000000..1b530ee4 --- /dev/null +++ b/lib/interrupt.fs @@ -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