home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / keymap.lbr / KEYMAP.ZZ0 / KEYMAP.Z80
Encoding:
Text File  |  1993-06-07  |  3.3 KB  |  156 lines

  1. ;
  2. ;-----Keymap----A function key generator------
  3. ;---Assemble with your favorite z80 assembler, link with syslib.
  4. ;
  5. ;---Set the following three values to match your system requirements,
  6. ;---The routine auto-installs in your iop, processing your keystrokes.
  7. ;---The offset value governs exactly where in the iop this routine
  8. ;---will load.
  9. ;
  10. iop    equ    0ec00h
  11. offset    equ    60h
  12. trigger equ    22    ;control-V is the trigger key
  13. ;
  14. keymap    equ    iop + offset
  15. cr    equ    13
  16. lf    equ    10
  17.     ext    instr,print
  18.     db    'Z3ENV',1
  19. z3ptr:    dw    0
  20. start:    call print
  21.     db    'Welcome to Keymap--',0
  22.     ld    hl,keymap
  23.     ld    de,teststr
  24.     call    instr
  25.     jr    nz,keepgoin
  26.     call    print
  27.     db    7,'Keymap already installed--New version overlaid',cr,lf,0
  28.     jr    beenhere
  29. keepgoin:    call    print
  30.     db    'initial installation',cr,lf,0
  31.     ld    hl,codbeg
  32.     ld    de,keymap
  33.     ld    bc,codend-codbeg
  34.     ldir
  35.     ld    hl,(iop + 10h)
  36.     ld    (coninad),hl
  37.     ld    hl,(iop + 0dh)
  38.     ld    (constad),hl
  39.     ld    hl,top
  40.     ld    (iop + 10h),hl
  41.     ld    hl,newstat
  42.     ld    (iop + 0dh),hl
  43.     ret
  44. beenhere:    ld    hl,codbeg+11
  45.     ld    de,keymap+11
  46.     ld    bc,codend-codbeg-11
  47.     ldir
  48.     ld    hl,top
  49.     ld    (iop + 10h),hl
  50.     ld    hl,newstat
  51.     ld    (iop + 0dh),hl
  52.     ret
  53. teststr:    db    'KEYMAP',0
  54. codbeg:    .phase    keymap
  55.     db    'KEYMAP',0
  56. coninad:    dw    0
  57. constad:    dw    0
  58. top:    ld    a,(pend)
  59.     and    a    ;chars pending?
  60.     jr    z,nopend
  61.     ld    hl,(chrptr)    ;yes, get the char in b
  62.     ld    b,(hl)
  63.     inc    hl    ;update pointer
  64.     ld    (chrptr),hl
  65.     ld    a,(hl)    ;check out next char
  66.     and    a
  67.     jr    z,strend    ;end of string if null
  68.     ld    a,b
  69.     ret        ;and return with character in a
  70. strend: ld    (pend),a
  71.     ld    a,b
  72.     ret
  73. nopend:
  74.     call conin
  75.     push af
  76.     xor a
  77.     ld (pend),a
  78.     ld a,(map)
  79.     and a    ;mapped?
  80.     jr nz,mapped
  81.     pop af
  82.     cp trigger
  83.     jr z,mappit; if the trigger char, set the map bit
  84.     ret    ;not mapped, this is our usual exit, char in a
  85. mappit:    ld a,1
  86.     ld (map),a
  87. kk:    call const
  88.     jr    z,kk
  89.     jr nopend ;set map bit, get next incoming char
  90. mapped: xor a
  91.     ld (map),a ;clear map bit
  92.     pop af
  93.     ld    d,a    ;save char in d
  94.     cp    27    ;is it a control char?
  95.     jr    nc,kaps    ;no.
  96.     add    a,40h    ;make control char->capital letter
  97.     jr    ok
  98. kaps:    call    caps    ;lower->upper case,if nec.
  99. ok:    ld    bc,(number)    ;# of hot keys
  100.     ld    hl,strlist-1 ;end of keylist
  101.     cpdr
  102.     ld    a,d    ;restore char, you might need it
  103.     ret    nz    ;just send character
  104.     ld    hl,strlist
  105.     add    hl,bc
  106.     add    hl,bc
  107.     ld    a,(hl)
  108.     ld    (chrptr),a
  109.     inc    hl
  110.     ld    a,(hl)
  111.     ld    (chrptr+1),a
  112.     ld    a,1
  113.     ld    (pend),a
  114.     jr     top        ;pending expanded string ready to go!
  115. caps:    cp    61H    ;usual lo-to up routine.
  116.     ret    c
  117.     cp    7bh
  118.     ret    nc
  119.     sub    20h
  120.     ret
  121. newstat:    call const
  122.     ret    nz    ;chars in queue, leave as is
  123.     ld    a,(pend)
  124.     and    a
  125.     ret    z    ;no pending chars, zero return
  126.     or    255
  127.     ret        ;end just like const does
  128. conin:    ld    hl,retnhere
  129.     push    hl
  130.     ld    hl,(coninad)
  131.     jp    (hl)
  132. const:    ld    hl,retnhere
  133.     push    hl
  134.     ld    hl,(constad)
  135.     jp    (hl)
  136. retnhere:    ret
  137. number:    dw    strlist-number-2
  138.     db    '567890CMQB`'
  139. strlist: dw    s5,s6,s7,s8,s9,s0,cs,ms,qs,bs,tilde
  140. s5:    db    '\(*',0        ;greek precursor
  141. s6:    db    '\*d',0        ;start subscript
  142. s7:    db    '\*D',0        ;end   subscript
  143. s8:    db    '\*u',0        ;start superscript
  144. s9:    db    '\*U',0        ;end   superscript
  145. s0:    db    26,'%+&',cr,0    ;run current program in background
  146. cs:    db    'cls',cr,0
  147. ms:    db    ' mex t',cr,0
  148. qs:    db    lf,'ecpm',cr,0
  149. bs:    db    'black',cr,0
  150. tilde:    db    '~/',0
  151. chrptr:    dw    0
  152. pend:    db    0
  153. map:    db    0
  154.     .dephase
  155. codend:    end    start
  156.