include "tios.h" include "flib.h" include "graphlib.h" include "irlib.h" xdef _main xdef _comment INBUF_SIZE equ 128 MAX_COL equ 37 ; 37 for the TI92 MAX_LINES equ 11 ; 11 for the TI89 (TI92?) MAX_X equ 238 ; 238 for the TI92 MAX_Y equ 113 ; 100 for the TI89 (128 for the 92) SPACE_X equ 6 ; 6 for normal font SPACE_Y equ 8 ; 8 for normal font KEEP_SIZE equ 300 ; 10*30 ; The 10 is for the 10 lines of the ; command line. SCROLL_SIZE equ 540 ; SPACE_Y*30 + KEEP_SIZE SIZE_SBUF equ 3010 ; 100*30-540-7*30 (7*30 for status line) SetFont macro move.w \1,-(a7) jsr tios::FontSetSys lea 2(a7),a7 endm WriteStr macro move.w \3,-(a7) pea \4(pc) move.w \2,-(a7) move.w \1,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 endm ; _main: clr.b $60000C bset.b #6,$60000C ; Turn on control mode bclr.b #0,$60000E ; Set R1 bclr.b #1,$60000E ; Set W1 move.l #SIZE_SBUF,-(a7) ; Allocate memory for a temp buffer. jsr tios::HeapAlloc lea 4(a7),a7 tst.w d0 beq error1 move.w d0,hTmpBuf tios::DEREF d0,a0 move.l a0,TmpBuf move.l #INBUF_SIZE,-(a7) ; Allocate memory for input buffer. jsr tios::HeapAlloc lea 4(a7),a7 tst.w d0 beq error2 move.w d0,hInBuf tios::DEREF d0,a0 move.l a0,InBuf ClearScreen: jsr flib::clr_scr SetFont #2 WriteStr #48,#14,#1,Text1 WriteStr #112,#26,#1,Text2 WriteStr #76,#38,#1,Text3 move.l #30,-(a7) ; Draw a horizontal line move.w #$FFFF,-(a7) move.l #LCD_MEM+270,-(a7) jsr tios::memset lea 10(a7),a7 clr.w d4 ; d4 : Input len clr.w iX move.w #51,iY SetFont #1 MainLoop: move.l InBuf,a0 PrintCmd jsr PrintCmdLine WaitKey: tst.w (tios::kb_vars+$1C) beq CheckLines move.w (tios::kb_vars+$1E),d0 clr.w (tios::kb_vars+$1C) cmp.w #264,d0 beq Exit cmp.w #257,d0 ; Backspace ? beq BackSp cmp.w #263,d0 ; Clear ? beq ClearCmd cmp #13,d0 ; Enter ? beq SendCmdLine cmp.w #255,d0 ;Valid character ? bhi WaitKey ;no => loop cmp.w #INBUF_SIZE,d4 ;Maxchar ? beq WaitKey addq.w #1,d4 ; Add charachter to buf. move.b d0,(a0)+ bra PrintCmd BackSp tst.w d4 beq WaitKey subq.w #1,d4 tst.b -(a0) bra PrintCmd CheckLines: btst.b #2,$60000E bne ReceiveData btst.b #3,$60000E bne ReceiveData bra WaitKey ReceiveData movem.l d3-d4/a0,-(a7) jsr irlib::GetByte jsr PrintChar jsr PrintCmdLine movem.l (a7)+,d3-d4/a0 bra WaitKey SendCmdLine tst.w d4 beq WaitKey move.b #$FE,(a0) ;the New Line code move.l InBuf,a0 SNextByte move.b (a0)+,d3 movem.l d3-d4/a0,-(a7) jsr irlib::PutByte movem.l (a7)+,d3-d4/a0 movem.l d3-d4/a0,-(a7) jsr PrintChar movem.l (a7)+,d3-d4/a0 dbra.b d4,SNextByte ClearCmd tst.w d4 ; If 2 consecutive [Clear]'s then clear beq ClearScreen ; the whole screen clr.w d4 ; If not, clear command line only. move.l InBuf,a0 bra PrintCmd Exit: move.w hInBuf(PC),-(a7) jsr tios::HeapFree lea 2(a7),a7 error2 move.w hTmpBuf(PC),-(a7) jsr tios::HeapFree lea 2(a7),a7 error1 jsr tios::reset_link rts ;********************************************************************* PrintChar: cmp.b #$FE,d3 bne NoNewLine addi.w #SPACE_Y,iY clr.w iX bra RDCont NoNewLine movem.l d0-d4/a0,-(a7) move.w #$00FF,-(A7) move.w #$0000,-(A7) move.w #$00FF,-(A7) move.w #2,-(a7) move.w iY,-(a7) move.w iX,-(a7) move.w d3,-(a7) jsr tios::DrawCharXY lea 14(a7),a7 movem.l (a7)+,d0-d4/a0 addi.w #SPACE_X,iX cmp.w #MAX_X,iX ble RDCont addi.w #SPACE_Y,iY clr.w iX RDCont cmp.w #MAX_Y,iY ble RDNoScroll movem.l d0-d4/a0,-(a7) move.l TmpBuf,a0 move.l #SIZE_SBUF,-(a7) move.l #LCD_MEM+SCROLL_SIZE,-(a7) move.l a0,-(a7) jsr tios::memcpy lea 12(a7),a7 jsr flib::clr_scr ; Won't erase status line. move.l TmpBuf,a0 move.l #SIZE_SBUF,-(a7) move.l a0,-(a7) move.l #LCD_MEM+KEEP_SIZE,-(a7) jsr tios::memcpy lea 12(a7),a7 move.l #30,-(a7) ; Redraw the horizontal line move.w #$FFFF,-(a7) move.l #LCD_MEM+270,-(a7) jsr tios::memset lea 10(a7),a7 movem.l (a7)+,d0-d4/a0 subi.w #SPACE_Y,iY RDNoScroll rts ;********************************************************************* PrintCmdLine: move.b #95,(a0) ;the '_' char clr.b 1(a0) movem.l d0-d7/a0-a6,-(a7) clr.w d0 clr.w d1 move.w #237,d2 moveq.w #7,d3 moveq.w #1,d4 jsr graphlib::fill movem.l (a7)+,d0-d7/a0-a6 movem.l d0-d7/a0-a6,-(a7) cmp.w #MAX_COL,d4 ble NoCut subi.w #MAX_COL,d4 move.l InBuf,a0 add.l d4,a0 move.w #160,d2 ; The '...' Char bra DrawStr NoCut: move.l InBuf,a0 move.w #62,d2 ; The '>' Char DrawStr: movem.l d0-d4/a0,-(a7) move.w #$00FF,-(A7) move.w #$0000,-(A7) move.w #$00FF,-(A7) move.w #1,-(a7) move.w #0,-(a7) move.w #0,-(a7) move.w d2,-(a7) jsr tios::DrawCharXY lea 14(a7),a7 movem.l (a7)+,d0-d4/a0 move.w #4,-(a7) move.l a0,-(a7) clr.w -(a7) move.w #7,-(a7) jsr tios::DrawStrXY lea 10(a7),a7 movem.l (a7)+,d0-d7/a0-a6 rts hInBuf dc.w 0 InBuf dc.l 0 hTmpBuf dc.w 0 TmpBuf dc.l 0 iX dc.w 0 iY dc.w 0 Text1: dc.b "InfraRed Chat v0.1",0 Text2: dc.b "by",0 Text3: dc.b "Sami Khawam",0 _comment: dc.b "IR Chat v0.1",0 end