coorMon:
res g_style_active, (iy+sGrFlags)
call j_CursorOff
call j_COORDISP
Mon: call j_RunIndicOff
call j_CursorOn
res displayCoords, (iy+newDispF)
bit sendFinalPacketOnMon, (iy+linkFlags2)
jr z, Mon_NoPacketSend
di
res sendFinalPacketOnMon, (iy+linkFlags2)
ld hl, Mon_ResetIndicOnly
call pushErrorHandleR
set indicOnly, (iy+indicFlags)
ld a, (mcxCurApp)
cp kError
jr nz, {+}
ld a, (errNo)
call j_SendSkipExitPacket
jr Mon_LinkEnd
+: call j_SendAck
Mon_LinkEnd:
call popErrorHandleR
Mon_ResetIndicOnly:
res indicOnly, (iy+indicFlags)
ei
Mon_NoPacketSend:
xor a
ld (kbdKey), a
ld (keyExtend), a
call j_getkey
monForceKey:
res recallingPrgmName, (iy+rclFlag2)
res recallingListName, (iy+rclFlag3)
ld (kbdKey), a
bit 0, (iy+2)
jr z, page0_433
res curAble, (iy+curFlags)
bit curOn, (iy+curFlags)
call z, j_BLINKGCUR
ld a, (kbdKey)
jr page0_436
page0_433:
call j_CursorOff
page0_436:
call j_RunIndicOn
or a
jr nz, page0_44D
bit appWantIntrpt, (iy+appFlags)
jr nz, page0_448
page0_442:
res onInterrupt, (iy+onFlags)
jr page0_4B2
page0_448:
ld a, 5
jp sendKPress
page0_44D:
cp 0B4h ; 'ԧ
jr nz, page0_470
ld a, 0CCh ; '̧
call IsFunctionMode
jr nz, page0_46D
ld a, 0ADh ; 'ͧ
sub_45A:
call IsParametricMode
jr nz, page0_46D
ld a, 0B1h ; 'ѧ
page0_461:
call IsFuncMode
jr nz, page0_46D
ld a, 0E8h ; '觍
ld (keyExtend), a
ld a, 0FEh
page0_46D:
ld (kbdKey), a
page0_470:
res 1, (iy+28h)
res 2, (iy+28h)
bit rawKeyHookActive, (iy+hookflags2)
jr z, page0_491
call j_call_rawkey_hook
bit 1, (iy+28h)
jr nz, page0_4B2
bit 2, (iy+28h)
jr z, page0_491
push af
jp page0_53E
page0_491:
cp 3Fh ; '?'
jr z, page0_4A2
call j_PULLDOWNCHK
jr c, page0_4B2
call j_clrTR
jr c, page0_4B2
call page0_7DE
page0_4A2:
jr z, sendKPress
cp 28h ; '('
jr z, sendKPress
cp 29h ; ')'
jr z, sendKPress
jr page0_4D0
page0_4AE:
pop hl
pop bc
djnz page0_4BA
page0_4B2:
jp coorMon
page0_4B5:
ld b, 8
ld hl, progToEdit-1
page0_4BA:
inc hl
ld a, (hl)
or a
jr z, page0_4B2
push bc
push hl
ld d, 0
ld e, a
call j_TokToKey
call cxMain
res onInterrupt, (iy+onFlags)
jr page0_4AE
page0_4D0:
cp 7Fh ; ''
jp c, page0_595
cp 0FEh ; '
jr z, sendKPress
cp 0FCh ; '𧍊
jr z, sendKPress
cp 0FBh ; '
jr nz, page0_4FA
ld a, (keyExtend)
or a
jr z, page0_4F7
cp 0Dh
jr c, page0_4F3
cp 8Ch ; '̧
jr c, page0_549
cp 0A6h ; 'Ƨ
jr nc, page0_549
page0_4F3:
ld a, 0FBh ;
jr sendKPress
page0_4F7:
ld a, (kbdKey)
page0_4FA:
cp 0EFh ; '留
jr nz, page0_502
ld a, 0A6h ; 'Ƨ
jr page0_510
page0_502:
cp 0F9h ; '
jr c, page0_50A
sub 14h
jr page0_510
page0_50A:
cp 0F3h ; '
jr c, sendKPress
sub 7Ch ; '|'
page0_510:
ld (keyExtend), a
ld a, 0FEh ; '
sendKPress:
cp 69h ; 'i'
jr nz, page0_51D
ld a, 0FCh ; '𧍊
jr page0_510
page0_51D:
cp 5Bh ; '['
jr nz, page0_525
ld a, 0FDh ; '
jr page0_510
page0_525:
cp 28h ; '('
push af
jr nz, page0_532
set recallingPrgmName, (iy+rclFlag2)
ld a, 0DAh ; 'ڧ
jr page0_53E
page0_532:
pop af
cp 29h ; ')'
push af
jr nz, page0_53E
set recallingListName, (iy+rclFlag3)
ld a, 7Fh ; ''
page0_53E:
call cxMain
res onInterrupt, (iy+onFlags)
pop af
jp z, page0_4B5
page0_549:
bit enableQueue, (iy+rclFlag)
jr z, page0_58E
ld de, (rclQueue)
page0_553:
ld hl, (editCursor)
bit useRclQueueEnd, (iy+hookflags1)
jr z, page0_560
ld hl, (rclQueueEnd)
ex de, hl
page0_560:
call CpHLDE
jr nc, page0_580
ld a, (hl)
call page0_172F
ld d, 0
ld e, a
jr nz, page0_571
ld d, a
inc hl
ld e, (hl)
page0_571:
bit useRclQueueEnd, (iy+hookflags1)
jr z, page0_57B
inc hl
ld (rclQueue), hl
page0_57B:
call j_TokToKey
page0_57E:
jr sendKPress
page0_580:
res enableQueue, (iy+rclFlag)
ld hl, 89F5h
ld a, (promptIns)
res 4, (hl)
or (hl)
ld (hl), a
page0_58E:
res useRclQueueEnd, (iy+hookflags1)
jp Mon
page0_595:
cp 27h ; '''
jr c, page0_57E
cp 5Ah ; 'Z'
jr c, page0_5C2
cp 75h ; 'u'
jr nc, page0_5BC
bit 0, (iy+9)
jr nz, page0_57E
cp 69h ; 'i'
jr c, page0_5BC
cp 6Dh ; 'm'
jr z, page0_5BC
cp 69h ; 'i'
jr z, page0_57E
ld b, a
ld a, (mcxCurApp)
cp 44h ; 'D'
ld a, b
jr nz, page0_57E
page0_5BC:
ld b, a
ld a, 44h ; 'D'
jr page0_5D0
push af
page0_5C2:
ld b, a
cp 59h ; 'Y'
jr nz, page0_5D0
ld a, (keyExtend)
add a, b
cp 5Bh ; '['
jr nc, JForceCmdNoChar
ld b, a
page0_5D0:
ld c, a
ld a, (mcxCurApp)
cp 50h ; 'P'
jr nz, page0_5E1
ld a, b
cp 40h ; '@'
jr z, JForceCmdNoChar
ld a, 50h ; 'P'
jr page0_5EA
page0_5E1:
cp 52h ; 'R'
ld a, c
jr nz, page0_5EA
cp 40h ; '@'
jr nz, page0_58E
page0_5EA:
call newContext0
ld a, b
jp page0_525
JForceCmdNoChar:
xor a
JForceCmd:
ld b, a
ld sp, (onSP)
res 6, (iy+0Ch)
call SetFastSpeed
ld a, 40h ; '@'
call newContext0
ld a, b
cp 0DAh ; 'ڧ
jr nz, page0_60D
ld a, 28h ; '('
page0_60A:
jp sendKPress
page0_60D:
cp 7Fh ; ''
jr nz, page0_60A
ld a, 29h ; ')'
jr page0_60A
sysErrHandler:
ld sp, (onSP)
ld a, 52h ; 'R'
call newContext
jp Mon
ret
newContext:
ld c, a
sub a
ld (kbdKey), a
ld b, a
in a, (6)
push af
ld a, c
call newContext0
pop af
sub_630:
out (6), a
ret
newContext0:
res appRetKeyOff, (iy+APIFlg)
ld hl, 859Ah
cp (hl)
jr nz, page0_64E
cp 44h ; 'D'
jr nz, page0_647
push bc
page0_642:
call j_GRPUTAWAY
pop bc
ret
page0_647:
cp 40h ; '@'
jr z, page0_64E
ld b, 27h ; '''
ret
page0_64E:
push bc
push af
pop af
page0_651:
cp 3Fh ; '?'
jr nz, page0_65B
ld a, 40h ; '@'
push af
xor a
jr page0_664
page0_65B:
push af
page0_65C:
sub 40h ; '@'
jr nz, page0_664
res 6, (iy+0Ch)
page0_664:
call Page0Call_3F51
pop af
push hl
push af
res curLock, (iy+curFlags)
call cxPutAway2
pop af
push af
ld b, a
ld a, (mcxCurApp)
cp 47h ; 'G'
ld a, b
jr z, page0_68E
bit 0, (iy+9)
jr z, page0_68E
cp 57h ; 'W'
jr z, page0_69E
cp 45h ; 'E'
jr z, page0_69E
cp 4Bh ; 'K'
jr z, page0_69E
page0_68E:
call Page0Call_3F57
cp 52h ; 'R'
jr z, page0_69E
call cxPPutAway
call page0_7DE
call z, SetFastSpeed
page0_69E:
ld a, (mcxCurApp)
pop bc
push af
push bc
cp 52h ; 'R'
jr nz, page0_6B4
call j_POPCX
call sub_73D
call page0_7DE
call z, SetFastSpeed
page0_6B4:
ld hl, 858Dh
ld de, 859Bh
ld bc, 0Eh
ldir
ld a, (appFlagsAddr)
ld (de), a
pop af
push af
cp 4Ah ; 'J'
jr nz, page0_6CE
call Page0Call_3F63
jr page0_707
page0_6CE:
cp 44h ; 'D'
call z, Page0Call_3F63
jr z, page0_6DF
set 6, (iy+1Dh)
set 7, (iy+1Dh)
jr page0_707
page0_6DF:
call page0_17DB
call CheckSplitFlag
jr z, page0_707
ld a, (mcxCurApp)
call j_CompareContext
jr nz, page0_707
ld a, 40h ; '@'
ld (mcxCurApp), a
ld hl, Page0Call_3F6F
ld a, (iy+12h)
push af
ld a, 40h ; '@'
call sub_71D
call cxPutAway
pop af
ld (iy+12h), a
page0_707:
pop af
pop bc
cp 46h ; 'F'
jr nz, page0_718
push af
ld a, b
cp 52h ; 'R'
jr z, page0_717
set promptEdit, (iy+promptFlags)
page0_717:
pop af
page0_718:
pop hl
ld (mcxCurApp), a
pop af
sub_71D:
bit 2, (iy+36h)
call nz, Page0Call_3F75
push af
set 5, (iy+1)
call sub_7A1
res 5, (iy+1)
pop bc
ret
page0_732:
add a, a
ld e, a
ld d, 0
add hl, de
jp ldHLind
cxPutAway:
call cxPutAway2
sub_73D:
call cxPPutAway
page0_740:
res promptEdit, (iy+promptFlags)
ret
cxPutAway2:
bit nocxPutAway, (iy+contextFlags)
ret nz
push hl
ld hl, (mcxPPutAway)
page0_74E:
call sub_77F
jr page0_762
cxPPutAway:
bit nocxPutAway, (iy+contextFlags)
ret nz
push hl
ld hl, (mcxPutAway)
call sub_77F
call zero_basic_prog
page0_762:
pop hl
page0_763:
jp CancelAlpha
cxRedisp:
ld hl, (unk_8593)
jr sub_77F
cxSizeWind:
bit 5, (iy+1)
push af
ld a, (menuActive)
ld b, a
page0_774:
ld hl, (mcxSizeWind)
sub_777:
call sub_77F
pop af
ret
cxErrEP:
ld hl, (mcxErrorEP)
sub_77F:
in a, (6)
push af
ld a, (mcxPage)
call sub_630
call sub_7A1
pop af
call sub_630
ret
cxMain:
push hl
ld hl, (mcxMain)
push af
ld a, (mcxPage)
call sub_630
pop af
call sub_7A1
pop hl
ret
sub_7A1:
jp (hl)
page0_7A2:
ld a, (unk_85A7)
call sub_630
ld hl, (unk_85A1)
jr sub_7A1
monErrHand:
ld hl, monErrHand
call pushErrorHandleR
ld a, 52h ; 'R'
call newContext0
jp Mon
push hl
ld hl, 64h ; 'd'
jr page0_7C5
page0_7C1:
push hl
ld hl, 32h ; '2'
page0_7C5:
call EnoughMem
jp c, Page0Call_24F9
pop hl
AppInit:
ld de, mcxMain
ld bc, 12
ldir
ld a, (hl)
ld (appFlagsAddr), a
in a, (6)
ld (mcxPage), a
ret
page0_7DE:
ld b, a
ld a, (mcxCurApp)
cp 58h ; 'X'
ld a, b
ret
handleONKeyPress:
;Switch to slow speed
in a, (2)
and 80h
jr z, {+}
in a, (20h)
ld e, a
xor a
out (20h), a
+: ld b, 0
debounceRestart:
ld hl, 1016h
debounceLoop:
in a, (4)
and 8
cp b
ld b, a
jr nz, debounceRestart
dec hl
ld a, l
or h
jr nz, debounceLoop
cp b
jr z, ONKeyBeingPressed
;ON key is being released
in a, (7)
ld b, a
in a, (2)
and 80h
jr z, {+}
;Restore previous speed
ld a, e
out (20h), a
ld a, b
cp 81h
jr isRAMUnhooked
+: ld a, b
and 4Fh
cp 41h
isRAMUnhooked:
jp nz, RAMUnhookedWaitForPowerOn
bit onRunning, (iy+onFlags)
ret nz
;ON key being released and we're just off, so just return from the interrupt handler
pop hl
sub a
push af
ld a, 8
out (3), a
pop af
out (3), a
ld a, 11h
jp noSecondHardwareTimer
ONKeyBeingPressed:
;Restore previous speed
in a, (2)
and 80h
jr z, HandlePowerOnRequest
ld a, e
out (20h), a
.module HandlePowerOnRequest
HandlePowerOnRequest:
ld a, 76h
out (4), a
in a, (2)
and 80h
jr z, {+}
in a, (7)
cp 81h
jr _isRAMUnhooked
+: in a, (7)
and 4Fh
cp 41h
_isRAMUnhooked:
jp nz, HookRAMAndPowerOn
bit shift2nd, (iy+shiftFlags)
jp z, HandleONPressed
;2nd is being pressed, so we might be turning off
bit enableKeyEcho, (iy+hookflags1)
jr nz, {+}
bit appRetKeyOff, (iy+APIFlg)
jr z, PowerOff
+: set kOffPressed, (iy+APIFlg)
ret
.endmodule
.module PowerOff
PowerOff:
ld a, 8
push af
ld a, 8
out (3), a
pop af
out (3), a
call TurnOffLCD
bit resetOnPowerOn, (iy+selfTestFlag)
jr z, {+}
;If above flag is set and APD is disabled, skip RAM checksum generation (forcing a reset)
bit apdAble, (iy+apdFlags)
jr z, _skipRAMChecksum
+: call SetFastSpeed
call PreviousContext_CloseAnyOpenMenu
call j_hideCursor
set monAbandon, (iy+monFlags)
ld hl, lcdFlag
set powerLcdForGC, (hl)
call forcecmd
ld hl, lcdFlag
res powerLcdForGC, (hl)
res monAbandon, (iy+monFlags)
bit alt_Off, (iy+hookflags1)
call nz, j_ExecuteOFFSCRPT
_DoShutDown:
call j_SetupDBusMem
ld a, 8
out (3), a
call TurnOffLCD
ld hl, flags+onFlags
bit clrScrnOnPowerOff, (hl)
res clrScrnOnPowerOff, (hl)
call nz, j_ClrScrn
call calculateRAMChecksum
ld (RAMChecksum), hl
_skipRAMChecksum:
res bPLinkOn, (iy+hookflags1)
res enableKeyEcho, (iy+hookflags1)
ld a, 36h
out (4), a
ld a, 11h
out (3), a
res shift2nd, (iy+shiftFlags)
res onRunning, (iy+onFlags)
ex af, af'
exx
ei
-: halt
jr {-}
.endmodule
HandleONPressed:
res checkNoBatteriesNextTime, (iy+batteryFlags2)
call ApdSetup
bit onRunning, (iy+onFlags)
jr nz, page0_94D
page0_8F1:
set onRunning, (iy+onFlags)
ld hl, flags+apdFlags
bit 4, (hl)
res 4, (hl)
jr nz, page0_92C
res indicInUse, (iy+indicFlags)
bit resetOnPowerOn, (iy+selfTestFlag)
jr z, page0_90D
bit 2, (hl)
jp z, resetRam
page0_90D:
ld sp, (onSP)
call j_resetStacks
xor a
ld (MenuCurrent), a
call refreshSystemRAM
call sub_ADA
call Page0Call_3E97
bit 6, (iy+0Ch)
call nz, Page0Call_3E9D
ei
jp Mon
page0_92C:
bit alt_On, (iy+hookflags1)
call nz, j_ExecuteONSCRPT
ld a, 8
push af
ld a, 8
out (3), a
pop af
out (3), a
call j_RstrOScreen
pop de
pop de
pop de
set 3, (hl)
call sub_ADA
ex af, af'
exx
ei
reti
page0_94D:
set onInterrupt, (iy+onFlags)
ret
HookRAMAndPowerOn:
ld a, 76h ; 'v'
out (4), a
ld a, 0C0h ; ''
out (0), a
in a, (2)
and 80h ; ''
ld a, 41h ; 'A'
jr z, page0_96B
ld a, 1
out (20h), a
xor a
out (0Fh), a
ld a, 81h ; 'g
page0_96B:
out (7), a
xor a
push af
ld a, 8
out (3), a
pop af
out (3), a
ld iy, 89F0h
call NZIf83Plus
call z, Page0Call_3EAF
ld hl, (RAMChecksum)
ld de, 0A55Ah
call CpHLDE
jp z, doFunkyTurnOnFromA55AChecksum
call NZIf83Plus
jr z, page0_9A0
ld b, 0
B_CALL(_getHardwareVersion)
bit 0, b
ld a, 1Fh
jr z, page0_9A2
ld a, 1Ch
jr page0_9A2
page0_9A0:
ld a, 17h
page0_9A2:
ld (contrast), a
call calculateRAMChecksum
ld de, (RAMChecksum)
call CpHLDE
jr nz, resetRam
dec de
ld (RAMChecksum), de
call Page0Call_3EB5
call PreviousContext_CloseAnyOpenMenu
ld a, 0Bh
out (3), a
res apdWarmStart, (iy+apdFlags)
call forcecmd
jp page0_8F1
resetRam:
di
ld hl, 8000h
ld de, 8001h
ld bc, 7FFFh
ld (hl), 0
ldir
ld hl, 109h
ld (localLanguage), hl
;#ifdef DEVIATE_FROM_ORIGINAL_FILE
; call NZIfColorModel
; jr z, {+}
; set 0, (iy+asm_Flag3)
;+:
;#endif
page0_9DE:
ld a, 0C0h ; ''
out (0), a
ld sp, 0FFF7h
call Page0Call_3EBB
ld hl, monErrHand
call pushErrorHandleR
ld (onSP), sp
call Page0Call_3EC1
jp Page0Call_3EC7
page0_9F8:
di
ld a, 0C0h ; ''
out (0), a
ld sp, 0FFF7h
ld hl, 8000h
ld de, 8001h
ld bc, 7FFFh
ld (hl), 0
ldir
ld hl, 109h
ld (localLanguage), hl
call Page0Call_3EBB
ld hl, monErrHand
call pushErrorHandleR
ld (onSP), sp
call Page0Call_3EC1
jp Page0Call_3ECD
page0_A26:
call GetCSC
set 2, (iy+9)
call j_getkey
call j_ClrScrn
res 2, (iy+9)
jp monForceKey
calculateRAMChecksum:
push ix
ld ix, 9D95h
ld bc, 60DBh
ld hl, 11h
ld d, h
page0_A47:
ld e, (ix+0)
inc ix
add hl, de
dec bc
ld a, c
or b
jr nz, page0_A47
ld e, d
ex de, hl
sbc hl, de
pop ix
ret
forcecmd:
call CanAlphIns
res textInverse, (iy+textFlags)
call j_Disp
res 6, (iy+0Ch)
ld a, 40h ; '@'
jp newContext0
bootCalc:
call SetSlowSpeed
ld a, 77h ; 'w'
out (4), a
ld b, 0
ld sp, 0FDFAh
page0_A78:
djnz $
ld ix, 1
add ix, sp
ld sp, ix
jr nc, page0_A78
ld sp, 0FFC5h
in a, (2)
and 80h ; ''
jr z, page0_A91
ld a, 1
out (20h), a
page0_A91:
ld a, 77h ; 'w'
out (4), a
im 1
ld a, 0C0h ; ''
out (0), a
RAMUnhookedWaitForPowerOn:
ld a, 37h ; '7'
out (4), a
sub a
push af
ld a, 8
out (3), a
pop af
out (3), a
ld a, 11h
out (3), a
ei
halt
lcd_busy:
push af
page0_AAF:
in a, (2)
and 2
jr z, page0_AAF
pop af
ret
page0_AB7:
TurnOffLCD:
ld a, 2
page0_AB9:
push af
loop:
in a, (2)
and 2
jr z, loop
pop af
out (10h), a
ret
page0_AC4:
smallDelay:
push af
inc hl
dec hl
pop af
ret
page0_AC9:
slowDelay:
ld a, 0FFh
slowDelayA:
push af
call forceSlowSpeed
pop af
delayLoop:
call smallDelay
dec a
jr nz, delayLoop
call restorePreviousSpeed
ret
sub_ADA:
ld a, 0Bh
out (3), a
call j_LCD_DRIVERON
call Chk_Batt_Low_2
ret nz
call refreshSystemRAM
in a, (2)
bit 0, a
jp z, PowerOff._skipRAMChecksum
sub_AEF:
call Page0Call_3ED9
call forcecmd
jp Page0Call_3EDF
Chk_Batt_Low_2:
call refreshSystemRAM
Chk_Batt_Low:
ld a, 76h ; 'v'
out (4), a
ld a, 0F6h ; '
out (4), a
ld b, 5
longerDelay:
call slowDelay
djnz longerDelay
set 5, (iy+18h)
in a, (2)
bit 0, a
jr nz, {+}
res 5, (iy+18h)
+: ld a, 76h ; 'v'
out (4), a
ld a, 0Ah
call slowDelayA
ld a, 76h ; 'v'
out (4), a
bit 5, (iy+18h)
ret
.module RefreshSystemRAM
refreshSystemRAM:
ld bc, 2710h
ld hl, ramStart
-: ld a, (hl)
ld (hl), a
dec bc
ld a, b
or c
jr nz, {-}
ret
.endmodule
doFunkyTurnOnFromA55AChecksum:
ld hl, 0
ld (RAMChecksum), hl
ld sp, (onSP)
ld iy, flags
call Page0Call_3EE5
call PreviousContext_CloseAnyOpenMenu
call forcecmd
res apdWarmStart, (iy+apdFlags)
bit 6, (iy+0Ch)
call nz, Page0Call_3E9D
ld a, 0Bh
out (3), a
call j_LCD_DRIVERON
set onRunning, (iy+onFlags)
call Chk_Batt_Low_2
call z, sub_AEF
bit alt_On, (iy+hookflags1)
call nz, j_ExecuteONSCRPT
ei
jp Mon
PreviousContext_CloseAnyOpenMenu:
call IsInMenu
jr z, PreviousContext
xor a
ld (MenuCurrent), a
call j_rstrpartial
PreviousContext:
call j_PrevContext
ret
IsInMenu:
ld b, a
ld a, (MenuCurrent)
or a
ld a, b
ret
SetSlowSpeed:
call NZIf83Plus
ret nz
jr {+}
forceSlowSpeed:
call NZIf83Plus
ret nz
in a, (20h)
ld (oldSESpeed), a
+: push af
xor a
out (20h), a
pop af
ret
restorePreviousSpeed:
call NZIf83Plus
ret nz
ld a, (oldSESpeed)
and 1
out (20h), a
ret
SetExSpeed:
or a
SetSpeed_NZForFast:
jr z, SetSlowSpeed
SetFastSpeed:
push af
call NZIf83Plus
jr nz, {+}
ld a, 1
out (20h), a
+: pop af
ret
page0_BBD:
pop af
push hl
ld hl, SEspeed
dec (hl)
pop hl
call NZIf83Plus
jr nz, {+}
and 1
out (20h), a
+: pop af
pop af
pop af
ret