;Utility routines include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON FillRect: DISAVE ld a,d sub h inc a ld (8127h),a ld a,h add a,80h ld (8125h),a push de ld a,l ld hl,frTable1 call fr1 ld (8128h),a ld a,b ld (8124h),a pop de ld a,e ld hl,frTable2 call fr1 ld (8129h),a ld a,b ld hl,8124h sub (hl) inc a ld (8126h),a B_CALL SetYUp ld a,(8127h) ld b,a ld a,(8125h) frMainLoop: res 4,(iy+2Ah) push bc push af B_CALL LCD_BUSY out (10h),a call GetDispRowOffset ex de,hl ld a,(8124h) and 1Fh ld l,a ld h,0 add hl,de ex de,hl ld hl,saveSScreen add hl,de ex de,hl push bc ld bc,plotSScreen add hl,bc pop bc push hl push de call fr2 B_CALL LCD_BUSY in a,(11h) frLoop1: B_CALL LCD_BUSY in a,(11h) push hl ld hl,812Ah or (hl) ; ld (de),a ld (hl),0FFh pop hl inc hl inc de ld a,b or a jr z,$F djnz frLoop1 ld a,(8129h) ld (812Ah),a ld b,1 bit 4,(iy+2Ah) set 4,(iy+2Ah) jr z,frLoop1 $$: pop de pop hl res 4,(iy+2Ah) call fr2 frLoop2: ; ld a,(de) ld a,0FFh bit 1,(iy+2) jr nz,$F ld (hl),a $$: B_CALL LCD_BUSY out (11h),a inc de inc hl ld a,b or a jr z,$F djnz frLoop2 ld a,(8129h) ld (812Ah),a ld b,1 bit 4,(iy+2Ah) set 4,(iy+2Ah) jr z,frLoop2 $$: pop af inc a pop bc dec b jr nz,frMainLoop B_CALL SetXUp EIRESTORE ret GetDispRowOffset: and 7Fh ld l,a ld h,0 add hl,hl add hl,hl push hl pop de add hl,de add hl,de ret fr1: push af srl a srl a srl a or 20h ld b,a pop af $$: sub 8 jr nc,$B add a,8 ld e,a ld d,0 add hl,de ld a,(hl) ret fr2: ld a,(8126h) dec a ld b,a ld a,(8128h) jr nz,$F push hl ld hl,8129h and (hl) pop hl $$: ld (812Ah),a ld a,(8124h) bit 7,a ret nz B_CALL LCD_BUSY out (10h),a ret frTable1: DB 0FFh,7Fh,3Fh,1Fh,0Fh,7,3,1 frTable2: DB 80h,0C0h,0E0h,0F0h,0F8h,0FCh,0FEh,0FFh strcpy: ld a,(hl) ld (de),a inc hl inc de or a jr nz,strcpy ret VPutSAppCenter: push hl call SStringLen pop hl ld a,95 sub c srl a ld (penCol),a VPutSApp: ld a,(hl) inc hl or a ret z B_CALL VPutMap jr VPutSApp SStringLen: ld c,0 $$: ld a,(hl) inc hl or a ret z push hl ld h,0 ld l,a add hl,hl add hl,hl add hl,hl B_CALL SFont_Len ld a,b pop hl add a,c ld c,a jr $B DispHexB: ld a,(hl) call DispHexA inc hl djnz DispHexB ret WaitTimer100ms: ;Waits 100ms call WaitTimer20ms call WaitTimer20ms call WaitTimer20ms WaitTimer40ms: ;Waits 40ms call WaitTimer20ms WaitTimer20ms: ;Waits 20ms ld b,2 WaitTimerBms: ;Waits B*10 milliseconds ld a,42h out (36h),a xor a out (37h),a ld a,b out (38h),a $$: in a,(4) bit 7,a jr z,$B ret SoftKey: push hl ld bc,7 ld de,95*256+7 ld h,1 B_CALL ILine ld b,19 ld d,b ld e,0 B_CALL ILine ld b,38 ld d,b B_CALL ILine ld b,57 ld d,b B_CALL ILine ld b,76 ld d,b B_CALL ILine ld b,0 ld d,b B_CALL ILine ld b,95 ld d,b B_CALL ILine pop hl ld a,57 ld (penRow),a ld a,3 SoftKeyLoop: ld (penCol),a push af call vputstring pop af add a,19 cp 98 jr nz,SoftKeyLoop ret IPutS11: push hl ld b,11 $$: ld a,(hl) B_CALL PutC inc hl djnz $B pop hl ret ;Draws horizontal dotted line ;Input: bc = (x,y) coordinate of first point (lower left corner is (0,0)) ; e = column to stop at ;Output: line drawn FunkyLine: ld d,1 FunkyLine_Loop: B_CALL IPoint inc b inc b ld a,b cp e jp m,FunkyLine_Loop ret vputstring: ld a,(hl) inc hl or a ret z B_CALL VPutMap jr vputstring VDispA: push ix push hl ld c,-1 VDispA_loop: inc c sub 10 jr nc,VDispA_loop add a,10 push af ld a,c add a,'0' B_CALL VPutMap pop af add a,'0' B_CALL VPutMap pop hl pop ix ret DispA: push hl ld c,-1 DispA_loop: inc c sub 10 jr nc,DispA_loop add a,10 push af ld a,c add a,'0' B_CALL PutC pop af add a,'0' B_CALL PutC pop hl ret IGetKey: push ix push bc push de push hl res onInterrupt,(iy+onFlags) B_CALL GetKey pop hl pop de pop bc pop ix ret IPutSUnicode: ;Display a unicode string descriptor ld b,(hl) inc hl inc hl dec b dec b $$: ld a,(hl) or a call nz,IPutC inc hl djnz $b ret PutSApp: IPutS: ld a,(hl) inc hl or a ret z call IPutC jr IPutS IPutC: push hl ;don't think these are necessary push bc B_CALL PutC pop bc pop hl ret Var TempNum,2 GetHexA: ;lets user input an 8 bit number in hexadecimal ;prompt is at currow,curcol ;number is returned in a set curAble,(iy+curFlags) ld b,2 ld hl,TempNum getnumhloop: call IGetKey cp 2 jp nz,gnhnotback ld a,b cp 2 jp z,gnhnotback ld a,' ' B_CALL PutMap ld hl,curCol dec (hl) jp GetHexA gnhnotback: sub 142 cp 10 jp c,gnhnumpressed sub 12 cp 6 jp c,gnhletpressed jp getnumhloop gnhnumpressed: ld (hl),a inc hl add a,48 call IPutC djnz getnumhloop jp gnhdone gnhletpressed: add a,10 ld (hl),a inc hl add a,55 call IPutC djnz getnumhloop gnhdone: dec hl ld b,(hl) dec hl ld a,(hl) rlca rlca rlca rlca or b res curAble,(iy+curFlags) ret DispHexHL: push af push bc push de push hl push ix ld a,h call DispHexA ld a,l call DispHexA pop ix pop hl pop de pop bc pop af ret VDispHexA: push ix push af push hl push bc push af rrca rrca rrca rrca call vdispha pop af call vdispha pop bc pop hl pop af pop ix ret vdispha: and 15 cp 10 jp nc,vdhlet add a,48 jp vdispdh vdhlet: add a,55 vdispdh: B_CALL VPutMap ret DispHexA: push ix push af push hl push bc push af rrca rrca rrca rrca call dispha pop af call dispha pop bc pop hl pop af pop ix ret dispha: and 15 cp 10 jp nc,dhlet add a,48 jp dispdh dhlet: add a,55 dispdh: call IPutC ret ;DialogBox ; Input ; (H,L) = (y,x) upper left ; (D,E) = (y,x) lower right ;H and l must be >= 1 ;D must be <= 62 ;E must be <= 93 ;Text inside the box must be displayed manually DialogBox: push hl push de dec h dec l inc d inc d inc e inc e B_CALL EraseRectBorder pop de pop hl push hl push de B_CALL DrawRectBorderClear pop de pop hl push hl push de inc d inc e B_CALL DrawRectBorder pop de pop hl ld a,h xor 63 ;Adjust for funny IPoint coordinates ld h,a ld a,d xor 63 ld b,l ld c,h ld d,0 B_CALL IPoint ;(b,c) = (x,y xor 63) - upper left ld b,e B_CALL IPoint inc b B_CALL IPoint dec c B_CALL IPoint ld c,a dec c B_CALL IPoint ld b,l B_CALL IPoint inc b B_CALL IPoint dec b inc c B_CALL IPoint ret VStrLen: ld b,0 VStrLen_Loop: ld a,(hl) or a ret z push hl ld h,0 ld l,a add hl,hl add hl,hl add hl,hl push bc B_CALL SFont_Len ld a,b pop bc pop hl inc hl add a,b ld b,a jr VStrLen_Loop fastCopy: di ld hl,plotsscreen ld b,64 ld a,07h out (10h),a ld a,80h-1 layerloop1: push bc ld b,0Ch inc a ld (OP1),a call lcddelay out (10h),a call lcddelay ld a,20h out (10h),a layerloop2: ld a,(hl) call lcddelay out (11h),a inc hl djnz layerloop2 pop bc ld a,(OP1) djnz layerloop1 ld a,5 call lcddelay out (10h),a ei ret lcddelay: push af lcddelayloop: in a,(2) and 2 jr z,lcddelayloop pop af ret fixVarNames: ;Converts TI-OS style variable name in OP1 to ASCIIZ ld a,(OP1) cp 01h ;list jr z,fixList cp 0Dh jr z,fixList cp 02h ;matrix jr z,fixMatrix cp 03h ;equation jr z,fixEquation cp 04h jr z,fixString cp 07h jr z,fixPicture cp 08h jr z,fixGDB ret fixList: ld a,(OP1+2) cp 10 jp p,fixNamedList add a,31h ld (OP1+2),a ld a,'L' ld (OP1+1),a ret fixNamedList: ld a,LlistL ld (OP1+1),a ret fixMatrix: ld a,(OP1+2) inc a ld hl,sMatrixTable-4 ld de,4 ld b,a f_m_1: add hl,de djnz f_m_1 ld de,OP1+1 ld bc,4 ldir ret sMatrixTable: DB 0C1h,"A",5Dh,0 DB 0C1h,"B",5Dh,0 DB 0C1h,"C",5Dh,0 DB 0C1h,"D",5Dh,0 DB 0C1h,"E",5Dh,0 DB 0C1h,"F",5Dh,0 DB 0C1h,"G",5Dh,0 DB 0C1h,"H",5Dh,0 DB 0C1h,"I",5Dh,0 DB 0C1h,"J",5Dh,0 fixPicture: ld a,(OP1+2) inc a ld hl,sPictureTable-5 ld de,5 ld b,a f_p_1: add hl,de djnz f_p_1 ld de,OP1+1 ld bc,5 ldir ret sPictureTable: DB "Pic1",0 DB "Pic2",0 DB "Pic3",0 DB "Pic4",0 DB "Pic5",0 DB "Pic6",0 DB "Pic7",0 DB "Pic8",0 DB "Pic9",0 DB "Pic0",0 fixGDB: ld a,(OP1+2) inc a ld hl,sGDBTable-5 ld de,5 ld b,a f_gdb_1: add hl,de djnz f_gdb_1 ld de,OP1+1 ld bc,5 ldir ret sGDBTable: DB "GDB1",0 DB "GDB2",0 DB "GDB3",0 DB "GDB4",0 DB "GDB5",0 DB "GDB6",0 DB "GDB7",0 DB "GDB8",0 DB "GDB9",0 DB "GDB0",0 fixEquation: ld a,(OP1+2) cp 7Fh jp p,fixEquation_s cp 3Fh jp p,fixEquation_r cp 1Fh jp p,fixEquation_l sub 10h ld hl,sEquTableY-3 inc a ld b,a ld de,3 fe_y_1: add hl,de djnz fe_y_1 ld de,OP1+1 ld bc,3 ldir ret sEquTableY: DB "Y",81h,0 DB "Y",82h,0 DB "Y",83h,0 DB "Y",84h,0 DB "Y",85h,0 DB "Y",86h,0 DB "Y",87h,0 DB "Y",88h,0 DB "Y",89h,0 DB "Y",80h,0 fixEquation_l: ld hl,sEquTableL-4 sub 20h inc a ld b,a ld de,4 fe_l_1: add hl,de djnz fe_l_1 ld de,OP1+1 ld bc,4 ldir ret sEquTableL: DB "X",81h,0Dh,0 DB "Y",81h,0Dh,0 DB "X",82h,0Dh,0 DB "Y",82h,0Dh,0 DB "X",83h,0Dh,0 DB "Y",83h,0Dh,0 DB "X",84h,0Dh,0 DB "Y",84h,0Dh,0 DB "X",85h,0Dh,0 DB "Y",85h,0Dh,0 DB "X",86h,0Dh,0 DB "Y",86h,0Dh,0 fixEquation_s: sub 80h add a,75h ld (OP1+1),a xor a ld (OP1+2),a ret fixEquation_r: ld hl,sEquTable-3 ld a,(OP1+2) sub 40h inc a ld b,a ld de,3 fe_r_1: add hl,de djnz fe_r_1 ld de,OP1+1 ld bc,3 ldir ret sEquTable: DB "r1",0 DB "r2",0 DB "r3",0 DB "r4",0 DB "r5",0 DB "r6",0 fixString: ld hl,sStrTable-5 ld a,(OP1+2) inc a ld b,a ld de,5 fs_1: add hl,de djnz fs_1 ld de,OP1+1 ld bc,5 ldir ret sStrTable: DB "Str1",0 DB "Str2",0 DB "Str3",0 DB "Str4",0 DB "Str5",0 DB "Str6",0 DB "Str7",0 DB "Str8",0 DB "Str9",0 DB "Str0",0 VEraseEOL: ld a,' ' B_CALL VPutMap ld a,(pencol) cp c jp m,VEraseEOL ret cmpstr: ld a,(de) cp (hl) ret nz or a ret z inc de inc hl jr cmpstr cmpstrb: ld a,(de) cp (hl) ret nz inc de inc hl djnz cmpstrb xor a ret putsb: push bc push hl $$: ld a,(hl) B_CALL PutC inc hl djnz $B pop hl pop bc ret