Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .nolist ; Obvious
- #include "ti83plus.inc" ; stuff
- #include "dcs7.inc" ; needed
- .list ; for
- .org $9D93 ; every
- .db t2ByteTok,tAsmCmp ; program
- ; Hooray for my first useful assembly program!!!
- ; |-----------------|
- ; | All code within |
- ; | the Off label | The portion of the code used is not meant to be power-efficient... it's not.
- ; | thanks to KermM | It WILL drain the batteries! It was intended for temporary power-off ONLY.
- ; | of Cemetech |
- ; |-----------------|
- ; Array-based optimization provided by Tanner of Cemetech
- _GetKeyRetOff .equ $500B ; GetKeyRetOff B_CALL not defined in ti83plus.inc
- Start:
- ld hl,CodeArray ; Put keys to press in memory
- KeyLoop:
- ld c,0 ; Ensure error level counter is reset to 0
- push hl ; Keep array in memory
- bcall(_GetKeyRetOff) ; Prevent NORMAL off on press of On key (would cause RAM leaks, etc.)
- pop hl ; Recall array to memory
- cp (hl) ; See if keypress represents currently needed key
- jr z,Correct ; If correct, jump to Correct* label to set needed values
- call nz,ErrorLevelUp ; Set error level (register c) to 1 if not correct
- cp kClear ; Check if key was Clear
- call z,Off ; If so, use the special Off function
- call nz,ErrorLevelUp ; If not, set error level to 2
- cp kOff ; Verify if user pressed [2nd]-[On]
- call z,Off ; If so, suspend the calc (special Off)
- call nz,ErrorLevelUp ; If no appropriate key was pressed, set error level to 3
- ld a,3 ; Set new temp value for register a
- cp c ; Check if error level was 3
- jr z,ErrorInit ; If error level WAS 3, wait for 7 keypresses before resume.
- jr KeyLoop ; Return to beginning of loop
- ErrorInit:
- ld b,7 ; Reset register b (error countdown) to 7
- push hl ; Preserve pointer to array
- Error:
- bcall(_GetKey) ; Wait for a keypress
- djnz Error ; Repeat until b=0, decrementing b each time
- ErrorEnd:
- pop hl ; Restore pointer to array
- jr Start ; Reset values and enter loop again
- Correct:
- inc hl ; Make hl point to next element in array
- ld b,(hl) ; Make register b equal to next element
- xor a ; Set a to 0
- cp b ; If b=0 (b=a)...
- jr z,Done ; End program
- jr KeyLoop ; Otherwise, go back to loop
- Done:
- bcall(_ClrLCDFull) ; Clear the screen
- bcall(_HomeUp) ; Prepare homescreen
- xor a ; Set register a to 0
- ld (curRow),a ; Set the starting row to the first one
- ld a,1 ; Set register a to 1
- ld (curCol),a ; Set the starting column to the second one
- ld hl,CorrectMsg ; Put the text in the proper register
- bcall(_PutS) ; Display the text
- res 7,(iy+28h) ; Allow normal off with no tricks
- ret ; Terminate
- Off:
- ld a,2
- out ($10),a ;turn off screen
- res OnInterrupt,(iy+OnFlags)
- call debounceon
- im 1 ;TI-OS default interrupt
- ei ;enable interrupts
- ld a,1 ;enable ONLY [ON] key, no linkport wake
- out (3),a
- halt
- di
- res OnInterrupt,(iy+OnFlags)
- ld a,3
- out ($10),a ;turn on screen
- debounceon:
- ld b,16
- debounceoninner:
- in a,(4)
- bit 3,a
- jr z,debounceon
- djnz debounceoninner
- ret ; Exit subroutine
- ErrorLevelUp:
- inc c ; Add 1 to register c's value
- ret ; Exit subroutine
- CorrectMsg:
- .db "Access Granted!",0 ; Message to display before terminated
- CodeArray:
- .db kUp, kUp, kDown, kDown, kLeft, kRight, kLeft, kRight, kCapB, kCapA, 0 ; Keys to press, in order, zero-terminated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement