home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / A / BIOS-R6.LBR / CXKEY.AYM / CXKEY.AYM
Text File  |  1992-10-12  |  17KB  |  1,063 lines

  1. ; All functions relating to 40 col operation has been removed. 
  2. ;
  3. ; A Screendump function has been added, it selects the printer
  4. ; based on the values of LOVEC, first it tests for ?pt$o$1,
  5. ; if that printer is selected (via the device command or predefined 
  6. ; during system initialization in CXIO.ASM) the screen dump will 
  7. ; be directed there,  if ?pt$o$1 is not selected then it testes for
  8. ; ?pt$o$2 and directs the screen dump there if that printer is selected
  9. ; If niether printer is selected the routine mereley returnes without
  10. ; doing anything.
  11. ;
  12. ; User assumes _ALL_ liability for use of this module. Original
  13. ; copyright is maintained by Commodore.
  14. ;
  15. ; screen$dump routine copyright April 26 1987 by James W. Waltrip IV
  16. ;
  17. ;-------------------------------------------------------------------------
  18. ; * ADDITIONS by Randy Winchester, 5/3/89
  19. ;
  20. ; Added drive D: to MFM unlock routine.
  21. ;
  22. ;-------------------------------------------------------------------------
  23. ;
  24.     title    'C128 keyboard handler         3 May   89'
  25.  
  26.     maclib    cxequ
  27.  
  28.     maclib    z80
  29.  
  30.     public    ?get$key,?int$cia,?kyscn
  31.     public    Fx$V$tbl
  32.  
  33.     extrn    ?stat,?save,?recov
  34.  
  35.     extrn    ?di$int
  36.  
  37.     extrn    cmdsk0,cmdsk1,cmdsk2,cmdsk3
  38.  
  39.     extrn    @pageM
  40.  
  41.     extrn    ?pt$o$2
  42.     extrn    ?pt$o$1,@lovec
  43.  
  44.     page
  45.  
  46.     DSEG
  47. ;
  48. ;
  49. ;
  50. ?int$cia:
  51.     lxi    b,key$row        ; point to CIA 1st register
  52.     mvi    a,0ffh
  53.     outp    a
  54.     inr    c
  55.     inr    c
  56.     outp    a
  57.     inr    c
  58.     xra    a
  59.     sta    commodore$mode        ; clear commodore shift mode
  60.     outp    a
  61.  
  62.  
  63.     lxi    h,key$scan$tbl        ; init key scan tbl pointer
  64.     mov    m,l            ; ..to the begining
  65. ;
  66. ;    initialize keyboard buffer and pointers
  67. ;
  68.     lxi    h,key$buffer
  69.     shld    key$get$ptr
  70.     shld    key$put$ptr
  71.     mvi    m,0ffh
  72.     lxi    d,key$buffer+1
  73.     lxi    b,key$buf$size-1
  74.     ldir
  75.     ret
  76.  
  77.     page
  78. ;==========================================================
  79. ;        KEYBOARD SCANNING FUNCTION
  80. ;==========================================================
  81. ;
  82. ;
  83. ;
  84. ;
  85. ?get$key:
  86.     lhld    msgptr
  87.     mov    a,h
  88.     ora    l
  89.     jrnz    mess$cont
  90.  
  91. ;
  92. ;
  93. ;
  94. re$scan:
  95.     call    scan$keys
  96.     push    psw
  97.  
  98.     mov    a,c
  99.     ani    special
  100.     cpi    special        ; control and rt. shift key
  101.     jrnz    not$special
  102.  
  103.     mov    a,b        ; get the matrix position
  104.     cpi    rt$arrow
  105.     jz    prog$fun
  106.  
  107.     cpi    lf$arrow
  108.     jz    prog$key
  109.  
  110.     cpi    alt$key
  111.     jz    toggle$plain$keys
  112.  
  113. ;
  114. ;
  115. ;
  116. not$special:
  117.     pop     psw
  118.     mov    d,a
  119.     lda    stat$enable
  120.     ani    80h        ; mask off plain keys bit
  121.     mov    a,d        ; recover input character
  122.     rnz            ; return if plain keys bit is set
  123.  
  124.     page
  125. ;
  126. ;
  127. ;
  128. test$function:
  129.     cpi    080h        ; check for MSB set 
  130.     rc            ; return if not
  131.  
  132.     cpi    0A0h        ; 80-9F are function keys
  133.     jrnc    not$8x
  134.  
  135. ;
  136. ;
  137. find$mess:
  138.     ani    1fh        ; 32 messages
  139.     mov    b,a        ; place Function # in B for search
  140.     call    get$fun$adr
  141.  
  142. ;
  143. ;
  144. mess$cont:
  145.     mov    b,m        ; get char to B
  146.     inx    h
  147.     mov    a,m
  148.     ora    a
  149.     jrnz    more$mess
  150.  
  151.     lxi    h,0
  152.  
  153. more$mess:
  154.     shld    msg$ptr
  155.     mov    a,b
  156.     mvi    c,0        ; no control keys
  157.     mvi    b,0f0h        ; tell user this is a function key
  158.     ora    a        ; check character (maybe 1st is 0)
  159.     jrz    re$scan        ; scan keys (no valid function key)
  160.  
  161.     jrnz    test$function    ; test for local function
  162.  
  163.     page
  164. ;
  165. ;
  166. ;
  167. get$fun$adr:
  168.     lhld    fun$tbl            ; get adr of msg table
  169.     dcx    h
  170. ; lxi    h,msgtbl-1            ; point to start of funtions (less one)
  171.     inr    b            ; adjust function # (to test for 0)
  172.     xra    a            ; get a zero in A
  173. check$fun$num:
  174.     inx    h            ; advance pointer to point at text
  175.     shld    msg$ptr            ; save message adr for caller
  176.     dcr    b            ; requested function ?
  177.     rz                ; yes, exit with HL=string adr 
  178.  
  179. find$end$marker:
  180.     cmp    m            ; end of text marker ? (0=EOTM)
  181.     jrz    check$fun$num        ; yes, go see if required fun # 
  182.  
  183.     inx    h            ; advance to next char
  184.     jr    find$end$marker        ; go find EOTM
  185.  
  186.     page
  187. ;
  188. ;    A0-AF    Set char color (80 col)
  189. ;    B0-B1    Set background color (80 col)
  190. ;
  191. not$8x:
  192.     cpi    0C0h        ; 
  193.     jrnc    not$80col$color
  194.  
  195.     sui    0A0h-20h        ; remove key bias
  196.     mov    b,a
  197.     RCALL    FR$color
  198.     jr    ?get$key
  199.  
  200. ;
  201. ;    C0-CF    Set char color (40 col)
  202. ;    D0-DF    Set background color (40 col)
  203. ;    E0-EF    Set border color (40 col)
  204. ;
  205. not$80col$color:
  206.     cpi    0F0h
  207.     jrnc    must$be$Fx
  208. ;
  209. ;
  210. ;
  211.     sui    0C0h-20h        ; remove key bias
  212.     mov    b,a
  213.     RCALL    FR$color+FR$40
  214.     jr    ?get$key
  215.  
  216.     page
  217. ;
  218. ;    F0-FF    special code functions
  219. ;                           
  220. must$be$Fx:
  221.     lxi    h,?get$key
  222.     push    h            ; save as the return adr
  223.     ani    0fh
  224.     add    a            ; double
  225.     lhld    key$FX$function
  226.     mov    e,a
  227.     mvi    d,0
  228.     dad    d            ; HL points to the function
  229.     mov    e,m
  230.     inx    h
  231.     mov    d,m
  232.     xchg
  233.     pchl
  234.  
  235. ;
  236. ;
  237. ;
  238. FX$V$tbl:
  239.     dw    screen$dump        ; F0
  240.     dw    display$pause        ; F1
  241.     dw    empty                ; F2
  242.     dw    empty             ; F3
  243.     dw    empty            ; F4
  244.     dw    reset$mfm        ; F5
  245.     dw    empty            ; F6
  246.     dw    empty            ; F7
  247.     dw    empty            ; F8
  248.     dw    empty            ; F9
  249.     dw    empty            ; FA
  250.     dw    empty            ; FB
  251.     dw    empty            ; FC
  252.     dw    empty            ; FD
  253.     dw    empty            ; FE
  254.  
  255.     dw    0            ; FF    go restart the C128 BASIC
  256.                     ;    mode (or C64)
  257.  
  258.  
  259.  
  260.     page
  261. ;
  262. ;    Function F0
  263. ;
  264. ; screen dump for the 80 col chip
  265. ;
  266. ;screen$dump:
  267. ;    lxi    h,2000
  268. ;    mvi    a,80
  269. ;    sta    width
  270. ;;
  271. ;    lxi    b,0D600h    ; 80 col cmd register
  272. ;    mvi    a,18
  273. ;    outp    a
  274. ;lx1:                
  275. ;    inp    a        ; get status
  276. ;    jp    lx1        ; loop until status good
  277. ;    inx    b        ; increment to data reg
  278. ;    mvi    a,0
  279. ;    outp    a
  280. ;;
  281. ;    dcx    b        ; decrement to command reg
  282. ;    mvi    a,019
  283. ;    outp    a
  284. ;lx2:
  285. ;    inp    a
  286. ;    jp    lx2        ; loop til status good
  287. ;    inx    b        ; increment to data reg
  288. ;    mvi    a,0
  289. ;    outp    a
  290. ;    dcx    b        ; decrement to command reg
  291. ;rpt:
  292. ;    inp    a        ; get status
  293. ;    jp    rpt        ; loop until good
  294. ;    mvi    a,31
  295. ;    outp    a
  296. ;lx3:
  297. ;    inp    a
  298. ;    jp    lx3
  299. ;    inx    b        ; increment to data reg
  300. ;    inp    a
  301. ;    dcx    b
  302. ;    call    convert
  303. ;;
  304. ;    push    b
  305. ;    push    h
  306. ;    mov    c,a
  307. ;    call    ?pt$o$2
  308. ;;
  309. ;;    call    ?pt$o$1
  310. ;;
  311. ;    pop    h
  312. ;    pop    b
  313. ;;
  314. ;    lda    width
  315. ;    dcr    a
  316. ;    sta    width
  317. ;    cz    cr$lf
  318. ;    dcx    h        ; counter for screen (2000 locations)
  319. ;    mov    a,l
  320. ;    cpi    0
  321. ;    jnz    over
  322. ;    mov    a,h
  323. ;    cpi    0
  324. ;    jz    cr$lf        ; return when HL = 0000
  325. ;over:
  326. ;    jmp    rpt
  327. ;cr$lf:
  328. ;    push    b
  329. ;    push    h
  330. ;    mvi    c,13
  331. ;;    call     ?pt$o$2
  332. ;;
  333. ;;    call    ?pt$o$1
  334. ;;
  335. ;    mvi    c,10
  336. ;    call     ?pt$o$2
  337. ;;
  338. ;;    call    ?pt$o$1
  339. ;;
  340. ;    mvi    a,80
  341. ;    sta    width
  342. ;    pop    h
  343. ;    pop    b
  344. ;    ret
  345. ;convert:
  346. ;    cpi    32
  347. ;    jc    set$space
  348. ;    cpi    128
  349. ;    jnc    set$space
  350. ;    ret
  351. ;set$space:
  352. ;    mvi    a,32
  353. ;    ret
  354. ;;
  355. ;width:    ds    1
  356. ;;
  357. ;
  358. ;
  359. ;    Function F0
  360. ;
  361. ; screen dump for the 80 col chip
  362.  
  363. screen$dump:
  364.     lda    @lovec + 1
  365.     bit    4,a
  366.     jnz    next
  367.     bit    3,a
  368.     rz
  369.     jr    ova
  370.  
  371. next:
  372.     lxi    h,?pt$o$1
  373.     shld    prt$ad
  374. ;
  375. ;
  376. ;
  377. ova:
  378.     lxi    h,2000
  379.     mvi    a,80
  380.     sta    width
  381. ;
  382.     lxi    b,0D600h    ; 80 col cmd register
  383.     mvi    a,18
  384.     outp    a
  385. lx1:                
  386.     inp    a        ; get status
  387.     jp    lx1        ; loop until status good
  388.     inx    b        ; increment to data reg
  389.     mvi    a,0
  390.     outp    a
  391. ;
  392.     dcx    b        ; decrement to command reg
  393.     mvi    a,019
  394.     outp    a
  395. lx2:
  396.     inp    a
  397.     jp    lx2        ; loop til status good
  398.     inx    b        ; increment to data reg
  399.     mvi    a,0
  400.     outp    a
  401.     dcx    b        ; decrement to command reg
  402. rpt:
  403.     inp    a        ; get status
  404.     jp    rpt        ; loop until good
  405.     mvi    a,31
  406.     outp    a
  407. lx3:
  408.     inp    a
  409.     jp    lx3
  410.     inx    b        ; increment to data reg
  411.     inp    a
  412.     dcx    b
  413.     call    convert
  414.     lda    width
  415.     dcr    a
  416.     sta    width
  417.     cz    cr$lf
  418.     dcx    h        ; counter for screen (2000 locations)
  419.     mov    a,l
  420.     cpi    0
  421.     jnz    rpt
  422.     mov    a,h
  423.     cpi    0
  424.     jnz    rpt
  425. cr$lf:
  426.     mvi    a,13
  427.     call     printer
  428.     mvi    a,10
  429.     call     printer
  430.     mvi    a,80
  431.     sta    width
  432.     ret
  433. convert:
  434.     cpi    32
  435.     jc    set$space
  436.     cpi    128
  437.     jc    printer
  438. set$space:
  439.     mvi    a,32
  440. ;
  441. printer:
  442.     push    h
  443.     push    b
  444.     mov    c,a
  445. ;
  446. prt$ad    equ    $+1
  447.     call    ?pt$o$2
  448.     pop    b
  449.     pop    h
  450.     ret
  451. ;
  452. width:    ds    1
  453. ;
  454. ;
  455. ;
  456. ;
  457. ;
  458. ;
  459. ;    Function F1
  460. ;
  461. display$pause:
  462.     mvi    a,-1
  463.     sta    cur$pos            ; move cursor out of window
  464.  
  465.     lxi    b,buff$small*256+buff$pos    ; B=size C=pos
  466.     call    ?save
  467.     mvi    a,buff$pos+1
  468.     sta    offset
  469.     mvi    b,5
  470.     lxi    h,pause$MSG
  471.  
  472. pause$disp$loop:
  473.     mov    a,m
  474.     push    h
  475.     push    b
  476.     call    disp$status
  477.     pop    b
  478.     pop    h
  479.     inx    h
  480.     djnz    pause$disp$loop
  481.  
  482. pause$loop:
  483.     call    scan$keys
  484.     jrz    pause$loop
  485.  
  486.     cpi    0F1h            ; pause key function code
  487.     jrnz    pause$loop
  488.  
  489.     jr    recov$small
  490.  
  491.  
  492. pause$MSG:
  493.     db    'Pause'
  494.  
  495. empty:
  496.     ret
  497.  
  498.     page
  499. ;
  500. ;    Function F2
  501. ;
  502. ; empty
  503. ;
  504. ;    Function F3
  505. ;
  506. ;empty
  507. ;
  508. ;    Function F4
  509. ;
  510. ; empty
  511. ;
  512. ;    Function F5
  513. ;
  514. ;    Unlock MFM selection for ALL drives in the system
  515. ;
  516. reset$mfm:
  517.     lda    cmdsk0+42        ; 42 is the offset from drive pointer
  518.     ani    7fh            ; MSB cleared to unlock the drive
  519.     sta    cmdsk0+42        ; unlock drive A
  520.     lda    cmdsk1+42
  521.     ani    7fh
  522.     sta    cmdsk1+42        ; unlock drive B
  523.     lda    cmdsk2+42
  524.     ani    7fh
  525.     sta    cmdsk2+42        ; unlock drive C
  526.     lda    cmdsk3+42
  527.     ani    7fh
  528.     sta    cmdsk3+42        ; unlock drive D
  529.     ret
  530.  
  531.  
  532.  
  533.     page
  534. ;
  535. ;    A zero in the MSB of the STAT$ENABLE byte will allow
  536. ;    special keyboard function. (codes above 80h)
  537. ;    A one will force the key value to be returned without
  538. ;    any special functions being executed.
  539. ;
  540. toggle$plain$keys:
  541.     pop    psw            ; remove garbage
  542.  
  543.     lda    stat$enable
  544.     xri    80h
  545.     sta    stat$enable
  546.     jmp    re$scan
  547.  
  548.     page
  549. ;
  550. ;
  551. ;
  552. prog$key:
  553.     pop    psw            ; remove garbage
  554.  
  555.     lxi    b,buff$small*256+buff$pos    ; B=size, C=position
  556.     call    ?save
  557.  
  558.     mvi    a,buff$pos+1
  559.     sta    offset
  560.     call    read$key        ; get key to re-program
  561.     push    h            ; save key's address
  562.     mov    a,m
  563.     call    disp$hex$byte
  564.     mvi    a,buff$pos+4
  565.     sta    offset
  566.     call    get$byte
  567.     pop    h
  568.     jrc    restore$buf$small
  569.     mov    m,a
  570. ;
  571. ;
  572. restore$buf$small:
  573.     call    delay
  574. recov$small:
  575.     lxi    b,buff$small*256+buff$pos    ; B=size, C=position
  576.     jmp    ?recov
  577.  
  578.     page
  579. ;
  580. ;
  581. ;
  582. prog$fun:
  583.     pop    psw            ; remove garbage
  584.  
  585.     lxi    b,buff$large*256+buff$pos    ; b=size, c=pos
  586.     call    ?save
  587.  
  588.     call    read$key        ; get function key to program
  589.     cpi    80h
  590.     jrc    restore$buf$large    ; error, exit
  591.  
  592.     cpi    0A0h
  593.     jrnc    restore$buf$large
  594.  
  595.     ani    1fh            ; 32 keys defined
  596.     mov    b,a
  597.     call    get$fun$adr        ; get pointer to function code
  598.  
  599.     xra    a
  600.     sta    string$index        ; start at start of string
  601.  
  602.     call    edit$fun
  603.  
  604.     lxi    h,0
  605.     shld    msg$ptr            ; clear message pointer
  606.  
  607. restore$buf$large:
  608.     call    delay
  609.     lxi    b,buff$large*256+buff$pos    ; B=size, C=position
  610.     jmp    ?recov
  611.  
  612.     page
  613. ;
  614. ;
  615. ;
  616. delay:
  617.     lxi    h,0
  618. delay$loop:
  619.     dcx    h
  620.     mov    a,h
  621.     ora    l
  622.     jrnz    delay$loop
  623.     ret
  624. ;
  625. ;
  626. ;
  627. edit$fun:
  628.     lxi    h,edit$fun
  629.     push    h            ; set return to here
  630.     call    disp$fun$key
  631.     call    read$key        ; B=matrix position
  632.     mov    d,a            ; save ASCII char in D
  633.     mov    a,c            ; get attr (C=cntr codes)
  634.     ani    special
  635.     cpi    special            ; check for cntr shift
  636.     jnz    not$cntr$shift
  637.  
  638.  
  639. ;
  640. ;
  641. ;
  642. check$exit:
  643.     mov    a,b            ; get matrix position
  644.     cpi    SF$exit
  645.     jrnz    check$delete
  646.  
  647.     pop    h            ; remover return adr
  648.     ret                ; go back to normal keyboard fun
  649.  
  650.     page
  651. ;
  652. ;
  653. ;
  654. check$delete:
  655.     cpi    SF$delete
  656.     jrnz    check$insert
  657. ;
  658. ;    delete the character at current cursor position
  659. ;
  660.     call    compute$adr        ; HL= current position
  661.     rz                ; don't want to delete end markers
  662.  
  663.     xchg                ; save in DE
  664.     lhld    key$tbl            ; get next table adr (keytbl)
  665.     dcx    h
  666. ; lxi    h,msgtbl$end-1        ; end adr
  667.     xra    a            ; clear the carry flag
  668.     dsbc    DE            ; compute number of bytes to move
  669.     mov    b,h
  670.     mov    c,l            ; place count in BC
  671.     mov    h,d
  672.     mov    l,e            ; HL=DE
  673.     inx    h            ;
  674.     ldir
  675.  
  676.     dcx    h            ; point to insert point
  677.     mvi    m,-1            ; fill table end with -1
  678.     ret
  679.  
  680.     page
  681. ;
  682. ;
  683. ;
  684. check$insert:
  685.     cpi    SF$insert
  686.     jrnz    check$right
  687. ;
  688. ;    insert a space into string
  689. ;
  690.     call    compute$adr
  691. ;
  692. ;    HL=address to insert a space at
  693. ;     value of HL is the same on return
  694. ;
  695. insert$space:
  696.     xchg
  697.     lhld    key$tbl            ; get start of next table
  698.     dcx    h            ; point to end of msg table
  699. ; lxi    h,msgtbl$end-1
  700.     xra    a
  701.     cmp    m            ; last char=0 (end of string)
  702.     rz                ; yes, don't insert 
  703.  
  704.     xra    a            ; clear the carry flag
  705.     dsbc    DE            ; compute number of bytes to move
  706.     mov    b,h
  707.     mov    c,l            ; place count in BC
  708.  
  709.     lhld    key$tbl
  710.     dcx    h
  711.     mov    d,h
  712.     mov    e,l
  713. ; lxi    d,msgtbl$end-1            ; dest adr
  714.     dcx    h
  715. ; lxi    h,msgtbl$end-2            ; source adr
  716.     lddr                ; move the data
  717.     inx    h            ; point to insert point
  718.     adi    ' '            ; A was equ to zero, add a space to
  719.     mov    m,a            ; ..clear the zero flag
  720.     ret                ; insert a space at the new location
  721.  
  722.     page
  723. ;
  724. ;
  725. ;
  726. check$right
  727.     cpi    SF$right
  728.     jrnz    check$left
  729. ;
  730. ;    move cursor right
  731. ;     if past right end go back to left end
  732. ;
  733.     call    compute$adr
  734.     lda    string$index
  735.     jrnz    move$rt
  736.  
  737.     mvi    a,-1    
  738. move$rt:
  739.     inr    a
  740.     sta    string$index
  741.     ret
  742.  
  743. ;
  744. ;
  745. ;
  746. check$left:
  747.     cpi    SF$left
  748.     rnz
  749. ;
  750. ;    move cursor left
  751. ;     if past left end go to right end
  752. ;
  753.     lda    string$index
  754.     ora    a
  755.     jrz    at$left$end
  756.  
  757.     dcr    a
  758.     sta    string$index
  759.     ret
  760.  
  761.  
  762.     page
  763. ;
  764. ;
  765. ;
  766. at$left$end:
  767.     call    compute$adr
  768.     rz                ; return if at right end
  769.  
  770.     lda    string$index
  771.     inr    a
  772.     sta    string$index        ; move right one position
  773.     jr    at$left$end        ; 
  774.  
  775.  
  776.  
  777. ;
  778. ;
  779. ;
  780. not$cntr$shift:
  781.     call    compute$adr        ; HL=function adr (A=0 if string end)
  782.     jrnz    no$insert
  783.  
  784.     push    d            ; save char to insert
  785.     call    insert$space
  786.     pop    d            ; recover character
  787.     rz                ; no room if zero flag set
  788.  
  789. no$insert:
  790.     mov    m,d            ; install key's value
  791.     lda    string$index
  792.     inr    a
  793.     sta    string$index
  794.     ret
  795.  
  796.     page
  797. ;
  798. ;
  799. ;
  800. compute$adr:
  801.     lhld    msg$ptr            ; get start of memory pointer
  802.     lda    string$index        ; get current offset
  803.     add    l
  804.     mov    l,a
  805.     mov    a,h
  806.     aci    0
  807.     mov    h,a            ; point to update location
  808.     mov    a,m
  809.     ora    a
  810.     ret
  811.  
  812. ;
  813. ;
  814. ;
  815. disp$fun$key:
  816.     mvi    a,buff$pos
  817.     sta    offset
  818.     mvi    a,'>'            ; display start prompt '>'
  819.     call    disp$status
  820.  
  821.     lhld    msg$ptr
  822.     lda    string$index
  823.  
  824. try$again:
  825.     cpi    buff$large-2
  826.     jrc    parameters$ok
  827.  
  828.     inx    h
  829.     dcr    a
  830.     jr    try$again
  831.  
  832.     page
  833. ;
  834. ;
  835. ;
  836. parameters$ok:
  837.     adi    buff$pos+1
  838.     sta    cur$pos 
  839.  
  840. disp$fun$loop:
  841.     mov    a,m
  842.     ora    a
  843.     inx    h             ; advance function pointer
  844.     jrz    disp$fun$end
  845.  
  846.     push    h
  847.     call    disp$status        ; display on status line
  848.     pop    h
  849.     lda    offset            ; get current cursor position
  850.     cpi    buff$pos+buff$large-1    ; to end of window?
  851.     jrnz    disp$fun$loop        ; no, display next character
  852.  
  853.  
  854. disp$fun$end:
  855.     mvi    a,'<'            ; display end prompt '<'
  856. disp$space$fill:
  857.     call    disp$status
  858.     lda    offset            ; get current cursor position
  859.     cpi    buff$pos+buff$large    ; to end of window?
  860.     rz
  861.  
  862.     mvi    a,' '            ; fill to the end with spaces
  863.     jr    disp$space$fill
  864.  
  865.     page
  866. ;
  867. ;
  868. ;
  869. disp$hex$byte:
  870.     push    psw
  871.     rar
  872.     rar
  873.     rar
  874.     rar
  875.     call    disp$hex$nibble
  876.     pop    psw
  877.  
  878. disp$hex$nibble:
  879.     ani    0fh
  880.     adi    '0'
  881.     cpi    '9'+1
  882.     jrc    disp$status
  883.  
  884.     adi    7
  885.  
  886. disp$status:
  887.     mov    b,a
  888.     lda    offset
  889.     mov    c,a
  890.     inr    a
  891.     sta    offset
  892.     lda    cur$pos
  893.     cmp    c
  894.     mvi    a,01000000b        ; set reverse video attributes
  895.     jrnz    not$cur$pos
  896.  
  897.     mvi    a,00010000b        ; set normal video and blink
  898. not$cur$pos:
  899.     jmp    ?stat
  900.  
  901.  
  902.     page
  903. ;
  904. ;
  905. ;
  906. get$byte:
  907.     mvi    e,0
  908.     call    read$nibble
  909.     rc
  910.  
  911.     add    a
  912.     add    a
  913.     add    a
  914.     add    a
  915.     mov    e,a
  916.  
  917. read$nibble:
  918.     push    d
  919.     call    read$key
  920.     mov    a,b            ; get matrix position
  921.     lxi    h,hex$key$tbl
  922.     lxi    b,16
  923.     ccir
  924.  
  925.     mov    a,c
  926.     pop    d
  927.     stc
  928.     rnz
  929.  
  930.     add    e
  931.     push    d
  932.     push    psw
  933.     call    disp$hex$nibble
  934.     pop    psw
  935.     pop    d
  936.     stc
  937.     cmc
  938.     ret
  939.  
  940. ;
  941. ;
  942. ;
  943. read$key:
  944.     call    scan$keys
  945.     inr    b
  946.     jrz    read$key        ; no, wait for one
  947.     dcr    b
  948.     ret
  949.  
  950.     page
  951. ;
  952. ;
  953. ;
  954. do$alpha$toggle:
  955.     mvi    m,0ffh        ; mark buffer position free    
  956.     lda    commodore$mode
  957.     xri    00100001b
  958.     ani    00100001b
  959.     sta    commodore$mode
  960. ;    
  961. ; output:
  962. ;    B=FF if no key pressed
  963. ;    A=00 if no key code assigned
  964. ;    else     A=ASCII key code 
  965. ;        B=matrix position (0-57)
  966. ;        C=control code (bits 1,0)
  967. ;            00=lower case    (lowest)
  968. ;            01=upper case
  969. ;            10=shift
  970. ;            11=control    (highest)
  971. ;          (bit 2) control key
  972. ;          (bit 4) rt. shift key
  973. ;          (bit 5) commodore key
  974. ;          (bit 7) lf. shift key
  975. ;
  976. ;    HL= address of ASCII key location
  977. ;
  978. ?kyscn:
  979. scan$keys:
  980.     lhld    key$get$ptr
  981.     mov    a,m        ; M=-1 if buffer empty
  982.     mov    b,a        ; B=-1 if no character
  983.     inr    a
  984.     rz            ; return if no key is pressed
  985. ;
  986. ;    there is a character in the buffer,
  987. ;    advance key$get$ptr to next character.
  988. ;
  989.     mov    a,l
  990.     adi    2
  991.     cpi    low(key$buffer+key$buf$size)
  992.     jrnz    not$buf$end
  993.     mvi    a,low(key$buffer)
  994. not$buf$end:
  995.     sta    key$get$ptr    ; update low byte of pointer
  996.  
  997.     page
  998. ;
  999. ;    test for commodore key, if found toggle commodore mode
  1000. ;
  1001.     mov    a,b        ; get buffered matrix position to A
  1002.     cpi    alpha$toggle
  1003.     jrz    do$alpha$toggle
  1004. ;
  1005. ;    if normal mode(00), or in commodore mode bit
  1006. ;
  1007.     inr    l        ; point to control byte
  1008.     lda    commodore$mode
  1009.     ani    00100000b    ; save commodore key set bit
  1010.     ora    m        ; get rest of control byte
  1011.     mov    c,a
  1012.     ani    3
  1013.     mov    a,c
  1014.     jrnz    is$control$or$shift
  1015.     lda    commodore$mode
  1016.     ora    c
  1017.  
  1018. is$control$or$shift:
  1019.     dcr    l
  1020.     mvi    m,0ffh        ; mark buffer position free    
  1021.  
  1022.     mov    l,b        ; save matrix position in HL
  1023.     mvi    h,0
  1024.     dad    h
  1025.     dad    h        ; mult. matrix position by 4
  1026.     mov    c,a        ; save the control code in C for caller
  1027.     ani    3
  1028.     add    l        ; add the offset 
  1029.     mov    l,a        ; update the pointer
  1030.     xchg
  1031.     lhld    key$tbl        ; get the start of the ASCII table
  1032.     dad    d        ; HL now points to the ASCII value
  1033.     mov    a,m        ; for the input key.
  1034.     ora    a        ; set zero flag if A=0
  1035.     ret
  1036.  
  1037.     page
  1038. ;
  1039. ;    used to convert a keyboard matrix position into it's HEX
  1040. ;    value (keys caps labelled with 0 to 9 and A to F)
  1041. ;
  1042. hex$key$tbl:
  1043.     db    15h        ; F
  1044.     db    0eh        ; E
  1045.     db    12h        ; D
  1046.     db    14h        ; C
  1047.     db    1ch        ; B
  1048.     db    0ah        ; A
  1049.     db    20h        ; 9
  1050.     db    1bh        ; 8
  1051.     db    18h        ; 7
  1052.     db    13h        ; 6
  1053.     db    10h        ; 5
  1054.     db    0bh        ; 4
  1055.     db    08h        ; 3
  1056.     db    3bh        ; 2
  1057.     db    38h        ; 1
  1058.     db    23h        ; 0
  1059.  
  1060.  
  1061.  
  1062.  
  1063.