APD

z80 » Advanced

Automatic Power Down (APD) is like a screen saver on your computer (except it's more of a battery saver because there's no phosporous in the screen to save). After about four minutes with no keys being pushed, the calculator will shut down the screen and wait until a key is pressed.

The actual APD is just a counter in memory that is decreased every interrupt (so interrupts must be enabled). When a key is pressed, that counter starts all over again from the top. If the counter wound down because no key was pressed, the interrupt handler will shut down and will not be exited until the [ON] key is pressed. The screen is saved and, when turned back on, will be displayed again along with program execution resuming.

There are a few addresses and constants you must know about before you start working with the APD.

;call equates for handlers
_APDHandler	=$4058	;main handler
_idle		=$405c	;shuts down if _APDWarmUp=$00
_APDSetup	=$4060	;resets _APDTimer to $a1

;memory addresses for apd counters
_APDSubTimer	=$c009	;APD sub-timer
_APDTimer	=$c00a	;APD timer
_APDWarmUp	=$c00b

;system flags at iy offset 8
APDable	=2		;enable APD counter
APDlock	=3		;lock APD
APDdone	=4		;APD has expired

The above calls have no inputs. Let's say you want to turn off the TI86 if nothing's been pressed in a while, just call '_idle'. It will check to see if it's time to shut down the calculator based on the interrupt handler's checking the status of keypresses. If you want to reset the _APD so it's fresh again, just call '_APDSetup'. That will reset the counter at '_APDTimer' to $a1 (its default value).

At '_APDHandler', TI-OS performs it's own updating of the APD counters. This is run from the interrupt handler, so don't use it on your own.

If you want to turn off the APD, reset APDable of the system flags. You need to set it before exiting your program of the calculator won't enable it again.

Here's the code for the APD routines from the TI86's ROM. The left most numbers are the address of the code in hexadecimal, then comes the code. Keep in mind that this is for ROM version 1.6. The first three sets of code will be the same on all ROM versions but where they refer to may be different among versions.

_APDHandler: 		;($4058)
	call sub _APDHandler	;($0170)
	ret

_idle:				;($405c)
	call sub _idle		;($0194)
	ret

_APDSetup:			;($4060)
	call sub _APDSetup	;($019b)
	ret

sub _APDHandler:
	ld hl,_APDWarmUP
	ld a,(hl)
	or a
	jr z,$0178
	dec (hl)
	ld a,($c3ed)	;the apd flag set
	bit 2,a		;APDable
	ret z		;not turned on so ret
	bit 3,a		;APDlock
	ret z		;unlocked so leave
	ld hl,_APDSubTimer
	dec (hl)
	ret nz
	inc hl		;not at _APDTimer
	dec (hl)
	ret nz
	res 3,(iy+8)	;unlock APD
	set 4,(iy+8	;tell ti-os it ran out
	jp $0c34	; -> shutdown routine

sub _idle:
	ld a,(_APDWarmUP)
	or a
	ret nz
	halt		;wait for interrupt
	ret

sub _APDSetup:
	ld hl,_APDTimer	;main counter
	ld (hl),$a1	;reset counter (%10100001)
	ret


More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS