- Timekeeping hook on the 83+SE
- 24 Feb 2010 11:57:18 pm
- Last edited by Will_W on 25 Feb 2010 11:23:58 pm; edited 1 time in total
Code:
Initialize_Timer:
ld a, 47h
out (30h), a ;turn timer on at 8Hz
ld a, 03h
out (31h), a ;timer mode, interrupt and loop
ld a, 8
out (32h), a ;timer starts at 8
Initialize_Keyhook:
ld hl, keyHook
in a, (6)
B_CALL RawKeyHook
ld hl, parserHook
in a, (6)
B_CALL SetParserHook
;============================================================
;set up that interrupt, use IM2. It jumps to the IM1
;interrupt once it finishes.
;============================================================
keyHook:
add a,e
im 2
ret
parserHook:
add a,e
im 2
or a
ret z
push hl
ld hl, 2626h ;real(
sbc hl,bc
pop hl
jr nz,ReturnZ
ld a,l
or a
ret z ;return if zero arguments
dec a
ret z ;return if one argument
push hl
B_CALL PushRealO1
pop hl
push hl
ld d,h
ld e,l
add hl,hl
add hl,hl
add hl,hl
add hl,de; hlx9
push hl
ex de,hl
ld hl,(fps)
or a
sbc hl,de
push hl
rst 20h
pop de
pop bc
ldir
ld hl,(fps)
ld de,9
or a
sbc hl,de
ld (fps),hl
B_CALL CkPosInt
jr z,Parser_Number_Ok
pop hl
B_JUMP ErrArgument
Parser_Number_Ok:
B_CALL ConvOP1 ;the first argument in de
sub 40 ;subtract 40.
ld e,a
ld d,0
ld hl,Parser_JumpTable
sla e ;offset x2, because it's a table of words
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
pop de ;it would seem DE is now the number of args
ld a,e ;A is now the number of args
dec a ;cause we just parsed one
jp (hl) ;jump to whatever command was activated
Parse_TimerOn:
di ;http://tifreakware.net/tutorials/83p/a/intguide.htm
ld hl,$9900
ld de,$9901
ld bc,256
ld (hl),$9a
ldir
ld hl,Interrupt_pre_addr
ld de,$9a9a
ld bc,Interrupt_End-Interrupt_Start
ldir
ld a,$99
ld i,a ;load $99 into I
im 2 ;switch to mode 2
ld a, 47h
out (30h), a ;turn timer on at 8Hz
ld a, 03h
out (31h), a ;timer mode, interrupt and loop
ld a, 8
out (32h), a ;timer starts at 8
ei
;=========================
;need exit code
;=========================
Parse_StartTimer:
ld a, 47h ;just gotta make sure the timer isn't off
out (30h), a ;turn timer on at 8Hz
ld a, 03h
out (31h), a ;timer mode, interrupt and loop
ld a, 8
out (32h), a ;timer starts at 8
xor a
ld (Time), a
ld (Time+1), a ;the timer starts at 0
;=================================
;I think this needs exit code too
;the FP stack might be a mess
;=================================
ReturnZ:
cp a
ret
;I copied and pasted good ol' omnicalcs jump table
;and made it suit my needs
Parser_JumpTable:
.dw Parse_TimerOn
.dw Parse_StartTimer
Parse_Error_Range:
Parse_Error_Domain:
B_JUMP ErrDomain
Parse_Error_DataType:
B_JUMP ErrDataType
Parse_Error_Break:
B_JUMP ErrBreak
Parse_Error_Syntax:
B_JUMP ErrSyntax
Parse_Error_Argument:
B_JUMP ErrArgument
Parse_Error_Undefined:
B_JUMP ErrUndefined
;============================================================
;you need to put this in a fixed location | done
;=========================================|
; .dw Time; in seconds since you turned it on
;============================================================
Interrupt_pre_addr:
.org 9a9ah
Interrupt_Start:
Check_Timer: ;this updates Time
ex af,af'
exx
in a,(4)
bit 5,a
ret z ;exit if no interrupt
in a,(31h)
bit 3,a ;if this is set, the time might be wrong
;it means a second went by where the clock
;wasn't updated.
;perhaps this error can be handled
;it shouldn't come up though
jp nz, Check_Timer_Error
ld a, 3
out (31h), 3;tells the calc that the interrupt has been
;handled.
ld a, 8
out (32h), a;one more second till it happens again
ld hl, (Time) ;\
inc hl ;|-increments Time.
ld (Time), hl ;/
exx
ex af,af'
jp 0038h ;TI's interrupt
.dw Time; in seconds since you turned it on
Interrupt_End
a rough sketch with some z80 thrown in.
It can't tell you what time it is, but it might make a stopwatch.