home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 89 / asm / source / irchat.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  7.7 KB  |  338 lines

  1.  
  2.  
  3. ;InfraRed Chat v0.1 for TI89
  4. ; by Sami Khawam
  5. ; sKhawam@bigfoot.com
  6. ;--------------------
  7. ;
  8. ;This is a port from the TI85 version.
  9. ;I wrote this little chat program in order to use it with my
  10. ;IR Link (see my page at: http://unet.univie.ac.at/~a9501901 ).
  11. ;
  12. ;Features and known bugs:
  13. ;-----------------------
  14. ;
  15. ;-In this version ther is NO WhiteBoard support, since I
  16. ; hadn't the time to convert it.
  17. ;
  18. ;-You can communicate with a TI82, TI83, TI85, TI86 and TI92.
  19. ; This program is compatible with IR_Term by Antoine Mercier.
  20. ;
  21. ;-I am including the source code with it.
  22. ;
  23. ;
  24. ;When using the program with the IR Link, the mode of the link
  25. ;should be set to the 'TI protocol without Ack' mode.
  26. ;
  27. ;If you don't have (yet) built an IR Link and you want to test
  28. ;this program you can connnect 2 calcs with the cable and test
  29. ;it; you cannot connect more that 2 calcs if you use the cable,
  30. ;but if you use the IR Link, you can communicate with as many
  31. ;calcs as you want.
  32. ;
  33. ;
  34. ;                                -Sami Khawam
  35. ;                                 sKhawam@bigfoot.com
  36. ;
  37.  
  38.  
  39.     include "doorsos.h"
  40.     include "graphlib.h"
  41.     include "userlib.h"
  42.    include "hexlib.h"
  43.    include "irlib.h"
  44.  
  45.     xdef    _ti89
  46.     xdef    _main
  47.     xdef    _comment
  48.  
  49.  
  50. INBUF_SIZE  equ   128
  51. MAX_COL     equ   24                   ; 24 for the TI89
  52. MAX_LINES   equ   11                   ; 11 for the TI89
  53. MAX_X       equ   155                  ; 155 for the TI89
  54. MAX_Y       equ   88                   ; 100 for the TI89
  55. SPACE_X     equ   6                    ; 6 for normal font;
  56. SPACE_Y     equ   8                    ; 8 for normal font;
  57. KEEP_SIZE   equ   300                  ; 10*30 
  58.                                        ; The 10 is for the 10 lines of the
  59.                                        ; command line.
  60. SCROLL_SIZE equ   540                  ; SPACE_Y*30 + KEEP_SIZE
  61. SIZE_SBUF   equ   2250                 ; 100*30-540-7*30 (7*30 for status line)
  62.  
  63. SetFont    macro
  64.     move.w    \1,-(a7)
  65.    jsr      doorsos::FontSetSys
  66.    lea      2(a7),a7
  67.     endm
  68. WriteStr    macro
  69.     move.w    \3,-(a7)
  70.    pea      \4(pc)
  71.     move.w    \2,-(a7)
  72.     move.w    \1,-(a7)
  73.    jsr      doorsos::DrawStrXY
  74.    lea      10(a7),a7
  75.     endm
  76.  
  77.  
  78. _main:
  79.  
  80.    clr.b    $60000C
  81.    bset.b   #6,$60000C      
  82.    bclr.b   #0,$60000E        ; Set R1
  83.    bclr.b   #1,$60000E        ; Set W1
  84.  
  85.  
  86.    move.l   #SIZE_SBUF,-(a7)           ; Allocate memory for a temp buffer.
  87.    jsr      doorsos::HeapAlloc
  88.    lea      4(a7),a7
  89.    tst.w    d0
  90.    beq      error1
  91.    move.w   d0,hTmpBuf
  92.    doorsos::DEREF d0,a0
  93.    move.l   a0,TmpBuf
  94.  
  95.    move.l   #INBUF_SIZE,-(a7)           ; Allocate memory for input buffer.
  96.    jsr      doorsos::HeapAlloc
  97.    lea      4(a7),a7
  98.    tst.w    d0
  99.    beq      error2
  100.    move.w   d0,hInBuf
  101.    doorsos::DEREF d0,a0
  102.    move.l   a0,InBuf
  103.  
  104.  
  105. ClearScreen:
  106.    jsr      graphlib::clr_scr2
  107.  
  108.    SetFont  #2
  109.    WriteStr #8,#14,#1,Text1
  110.    WriteStr #62,#26,#1,Text2
  111.    WriteStr #34,#38,#1,Text3
  112.  
  113.    move.l   #30,-(a7)              ; Draw a horizontal line
  114.    move.w   #$FFFF,-(a7)
  115.    move.l   #LCD_MEM+270,-(a7)
  116.    jsr      doorsos::memset
  117.    lea      10(a7),a7
  118.  
  119.    clr.w    d4                ; d4 : Input len
  120.    clr.w    iX
  121.    move.w   #51,iY
  122.    SetFont  #1
  123.  
  124.  
  125. MainLoop:
  126.  
  127.    move.l   InBuf,a0
  128.  
  129. PrintCmd
  130.    jsr      PrintCmdLine
  131.  
  132. WaitKey:
  133.    tst.w    (doorsos::kb_vars+$1C)
  134.    beq      CheckLines
  135.    move.w   (doorsos::MaxHandles+$1E),d0
  136.    clr.w    (doorsos::kb_vars+$1C)
  137.    cmp.w    #264,d0
  138.    beq      Exit
  139.    cmp.w    #257,d0                 ; Backspace ?
  140.    beq      BackSp
  141.    cmp.w    #263,d0                 ; Clear ?
  142.    beq      ClearCmd
  143.    cmp      #13,d0                  ; Enter ?
  144.    beq      SendCmdLine
  145.  
  146.    cmp.w    #255,d0           ;Valid character ?
  147.    bhi      WaitKey           ;no => loop
  148.    cmp.w    #INBUF_SIZE,d4    ;Maxchar ?
  149.    beq      WaitKey
  150.  
  151.    addq.w   #1,d4          ; Add charachter to buf.
  152.    move.b   d0,(a0)+
  153.    bra      PrintCmd
  154.  
  155. BackSp
  156.    tst.w    d4
  157.    beq      WaitKey
  158.    subq.w   #1,d4
  159.     tst.b        -(a0)
  160.    bra      PrintCmd
  161.    
  162.  
  163. CheckLines:
  164.    btst.b   #2,$60000E
  165.    bne      ReceiveData
  166.    btst.b   #3,$60000E
  167.    bne      ReceiveData
  168.    bra      WaitKey
  169. ReceiveData
  170.    movem.l  d3-d4/a0,-(a7)
  171.    jsr      irlib::GetByte
  172.    jsr      PrintChar
  173.    jsr      PrintCmdLine
  174.    movem.l  (a7)+,d3-d4/a0
  175.    bra      WaitKey
  176.  
  177.  
  178. SendCmdLine
  179.    tst.w    d4
  180.    beq      WaitKey
  181.    move.b   #$FE,(a0)       ;the New Line code
  182.    move.l   InBuf,a0
  183. SNextByte
  184.    move.b   (a0)+,d3
  185.    movem.l  d3-d4/a0,-(a7)
  186.    jsr      irlib::PutByte
  187.    movem.l  (a7)+,d3-d4/a0
  188.    movem.l  d3-d4/a0,-(a7)
  189.    jsr      PrintChar
  190.    movem.l  (a7)+,d3-d4/a0
  191.    dbra.b   d4,SNextByte
  192.  
  193. ClearCmd
  194.    tst.w    d4                ; If 2 consecutive [Clear]'s then clear
  195.    beq      ClearScreen       ; the whole screen
  196.    clr.w    d4                ; If not, clear command line only.
  197.    move.l   InBuf,a0
  198.    bra      PrintCmd
  199.  
  200.  
  201.  
  202. Exit:
  203.    move.w  hInBuf(PC),-(a7)
  204.    jsr     doorsos::HeapFree
  205.    lea     2(a7),a7
  206. error2
  207.    move.w  hTmpBuf(PC),-(a7)
  208.    jsr     doorsos::HeapFree
  209.    lea     2(a7),a7
  210. error1
  211.    jsr      doorsos::reset_link
  212.     rts
  213.  
  214. ;*********************************************************************
  215.  
  216. PrintChar:
  217.    cmp.b    #$FE,d3
  218.    bne      NoNewLine
  219.    addi.w   #SPACE_Y,iY
  220.    clr.w    iX
  221.    bra      RDCont
  222.  
  223. NoNewLine
  224.    movem.l  d0-d4/a0,-(a7)
  225.    move.w   #1,-(a7)
  226.    move.w   iY,-(a7)
  227.    move.w   iX,-(a7)
  228.    move.w   d3,-(a7)
  229.    jsr      userlib::DrawCharXY
  230.    lea      8(a7),a7
  231.    movem.l  (a7)+,d0-d4/a0
  232.  
  233.    addi.w   #SPACE_X,iX
  234.  
  235.    cmp.w    #MAX_X,iX
  236.    ble      RDCont
  237.    addi.w   #SPACE_Y,iY
  238.    clr.w    iX
  239.  
  240. RDCont
  241.    cmp.w    #MAX_Y,iY
  242.    ble      RDNoScroll
  243.  
  244.    movem.l  d0-d4/a0,-(a7)
  245.  
  246.    move.l   TmpBuf,a0
  247.  
  248.    move.l   #SIZE_SBUF,-(a7)             
  249.    move.l   #LCD_MEM+SCROLL_SIZE,-(a7)    
  250.    move.l   a0,-(a7)                
  251.    jsr      doorsos::memcpy         
  252.    lea      12(a7),a7
  253.  
  254.    jsr      graphlib::clr_scr2      ; Won't erase status line.
  255.  
  256.    move.l   TmpBuf,a0
  257.  
  258.    move.l   #SIZE_SBUF,-(a7)             
  259.    move.l   a0,-(a7)                
  260.    move.l   #LCD_MEM+KEEP_SIZE,-(a7)    
  261.    jsr      doorsos::memcpy         
  262.    lea      12(a7),a7
  263.  
  264.    move.l   #30,-(a7)              ; Redraw the horizontal line
  265.    move.w   #$FFFF,-(a7)
  266.    move.l   #LCD_MEM+270,-(a7)
  267.    jsr      doorsos::memset
  268.    lea      10(a7),a7
  269.  
  270.    movem.l  (a7)+,d0-d4/a0
  271.  
  272.    subi.w   #SPACE_Y,iY
  273. RDNoScroll
  274.    rts
  275.  
  276.  
  277. ;*********************************************************************
  278.  
  279. PrintCmdLine:
  280.    move.b   #95,(a0)       ;the '_' char
  281.    clr.b    1(a0)
  282.  
  283.    movem.l  d0-d7/a0-a6,-(a7)
  284.    clr.w    d0
  285.    clr.w    d1
  286.    move.w   #160,d2
  287.    moveq.w  #7,d3
  288.    moveq.w  #1,d4
  289.    jsr      graphlib::fill
  290.     movem.l    (a7)+,d0-d7/a0-a6
  291.  
  292.    movem.l  d0-d7/a0-a6,-(a7)
  293.    cmp.w    #MAX_COL,d4
  294.    ble      NoCut
  295.    subi.w   #MAX_COL,d4
  296.    move.l   InBuf,a0
  297.    add.l    d4,a0
  298.    move.w   #160,d2           ; The '...' Char
  299.    bra      DrawStr
  300. NoCut
  301.    move.l   InBuf,a0
  302.    move.w   #62,d2            ; The '>' Char
  303. DrawStr
  304.    movem.l  d0-d4/a0,-(a7)
  305.    move.w   #1,-(a7)
  306.    clr.l    -(a7)          ; x and y are 0
  307.    move.w   d2,-(a7)
  308.    jsr      userlib::DrawCharXY
  309.    lea      8(a7),a7
  310.    movem.l  (a7)+,d0-d4/a0
  311.  
  312.    move.w   #1,-(a7)
  313.    move.l   a0,-(a7)
  314.    clr.w    -(a7)
  315.    move.w   #7,-(a7)
  316.    jsr      doorsos::DrawStrXY
  317.    lea      10(a7),a7
  318.  
  319.     movem.l    (a7)+,d0-d7/a0-a6
  320.    rts
  321.  
  322.  
  323.  
  324. hInBuf        dc.w   0
  325. InBuf         dc.l   0
  326. hTmpBuf       dc.w   0
  327. TmpBuf        dc.l   0
  328. iX            dc.w   0
  329. iY            dc.w   0
  330.  
  331.  
  332. Text1:   dc.b  "InfraRed Chat v0.1",0
  333. Text2:   dc.b  "by",0
  334. Text3:   dc.b  "Sami Khawam",0
  335. _comment dc.b  "IR Chat v0.1",0
  336.     end
  337.  
  338.