I've been working on this program for a while, and I want to add an auto power down that doesn't use the system routine and can take a customizable amount of time to activate. I have been trying for a while, and I can't get it to work. The calculator will go into low-power mode, but upon pressing the power button, it will display the screen and freeze. Right now, I only have it at 30 seconds and haven't programmed in a timer reset at all (when you press a button, the timer won't restart). If someone could take a look at my program and see what the problem is, I would really appreciate it.
;#SECTION "MAIN", CODE
org userMem - 2
db 0BBh, 6Dh
; fast mode
ld a, 3
out (20h), a
; install interrupt
im 2
ld a, 99h
ld i, a
ld hl, 9900h
ld de, 9901h
ld bc, 256
ld (hl), 98h
ldir
ld a, 0C3h
ld (9898h), a
ld hl, interrupt
ld (9899h), hl
call initialize
mainMenu:
ld a, 10000001b
ld (runningInterrupts), a
call keyWait
newGame:
loadGame:
mainMenuKeyLoop:
ld a, 10111111b
out (01h), a
nop
nop
nop
nop
in a, (01h)
bit 0, a
jq z, exit
bit 1, a
jq z, help
bit 2, a
jq z, settings
bit 3, a
jq z, loadGame
bit 4, a
jq z, newGame
bit 7, a
jq z, exit
jq mainMenuKeyLoop
;#SECTION "EXIT", CODE
exit:
call keyWait
di
im 1
xor a
out (31h), a
ld a, 00001011b
out (03h), a
call LCD_BUSY_QUICK
ld a, 05h
out (10h), a
B_CALL _ClrLCDFull
ret
saveDataStart:
counter:
db 172
saveDataEnd:
;#SECTION "ROUTINES", CODE
keyWait:
ld a, 10000000b
out (01h), a
nop
nop
nop
nop
in a, (01h)
inc a
jq nz, keyWait
ret
;#SECTION "INTERUPT", CODE
interrupt:
ex af, af'
exx
; timers and stuff
in a, (04h)
ld b, a
xor a
out (03h), a
bit 5, b
jq z, exitInterrupt
initialize:
ld a, 40h
out (30h), a
ld a, 2
out (31h), a
ld a, (counter)
out (32h), a
; check what to run
ld a, (runningInterrupts)
bit 7, a
call nz, mainMenuDraw
ld a, (runningInterrupts)
bit 0, a
call nz, APD
exitInterrupt:
ex af, af'
exx
ei
ret
mainMenuDraw:
ld hl, mainMenuPicData
ld a, (grayCarry)
rra
ld a, (grayMask)
push af
ld c, 80h
newRow:
call LCD_BUSY_QUICK
ld a, 20h
out (10h), a
call LCD_BUSY_QUICK
ld a, c
cp 0B9h
jq z, endDraw
out (10h), a
ld b, 12
ditherLoop:
pop af
rra
push af
ld d, a
and (hl)
ld e, a
inc hl
ld a, d
cpl
and (hl)
inc hl
or e
ld e, a
call LCD_BUSY_QUICK
ld a, e
out (11h), a
djnz ditherLoop
pop af
rla
push af
inc c
jq newRow
endDraw:
pop af
rla
ld (grayMask), a
ld a, 0
rla
ld (grayCarry), a
call LCD_BUSY_QUICK
ret
APD:
ld hl, (APDCounter)
dec hl
ld a, h
or l
ld (APDCounter), hl
ret nz
ld hl, 1800
ld (APDCounter), hl
xor a
out (30h), a
ld a, 1
out (03h), a
halt
xor a
out (03h), a
call initialize
ex af, af'
exx
ret
runningInterrupts:
; MM draw,,,,,,,APD
db 00000000b
grayCarry:
db 1
grayMask:
db 01101101b
APDCounter:
dw 1800
I didn't show a lot of the code that had nothing to do with the APD in the code spoiler, but I left it in in the attachment if you need to see it all.