/
DISPATCH.INC
83 lines (73 loc) · 2.1 KB
/
DISPATCH.INC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;*** dispatch.inc - table dispatch macros
;
; Author:
; Benjamin W. Slivka
; Microsoft Corporation
; (c) 1987
BREAK <dtB,dtS,dtE,dtDisp - Dispatch Table Macros>
;*** dtB - BEGIN dispatch table
;
; ENTRY: name = name of dt table
; badAddr = local label for unspecified entries
; EXIT: Table name declared.
; ?sIndex = -1, indicates no entries specified yet
; ?badAddr set to default handler for unspecified entries
dtB macro name,badAddr ;; Beginning of Dispatch Table
?sIndex = -1
?badAddr = badAddr
&name&DispTable label word ;; Start of dispatch table
endm
;*** dtS - SPECIFIC dispatch table entry
;
; ENTRY: name = name of dt table
; index = index of entry
; addr = address of handler
; EXIT: Unspecified entries prior to "index" filled in;
; Specified entry filled in.
; ?sIndex = next index to fill in;
; ?Low&name = lowest specified index, if first dtS
dtS macro name,index,addr ;; Specific entry in Dispatch Table
if ?sIndex eq -1 ;; First entry in table
Low&name equ &index ;; Set lowest index
?sIndex = index
endif
if ?sIndex gt index
.err ;dtS: index out of order
else
if ?sIndex lt index ;; Fill unspecified entries
rept index - ?sIndex
dw ?badAddr
endm
endif
dw addr ;; Specified entry
?sIndex = index+1 ;; Set new start index
endif
endm
;*** dtE - END dispatch table
;
; ENTRY: name = name of dt table
; EXIT: ?High&name defined as highest specified index
dtE macro name ;; End of Dispatch Table
High&name equ ?sIndex-1 ;; Set highest iIndex
endm
;*** dtDisp - Make dispatch using dt table
;
; ENTRY: name = name of dt table
; (BX) = index of handler to call
;
; EXIT: IF index in "reg" is in range THEN
; jmp to handler in table
; ELSE
; continue execution at next instruction
;
; USES: BX,flags
dtDisp macro name
local a
sub bx,Low&Name ;; (bx) = index into table
jb short a ;; Index is too small
cmp bx,High&Name - Low&Name ;;
ja short a ;; Index is too large
shl bx,1
jmp cs:&name&DispTable[bx] ;; Go to handler
a:
endm