home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11edi.mac < prev    next >
Text File  |  2020-01-01  |  16KB  |  723 lines

  1.     .title    k11edi    Command line editing
  2.     .ident    /3.52/
  3.  
  4. ;    18-Jul-86  12:00:29  Brian Nelson
  5. ;
  6. ;    This code is used (currently) for the RSTS/E Command Line
  7. ;    Editor (CLE.RTS) written by the above author, and for 5.1
  8. ;    of MINITAB. The encryption calls are for the RSTS/E CLE.
  9.  
  10.  
  11.  
  12.  
  13.  
  14.     .iif ndf, $MINITAB, $MINITAB = 0
  15.  
  16.     .if eq    ,$Minitab
  17.     .if ndf, K11INC
  18.     .ift
  19.     .include    /IN:K11MAC.MAC/
  20.     .endc
  21.     .endc
  22.  
  23.     .enabl    gbl
  24.  
  25.     .psect    rwdata    ,rw,d,lcl,rel,con
  26.     .psect    CLECTX    ,rw,d,gbl,rel,con
  27. curpos:    .word    edipos
  28. curlen:    .word    edilen
  29. curcmd:    .word    edicmd
  30. maxsiz:    .word    edisiz
  31. clests:    .word    edists
  32. enckey:    .word    $enckey
  33. deckey:    .word    $deckey
  34.  
  35.     .if ne    ,$Minitab
  36.     .ift
  37.  
  38.  
  39.     .macro    dump    v
  40.     mov    v    ,-(sp)
  41.     call    o$dump
  42.     .globl    o$dump
  43.     .endm    dump
  44.  
  45.     CR    =    15
  46.     LF    =    12
  47.  
  48.     LN$MAX    =    80.
  49.     LN$CNT    =    3
  50.  
  51.     ER$EOF    ==    -1
  52. $lastl:    .blkb    <<LN$MAX+2>*LN$CNT>+2
  53. lastli:    .word    $lastl    ,$lastl+<1*<LN$MAX+2>>,$lastl+<2*<LN$MAX+2>>,0
  54. lastcn:    .word    LN$CNT
  55. edipos:    .word    0
  56. edilen:    .word    0
  57. edicmd:    .word    -1
  58. edists:    .word    0
  59. edikey:    .word    0
  60. edisiz:    .word    LN$MAX
  61. $enckey:
  62. $deckey:
  63.  
  64.     TTY    =    0
  65.  
  66.     .endc                    ; If NE, $Minitab
  67.  
  68.     .psect    $pdata    ,ro,d,lcl,rel,con
  69.  
  70.     .psect    $code    ,i,ro,i,lcl,rel
  71.  
  72.  
  73.     FALSE    =    0
  74.     TRUE    =    1
  75.  
  76.     IN$MODE    =    1
  77.     SET$VT1    =    2
  78.  
  79.     $DEBUG    =    0
  80.     .iif ndf, $DEBUG, $DEBUG = 0
  81.  
  82.  
  83.  
  84.  
  85.     .sbttl    Define macros
  86.  
  87.     .if ne    ,$MINITAB
  88.     .ift
  89.  
  90.     .MACRO    ENCRYPT    txt,key
  91.     .ENDM    ENCRYPT
  92.  
  93.     .MACRO    DECRYPT    txt,key
  94.     .ENDM    DECRYPT
  95.  
  96.     .MACRO    DEBUG    a,b,c
  97.     .ENDM    DEBUG
  98.  
  99.  
  100.     .MACRO    STRCPY    dst,src
  101.     mov    src    ,-(sp)
  102.     mov    dst    ,-(sp)
  103.     jsr    pc    ,strcpy
  104.     .ENDM    STRCPY
  105.  
  106.     .MACRO    STRLEN    src
  107.     mov    src    ,-(sp)
  108.     call    strlen
  109.     .ENDM    STRLEN
  110.  
  111.     .MACRO    SCAN    ch,str
  112.     mov    str    ,-(sp)
  113.     clr    -(sp)
  114.     bisb    ch    ,@sp
  115.     call    scanch
  116.     .ENDM    SCAN
  117.  
  118.     .MACRO    SAVE    list
  119.     .if b , <list>
  120.     .ift
  121.      SAVE    <r0,r1,r2,r3,r4,r5>
  122.     .iff
  123.     .irp    x,<list>
  124.      mov    x,-(sp)
  125.         .endr
  126.     .endc
  127.     .ENDM    SAVE
  128.  
  129.  
  130.     .MACRO    UNSAVE    list
  131.     .if b , <list>
  132.     .ift
  133.     UNSAVE    <r5,r4,r3,r2,r1,r0>
  134.     .iff
  135.     .irp    x,<list>
  136.      mov    (sp)+,x
  137.         .endr
  138.     .endc
  139.     .ENDM    UNSAVE
  140.  
  141.     .MACRO    GLOBAL    LIST
  142.     .GLOBL    LIST
  143.     .ENDM    GLOBAL
  144.  
  145.  
  146.     .iff                ; Kermit or CLE
  147.  
  148.     .MACRO    ENCRYPT    txt,key
  149.     mov    key    ,-(sp)
  150.     mov    txt    ,-(sp)
  151.     call    ENCRYPT
  152.     .endm    ENCRYPT
  153.  
  154.     .MACRO    DECRYPT    txt,key
  155.     mov    key    ,-(sp)
  156.     mov    txt    ,-(sp)
  157.     call    DECRYPT
  158.     .endm    DECRYPT
  159.  
  160.  
  161.     .MACRO    DEBUG    txt,sts=1,docr=1
  162.     .if ne    ,$DEBUG
  163.     .if ne    ,sts
  164.     .save
  165.     .psect    $pdata
  166.     $$ = .
  167.     .if b    ,<txt>
  168.     .ift
  169.     .byte    15,12,0
  170.     .iff
  171.     .asciz    @txt@
  172.     .endc
  173.     .even
  174.     .restore
  175.     mov    #$$    ,-(sp)        ; dump the text next please
  176.     CALL    mout            ; to the terminal
  177.     .globl    mout            ; perhaps
  178.     .if nb    ,<txt>
  179.     .ift
  180.     .iif nb,docr, message
  181.     .endc
  182.     .endc
  183.     .endc
  184.     .endm    DEBUG
  185.  
  186.     .endc                ; if NE, $Minitab
  187.  
  188.     .macro    WRTALL    arg        ; IO.WAL for an .asciz string
  189.     mov    arg    ,-(sp)        ; Pass the address
  190.     call    wrtall            ; Do it
  191.     GLOBAL    <wrtall>        ; Insure globalized
  192.     .endm    WRTALL            ; Done
  193.  
  194.  
  195.     .enabl    lsb
  196.  
  197. Kbredi::.iif ne, $MINITAB, mov    r1,-(sp);
  198.     .iif ne, $MINITAB, mov    r5,-(sp);
  199.     SAVE    <r2,r3,r4>        ; Save
  200.     cmpb    vttype    ,#TTY        ; Not a VT100 or VT2xx?
  201.     bne    10$            ; No, try editing
  202.     .if ne    ,$MINITAB        ; Minitab today?
  203.     .ift                ; Yes
  204.     sec                ; Just set carry and exit
  205.     .iff                ; Kermit or CLE
  206.     WRTALL    @r5            ; Prompt
  207.     CALLS    kbread    ,<2(r5)>    ; Hardcopy, use vanilla reads
  208.     .endc                ; All done
  209.     br    100$            ; Exit
  210. 10$:    WRTALL    #$cr            ;
  211.     WRTALL    @r5            ;
  212.     bit    #SET$VT1,@clests    ; Insure terminal in VT100 mode
  213.     bne    15$            ; Already did it
  214.     WRTALL    #$setvt1        ; Not done, do so
  215.     bis    #SET$VT1,@clests    ; Flag as having been done
  216. 15$:    clr    @curpos            ; Assume at start of the line.
  217.     clr    @curlen            ; No length
  218.     mov    2(r5)    ,r4        ; Buffer address
  219.     clrb    @r4            ; Insure starting with .ASCIZ
  220. 20$:    CALL    read1ch            ; Read one character now
  221.     mov    r0    ,r3        ; Any data persent?
  222.     beq    90$            ; Yes, treat as a control Z
  223.     SCAN    r3    ,#scanlst    ; Look for a match
  224.     asl    r0            ; And dispatch
  225.     jsr    pc    ,@scandsp(r0)    ; Do it
  226.     bcs    20$            ; Not done
  227.     .iif ne, $MINITAB, mov    r1,r0    ;
  228.     br    100$            ; Done
  229.                     ;
  230. 90$:    mov    #ER$EOF    ,r0        ; Error, return END_OF_FILE
  231.     clr    r1            ; And no data
  232. 100$:    UNSAVE    <r4,r3,r2>        ; Exit
  233.     .iif ne, $MINITAB, mov     (sp)+,r5;
  234.     .iif ne, $MINITAB, mov     (sp)+,r1;
  235.     return
  236.  
  237.     .dsabl    lsb
  238.  
  239.  
  240.     .save
  241.     .psect    $pdata    
  242. scanlst:.byte    'H&37    ,'E&37    ,'B&37    ,'U&37    ,'Z&37    ,CR    ,LF
  243.     .byte    'I&37    ,177    ,33    ,233    ,'R&37    ,'X&37    ,'C&37
  244.     .byte    'A&37
  245.     .byte    0
  246.     .even
  247.  
  248. scandsp:.word    INSCH
  249.     .word    SOL    ,EOL    ,PREV    ,CTRLU    ,EOF    ,NOOP    ,DONE
  250.     .word    NOOP    ,DORUB    ,DOESC    ,DO220    ,RETYPE    ,CANTYP    ,CTRLC
  251.     .word    TOGGLE
  252. esclst:    .byte    'A&137    ,'B&137    ,'C&137    ,'D&137    ,0
  253.     .even
  254. escdsp:    .word    NOOP
  255.     .word    PREV    ,NEXT    ,RIGHT    ,LEFT
  256.  
  257. $cc:    .asciz    /^C/
  258. $cz:    .asciz    /^Z/
  259. $bs:    .byte    'H&37,0
  260. $cr:    .byte    15,0
  261. $right:    .asciz    <33>/[C/
  262. $left:    .asciz    <33>/[D/
  263. $save:    .asciz    <33>/7/
  264. $resto:    .asciz    <33>/8/
  265. $ceol:    .asciz    <33>/[K/
  266. $crlf:    .byte    CR,LF,0
  267. $rrub:    .byte    10,40,10,0
  268. $setvt:    .byte    33,'<
  269.     .even
  270.     .restore
  271.  
  272.  
  273.  
  274.  
  275. Doesc:    DEBUG    <Doesc>            ; ...
  276.     CALL    read1ch            ; Get next in esc seq
  277. Do220:    DEBUG    <Do220>            ; You know
  278.     CALL    read1ch            ; Ditto
  279.     mov    r0    ,r3        ; Get the data
  280.     beq    90$            ; Error Exit
  281.     SCAN    r3    ,#esclst    ; Process the character
  282.      asl    r0            ; Convert to word offset
  283.     jsr    pc    ,@escdsp(r0)    ; Do it
  284.     br    100$            ; Ok
  285. 90$:    sec                ; Failure on the READ
  286. 100$:    return                ; And Exit
  287.  
  288. Noop:    DEBUG    <Noop>            ; ...
  289.     sec                ; Ignore
  290.     return                ; And Exit
  291.  
  292. Insch:    DEBUG    <Insch>,FALSE        ; ...
  293.     sub    #200    ,sp        ; A temp buffer
  294.     mov    sp    ,r2        ; A pointer to it
  295.     tst    r3            ; Null?
  296.     beq    100$            ; Ignore
  297.     cmp    @curlen    ,@maxsiz    ; Too many chars?
  298.     blo    10$            ; No
  299.     CALL    done            ; Yes, exit
  300.     br    100$            ; Bye
  301. 10$:    inc    @curlen            ; Save this
  302.     mov    @curpos    ,r1        ; Get the offset into line
  303.     add    r4    ,r1        ; Where to stuff the data
  304.     tstb    @r1            ; Already at end of line?
  305.     beq    20$            ; Yes, we have the stop to stuff it
  306.     bit    #IN$MODE,@clests    ; Insert or overstrike?
  307.     bne    15$            ; Insert
  308.     movb    r3    ,(r1)+        ; Overstrike
  309.     br    30$            ; Exit
  310. 15$:    STRCPY    r2    ,r1        ; No, so save the data now
  311.     movb    r3    ,(r1)+        ; And insert the new character
  312.     STRCPY    r1    ,r2        ; And put the trailing data back in.
  313.     br    30$            ; Now for the echoing
  314. 20$:    movb    r3    ,(r1)+        ; Already at eol, insert
  315.     clrb    @r1            ; And insure .ASCIZ
  316.     dec    r1            ; ...
  317.     WRTALL    r1            ; Echo
  318.     br    90$            ; Exit
  319. 30$:    WRTALL    #$save            ; Save cursor pos
  320.     dec    r1            ; Back to to the new character
  321.     WRTALL    r1            ; Dump the data
  322.     WRTALL    #$restore        ; Put the cursor back now
  323.     WRTALL    #$right            ; Move over on the display
  324. 90$:    inc    @curpos            ; Move over one
  325. 100$:    add    #200    ,sp        ; Pop buffer
  326.     sec                ; Not done
  327.     return                ; Exit
  328.  
  329.  
  330.  
  331.     .sbttl    More line editing routines
  332.  
  333.  
  334. ;    SOL    Move to start of line (Control H)
  335.  
  336. Sol:    DEBUG    <Sol>            ; ...
  337.     tst    @curpos            ; Stop when at position 0
  338.     ble    100$            ; Done
  339.     WRTALL    #$bs            ; Move
  340.     dec    @curpos            ; Fix position
  341.     br    sol            ; Next please
  342. 100$:    clr    @curpos            ; Insure correct
  343.     sec                ; Not done
  344.     return                ; Exit
  345.  
  346.  
  347.  
  348. ;    EOL    Move to End of Line, Control E
  349.  
  350.  
  351. Eol:    DEBUG    <Eol>            ; ...
  352.     STRLEN    r4            ; Find string length
  353. 10$:    cmp    @curpos    ,r0        ; End yet?
  354.     bhis    100$            ; Yes
  355.     WRTALL    #$right            ; No
  356.     inc    @curpos            ; Fix this
  357.     br    10$            ; Next
  358. 100$:    sec                ; Not done
  359.     return                ; Exit
  360.  
  361. Gotoeol:STRLEN    r4            ; Find string length
  362. 10$:    cmp    @curpos    ,r0        ; End yet?
  363.     bhis    100$            ; Yes
  364.     inc    @curpos            ; Fix this
  365.     br    10$            ; Next
  366. 100$:    return                ; Exit
  367.  
  368. ;    EOF    Control Z on input
  369.  
  370.     .enabl    lsb            ; Temp
  371.  
  372. Ctrlc:    DEBUG    <Control C>        ; ...
  373.     WRTALL    #$cc            ; Echo a control C
  374.     br    100$            ; Common exit now
  375.  
  376. Eof:    DEBUG    <Eof>            ; ...
  377.     WRTALL    #$cz            ; Echo a control Z
  378.     .if ne    ,$MINITAB        ;
  379.     WRTALL    #$crlf            ;
  380.     .endc                ;
  381. 100$:    mov    #ER$EOF    ,r0        ; Control Z
  382.     clr    r1            ; And return byte count of zero
  383.     clc                ; All done
  384.     return                ; Exit
  385.  
  386.     .dsabl    lsb            ; Done
  387.     .enabl    lsb
  388.  
  389.  
  390.  
  391.     .sbttl    Carriage return (actually LF) processing
  392.  
  393. ;    Done.    CR on input, store new line and bubble previous ones back
  394.  
  395. Done:    mov    r5    ,-(sp)        ; A scratch register we need
  396.     DEBUG    <Done>            ; ...
  397.     WRTALL    #$crlf            ;
  398.     STRLEN    r4            ; Get byte count (we have CR or LF)
  399.     mov    r0    ,r1        ; Return it
  400.     beq    90$            ; Nothing there, don't copy it.
  401.     clr    r2            ; The index
  402.     mov    lastcnt    ,r3        ; Number of lines to do
  403. 10$:    mov    lastli(r2),r0        ; Look to find a free spot.
  404.     tstb    @r0            ; Empty?
  405.     beq    60$            ; Yes
  406.     add    #2    ,r2        ; No, keep looking
  407.     sob    r3    ,10$        ; ....
  408.                     ; No room for command line.
  409.     clr    r2            ; The index
  410.     mov    r4    ,-(sp)        ; Save it
  411.     mov    lastcnt    ,r3        ; Number of lines to do
  412.     dec    r3            ; ...
  413.     asl    r3            ; See if this is same as last
  414.     mov    lastli(r3),r5        ; Current address
  415.     inc    r5            ; Skip the length
  416.     mov    r5    ,-(sp)        ; Save
  417.     DECRYPT    r5,deckey        ; Undo the old line
  418.     STRLEN    r4            ; Length
  419.     cmpb    -1(r5)    ,r0        ; Same length
  420.     bne    20$            ; No
  421. 15$:    cmpb    (r4)+    ,(r5)+        ; Check for string equality
  422.     bne    20$            ; Not the same
  423.     sob    r0    ,15$        ; Same, check next
  424. 20$:    mov    (sp)+    ,r5        ; Restore old text pointer
  425.     mov    (sp)+    ,r4        ; Restore the current pointer
  426.     ENCRYPT    r5,enckey        ; Restore the data
  427.     asr    r3            ; Restore r3
  428.     tst    r0            ; Same ?
  429.     bne    30$            ; No
  430.     mov    r3    ,@curcmd    ; Yes, save index
  431.     br    100$            ; Exit
  432. 30$:
  433. 40$:    mov    lastli(r2),r0        ; Counted string format
  434.     mov    lastli+2(r2),r1        ; Again
  435.     movb    (r1)    ,(r0)+        ; Copy the string length
  436.     beq    55$            ; Can't happen, but may as well check
  437.     clr    r5            ; Counter for the copy operation
  438.     bisb    (r1)+    ,r5        ; Copy the byte count
  439. 50$:    movb    (r1)+    ,(r0)+        ; Copy the string now
  440.     sob    r5    ,50$        ; Next
  441. 55$:    add    #2    ,r2        ; Move up
  442.     sob    r3    ,40$        ; Next please
  443.                     ;
  444. 60$:    mov    lastli(r2),r1        ; Copy the line at last
  445.     STRLEN    r4            ; Get the line length
  446.     mov    @maxsiz    ,r3        ; For padding with spaces
  447.     movb    r0    ,(r1)+        ; Copy the length
  448.     beq    80$            ; Nothing
  449.     mov    r4    ,r5        ; Source string
  450.     mov    r1    ,-(sp)        ; Save text address
  451. 70$:    movb    (r5)+    ,(r1)+        ; Copy the data now
  452.     dec    r3            ; Keep track of remaining space
  453.     beq    75$            ; No room left
  454.     sob    r0    ,70$        ; Next please
  455. 74$:    movb    #40    ,(r1)+        ; Now space fill the line
  456.     sob    r3    ,74$        ; Next please
  457. 75$:    mov    (sp)+    ,r1        ; Restore text address
  458.     ENCRYPT    r1,enckey        ; Encode it
  459. 80$:    asr    r2            ; Set 'Current' Command index
  460.     mov    r2    ,@curcmd    ; And save it
  461.     br    100$            ; Exit
  462. 90$:    movb    #CR    ,@r4        ; Return only a carriage return
  463.     clrb    1(r4)            ; .ASCIZ
  464. 100$:    STRLEN    r4            ; Get line length
  465.     mov    r0    ,r1        ; Where to return it.
  466.     clr    r0            ; No errors
  467.     mov    (sp)+    ,r5        ; Restore r5
  468.     clc                ; All done
  469.     return                ; Exit
  470.  
  471.     .dsabl    lsb
  472.  
  473.  
  474.  
  475.  
  476. ;    PREV:    Recall previous command line, UP-Arrow Key.
  477.  
  478. Prev:    DEBUG    <Prev>            ; ...
  479.     mov    r5    ,-(sp)        ; Save it
  480. 10$:    mov    @curcmd    ,r2        ; Current command number
  481.     blt    100$            ; Never been here.
  482.     CALL    sol            ; Back up
  483.     WRTALL    #$cr            ; Start of line
  484.     WRTALL    #$ceol            ; Clear
  485.     WRTALL    @r5            ; Prompt
  486.     asl    r2            ; We want addresses today
  487.     mov    lastli(r2),r2        ; At last
  488.     tstb    @r2            ; Anything to copy?
  489.     bne    20$            ; Yes
  490.     dec    @curcmd            ; No, back up again
  491.     bge    10$            ; Ok
  492.     clr    @curcmd            ; Reached the end
  493.     br    100$            ; And exit
  494. 20$:    clrb    @r4            ; TO be safe
  495.     clr    r3            ; Get length next
  496.     bisb    (r2)+    ,r3        ; Do it
  497.     beq    50$            ; Nothing?
  498.     mov    @maxsiz    ,r0        ; Copy all for DES types
  499.     mov    r4    ,r5        ; A copy of the destination
  500. 30$:    movb    (r2)+    ,(r5)+        ; Copy it
  501.     sob    r0    ,30$        ; Next please
  502.     DECRYPT    r4,deckey        ; Decode the data
  503.     add    r4    ,r3        ; Point to the real end of data
  504.     clrb    @r3            ; Insure .asciz
  505.     WRTALL    r4            ; Echo it
  506. 50$:    CALL    gotoeol            ; Move to end of the line
  507.     STRLEN    r4            ; Get length
  508.     mov    r0    ,@curlen    ; And save it
  509.     tst    @curcmd            ; Check for underflow
  510.     ble    100$            ; Yes, exit
  511.     dec    @curcmd            ; No, backup now.
  512.     br    100$            ; Exit
  513. 90$:    clrb    @r4            ; Nothing, kill the buffer
  514. 100$:    sec                ; Not done yet
  515.     mov    (sp)+    ,r5        ; Restore this
  516.     return                ; Exit
  517.  
  518.  
  519. ;    Control U:    Erase entire line
  520.  
  521. Ctrlu:    DEBUG    <Ctrlu>            ; ...
  522.     CALL    sol            ; Move to start of the line
  523.     WRTALL    #$ceol            ; Erase to the end of the line
  524.     clrb    @r4            ; No data left over
  525.     clr    @curlen            ; No length
  526.     sec                ; Not done
  527.     return                ; Exit
  528.  
  529. Right:    DEBUG    <Right>            ; ...
  530.     STRLEN    r4            ; Get current length of the line
  531.     cmp    @curpos    ,r0        ; Already at EOL?
  532.     bhis    100$            ; Yes
  533.     inc    @curpos            ; No, move over
  534.     WRTALL    #$right            ; Simple to do.
  535. 100$:    sec                ; Not done
  536.     return                ; Exit
  537.  
  538.  
  539.  
  540.     .sbttl    Rubouts and move left
  541.  
  542. ;    DORUB:    Erase character
  543.  
  544. Dorub:    DEBUG    <Dorub>,FALSE        ; ...
  545.     sub    #200    ,sp        ; Allocate a buffer again
  546.     mov    sp    ,r3        ; And a pointer to such.
  547.     tstb    @r4            ; Is there ANYTHING in the line?
  548.     beq    100$            ; No, it's a NO-OP
  549.     tst    @curpos            ; Already at SOL (start of line)?
  550.     bgt    10$            ; No
  551.     clr    @curpos            ; Insure correct position
  552.     clr    @curlen            ; Save this
  553.     br    20$            ; Off to common code
  554. 10$:    mov    r4    ,r2        ; See if at eoln
  555.     add    @curpos    ,r2        ; Compute address
  556.     dec    @curpos            ; Correct offset now
  557.     dec    @curlen            ; Fix this up
  558.     movb    @r2    ,-(sp)        ; Get current
  559.     beq    20$            ; Nothing to do
  560.     WRTALL    #$LEFT            ; Go back one please
  561. 20$:    mov    r4    ,r2        ; And move down
  562.     add    @curpos    ,r2        ; Point to CURRENT character
  563.     mov    r2    ,r1        ; Again
  564.     inc    r1            ; Next position please
  565.     STRCPY    r3    ,r1        ; Make a temporary copy of the data
  566.     STRCPY    r2    ,r3        ; Move it down
  567.     tstb    (sp)+            ; Were we already at EOL?
  568.     bne    30$            ; No
  569.     WRTALL    #$rrub            ; Use simple style BS SP BS if EOL
  570.     br    100$            ; Exit
  571. 30$:    WRTALL    #$save            ; Save cursor position
  572.     WRTALL    #$ceol            ; Erase to EOL
  573.     WRTALL    r2            ; Dump buffer
  574.     WRTALL    #$restore        ; And go back
  575. 100$:    add    #200    ,sp        ; Pop local buffer and Exit
  576.     sec                ; Not done
  577.     return                ; Exit
  578.  
  579.  
  580. ;    Left:    Move left one character
  581.  
  582. Left:    DEBUG    <Left>            ; ...
  583.     tst    @curpos            ; Can we back up ?
  584.     ble    100$            ; No
  585.     dec    @curpos            ; Yes, backup a bit
  586.     WRTALL    #$left            ; And do so.
  587. 100$:    sec                ; Not done
  588.     return                ; Exit
  589.  
  590.  
  591.     .sbttl    Command recall and control R processing
  592.  
  593. Next:    DEBUG    <Next>            ; ...
  594.     mov    r5    ,-(sp)        ; Save
  595.     mov    curcmd    ,r2        ; Point to CURCMD
  596.     tst    @r2            ; Current command number
  597.     blt    100$            ; Never been here.
  598.     mov    lastcnt    ,-(sp)        ; Get the recall buffer count
  599.     dec    (sp)            ; ...
  600.     cmp    @r2    ,(sp)+        ; Can we move up?
  601.     bge    100$            ; No
  602.     inc    @r2            ; Yes, move up.
  603.     CALL    sol            ; Back up
  604.     WRTALL    #$cr            ; Start of line
  605.     WRTALL    #$ceol            ; Clear
  606.     WRTALL    @r5            ; Prompt
  607.     mov    @r2    ,r2        ; Copy it.
  608.     asl    r2            ; We want addresses today
  609.     mov    lastli(r2),r2        ; At last
  610.     tstb    @r2            ; Anything to copy?
  611.     beq    90$            ; No
  612.                     ;
  613.     clrb    @r4            ; TO be safe
  614.     clr    r3            ; Get length next
  615.     bisb    (r2)+    ,r3        ; Do it
  616.     mov    @maxsiz    ,r0        ; Copy ALL for DES type routines
  617.     mov    r4    ,r5        ; A copy of the destination
  618. 30$:    movb    (r2)+    ,(r5)+        ; Copy it
  619.     sob    r0    ,30$        ; Next please
  620.     DECRYPT    r4,deckey        ; Decode the data
  621.     add    r4    ,r3        ; Point to the real end of data
  622.     clrb    @r3            ; And force to .ASCIZ
  623.     WRTALL    r4            ; Dump the data
  624.     call    gotoeol            ; Fix internal pointers
  625.     STRLEN    r4            ; Get last line length
  626.     mov    r0    ,@curlen    ; And save it
  627.     mov    lastcnt    ,-(sp)        ; Get the recall buffer count
  628.     dec    (sp)            ; ...
  629.     cmp    @curcmd    ,(sp)+        ; Poised at the last command?
  630.     bne    100$            ; No
  631.     dec    @curcmd            ; Fix so PREV works correctly.
  632.     br    100$            ; Exit
  633. 90$:    clrb    @r4            ; Nothing, kill the buffer
  634. 100$:    sec                ; Not done yet
  635.     mov    (sp)+    ,r5        ; Restore
  636.     return                ; Exit
  637.  
  638.  
  639.  
  640. Retype:    DEBUG    <Retype>        ; ...
  641.     WRTALL    #$cr            ; Start of line
  642.     WRTALL    #$ceol            ; Clear
  643.     WRTALL    @r5            ; Prompt
  644.     WRTALL    r4            ; Dump the buffer
  645.     WRTALL    #$cr            ; Back up again
  646.     STRLEN    @r5            ; Get a new poistion now
  647.     add    @curpos    ,r0        ; Get to correct position
  648.     beq    100$            ; Nothing (?)
  649. 10$:    WRTALL    #$right            ; Move over
  650.     sob    r0    ,10$        ; Simple
  651. 100$:    sec                ; Not yet done
  652.     return                ; Exit
  653.  
  654. Cantyp:    call    clrcns            ; Eat up console data
  655.     sec                ; Not done
  656.     return                ; Exit
  657.  
  658. Toggle:    mov    #IN$MODE,r0        ; Toggle modes
  659.     xor    r0    ,@clests    ; Do it
  660.     sec                ; Not done
  661.     return                ; Exit
  662.  
  663.  
  664.  
  665.     .sbttl    Utilities
  666.  
  667.     .if ne    ,$MINITAB
  668.     .ift
  669.  
  670. Strlen:    mov    2(sp)    ,r0        ; Get string length
  671. 10$:    tstb    (r0)+            ; Look for end
  672.     bne    10$            ; Not yet
  673.     sub    2(sp)    ,r0        ; Compute length
  674.     dec    r0            ; Fix
  675.     mov    (sp)+    ,(sp)        ; Pop stack
  676.     return                ; Exit
  677.  
  678. ;    Strcpy
  679. ;
  680. ;    input:
  681. ;        0(sp)    return address
  682. ;        2(sp)    dst address
  683. ;        4(sp)    src address
  684. ;    output:    r0    dest address
  685.  
  686.  
  687. Strcpy:    save    <r1>            ; save temp registers please
  688.     mov    2+2(sp)    ,r0        ; destination address
  689.     mov    2+4(sp)    ,r1        ; source .asciz address
  690. 10$:    movb    (r1)+    ,(r0)+        ; copy until a null
  691.     bne    10$            ; not done
  692.     mov    2+2(sp)    ,r0        ; return the dst address
  693.     unsave    <r1>            ; pop r1 and exit
  694.     mov    (sp)    ,4(sp)        ; move return address up now
  695.     cmp    (sp)+    ,(sp)+        ; pop junk and exit
  696.     return
  697.  
  698. ;    S C A N C H 
  699. ;
  700. ;    input:    4(sp)    the string address
  701. ;        2(sp)    the character to look for
  702. ;    output:    r0    position of ch in string
  703.  
  704.  
  705. Scanch:    save    <r2>            ; save temps
  706.     mov    6(sp)    ,r2        ; get address of the string
  707.     clr    r0            ; initial found position
  708. 10$:    tstb    @r2            ; end of the string yet ?
  709.     beq    90$            ; yes
  710.     inc    r0            ; no, pos := succ(pos)
  711.     cmpb    4(sp)    ,(r2)+        ; does the ch match the next one?
  712.     bne    10$            ; no, try again
  713.     br    100$            ; yes, exit loop
  714. 90$:    clr    r0            ; failure, return postion = 0
  715. 100$:    unsave    <r2>            ; pop r2
  716.     mov    @sp    ,4(sp)        ; move return address up
  717.     cmp    (sp)+    ,(sp)+        ; pop stack
  718.     return                ; and exit
  719.  
  720.     .endc                ; If NE, $Minitab
  721.  
  722.     .end
  723.