-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImgVx86.asm
286 lines (254 loc) · 4.96 KB
/
ImgVx86.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
285
; ImgVx86 - DOS image/photo viwer, Version 1.0
; Copyright 1998-2003 ardeshirv@protonmail.com, Licensed under GPLv3+
Title "ImgVx86"
.8086
SegmentGraphic SEGMENT AT 0A000h
bytScreen db 64000 dup(?)
SegmentGraphic ENDS
CodeSeg SEGMENT PARA PUBLIC 'CODE'
ASSUME cs:CodeSeg, ds:CodeSeg, es:CodeSeg, ss:CodeSeg
ORG 100h
;-----------------------------------------------------------------------;
; Main Entry Point ;
;-----------------------------------------------------------------------;
Main PROC NEAR
call ClearScreen
; Init Graphic Mode
mov ax, 0013h
int 10h
call UpdatePalette
; Read First Command Line Argument
mov dx, 82h
mov di, dx
mov ax, 13
mov cx, 80
repne scasb
mov BYTE PTR [di - 1], ah
call DrawImage
call WaitKeyPress
; Restore Graphic Mode
mov ax, 0002h
int 10h
ret
Main ENDP
;-----------------------------------------------------------------------;
; WriteStr(SI(StringZ)) ;
;-----------------------------------------------------------------------;
;WriteStr PROC NEAR
; push ax
; push bx
; push si
; pushf
; mov ah, 14
; xor bh, bh
; cld
;WSLoop: lodsb
; or al, al
; jz WSEnd
; int 10h
; jmp WSLoop
;WSEnd: popf
; pop si
; pop bx
; pop ax
; ret
;WriteStr ENDP
;-----------------------------------------------------------------------;
; DrawImage(DX(strFileNameZ)) ;
; Read Image file from file and draw on screen. ;
;-----------------------------------------------------------------------;
DrawImage PROC NEAR
push ax
push bx
push cx
push dx
push si
push di
push bp
pushf
; Open File
mov ax, 03D00h
int 21h
mov wrdFileHandler, ax
jc diFileOpenErr
sub cx, cx
mDrawCol: sub dx, dx
mLoadNext: mov si, dx
mov bp, cx
; Read File
mov ah, 03Fh
mov bx, wrdFileHandler
mov cx, 100
mov dx, 81h
int 21h
jc diFileReadErr
; Draw pixel
mov cx, bp
mov dx, si
mov ah, 0ch
mov bx, 81h
mDrawAgain: mov di, cx
mov cl, 2
mov al, [bx]
shr al, cl
sub al, 03
mov cx, di
int 10h
inc bx
inc dx
cmp dx, 100
je mLoadNext
cmp dx, 200
jne mDrawAgain
inc cx
cmp cx, 320
jne mDrawCol
; Close File
mov bx, wrdFileHandler
mov ah, 03Eh
int 21h
jc diFileCloseErr
; Error Handlers
jmp diEndNormaly
diFileOpenErr: ;mov si, OFFSET strFileOpenErr
;call WriteStr
;int 20h
;jmp diEndNormaly
diFileCloseErr: ;mov si, OFFSET strFileCloseErr
;call WriteStr
;jmp diEndNormaly
diFileReadErr: ;mov si, OFFSET strFileReadErr
;call WriteStr
int 20h
diEndNormaly: popf
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
DrawImage ENDP
;-----------------------------------------------------------------------;
; WaitKeyPress - Wait for key press. ;
;-----------------------------------------------------------------------;
WaitKeyPress PROC NEAR
push ax
sub ah, ah
int 16h
pop ax
ret
WaitKeyPress ENDP
;-----------------------------------------------------------------------;
; UpdatePalette ;
;-----------------------------------------------------------------------;
UpdatePalette PROC Near
push ax
push bx
push cx
push dx
mov ax, 1012h
xor bx, bx
mov cx, End_Palette - bytPalette
mov dx, OFFSET bytPalette
int 10h
pop dx
pop cx
pop bx
pop ax
ret
UpdatePalette ENDP
;-----------------------------------------------------------------------;
; CleanScreen - Clear Screen Monitor. ;
;-----------------------------------------------------------------------;
ClearScreen PROC NEAR
push ax
push bx
push cx
push dx
pushf
xor cx, cx
mov bh, 07h
mov ax, 0600h
mov dx, 0184Fh
int 10h
popf
pop dx
pop cx
pop bx
pop ax
ret
ClearScreen ENDP
;-----------------------------------------------------------------------;
; Data Defination: ;
;-----------------------------------------------------------------------;
wrdFileHandler dw 0
;strFileName db "Image.img", 0
;strFileOpenErr db "File open failed.", 0Dh, 0Ah, 0
;strFileCloseErr db "File close failed.", 0Dh, 0Ah, 0
;strFileReadErr db "Read from file failed.", 0Dh, 0Ah, 0
bytPalette db 01, 0, 0
db 02, 0, 0
db 03, 0, 0
db 04, 0, 0
db 05, 0, 0
db 06, 0, 0
db 07, 0, 0
db 08, 0, 0
db 09, 0, 0
db 10, 0, 0
db 11, 0, 0
db 12, 0, 0
db 13, 0, 0
db 14, 0, 0
db 15, 0, 0
db 16, 0, 0
db 17, 0, 0
db 18, 0, 0
db 19, 0, 0
db 20, 0, 0
db 21, 0, 0
db 22, 0, 0
db 23, 0, 0
db 24, 0, 0
db 25, 0, 0
db 26, 0, 0
db 27, 0, 0
db 28, 0, 0
db 29, 0, 0
db 31, 0, 0
db 32, 0, 0
db 33, 0, 0
db 34, 0, 0
db 35, 0, 0
db 36, 0, 0
db 37, 0, 0
db 38, 0, 0
db 39, 0, 0
db 40, 0, 0
db 41, 0, 0
db 42, 0, 0
db 43, 0, 0
db 44, 0, 0
db 45, 0, 0
db 46, 0, 0
db 47, 0, 0
db 48, 0, 0
db 49, 0, 0
db 51, 0, 0
db 52, 0, 0
db 53, 0, 0
db 54, 0, 0
db 55, 0, 0
db 56, 0, 0
db 57, 0, 0
db 58, 0, 0
db 59, 0, 0
db 60, 0, 0
db 61, 0, 0
db 62, 0, 0
db 63, 0, 0
End_Palette:
CodeSeg ENDS
END Main