**************************************************************************** **************************************************************************** ** ** Monster for TI-89 (Basic "library" routines) ** ** Copyright 2004 by Patrick Davidson. This software may be freely ** modified and/or copied with no restrictions. There is no warranty. ** ** by Patrick Davidson (pad@calc.org, http://pad.calc.org/) ** ** Last updated September 16, 2004 ** **************************************************************************** **************************************************************************** ******************************************** CONTRAST CHANGE Contrast_Keys GETEDGE 1,1,8,4 ; + bne.s \ncu JSR_ROM OSContrastUp \ncu: GETEDGE 1,2,9,0 ; - bne.s \ncd JMP_ROM OSContrastDn \ncd: rts ******************************************** CONVERT BYTE TO BCD * * Converts the BYTE in D0 to packed BCD with the result placed in * temp_buffer. * ******** Convert_To_BCD: ext.w d0 ext.l d0 divu #10,d0 move.w d0,d1 swap d0 lsl.w #4,d1 or.w d1,d0 move.b d0,temp_buffer(a5) rts ******************************************** 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 ******************************************** 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 Wait_Key: move.w #0,$600018 move.w #200,d0 \loop: dbra d0,\loop Wait_Key_Loop: MOVE.B $60001b,D0 not.b d0 beq.s Wait_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 temp_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 temp_buffer(a5),d0 rts no_key: moveq #0,d0 rts ******************************************** RANDOM-NUMBER GENERATOR random: move.l d1,-(sp) move.w #31421,d1 mulu seed(a5),d1 add.w #6927,d1 move.w d1,seed(a5) mulu d1,d4 swap d4 move.l (sp)+,d1 rts ******************************************** 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