Author Topic: Custom APD Help  (Read 3725 times)

0 Members and 1 Guest are viewing this topic.

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Custom APD Help
« on: December 12, 2018, 08:44:14 pm »
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.
Code: [Select]
;#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.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Custom APD Help
« Reply #1 on: December 12, 2018, 10:51:49 pm »
One quick thing I notice is that in the APD routine, you halt, but interrupts aren't enabled. As well, it looks like registers will get clobbered.
I'm too lazy to check at the moment, but try this modification:
Code: [Select]
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
 exx
 ex af,af'
 ei
 halt
 exx
 ex af,af'
 xor a
 out (03h), a
 jq initialize

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Custom APD Help
« Reply #2 on: December 13, 2018, 01:42:30 pm »
Thank you so much!  I have been trying to work past that particular issue for at least a week, and now I've got it figured out.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Custom APD Help
« Reply #3 on: December 13, 2018, 01:43:10 pm »
Oh, awesome! So it worked?

Offline Sue Doenim

  • LV2 Member (Next: 40)
  • **
  • Posts: 27
  • Rating: +0/-0
    • View Profile
Re: Custom APD Help
« Reply #4 on: December 15, 2018, 12:15:24 am »
Yes.  Thank you.