home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / trs80model4.zip / m4key.asm < prev    next >
Assembly Source File  |  1986-10-22  |  6KB  |  170 lines

  1. ;        m4key/asm
  2. ;
  3. GETKEY        EQU    $
  4.         LD    HL,(KEYPOS)    ;Get the buffered keys address
  5. GETKEY_0    EQU    $
  6.         LD    A,(HL)        ;Get the key there
  7.         IFZ    GETKEY_1    ;Jump if no key available
  8.         INC    HL        ;Point to next
  9.         LD    (KEYPOS),HL    ;Save the new pointer
  10.         CP    A        ;Set Z status
  11.         RET            ;Return the key
  12. ;
  13. ;    Here, we must change the current string pointer back to a KNOWN
  14. ;    zero byte.  Otherwise the next defintion may move non-zero data
  15. ;    underneath the pointer and result in garbage being retrieved on
  16. ;    the next call to GETKEY.
  17. ;
  18. GETKEY_1    EQU    $
  19.         LD    HL,ATNULL    ;Replace current string pointer
  20.         LD    (KEYPOS),HL
  21.         CALL    TRMIN        ;Get a key from *SI
  22.         RET    NZ        ;Return if nothing there
  23.         LD    (SAVEDKEY),A    ;Save it for later use
  24.         CALL    KEYTRANS    ;Get the address from the table
  25.         OR    H        ;A holds L, OR in H to check
  26.         JR    NZ,GETKEY_0    ;Jump if string is present
  27.         LD    A,(SAVEDKEY)    ;Get the real key back
  28.         CP    A        ;Set Z status
  29.         RET            ;Return the key
  30. ;
  31. ;    Store a key definition into the table
  32. ;
  33. DEFKEY        EQU    $
  34.         LD    (KEYSTRING),HL    ;Save the pointer to the data
  35.         LD    (KEYNUMBER),A    ;Save the key to be replaced
  36.         PUSH    AF
  37.         LD    A,B        ;Get the number of bytes in (HL)
  38.         LD    (STRINGLEN),A    ;Store it
  39.         POP    AF
  40.         CALL    KEYTRANS    ;Get the address of the current
  41.         OR    H        ;definition and see if one exists
  42.         CALL    NZ,DELETEKEY    ;If so, then remove it
  43.         LD    A,(STRINGLEN)    ;Get the length
  44.         OR    A        ;Is there a string there?
  45.         RET    Z        ;Return if none.  Old was deleted
  46.         LD    HL,DEFTABLE+DEFTLEN-1;Get the top of the table
  47.         LD    DE,(TOPADDR)    ;Get the start of available
  48.         OR    A        ;Reset carry
  49.         SBC    HL,DE        ;Compute available number bytes
  50.         LD    C,A        ;Get the request size as 16 bits
  51.         LD    B,0
  52.         OR    A        ;Reset the carry
  53.         SBC    HL,BC        ;Compute the remaining after use
  54.         JR    NC,DEFKEY_1    ;Jump if there is room for it
  55.         LD    DE,NOSPACE    ;Print the error message
  56.         CALL    PRTSTR
  57.         RET            ;Return without defining it
  58. DEFKEY_1    EQU    $
  59.         LD    HL,(KEYSTRING)    ;Get the new definition
  60.         PUSH    DE        ;Save the address to store at
  61.         LDIR            ;Move the string
  62.         EX    DE,HL        ;Get the ending address
  63.         LD    (HL),0        ;Put a NULL in
  64.         INC    HL        ;Point to next available
  65.         LD    (TOPADDR),HL    ;Save the new available address
  66.         POP    DE        ;Restore the definition address
  67.         LD    HL,(TABLEADDR)    ;Get the address in the table
  68.         LD    (HL),E        ;Store the LSB
  69.         INC    HL        ;Point to the MSB
  70.         LD    (HL),D        ;Save the MSB
  71.         RET            ;Return to the caller
  72. ;
  73. ;    Get the address of the string corresponding to the key number
  74. ;    in A.  A holds the value of H on return.  HL is zero if no
  75. ;    definition exists.  HL is the address of the string that is
  76. ;    defined for the key if it is non-zero.  The last byte in the
  77. ;    string is followed by a zero byte.
  78. ;
  79. KEYTRANS    EQU    $
  80.         LD    HL,KEYTABLE    ;Get the pointer table
  81.         LD    C,A        ;Put it into C
  82.         LD    B,0        ;Set B to zero initially
  83.         RLC    C        ;C = C * 2
  84.         JR    NC,KEYTRANS_1    ;If carry on shift then c > 127,
  85.         INC    B        ;so increment B to recover bit 7
  86. KEYTRANS_1    EQU    $
  87.         RES    0,C        ;Reset the LSB of C.
  88.         ADD    HL,BC        ;Compute the table address
  89.         LD    (TABLEADDR),HL    ;Save the address of the key def
  90.         LD    A,(HL)        ;Get the LSB
  91.         INC    HL        ;Point to the MSB
  92.         LD    H,(HL)        ;Get it
  93.         LD    L,A        ;Get the LSB
  94.         RET            ;Return to caller
  95. ;
  96. ;    Delete a key definition from the table.  No parameters are
  97. ;    needed.  The key to undefine is pointed to by (TABLEADDR).
  98. ;    Thus, you must call KEYTRANS with the key number in A and then
  99. ;    call DELETEKEY to delete the key.
  100. ;
  101. DELETEKEY    EQU    $
  102.         LD    HL,(TABLEADDR)    ;Get the addr of the definition
  103.         LD    E,(HL)        ;Get the LSB of the string
  104.         XOR    A        ;Clear A
  105.         LD    (HL),A        ;Zap the LSB
  106.         INC    HL        ;Point to the MSB
  107.         LD    D,(HL)        ;Get the MSB
  108.         LD    (HL),A        ;Zap the MSB
  109.         LD    (CMPADDR),DE    ;Save the address for compares
  110.         LD    H,D        ;Copy DE to HL
  111.         LD    L,E
  112. ;        XOR    A        ;A is already zero (what we seek)
  113.         CPIR            ;Look for it
  114.         PUSH    HL        ;Save the ending address
  115.         OR    A        ;Reset the carry
  116.         SBC    HL,DE        ;Compute the difference
  117.         LD    (MOVEDIFF),HL    ;Save the difference
  118.         LD    HL,(TOPADDR)    ;Get the end of the table
  119.         POP    BC        ;Get the end of string to delete
  120.         OR    A        ;reset the carry
  121.         SBC    HL,BC        ;Calculate number bytes to move
  122.         PUSH    BC        ;Exchange HL and BC
  123.         PUSH    HL
  124.         POP    BC
  125.         POP    HL
  126.         LD    A,B        ;Check for zero length
  127.         OR    C
  128.         JR    Z,DELETEKEY_1    ;Don't move 65536 bytes
  129.         LDIR            ;Adjust the strings down
  130. DELETEKEY_1    EQU    $
  131.         LD    (TOPADDR),DE    ;Set the new top address
  132.         LD    HL,KEYTABLE    ;Get start of table
  133.         LD    B,0        ;Check 256 entrys
  134. DELETEKEY_2    EQU    $
  135.         PUSH    BC        ;Save the counter
  136.         LD    C,(HL)        ;Get the table value LSB
  137.         INC    HL        ;Point to MSB
  138.         LD    B,(HL)        ;Get the MSB
  139.         DEC    HL        ;Back to original address
  140.         LD    A,B        ;Check for any definition
  141.         OR    C        ;Set the flags
  142.         JR    Z,DELETEKEY_4    ;Skip this entry
  143.         PUSH    HL        ;Save the table address
  144.         LD    HL,(CMPADDR)    ;Get the address to check against
  145.         OR    A        ;Reset the carry
  146.         SBC    HL,BC        ;Compute the difference
  147.         JP    P,DELETEKEY_3    ;Jump if no adjust needed
  148.         LD    H,B        ;Copy BC to HL
  149.         LD    L,C
  150.         LD    BC,(MOVEDIFF)    ;Get the difference
  151.         OR    A        ;Reset the carry
  152.         SBC    HL,BC        ;Adjust the pointer
  153.         LD    C,L        ;Copy HL to BC
  154.         LD    B,H        ;Get the MSB
  155.         POP    HL        ;Get the destination address
  156.         LD    (HL),C        ;Store the LSB back
  157.         INC    HL        ;Point to MSB
  158.         LD    (HL),B        ;Store the MSB
  159.         JR    DELETEKEY_5    ;Join other code
  160. DELETEKEY_3    EQU    $
  161.         POP    HL        ;Get the table address back
  162. DELETEKEY_4    EQU    $
  163.         INC    HL        ;Point to next table pos
  164. DELETEKEY_5    EQU    $
  165.         INC    HL        ;One more increment
  166.         POP    BC        ;Get the counter back
  167.         DJNZ    DELETEKEY_2    ;Loop until done
  168.         RET
  169. ;end of file
  170.