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