-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmplex.asm
More file actions
144 lines (116 loc) · 3.5 KB
/
mplex.asm
File metadata and controls
144 lines (116 loc) · 3.5 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
;;================================================
;; SKELETSR: A skeleton DOS TSR program
;; MPLEX.ASM: Multiplex interrupt interface implementation
;; Copyright © 2026 Zive Technology Research
;; Licensed under the BSD 2-Clause License
;;================================================
include common.inc
public MultiplexId
public SavedMultiplexVector
public MultiplexInterruptHandler
extrn Psp: word
;;================================================
;; Resident data
;;================================================
.data
;; Dispatch table for multiplex subfunctions
MultiplexDispatchTable dw InstallationCheck ; 00h
dw Uninstall ; 01h
;; Saved multiplex (interrupt 2Fh) vector
SavedMultiplexVector dd ?
;; Multiplex ID
MultiplexId db 0
;;================================================
;; Resident code
;;================================================
.code
;;================================================
;; MultiplexInterruptHandler: Our multiplex interrupt handler
;;
;; Inputs: AH = multiplex ID
;; AL = subfunction
;; Outputs: AL = result code
;; Clobbers: none
MultiplexInterruptHandler proc far
; Is this interrupt for us?
cmp ah, cs:[MultiplexId] ; check multiplex ID
jne short @@ChainToSavedHandler ; not for us, chain to saved handler
; Clear direction flag; enable interrupts
cld
sti
; Check subfunction
cmp al, 1
ja @@UnknownFunction
; Dispatch to handler
push bx
mov bl, al
xor bh, bh
shl bx, 1
call cs:[bx + MultiplexDispatchTable]
pop bx
iret
@@ChainToSavedHandler:
jmp cs:[SavedMultiplexVector]
@@UnknownFunction:
mov al, 01h
iret
MultiplexInterruptHandler endp
;;================================================
;; InstallationCheck: Respond to Installation Check subfunction
;;
;; Inputs: none
;; Outputs: AL = 0FFh to indicate installed
;; SI:DI = ZMP signature 'ZIVE'
;; DX = TSR signature 'SK'
;; Clobbers: none
InstallationCheck proc near
mov al, 0FFh ; Indicate installed
mov si, 'ZI' ; ZMP signature in SI:DI -- 'ZIVE'
mov di, 'VE'
mov dx, 'SK' ; TSR signature in DX -- 'SK'
ret
InstallationCheck endp
;;================================================
;; Uninstall: Respond to Uninstall subfunction, uninstalling our TSR if possible
;;
;; Inputs: none
;; Outputs: AL = 0 on success
;; AL = 1 on failure
;; Clobbers: none
Uninstall proc near
multipush ax, dx, ds, es
;;================================================
;; Can we uninstall?
;;================================================
; Does the multiplex vector still point to us?
DosGetVector 2Fh
mov ax, cs
mov dx, es
cmp dx, ax
jne @@CantUninstall
cmp bx, offset cs:MultiplexInterruptHandler
jne @@CantUninstall
;;================================================
;; Yes; can uninstall
;;================================================
; Restore original multiplex vector
lds dx, cs:[SavedMultiplexVector]
DosSetVector 2Fh, ds, dx
; Free PSP and our resident code/data
mov es, cs:[Psp]
mov ah, 49h
int 21h
; Return success
multipop es, ds, dx, ax
xor al, al
ret
;;================================================
;; No; cannot uninstall
;;================================================
@@CantUninstall:
; Return failure
multipop es, ds, dx, ax
mov al, 01h
ret
Uninstall endp
end