-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWIN.ASM
284 lines (219 loc) · 5.22 KB
/
WIN.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
; Turbo Pascal 6.0 example
; Assembler include file for WIN.PAS unit
; Copyright (c) 1989,90 by Borland International, Inc.
TITLE WIN
LOCALS @@
; Coordinate record
X EQU (BYTE PTR 0)
Y EQU (BYTE PTR 1)
; BIOS workspace equates
CrtMode EQU (BYTE PTR 49H)
CrtWidth EQU (BYTE PTR 4AH)
DATA SEGMENT WORD PUBLIC
; Externals from CRT unit
EXTRN CheckSnow:BYTE,WindMin:WORD,WindMax:WORD
DATA ENDS
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE,DS:DATA
; procedure WriteStr(X, Y: Byte; S: String; Attr: Byte);
PUBLIC WriteStr
WriteStr:
PUSH BP
MOV BP,SP
LES BX,[BP+8]
MOV CL,ES:[BX]
MOV SI,OFFSET CS:CrtWriteStr
CALL CrtWrite
POP BP
RETF 10
; procedure WriteChar(X, Y, Count: Byte; Ch: Char; Attr: Byte);
PUBLIC WriteChar
WriteChar:
PUSH BP
MOV BP,SP
MOV CL,[BP+10]
MOV SI,OFFSET CS:CrtWriteChar
CALL CrtWrite
POP BP
RETF 10
; procedure FillWin(Ch: Char; Attr: Byte);
PUBLIC FillWin
FillWin:
MOV SI,OFFSET CS:CrtWriteChar
JMP SHORT CommonWin
; procedure ReadWin(var Buf);
PUBLIC ReadWin
ReadWin:
MOV SI,OFFSET CS:CrtReadWin
JMP SHORT CommonWin
; procedure WriteWin(var Buf);
PUBLIC WriteWin
WriteWin:
MOV SI,OFFSET CS:CrtWriteWin
; Common FillWin/ReadWin/WriteWin routine
CommonWin:
PUSH BP
MOV BP,SP
XOR CX,CX
MOV DX,WindMin
MOV CL,WindMax.X
SUB CL,DL
INC CX
@@1: PUSH CX
PUSH DX
PUSH SI
CALL CrtBlock
POP SI
POP DX
POP CX
INC DH
CMP DH,WindMax.Y
JBE @@1
POP BP
RETF 4
; Write string to screen
CrtWriteStr:
PUSH DS
MOV AH,[BP+6]
LDS SI,[BP+8]
INC SI
JC @@4
@@1: LODSB
MOV BX,AX
@@2: IN AL,DX
TEST AL,1
JNE @@2
CLI
@@3: IN AL,DX
TEST AL,1
JE @@3
MOV AX,BX
STOSW
STI
LOOP @@1
POP DS
RET
@@4: LODSB
STOSW
LOOP @@4
POP DS
RET
; Write characters to screen
CrtWriteChar:
MOV AL,[BP+8]
MOV AH,[BP+6]
JC @@4
MOV BX,AX
@@1: IN AL,DX
TEST AL,1
JNE @@1
CLI
@@2: IN AL,DX
TEST AL,1
JE @@2
MOV AX,BX
STOSW
STI
LOOP @@1
RET
@@4: REP STOSW
RET
; Read window buffer from screen
CrtReadWin:
PUSH DS
PUSH ES
POP DS
MOV SI,DI
LES DI,[BP+6]
CALL CrtCopyWin
MOV [BP+6],DI
POP DS
RET
; Write window buffer to screen
CrtWriteWin:
PUSH DS
LDS SI,[BP+6]
CALL CrtCopyWin
MOV [BP+6],SI
POP DS
RET
; Window buffer copy routine
CrtCopyWin:
JC @@4
@@1: LODSW
MOV BX,AX
@@2: IN AL,DX
TEST AL,1
JNE @@2
CLI
@@3: IN AL,DX
TEST AL,1
JE @@3
MOV AX,BX
STOSW
STI
LOOP @@1
RET
@@4: REP MOVSW
RET
; Do screen operation
; In CL = Buffer length
; SI = Write procedure pointer
; BP = Stack frame pointer
CrtWrite:
MOV DL,[BP+14]
DEC DL
ADD DL,WindMin.X
JC CrtExit
CMP DL,WindMax.X
JA CrtExit
MOV DH,[BP+12]
DEC DH
ADD DH,WindMin.Y
JC CrtExit
CMP DH,WindMax.Y
JA CrtExit
XOR CH,CH
JCXZ CrtExit
MOV AL,WindMax.X
SUB AL,DL
INC AL
CMP CL,AL
JB CrtBlock
MOV CL,AL
; Do screen operation
; In CL = Buffer length
; DX = CRT coordinates
; SI = Procedure pointer
CrtBlock:
MOV AX,40H
MOV ES,AX
MOV AL,DH
MUL ES:CrtWidth
XOR DH,DH
ADD AX,DX
SHL AX,1
MOV DI,AX
MOV AX,0B800H
CMP ES:CrtMode,7
JNE @@1
MOV AH,0B0H
@@1: MOV ES,AX
MOV DX,03DAH
CLD
CMP CheckSnow,1
JMP SI
; Exit from screen operation
CrtExit:
RET
; function WinSize: Word;
PUBLIC WinSize
WinSize:
MOV AX,WindMax
SUB AX,WindMin
ADD AX,101H
MUL AH
SHL AX,1
RETF
CODE ENDS
END