home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / forst / expect.s < prev    next >
Encoding:
Text File  |  1993-10-23  |  4.8 KB  |  207 lines

  1. ; EXPECT.S: Expect package for console input
  2. ; Copyright <C> John Redmond, 1990,
  3. ; Public domain for non-commercial use.
  4. ;
  5.     section    text
  6.     even
  7. ;
  8. _expect: tst.l    (a6)
  9.     beq.s    .exx
  10.     movem.l    d2/a2-a3,-(a7)
  11.     move.l    (a6),d1            ;buffer address
  12.         move.l  4(a6),d2
  13.         move.l  #32,d0
  14.         movem.l d0-d2,-(a6)
  15.         bsr     _fill            ;clear buffer
  16.         push    #0            ;#chars already in the buffer
  17.         bsr.s    re_expect
  18.         movem.l    (a7)+,d2/a2-a3
  19. .exx:    rts
  20. ;
  21. re_expect: movem.l a2/d2-d5,-(a7)
  22.     pop    d2            ;# chars already in buffer
  23.     pop    d3            ;max # chars
  24.     pop    a2            ;buffer address
  25.     moveq.l    #0,d4            ;# chars on right of cursor
  26.     move.l    d2,d5            ;# chars on left of cursor
  27.     beq.s    .rel            ;no chars in buffer
  28.     push    a2
  29.     push    d2
  30.     bsr    _ctype            ;type what is in the buffer
  31.     sub.l    d2,d3            ;chars to go
  32.     add.l    d2,a2            ;adjust pointer
  33. .rel:    bsr    _ekey            ;keystroke with edit
  34.     tst.l    d1            ;check flag
  35.     bmi.s    .rel            ;neg if char not acceptable
  36.         cmp.b   #13,d0                  ;finished?
  37.         beq.s     .rex
  38.         bsr.s     kpchar
  39.         tst.l    d3            ;# chars to go
  40.         bne.s    .rel
  41. .rex:   lea     span,a1                 ;keep # significant chars
  42.         move.l    d2,(a1)
  43.         bsr    rtype
  44.     bsr     _space
  45.         movem.l    (a7)+,a2/d2-d5
  46.         rts
  47. ;
  48. _ekey:                  ;expects ^buffer, #to go, #so far
  49.     bsr    _xkey
  50.         pop     d0            ;the char
  51.         cmp.w    #$0e08,d0        ;backspace?
  52.         beq    bspace
  53.         cmp.w    #$011b,d0        ;escape?
  54.         beq    bspaces
  55.     cmp.w    #$4b00,d0
  56.     beq    goleft            ;cursor left?
  57.     cmp.w    #$4d00,d0
  58.     beq    goright            ;cursor right?
  59.     cmp.w    #$7300,d0
  60.     beq    farleft            ;cursor left?
  61.     cmp.w    #$7400,d0
  62.     beq    farright        ;cursor right?
  63.         moveq.l    #0,d1            ;flag for an OK char
  64.         cmp.b    #13,d0            ;return
  65.         beq    .ekx
  66.     cmp.b    #32,d0
  67.     bge.s    .ekx
  68. .ek8:    moveq.l    #-1,d1            ;not an OK char
  69. .ekx:    rts
  70. ;
  71. kpchar:    tst.l    d3
  72.     beq.s    .kcx            ;no more room
  73.     bsr.s    insertchar
  74.         bsr.s    showchars
  75.         addq.l  #1,d2            ;char count
  76.         subq.l  #1,d3            ;# chars to go
  77.         addq.l    #1,d5            ;# chars on left of cursor
  78. .kcx:   rts
  79. ;
  80. insertchar: tst.l d4            ;chars on right?
  81.     beq.s    .ic5
  82.     push    d0            ;the char
  83.     lea    1(a2),a0
  84.     push    a2            ;string start
  85.     push    a0            ;string dest
  86.     push    d4            ;# chars right
  87.     bsr    _cmovegt
  88.     pop    d0            ;get the char back
  89. .ic5:    move.b  d0,(a2)+        ;char into buffer
  90. .icx:    rts
  91. ;
  92. showchars:
  93.     push    d0
  94.     bsr    _conout
  95.     tst.l    d4
  96.     beq.s    .scx
  97.     bsr.s    showright
  98. ;    bsr    toright
  99. .scx:    rts
  100. ;
  101. showright: push    #27
  102.     bsr    _conout
  103.     push    #$6a
  104.     bsr    _conout            ;mark cursor position
  105.     push    #27
  106.     bsr    rtype
  107.     bsr    _conout
  108.     push    #$6b
  109.     bsr    _conout            ;restore cursor position
  110.     rts
  111. ;
  112. rtype:    push    a2    
  113.     push    d4
  114.     bsr    _ctype            ;type string after char
  115.     rts
  116. ;
  117. bspace: tst.l   d5
  118.         beq.s     .bsx            ;cannot backspace
  119.         bsr     _bspace
  120.         subq.l  #1,d2            ;# chars so far
  121.         addq.l  #1,d3            ;# chars to go
  122.         subq.l    #1,d5            ;# chars on left
  123.         move.b    #32,-(a2)        ;backup buffer pointer
  124.         tst.l    d4            ;#chars on right
  125.         beq.s    .bsx
  126.         move.l    a2,a0
  127.         addq.l    #1,a0
  128.         push    a0
  129.         push    a2            ;dest
  130.         push    d4
  131.         bsr    _cmove            ;shuffle string left
  132.         move.b    #32,(a2,d4.l)        ;poke a space at the end
  133.         addq.l    #1,d4            ;include space at end
  134.         bsr    showright
  135.         subq.l    #1,d4            ;forget the space
  136. .bsx:   moveq.l    #-1,d1
  137.     rts
  138. ;
  139. bspaces: tst.l   d5
  140.         beq     .bssx                   ;cannot backspace
  141.         push    d4            ;# chars on right
  142.         bsr    _spaces            ;clear on right
  143.         push    d2            ;# chars so far
  144.         bsr     _bspaces                ;# times is on stack
  145.         add.l   d5,d3                   ;restore # chars to go
  146.         suba.l  d5,a2            ;restore pointer
  147.         clr.l    d2            ;# chars so far
  148.         clr.l   d4            ;# chars on right
  149.         clr.l    d5            ;# chars on left
  150.         push    a2
  151.         push    d3
  152.         push    #32
  153.         bsr    _fill            ;clear the buffer
  154. .bssx:  moveq.l    #-1,d1
  155.     rts
  156. ;
  157. farleft: tst.l    d5            ;# chars on left
  158.     beq.s    .flx
  159.     add.l    d5,d4            ;# chars on right
  160.     sub.l    d5,a2            ;char pointer
  161. .fll:    bsr    toleft
  162.     subq.l    #1,d5
  163.     bne.s    .fll
  164. .flx:    moveq.l    #-1,d1
  165.     rts
  166. ;
  167. farright: tst.l    d4            ;# chars on right
  168.     beq.s    .frx
  169.     add.l    d4,d5            ;# chars on left
  170.     add.l    d4,a2            ;char pointer
  171. .frl:    bsr    toright
  172.     subq.l    #1,d4
  173.     bne.s    .frl
  174. .frx:    moveq.l    #-1,d1
  175.     rts
  176. ;
  177. toright: push    #27
  178.     bsr    _conout
  179.     push    #$43
  180.     bsr    _conout            ;cursor right
  181.     rts
  182. ;
  183. toleft:    push    #27
  184.     bsr    _conout
  185.     push    #$44
  186.     bsr    _conout            ;cursor left
  187.     rts
  188. ;
  189. goright: tst.l    d4            ;# chars on right
  190.     beq.s    .grx
  191.     addq.l    #1,a2            ;bump pointer
  192.     subq.l    #1,d4            ;# chars on right
  193.     addq.l    #1,d5            ;# chars on left
  194.     bsr.s    toright
  195. .grx:    moveq.l    #-1,d1
  196.     rts
  197. ;
  198. goleft: tst.l    d5
  199.     beq.s    .glx
  200.     subq.l    #1,a2            ;pointer
  201.     addq.l    #1,d4            ;# chars on right
  202.     subq.l    #1,d5            ;#chars on left
  203.     bsr.s    toleft
  204. .glx:    moveq.l    #-1,d1
  205.     rts
  206. ;
  207.