Rev 195 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; IMGVIEW.ASM |
2 | ; |
||
3 | ; This program displays jpeg images. The window can be resized. |
||
4 | ; |
||
5 | ; Version 0.0 END OF 2003 |
||
6 | ; Octavio Vega |
||
7 | ; Version 0.1 7th March 2004 |
||
8 | ; Mike Hibbett ( very small part! ) |
||
9 | ; Version 0.11 7th April 2004 |
||
10 | ; Ville Turjanmaa ( 'set_as_bgr' function ) |
||
11 | ; Version 0.12 29th May 2004 |
||
12 | ; Ivan Poddubny (correct "set_as_bgr"+parameters+boot+...) |
||
13 | ; Version 0.12 30 de mayo 2004 |
||
14 | ; Octavio Vega |
||
15 | ; bugs correction and slideshow |
||
16 | ; version 0.13 3 de junio 2004 |
||
17 | ; Octavio Vega |
||
18 | ; unos retoques |
||
19 | ; version 0.14 10th August 2004 |
||
20 | ; Mike Hibbett Added setting default colours |
||
135 | diamond | 21 | ; version 0.15 24th August 2006 |
22 | ; diamond (rewritten to function 70) |
||
31 | halyavin | 23 | ; |
135 | diamond | 24 | |
31 | halyavin | 25 | memsize=20000h |
26 | org 0 |
||
27 | PARAMS = memsize - 1024 |
||
28 | |||
180 | heavyiron | 29 | appname equ 'Jpegview ' |
30 | version equ '0.15' |
||
31 | |||
31 | halyavin | 32 | use32 |
33 | |||
34 | db 'MENUET01' ; 8 byte id |
||
35 | dd 0x01 ; header version |
||
36 | dd START ; start of code |
||
37 | dd I_END ; size of image |
||
38 | dd memsize ; memory for app |
||
39 | dd memsize - 1024 ; esp |
||
40 | dd PARAMS , 0x0 ; I_Param , I_Icon |
||
41 | |||
42 | stack_size=4096 + 1024 |
||
43 | |||
132 | diamond | 44 | include 'macros.inc' |
31 | halyavin | 45 | |
46 | START: ; start of execution |
||
47 | |||
48 | cmp [PARAMS], byte 0 |
||
49 | jne check_parameters |
||
50 | |||
51 | ; Calculate the 'free' memory available |
||
52 | ; to the application, and create the malloc block from it |
||
53 | .l1: |
||
54 | mov ecx,memsize-fin-stack_size |
||
55 | mov edi,fin |
||
56 | call add_mem |
||
57 | |||
58 | call colorprecalc ;inicializa tablas usadas para pasar de ybr a bgr |
||
59 | call draw_window |
||
60 | call read_string.rs_done |
||
61 | |||
62 | still: |
||
63 | push still |
||
64 | mov ebx,100 ;1 second |
||
65 | mov eax,23 ; wait here for event |
||
66 | int 0x40 |
||
67 | cmp eax,1 ; redraw request ? |
||
68 | je draw_window |
||
69 | cmp eax,2 ; key in buffer ? |
||
70 | je read_string |
||
71 | cmp eax,3 ; button in buffer ? |
||
72 | je button |
||
73 | jmp display_next |
||
74 | |||
75 | button: ; BUTTON |
||
76 | mov eax,17 |
||
77 | int 0x40 |
||
78 | cmp ah,3 |
||
79 | je set_as_bgr2 |
||
80 | cmp ah,2 |
||
81 | je slideshow |
||
82 | cmp ah,1 ; CLOSE PROGRAM |
||
83 | jne close_program.exit |
||
84 | close_program: |
||
85 | mov eax,-1 |
||
86 | int 0x40 |
||
87 | .exit: |
||
88 | ret |
||
89 | |||
90 | ; Put a 'chunk' of the image on the window |
||
91 | put_image: |
||
92 | pushad |
||
93 | |||
94 | lea ebp,[edx+eax+7] |
||
95 | cmp [winxs],bp |
||
96 | jc .l1 |
||
97 | lea ebp,[ecx+ebx+20+2+17] |
||
98 | cmp [winys],bp |
||
99 | jc .l1 |
||
100 | |||
195 | heavyiron | 101 | add eax,2 ; offset for boarder |
102 | add ebx,2 ; offset for title bar |
||
31 | halyavin | 103 | push ax ; pox |
104 | push bx ; pos |
||
105 | push cx ; size |
||
106 | push dx ; size |
||
107 | pop ecx |
||
108 | pop edx |
||
109 | mov ebx,edi |
||
110 | mov eax,7 |
||
111 | |||
112 | int 40h ; Put image function |
||
113 | .l1: |
||
114 | popad |
||
115 | ret |
||
116 | |||
117 | |||
118 | |||
119 | ;****************************************************************************** |
||
120 | |||
121 | check_parameters: |
||
122 | cmp [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler |
||
123 | je boot_set_background |
||
124 | |||
125 | mov edi, name_string ; clear string with file name |
||
126 | mov al, 0 |
||
127 | mov ecx, 100 |
||
128 | rep stosb |
||
129 | |||
130 | mov ecx, 100 ; calculate length of parameter string |
||
131 | mov edi, PARAMS |
||
132 | repne scasb |
||
133 | sub edi, PARAMS |
||
134 | mov ecx, edi |
||
135 | |||
136 | mov esi, PARAMS ; copy parameters to file name |
||
137 | mov edi, name_string |
||
138 | cld |
||
139 | rep movsb |
||
140 | |||
141 | jmp START.l1 ; return to beggining of the progra |
||
142 | |||
143 | ;****************************************************************************** |
||
144 | |||
145 | |||
146 | |||
147 | boot_set_background: |
||
148 | |||
149 | mov ecx,memsize-fin-stack_size ; size |
||
150 | mov edi,fin ; pointer |
||
151 | call add_mem ; mark memory from fin to 0x100000-1024 as free |
||
152 | call colorprecalc ; calculate colors |
||
153 | mov esi,name_string |
||
154 | call open |
||
155 | test eax,eax |
||
156 | jz close_program |
||
157 | call jpeg_info |
||
158 | mov dword [jpeg_st],ebp |
||
159 | call set_as_bgr2 ; set wallpaper |
||
160 | jmp close_program ; close the program right now |
||
161 | |||
162 | ;****************************************************************************** |
||
163 | ;****************************************************************************** |
||
164 | |||
165 | set_as_bgr2: |
||
166 | mov ebp,dword[jpeg_st] |
||
167 | test ebp,ebp |
||
168 | jz .end |
||
470 | serge | 169 | |
31 | halyavin | 170 | mov eax, 15 |
171 | mov ebx, 1 |
||
172 | mov ecx, [ebp + x_size] |
||
173 | mov edx, [ebp + y_size] |
||
174 | int 0x40 |
||
175 | |||
470 | serge | 176 | mov dword [ebp+draw_ptr],put_chunk_to_bgr |
177 | call jpeg_display |
||
178 | |||
31 | halyavin | 179 | ; Stretch the image to fit |
180 | mov eax, 15 |
||
181 | mov ebx, 4 |
||
182 | mov ecx, 2 |
||
183 | int 0x40 |
||
184 | |||
185 | mov eax, 15 |
||
186 | mov ebx, 3 |
||
187 | int 0x40 |
||
188 | |||
189 | |||
190 | .end: |
||
191 | ret |
||
192 | |||
193 | ;****************************************************************************** |
||
194 | |||
195 | put_chunk_to_bgr: |
||
196 | pushad |
||
197 | |||
198 | mov [x_pointer], edi |
||
199 | mov esi, ecx |
||
200 | imul esi, 3 |
||
201 | mov [x_numofbytes], esi |
||
202 | mov ecx, [ebp + x_size] |
||
203 | imul ecx, ebx |
||
204 | add ecx, eax |
||
205 | imul ecx, 3 |
||
206 | mov [x_offset], ecx |
||
207 | mov [x_counter], edx |
||
208 | mov eax, [ebp + x_size] |
||
209 | imul eax, 3 |
||
210 | mov [x_numofb2], eax |
||
211 | .new_string: |
||
212 | mov eax, 15 |
||
213 | mov ebx, 5 |
||
214 | mov ecx, [x_pointer] |
||
215 | mov edx, [x_offset] |
||
216 | mov esi, [x_numofbytes] |
||
217 | int 0x40 |
||
218 | mov eax, [x_numofbytes] |
||
219 | add [x_pointer], eax |
||
220 | mov eax, [x_numofb2] |
||
221 | add [x_offset], eax |
||
222 | dec [x_counter] |
||
223 | jnz .new_string |
||
224 | |||
225 | popad |
||
226 | ret |
||
227 | |||
228 | ;****************************************************************************** |
||
229 | |||
230 | |||
231 | |||
232 | ; ********************************************* |
||
233 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
234 | ; ********************************************* |
||
235 | |||
236 | |||
237 | draw_window: |
||
238 | |||
195 | heavyiron | 239 | mov eax,48 |
240 | mov ebx,3 |
||
241 | mov ecx,sc |
||
242 | mov edx,sizeof.system_colors |
||
243 | int 0x40 |
||
244 | |||
31 | halyavin | 245 | mov eax,12 |
246 | mov ebx,1 |
||
247 | int 0x40 |
||
248 | |||
249 | ; Draw the window to the appropriate size - it may have |
||
250 | ; been resized by the user |
||
135 | diamond | 251 | cmp [winxs], 0 |
31 | halyavin | 252 | jne dw_001 |
253 | |||
254 | ; Give the screen some inital defaults |
||
135 | diamond | 255 | mov [winxs], 400 |
256 | mov [winys], 300 |
||
31 | halyavin | 257 | mov ax, 100 |
258 | mov [winxo], ax |
||
259 | mov [winyo], ax |
||
260 | jmp dw_002 |
||
261 | |||
262 | dw_001: |
||
263 | mov eax, 9 |
||
264 | mov ebx, memsize - 1024 |
||
265 | mov ecx, -1 |
||
266 | int 0x40 |
||
267 | mov eax, [ebx + 34] |
||
268 | mov [winxo], ax |
||
269 | mov eax, [ebx + 38] |
||
270 | mov [winyo], ax |
||
271 | mov eax, [ebx + 42] |
||
272 | mov [winxs], ax |
||
273 | mov eax, [ebx + 46] |
||
274 | mov [winys], ax |
||
275 | |||
276 | dw_002: |
||
135 | diamond | 277 | mov ebx, dword [winxo-2] |
278 | mov bx, [winxs] |
||
279 | mov ecx, dword [winyo-2] |
||
280 | mov cx, [winys] |
||
31 | halyavin | 281 | |
135 | diamond | 282 | xor eax,eax ; DRAW WINDOW |
195 | heavyiron | 283 | mov edx,[sc.work] |
284 | or edx,0x33000000 |
||
180 | heavyiron | 285 | mov edi,header ; WINDOW LABEL |
31 | halyavin | 286 | int 0x40 |
287 | |||
288 | |||
195 | heavyiron | 289 | mov eax,8 ; BUTTON 2: slideshow |
290 | mov ebx,57 |
||
31 | halyavin | 291 | mov cx, [winys] |
195 | heavyiron | 292 | sub cx, 39 |
31 | halyavin | 293 | shl ecx, 16 |
294 | add ecx, 12 |
||
195 | heavyiron | 295 | mov esi, [sc.work_button] |
31 | halyavin | 296 | mov edx,2 |
297 | int 0x40 |
||
298 | |||
299 | mov eax,4 ; Button text |
||
300 | movzx ebx, word [winys] |
||
195 | heavyiron | 301 | add ebx, 3 shl 16 - 36 |
302 | mov ecx,[sc.work_button_text] |
||
31 | halyavin | 303 | mov edx,setname |
304 | mov esi,setnamelen-setname |
||
305 | int 0x40 |
||
306 | |||
307 | |||
308 | mov eax,8 ; BUTTON 3: set as background |
||
309 | mov bx, [winxs] |
||
195 | heavyiron | 310 | sub bx, 65 |
31 | halyavin | 311 | shl ebx, 16 |
312 | mov bx,55 |
||
313 | mov cx, [winys] |
||
195 | heavyiron | 314 | sub cx, 39 |
31 | halyavin | 315 | shl ecx, 16 |
316 | add ecx, 12 |
||
195 | heavyiron | 317 | mov esi, [sc.work_button] |
31 | halyavin | 318 | mov edx,3 |
319 | int 0x40 |
||
320 | |||
321 | mov eax,4 ; Button text |
||
322 | movzx ebx, word [winxs] |
||
195 | heavyiron | 323 | sub ebx, 63 |
31 | halyavin | 324 | shl ebx,16 |
325 | mov bx, word [winys] |
||
195 | heavyiron | 326 | sub bx,36 |
327 | mov ecx,[sc.work_button_text] |
||
31 | halyavin | 328 | mov edx,setbgr |
329 | mov esi,setbgrlen-setbgr |
||
330 | int 0x40 |
||
331 | call print_strings |
||
332 | call load_image |
||
333 | mov eax,12 ; function 12:tell os about windowdraw |
||
334 | mov ebx,2 ; 2, end of draw |
||
335 | int 0x40 |
||
336 | |||
337 | ret |
||
338 | |||
339 | |||
340 | |||
341 | ; Read in the image file name. |
||
342 | read_string: |
||
343 | movzx edi,byte[name_string.cursor] |
||
344 | add edi,name_string |
||
345 | mov eax,2 |
||
346 | int 0x40 ; Get the key value |
||
347 | shr eax,8 |
||
348 | cmp eax,13 ; Return key ends input |
||
349 | je .rs_done |
||
350 | cmp eax,8 |
||
351 | jnz .nobsl |
||
352 | cmp edi,name_string |
||
353 | je .exit |
||
354 | dec edi |
||
355 | mov [edi],byte 0;'_' |
||
356 | dec byte[name_string.cursor] |
||
357 | jmp print_strings |
||
358 | .exit: ret |
||
359 | .nobsl: |
||
360 | cmp eax,31 |
||
361 | jbe .exit |
||
362 | cmp eax,97 |
||
363 | jb .keyok |
||
364 | sub eax,32 |
||
365 | .keyok: |
||
366 | mov ah,0 |
||
367 | stosw |
||
368 | cmp edi,name_string.end |
||
369 | jnc print_strings |
||
370 | inc byte[name_string.cursor] |
||
371 | jmp print_strings |
||
372 | .rs_done: |
||
373 | call print_strings |
||
374 | mov esi,name_string |
||
375 | call open |
||
376 | test eax,eax |
||
377 | jz .exit |
||
378 | call jpeg_info |
||
379 | test ebp,ebp |
||
380 | jz close |
||
381 | xchg [jpeg_st],ebp |
||
382 | call jpeg_close |
||
383 | |||
384 | load_image: |
||
385 | |||
386 | mov eax,13 ; clear picture area |
||
387 | movzx ebx, word [winxs] |
||
195 | heavyiron | 388 | add ebx, 1 shl 16 -10 |
31 | halyavin | 389 | movzx ecx, word [winys] |
195 | heavyiron | 390 | sub ecx, 40 |
391 | add ecx, 1 shl 16 |
||
31 | halyavin | 392 | |
195 | heavyiron | 393 | mov edx,[sc.work] |
31 | halyavin | 394 | int 0x40 |
395 | mov ebp,[jpeg_st] |
||
396 | test ebp,ebp |
||
397 | jz .exit |
||
398 | mov dword [ebp+draw_ptr],put_image |
||
399 | jmp jpeg_display |
||
400 | .exit: ret |
||
401 | |||
402 | print_strings: |
||
403 | pusha |
||
404 | mov eax,13 ; clear text area |
||
405 | movzx ebx, word [winxs] |
||
195 | heavyiron | 406 | add ebx, 59 shl 16 -125 |
31 | halyavin | 407 | mov cx, [winys] |
195 | heavyiron | 408 | sub cx, 39 |
31 | halyavin | 409 | shl ecx, 16 |
410 | add ecx, 12 |
||
411 | mov edx,0xffffff |
||
412 | int 0x40 |
||
413 | |||
414 | mov eax,4 ; |
||
415 | movzx ebx, word [winys] |
||
195 | heavyiron | 416 | add ebx, 61 shl 16 - 37 |
31 | halyavin | 417 | mov ecx,0x000000 |
418 | mov edx,name_string |
||
419 | mov esi,60 |
||
420 | int 0x40 |
||
421 | popa |
||
422 | ret |
||
423 | |||
424 | slideshow: |
||
135 | diamond | 425 | cmp [file_dir], 0 |
426 | jnz .exit |
||
427 | cmp [jpeg_st], 0 |
||
428 | jz .exit |
||
429 | mov esi, name_string |
||
430 | movzx ecx, byte [name_string.cursor] |
||
431 | .l1: |
||
432 | cmp byte [esi+ecx], '/' |
||
433 | jz .l2 |
||
434 | loop .l1 |
||
435 | .exit: |
||
436 | ret |
||
437 | .l2: |
||
438 | mov byte [esi+ecx], 0 |
||
439 | call open |
||
440 | mov byte [esi+ecx], '/' |
||
441 | test eax, eax |
||
442 | jz .exit |
||
443 | test byte [fileattr], 0x10 |
||
444 | jz .exit |
||
445 | mov [file_dir], eax |
||
446 | inc ecx |
||
447 | mov [name_string.cursor], cl |
||
31 | halyavin | 448 | display_next: |
135 | diamond | 449 | mov ebx, [file_dir] |
450 | test ebx, ebx |
||
451 | jnz @f |
||
452 | ret |
||
453 | @@: |
||
454 | mov byte [ebx], 1 |
||
455 | mov byte [ebx+12], 1 |
||
456 | mov dword [ebx+16], dirinfo |
||
457 | mov eax, 70 |
||
458 | int 0x40 |
||
459 | mov eax, [file_dir] |
||
460 | inc dword [eax+4] |
||
461 | cmp ebx, 1 |
||
462 | jz @f |
||
463 | mov eax, [file_dir] |
||
464 | and [file_dir], 0 |
||
465 | jmp close |
||
466 | @@: |
||
467 | movzx edi, byte [name_string.cursor] |
||
468 | add edi, name_string |
||
469 | lea esi, [dirinfo+32+40] |
||
470 | @@: |
||
471 | lodsb |
||
472 | stosb |
||
473 | test al, al |
||
474 | jnz @b |
||
475 | mov ecx, name_string.end |
||
476 | sub ecx, edi |
||
477 | rep stosb |
||
31 | halyavin | 478 | call print_strings |
479 | mov esi,name_string |
||
480 | call open |
||
481 | test eax,eax |
||
482 | jz display_next |
||
483 | call jpeg_info |
||
484 | test ebp,ebp |
||
485 | jnz .l6 |
||
486 | call close |
||
487 | jmp display_next |
||
488 | .l6: |
||
489 | mov dword[ebp+draw_ptr],put_image |
||
490 | push ebp |
||
491 | xchg [jpeg_st],ebp |
||
492 | call jpeg_close |
||
493 | pop ebp |
||
494 | jmp jpeg_display |
||
495 | |||
496 | |||
497 | include 'filelib.asm' |
||
498 | include 'memlib.asm' |
||
499 | include 'jpeglib.asm' |
||
500 | |||
501 | |||
502 | ; DATA AREA |
||
503 | |||
504 | wcolor dd 0x000000 |
||
180 | heavyiron | 505 | header db appname,version,0 |
31 | halyavin | 506 | setname db 'SLIDESHOW' |
507 | setnamelen: |
||
508 | |||
509 | setbgr db ' BGR ' |
||
510 | setbgrlen: |
||
511 | |||
512 | x_pointer dd 0 |
||
513 | x_offset dd 0 |
||
514 | x_numofbytes dd 0 |
||
515 | x_numofb2 dd 0 |
||
516 | x_counter dd 0 |
||
135 | diamond | 517 | winxo dw 0 |
518 | winyo dw 0 |
||
519 | winxs dw 0 |
||
520 | winys dw 0 |
||
521 | jpeg_st dd 0 |
||
522 | file_dir dd 0 |
||
31 | halyavin | 523 | name_string: db '/rd/1/jpegview.jpg',0 |
135 | diamond | 524 | rb 256 |
31 | halyavin | 525 | .end: |
526 | .cursor: db 19 |
||
527 | .cursor2: db 0 |
||
528 | |||
529 | align 4 |
||
530 | |||
531 | rgb16: db 0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63 |
||
532 | rgb4: db 0,21,42,63 |
||
533 | |||
534 | include 'jpegdat.asm' |
||
535 | |||
536 | align 4 |
||
537 | |||
538 | iniciomemoria: |
||
539 | dd -(iniciomemoria+4),-(iniciomemoria+4),(iniciomemoria+4),.l1,0 |
||
540 | .l1 dd 0 |
||
541 | |||
542 | fin: |
||
543 | I_END: |
||
195 | heavyiron | 544 | sc system_colors |
135 | diamond | 545 | fileattr: rb 40 |
546 | dirinfo: rb 32+304 |