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