**************************************************************************** **************************************************************************** ** ** 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 July 28, 2001 ** **************************************************************************** **************************************************************************** ******************************************** 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. * ******** 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 #25,d1 rkl_waste_time: dbra d1,rkl_waste_time move.b $60001b,(a4)+ rol.w #1,d2 dbra d0,read_keys_loop rts Read_Key_Edges: bsr.s Read_All_Keys ; Check current states lea key_data(a5),a4 lea old_keys(a5),a6 move.l (a6),d0 ; D0 = old key data move.l (a4),(a6)+ ; new data becomes old not.l d0 or.l d0,(a4)+ ; 0 bit = - edge (key down) move.l (a6),d0 ; D0 = old key data move.l (a4),(a6)+ ; new data becomes old not.l d0 or.l d0,(a4)+ ; 0 bit = - edge (key down) IFD ti92plus move.w (a6),d0 ; D0 = old key data move.w (a4),(a6)+ ; new data becomes old not.w d0 or.w d0,(a4)+ ; 0 bit = - edge (key down) ENDIF 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