#define TI84PCE ;#define TI84PCSE ;====== Includes =============================================================== PutMapFlags .equ 4Ah PutMapUseColor .equ 4 #ifdef TI84PCE .assume ADL=1 #include "ti84pce.inc" #define b_call(x) call x _FormReal .equ _GetKey + (3*11);0020DC0h _DelListEl .equ 0020E70h _IncLstSize .equ 0020E68h pTempCnt .equ 0D02596h ; I hope this is right. . . . #ifndef fillRectColor fillRectColor .equ 0D02AC0h #endif #define .daddr .dl scrapRam .equ 0D00000h #endif #ifdef TI84PCSE #include "ti84pcse.inc" #define .daddr .dw scrapRam .equ 8000h #ifndef fillRectColor fillRectColor .equ 0A5F4h #endif #endif ;====== Equates ================================================================ ; Flags RetFlags .equ asm_Flag1 Ret1 .equ 0 Ret1M .equ 1 Ret2 .equ 1 Ret2M .equ 2 RetForceList .equ 2 RetForceListM .equ 4 GetTokenFlags .equ RetFlags Get2ByteToken .equ 3 ConvFlags .equ RetFlags ConvOddNibble .equ 4 ; Variables QuitSp .equ scrapRam ListLocation .equ QuitSp + 3 ListIndex .equ ListLocation + 3 Ret1Value .equ ListIndex + 3 Ret2Value .equ Ret1Value + 3 ; Commands cmdRunIndicOff .equ 1 cmdCursorOff .equ cmdRunIndicOff + 1 cmdInverseTextOff .equ cmdCursorOff + 1 cmdDisableColor .equ cmdInverseTextOff + 1 cmdGetCursorPos .equ cmdDisableColor + 1 cmdGetFgColor .equ cmdGetCursorPos + 1 cmdGetBgColor .equ cmdGetFgColor + 1 cmdReadBuffer .equ cmdGetBgColor + 1 cmdReadBufferInc .equ cmdReadBuffer + 1 cmdRunIndicOn .equ cmdRunIndicOff + 10 cmdCursorOn .equ cmdCursorOff + 10 cmdInverseTextOn .equ cmdInverseTextOff + 10 cmdEnableColor .equ cmdInverseTextOff + 10 cmdSetCursorPos .equ cmdGetCursorPos + 10 cmdSetFgColor .equ cmdGetFgColor + 10 cmdSetBgColor .equ cmdGetBgColor + 10 cmdPutMap .equ cmdReadBuffer + 10 cmdPutC .equ cmdReadBufferInc + 10 cmdToggleRunIndic .equ cmdRunIndicOff + 20 cmdToggleCursor .equ cmdCursorOff + 20 cmdToggleInverseText .equ cmdInverseTextOff + 20 cmdToggleColor .equ cmdDisableColor + 20 ;====== Header ================================================================= .org userMem - 2 #ifdef TI84PCE .db tExtTok, tAsm84CeCmp #endif #ifdef TI83PCE .db tExtTok, tAsm84CeCmp #endif #ifdef TI84PCSE .db tExtTok, tAsm84CCmp #endif ;====== Start ================================================================== ; Check for input arguments call GetAnsLoc ret c ; Not found and 1Fh cp ListObj ret nz ; For fast egress ld (QuitSp), sp ; Make sure list isn't giant inc de ld a, (de) or a ret nz ; Reset flags ld (iy + RetFlags), 0 ; Return values, list index sbc hl, hl ld (Ret1Value), hl ld (Ret2Value), hl inc hl ld (ListIndex), hl TryNextCommand: ; Branch on input argument call GetListAInc ld hl, CommandBranchTable call BranchOnTable jr TryNextCommand Ret1Val: ld (Ret1Value), a ld a, (iy + RetFlags) or Ret1M and ~(Ret2M | RetForceListM) ld (iy + RetFlags), a ret Ret2Val: ld (Ret2Value), a ld a, (iy + RetFlags) or Ret1M | Ret2M and ~RetForceListM ld (iy + RetFlags), a ret GetVersion: ld hl, Version b_call(_Mov9ToOP1) b_call(_StoAns) jp ForceExit Version: .db 00, 80h, 11h, 20h, 0, 0, 0, 0, 0 GetHwType: ld hl, HwType b_call(_Mov9ToOP1) b_call(_StoAns) jp ForceExit HwType: #ifdef TI84PCSE .db 00, 80h, 40h, 0, 0, 0, 0, 0, 0 #endif #ifdef TI84PCE .db 00, 80h, 50h, 0, 0, 0, 0, 0, 0 #endif #ifdef TI83PCE .db 00, 80h, 60h, 0, 0, 0, 0, 0, 0 #endif RunIndicOff: b_call(_RunIndicOff) ret RunIndicOn: b_call(_RunIndicOn) ret ToggleRunIndic: ld a, (iy + indicFlags) xor 1 ld (iy + indicFlags), a ret CursorOff: b_call(_CursorOff) ret CursorOn: b_call(_CursorOn) ret ToggleCursor: ld a, (iy + curFlags) xor 4 ld (iy + curFlags), a ret InverseTextOff: res textInverse, (iy + textFlags) ret InverseTextOn: set textInverse, (iy + textFlags) ret ToggleInverseText: ld a, (iy + textFlags) xor 8 ld (iy + textFlags), a ret DisableColor: res PutMapUseColor, (iy + PutMapFlags) res textEraseBelow, (iy + textFlags) ret EnableColor: set PutMapUseColor, (iy + PutMapFlags) set textEraseBelow, (iy + textFlags) ; set textInsMode, (iy + textFlags) ret ToggleColor: ld a, (iy + PutMapFlags) xor 10h ld (iy + PutMapFlags), a ret DisableLowercase: res lwrCaseActive, (iy + appLwrCaseFlag) ret EnableLowercase: set lwrCaseActive, (iy + appLwrCaseFlag) ret GetCursorPos: ld a, (curRow) inc a ld (Ret1Value), a ld a, (curCol) inc a jp Ret2Val SetCursorPos: call GetListAInc dec a cp 10 jp nc, Exit ld (curRow), a call GetListAInc dec a cp 26 jp nc, Exit ld (curCol), a ret GetFgColor: ld hl, (TextFgColor) call ColorToIndex jp Ret1Val SetFgColor: call GetListAInc call IndexToColor #ifndef TI84PCSE ld.sis (0FFFFh & TextFgColor), hl #else ld (TextFgColor), hl #endif ret GetBgColor: ld hl, (TextBgColor) call ColorToIndex jp Ret1Val SetBgColor: call GetListAInc call IndexToColor #ifndef TI84PCSE ld.sis (0FFFFh & TextBgColor), hl #else ld (TextBgColor), hl #endif ret GetColors: ld hl, (TextFgColor) call ColorToIndex ld (Ret1Value), a ld hl, (TextBgColor) call ColorToIndex jp Ret2Val SetColors: call SetFgColor jr SetBgColor ReadBuffer: call GetTextShadowPtr ld a, (hl) jp Ret1Val PutMap: call GetListAInc b_call(_PutMap) ret ReadBufferInc: call ReadBuffer ld a, (curCol) inc a ld (curCol), a cp 26 ret c xor a ld (curCol), a ld a, (curRow) inc a ld (curRow), a cp 10 ret c xor a ld (curRow), a ret PutC: call GetListAInc b_call(_PutC) ret GetCursor: ld a, (iy + shiftFlags) and 0F8h bit textInsMode, (iy + textFlags) ; textInsMode = bit 4 jp z, Ret1Val or 4 jp Ret1Val SetCursor: call GetListAInc bit 2, a jr z, +_ set textInsMode, (iy + textFlags) jr ++_ _: res textInsMode, (iy + textFlags) _: and 0F8h ld b, a ld a, (iy + shiftFlags) and 7 or b ld (iy + shiftFlags), a ret GetTokenByte: call GetListAInc dec a jp p, +_ ld a, 9 _: ld h, a ld l, tVarStrng ld (OP1 + 1), hl ld a, StrngObj ld (OP1), a b_call(_FindSym) jr nc, +_ ; String not found, return error code ld hl, 257 gtberr: ld (Ret1Value), hl ld a, (iy + RetFlags) or Ret1M | RetForceListM and ~Ret2M ld (iy + RetFlags), a jp Exit _: #ifdef TI84PCSE ld a, b or a jr z, +_ ld hl, 259 jr gtberr #else ld hl, 0D00000h - 1 or a sbc hl, de jr c, +_ ld hl, 12 ; flag sl sh t1 t2 ver ll lh lu n1 n2 add hl, de ex de, hl _: or a sbc hl, hl #endif _: ex de, hl ld e, (hl) inc hl ld d, (hl) inc hl ex de, hl add hl, de push hl push de call GetListAInc or a jp z, ForceExit ex de, hl pop hl pop bc etbl: dec de ld a, e or d ld a, (hl) jr z, etbd b_call(_IsA2ByteTok) jr nz, +_ inc hl _: inc hl or a sbc hl, bc add hl, bc jr c, etbl ld hl, 258 jr gtberr etbd: ld (Ret1Value), a b_call(_IsA2ByteTok) ld a, (iy + RetFlags) jr nz, +_ or Ret2M _: or Ret1M | RetForceListM ld (iy + RetFlags), a and Ret2M ret z inc hl ld a, (hl) ld (Ret2Value), a ret GetToken: call GetListAInc push af b_call(_IsA2ByteTok) ld de, 1 jr nz, getTok1 set Get2ByteToken, (iy + GetTokenFlags) call GetListA ; Get second byte now to ensure it actually exists ld (Ret1Val), a ld de, 2 getTok1: call CreateTempString pop af inc de inc de ld (de), a bit Get2ByteToken, (iy + GetTokenFlags) jr z, markTempDirtyExit inc de ld a, (Ret1Val) ld (de), a jr markTempDirtyExit GetQuote: ld a, tString jr +_ GetStore: ld a, tStore _: ld de, 1 push af call CreateTempString pop af ; push hl inc de inc de ld (de), a markTempDirtyExit: ld sp, (QuitSp) markTempDirty: b_call(_OP4ToOP1) b_call(_OP1ToOP6) b_call(_StoAns) b_call(_OP6ToOP1) b_call(_FindSym) ; pop hl ret c ; ??? Should not happen ; set 7, (hl) ; Mark temporary string as dirty. I don't know if this is necessary or not, though probably not. b_call(_DelVar) ; Seems necessary? ret NumToStr: call GetListItemInc b_call(_OP1ToOP5) ld de, 20 call CreateTempString call markTempDirty b_call(_OP5ToOP1) ld a, 12 b_call(_FormReal) push bc ld hl, OP3 call TokenizeString b_call(_RclAns) pop bc ld a, c ld (de), a inc de ld a, b ld (de), a inc de ld hl, OP3 push bc ldir pop bc ld hl, 20 or a sbc hl, bc ex de, hl b_call(_DelMem) jp ForceExit getSeveralValues: ld hl, Ret1Value _: push hl push bc call GetListAInc pop bc pop hl ld (hl), a inc hl djnz -_ ret FillRect: ld b, 5 call getSeveralValues ld hl, Ret1Value + 0 dec (hl) inc hl dec (hl) ld a, (Ret1Value + 4) call IndexToColor ld.sis (0FFFFh & fillRectColor), hl #ifdef TI84PCSE ld a, (Ret1Value + 1) call mult12 inc hl inc hl ld a, (Ret1Value + 3) push hl call mult12 pop de add hl, de ex de, hl ld a, (Ret1Value + 0) call mult20 add a, 37 ld b, a ld a, (Ret1Value + 2) call mult20 add a, b ld c, a #else ld de, (Ret1Value + 1) ld d, 12 mlt de inc de inc de ld hl, (Ret1Value + 3) ld h, 12 mlt hl add hl, de ex de, hl ld bc, (Ret1Value + 0) ld b, 20 mlt bc ld a, c add a, 37 ld b, a push hl ld hl, (Ret1Value + 2) ld h, 20 mlt hl add a, l pop hl ld c, a #endif dec c dec de b_call(_FillRect) ; HL: xleft, DE: xright, B: Ytop, C: Ybottom ret #ifdef TI84PCSE mult12: ld l, a ld h, 0 add hl, hl add hl, hl ld e, l ld d, h add hl, hl add hl, de ret mult20: add a, a add a, a ld c, a add a, a add a, a add a, c ret #endif FillRectRepaint: call FillRect call GetListAInc call IndexToColor #ifndef TI84PCSE ld.sis (0FFFFh & TextFgColor), hl #else ld (TextFgColor), hl #endif ld a, (Ret1Value + 4) call IndexToColor #ifndef TI84PCSE ld.sis (0FFFFh & TextBgColor), hl #else ld (TextBgColor), hl #endif call setrowcol ld de, (curRow) push de fillrloop: call setrowcol call GetTextShadowPtr ld a, (Ret1Value + 3) ld b, a fillrloopi: ld a, (hl) inc hl b_call(_PutC) djnz fillrloopi ld hl, Ret1Value + 2 dec (hl) jr z, +_ dec hl dec hl inc (hl) jr fillrloop _: pop de #ifdef TI84PCSE ld (curRow), de #else ld.sis (0FFFFh & curRow), de #endif ret setrowcol: ld a, (Ret1Value + 0) cp 10 ret nc ld l, a ld a, (Ret1Value + 1) cp 26 ret nc ld h, a #ifdef TI84PCSE ld (curRow), hl #else ld.sis (0FFFFh & curRow), hl #endif ret And8: call GetListAInc push af call GetListAInc pop bc and b jp Ret1Val Or8: call GetListAInc push af call GetListAInc pop bc or b jp Ret1Val Xor8: call GetListAInc push af call GetListAInc pop bc xor b jp Ret1Val Not8: call GetListAInc cpl jp Ret1Val BitTest: call GetListAInc push hl call GetListAInc pop hl ld b, a or a jr z, btd ld b, a #ifdef TI84PCSE ld a, 16 + 1 #else ld a, 24 + 1 #endif sub b ld b, a _: adc hl, hl djnz -_ btd: ld a, l and 1 jp Ret1Val ;------ ------------------------------------------------------------------------ #ifdef NEVER pausetest: ld (iy + Asm_Flag2), 'a' push af push bc push de push hl push ix ; ld a, (iy + Asm_Flag2) ; b_call(_PutC) ; b_call(_GetKey) ; inc (iy + Asm_Flag2) pop ix pop hl pop de pop bc pop af ret #endif ForceExit: ld sp, (QuitSp) ret Exit: ld sp, (QuitSp) bit Ret1, (iy + RetFlags) ret z ; Need to return something bit RetForceList, (iy + RetFlags) jr nz, +_ bit Ret2, (iy + RetFlags) jr z, exitSingleValue ; Ans is already a list, so trim to size _: ld de, (ListLocation) ld a, (de) bit Ret2, (iy + RetFlags) jr nz, +_ sub 1 jr z, exitReadyToStore jr ++_ _: sub 2 jr z, exitReadyToStore jr c, exitSmall _: or a sbc hl, hl ld l, a ld bc, 1 ld a, ListObj b_call(_DelListEl) jr exitReadyToStoreNeedAnsLoc exitSmall: ld a, ListObj b_call(_IncLstSize) exitReadyToStoreNeedAnsLoc: call GetAnsLoc exitReadyToStore: ld hl, (Ret1Value) b_call(_SetXXXXOP2) b_call(_OP2ToOP1) ld de, (ListLocation) ld hl, 1 b_call(_PutToL) bit Ret2, (iy + RetFlags) ret z ld hl, (Ret2Value) b_call(_SetXXXXOP2) b_call(_OP2ToOP1) ld de, (ListLocation) ld hl, 2 b_call(_PutToL) ret exitSingleValue: ld hl, (Ret1Value) b_call(_SetXXXXOP2) b_call(_OP2ToOP1) b_call(_StoAns) ret ;====== Routines =============================================================== ;------ ------------------------------------------------------------------------ ConvertToInt: ; Converts OP1 to an integer in HL ; Inputs: ; - OP1: Integer ; Outputs: ; - HL: Integer, truncated to whole number ; HL is 16-bit on Z80, 24-bit on eZ80 ; - HL is 0 if conversion error ; Destroys: ; - AF ; - B ; - DE ; - IX or a sbc hl, hl ex de, hl sbc hl, hl ld a, (OP1) or a ret nz ld a, (OP1 + 1) sub 80h ret c inc a #ifdef TI84PCSE cp 6 #else cp 9 #endif ret nc ld b, a res ConvOddNibble, (iy + ConvFlags) ld ix, OP1 + 2 convloop: call convGetNibble ret m call Mult10 ld e, a add hl, de jr convloop convGetNibble: dec b ret m bit ConvOddNibble, (iy + ConvFlags) jr nz, +_ ld a, (ix) rra rra rra rra and 0Fh set ConvOddNibble, (iy + ConvFlags) ret _: res ConvOddNibble, (iy + ConvFlags) ld a, (ix) inc ix and 0Fh ret ;------ ------------------------------------------------------------------------ Mult10: ; Returns HL * 10 push de #ifdef TI84PCSE add hl, hl ld e, l ld d, h add hl, hl add hl, hl add hl, de #else add hl, hl ex de, hl or a sbc hl, hl add hl, de ex de, hl add hl, hl add hl, hl add hl, de #endif pop de ret ;------ ------------------------------------------------------------------------ GetAnsLoc: b_call(_AnsName) b_call(_FindSym) ld (ListLocation), de ret ;------ ------------------------------------------------------------------------ GetListA: call GetListItem call ConvertToInt ld a, l ret GetListItem: ld de, (ListLocation) ld hl, (ListIndex) ld a, (de) cp l jp c, Exit b_call(_GetLToOP1) ret GetListAInc: call GetListA _: push hl ld hl, (ListIndex) inc hl ld (ListIndex), hl pop hl ret GetListItemInc: call GetListItem jr -_ ;------ GetTextShadowPtr ------------------------------------------------------- GetTextShadowPtr: #ifndef TI84PCSE or a sbc hl, hl ld de, (curRow) ld l, d ld d, 26 mlt de add hl, de #else ld hl, (curRow) ld a, h ld h, 0 add hl, hl ld e, l ld d, h add hl, hl add hl, hl ld c, l ld b, h add hl, hl add hl, de add hl, bc add a, l jr nc, $ + 3 inc h ld l, a #endif ld de, textShadow add hl, de ret ;------ BranchOnTable ---------------------------------------------------------- BranchOnTable: ; Branches based on A ; Inputs: ; - A: Index into table ; - HL: Pointer to table ; Outputs: ; - Branch ; - A is the index value ; - Aborts to Exit if index is past end of table ; Destroys: ; - B ; - HL cp (hl) jp nc, Exit ld b, a #ifndef TI84PCSE dec hl #endif dec hl inc b _: inc hl #ifndef TI84PCSE inc hl #endif inc hl djnz -_ #ifndef TI84PCSE ld hl, (hl) #else ld b, (hl) inc hl ld h, (hl) ld l, b #endif jp (hl) ;------ IndexToColor ----------------------------------------------------------- IndexToColor: ; Converts a BASIC color to a 16-bit color ; Inputs: ; - A: Color ; Outputs: ; - HL: Color ; Destroys: ; - DE ; - AF sub 10 cp 16 ld hl, 0h ret nc add a, a ld de, OsColorPalette sbc hl, hl ld l, a add hl, de #ifndef TI84PCSE ex de, hl sbc hl, hl ex de, hl ld d, (hl) inc hl ld e, (hl) ex de, hl #else ld a, (hl) inc hl ld l, (hl) ld h, a #endif ret ;------ ColorToIndex ----------------------------------------------------------- ColorToIndex: ; Converts a 16-bit color into a BASIC color ; Inputs: ; - HL: Color ; Outputs: ; - A: Color number ; - NZ if color found, Z if not found ; Destroys: ; - B ; - DE ; - HL ld b, 15 ex de, hl ld hl, OsColorPalette + 29 ciloop: ld a, (hl) #ifndef TI84PCSE cp e #else cp d #endif dec hl jr nz, +_ ld a, (hl) #ifndef TI84PCSE cp d #else cp e #endif jr nz, +_ ld a, b add a, 9 ret _: dec hl djnz ciloop xor a ld a, 12 ret ;------ TokenizeString --------------------------------------------------------- TokenizeString: ld a, (hl) or a ret z call AsciiToToken ld (hl), a inc hl jr TokenizeString ;------ AsciiToToken ----------------------------------------------------------- AsciiToToken: push hl push bc ld hl, AsciiToTokenTable ld b, (hl) inc hl _: cp (hl) inc hl jr z, +_ inc hl djnz -_ inc hl _: ld a, (hl) pop bc pop hl ret ;------ CreateTempString ------------------------------------------------------- CreateTempString: ; Creates a temporary string variable. ; Inputs: ; - DE: Size ; Outputs: ; - HL: Pointer to VAT entry ; - DE: Pointer to data ; - OP4: Name of temporary item. ; You can B_CALL(_OP4ToOP1) and then B_CALL(_StoAns) to store it to Ans. ; Destroys: ; - Assume all call TempStringName ex de, hl b_call(_CreateStrng) ret TempStringName: ld hl, '$' | (StrngObj << 8) #ifndef TI84PCSE ld.sis (0FFFFh & OP1), hl ld.sis hl, (0FFFFh & pTempCnt) ld.sis (0FFFFh & (OP1 + 2)), hl inc hl ld.sis (0FFFFh & pTempCnt), hl #else ld (OP1), hl ld hl, (pTempCnt) ld (OP1 + 2), hl inc hl ld (pTempCnt), hl #endif DoNothing: ret ;====== Data =================================================================== CommandBranchTable: #ifdef TI84PCSE .db (CommandBranchTableEnd - CommandBranchTable) / 2 #else .db (CommandBranchTableEnd - CommandBranchTable) / 3 #endif .daddr DoNothing ; 0 .daddr RunIndicOff ; 1 .daddr CursorOff ; 2 .daddr InverseTextOff ; 3 .daddr DisableColor ; 4 .daddr GetCursorPos ; 5 .daddr GetFgColor ; 6 .daddr GetBgColor ; 7 .daddr ReadBuffer ; 8 .daddr ReadBufferInc ; 9 .daddr GetVersion ; 10 .daddr RunIndicOn ; 11 .daddr CursorOn ; 12 .daddr InverseTextOn ; 13 .daddr EnableColor ; 14 .daddr SetCursorPos ; 15 .daddr SetFgColor ; 16 .daddr SetBgColor ; 17 .daddr PutMap ; 18 .daddr PutC ; 19 .daddr GetHwType ; 20 .daddr ToggleRunIndic ; 21 .daddr ToggleCursor ; 22 .daddr ToggleInverseText ; 23 .daddr ToggleColor ; 24 .daddr NumToStr ; 25 .daddr GetQuote ; 26 .daddr GetStore ; 27 .daddr GetToken ; 28 .daddr GetTokenByte ; 29 .daddr GetColors ; 30 .daddr GetCursor ; 31 .daddr DisableLowercase ; 32 .daddr FillRect ; 33 .daddr FillRectRepaint ; 34 .daddr And8 ; 35 .daddr Or8 ; 36 .daddr Xor8 ; 37 .daddr Not8 ; 38 .daddr BitTest ; 39 .daddr SetColors ; 40 .daddr SetCursor ; 41 .daddr EnableLowercase ; 42 CommandBranchTableEnd: OsColorPalette: ; Courtesy of KermM .db 0, 1Fh ; Blue .db 0F8h, 0 ; Red .db 0, 0 ; Black .db 0F8h, 1Fh ; Magenta .db 4, 0E0h ; Green .db 0FCh, 64h ; Orange .db 0B1h, 0 ; Brown .db 0, 10h ; Navy .db 4, 9Fh ; LtBlue .db 0FFh, 0E0h ; Yellow .db 0FFh, 0FFh ; White .db 0E7h, 1Ch ; LtGray .db 0C6h, 18h ; MedGray .db 8Ch, 51h ; Gray .db 52h, 0AAh ; DarkGray AsciiToTokenTable: .db (AsciiToTokenTableEnd - AsciiToTokenTable) / 2 .db '0', '0' .db '1', '1' .db '2', '2' .db '3', '3' .db '4', '4' .db '5', '5' .db '6', '6' .db '7', '7' .db '8', '8' .db '9', '9' .db '.', tDecPt ; . .db 14h, tFromDeg ; degree symbol .db 15h, tFromRad ; radian symbol .db 1Ah, tChs ; negate/change sign .db 1Bh, tee ; e.g. 1.3E7 .db '\'', tAPost .db '"', tString .db '+', tAdd .db '-', tSub .db '*', tMul .db '/', tDiv .db ' ', ' ' AsciiToTokenTableEnd: .db tQuest