-
Notifications
You must be signed in to change notification settings - Fork 17
interrupts in camelforth
Neal Crook edited this page Sep 1, 2018
·
3 revisions
CamelForth in its current form has no facilities for handling interrupts, but it will co-exist with interrupts in the system (and they can use the CamelForth stack).
Here is an interrupt example. The code has two parts:
- An initialisation section that is invoked from CamelForth and which returns to CamelForth (an example of interacting politely with the CamelForth virtual machine (VM))
- An interrupt service routine -- all that it does is to use a memory location to count interrupts.
This code was written to test the mk2 memory mapping unit.
0001 * TEST MULTICOMP TIMER INTERRUPT FROM CAMELFORTH
0002 *
0003 * 1/ NEED CAMELFORTH RUNNING FROM RAM SO THAT WE CAN CHANGE THE
0004 * INTERRUPT VECTOR:
0005 * HEX MMUMAP EFTOCD E000 C000 2000 CMOVE CDTOCD PIVOTRST
0006 * 2/ CHANGE VECTOR AT FFF8 TO POINT TO ISR
0007 * HEX 100F FFF8 !
0008 * 3/ ENTER THIS CODE BELOW TO RAM @1000 (USE THE .LST FILE)
0009 * eg: 3606 1000 ! 8602 1002 ! (etc)
0010 * 4/ RUN IT:
0011 * HEX 1000 EXECUTE
0012 *
0013 * SHOULD RETURN TO THE CAMELFORTH PROMPT IMMEDIATELY.
0014 * INSPECT LOCATION "COUNT" - SHOULD SEE IT INCREMENTING AT 50Hz
0015 * WRISTWATCH TEST: I SAW IT INCREMENT FROM 2665 TO 5679 IN
0016 * 60s. (5679-2665)/50 = 60.28s
0017
0018 ffdd TIMER EQU $FFDD
0019
0020 1000 ORG $1000
0021
0022 * COME HERE FROM FORTH SO MUST PRESERVE FORTH VM: Y, D
0023 * ENABLE TIMER AND INTERRUPT
0024 1000 36 06 PSHU D
0025 1002 86 02 LDA #2
0026 1004 b7 ff dd STA TIMER START TIMER
0027 1007 1c ef ANDCC #%11101111 ENABLE INTERRUPTS
0028 1009 37 06 PULU D
0029 * RETURN TO CAMELFORTH
0030 100b 37 20 PULU Y
0031 100d 6e b1 JMP [,Y++]
0032
0033
0034 * ISR - ALL REGISTERS SAVED/RESTORED ACROSS HERE
0035 100f 7c ff dd ISR INC TIMER
0036 1012 2a 08 BPL NOTME
0037 1014 be 10 1d LDX COUNT
0038 1017 30 01 LEAX 1,X aka INX
0039 1019 bf 10 1d STX COUNT
0040 NOTME
0041 101c 3b RTI
0042
0043 101d 00 00 COUNT FDB $0
```