Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
205 heavyiron 1
;
2
;    BACKGROUND SET  - Compile with fasm
3
;
4
  use32
5
  org     0x0
6
  db      'MENUET01'    ; 8 byte id
7
  dd      0x01          ; version
8
  dd      START         ; program start
9
  dd      I_END         ; image size
451 heavyiron 10
  dd      0x80000       ; reguired amount of memory
205 heavyiron 11
  dd      0x80000       ; stack pointer
12
  dd      I_Param,0
13
 
14
  include 'lang.inc'
15
  include 'macros.inc'
16
 
17
START:
451 heavyiron 18
    mov  eax,48
19
    mov  ebx,3
20
    mov  ecx,sc
21
    mov  edx,sizeof.system_colors
22
    mcall
205 heavyiron 23
 
24
    call check_parameters
25
    call draw_window
26
 
27
    call load_texture
28
    call draw_image
29
 
451 heavyiron 30
 
205 heavyiron 31
still:
32
 
33
    mov  eax,10                 ; wait here for event
34
    int  0x40
35
    cmp  eax,1
36
    jz   red
37
    cmp  eax,2
38
    jz   key
39
    cmp  eax,3
40
    jz   button
41
    jmp  still
42
 
43
  key:
44
    mov  eax,2
45
    int  0x40
46
    jmp  still
47
 
48
  red:
49
    call draw_window
50
    jmp  still
51
 
52
  button:
53
    mov  eax,17
54
    int  0x40
55
 
56
    shr  eax,8
57
    and  eax,255
58
 
59
    cmp  eax,101                ; tiled
60
    jne  no101
61
    mov  eax,15
62
    mov  ebx,4
63
    mov  ecx,1
64
    int  0x40
65
    mov  eax,15
66
    mov  ebx,3
67
    int  0x40
68
    jmp  still
69
  no101:
70
 
71
    cmp  eax,102               ; stretch
72
    jne  no102
73
    mov  eax,15
74
    mov  ebx,4
75
    mov  ecx,2
76
    int  0x40
77
    mov  eax,15
78
    mov  ebx,3
79
    int  0x40
80
    jmp  still
81
  no102:
82
 
83
    cmp  eax,1           ; end program
84
    jnz  noproend
85
    or   eax,-1
86
    int  0x40
87
  noproend:
88
 
89
    cmp  eax,11
90
    jz   bg
91
    cmp  eax,12
92
    jz   bg
93
    cmp  eax,13
94
    jz   bg
95
 
96
    cmp  eax,121
97
    jb   no_bg_select
98
    cmp  eax,133
99
    jg   no_bg_select
100
    sub  eax,121
101
    shl  eax,2
102
    add  eax,arrays
103
    mov  eax,[eax]
104
    mov  [usearray],eax
105
    call load_texture
106
    call draw_image
107
    jmp  still
108
  no_bg_select:
109
 
110
    cmp  eax,14+20
111
    jge  bg4
112
 
113
    jmp  bg2
114
 
115
 
116
check_parameters:
117
 
118
    cmp  [I_Param],dword 'BOOT'
119
    je   @f
120
    ret
121
  @@:
122
 
123
    call load_texture
124
 
125
    mov  eax,15
126
    mov  ebx,1
127
    mov  ecx,256
128
    mov  edx,256
129
    int  0x40
130
 
131
    mov  eax,15
132
    mov  ebx,5
133
    mov  ecx,0x40000 ; <<< 0x40000 for blue, 0x40000+1 for red,
134
                       ; <<< 0x40000+2 for green background at boot
135
    mov  edx,0
136
    mov  esi,256*3*256
137
    int  0x40
138
 
139
    mov  eax,15
140
    mov  ebx,4
141
    mov  ecx,2
142
    int  0x40
143
 
144
    mov  eax,15
145
    mov  ebx,3
146
    int  0x40
147
 
148
    mov  eax,-1
149
    int  0x40
150
 
151
 
152
 
153
set_picture:
154
 
155
    mov  eax,image+99-3*16
156
    mov  ebx,0x40000+255*3+255*3*256
157
  newpix:
158
    mov  ecx,[eax]
159
    mov  [ebx],cx
160
    shr  ecx,16
161
    mov  [ebx+2],cl
162
    add  eax,3
163
    sub  ebx,3
164
    cmp  ebx,0x40002
165
    jge  newpix
166
 
167
    ret
168
 
169
 
170
load_texture:
171
 
172
    call  gentexture
173
    call  set_picture
174
 
175
    ret
176
 
177
 
178
; set background
179
 
180
bg:
181
 
182
    mov  edi,0x40000
183
 
184
    cmp  eax,12
185
    jnz  bb1
186
    mov  edi,0x40000+1
187
  bb1:
188
    cmp  eax,13
189
    jnz  bb2
190
    mov  edi,0x40000+2
191
  bb2:
192
 
193
    mov  eax,15
194
    mov  ebx,1
195
    mov  ecx,256
196
    mov  edx,256
197
    int  0x40
198
 
199
    mov  eax,15
200
    mov  ebx,5
201
    mov  ecx,edi
202
    mov  edx,0
203
    mov  esi,256*256*3
204
    int  0x40
205
 
206
    mov  eax,15
207
    mov  ebx,3
208
    int  0x40
209
 
210
    jmp  still
211
 
212
 
213
; colored background
214
 
215
bg2:
216
 
217
    push eax
218
 
219
    mov  eax,15
220
    mov  ebx,1
221
    mov  ecx,8
222
    mov  edx,8
223
    int  0x40
224
 
225
    mov  eax,[esp]
226
 
227
    sub  eax,14
228
    shl  eax,2
229
 
230
    mov  edx,[colors+eax]
231
 
232
    mov  esi,32*32*4
233
    mov  edi,0
234
    mov  ecx,0
235
  dbl2:
236
    mov  eax,15
237
    mov  ebx,2
238
    int  0x40
239
    add  ecx,3
240
    inc  edi
241
    cmp  edi,esi
242
    jb   dbl2
243
 
244
 
245
    mov  eax,15
246
    mov  ebx,3
247
    int  0x40
248
 
249
    jmp  still
250
 
251
 
252
; shaped background
253
 
254
bg4:
255
 
256
    sub  eax,14+20
257
    shl  eax,3
258
    add  eax,shape
259
    mov  ecx,[eax+0]
260
    mov  edx,[eax+4]
261
 
262
    mov  eax,15
263
    mov  ebx,1
264
    int  0x40
265
 
266
    mov  eax,15
267
    mov  ebx,3
268
    int  0x40
269
 
270
    jmp  still
271
 
272
 
273
; *********************************************
274
; ******* CELLULAR TEXTURE GENERATION *********
275
; **** by Cesare Castiglia (dixan/sk/mfx) *****
276
; ********* dixan@spinningkids.org   **********
277
; *********************************************
278
; * the algorythm is kinda simple. the color  *
279
; * component for every pixel is evaluated    *
280
; * according to the squared distance from    *
281
; * the closest point in 'ptarray'.           *
282
; *********************************************
283
 
284
gentexture:
285
 
286
  mov ecx,0          ; ycounter
287
  mov edi,0          ; pixel counter
288
 
289
  mov ebp,[usearray]
290
 
291
 ylup:
292
    mov ebx,0
293
 
294
 xlup:
295
  push edi
296
  mov edi, 0
297
  mov esi, 512000000           ; abnormous initial value :)
298
 
299
 pixlup:
300
   push esi
301
   mov eax,ebx                 ; evaluate first distance
302
   sub eax, [ebp+edi]          ; x-x1
303
   call wrappit
304
   imul eax
305
   mov esi, eax                ; (x-x1)^2
306
   mov eax, ecx
307
   add edi,4
308
   sub eax, [ebp+edi]          ; y-y1
309
   call wrappit
310
   imul eax                    ; (y-y1)^2
311
   add eax,esi                 ; (x-x1)^2+(y-y1)^2
312
   pop esi
313
 
314
   cmp esi,eax
315
   jb  ok                      ; compare and take the smaller one
316
   mov esi,eax
317
 
318
  ok:
319
   add edi,4
320
   cmp [ebp+edi],dword 777
321
   jne pixlup
322
 
323
   mov eax,esi                 ; now evaluate color...
324
 
325
   mov edi,24            ; 50 = max shaded distance
326
   idiv edi
327
 
328
   pop edi
329
   mov [image+51+edi],eax
330
   add edi,3
331
 
332
  add ebx,1              ; bounce x loop
333
  cmp ebx,256            ; xsize
334
  jne xlup
335
 
336
  add ecx,1
337
  cmp ecx,256            ; ysize
338
  jne ylup
339
 
340
  ret
341
 
342
wrappit:
343
  cmp eax,0              ; this makes the texture wrap
344
  jg noabs
345
  neg eax
346
  noabs:
347
  cmp eax,128
348
  jb nowrap
349
  neg eax
350
  add eax,256
351
  nowrap:
352
  ret
353
 
354
; *********************************************
355
; ******* WINDOW DEFINITIONS AND DRAW *********
356
; *********************************************
357
 
358
 
359
draw_image:
360
 
361
    mov  eax,7
362
    mov  ebx,0x40000
363
    mov  ecx,256*65536+255
451 heavyiron 364
    mov  edx,14*65536+40;55
205 heavyiron 365
    int  0x40
366
 
367
    ret
368
 
369
 
451 heavyiron 370
y_add  equ  19 ; 30
205 heavyiron 371
y_s    equ  13
372
 
451 heavyiron 373
y_add2 equ  315 ;325
205 heavyiron 374
set    equ  0 ;15
375
 
376
draw_window:
377
 
378
    mov eax, 12                   ; tell os about draw
379
    mov ebx, 1
380
    int 0x40
381
 
451 heavyiron 382
    xor eax, eax                    ; define and draw window
205 heavyiron 383
    mov ebx, 220*65536+293
384
    mov ecx, 50*65536+408
451 heavyiron 385
    mov edx, [sc.work]
386
    or  edx, 0x33000000
387
    mov edi, header
205 heavyiron 388
    int 0x40
389
 
390
    call draw_image
391
 
392
    mov  eax,8                     ; Blue button
451 heavyiron 393
    mov  ebx,(set+190+27)*65536+17
205 heavyiron 394
    mov  ecx,y_add*65536+y_s
395
    mov  edx,11
451 heavyiron 396
    mov  esi,0x005555bb
205 heavyiron 397
    int  0x40
451 heavyiron 398
    ;mov  eax,8                     ; Red button
399
    mov  ebx,(set+208+27)*65536+17
205 heavyiron 400
    mov  edx,12
451 heavyiron 401
    mov  esi,0x00bb5555
205 heavyiron 402
    int  0x40
451 heavyiron 403
    ;mov  eax,8                     ; Green button
404
    mov  ebx,(set+253)*65536+17
205 heavyiron 405
    mov  edx,13
451 heavyiron 406
    mov  esi,0x0055bb55
205 heavyiron 407
    int  0x40
408
 
451 heavyiron 409
    ;mov  eax, 8                     ; tiled
410
    mov  ebx, 90*65536+63
205 heavyiron 411
    mov  ecx, y_add*65536+y_s
412
    mov  edx, 101
451 heavyiron 413
    mov  esi, [sc.work_button]
205 heavyiron 414
    int  0x40
415
 
451 heavyiron 416
    ;mov  eax, 8                     ; stretch
417
    mov  ebx, 154*65536+61
205 heavyiron 418
    mov  edx, 102
419
    int  0x40
420
 
451 heavyiron 421
    mov  eax, 4
422
    mov  ebx, 215*65536+5
423
    mov  ecx, [sc.work_text]
205 heavyiron 424
    mov  edx, apply_text
425
    mov  esi, apply_text.size
426
    int  0x40
427
 
451 heavyiron 428
    mov  ebx, 14*65536+301
205 heavyiron 429
    mov  edx, image_buttons_text
430
    mov  esi, image_buttons_text.size
431
    int  0x40
432
 
451 heavyiron 433
    mov  ebx, 14*65536+(y_add2+27)
205 heavyiron 434
    mov  edx, simple_text
435
    mov  esi, simple_text.size
436
    int  0x40
437
 
438
    mov  ecx, (y_add2)*65536+20
451 heavyiron 439
    mov  ebx, (13)*65536+25
205 heavyiron 440
    mov  edx, 121
451 heavyiron 441
    mov  esi, [sc.work_button]
205 heavyiron 442
    mov  edi, 9
443
    mov  eax, 8
444
  @@:
445
    int  0x40
446
    add  ebx, 29*65536
447
    inc  edx
448
    dec  edi
449
    jnz  @b
450
 
451
 
452
    mov  edx, 34+4
453
    mov  edi, 4
454
    mov  eax, 8
451 heavyiron 455
    mov  ebx, 13*65536+18
205 heavyiron 456
    mov  ecx, y_add*65536+y_s
457
  @@:
458
    int  0x40
459
    inc  edx
460
    add  ebx, 19*65536
461
    dec  edi
462
    jnz  @b
463
 
464
 
465
    ;-----------------------
451 heavyiron 466
    mov  edx,14                            ; button number
467
    mov  ebx,(13)*65536+17                 ; button start x & size
205 heavyiron 468
    mov  ecx,(y_add2+40)*65536+14          ; button start y & size
469
 
470
  newcb:
471
    mov  esi,[(edx-14)*4+colors]
472
 
473
    mov  eax,8
474
    int  0x40
475
 
476
    inc  edx
477
    add  ebx,20*65536
478
    add  esi,5*256*256
479
 
480
    cmp  edx,27
481
    jnz  newcb
482
    ;-----------------------
483
 
484
    mov  eax, 4
451 heavyiron 485
    mov  ebx, 94*65536+4+y_add
486
    mov  ecx, [sc.work_button_text]
205 heavyiron 487
    mov  edx, la2
488
    mov  esi, la2.size
489
    int  0x40
490
 
491
    mov  eax,12
492
    mov  ebx,2
493
    int  0x40
494
 
495
    ret
496
 
497
 
498
 
499
; DATA SECTION
500
 
451 heavyiron 501
if lang eq ru
502
    header db 'Генератор фона рабочего стола',0
503
else
504
    header db 'Background',0
505
end if
205 heavyiron 506
 
507
lsz apply_text,\
508
    ru, "Применить:",\
509
    en, "Apply:"
510
 
511
lsz image_buttons_text,\
512
    ru, "Выберите образец:",\
513
    en, "Select pattern:"
514
 
515
lsz simple_text,\
516
    ru, "Одноцветный фон:",\
517
    en, "Single-color background:"
518
 
519
lsz la2,\
451 heavyiron 520
    ru, "ЗАМОСТИТЬ  РАСТЯНУТЬ",\
521
    en, "  TILED     STRETCH"
205 heavyiron 522
 
523
 
524
xx   db    'x'
525
 
526
colors:
527
    dd  0x770000
528
    dd  0x007700
529
    dd  0x000077
530
    dd  0x777700
531
    dd  0x770077
532
    dd  0x007777
533
    dd  0x777777
534
    dd  0x335577
535
    dd  0x775533
536
    dd  0x773355
537
    dd  0x553377
538
    dd  0x000000
539
    dd  0xcccccc
540
 
541
 
542
shape:
543
 
544
    dd  1024,64
545
    dd  1024,32
546
    dd  2048,32
547
    dd  4096,32
548
 
549
    dd  512,16
550
    dd  1024,16
551
    dd  2048,16
552
    dd  4096,16
553
 
554
    dd  64,32
555
    dd  64,16
556
    dd  32,32
557
    dd  8,8
558
    dd  16,16
559
    dd  64,64
560
 
561
usearray dd ptarray
562
 
563
arrays dd ptarray,ptarray2,ptarray3,ptarray4,ptarray5,ptarray6
564
        dd ptarray7,ptarray8,ptarray9
565
 
566
ptarray:
567
 
568
    dd  150,50
569
    dd  120,30
570
    dd  44,180
571
    dd  50,66
572
    dd  27,6
573
    dd  95,212
574
    dd  128,177
575
    dd  201,212
576
    dd  172,201
577
    dd  250,100
578
    dd  24,221
579
    dd  11,123
580
    dd  248,32
581
    dd  34,21
582
    dd  777     ; <- end of array
583
 
584
ptarray2:
585
 
586
    dd  0,0,50,50,100,100,150,150,200,200,250,250
587
    dd  50,150,150,50,200,100,100,200
588
    dd  777
589
 
590
ptarray3:
591
 
592
    dd  55,150,150,55,200,105,105,200
593
    dd  30,30,220,220
594
    dd  777
595
 
596
ptarray4:
597
 
598
    dd  196,0,196,64,196,128,196,196
599
    dd  64,32,64,96,64,150,64,228
600
    dd  777
601
 
602
ptarray5:
603
 
604
    dd  196,0,196,64,196,128,196,196
605
    dd  64,0,64,64,64,128,64,196
606
    dd  777
607
 
608
ptarray6:
609
 
610
    dd  49,49,128,50,210,50
611
    dd  50,128,128,128,210,128
612
    dd  50,210,128,210,210,210
613
 
614
    dd  777
615
 
616
ptarray7:
617
 
618
    dd  0,0
619
    dd  196,196,64,64
620
    dd  128,0
621
    dd  0,128
622
    dd  64,64,196,64
623
    dd  196,196,64,196
624
    dd  128,128
625
 
626
    dd  777
627
 
628
ptarray8:
629
 
630
    dd  0, 128
631
    dd  0, 128
632
    dd  128, 0
633
    dd  0, 128
634
    dd  128, 0
635
    dd  0, 128
636
    dd  128, 0
637
    dd  0, 128
638
    dd  128, 0
639
    dd  128, 128
640
 
641
    dd  777
642
 
643
ptarray9:
644
 
645
 
646
     dd  0,248,64,128,128,64,196,48,160,160,94,224,240,96,5,5,777
647
 
648
 
649
I_Param:
650
 
651
image:
652
 
451 heavyiron 653
I_END:
205 heavyiron 654
 
451 heavyiron 655
sc system_colors