Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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
21
;
22
               memsize=20000h
23
               org 0
24
 PARAMS     =    memsize - 1024
25
 
26
use32
27
 
28
               db     'MENUET01'              ; 8 byte id
29
               dd     0x01                    ; header version
30
               dd     START                   ; start of code
31
               dd     I_END                   ; size of image
32
               dd     memsize                 ; memory for app
33
               dd     memsize - 1024           ; esp
34
               dd     PARAMS , 0x0               ; I_Param , I_Icon
35
 
36
include 'lang.inc'
37
stack_size=4096 + 1024
38
 
39
 
40
START:                          ; start of execution
41
 
42
    cmp     [PARAMS], byte 0
43
    jne     check_parameters
44
 
45
    ; Calculate the 'free' memory available
46
    ; to the application, and create the malloc block from it
47
  .l1:
48
    mov     ecx,memsize-fin-stack_size
49
    mov     edi,fin
50
    call    add_mem
51
 
52
    ; Get some memory
53
    mov     ecx,16384
54
    call    malloc
55
    mov     [work_area],edi
56
    call    colorprecalc ;inicializa tablas usadas para pasar de ybr a bgr
57
    call    draw_window
58
    call    read_string.rs_done
59
 
60
still:
61
    push still
62
    mov ebx,100                ;1 second
63
    mov  eax,23                 ; wait here for event
64
    int  0x40
65
    cmp  eax,1                  ; redraw request ?
66
    je   draw_window
67
    cmp  eax,2                  ; key in buffer ?
68
    je   read_string
69
    cmp  eax,3                  ; button in buffer ?
70
    je   button
71
    jmp display_next
72
 
73
button:                       ; BUTTON
74
    mov  eax,17
75
    int  0x40
76
    cmp ah,3
77
    je set_as_bgr2
78
    cmp ah,2
79
    je slideshow
80
    cmp  ah,1                   ; CLOSE PROGRAM
81
    jne  close_program.exit
82
close_program:
83
    mov  eax,-1
84
    int  0x40
85
  .exit:
86
    ret
87
 
88
   ; Put a 'chunk' of the image on the window
89
put_image:
90
    pushad
91
 
92
    lea ebp,[edx+eax+7]
93
    cmp  [winxs],bp
94
    jc     .l1
95
    lea ebp,[ecx+ebx+20+2+17]
96
    cmp [winys],bp
97
    jc     .l1
98
 
99
    add     eax,5  ; offset for boarder
100
    add     ebx,20 ; offset for title bar
101
    push    ax ; pox
102
    push    bx ; pos
103
    push    cx ; size
104
    push    dx ; size
105
    pop     ecx
106
    pop     edx
107
    mov     ebx,edi
108
    mov     eax,7
109
 
110
    int     40h                         ; Put image function
111
.l1:
112
    popad
113
    ret
114
 
115
 
116
 
117
;******************************************************************************
118
 
119
check_parameters:
120
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
121
    je      boot_set_background
122
 
123
    mov     edi, name_string       ; clear string with file name
124
    mov     al,  0
125
    mov     ecx, 100
126
    rep     stosb
127
 
128
    mov     ecx, 100               ; calculate length of parameter string
129
    mov     edi, PARAMS
130
    repne   scasb
131
    sub     edi, PARAMS
132
    mov     ecx, edi
133
 
134
    mov     esi, PARAMS            ; copy parameters to file name
135
    mov     edi, name_string
136
    cld
137
    rep     movsb
138
 
139
    jmp     START.l1       ; return to beggining of the progra
140
 
141
;******************************************************************************
142
 
143
 
144
set_default_colours:
145
 
146
     pusha
147
 
148
     mov  eax,6            ; load default color map
149
     mov  ebx,defcol
150
     mov  ecx,0
151
     mov  edx,-1
152
     mov  esi,0x10000
153
     int  0x40
154
 
155
     mov  eax,48           ; set default color map
156
     mov  ebx,2
157
     mov  ecx,0x10000
158
     mov  edx,10*4
159
     int  0x40
160
 
161
     popa
162
     ret
163
 
164
defcol db 'DEFAULT.DTP'
165
 
166
 
167
boot_set_background:
168
    call    set_default_colours
169
 
170
    mov     ecx,memsize-fin-stack_size  ; size
171
    mov     edi,fin                     ; pointer
172
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
173
    ; Get some memory
174
    mov     ecx,16384           ; get 16 Kb of memory
175
    call    malloc              ; returns pointer in edi
176
    mov     [work_area],edi     ; save it
177
    call    colorprecalc        ; calculate colors
178
    mov     esi,name_string
179
    call    open
180
    test    eax,eax
181
    jz      close_program
182
    call    jpeg_info
183
    mov dword [jpeg_st],ebp
184
    call    set_as_bgr2         ; set wallpaper
185
    jmp     close_program       ; close the program right now
186
 
187
;******************************************************************************
188
;******************************************************************************
189
 
190
set_as_bgr2:
191
    mov ebp,dword[jpeg_st]
192
    test    ebp,ebp
193
    jz      .end
194
 
195
    mov     dword [ebp+draw_ptr],put_chunk_to_bgr
196
    call    jpeg_display
197
    mov     eax, 15
198
    mov     ebx, 1
199
    mov     ecx, [ebp + x_size]
200
    mov     edx, [ebp + y_size]
201
    int     0x40
202
 
203
    ; Stretch the image to fit
204
    mov     eax, 15
205
    mov     ebx, 4
206
    mov     ecx, 2
207
    int     0x40
208
 
209
    mov     eax, 15
210
    mov     ebx, 3
211
    int     0x40
212
 
213
 
214
 .end:
215
    ret
216
 
217
;******************************************************************************
218
 
219
put_chunk_to_bgr:
220
    pushad
221
 
222
    mov     [x_pointer], edi
223
    mov     esi, ecx
224
    imul    esi, 3
225
    mov     [x_numofbytes], esi
226
    mov     ecx, [ebp + x_size]
227
    imul    ecx, ebx
228
    add     ecx, eax
229
    imul    ecx, 3
230
    mov     [x_offset], ecx
231
    mov     [x_counter], edx
232
    mov     eax, [ebp + x_size]
233
    imul    eax, 3
234
    mov     [x_numofb2], eax
235
 .new_string:
236
    mov     eax, 15
237
    mov     ebx, 5
238
    mov     ecx, [x_pointer]
239
    mov     edx, [x_offset]
240
    mov     esi, [x_numofbytes]
241
    int     0x40
242
    mov     eax, [x_numofbytes]
243
    add     [x_pointer], eax
244
    mov     eax, [x_numofb2]
245
    add     [x_offset], eax
246
    dec     [x_counter]
247
    jnz     .new_string
248
 
249
    popad
250
    ret
251
 
252
;******************************************************************************
253
 
254
 
255
 
256
;   *********************************************
257
;   *******  WINDOW DEFINITIONS AND DRAW ********
258
;   *********************************************
259
 
260
 
261
draw_window:
262
 
263
    mov  eax,12
264
    mov  ebx,1
265
    int  0x40
266
 
267
    ; Draw the window to the appropriate size - it may have
268
    ; been resized by the user
269
    mov     eax, 0
270
    cmp     [winxs], ax
271
    jne     dw_001
272
 
273
    ; Give the screen some inital defaults
274
    mov     ax, 400
275
    mov     [winxs], ax
276