-
Notifications
You must be signed in to change notification settings - Fork 5
/
DEND.ASM
153 lines (117 loc) · 2.5 KB
/
DEND.ASM
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
145
146
147
148
149
150
151
152
153
; *******************************************************
; * *
; * Turbo Pascal Run-time Library *
; * DPMI Termination Procedures Module *
; * *
; * Copyright (c) 1988,92 Borland International *
; * *
; *******************************************************
TITLE DEND
.286P
INCLUDE SE.ASM
CONST SEGMENT WORD PUBLIC
; Runtime error message string
ErrorStr DB 'Runtime error '
ErrorCodeStr DB '000 at '
ErrorAddrStr DB '0000:0000.',cr,lf,'$'
CONST ENDS
DATA SEGMENT WORD PUBLIC
; Externals
EXTRN ExitProc:DWORD,ExitCode:WORD,ErrorAddr:DWORD
EXTRN PrefixSeg:WORD,InOutRes:WORD
DATA ENDS
DGROUP GROUP CONST,DATA
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE,DS:DGROUP
; Publics
PUBLIC HaltTurbo,HaltError,Terminate,DoExitProcs
; RunError standard procedure
HaltError:
POP CX
POP BX
JMP SHORT Terminate
; Halt standard procedure
HaltTurbo:
XOR CX,CX
XOR BX,BX
; Terminate program
; In AX = Exit code
; BX:CX = Error address (or NIL)
Terminate:
MOV DX,SEG DATA ;Reset DS
MOV DS,DX
STI ;Enable interrupts
MOV ExitCode,AX ;Save exit code
MOV AX,CX ;Is error address NIL?
OR AX,BX
JE @@2 ;Yes, @@2
VERR BX ;Valid selector?
JE @@1 ;Yes, @@1
MOV BX,0FFFFH ;Unknown address
MOV CX,BX
JMP SHORT @@2
@@1: MOV ES,BX ;Get logical segment number
MOV BX,WORD PTR ES:0
@@2: MOV ErrorAddr.ofs,CX ;Save error address
MOV ErrorAddr.seg,BX
CMP PrefixSeg,0 ;Is this a library?
JE @@3 ;Yes, WEP will do exit procs
CALL DoExitProcs ;Execute exit procedures
@@3: MOV AX,ErrorAddr.ofs ;Runtime error?
OR AX,ErrorAddr.seg
JE @@4 ;No, @@4
MOV CX,10
MOV AL,ExitCode.b0
XOR AH,AH
MOV BX,OFFSET ErrorCodeStr+3
CALL Num2Str
MOV CX,16
MOV AX,ErrorAddr.seg
MOV BX,OFFSET ErrorAddrStr+4
CALL Num2Str
MOV AX,ErrorAddr.ofs
MOV BX,OFFSET ErrorAddrStr+9
CALL Num2Str
MOV AH,9
MOV DX,OFFSET ErrorStr
INT DOS
@@4: MOV AL,ExitCode.b0 ;Get exit code
MOV AH,dosExit ;Terminate application
INT DOS
; Execute exit procedures
DoExitProcs:
@@1: LES BX,ExitProc
MOV AX,ES
OR AX,BX
JE @@2
XOR AX,AX
MOV ExitProc.ofs,AX
MOV ExitProc.seg,AX
MOV InOutRes,AX
MOV AX,OFFSET @@1
PUSH CS
PUSH AX
PUSH ES
PUSH BX
RETF
@@2: RET
; Convert number to string
; In AX = Number
; BX = Pointer to end of buffer
; CX = Number base
Num2Str:
@@1: XOR DX,DX
DIV CX
ADD DL,'0'
CMP DL,'0'+10
JB @@2
ADD DL,'A'-'0'-10
@@2: DEC BX
MOV [BX],DL
OR AX,AX
JNE @@1
RET
; Copyright notice
Copyright DB 'Portions Copyright (c) 1983,92 Borland'
CODE ENDS
END