Subversion Repositories Kolibri OS

Rev

Rev 547 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 547 Rev 606
1
;    IMGVIEW.ASM
1
;    IMGVIEW.ASM
2
;
2
;
3
;    This program displays jpeg images. The window can be resized.
3
;    This program displays jpeg images. The window can be resized.
4
;
4
;
5
;    Version 0.0    END OF 2003
5
;    Version 0.0    END OF 2003
6
;                   Octavio Vega
6
;                   Octavio Vega
7
;    Version 0.1    7th March 2004
7
;    Version 0.1    7th March 2004
8
;                   Mike Hibbett ( very small part! )
8
;                   Mike Hibbett ( very small part! )
9
;    Version 0.11   7th April 2004
9
;    Version 0.11   7th April 2004
10
;                   Ville Turjanmaa ( 'set_as_bgr' function )
10
;                   Ville Turjanmaa ( 'set_as_bgr' function )
11
;    Version 0.12   29th May 2004
11
;    Version 0.12   29th May 2004
12
;                   Ivan Poddubny (correct "set_as_bgr"+parameters+boot+...)
12
;                   Ivan Poddubny (correct "set_as_bgr"+parameters+boot+...)
13
;    Version 0.12   30 de mayo 2004
13
;    Version 0.12   30 de mayo 2004
14
;                   Octavio Vega
14
;                   Octavio Vega
15
;                   bugs correction and slideshow
15
;                   bugs correction and slideshow
16
;    version 0.13   3 de junio 2004
16
;    version 0.13   3 de junio 2004
17
;                   Octavio Vega
17
;                   Octavio Vega
18
;                   unos retoques
18
;                   unos retoques
19
;    version 0.14   10th August 2004
19
;    version 0.14   10th August 2004
20
;                   Mike Hibbett Added setting default colours
20
;                   Mike Hibbett Added setting default colours
21
;    version 0.15   24th August 2006
21
;    version 0.15   24th August 2006
22
;                   diamond (rewritten to function 70)
22
;                   diamond (rewritten to function 70)
23
;    version 0.16   19th May 2007
23
;    version 0.16   19th May 2007
24
;                   Mario79
24
;                   Mario79
25
;                   1) correction for changed function 15,
25
;                   1) correction for changed function 15,
26
;                   2) use monochrome background if free memory there are less than 2 MB
26
;                   2) use monochrome background if free memory there are less than 2 MB
27
;                   3) use COL0 - COL9 boot parameter
27
;                   3) use COL0 - COL9 boot parameter
28
;                   0=black,1=white,2=green,3=lilas,4=grey
28
;                   0=black,1=white,2=green,3=lilas,4=grey
29
;                   5=light-blue,6=blue,7=salad,8=pink,9=yellow
29
;                   5=light-blue,6=blue,7=salad,8=pink,9=yellow
30
;    version 0.17   17th June 2007
30
;    version 0.17   17th June 2007
31
;                   diamond (background definition now uses shared memory)
31
;                   diamond (background definition now uses shared memory)
-
 
32
;    version 0.18   9th August 2007
-
 
33
;                   Mario79
-
 
34
;                   Open file with parameter in patch:
-
 
35
;                   Size of parameter - 4 bytes. Parameter starts with the character "\",
-
 
36
;                   the unused characters are filled by a blank (ASCII 20h).
-
 
37
;                   '\T  /hd0/1/1.jpg' - set background, mode: tile
-
 
38
;                   '\S  /hd0/1/1.jpg' - set background, mode: stretch
32
                  
39
                  
33
               memsize=20000h
40
               memsize=20000h
34
               org 0
41
               org 0
35
 PARAMS     =    memsize - 1024
42
 PARAMS     =    memsize - 1024
36
 
43
 
37
appname equ 'Jpegview '
44
appname equ 'Jpegview '
38
version equ '0.17'
45
version equ '0.18'
39
 
46
 
40
use32
47
use32
41
 
48
 
42
               db     'MENUET01'              ; 8 byte id
49
               db     'MENUET01'              ; 8 byte id
43
               dd     0x01                    ; header version
50
               dd     0x01                    ; header version
44
               dd     START                   ; start of code
51
               dd     START                   ; start of code
45
               dd     I_END                   ; size of image
52
               dd     I_END                   ; size of image
46
               dd     memsize                 ; memory for app
53
               dd     memsize                 ; memory for app
47
               dd     memsize - 1024           ; esp
54
               dd     memsize - 1024           ; esp
48
               dd     PARAMS , 0x0               ; I_Param , I_Icon
55
               dd     PARAMS , 0x0               ; I_Param , I_Icon
49
 
56
 
50
stack_size=4096 + 1024
57
stack_size=4096 + 1024
51
 
58
 
52
include '..\..\..\macros.inc'
59
include '..\..\..\macros.inc'
53
 
60
 
54
START:                          ; start of execution
61
START:                          ; start of execution
55
        mcall   68,11           ; initialize heap
62
        mcall   68,11           ; initialize heap
56
 
63
 
57
    cmp     [PARAMS], byte 0
64
    cmp     [PARAMS], byte 0
58
    jne     check_parameters
65
    jne     check_parameters
59
 
66
 
60
    ; Calculate the 'free' memory available
67
    ; Calculate the 'free' memory available
61
    ; to the application, and create the malloc block from it
68
    ; to the application, and create the malloc block from it
62
  .l1:
69
  .l1:
63
    mov     ecx,memsize-fin-stack_size
70
    mov     ecx,memsize-fin-stack_size
64
    mov     edi,fin
71
    mov     edi,fin
65
    call    add_mem
72
    call    add_mem
66
 
73
 
67
    call    colorprecalc ;inicializa tablas usadas para pasar de ybr a bgr
74
    call    colorprecalc ;inicializa tablas usadas para pasar de ybr a bgr
68
    call    draw_window
75
    call    draw_window
69
    call    read_string.rs_done
76
    call    read_string.rs_done
70
 
77
 
71
still:
78
still:
72
    push still
79
    push still
73
    mov ebx,100                ;1 second
80
    mov ebx,100                ;1 second
74
    mov  eax,23                 ; wait here for event
81
    mov  eax,23                 ; wait here for event
75
    mcall
82
    mcall
76
    cmp  eax,1                  ; redraw request ?
83
    cmp  eax,1                  ; redraw request ?
77
    je   draw_window
84
    je   draw_window
78
    cmp  eax,2                  ; key in buffer ?
85
    cmp  eax,2                  ; key in buffer ?
79
    je   read_string
86
    je   read_string
80
    cmp  eax,3                  ; button in buffer ?
87
    cmp  eax,3                  ; button in buffer ?
81
    je   button
88
    je   button
82
    jmp display_next
89
    jmp display_next
83
 
90
 
84
button:                       ; BUTTON
91
button:                       ; BUTTON
85
    mov  eax,17
92
    mov  eax,17
86
    mcall
93
    mcall
87
    cmp ah,3
94
    cmp ah,3
88
    je set_as_bgr2
95
    je set_as_bgr2
89
    cmp ah,2
96
    cmp ah,2
90
    je slideshow
97
    je slideshow
91
    cmp  ah,1                   ; CLOSE PROGRAM
98
    cmp  ah,1                   ; CLOSE PROGRAM
92
    jne  close_program.exit
99
    jne  close_program.exit
93
close_program:
100
close_program:
94
    mov  eax,-1
101
    mov  eax,-1
95
    mcall
102
    mcall
96
  .exit:
103
  .exit:
97
    ret
104
    ret
98
 
105
 
99
   ; Put a 'chunk' of the image on the window
106
   ; Put a 'chunk' of the image on the window
100
put_image:
107
put_image:
101
    pushad
108
    pushad
102
 
109
 
103
    lea ebp,[edx+eax+7]
110
    lea ebp,[edx+eax+7]
104
    cmp  [winxs],bp
111
    cmp  [winxs],bp
105
    jc     .l1
112
    jc     .l1
106
    lea ebp,[ecx+ebx+20+2+17]
113
    lea ebp,[ecx+ebx+20+2+17]
107
    cmp [winys],bp
114
    cmp [winys],bp
108
    jc     .l1
115
    jc     .l1
109
 
116
 
110
    add     eax,2  ; offset for boarder
117
    add     eax,2  ; offset for boarder
111
    add     ebx,2 ; offset for title bar
118
    add     ebx,2 ; offset for title bar
112
    push    ax ; pox
119
    push    ax ; pox
113
    push    bx ; pos
120
    push    bx ; pos
114
    push    cx ; size
121
    push    cx ; size
115
    push    dx ; size
122
    push    dx ; size
116
    pop     ecx
123
    pop     ecx
117
    pop     edx
124
    pop     edx
118
    mov     ebx,edi
125
    mov     ebx,edi
119
    mov     eax,7
126
    mov     eax,7
120
 
127
 
121
    mcall                         ; Put image function
128
    mcall                         ; Put image function
122
.l1:
129
.l1:
123
    popad
130
    popad
124
    ret
131
    ret
125
 
132
 
126
 
133
 
127
 
134
 
128
;******************************************************************************
135
;******************************************************************************
129
 
136
 
130
check_parameters:
137
check_parameters:
131
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
138
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
132
    je      boot_set_background
139
    je      boot_set_background
133
    cmp     [PARAMS], word "CO"
140
    cmp     [PARAMS], word "CO"
134
    jne     @f
141
    jne     @f
135
    cmp     [PARAMS+2], byte "L"
142
    cmp     [PARAMS+2], byte "L"
136
    je      boot_set_background    
143
    je      boot_set_background    
137
@@:
144
@@:
-
 
145
    cmp     byte [PARAMS], "\"
-
 
146
    jne     @f
-
 
147
    cmp     [PARAMS+1], byte "S"
-
 
148
    jne     .tile
-
 
149
    mov     [drawing_mode],2
-
 
150
    jmp     @f
-
 
151
.tile:
-
 
152
    cmp     [PARAMS+1], byte "T"
-
 
153
    jne     @f
-
 
154
    mov     [drawing_mode],1
-
 
155
@@:
138
        cmp     byte [PARAMS], 1
156
    cmp     byte [PARAMS], 1
139
        jz      ipc_service
157
    jz      ipc_service
140
    mov     edi, name_string       ; clear string with file name
158
    mov     edi, name_string       ; clear string with file name
141
    mov     al,  0
159
    mov     al,  0
142
    mov     ecx, 100
160
    mov     ecx, 100
143
    rep     stosb
161
    rep     stosb
144
 
162
 
145
    mov     ecx, 100               ; calculate length of parameter string
163
    mov     ecx, 100               ; calculate length of parameter string
146
    mov     edi, PARAMS
164
    mov     edi, PARAMS
147
    repne   scasb
165
    repne   scasb
-
 
166
    
148
    sub     edi, PARAMS
167
    sub     edi, PARAMS
149
    mov     ecx, edi
168
    mov     ecx, edi
150
 
-
 
151
    mov     esi, PARAMS            ; copy parameters to file name
169
    mov     esi, PARAMS            ; copy parameters to file name
152
    mov     edi, name_string
170
    mov     edi, name_string
-
 
171
    cmp     byte [PARAMS], "\"
-
 
172
    jne     @f
-
 
173
    add     esi,4
-
 
174
    sub     ecx,4
-
 
175
@@:
153
    cld
176
    cld
154
    rep     movsb
177
    rep     movsb
-
 
178
 
155
 
179
    cmp     byte [PARAMS], "\"
-
 
180
    je      boot_set_background.1      
156
    jmp     START.l1       ; return to beggining of the progra
181
    
157
 
182
    jmp     START.l1       ; return to beggining of the progra
-
 
183
;******************************************************************************
-
 
184
boot_set_background:
158
;******************************************************************************
185
    mov     [drawing_mode],2
159
boot_set_background:
186
.1:
160
    mcall 18,16
187
    mcall 18,16
161
    cmp   eax,1024*2
188
    cmp   eax,1024*2
162
    jb    set_mono
189
    jb    set_mono
163
    mov     ecx,memsize-fin-stack_size  ; size
190
    mov     ecx,memsize-fin-stack_size  ; size
164
    mov     edi,fin                     ; pointer
191
    mov     edi,fin                     ; pointer
165
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
192
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
166
    call    colorprecalc        ; calculate colors
193
    call    colorprecalc        ; calculate colors
167
    mov     esi,name_string
194
    mov     esi,name_string
168
    call    open
195
    call    open
169
    test    eax,eax
196
    test    eax,eax
170
    jz      close_program
197
    jz      close_program
171
    call    jpeg_info
198
    call    jpeg_info
172
    mov dword [jpeg_st],ebp
199
    mov dword [jpeg_st],ebp
173
    call    set_as_bgr2         ; set wallpaper
200
    call    set_as_bgr2         ; set wallpaper
174
    jmp     close_program       ; close the program right now
201
    jmp     close_program       ; close the program right now
175
 
202
 
176
;******************************************************************************
203
;******************************************************************************
177
set_mono:
204
set_mono:
178
    mov     eax, 15
205
    mov     eax, 15
179
    mov     ebx, 1
206
    mov     ebx, 1
180
    mov     ecx, 1
207
    mov     ecx, 1
181
    mov     edx, 1
208
    mov     edx, 1
182
    mcall
209
    mcall
183
 
210
 
184
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
211
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
185
    jne     @f
212
    jne     @f
186
.green:
213
.green:
187
    mov     ecx,mono+6
214
    mov     ecx,mono+6
188
    jmp     .set
215
    jmp     .set
189
@@:
216
@@:
190
;    cmp     [PARAMS], word "CO" ; received BOOT parameter -> goto handler
217
;    cmp     [PARAMS], word "CO" ; received BOOT parameter -> goto handler
191
;    jne     .green
218
;    jne     .green
192
    xor     ecx,ecx
219
    xor     ecx,ecx
193
    mov     cl,[PARAMS+3]
220
    mov     cl,[PARAMS+3]
194
    sub     cl,0x30
221
    sub     cl,0x30
195
    cmp     ecx,0
222
    cmp     ecx,0
196
    jb      .green
223
    jb      .green
197
    cmp     ecx,9     
224
    cmp     ecx,9     
198
    ja      .green
225
    ja      .green
199
    imul    ecx,3
226
    imul    ecx,3
200
    add     ecx,mono
227
    add     ecx,mono
201
.set:
228
.set:
202
    mcall   15,5, ,0,3
229
    mcall   15,5, ,0,3
203
 
230
 
204
    ; Stretch the image to fit
231
    ; Stretch the image to fit
205
    mov     eax, 15
232
    mov     eax, 15
206
    mov     ebx, 4
233
    mov     ebx, 4
207
    mov     ecx, 1
234
    mov     ecx, 1
208
    mcall
235
    mcall
209
 
236
 
210
    mov     eax, 15
237
    mov     eax, 15
211
    mov     ebx, 3
238
    mov     ebx, 3
212
    mcall
239
    mcall
213
    jmp     close_program
240
    jmp     close_program
214
    
241
    
215
mono:
242
mono:
216
    db 0,0,0       ; black
243
    db 0,0,0       ; black
217
    db 255,255,255 ; white
244
    db 255,255,255 ; white
218
    db 128,128,0   ; green
245
    db 128,128,0   ; green
219
    db 240,202,166 ; lilas
246
    db 240,202,166 ; lilas
220
    db 192,192,192 ; grey
247
    db 192,192,192 ; grey
221
    db 255,255,0   ; light-blue
248
    db 255,255,0   ; light-blue
222
    db 255,0,0     ; blue
249
    db 255,0,0     ; blue
223
    db 192,220,192 ; salad
250
    db 192,220,192 ; salad
224
    db 255,0,255   ; pink
251
    db 255,0,255   ; pink
225
    db 0,255,255   ; yellow
252
    db 0,255,255   ; yellow
226
;******************************************************************************
253
;******************************************************************************
227
 
254
 
228
set_as_bgr2:
255
set_as_bgr2:
229
    mov ebp,dword[jpeg_st]
256
    mov ebp,dword[jpeg_st]
230
    test    ebp,ebp
257
    test    ebp,ebp
231
    jz      .end
258
    jz      .end
232
    
259
    
233
    mov     eax, 15
260
    mov     eax, 15
234
    mov     ebx, 1
261
    mov     ebx, 1
235
    mov     ecx, [ebp + x_size]
262
    mov     ecx, [ebp + x_size]
236
    mov     edx, [ebp + y_size]
263
    mov     edx, [ebp + y_size]
237
    mcall
264
    mcall
238
 
265
 
239
        mov     ebx, 6
266
        mov     ebx, 6
240
        mcall
267
        mcall
241
        test    eax, eax
268
        test    eax, eax
242
        jz      .end
269
        jz      .end
243
        mov     [ipc_mem_out], eax
270
        mov     [ipc_mem_out], eax
244
 
271
 
245
    mov     dword [ebp+draw_ptr],put_chunk_to_mem
272
    mov     dword [ebp+draw_ptr],put_chunk_to_mem
246
    call    jpeg_display
273
    call    jpeg_display
247
 
274
 
248
        mov     eax, 15
275
        mov     eax, 15
249
        mov     ebx, 7
276
        mov     ebx, 7
250
        mov     ecx, [ipc_mem_out]
277
        mov     ecx, [ipc_mem_out]
251
        mcall
278
        mcall
252
 
279
 
253
    ; Stretch the image to fit
280
    ; Stretch the image to fit
254
    mov     eax, 15
281
    mov     eax, 15
255
    mov     ebx, 4
282
    mov     ebx, 4
256
    mov     ecx, 2
283
    mov     ecx, [drawing_mode]  ;2
257
    mcall
284
    mcall
258
 
285
 
259
    mov     eax, 15
286
    mov     eax, 15
260
    mov     ebx, 3
287
    mov     ebx, 3
261
    mcall
288
    mcall
262
 
289
 
263
 
290
 
264
 .end:
291
 .end:
265
    ret
292
    ret
266
 
293
 
267
;******************************************************************************
294
;******************************************************************************
268
 
295
 
269
ipc_service:
296
ipc_service:
270
        mov     esi, PARAMS+1
297
        mov     esi, PARAMS+1
271
        xor     eax, eax
298
        xor     eax, eax
272
        xor     ecx, ecx
299
        xor     ecx, ecx
273
@@:
300
@@:
274
        lodsb
301
        lodsb
275
        test    al, al
302
        test    al, al
276
        jz      @f
303
        jz      @f
277
        lea     ecx, [ecx*5]
304
        lea     ecx, [ecx*5]
278
        lea     ecx, [ecx*2+eax-'0']
305
        lea     ecx, [ecx*2+eax-'0']
279
        jmp     @b
306
        jmp     @b
280
@@:
307
@@:
281
        add     ecx, 16
308
        add     ecx, 16
282
        mov     edx, ecx
309
        mov     edx, ecx
283
        mcall   68, 12
310
        mcall   68, 12
284
        test    eax, eax
311
        test    eax, eax
285
        jnz     @f
312
        jnz     @f
286
.exit:
313
.exit:
287
        mcall   -1
314
        mcall   -1
288
@@:
315
@@:
289
        mov     ecx, eax
316
        mov     ecx, eax
290
        and     dword [ecx], 0
317
        and     dword [ecx], 0
291
        mov     dword [ecx+4], 8
318
        mov     dword [ecx+4], 8
292
        mov     [ipc_mem], ecx
319
        mov     [ipc_mem], ecx
293
        mcall   60, 1
320
        mcall   60, 1
294
        mcall   40, 1 shl 6
321
        mcall   40, 1 shl 6
295
        mcall   23, 500         ; wait up to 5 seconds for IPC message
322
        mcall   23, 500         ; wait up to 5 seconds for IPC message
296
        test    eax, eax
323
        test    eax, eax
297
        jz      .exit
324
        jz      .exit
298
; we got message with JPEG data, now decode it
325
; we got message with JPEG data, now decode it
299
        mov     eax, [ecx+12]
326
        mov     eax, [ecx+12]
300
        mov     [ipc_mem_size], eax
327
        mov     [ipc_mem_size], eax
301
; init JPEG decoder
328
; init JPEG decoder
302
    mov     ecx,memsize-fin-stack_size  ; size
329
    mov     ecx,memsize-fin-stack_size  ; size
303
    mov     edi,fin                     ; pointer
330
    mov     edi,fin                     ; pointer
304
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
331
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
305
    call    colorprecalc        ; calculate colors
332
    call    colorprecalc        ; calculate colors
306
; hook file functions
333
; hook file functions
307
        mov     ecx, 4
334
        mov     ecx, 4
308
        call    malloc
335
        call    malloc
309
        and     dword [edi], 0
336
        and     dword [edi], 0
310
        lea     eax, [edi-file_handler.position]
337
        lea     eax, [edi-file_handler.position]
311
        mov     byte [read], 0xE9
338
        mov     byte [read], 0xE9
312
        mov     dword [read+1], read_from_mem - (read+5)
339
        mov     dword [read+1], read_from_mem - (read+5)
313
; decode
340
; decode
314
    call    jpeg_info
341
    call    jpeg_info
315
    mov     dword [jpeg_st],ebp
342
    mov     dword [jpeg_st],ebp
316
    test    ebp,ebp
343
    test    ebp,ebp
317
    jz      .end
344
    jz      .end
318
 
345
 
319
        mov     eax, [ebp + x_size]
346
        mov     eax, [ebp + x_size]
320
        mul     dword [ebp + y_size]
347
        mul     dword [ebp + y_size]
321
        lea     eax, [eax*3+8]
348
        lea     eax, [eax*3+8]
322
        mov     ecx, eax
349
        mov     ecx, eax
323
        mcall   68, 12
350
        mcall   68, 12
324
        test    eax, eax
351
        test    eax, eax
325
        jz      .end
352
        jz      .end
326
        add     eax, 8
353
        add     eax, 8
327
        mov     [ipc_mem_out], eax
354
        mov     [ipc_mem_out], eax
328
        mov     ebx, [ebp + x_size]
355
        mov     ebx, [ebp + x_size]
329
        mov     [eax-8], ebx
356
        mov     [eax-8], ebx
330
        mov     ebx, [ebp + y_size]
357
        mov     ebx, [ebp + y_size]
331
        mov     [eax-4], ebx
358
        mov     [eax-4], ebx
332
 
359
 
333
    mov     dword [ebp+draw_ptr],put_chunk_to_mem
360
    mov     dword [ebp+draw_ptr],put_chunk_to_mem
334
    call    jpeg_display
361
    call    jpeg_display
335
 
362
 
336
; IPC response
363
; IPC response
337
        mov     esi, [ebp + x_size]
364
        mov     esi, [ebp + x_size]
338
        imul    esi, [ebp + y_size]
365
        imul    esi, [ebp + y_size]
339
        lea     esi, [esi*3+8]
366
        lea     esi, [esi*3+8]
340
        mov     edx, [ipc_mem_out]
367
        mov     edx, [ipc_mem_out]
341
        sub     edx, 8
368
        sub     edx, 8
342
.response:
369
.response:
343
        mov     ecx, [ipc_mem]
370
        mov     ecx, [ipc_mem]
344
        mov     ecx, [ecx+8]
371
        mov     ecx, [ecx+8]
345
        mcall   60,2
372
        mcall   60,2
346
 
373
 
347
    jmp     close_program       ; close the program right now
374
    jmp     close_program       ; close the program right now
348
 
375
 
349
.end:
376
.end:
350
        mov     esi, 8
377
        mov     esi, 8
351
        mov     edx, x_pointer  ; points to 2 null dwords
378
        mov     edx, x_pointer  ; points to 2 null dwords
352
        jmp     .response
379
        jmp     .response
353
 
380
 
354
read_from_mem:
381
read_from_mem:
355
; in: eax=handle, ecx=size, edi=pointer to buffer
382
; in: eax=handle, ecx=size, edi=pointer to buffer
356
; out: ecx=number of read bytes, buffer filled
383
; out: ecx=number of read bytes, buffer filled
357
        pushad
384
        pushad
358
        mov     esi, [ipc_mem]
385
        mov     esi, [ipc_mem]
359
        add     esi, 16
386
        add     esi, 16
360
        add     esi, [eax+file_handler.position]
387
        add     esi, [eax+file_handler.position]
361
        add     ecx, [eax+file_handler.position]
388
        add     ecx, [eax+file_handler.position]
362
        cmp     ecx, [ipc_mem_size]
389
        cmp     ecx, [ipc_mem_size]
363
        jb      @f
390
        jb      @f
364
        mov     ecx, [ipc_mem_size]
391
        mov     ecx, [ipc_mem_size]
365
@@:
392
@@:
366
        sub     ecx, [eax+file_handler.position]
393
        sub     ecx, [eax+file_handler.position]
367
        add     [eax+file_handler.position], ecx
394
        add     [eax+file_handler.position], ecx
368
        rep     movsb
395
        rep     movsb
369
        popad
396
        popad
370
        ret
397
        ret
371
 
398
 
372
;******************************************************************************
399
;******************************************************************************
373
 
400
 
374
put_chunk_to_mem:
401
put_chunk_to_mem:
375
; in: (eax,ebx) = start coordinates of chunk
402
; in: (eax,ebx) = start coordinates of chunk
376
;     (ecx,edx) = sizes of chunk
403
;     (ecx,edx) = sizes of chunk
377
;     edi -> chunk data
404
;     edi -> chunk data
378
        push    esi edi edx
405
        push    esi edi edx
379
        mov     esi, edi
406
        mov     esi, edi
380
        mov     edi, ebx
407
        mov     edi, ebx
381
        imul    edi, [ebp + x_size]
408
        imul    edi, [ebp + x_size]
382
        add     edi, eax
409
        add     edi, eax
383
        lea     edi, [edi*3]
410
        lea     edi, [edi*3]
384
        add     edi, [ipc_mem_out]
411
        add     edi, [ipc_mem_out]
385
@@:
412
@@:
386
        push    ecx edi
413
        push    ecx edi
387
        lea     ecx, [ecx*3]
414
        lea     ecx, [ecx*3]
388
        rep     movsb
415
        rep     movsb
389
        pop     edi ecx
416
        pop     edi ecx
390
        add     edi, [ebp + x_size]
417
        add     edi, [ebp + x_size]
391
        add     edi, [ebp + x_size]
418
        add     edi, [ebp + x_size]
392
        add     edi, [ebp + x_size]
419
        add     edi, [ebp + x_size]
393
        dec     edx
420
        dec     edx
394
        jnz     @b
421
        jnz     @b
395
        pop     edx edi esi
422
        pop     edx edi esi
396
        ret
423
        ret
397
 
424
 
398
;******************************************************************************
425
;******************************************************************************
399
 
426
 
400
 
427
 
401
 
428
 
402
;   *********************************************
429
;   *********************************************
403
;   *******  WINDOW DEFINITIONS AND DRAW ********
430
;   *******  WINDOW DEFINITIONS AND DRAW ********
404
;   *********************************************
431
;   *********************************************
405
 
432
 
406
 
433
 
407
draw_window:
434
draw_window:
408
 
435
 
409
    mov  eax,48
436
    mov  eax,48
410
    mov  ebx,3
437
    mov  ebx,3
411
    mov  ecx,sc
438
    mov  ecx,sc
412
    mov  edx,sizeof.system_colors
439
    mov  edx,sizeof.system_colors
413
    mcall
440
    mcall
414
 
441
 
415
    mov  eax,12
442
    mov  eax,12
416
    mov  ebx,1
443
    mov  ebx,1
417
    mcall
444
    mcall
418
 
445
 
419
    ; Draw the window to the appropriate size - it may have
446
    ; Draw the window to the appropriate size - it may have
420
    ; been resized by the user
447
    ; been resized by the user
421
    cmp     [winxs], 0
448
    cmp     [winxs], 0
422
    jne     dw_001
449
    jne     dw_001
423
 
450
 
424
    ; Give the screen some inital defaults
451
    ; Give the screen some inital defaults
425
    mov     [winxs], 400
452
    mov     [winxs], 400
426
    mov     [winys], 300
453
    mov     [winys], 300
427
    mov     ax, 100
454
    mov     ax, 100
428
    mov     [winxo], ax
455
    mov     [winxo], ax
429
    mov     [winyo], ax
456
    mov     [winyo], ax
430
    jmp     dw_002
457
    jmp     dw_002
431
 
458
 
432
dw_001:
459
dw_001:
433
    mov     eax, 9
460
    mov     eax, 9
434
    mov ebx, memsize - 1024
461
    mov ebx, memsize - 1024
435
    mov ecx, -1
462
    mov ecx, -1
436
    mcall
463
    mcall
437
    mov     eax, [ebx + 34]
464
    mov     eax, [ebx + 34]
438
    mov     [winxo], ax
465
    mov     [winxo], ax
439
    mov     eax, [ebx + 38]
466
    mov     eax, [ebx + 38]
440
    mov     [winyo], ax
467
    mov     [winyo], ax
441
    mov     eax, [ebx + 42]
468
    mov     eax, [ebx + 42]
442
    mov     [winxs], ax
469
    mov     [winxs], ax
443
    mov     eax, [ebx + 46]
470
    mov     eax, [ebx + 46]
444
    mov     [winys], ax
471
    mov     [winys], ax
445
 
472
 
446
dw_002:
473
dw_002:
447
        mov     ebx, dword [winxo-2]
474
        mov     ebx, dword [winxo-2]
448
        mov     bx, [winxs]
475
        mov     bx, [winxs]
449
        mov     ecx, dword [winyo-2]
476
        mov     ecx, dword [winyo-2]
450
        mov     cx, [winys]
477
        mov     cx, [winys]
451
 
478
 
452
    xor  eax,eax                   ; DRAW WINDOW
479
    xor  eax,eax                   ; DRAW WINDOW
453
    mov  edx,[sc.work]
480
    mov  edx,[sc.work]
454
    or   edx,0x33000000
481
    or   edx,0x33000000
455
    mov  edi,title                ; WINDOW LABEL
482
    mov  edi,title                ; WINDOW LABEL
456
    mcall
483
    mcall
457
 
484
 
458
 
485
 
459
    mov  eax,8                     ; BUTTON 2: slideshow
486
    mov  eax,8                     ; BUTTON 2: slideshow
460
    mov  ebx,57
487
    mov  ebx,57
461
    mov  cx, [winys]
488
    mov  cx, [winys]
462
    sub  cx, 39
489
    sub  cx, 39
463
    shl  ecx, 16
490
    shl  ecx, 16
464
    add  ecx, 12
491
    add  ecx, 12
465
    mov  esi, [sc.work_button]
492
    mov  esi, [sc.work_button]
466
    mov  edx,2
493
    mov  edx,2
467
    mcall
494
    mcall
468
 
495
 
469
    mov  eax,4                     ; Button text
496
    mov  eax,4                     ; Button text
470
    movzx ebx, word [winys]
497
    movzx ebx, word [winys]
471
    add   ebx, 3 shl 16 - 36
498
    add   ebx, 3 shl 16 - 36
472
    mov  ecx,[sc.work_button_text]
499
    mov  ecx,[sc.work_button_text]
473
    mov  edx,setname
500
    mov  edx,setname
474
    mov  esi,setnamelen-setname
501
    mov  esi,setnamelen-setname
475
    mcall
502
    mcall
476
 
503
 
477
 
504
 
478
    mov  eax,8                     ; BUTTON 3: set as background
505
    mov  eax,8                     ; BUTTON 3: set as background
479
    mov  bx, [winxs]
506
    mov  bx, [winxs]
480
    sub  bx, 65
507
    sub  bx, 65
481
    shl  ebx, 16
508
    shl  ebx, 16
482
    mov  bx,55
509
    mov  bx,55
483
    mov  cx, [winys]
510
    mov  cx, [winys]
484
    sub  cx, 39
511
    sub  cx, 39
485
    shl  ecx, 16
512
    shl  ecx, 16
486
    add  ecx, 12
513
    add  ecx, 12
487
    mov  esi, [sc.work_button]
514
    mov  esi, [sc.work_button]
488
    mov  edx,3
515
    mov  edx,3
489
    mcall
516
    mcall
490
 
517
 
491
    mov  eax,4                     ; Button text
518
    mov  eax,4                     ; Button text
492
    movzx ebx, word [winxs]
519
    movzx ebx, word [winxs]
493
    sub   ebx, 63
520
    sub   ebx, 63
494
    shl   ebx,16
521
    shl   ebx,16
495
    mov   bx, word [winys]
522
    mov   bx, word [winys]
496
    sub   bx,36
523
    sub   bx,36
497
    mov  ecx,[sc.work_button_text]
524
    mov  ecx,[sc.work_button_text]
498
    mov  edx,setbgr
525
    mov  edx,setbgr
499
    mov  esi,setbgrlen-setbgr
526
    mov  esi,setbgrlen-setbgr
500
    mcall
527
    mcall
501
    call    print_strings
528
    call    print_strings
502
    call    load_image
529
    call    load_image
503
    mov     eax,12                    ; function 12:tell os about windowdraw
530
    mov     eax,12                    ; function 12:tell os about windowdraw
504
    mov     ebx,2                     ; 2, end of draw
531
    mov     ebx,2                     ; 2, end of draw
505
    mcall
532
    mcall
506
 
533
 
507
    ret
534
    ret
508
 
535
 
509
 
536
 
510
 
537
 
511
    ; Read in the image file name.
538
    ; Read in the image file name.
512
read_string:
539
read_string:
513
    movzx edi,byte[name_string.cursor]
540
    movzx edi,byte[name_string.cursor]
514
    add     edi,name_string
541
    add     edi,name_string
515
    mov     eax,2
542
    mov     eax,2
516
    mcall                        ; Get the key value
543
    mcall                        ; Get the key value
517
    shr     eax,8
544
    shr     eax,8
518
    cmp     eax,13                      ; Return key ends input
545
    cmp     eax,13                      ; Return key ends input
519
    je      .rs_done
546
    je      .rs_done
520
    cmp     eax,8
547
    cmp     eax,8
521
    jnz     .nobsl
548
    jnz     .nobsl
522
    cmp     edi,name_string
549
    cmp     edi,name_string
523
    je      .exit
550
    je      .exit
524
    dec     edi
551
    dec     edi
525
    mov     [edi],byte 0;'_'
552
    mov     [edi],byte 0;'_'
526
    dec     byte[name_string.cursor]
553
    dec     byte[name_string.cursor]
527
    jmp     print_strings
554
    jmp     print_strings
528
.exit:   ret
555
.exit:   ret
529
.nobsl:
556
.nobsl:
530
    cmp     eax,31
557
    cmp     eax,31
531
    jbe     .exit
558
    jbe     .exit
532
    cmp     eax,97
559
    cmp     eax,97
533
    jb      .keyok
560
    jb      .keyok
534
    sub     eax,32
561
    sub     eax,32
535
.keyok:
562
.keyok:
536
    mov ah,0
563
    mov ah,0
537
    stosw
564
    stosw
538
    cmp edi,name_string.end
565
    cmp edi,name_string.end
539
    jnc print_strings
566
    jnc print_strings
540
    inc byte[name_string.cursor]
567
    inc byte[name_string.cursor]
541
    jmp    print_strings
568
    jmp    print_strings
542
.rs_done:
569
.rs_done:
543
    call   print_strings
570
    call   print_strings
544
    mov     esi,name_string
571
    mov     esi,name_string
545
    call    open
572
    call    open
546
    test    eax,eax
573
    test    eax,eax
547
    jz      .exit
574
    jz      .exit
548
    call    jpeg_info
575
    call    jpeg_info
549
    test    ebp,ebp
576
    test    ebp,ebp
550
    jz      close
577
    jz      close
551
    xchg    [jpeg_st],ebp
578
    xchg    [jpeg_st],ebp
552
    call jpeg_close
579
    call jpeg_close
553
 
580
 
554
load_image:
581
load_image:
555
 
582
 
556
    mov     eax,13              ; clear picture area
583
    mov     eax,13              ; clear picture area
557
    movzx    ebx, word [winxs]
584
    movzx    ebx, word [winxs]
558
    add     ebx, 1  shl 16 -10
585
    add     ebx, 1  shl 16 -10
559
    movzx    ecx, word [winys]
586
    movzx    ecx, word [winys]
560
    sub     ecx, 40
587
    sub     ecx, 40
561
    add     ecx, 1  shl 16
588
    add     ecx, 1  shl 16
562
 
589
 
563
    mov     edx,[sc.work]
590
    mov     edx,[sc.work]
564
    mcall
591
    mcall
565
    mov    ebp,[jpeg_st]
592
    mov    ebp,[jpeg_st]
566
    test    ebp,ebp
593
    test    ebp,ebp
567
    jz      .exit
594
    jz      .exit
568
    mov     dword [ebp+draw_ptr],put_image
595
    mov     dword [ebp+draw_ptr],put_image
569
    jmp    jpeg_display
596
    jmp    jpeg_display
570
 .exit: ret
597
 .exit: ret
571
 
598
 
572
print_strings:
599
print_strings:
573
    pusha
600
    pusha
574
    mov     eax,13              ; clear text area
601
    mov     eax,13              ; clear text area
575
    movzx   ebx, word [winxs]
602
    movzx   ebx, word [winxs]
576
    add     ebx, 59 shl 16 -125
603
    add     ebx, 59 shl 16 -125
577
    mov     cx, [winys]
604
    mov     cx, [winys]
578
    sub     cx, 39
605
    sub     cx, 39
579
    shl     ecx, 16
606
    shl     ecx, 16
580
    add     ecx, 12
607
    add     ecx, 12
581
    mov     edx,0xffffff
608
    mov     edx,0xffffff
582
    mcall
609
    mcall
583
 
610
 
584
    mov     eax,4               ;
611
    mov     eax,4               ;
585
    movzx   ebx, word [winys]
612
    movzx   ebx, word [winys]
586
    add     ebx, 61 shl 16 - 37
613
    add     ebx, 61 shl 16 - 37
587
    mov     ecx,0x000000
614
    mov     ecx,0x000000
588
    mov     edx,name_string
615
    mov     edx,name_string
589
    mov     esi,60
616
    mov     esi,60
590
    mcall
617
    mcall
591
    popa
618
    popa
592
    ret
619
    ret
593
 
620
 
594
slideshow:
621
slideshow:
595
        cmp     [file_dir], 0
622
        cmp     [file_dir], 0
596
        jnz     .exit
623
        jnz     .exit
597
        cmp     [jpeg_st], 0
624
        cmp     [jpeg_st], 0
598
        jz      .exit
625
        jz      .exit
599
        mov     esi, name_string
626
        mov     esi, name_string
600
        movzx   ecx, byte [name_string.cursor]
627
        movzx   ecx, byte [name_string.cursor]
601
.l1:
628
.l1:
602
        cmp     byte [esi+ecx], '/'
629
        cmp     byte [esi+ecx], '/'
603
        jz      .l2
630
        jz      .l2
604
        loop    .l1
631
        loop    .l1
605
.exit:
632
.exit:
606
        ret
633
        ret
607
.l2:
634
.l2:
608
        mov     byte [esi+ecx], 0
635
        mov     byte [esi+ecx], 0
609
        call    open
636
        call    open
610
        mov     byte [esi+ecx], '/'
637
        mov     byte [esi+ecx], '/'
611
        test    eax, eax
638
        test    eax, eax
612
        jz      .exit
639
        jz      .exit
613
        test    byte [fileattr], 0x10
640
        test    byte [fileattr], 0x10
614
        jz      .exit
641
        jz      .exit
615
        mov     [file_dir], eax
642
        mov     [file_dir], eax
616
        inc     ecx
643
        inc     ecx
617
        mov     [name_string.cursor], cl
644
        mov     [name_string.cursor], cl
618
display_next:
645
display_next:
619
        mov     ebx, [file_dir]
646
        mov     ebx, [file_dir]
620
        test    ebx, ebx
647
        test    ebx, ebx
621
        jnz     @f
648
        jnz     @f
622
        ret
649
        ret
623
@@:
650
@@:
624
        mov     byte [ebx], 1
651
        mov     byte [ebx], 1
625
        mov     byte [ebx+12], 1
652
        mov     byte [ebx+12], 1
626
        mov     dword [ebx+16], dirinfo
653
        mov     dword [ebx+16], dirinfo
627
        mov     eax, 70
654
        mov     eax, 70
628
        mcall
655
        mcall
629
        mov     eax, [file_dir]
656
        mov     eax, [file_dir]
630
        inc     dword [eax+4]
657
        inc     dword [eax+4]
631
        cmp     ebx, 1
658
        cmp     ebx, 1
632
        jz      @f
659
        jz      @f
633
        mov     eax, [file_dir]
660
        mov     eax, [file_dir]
634
        and     [file_dir], 0
661
        and     [file_dir], 0
635
        jmp     close
662
        jmp     close
636
@@:
663
@@:
637
        movzx   edi, byte [name_string.cursor]
664
        movzx   edi, byte [name_string.cursor]
638
        add     edi, name_string
665
        add     edi, name_string
639
        lea     esi, [dirinfo+32+40]
666
        lea     esi, [dirinfo+32+40]
640
@@:
667
@@:
641
        lodsb
668
        lodsb
642
        stosb
669
        stosb
643
        test    al, al
670
        test    al, al
644
        jnz     @b
671
        jnz     @b
645
        mov     ecx, name_string.end
672
        mov     ecx, name_string.end
646
        sub     ecx, edi
673
        sub     ecx, edi
647
        rep     stosb
674
        rep     stosb
648
    call   print_strings
675
    call   print_strings
649
    mov     esi,name_string
676
    mov     esi,name_string
650
    call    open
677
    call    open
651
    test    eax,eax
678
    test    eax,eax
652
    jz      display_next
679
    jz      display_next
653
    call    jpeg_info
680
    call    jpeg_info
654
    test    ebp,ebp
681
    test    ebp,ebp
655
    jnz     .l6
682
    jnz     .l6
656
    call close
683
    call close
657
    jmp display_next
684
    jmp display_next
658
   .l6:
685
   .l6:
659
    mov dword[ebp+draw_ptr],put_image
686
    mov dword[ebp+draw_ptr],put_image
660
    push ebp
687
    push ebp
661
    xchg [jpeg_st],ebp
688
    xchg [jpeg_st],ebp
662
    call jpeg_close
689
    call jpeg_close
663
    pop ebp
690
    pop ebp
664
    jmp jpeg_display
691
    jmp jpeg_display
665
 
692
 
666
 
693
 
667
include 'filelib.asm'
694
include 'filelib.asm'
668
include 'memlib.asm'
695
include 'memlib.asm'
669
include 'jpeglib.asm'
696
include 'jpeglib.asm'
670
 
697
 
671
 
698
 
672
; DATA AREA
699
; DATA AREA
673
 
700
 
674
wcolor          dd  0x000000
701
wcolor          dd  0x000000
-
 
702
drawing_mode    dd  2
675
title          db  appname,version,0
703
title          db  appname,version,0
676
setname          db  'SLIDESHOW'
704
setname          db  'SLIDESHOW'
677
setnamelen:
705
setnamelen:
678
 
706
 
679
setbgr           db  '   BGR  '
707
setbgr           db  '   BGR  '
680
setbgrlen:
708
setbgrlen:
681
 
709
 
682
x_pointer       dd  0
710
x_pointer       dd  0
683
x_offset        dd  0
711
x_offset        dd  0
684
x_numofbytes    dd  0
712
x_numofbytes    dd  0
685
x_numofb2       dd  0
713
x_numofb2       dd  0
686
x_counter       dd  0
714
x_counter       dd  0
687
winxo           dw  0
715
winxo           dw  0
688
winyo           dw  0
716
winyo           dw  0
689
winxs           dw  0
717
winxs           dw  0
690
winys           dw  0
718
winys           dw  0
691
jpeg_st         dd  0
719
jpeg_st         dd  0
692
file_dir        dd  0
720
file_dir        dd  0
693
name_string:    db '/sys/jpegview.jpg',0
721
name_string:    db '/sys/jpegview.jpg',0
694
rb 256
722
rb 256
695
    .end:
723
    .end:
696
    .cursor: db 19
724
    .cursor: db 19
697
    .cursor2: db 0
725
    .cursor2: db 0
698
 
726
 
699
align 4
727
align 4
700
 
728
 
701
rgb16:          db 0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63
729
rgb16:          db 0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63
702
rgb4:           db 0,21,42,63
730
rgb4:           db 0,21,42,63
703
 
731
 
704
include 'jpegdat.asm'
732
include 'jpegdat.asm'
705
 
733
 
706
align 4
734
align 4
707
 
735
 
708
iniciomemoria:
736
iniciomemoria:
709
              dd -(iniciomemoria+4),-(iniciomemoria+4),(iniciomemoria+4),.l1,0
737
              dd -(iniciomemoria+4),-(iniciomemoria+4),(iniciomemoria+4),.l1,0
710
.l1           dd 0
738
.l1           dd 0
711
 
739
 
712
I_END:
740
I_END:
713
sc     system_colors
741
sc     system_colors
714
ipc_mem dd ?
742
ipc_mem dd ?
715
ipc_mem_size dd ?
743
ipc_mem_size dd ?
716
ipc_mem_out dd ?
744
ipc_mem_out dd ?
717
fileattr: rb 40
745
fileattr: rb 40
718
dirinfo: rb 32+304
746
dirinfo: rb 32+304
719
fin:
747
fin: