**************************************************************************** **************************************************************************** ** ** Platinum Edition for TI-89 (Basic "library" routines) ** ** This software is in the public domain. There is no warranty. ** ** by Patrick Davidson (pad@calc.org, http://pad.calc.org/) ** ** Last updated September 27, 2001 ** **************************************************************************** **************************************************************************** ******************************************** TEST ENTER KEY Test_Enter: IFND ti89 GETEDGE THIS_IS_FOR,TI92_ONLY,6,6 beq.s \enter ENDIF GETEDGE 1,0,9,1 ; ENTER \enter: rts ******************************************** DIVIDE D2 (WORD) BY 4 * * This routine divides D2 by 4 with rounding of fractional values up or * down decided by the cycle counter. If the fraction is 1/4, it will be * rounded up 1/4 of the time, 1/2 is rounded up 1/2 of the time, and 3/4 * is rounded up 3/4 of the time. This is used for moving objects with * fractional velocities in such a way that (over many frames) the velocity * averages out to the specified fraction. If the fraction is 1/2, the * distance will every other frame, rather than having two frames in a row * of each value, as this gives smoother motion. * * Returns result in D2. Modified D2, D3, and D4. * ******** Div_D2_By_4: move.w d2,d3 asr.w #2,d2 and.w #3,d3 lsl.w #3,d3 move.w cycle_counter+2(a5),d4 and.w #3,d4 jmp round_table(pc,d3.w) round_table: rts roundup: addq.w #1,d2 rts dc.w 31337 onefourth: beq.s roundup rts dc.w 31337,31337 onehalf: lsr.w #1,d4 bcc.s roundup rts dc.w 31337 threefourths: cmp.w #3,d4 bne.s roundup rts ******************************************** READ ALL KEYS * * Reads all keys by hardware and places their values in the key_data buffer. * Keypresses occuring on this read are indicated in the key_edge buffer. * ******** Read_All_Keys: IFD ti89 moveq #7,d0 ENDIF IFD ti92plus moveq #9,d0 ENDIF lea key_data(a5),a4 moveq #-2,d2 read_keys_loop: move.w d2,$600018 moveq #34,d1 rkl_waste_time: dbra d1,rkl_waste_time move.b (a4),d3 ; D3 = old key data move.b $60001b,d4 ; D4 = new key data move.b d4,(a4)+ move.b d3,9(a4) not.b d3 or.b d4,d3 ; 0 = - edge (key down) move.b d3,19(a4) rol.w #1,d2 dbra d0,read_keys_loop rts Wait_No_Key: move.w #0,$600018 move.w #200,d0 \loop: dbra d0,\loop Wait_No_Key_Loop: MOVE.B $60001b,D0 not.b d0 bne.s Wait_No_Key_Loop RTS ******************************************** TI-OS KEYBOARD READING Get_Key: bsr.s Test_Key beq.s Get_Key rts Test_Key: moveq #6,d0 trap #9 ; Get pointer to keyboard queue in A0 move.l a0,-(sp) pea _string_buffer(a5) move.l ($c8).w,a0 add.l #$3aa*4,a0 move.l (a0),a0 jsr (a0) ; OSdequeue() addq.l #8,sp tst.w d0 bne.s no_key move.w _string_buffer(a5),d0 rts no_key: moveq #0,d0 rts ******************************************** RANDOM-NUMBER GENERATOR random: ; based on flib random move.l d1,-(sp) move.w #0,d1 mulu.w #31421,d1 add.w #6927,d1 mulu.w d1,d0 move.w d1,random+4 clr.w d0 swap d0 move.l (sp)+,d1 rts ******************************************** CALL INTERRUPT 1 ROUTINE call_old_int1: movem.l d0/a0,-(sp) lea (LCD_MEM+99*30+20).w,a0 moveq #5,d0 \loop: move.l -(a0),-(sp) move.l -(a0),-(sp) move.l -(a0),-(sp) move.l -(a0),-(sp) move.l -(a0),-(sp) lea -10(a0),a0 dbra d0,\loop pea return(pc) move.w sr,-(sp) move.l originalint1(pc),a0 jmp (a0) return: lea (LCD_MEM+94*30).w,a0 moveq #5,d0 \loop: move.l (sp)+,(a0)+ move.l (sp)+,(a0)+ move.l (sp)+,(a0)+ move.l (sp)+,(a0)+ move.l (sp)+,(a0)+ lea 10(a0),a0 dbra d0,\loop movem.l (sp)+,d0/a0 rte ******************************************** BASIC TEXT DISPLAY ROUTINES Set_Font: ; Set font to D0 move.w d0,-(sp) JSR_ROM FontSetSys addq.w #2,sp rts Display_String: ; Display (A0) at (D1,D0) move.w #4,-(sp) pea (a0) move.w d0,-(sp) move.w d1,-(sp) JSR_ROM DrawStr lea 10(sp),sp rts _sprintf: ____sprintf: JMP_ROM sprintf ******************************************* ADD BCD LONGWORDS * * Adds (A0) to (A1), changing A0 and A1. Pointers should initially point * right past the end of the longwords. * ******** Add_BCD: andi #0,ccr abcd -(a0),-(a1) abcd -(a0),-(a1) abcd -(a0),-(a1) abcd -(a0),-(a1) rts ******************************************* SUBTRACT BCD LONGWORDS * * Subtracts (A0) from (A1), changing A0 and A1. Pointers should initially * point right past the end of the longwords. * ******** Sub_BCD: andi #0,ccr sbcd -(a0),-(a1) sbcd -(a0),-(a1) sbcd -(a0),-(a1) sbcd -(a0),-(a1) rts