-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflat3.asm
234 lines (188 loc) · 3.6 KB
/
flat3.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
include flat3.inc
include sys.inc
SHIFT_CONST equ 12
.model tiny
.code
.386
org 100h
flat_triangle proc
@@x1 equ word ptr [bp+4]
@@y1 equ word ptr [bp+6]
@@x2 equ word ptr [bp+8]
@@y2 equ word ptr [bp+10]
@@x3 equ word ptr [bp+12]
@@y3 equ word ptr [bp+14]
@@col equ word ptr [bp+16]
@@dx12 equ dword ptr [bp-4]
@@dx13 equ dword ptr [bp-8]
@@dx23 equ dword ptr [bp-12]
push bp
mov bp, sp
sub sp, 12
push es
mov es, buffer_seg
mov ax, @@y1
cmp ax, @@y3
jle ft_check1
xchg ax, @@y3
mov @@y1, ax
mov ax, @@x1
xchg ax, @@x3
mov @@x1, ax
ft_check1:
mov ax, @@y2
cmp ax, @@y3
jle ft_check2
xchg ax, @@y3
mov @@y2, ax
mov ax, @@x2
xchg ax, @@x3
mov @@x2, ax
ft_check2:
mov ax, @@y1
cmp ax, @@y2
jle ft_check3
xchg ax, @@y2
mov @@y1, ax
mov ax, @@x1
xchg ax, @@x2
mov @@x1, ax
ft_check3:
mov bx, @@y2
sub bx, @@y1
jnz ft_dx12_make
mov @@dx12, 0
jmp ft_dx12_done
ft_dx12_make:
mov ax, @@x2
sub ax, @@x1
movsx eax, ax
movsx ebx, bx
shl eax, SHIFT_CONST
cdq
idiv ebx
mov @@dx12, eax
ft_dx12_done:
mov bx, @@y3
sub bx, @@y1
jnz ft_dx13_make
mov @@dx13, 0
jmp ft_dx13_done
ft_dx13_make:
mov ax, @@x3
sub ax, @@x1
movsx eax, ax
movsx ebx, bx
shl eax, SHIFT_CONST
cdq
idiv ebx
mov @@dx13, eax
ft_dx13_done:
mov bx, @@y3
sub bx, @@y2
jnz ft_dx23_make
mov @@dx23, 0
jmp ft_dx23_done
ft_dx23_make:
mov ax, @@x3
sub ax, @@x2
movsx eax, ax
movsx ebx, bx
shl eax, SHIFT_CONST
cdq
idiv ebx
mov @@dx23, eax
ft_dx23_done:
movsx eax, @@x1
shl eax, SHIFT_CONST
mov ebx, eax
mov cx, @@y1
cmp cx, @@y2
jge ft_loop1_end
ft_loop1:
push eax
push cx
push @@col
push cx
mov edx, ebx
sar edx, SHIFT_CONST
push dx
sar eax, SHIFT_CONST
push ax
call flat_line
pop cx
pop eax
add eax, @@dx13
add ebx, @@dx12
inc cx
cmp cx, @@y2
jl ft_loop1
ft_loop1_end:
movsx ebx, @@x2
shl ebx, SHIFT_CONST
mov cx, @@y2
cmp cx, @@y3
jge ft_loop2_end
ft_loop2:
push eax
push cx
push @@col
push cx
mov edx, ebx
sar edx, SHIFT_CONST
push dx
sar eax, SHIFT_CONST
push ax
call flat_line
pop cx
pop eax
add eax, @@dx13
add ebx, @@dx23
inc cx
cmp cx, @@y3
jl ft_loop2
ft_loop2_end:
pop es
mov sp, bp
pop bp
ret 14
endp
flat_line proc
@@x1 equ word ptr [bp+4]
@@x2 equ word ptr [bp+6]
@@y equ word ptr [bp+8]
@@col equ word ptr [bp+10]
push bp
mov bp, sp
mov ax, @@y
or ax, ax
jl fl_quit
cmp ax, 199
jg fl_quit
mov ax, @@x1
cmp ax, @@x2
je fl_quit
jl fl_ok
xchg ax, @@x2
mov @@x1, ax
fl_ok:
mov di, @@y
mov ax, di
shl di, 6
shl ax, 8
add di, ax
add di, @@x1
mov ax, @@col
mov ah, al
mov cx, @@x2
sub cx, @@x1
shr cx, 1
jnc fl_draw
stosb
fl_draw:
rep stosw
fl_quit:
pop bp
ret 8
endp
end