.module Sleep ;------------------------------------------------------------------------------- ;@doc:routine ; ; === Sleep.Initialise === ; ; Initialises the Sleep module. ; ; DESTROYED: ; REGISTERS ; * HL ; ;@doc:end ;------------------------------------------------------------------------------- Initialise ld hl,120 ld (Sleep.IdleTime),hl ; Automatic run-on. ;------------------------------------------------------------------------------- ;@doc:routine ; ; === Sleep.ResetIdleTimer === ; ; Resets the APD idle timer. ; ;@doc:end ;------------------------------------------------------------------------------- ResetIdleTimer push af push hl di ld hl,(Sleep.IdleTime) ld (Sleep.CountdownTimer.Seconds),hl ld a,115 ld (Sleep.CountdownTimer.CentiSeconds),a ei pop hl pop af ret ;------------------------------------------------------------------------------- ;@doc:routine ; ; === Sleep.SleepIfIdle === ; ; If the APD timer has expired, sleep the calculator - otherwise return. ; ;@doc:end ;------------------------------------------------------------------------------- SleepIfIdle push af push hl ld hl,(Sleep.CountdownTimer.Seconds) ld a,h or l jr nz,+ ld hl,(Sleep.IdleTime) ld a,h or l jr z,+ call Sleep call ResetIdleTimer + pop hl pop af ret ;------------------------------------------------------------------------------- ;@doc:routine ; ; === Sleep.Sleep === ; ; Puts the calculator into a low power state. ; ; DESTROYED: ; REGISTERS ; * AF. ; ;@doc:end ;------------------------------------------------------------------------------- Sleep .fcall "LCD.Busy" ld a,$02 out (Lcd.InstPort),a ld a,%00000001 ; Only On key should generate interrupts. out (3),a halt ; Clear Escape state that would have been set by pressing On. xor a ld (Interrupt.OnKey),a ld a,%00001011 out (3), a .fcall "LCD.Copy" .fcall "LCD.Busy" ld a,$03 out (Lcd.InstPort),a jp ResetIdleTimer .endmodule