Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
485 heavyiron 1
;
2
;    ICON APPLICATION
3
;
4
;    Compile with FASM for Menuet
5
;
6
;    August 12, 2004 - 32-bit ICO format support (mike.dld)
7
;    March  14, 2007 - rewriten for KolibriOS (heavyiron)
8
 
9
use32
10
 
11
 org    0x0
12
 db     'MENUET01'              ; 8 byte id
13
 dd     0x01                    ; header version
14
 dd     START                   ; start of code
15
 dd     I_END                   ; size of image
16
 dd     0x8000                  ; memory for app
17
 dd     0x8000                  ; esp
18
 dd     I_PARAM , 0x0           ; I_Param , I_Icon
19
 
20
; params 4 xpos 4 ypos 30 iconfile 30 startfile 10 label
21
;          +0     +4      +8          +38          +68
22
 
23
include  '..\..\..\macros.inc'
24
;__DEBUG__ fix 1
25
;__DEBUG_LEVEL__ fix 1
26
;include  'debug-fdo.inc'
503 heavyiron 27
flipdelay = 7
485 heavyiron 28
 
29
START:           ; start of execution
30
 
31
    cmp  [I_PARAM],byte 0
32
    jne  nohalt
33
    or   eax,-1
34
    mcall
35
  nohalt:
36
 
37
    mov  eax,[I_PARAM+0]
38
    sub  eax,0x01010101
39
    mov  [xpos],eax
40
    mov  eax,[I_PARAM+4]
41
    sub  eax,0x01010101
42
    mov  [ypos],eax
43
 
44
    mov  esi,I_PARAM+8
45
    mov  edi,fname
46
    mov  ecx,30
47
    cld
48
    rep  movsb
49
    call fill_paths
50
 
51
;DEBUGF 1,"fname: '%s'\n",fname
52
 
53
    mov  esi,I_PARAM+8+30
54
    mov  edi,start_file
55
    mov  ecx,30
56
    rep  movsb
57
    call fill_paths
58
 
59
    mov  esi,I_PARAM+8+30+30
60
    mov  edi,labelt
61
    mov  ecx,10
62
    cld
63
    rep  movsb
64
 
65
    mov  eax,40          ; get also event background change
66
    mov  ebx,10101b
67
    mcall
68
 
69
 
70
    call get_bg
71
 
72
  red:           ; redraw
73
    call draw_window
74
 
75
still:
76
 
77
    mov  eax,10          ; wait here for event
78
    mcall
79
 
80
    cmp  eax,1          ; redraw request ?
81
    jz  red
82
    cmp  eax,3          ; button in buffer ?
83
    jz  button
84
 
85
  check:
86
    call get_bg
87
    call draw_icon
88
    mcall 5,80
89
    jmp  still
90
 
91
  button:          ; button
92
    mov  al,17          ; get id
93
    mcall
94
 
95
    mov  eax,70
96
    mov  ebx,finfo_start
97
    mcall
98
 
99
    call flip_icon
100
 
101
    jmp  still
102
 
103
flip_icon:
104
 
105
     mov  eax,1
106
     call flip
107
     mov  eax,2
108
     call flip
109
     mov  eax,3
110
     call flip
111
     mov  eax,4
112
     call flip
113
     mov  eax,5
114
     call flip
115
     mov  eax,4
116
     call flip
117
     mov  eax,3
118
     call flip
119
     mov  eax,2
120
     call flip
121
     mov  eax,1
122
     call flip
123
     mov  eax,0
124
     call flip
125
 
126
     ret
127
 
128
flip:
129
     mov  [iconstate],eax
130
     call get_bg
131
     call draw_icon
132
     mov  eax,5
133
     mov  ebx,flipdelay
134
     mcall
135
     ret
136
 
137
fill_paths:
138
     dec  edi
139
     mov  ecx,30
140
     std
141
     mov  al,' '
142
     repe scasb
143
     cld
144
     mov  byte[edi+2],0
145
     ret
146
 
147
draw_window:
148
 
149
    mov  eax,12      ; function 12:tell os about windowdraw
150
    mov  ebx,1      ; 1, start of draw
151
    mcall
152
 
153
       ; DRAW WINDOW
154
    xor  eax,eax            ; function 0 : define and draw window
155
    mov  ebx,[xpos-2]
156
    mov  ecx,[ypos-2]
157
    add  ebx,[yw]           ; [x start] *65536 + [x size]
158
    add  ecx,67             ; [y start] *65536 + [y size]
159
    mov  edx,0x01000000     ; color of work area RRGGBB,8->color gl
160
    mcall
161
 
162
    mov  eax,8      ; button
163
    mov  ebx,51
164
    mov  ecx,67
165
    mov  edx,0x60000001
166
    mcall
167
 
168
    call draw_icon
169
 
170
    mov  eax,12
171
    mov  ebx,2
172
    mcall
173
 
174
    ret
175
 
176
get_bg:
177
 
178
    mov  eax,14
179
    mcall
180
    add  eax,0x00010001
181
    mov  [scrxy],eax
182
 
183
    mov  eax,39        ; get background type
184
    mov  ebx,4
185
    mcall
186
    mov  [bgrdrawtype],eax
187
 
188
    mov  eax,39        ; get background size
189
    mov  ebx,1
190
    mcall
191
    mov  [bgrxy],eax
192
 
193
    mov  eax,70
194
    mov  ebx,finfo
195
    mcall
196
 
197
    mov  [itype],0
198
    cmp  word[I_END+256],'BM'
199
    je  @f
200
    inc  [itype]
201
  @@:
202
 
203
    mov  ebx,[yw]
204
    xor  ecx,ecx            ; 10608 = 52*68*3 - bg image
205
    mov  esi,I_END+256+9662 ; 9662 - icon file image
206
    mov  edi,51*3
207
 
208
  newb:
209
 
210
    push ebx ecx
211
 
212
  yesbpix:
213
 
214
    cmp   [bgrdrawtype],dword 2
215
    jne   nostretch
216
 
217
    mov   eax,[ypos]
218
    add   eax,ecx
219
    xor   edx,edx
220
    movzx ebx,word [bgrxy]
221
    mul   ebx
222
    xor   edx,edx
223
    movzx ebx,word [scrxy]
224
    div   ebx
225
    xor   edx,edx
226
    movzx ebx,word [bgrxy+2]
227
    mul   ebx
228
    push  eax
229
 
230
    mov   eax,[xpos]
231
    add   eax,[esp+8]
232
    xor   edx,edx
233
    movzx ebx,word [bgrxy+2]
234
    mul   ebx
235
    xor   edx,edx
236
    movzx ebx,word [scrxy+2]
237
    div   ebx
238
    add   eax,[esp]
239
    add   esp,4
240
 
241
  nostretch:
242
 
243
    cmp   [bgrdrawtype],dword 1
244
    jne   notiled
245
 
246
    mov  eax,[ypos]
247
    add  eax,ecx
248
    xor  edx,edx
249
    movzx ebx,word [bgrxy]
250
    div  ebx
251
    mov  eax,edx
252
    movzx  ebx,word [bgrxy+2]
253
    xor  edx,edx
254
    mul  ebx
255
    push eax
256
 
257
    mov  eax,[xpos]
258
    add  eax,[esp+8]
259
    movzx ebx,word [bgrxy+2]
260
    xor  edx,edx
261
    div  ebx
262
    mov  eax,edx
263
    add  eax,[esp]
264
    add  esp,4
265
 
266
  notiled:
267
 
268
    lea  ecx,[eax+eax*2]
269
 
270
    mov  eax,39
271
    mov  ebx,2
272
 
273
    mcall
274
 
275
  nobpix:
276
 
277
    pop  ecx ebx
278
 
279
    mov  [esi+edi+0],al
280
    mov  [esi+edi+1],ah
281
    shr  eax,16
282
    mov  [esi+edi+2],al
283
    sub  edi,3
284
 
285
    dec  ebx
286
    jge  newb
287
    mov  ebx,[yw]
288
 
289
    add  esi,52*3
290
    mov  edi,51*3
291
    inc  ecx
292
    cmp  ecx,68
293
    jne  newb
294
 
295
;*****************************************************************************
296
 
297
    mov  esi,I_END+256+9662+10608-17*52*3+3 ;! 54+32*3*33-3
298
    mov  eax,[iconstate]
299
    mov  eax,[add_table0+eax*4]
300
    add  esi,eax
301
    mov  edi,I_END+256+62
302
    cmp  [itype],0
303
    jne  @f
304
    mov  edi,I_END+256+54
305
  @@:
306
    xor  ebp,ebp
307
    mov  [pixl],0
308
  newp:
309
 
310
    virtual at edi
311
      r db ?
312
      g db ?
313
      b db ?
314
      a db ?
315
    end virtual
316
    virtual at esi+ebp
317
      ar db ?
318
      ag db ?
319
      ab db ?
320
    end virtual
321
 
322
    movzx ecx,[a]
323
 
324
    push  ebp
325
    cmp   [iconstate],3
326
    jb   @f
327
    neg   ebp
328
  @@:
329
 
330
    cmp  [itype],0
331
    jne  @f
332
    mov  eax,[edi]
333
    and  eax,$00FFFFFF
334
    jnz  @f
335
    jmp  no_transp
336
  @@:
337
 
338
    movzx eax,[r]
339
    cmp   [itype],0
340
    je   @f
341
    movzx ebx,byte[ar]
342
    sub   eax,ebx
343
    imul  eax,ecx
344
    xor   edx,edx
345
    or   ebx,$0FF
346
    div   ebx
347
    movzx ebx,[ar]
348
    add   eax,ebx
349
  @@:
350
    mov  [esi+ebp+0],al
351
 
352
    movzx eax,[g]
353
    cmp   [itype],0
354
    je   @f
355
    movzx ebx,[ag]
356
    sub   eax,ebx
357
    imul  eax,ecx
358
    xor   edx,edx
359
    or   ebx,$0FF
360
    div   ebx
361
    movzx ebx,[ag]
362
    add   eax,ebx
363
  @@:
364
    mov  [esi+ebp+1],al
365
 
366
    movzx eax,[b]
367
    cmp   [itype],0
368
    je   @f
369
    movzx ebx,[ab]
370
    sub   eax,ebx
371
    imul  eax,ecx
372
    xor   edx,edx
373
    or   ebx,$0FF
374
    div   ebx
375
    movzx ebx,[ab]
376
    add   eax,ebx
377
  @@:
378
    mov  [esi+ebp+2],al
379
 
380
  no_transp:
381
 
382
    pop   ebp
383
 
384
    movzx eax,[itype]
385
    imul  eax,6
386
    add   eax,[iconstate]
387
    push  eax
388
    mov   eax,[add_table1+eax*4]
389
    add   edi,eax
390
 
391
    add  ebp,3
392
    pop  eax
393
    mov  eax,[add_table2+eax*4]
394
    add  [pixl],eax
395
    cmp  [pixl],48
396
    jl  newp
397
    xor  ebp,ebp
398
    mov  [pixl],0
399
 
400
    sub  esi,52*3
401
    cmp  esi,I_END+256+9662+52*4*3
402
    jge  newp
403
 
404
;*****************************************************************************
405
 
406
    ret
407
 
408
draw_picture:
409
    mov  eax,7
410
    mov  ebx,I_END+256+9662
411
    mov  ecx,52 shl 16 + 68
412
    xor  edx,edx
413
    mcall
414
    ret
415
 
416
draw_icon:
417
    call draw_picture
418
    call draw_text
419
    ret
420
 
421
draw_text:
422
 
423
    mov   eax,labelt       ;text_length
424
  news:
425
    cmp   [eax],byte 40
426
    jb   founde
427
    inc   eax
428
    cmp   eax,labelt+11
429
    jb   news
430
   founde:
431
    sub   eax,labelt
432
 
433
    lea   eax,[eax+eax*2]  ; eax *= char_width/2
434
    shl   eax,16
435
    mov   ebx,26*65536+58
436
    sub   ebx,eax
437
    movzx ecx,byte [I_PARAM+8+30+30+10]
438
    shl   ecx,16
439
    add   ebx,ecx
440
 
441
; replaced - delete commented lines below if you like that style
442
    mov   eax,4          ; white text
443
 
444
    xor   ecx,ecx
445
    mov   edx,labelt
446
    mov   esi,labellen-labelt
447
    add   ebx,1 shl 16      ;*65536+1
448
    mcall
449
    inc   ebx
450
    mcall
451
    add   ebx,1 shl 16
452
    mcall
453
    inc   ebx
454
    mcall
455
    sub   ebx,1 shl 16
456
    mcall
503 heavyiron 457
    sub   ebx,1 shl 16 +1
485 heavyiron 458
    mcall
503 heavyiron 459
    sub   ebx,1 shl 16 + 1
485 heavyiron 460
    mcall
503 heavyiron 461
    add   ebx,1 shl 16 - 1
485 heavyiron 462
    mcall
463
    inc   ebx
464
    mov   ecx,0xffffff
465
    mcall
466
 
467
    ;xor   ecx,ecx        ; black shade of text
468
    ;mov   edx,labelt
469
    ;mov   esi,labellen-labelt
470
    ;add   ebx,1*65536+1
471
    ;mcall
472
    ;sub   ebx,1*65536+1
473
    ;mov   ecx,0xffffff
474
    ;mcall
475
 
476
    ret
477
 
478
 
479
; DATA AREA
480
 
481
itype       db 0
482
 
483
align 4
484
 
485
tl          dd  2
486
yw          dd  51
487
 
488
xpos        dd  15
489
ypos        dd  185
490
 
491
bgrxy       dd  0x0
492
scrxy       dd  0x0
493
bgrdrawtype dd  0x0
494
 
495
iconstate   dd 0
496
 
497
add_table0  dd (24-6*4)*3,(24-6*2)*3,(24-6*1)*3,\
498
               (24+6*1)*3,(24+6*2)*3,(24+6*4)*3
499
 
500
add_table1  dd 3,6,12,12,6,3
501
            dd 4,8,16,16,8,4
502
 
503
add_table2  dd 1,2,4,4,2,1
504
            dd 1,2,4,4,2,1
505
 
506
finfo_start:
507
            dd 7
508
            dd 0
509
            dd 0
510
            dd 0
511
            dd 0
512
            db 0
513
            dd start_file
514
 
515
finfo:
516
            dd 0
517
            dd 0
518
            dd 0
519
            dd 9662
520
            dd I_END+256
521
            db 0
522
            dd fname
523
 
524
start_file  rb  30
525
fname       rb  30
526
 
527
labelt:
528
            rb  10
529
labellen:
530
 
531
pixl dd ?
532
 
533
;include_debug_strings
534
I_PARAM:
535
 
536
I_END: