home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / modem / qt-genie.z < prev    next >
Encoding:
Text File  |  1993-06-08  |  4.1 KB  |  147 lines

  1. ; QT-GENIE.Z keyboard map function and user function to enable
  2. ; line splitting
  3.  
  4. .var    linesz    30        ; default number of chars before we start
  5.                 ; looking for a space
  6.  
  7. .var    free    0x0400        ; where in the patch we can place things
  8.  
  9. .org    0x0276            ; patch into the user function
  10.     jp    user        ; go do ours
  11.  
  12. .org    0x0279
  13.     jp    kbmap        ; hook into keyboard map routine
  14.  
  15. .var    ilprmt    0x027c        ; in line prompt call
  16.  
  17. .org    free
  18. user:
  19.     call    ilprmt        ; prompt for and get an answer
  20.     db    'Auto line splitting enable (Y/n)? \0'
  21.     ld    hl,0x7f        ; point just before it
  22. byp:    inc    hl
  23.     ld    a,(hl)        ; get the next character
  24.     cp    ' '        ; space?
  25.     jr    z,byp        ; yes, skip over it
  26.     sub    '0'
  27.     cp    10
  28.     jr    c,number    ; numeric input - go handle it
  29.     add    a,'0'        ; convert back
  30.     or    0x20        ; force lower case
  31.     xor    0x20        ; this really tests for a null .....
  32.     jr    z,gotans    ; yes, save zero byte
  33.     xor    0x20 ^ 'y'    ; and check for a 'y' (including 'Y')
  34. gotans:    ld    (split),a    ; save the flag - zero enables, non-zero
  35.                 ; disables
  36.     ld    a,linesz    ; set line length to default of 30
  37. setll:    ld    (linlen),a    ; set the line length from a
  38.     xor    a
  39.     ld    (count),a    ; and set the count to zero
  40.     ret
  41.  
  42. number:    ld    e,a        ; save current value in e
  43.     inc    hl        ; point to next character
  44.     ld    a,(hl)
  45.     sub    '0'        ; convert .....
  46.     cp    10        ; and test if it's a digit
  47.     jr    nc,gotnum    ; nope - we're all done
  48.     ld    d,a
  49.     ld    a,e
  50.     add    a,a        ; a = e * 2
  51.     add    a,a        ;       * 4
  52.     add    a,e        ;       * 5
  53.     add    a,a        ;       * 10
  54.     add    a,d        ;       + d
  55.     jr    number
  56. gotnum:    ld    a,e        ; get value back from e
  57.     or    a        ; if it's zero .....
  58.     ld    a,1        ; set a != 0 to disable
  59.     jr    z,gotans    ; and go do it
  60.     xor    a
  61.     ld    (split),a    ; else set split flag to enable
  62.     ld    a,e        ; and get the line length back from e
  63.     jr    setll        ; go do the set with whatever we have
  64.  
  65. kbmap:
  66.     and    0x7f        ; ditch bit 7, just because I'm paranoid
  67.     cp    0x7f        ; is the key a delete?
  68.     jr    nz,nodel    ; nope, leave it alone
  69.     ld    a,'\b'        ; else change it into a backspace
  70. nodel:    ld    hl,split    ; point at the flag
  71.     inc    (hl)
  72.     dec    (hl)
  73.     ret    nz        ; not splitting - get outa here
  74.     ld    c,a        ; save char in c
  75.     ld    hl,(state)
  76.     ld    a,h
  77.     or    l        ; are we in the middle of a line break?
  78.     jr    nz,linbrk    ; yes, so handle it elsewhere
  79.     ld    a,c        ; get the character back from c
  80.     ld    hl,0x01cf    ; point at the escape character
  81.     cp    (hl)
  82.     ret    z        ; we have to let these through!
  83.     ld    hl,count    ; point hl at the count for everyone
  84.     cp    '\b'
  85.     jr    z,backsp    ; handle backspaces
  86.     cp    '\r'
  87.     jr    z,return    ; and returns
  88.     cp    '\n'
  89.     jr    z,newlin    ; and linefeeds
  90.     inc    b        ; set b to 1 for a potential swallow
  91.     cp    0x7f        ; throw away deletes
  92.     ret    z
  93.     cp    ' '        ; is it a space?
  94.     jr    z,space        ; handle specially if so
  95.     ret    c        ; and throw away other control characters
  96.     dec    b        ; reset b to pass the single character
  97.     inc    (hl)        ; bump count
  98.     ret            ; and return - char is still in a
  99.  
  100. backsp:
  101.     dec    (hl)        ; anything in the current count
  102.     ret    p        ; yes, return, char in a, b is OK
  103.     inc    (hl)        ; nothing on line, restore count
  104.     inc    b        ; set b to 1 for a swallow
  105.     ret            ; all done
  106.  
  107. return:
  108.     ld    hl,retstr    ; point at the return string
  109.     jr    linbrk
  110.  
  111. newlin:
  112.     ld    hl,nlstr    ; point at the new line string
  113.     jr    linbrk
  114.  
  115. space:
  116.     inc    (hl)        ; we passed another character, count it
  117.     ld    a,(linlen)    ; get the line length
  118.     cp    (hl)        ; too long yet?
  119.     ld    a,c
  120.     dec    b
  121.     ret    nc        ; no, return character in a
  122.     ld    hl,string    ; else point at the string to send
  123.  
  124. linbrk:
  125.     ld    a,(hl)        ; get the next character from the string
  126.     inc    hl        ; move the pointer
  127.     inc    (hl)
  128.     dec    (hl)        ; end of string?
  129.     ld    b,2        ; set b to 2 to say there's more coming
  130.     jr    nz,savehl    ; not end of string, save hl and return
  131.     ld    b,(hl)        ; set b to zero again
  132.     ld    hl,count
  133.     ld    (hl),b        ; zero out the count from b
  134.     ld    h,b
  135.     ld    l,b        ; set hl to zero to reset the state machine
  136. savehl:    ld    (state),hl    ; save the pointer / NULL
  137.     ret
  138.  
  139. count:    db    0        ; count of chars since the last new line
  140. linlen:    db    linesz        ; line size we're currently using
  141. split:    db    1        ; flag if we're splitting: zero => we are
  142. state:    dw    0        ; what state are we in?
  143.  
  144. string:    db    ' .....\r\0'    ; space string to break lines
  145. retstr:    db    ' /end\r\0'    ; return string to end a paragraph
  146. nlstr:    db    '\r\0'        ; newline to end
  147.