home *** CD-ROM | disk | FTP | other *** search
- ;
- ;
- ; IR Link Library v1.0 for the TI89 and TI92+
- ;
- ; by Sami Khawam ( sKhawam@bigfoot.com )
- ;
- ;
- ; This library will enable you to use the IR Link. There are only
- ; 4 routines now, but new routines will be added in the future ( like
- ; remote control encoding, decoding...).
- ;
- ; Although the ROM link routines can be used with the IR Link, this
- ; library has it own linking routines ( work also without the IR Link ).
- ;
- ; This library is accualy an executable asm program. When executed
- ; the user will be able to change the settings of the library.
- ; Currently there are 3 settings you can change:
- ;
- ; -Swap Lines: On/Off .
- ; This option is useful if you have unintetionaly swaped the red
- ; and the white wires of the calc-ir_link connection. Use it
- ; if you dont want to solder the cable again.
- ;
- ; -Timeout duration:
- ; Set the duration that the calc should try to transfer data
- ; when it doesn't receive anything.
- ;
- ; -Linking Delay:
- ; Set the linking delay. Maybe useful if connected with a
- ; slower calc(eg. TI82), or if you are getting errors.
- ;
- ; If you haven't yet heard of the IR Link, take a look at my homepage:
- ;
- ; http://sami.ticalc.org
- ;
- ;
- ; Thanks for Antoine Mercier for having ported
- ; the PutByte routine from the TI85.
- ;
- ;
- ; Sami Khawam
-
-
- include "doorsos.h"
- include "graphlib.h"
- include "userlib.h"
- include "hexlib.h"
- xdef _main
- xdef _ti92plus
- xdef _ti89
- xdef _comment
- xdef irlib@0000
- xdef irlib@0001
- xdef irlib@0002
- xdef irlib@0003
- xdef irlib@0004
-
-
-
- ;************** Start of program ***************
-
- _main:
-
- move.w #40,d5 ; d5 contains the cursor position
-
- ClearScreen:
- jsr graphlib::clr_scr
- SetFont #2
- WriteStr #18,#1,#1,_comment
- WriteStr #45,#20,#1,Text1
- SetFont #1
- WriteStr #8,#40,#1,Text2
- WriteStr #8,#56,#1,Text3
- WriteStr #8,#72,#1,Text4
-
-
- DrawCur:
-
- move.w #4,-(a7)
- move.w d5,-(a7)
- move.w #1,-(a7)
- move.w #26,-(a7) ; This is the '>>' charachter.
- jsr userlib::DrawCharXY
- lea 8(a7),a7
-
-
- PrintState:
- btst.b #0,(SwapL)
- beq PrintOff
- WriteStr #120,#40,#1,Text5
- bra PrintDelays
- PrintOff
- WriteStr #120,#40,#1,Text6
-
-
- PrintDelays:
- clr.l d0
- move.w (Timeout),d0
- move.l #7,d1
- move.l #15,d2
- move.l #3,d4
- jsr hexlib::put_hex
-
- clr.l d0
- move.w (LDelay),d0
- move.l #9,d1
- move.l #15,d2
- move.l #3,d4
- jsr hexlib::put_hex
-
- MainLoop:
-
- jsr userlib::idle_loop
-
-
- cmp #KEY_DOWN,d0 ; Down
- beq CurDown
- cmp #KEY_UP,d0 ; Up
- beq CurUp
- cmp #KEY_RIGHT,d0 ; Right
- beq CurRight
- cmp #KEY_LEFT,d0 ; Left
- beq CurLeft
- cmp #264,d0 ; Exit
- beq Exit
- bra MainLoop
-
- CurDown:
- cmp #72,d5
- bge MainLoop
- add.w #16,d5
- bra ClearScreen
- CurUp:
- cmp #40,d5
- ble MainLoop
- sub.w #16,d5
- bra ClearScreen
-
- CurRight:
- cmp #40,d5
- bne CheckTO
- SwpL
- bchg.b #0,(SwapL)
- bra ClearScreen
- CheckTO
- cmp #56,d5
- bne CheckDE1
- add.w #$0100,(Timeout)
- bra PrintDelays
- CheckDE1
- cmp #72,d5
- bne MainLoop
- add.w #$0100,(LDelay)
- bra PrintDelays
-
- CurLeft:
- cmp #40,d5
- beq SwpL
- cmp #56,d5
- bne CheckDE2
- sub.w #$0100,(Timeout)
- bra PrintDelays
- CheckDE2
- cmp #72,d5
- bne MainLoop
- sub.w #$0100,(LDelay)
- bra PrintDelays
-
-
- Exit:
- jsr doorsos::reset_link
- rts
-
- ;************** Start of library ***************
-
-
-
- ; **********************************************
- ;
- ; PutByte: Send a byte to the IR Link
- ; Input: d3.b Byte to send
- ; Output: none
- ; Destroyed: d4
- ;
- ;
- ;
- ; PutLink: Send a byte/word or longword to the IR Link
- ; Input: d3 data to send
- ; d4 number of bits -1 (7...31)
- ; Output: none
- ; Destroyed: none
- ;
- ; Thanks for Antoine Mercier for having ported
- ; those routine from the TI85.
- ;
-
- irlib@0000:
- PutByte:
- move.w #7,d4
- irlib@0001:
- PutLink:
- movem d2-d4,-(a7)
- clr.b $60000C
- bset.b #6,$60000C ; Turn on control mode
-
- btst.b #0,(SwapL)
- beq nextbit
- not.l d3
-
- nextbit:
- bclr.b #0,$60000E ; rouge haut
- bclr.b #1,$60000E ; blanc haut
- lsr.l #1,d3
- bcc pbsend0
- pbsend1:
- bset.b #1,$60000E ; blanc bas
- bra pbsuite
- pbsend0:
- bset.b #0,$60000E ; rouge bas
- pbsuite:
- move.w (Timeout),d2
- ; move.w #$FFFF,d2
- waitforR0:
- btst.b #2,$60000E
- bne suite1
- btst.b #2,$60000E
- bne suite1
- dbra.w d2,waitforR0
- bra pbfin
- suite1:
- move.w (Timeout),d2
- ; move.w #$FFFF,d2
- waitforW0:
- btst.b #3,$60000E
- bne suite2
- btst.b #3,$60000E
- bne suite2
- dbra.w d2,waitforW0
- bra pbfin
- suite2:
- bclr.b #0,$60000E ; rouge haut
- bclr.b #1,$60000E ; blanc haut
- move.w (Timeout),d2
- ; move.w #$FFFF,d2
- waitforR1:
- btst.b #2,$60000E
- beq suite3
- btst.b #2,$60000E
- beq suite3
- dbra.w d2,waitforR1
- bra pbfin
- suite3:
- move.w (Timeout),d2
- ; move.w #$FFFF,d2
- waitforW1:
- btst.b #3,$60000E
- beq suite4
- btst.b #3,$60000E
- beq suite4
- dbra.w d2,waitforW1
- bra pbfin
- suite4:
- ; sub.w #1,d4
- ; cmp.w #0,d4
- ; bne nextbit
- dbra.w d4,nextbit
-
- move.w (LDelay),d2
- ; move.w #$08FF,d2
- Delay:
- nop
- dbra.w d2,Delay
-
-
- pbfin:
- bclr.b #0,$60000E ; rouge haut
- bclr.b #1,$60000E ; blanc haut
- movem (a7)+,d2-d4
- rts
-
- ;*****************************************************
-
-
- ; **********************************************
- ;
- ; GetByte: Get a byte from the IR Link
- ; Input: none
- ; Output: d3.b Byte received
- ; Destroyed: d4
- ;
- ;
- ;
- ; PutLink: Get a byte/word of longword from the IR Link -DOESN'T WORK
- ; Input: d4.w Number of Bits
- ; Output: d3 data received
- ; Destroyed: none
- ;
- ; The GetLink routine DOES NOT WORK!
- ;
- ;
- irlib@0002:
- GetByte:
- move.w #7,d4
- irlib@0003:
- GetLink: ; Doesn't work with d4 != 8
- movem d1-d2,-(a7)
- clr.l d3
- clr.b $60000C
- bset.b #6,$60000C ; Turn on control mode
- GLNextBit
- move.w (Timeout),d2
- ; move.w #$FFFF,d2
- GLWaitChange:
- btst.b #2,$60000E
- bne GLGet0
- btst.b #3,$60000E
- bne GLGet1
- btst.b #2,$60000E
- bne GLGet0
- btst.b #3,$60000E
- bne GLGet1
- dbra.w d2,GLWaitChange
- bra GLEnd
- GLGet0:
- bset.b #1,$60000E ; Set W0
- lsr.l #1,d3
- move.w (Timeout),d2
- GLWaitR1:
- btst.b #2,$60000E
- beq GLSetHigh
- btst.b #2,$60000E
- beq GLSetHigh
- dbra.w d2,GLWaitR1
- bra GLEnd
- GLGet1:
- bset.b #0,$60000E ; Set R0
- lsr.l #1,d3
- ori #$80,d3
- move.w (Timeout),d2
- GLWaitW1:
- btst.b #3,$60000E
- beq GLSetHigh
- btst.b #3,$60000E
- beq GLSetHigh
- dbra.w d2,GLWaitW1
- bra GLEnd
- GLSetHigh
- bclr.b #0,$60000E ; Set R1
- bclr.b #1,$60000E ; Set W1
- move.w #$0010,d2
- GLWaitR1_2:
- btst.b #2,$60000E
- beq GLCont1
- btst.b #2,$60000E
- beq GLCont1
- dbra.w d2,GLWaitR1_2
- GLCont1:
- move.w #$0010,d2
- GLWaitW1_2:
- btst.b #3,$60000E
- beq GLCont2
- btst.b #3,$60000E
- beq GLCont2
- dbra.w d2,GLWaitW1_2
- GLCont2:
- dbra.w d4,GLNextBit
- GLEnd:
- bclr.b #0,$60000E ; Set R1
- bclr.b #1,$60000E ; Set W1
-
- btst.b #0,(SwapL)
- beq GLNoSwap
- not.l d3
-
- GLNoSwap
- movem (a7)+,d1-d2
- rts
-
- ;*****************************************************
- ;
- ; Convert between frequency in KHz to delay units needed by the IR Link.
- ; Input: d2.b Freq in KHz.
- ; Output: d3.w contains the 2 delay values.
- ; Used: a2
- ;
- irlib@0004:
- Freq2Delay:
- sub.b #30,d2 ; Substract 30KHz from it.
- andi #30,d2
- lea DelayTab(PC),a2 ; Now A2 points to the delay table.
- move.w 0(a2,d2),d3 ; Copy the 2 delay values corresponding
- ; to the freq to d3.
- rts
-
-
-
-
- ;*****************************************************
-
-
- DelayTab: ; To convert between KHz and delay units.
- dc.b $0F,$0B
- dc.b $10,$0C
- dc.b $11,$0D
- dc.b $12,$0E
- dc.b $12,$0F
- dc.b $13,$0F
- dc.b $14,$10
- dc.b $14,$11
- dc.b $15,$11
- dc.b $15,$12
-
- LDelay:
- dc.w $00FF
- Timeout:
- dc.w $FFFF
- SwapL:
- dc.w 0
-
- Text1: dc.b "Settings",0
- Text2: dc.b "Swap Lines:",0
- Text3: dc.b "Timeout duration:",0
- Text4: dc.b "Linking Delay:",0
- Text5: dc.b "On ",0
- Text6: dc.b "Off",0
-
- _comment dc.b "IR Link Library",0
-
- end
-