home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / nor_asm / dispat22.asm < prev    next >
Assembly Source File  |  1989-05-17  |  3KB  |  93 lines

  1. .MODEL    SMALL
  2.  
  3. .CODE
  4.     EXTRN    NEXT_SECTOR:PROC            ;In DISK_IO.ASM
  5.     EXTRN    PREVIOUS_SECTOR:PROC            ;In DISK_IO.ASM
  6.     EXTRN    PHANTOM_UP:PROC, PHANTOM_DOWN:PROC    ;In PHANTOM.ASM
  7.     EXTRN    PHANTOM_LEFT:PROC, PHANTOM_RIGHT:PROC
  8. .DATA
  9. ;-----------------------------------------------------------------------;
  10. ; This table contains the legal extended ASCII keys and the addresses    ;
  11. ; of the procedures that should be called when each key is pressed.    ;
  12. ;                                    ;
  13. ; The format of the table is                        ;
  14. ;        DB    72        ;Extended code for cursor up    ;
  15. ;        DW    OFFSET PHANTOM_UP                ;
  16. ;-----------------------------------------------------------------------;
  17. DISPATCH_TABLE    LABEL    BYTE
  18.     DB    61                ;F3
  19.     DW    OFFSET _TEXT:PREVIOUS_SECTOR
  20.     DB    62                ;F4
  21.     DW    OFFSET _TEXT:NEXT_SECTOR
  22.     DB    72                ;Cursor up
  23.     DW    OFFSET _TEXT:PHANTOM_UP
  24.     DB    80                ;Cursor down
  25.     DW    OFFSET _TEXT:PHANTOM_DOWN
  26.     DB    75                ;Cursor left
  27.     DW    OFFSET _TEXT:PHANTOM_LEFT
  28.     DB    77                ;Cursor right
  29.     DW    OFFSET _TEXT:PHANTOM_RIGHT
  30.     DB    0                ;End of the table
  31.  
  32. .CODE
  33.  
  34.     PUBLIC    DISPATCHER
  35.     EXTRN    READ_BYTE:PROC, EDIT_BYTE:PROC
  36. ;-----------------------------------------------------------------------;
  37. ; This is the central dispatcher. During normal editing and viewing,    ;
  38. ; this procedure reads characters from the keyboard and, if the char    ;
  39. ; is a command key (such as a cursor key), DISPATCHER calls the        ;
  40. ; procedures that do the actual work.  This dispatching is done for    ;
  41. ; special keys listed in the table DISPATCH_TABLE, where the procedure    ;
  42. ; addresses are stored just after the key names.            ;
  43. ;                                    ;
  44. ; If the character is not a special key, then it should be placed    ;
  45. ; directly into the sector buffer--this is the editing mode.        ;
  46. ;                                    ;
  47. ; Uses:        READ_BYTE, EDIT_BYTE                    ;
  48. ;-----------------------------------------------------------------------;
  49. DISPATCHER    PROC
  50.     PUSH    AX
  51.     PUSH    BX
  52.     PUSH    DX
  53. DISPATCH_LOOP:
  54.     CALL    READ_BYTE        ;Read character into AX
  55.     OR    AH,AH            ;AX = -1 if no character read, 1
  56.                     ; for an extended code.
  57.     JS    DISPATCH_LOOP        ;No character read, try again
  58.     JNZ    SPECIAL_KEY        ;Read extended code
  59.     MOV    DL,AL
  60.     CALL    EDIT_BYTE        ;Was normal character, edit byte
  61.     JMP    DISPATCH_LOOP        ;Read another character
  62.  
  63. SPECIAL_KEY:
  64.     CMP    AL,68            ;F10--exit?
  65.     JE    END_DISPATCH        ;Yes, leave
  66.                     ;Use BX to look through table
  67.     LEA    BX,DISPATCH_TABLE
  68. SPECIAL_LOOP:
  69.     CMP    BYTE PTR [BX],0        ;End of table?
  70.     JE    NOT_IN_TABLE        ;Yes, key was not in the table
  71.     CMP    AL,[BX]            ;Is it this table entry?
  72.     JE    DISPATCH        ;Yes, then dispatch
  73.     ADD    BX,3            ;No, try next entry
  74.     JMP    SPECIAL_LOOP        ;Check next table entry
  75.  
  76. DISPATCH:
  77.     INC    BX            ;Point to address of procedure
  78.     CALL    WORD PTR [BX]        ;Call procedure
  79.     JMP    DISPATCH_LOOP        ;Wait for another key
  80.  
  81. NOT_IN_TABLE:                ;Do nothing, just read next character
  82.     JMP    DISPATCH_LOOP
  83.  
  84. END_DISPATCH:
  85.     POP    DX
  86.     POP    BX
  87.     POP    AX
  88.     RET
  89. DISPATCHER    ENDP
  90.  
  91.  
  92.     END
  93.