home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 82 / asm / source / ash / irchat82.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  12.8 KB  |  551 lines

  1.  
  2. ; InfraRed Chat for the IR Link (http://unet.univie.ac.at/~a9501901/irlink)
  3. ;   by Sami Khawam (sKhawam@bigfoot.com)
  4. ;   http://unet.univie.ac.at/~a9501901
  5. ;
  6. ; NOTE: The Keys indexes are had been fixed.
  7. ; This is for ASH.
  8. ;
  9. ; No WhiteBoard support! (Chat can be made with a TI85 or TI85, but
  10. ; no drawings ... :( 
  11. ;
  12. ; Thanks for Randy Gluvna (gluvna@home.com) for his recieve routine.
  13. ; Thanks for Osma Suominen (ozone@clinet.fi) for his keys scaning
  14. ; codes for the TI85, and for his MChat.
  15. ;
  16. ;
  17. ;                               - Sami Khawam
  18.  
  19. #INCLUDE "TI82.H"
  20. #INCLUDE "KEYS.INC"
  21.  
  22. PORT = 000H
  23.  
  24. .ORG START_ADDR
  25. .db "IR Chat v.12 ",0
  26. BySK:
  27. .db "by Sami Khawam", 0
  28.  
  29.  
  30. BufferLen       =       APD_BUF    ; String length
  31. TextBuffer      =       APD_BUF+1
  32.  
  33. KeyFlags        =       GRAPH_MEM        ; 0000xxxx
  34.                                         ; bit 0 = Alpha
  35.                                         ; bit 1 = Num
  36.                                         ; bit 2 = Lock
  37. CursorX         =       KeyFlags + 1
  38. ScreenX         =       CursorX + 1
  39. ScreenY         =       ScreenX + 1
  40. iCursor         =       ScreenY + 1
  41.  
  42.  
  43.  
  44. Init:
  45.         ROM_CALL(CLEARLCD)
  46.  
  47.         ld      a, 4
  48.         out     (5), a
  49.  
  50.         ld      de, $0102
  51.         ld      (CURSOR_ROW), de
  52.         ld      hl, ProgName
  53.         ROM_CALL(D_ZT_STR)            
  54.         ld      de, $0103
  55.         ld      (CURSOR_ROW), de
  56.         ld      hl, BySK
  57.         ROM_CALL(D_ZT_STR)            
  58.  
  59.         ld      hl, $0004
  60.         ld      (ScreenX), hl
  61.         xor     a           
  62.         ld      (KeyFlags), a
  63.         ld      a, $DC
  64.         ld      (iCursor), a
  65.         jp      ClearInput
  66.  
  67.  
  68.  
  69.  
  70. MainLoop:
  71.         ld      a, $C0          ; Set W1 and R1
  72.         out     (0), a
  73.  
  74.         in      a, (0)
  75.         and     3
  76.         cp      3
  77.         jp      nz, ReceiveLine ; Only one line low.
  78.  
  79.  
  80.  
  81. GetKey:
  82.         call GET_KEY
  83.         or a                    ; No key pressed
  84.         jr z, MainLoop
  85.         cp G_MODE
  86.         ret z
  87.         cp G_DEL
  88.         jp z, BackSpace
  89.         cp G_ENTER
  90.         jp z, SendLine
  91.         cp G_CLEAR
  92.         jp z, ClearInput
  93.         cp G_2nd
  94.         jp z, SetNumber
  95.         cp G_ALPHA
  96.         jp z, SetAlpha
  97.  
  98.         cp      $0a                 ; Ignore the arrows and 'Enter'.
  99.         jp      c, MainLoop
  100.  
  101.         sub     $0a     
  102.  
  103.         ld      hl, Scan2Index
  104.         ld      d,0
  105.         ld      e,a
  106.         add     hl,de
  107.         ld      a,(hl)               ; a=ascii value of key
  108.         or      a
  109.         jp      z, MainLoop          ; Invalid key - loop
  110.         ld      c, a
  111.  
  112.         ld      a, (KeyFlags)
  113.         and     1
  114.         jr      nz, AlphaSet
  115.         ld      a, (KeyFlags)
  116.         and     2
  117.         jr      nz, NumSet
  118.  
  119.  
  120.         ld      a, c
  121.         ld      hl, Index2Ascii
  122.         ld      d,0
  123.         ld      e,a
  124.         add     hl,de
  125.         ld      a,(hl)               ; a=ascii value of key
  126.         or      a
  127.         jp      z, MainLoop          ; Invalid key - loop
  128.         jr      Continue2
  129.  
  130.  
  131. AlphaSet:
  132.         ld      a, c
  133.         ld      hl, Index2Shift
  134.         ld      d,0
  135.         ld      e,a
  136.         add     hl,de
  137.         ld      a,(hl)               ; a=ascii value of key
  138.         or      a
  139.         jp      z, MainLoop          ; Invalid key - loop
  140.         ld      c, a
  141.         jr      Continue
  142.  
  143. NumSet:
  144.         ld      a, c
  145.         ld      hl, Index2Num
  146.         ld      d,0
  147.         ld      e,a
  148.         add     hl,de
  149.         ld      a,(hl)               ; a=ascii value of key
  150.         or      a
  151.         jp      z, MainLoop          ; Invalid key - loop
  152.         ld      c, a
  153.  
  154.  
  155. Continue:
  156.         ld      a, (KeyFlags)
  157.         and     4
  158.         jr      nz, IsLocked
  159.         xor     a
  160.         ld      (KeyFlags), a
  161.         ld      a, $DC
  162.         ld      (iCursor), a
  163.         call    PrintInput
  164.  
  165. IsLocked:
  166.         ld      a, c
  167. Continue2:
  168.         ld      b, a
  169.         ld      hl, TextBuffer
  170.         ld      d, 0
  171.         ld      a, (BufferLen)
  172.         ld      e, a
  173.         add     hl, de
  174.         ld      (hl), b
  175.  
  176.         ld      a, (BufferLen)
  177.         inc     a
  178.         ld      (BufferLen), a
  179.  
  180.         ld      a, (CursorX)
  181.         cp      12
  182.         jr      nz, NoDecal
  183.  
  184. PrintInputLine:
  185.         ld      hl, $0000
  186.         ld      (CURSOR_ROW), hl
  187.  
  188.         ld      a, (BufferLen)
  189.         sub     12
  190.         ld      hl, TextBuffer
  191.         ld      d, 0
  192.         ld      e, a
  193.         add     hl, de
  194.  
  195.         ld      b, 12
  196.         ld      a, $CE
  197.         ROM_CALL(TX_CHARPUT)            
  198. NextChar:
  199.         ld      a, (hl)
  200.         ROM_CALL(TX_CHARPUT)            
  201.         inc     hl
  202.         djnz    NextChar
  203.         call    PrintInput
  204.         jp      MainLoop
  205.  
  206. NoDecal:
  207.         inc     a
  208.         ld      (CursorX), a
  209.         ld      a, b
  210.         ROM_CALL(TX_CHARPUT)            
  211.         call    PrintInput
  212.         jp      MainLoop
  213.  
  214.  
  215. BackSpace:
  216.         ld      a, (BufferLen)
  217.         or      a
  218.         jp      z, MainLoop
  219.         dec     a
  220.         ld      (BufferLen), a
  221.  
  222.         ld      a, (CursorX)
  223.         cp      12
  224.         jr      nz, FirstCh
  225.         ld      a, (BufferLen)
  226.         cp      11              ; !!!!!!
  227.         jp      nz, PrintInputLine
  228. FirstCh
  229.         dec     a
  230.         ld      (CursorX), a
  231.         ld      a, ' '
  232.         ROM_CALL(TX_CHARPUT)            
  233.         ld      a, (CURSOR_COL)
  234.         dec     a
  235.         dec     a
  236.         ld      (CURSOR_COL), a
  237.         call    PrintInput
  238.         jp      MainLoop
  239.  
  240.  
  241. SetAlpha:
  242.         ld      a, (KeyFlags)
  243.         and     1
  244.         jr      z, ASet
  245.         ld      a, (KeyFlags)
  246.         and     4                       
  247.         jr      z, ALock
  248.         xor     a
  249.         ld      (KeyFlags), a           ; Normal set
  250.         ld      a, $DC
  251.         jr      ANEnd
  252. ASet
  253.         ld      a, 1
  254.         ld      (KeyFlags), a           ; Alpha set
  255.         ld      a, $DF
  256.         jr      ANEnd
  257. ALock
  258.         ld      a, 5
  259.         ld      (KeyFlags), a           ; Alpha locked
  260.         ld      a, $DB
  261. ANEnd
  262.         ld      (iCursor), a
  263.         call    PrintInput
  264.         jp      MainLoop
  265.  
  266.  
  267. SetNumber:
  268.         ld      a, (KeyFlags)
  269.         and     2
  270.         jr      z, NSet
  271.         ld      a, (KeyFlags)
  272.         and     4                       
  273.         jr      z, NLock
  274.         xor     a
  275.         ld      (KeyFlags), a           ; Normal set
  276.         ld      a, $DC
  277.         jr      SNEnd
  278. NSet
  279.         ld      a, 2
  280.         ld      (KeyFlags), a           ; Num set
  281.         ld      a, $DD
  282.         jr      SNEnd
  283. NLock
  284.         ld      a, 6
  285.         ld      (KeyFlags), a           ; Num locked
  286.         ld      a, $D9
  287. SNEnd
  288.         ld      (iCursor), a
  289.         call    PrintInput
  290.         jp      MainLoop
  291.  
  292.  
  293.  
  294. SendLine
  295.         ld      a, (BufferLen)
  296.         or      a
  297.         jp      z, MainLoop
  298.         ld      b, a
  299.         call    ScrollPage
  300.         ld      hl, TextBuffer
  301. NextByte
  302.         ld      a,   (hl)              
  303.         ROM_CALL(TX_CHARPUT)            
  304.         call    PutByte           ; Now we send all bytes.
  305.         inc     hl
  306.         djnz    NextByte
  307.         ld      de, (CURSOR_ROW)
  308.         inc     de
  309.         ld      d, 0
  310.         ld      (CURSOR_ROW), de
  311.         ld      (ScreenX), de
  312.         ld      a, $FE
  313.         call    PutByte           ; Send 'Enter'.
  314.  
  315.  
  316. ClearInput:
  317.         xor     a               ;ld      a, 0
  318.         ld      (BufferLen), a
  319.         inc     a
  320.         ld      (CursorX), a
  321.         ld      hl, $0200
  322.         ld      (CURSOR_ROW), hl
  323.         ld      b, 12
  324.         ld      a, ' '
  325. NextBlank:
  326.         ROM_CALL(TX_CHARPUT)            
  327.         djnz    NextBlank
  328.         ld      hl, $0000
  329.         ld      (CURSOR_ROW), hl
  330.         ld      a, '>'
  331.         ROM_CALL(TX_CHARPUT)            
  332.         call    PrintInput
  333.         jp      MainLoop
  334.  
  335.  
  336. PrintInput
  337.         ld      a, (iCursor)
  338.         ROM_CALL(TX_CHARPUT)            
  339.         ld      a, (CURSOR_COL)
  340.         dec     a
  341.         ld      (CURSOR_COL), a
  342.         ret
  343.  
  344.  
  345. ScrollPage:
  346.         ld      hl, (ScreenX)
  347.         ld      (CURSOR_ROW), hl
  348.         ld      a, l                   
  349.         cp      8
  350.         ret     nz
  351.         dec     hl
  352.         ld      (CURSOR_ROW), hl
  353.         ld      a, 1
  354.         ld      ($8C8F),a         ;Starting row is 1
  355.         ld      a, 8
  356.         ld      ($8C90),a         ;Last row to scroll is 7
  357.         res     1, (IY+0D)      ; don't scroll the text memory!!!!!!!!!!!!!
  358.         ROM_CALL(SCROLL_UP)  
  359.         ret
  360.  
  361.  
  362.  
  363. ReceiveLine:
  364.         call    GetByte
  365.         or      a
  366.         jp      z, MainLoop     
  367.  
  368.         ld      c, a
  369.         call    ScrollPage
  370.         ld      a, c
  371.         cp      $FE
  372.         jr      z, NextLine
  373.         ROM_CALL(TX_CHARPUT)            
  374.         jr      NoNextLine
  375. NextLine:
  376.         inc     hl
  377.         ld      h, 0
  378.         ld      (CURSOR_ROW), hl
  379. NoNextLine:
  380.         ld      hl, (CURSOR_ROW)
  381.         ld      (ScreenX), hl
  382.         ld      a, (CursorX)
  383.         ld      d, a
  384.         ld      e, 0
  385.         ld      (CURSOR_ROW), de
  386.         jp      MainLoop
  387.  
  388.  
  389.  
  390. ; Thanks for Randy Gluvna (gluvna@home.com) for this recieve routine.
  391.  
  392.  
  393.  
  394. GetByte:
  395.         LD      B,008H
  396. R0:
  397.         LD      DE,0FFFFH       
  398.         JR      R2              
  399. R1:
  400.         IN      A,(PORT)        
  401.         AND     003H            
  402.         RET     Z               
  403.         CP      003H            
  404.         JR      NZ,R3           
  405.         IN      A,(PORT)        
  406.         AND     003H            
  407.         RET     Z               
  408.         CP      003H            
  409.         JR      NZ,R3           
  410. R2:
  411.         DEC     DE              
  412.         LD      A,D             
  413.         OR      E               
  414.         JR      NZ,R1           
  415.         RET                     
  416. R3:
  417.         SUB     002H            
  418.         JR      NC,R8           
  419.         LD      A,0D4H          
  420.         OUT     (PORT),A        
  421.         RR      C               
  422.         LD      DE,0FFFFH       
  423. R4:
  424.         IN      A,(PORT)        
  425.         AND     003H            
  426.         CP      002H            
  427.         JR      Z,R5            
  428.         DEC     DE              
  429.         LD      A,D             
  430.         OR      E               
  431.         JR      NZ,R4           
  432.         RET                     
  433. R5:
  434.         LD      A,0C0H          
  435.         OUT     (PORT),A        
  436.         LD      D,004H          
  437. R6:
  438.         DEC     D               
  439.         JR      Z,R7            
  440.         IN      A,(PORT)        
  441.         AND     003H            
  442.         CP      003H            
  443.         JR      NZ,R6           
  444. R7:
  445.         DJNZ    R0              
  446.         LD      A,C             
  447.         RET                     
  448. R8:
  449.         LD      A,0E8H          
  450.         OUT     (PORT),A        
  451.         RR      C               
  452.         LD      DE,0FFFFH       
  453. R9:
  454.         IN      A,(PORT)        
  455.         AND     003H            
  456.         CP      001H            
  457.         JR      Z,R5            
  458.         DEC     DE              
  459.         LD      A,D             
  460.         OR      E               
  461.         JR      NZ,R9           
  462.         RET                     
  463.  
  464.  
  465. PutByte:
  466.         push bc
  467.         LD      C,A
  468.         LD      B,8             ; 8 Bits
  469. PB_Next_Bit:
  470.         LD      A, $C0          ; Set W1 and R1
  471.         OUT     (0),A
  472.  
  473. Cont:
  474.         RR      C
  475.         JR      NC, PB_SendZero
  476. PB_SendOne:
  477.         LD      A, $E8
  478.         JR      PB_Output_val
  479. PB_SendZero:
  480.         LD      A, $D4
  481. PB_Output_val:
  482.         OUT     (0),A
  483.  
  484.         LD      DE, $FFFF       ; For time-out
  485. PB_Wait_for_W0_and_R0:
  486.         IN      A,(0)
  487.         AND     3
  488.         JR      Z, PB_Continue
  489.         IN      A,(0)
  490.         AND     3
  491.         JR      Z, PB_Continue
  492.         DEC     DE
  493.         LD      A,D
  494.         OR      E
  495.         JR      NZ, PB_Wait_for_W0_and_R0
  496.         JR      PB_End          ; If error return.
  497.  
  498. PB_Continue:
  499.         LD      A, $C0          ; Set W1 and R1
  500.         OUT     (0),A
  501.  
  502.         LD      DE, $FFFF       ; Reload time-out
  503. PB_Wait_for_W1_and_R1:
  504.         DEC     DE
  505.         LD      A,D
  506.         OR      E
  507.         JR      Z, PB_End
  508.         IN      A,(0)
  509.         AND     3
  510.         CP      3
  511.         JR      NZ, PB_Wait_for_W1_and_R1
  512.  
  513.         DJNZ    PB_Next_Bit
  514. PB_End:
  515.         POP    BC
  516.         RET
  517.  
  518.  
  519. Scan2Index:
  520. .db 1, 2, 3, 4, 5, 0, 0, 6, 7, 8, 9, 10, 11
  521. .db 1, 2, 12, 13, 14, 15, 16, 17, 18
  522. .db 0, 19, 20, 21, 22, 23, 24, 25, 0
  523. .db 0, 26, 27, 28, 29, 30, 31
  524.  
  525.  
  526.  
  527. Index2Ascii:
  528. ; Plain
  529. .db 0,$22, "wrmh?", $c1,
  530. .db "vqlg:zupkfc yto"
  531. .db "jebxsnida"
  532.  
  533. Index2Shift:
  534. .db 0,$22, "WRMH?", $c1,
  535. .db "VQLG:ZYPKFC YTO"
  536. .db "JEBXSNIDA"
  537.  
  538. Index2Num:
  539. .db 0,"+-*/^-3"
  540. .db "69)", 34, ".258(", 196, "!0147"
  541. .db "E<>=e", $1D, $D3, 206, "?"
  542.  
  543.  
  544.  
  545. ProgName:
  546. .db "InfraRed Chat", 0
  547.  
  548. .end
  549.  
  550.