;Sector 30h/70h routines include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON newSectorStart: ;---------------------------------------- ;Vector table for OS replacement routines ;DO NOT MODIFY THESE jp SendCByte jp ContinueGetByte jp Rec1stByteNC jp RecAByteIO jp Send4Bytes ;---------------------------------------- SendCByte: ld a,c push bc bit 1,(iy+3Ah) ld b,1 call nz,CallIOLinkHook pop bc ld c,a ret nz B_CALL NZIf83Plus jr z,SendCByteLA ld b,8 SCB_ByteLoop: ld de,0FFFFh rr c jr nc,$F ld a,2 jr SCB_Continue $$: ld a,1 SCB_Continue: ld a,1 out (0),a SCB_BitLoop: in a,(0) and 3 jr z,SCB_BitDone in a,(0) and 3 jr z,SCB_BitDone dec de ld a,d or e jr nz,SCB_BitLoop LinkError: B_JUMP JErrorNo SCB_BitDone: ld a,0 out (0),a ld de,0FFFFh SCB_BitReallyDone: dec de ld a,d or e jr z,LinkError in a,(0) and 3 cp 3 jr nz,SCB_BitReallyDone djnz SCB_ByteLoop ret SendCByteLA: call EnableLinkAssist call ResetDelayCounter call ResetDelayCounter SCB_LA_Loop: ld a,0FAh ld (9C86h),a in a,(9) bit 5,a jr z,$F ld a,c out (0Dh),a ret $$: call NZIfTimeout jr z,SCB_LA_Loop jr flagErrLinkXmit nopFlagErrLinkXmit: nop flagErrLinkXmit: ld a,(iy+3Dh) and 0F0h ld (iy+3Dh),a errLinkXmit: B_JUMP ErrLinkXmit ResetDelayCounter: push hl ld hl,0FFFFh in a,(20h) and 1 jr nz,$F ld hl,6800h $$: ld (9CACh),hl pop hl ret NZIfTimeout: push hl ld h,2 $$: dec h jr nz,$B ld hl,(9CACh) dec hl ld (9CACh),hl ld a,l or h jr nz,$F ld a,1 jr timeoutRet $$: ld a,0 timeoutRet: or a pop hl ret MaybeEnableLinkAssist: B_CALL NZIf83Plus ret nz EnableLinkAssist: bit 0,(iy+3Eh) ret nz set 0,(iy+3Eh) in a,(9) xor a out (8),a ret ContinueGetByteReturn: push bc bit 1,(iy+3Ah) ld b,6 call nz,CallIOLinkHook pop bc ret ContinueGetByte: push hl ld hl,ContinueGetByteReturn ex (sp),hl push bc bit 1,(iy+3Ah) ld b,2 call nz,CallIOLinkHook pop bc ret nz di res 5,(iy+3Dh) B_CALL NZIf83Plus jr nz,CGBNoLA di call ReceiveLAByteToC cp 0 jr z,CGB_Continue ld a,c cp 0E0h jr z,CGB_TIKeyboardStuff jr flagErrLinkXmit CGBNoLA: ld b,8 call ReceiveByteToC_ready cp 0 jr nz,errLinkXmit CGB_Continue: ld a,c cp 0E0h ret nz in a,(2) and 80h jr z,$F in a,(9) bit 6,a jr nz,CGB_TIKeyboardStuff res 0,(iy+3Eh) ld a,80h out (8),a $$: call DoReceive2 jr c,EnableLinkAssistCtoA jr z,$F jr EnableLinkAssistCtoA $$: nop CGB_TIKeyboardStuff: call DoFinalReceive jr nz,nopFlagErrLinkXmit set 5,(iy+3Dh) ld b,a ld a,(9CAFh) or a ld a,b ret nz call KeyboardRoutine res 0,(iy+1Dh) ret KeyboardRoutine: ld (9CB0h),a and 7Fh cp 7Fh jr z,KR_Continue cp 60h jr nc,KR_Continue cp 50h jr c,$F and 0Fh ld b,a ld a,0F0h and (iy+3Dh) or b ld (iy+3Dh),a jr KR_End $$: cp 41h jr nc,KR_Continue cp 12h jr z,KR_Continue cp 1Ah jr z,KR_Continue cp 24h jr z,KR_Continue cp 2Ch jr z,KR_Continue call ConvertKeyCode push af ld a,(9CB0h) ld b,a pop af or a jr z,KR_End ld c,a ld a,c ld (8444h),a ret KR_Continue: ld a,(iy+3Dh) and 0F0h ld (iy+3Dh),a KR_End:xor a ld (9CB0h),a ld (9CB1h),a ret ConvertKeyCode: or a ret z dec a ld c,a ld hl,keyTable1 ld a,(iy+3Dh) and 0Fh cp 8 jr z,$F ld hl,keyTable2 cp 4 jr nz,CKC_Continue1 $$: ld b,0 add hl,bc ld a,(hl) $$: ld (keyExtend),a ld a,0FBh jr CKC_End CKC_Continue1: cp 3 jr c,$F bit 6,(iy+3Dh) jr z,$F ld a,8Bh jr $B $$: ld hl,keyTable3 and 3 jr nz,$F ld hl,keyTable4 $$: push hl ld b,0 add hl,bc ld a,(hl) pop hl push af push hl ld de,8 sbc hl,de ld a,c srl a srl a srl a ld e,a add hl,de ld a,c and 7 inc a ld b,a ld a,(hl) $$: srl a djnz $B ld a,32h jr c,$F xor a $$: ld (9CB1h),a pop hl ld de,40h add hl,de ld a,(hl) or a jr z,CKC_Continue2 ld b,a ld a,c $$: inc hl cp (hl) jr z,CKC_AlmostDone inc hl djnz $B CKC_Continue2: pop af bit 3,(iy+24h) ret z ld b,a ld a,(iy+3Dh) and 3 ld a,(9CB0h) jr z,$F and 80h ld a,b ret z jr CKC_Continue3 $$: and 80h ld a,b ret nz CKC_Continue3: cp 9Ah ret c cp 0B4h ret nc add a,48h ld (keyExtend),a ld a,0FCh ret CKC_AlmostDone: pop af ld (keyExtend),a inc hl ld a,(hl) cp 0FBh ret nz CKC_End: ld c,a ld a,(keyExtend) bit 1,(iy+3Eh) jr z,CKC_End2 cp 0Dh jr z,$F cp 0Eh jr nz,CKC_End2 $$: ld a,c ret CKC_End2: bit 6,(iy+3Dh) jr nz,$B ld b,14h ld hl,keyTable5 $$: cp (hl) inc hl jr z,$F inc hl inc hl djnz $B cp 0Dh ld a,c ret c xor a ld (keyExtend),a ret $$: ld a,(hl) ld (keyExtend),a inc hl ld a,(hl) ret keyTable4: DB 8Fh,06h,0Dh,0AAh,9Ah,8Bh,0B3h,0Ah,90h,91h,9Eh,0B0h,0ACh,0B1h,9Ch,07h,92h,00h,0ABh,0ADh,9Dh,9Fh,0AFh,08h,93h,00h DB 0AEh,0B2h,0A1h,0A0h,9Bh,99h,94h,95h,0A2h,00h,0A3h,0A4h,0A7h,02h,97h,96h,0A8h,00h,08h,0A5h,0A6h,01h,8Eh,81h,0A9h DB 87h,27h,8Bh,8Bh,03h,21h,0Ah,08h,88h,05h,83h,8Dh,04h,08h,01h,0FBh,02h,0FBh,05h,0FBh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h,5Eh,8Ah keyTable5: DB 0Dh,00h,99h,20h,00h,09h,0Eh,00h,99h,41h,00h,40h,18h,00h,8Ch,17h,0Bh,0FEh,22h,0Fh,0FEh,24h,0Dh,0FEh,26h,00h,49h,27h DB 00h,48h,28h,00h,2Eh,29h,00h,5Ah,2Ah,00h,44h,1Dh,00h,3Eh,0Fh,00h,0Bh,4Dh,00h,0Eh,4Eh,00h,0Fh,8Bh,00h,00h,23h,00h,0Bh DB 19h,00h,2Ch Rec1stByteNCReturn: push bc bit 1,(iy+3Ah) ld b,7 call nz,CallIOLinkHook pop bc ret Rec1stByteNC: push hl ld hl,Rec1stByteNCReturn ex (sp),hl push bc bit 1,(iy+3Ah) ld b,3 call nz,CallIOLinkHook pop bc ret nz di res indicOnly,(iy+indicFlags) ld a,5 push af $$: in a,(2) and 2 jr z,$B pop af out (10h),a ei B_CALL NZIf83Plus jr nz,Rec1st83P call EnableLinkAssist call LAReceiveByteToC jr RABIO Rec1st83P: B_CALL CHKERRBREAK B_CALL HandleLinkKeyActivity in a,(0) and 3 cp 3 jr z,Rec1st83P set indicOnly,(iy+indicFlags) ld b,8 call ReceiveByteToC_ready jr RABIO LAReceiveByteToC: B_CALL CHKERRBREAK B_CALL HandleLinkKeyActivity in a,(9) and 58h jr z,LAReceiveByteToC set indicOnly,(iy+indicFlags) jr ReceiveLAByteToC RecAByteIOReturn: push bc bit 1,(iy+3Ah) ld b,8 call nz,CallIOLinkHook pop bc ld c,a ret RecAByteIO: push hl ld hl,RecAByteIOReturn ex (sp),hl push bc bit 1,(iy+3Ah) ld b,4 call nz,CallIOLinkHook pop bc ld c,a ret nz RecAByteIOStart: di call ReceiveByteToC RABIO: call RecAByteIO_sub ret c ret nz jr z,RecAByteIOStart RecAByteIO_sub: cp 1 ld a,c jr nz,$F cp 0E0h jr nz,errLinkXmit jr RABIOAlmostDone $$: cp 0E0h ret nz in a,(2) and 80h jr z,$F in a,(9) bit 6,a jr nz,RABIOAlmostDone and 19h jr nz,CtoAret $$: call DoReceive jr c,doEnableLinkAssistCtoA jr nz,EnableLinkAssistCtoA RABIOAlmostDone: call DoFinalReceive xor a ret CtoAret; ld a,c ret DoFinalReceive: call DisableLinkAssist call FixLink jr c,errLinkXmit in a,(2) and 80h call nz,enableLA call ReceiveByteToC ld d,a ld a,c cp 1 push af push de call ReceiveByteToC pop de ld e,a pop af ld b,a ld a,c ret FixLink: push hl in a,(2) and 80h jr z,$F ld hl,39h in a,(20h) and 1 jr nz,FixLinkContinue $$: ld hl,17h FixLinkContinue: dec hl ld a,h or l jr z,scfP1CtoAret in a,(0) and 3 jr z,FixLinkContinue jr P1CtoAret enableLA: ld a,80h out (8),a xor a out (8),a in a,(9) set 0,(iy+3Eh) xor a ret DisableLinkAssist: in a,(2) and 80h ret z in a,(9) and 99h ret nz res 0,(iy+3Eh) ld a,80h out (8),a ret doEnableLinkAssistCtoA: nop EnableLinkAssistCtoA: call MaybeEnableLinkAssist ld a,c or a ret DoReceive2: push hl in a,(2) and 80h jr z,ReceiveNoLA ld hl,37h in a,(20h) and 1 jr z,ReceiveNoLA jr ReceiveNoLA2 DoReceive: push hl in a,(2) and 80h jr z,ReceiveNoLA ld hl,28h in a,(20h) and 1 jr nz,$F ld l,10h $$: dec hl ld a,h or l jr z,scfP1CtoAret in a,(9) bit 6,a jr nz,$F bit 4,a jr nz,P1CtoAret and 8 jr z,$B in a,(9) bit 6,a jr nz,$F and 19h jr z,$B jr nz,P1CtoAret $$: xor a jr P1CtoAret ReceiveNoLA: ld hl,16h ReceiveNoLA2: $$: dec hl ld a,h or l jr z,scfP1CtoAret in a,(0) and 3 cp 3 jr z,$B in a,(0) and 3 cp 3 jr z,$B or a P1CtoAret: pop hl ld a,c ret scfP1CtoAret: scf jr P1CtoAret ReceiveByteToC: ld b,8 RBTC_Byte_Loop: B_CALL NZIf83Plus jr z,ReceiveLAByteToC ld de,0FFFFh jr RBTC_Start_Loop RBTC_Loop: in a,(0) and 3 jr z,flagErrLinkXmit cp 3 jr nz,ReceiveByteToC_ready in a,(0) and 3 jr z,flagErrLinkXmit cp 3 jr nz,ReceiveByteToC_ready RBTC_Start_Loop: dec de ld a,d or e jr nz,RBTC_Loop jr errLinkXmit ReceiveByteToC_ready: cp 2 jr z,RBTC_is2 ld a,1 out (0),a rr c ld de,0FFFFh $$: in a,(0) and 3 cp 2 jr z,RBTC_Continue dec de ld a,d or e jr nz,$B B_JUMP JErrorNo RBTC_Continue: ld a,0 out (0),a ld d,4 $$: dec d jr z,$F in a,(0) and 3 cp 3 jr nz,$B $$: djnz RBTC_Byte_Loop ld a,0 ret RBTC_is2: ld a,2 out (0),a rr c ld de,0FFFFh $$: in a,(0) and 3 cp 1 jr z,RBTC_Continue dec de ld a,d or e jr nz,$B B_JUMP JErrorNo ReceiveLAByteToC: call EnableLinkAssist call ResetDelayCounter call ResetDelayCounter $$: ld a,0 ld (9C86h),a call NZIfTimeout jr nz,flagErrLinkXmit in a,(9) bit 6,a jr nz,$F and 11h jr z,$B in a,(0Ah) ld c,a ld a,0 ret $$: and 11h jr z,flagErrLinkXmit in a,(0Ah) ld c,a ld a,1 ret Send4Bytes: push bc bit 1,(iy+3Ah) ld b,5 call nz,CallIOLinkHook pop bc ret nz call MaybeEnableLinkAssist ld hl,250 $$: dec hl ld a,h or l jr nz,$B S4BLoop: B_CALL NZIf83Plus jr z,S4BLA ld a,0 out (0),a in a,(0) and 3 cp 3 jr z,S4BSendBytes S4BReceivedByte: call ReceiveByteToC call RecAByteIO_sub jr c,errLinkXmit jr z,S4BLoop S4BLA: in a,(9) and 19h jr nz,S4BReceivedByte S4BSendBytes: ld hl,0 ld (header+4),hl ld a,(header) B_CALL SendAByte ld a,(header+1) B_CALL SendAByte ld a,(header+2) B_CALL SendAByte ld a,(header+3) B_CALL SendAByte ret CallIOLinkHook: push af push hl ld hl,9BD8h call GetHookByte pop hl jr z,$F pop af res 1,(iy+3Ah) ret $$: pop af push hl ld hl,hookExecTemp ex (sp),hl B_JUMP OffPageJump GetHookByte: push bc push de ld e,(hl) inc hl ld d,(hl) inc hl ld a,(hl) cp 0FFh jr z,$F ld (hookExecTemp+2),a ex de,hl B_CALL GetBytePaged inc hl ld (hookExecTemp),hl ld a,b $$: pop de pop bc cp 83h ret newSectorEnd: