Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
lang equ ru
2
 
3
;
4
;   Assembler
5
;     SMALL
6
;       CODE
7
;         Graphics
8
;           Libary
9
;
10
;   Ver 0.10 By Pavlushin Evgeni (RUSSIA)
11
;   www.waptap@mail.ru
12
 
13
;InfoList
14
;0.01 LoadImage
15
;0.02 SetBmp
16
;0.03 Bmptoimg, Setimg ~01.03.2004
17
;0.04 Bug deleted, copyimg ~03.05.2004
18
;0.05 fullimg, collimg ~05.05.2004
19
;0.06 getimg ~09.05.2004
20
;0.07 convbmp ~13.05.2004
21
;0.08 fps ~14.05.2004
22
;0.09 drawfbox ~03.06.2004
23
;0.10 all macros optimized by halyavin, add at ~07.06.2004
24
 
25
;DrawBox
26
macro drawfbox x,y,xs,ys,color
27
{
28
    mov  ecx,y
29
    mov  ebx,x
30
    shl  ebx,16
31
    add  ebx,xs
32
    shl  ecx,16
33
    add  ecx,ys
34
    mov  edx,color
35
    mov  eax,13
485 heavyiron 36
    mcall
31 halyavin 37
}
38
 
39
; FPS - Set Frame Per Second Display
40
fps_show_frequency=40
41
macro fps x,y,color,delcolor
42
{
43
local spdat,savetime,new_time,fps,fps_cntr,out_fps,new_time,ttt
44
local no_out_fps
45
    jmp spdat
46
savetime dd 0
47
fps_cntr dd 0
48
fps      dd 0
49
ttt      dd 0
50
spdat:
51
get_time:
52
    mov eax,3
485 heavyiron 53
    mcall
31 halyavin 54
    cmp eax,[savetime]
55
    jne new_time
56
    inc [fps_cntr]
57
    cmp dword [ttt],0
58
    je  out_fps
59
    dec dword [ttt]
60
    jmp no_out_fps
61
new_time:
62
    mov [savetime],eax
63
    mov ebx,[fps_cntr]
64
    mov [fps],ebx
65
    mov [fps_cntr],0
66
out_fps:
67
if ~(delcolor eq )
68
    mov ebx,x*65536+30
69
    mov ecx,y*65536+7
70
    mov edx,delcolor
71
    mov eax,13
485 heavyiron 72
    mcall
31 halyavin 73
end if
74
    mov dword [ttt],fps_show_frequency
75
    mov eax,47
76
    mov ebx,5*65536
77
;   mov bl,0
78
    mov edx,x*65536+y
79
    mov esi,color
80
    mov ecx,[fps]
485 heavyiron 81
    mcall
31 halyavin 82
no_out_fps:
83
}
84
 
85
 
86
 
87
; COLLIMG - Collusion image's
88
_1dbounce_count=0;
89
macro collimg img1_off,x1,y1,img2_off,x2,y2,otv
90
{
91
local bounce,exit,anot,bc,nbc
92
	mov esi,[img1_off] ;xs1
93
	mov edi,[img2_off] ;ys2
94
	mov eax,x1 ;
95
	mov ebx,x2 ;
96
	call _1dbounce
97
	mov edx,ecx
98
	mov esi,[img1_off+4] ;ys1
99
	mov edi,[img2_off+4] ;ys2
100
	mov eax,y1 ;
101
	mov ebx,y2 ;
102
	call _1dbounce
103
	add edx,ecx
104
	cmp edx,2
105
	je bounce
106
	mov otv,0
107
	jmp exit
108
_1dbounce_count=_1dbounce_count+1
109
if (_1dbounce_count = 1)
110
_1dbounce:
111
	cmp ebx,eax
112
	jnae anot
113
	add eax,esi
114
	cmp eax,ebx
115
	jna nbc
116
	jmp bc
117
anot:
118
    add ebx,edi
119
	cmp ebx,eax
120
	jna nbc
121
bc:
122
    mov ecx,1
123
	ret
124
nbc:
125
	mov ecx,0
126
	ret
127
end if
128
bounce:
129
	mov otv,1
130
exit:
131
}
132
 
133
; SETBMP -  Set bmp to window
134
; (SYNTAX)  SETBMP dd xstart ,dd ystart ,BMP_offset,dd soi
135
; (SAMPLE)  SETBMP dword [xt],dword [yt],I_END,dword [tsoi]
136
;           SETBMP 15,10,I_END,dword [tsoi]
137
; ( NOTE )  SOI - Start of image
138
 
139
macro setbmp arg1,arg2,arg3,arg4
140
{
141
local nodi
142
    cmp  word [arg3],word 'BM'
143
    jne  nodi
144
    mov  eax,7
145
    mov  ebx,arg4 ;[soi]
146
    mov  ecx,dword [arg3+18]
147
    shl  ecx,16
148
    add  ecx,dword [arg3+22]
149
if (arg1 eqtype 0) & (arg2 eqtype 0)
150
    mov  edx,arg1*65536+arg2
151
else
152
    mov  edx,arg1
153
    shl  edx,16
154
    add  edx,arg2
155
end if
485 heavyiron 156
    mcall
31 halyavin 157
  nodi:
158
}
159
 
160
macro setimg arg1,arg2,arg3
161
{
162
local nodi
163
    mov  eax,7
164
    mov  ebx,arg3
165
    add  ebx,8
166
    mov  ecx,dword [arg3]
167
    shl  ecx,16
168
    add  ecx,dword [arg3+4]
169
if (arg1 eqtype 0) & (arg2 eqtype 0)
170
    mov  edx,arg1*65536+arg2
171
else
172
    mov  edx,arg1
173
    shl  edx,16
174
    add  edx,arg2
175
end if
485 heavyiron 176
    mcall
31 halyavin 177
}
178
 
179
;Not optimiz
180
macro getimg imgsrc,x,y,xs,ys,imgdest
181
{
182
local cyc
183
    mov eax,xs
184
    mov dword [imgdest],eax
185
    mov eax,ys
186
    mov dword [imgdest+4],eax
187
 
188
    mov eax,dword [imgsrc] ;getx size
189
    mov edi,eax
190
    mov ebx,y
191
    mul ebx
192
    add eax,x
193
    mov ebx,3
194
    mul ebx     ;eax=offset on imsrc
195
 
196
    mov ecx,0
197
    mov ebx,0
198
    mov ebp,eax
199
    mov esi,0
200
 
201
    add esi,8
202
    add ebp,8
203
 
204
cyc:
205
    mov al,byte [imgsrc+ebp]
206
    mov [imgdest+esi],al
207
    mov al,byte [imgsrc+ebp+1]
208
    mov [imgdest+esi+1],al
209
    mov al,byte [imgsrc+ebp+2]
210
    mov [imgdest+esi+2],al
211
    add esi,3
212
    add ebp,3
213
    inc ecx
214
    cmp ecx,xs
215
    jne cyc
216
    add ebp,edi
217
    add ebp,edi
218
    add ebp,edi
219
    sub ebp,xs
220
    sub ebp,xs
221
    sub ebp,xs
222
    mov ecx,0
223
    inc ebx
224
    cmp ebx,ys
225
    jne cyc
226
 
227
}
228
 
229
;
230
macro bmptoimg bmp_off,soi,img_off
231
{
232
local nodix,conv
233
    cmp  word [bmp_off],word 'BM'
234
    jne  nodix
235
    mov  eax,dword [bmp_off+18]
236
    mov  ebx,dword [bmp_off+22]
237
    mov  dword [img_off],eax
238
    mov  dword [img_off+4],ebx
239
    mul  ebx
240
    lea  ecx,[eax+2*eax]
241
    lea  edi,[img_off+8]
242
    mov  esi,dword [soi]
243
    cld
244
    rep  movsb
245
nodix:
246
}
247
 
248
macro copyimg img2_off,img1_off
249
{
250
local cop
251
    mov  eax,dword [img1_off]
252
    mov  ebx,dword [img1_off+4]
253
    mul  ebx
254
    lea  ecx,[eax+2*eax]
255
    lea  esi,[img1_off+8]
256
    lea  edi,[img2_off+8]
257
    cld
258
    rep  movsb
259
}
260
 
261
macro fullimg img_off,xs,ys,color
262
{
263
local cop
264
    mov eax,xs
265
    mov ebx,ys
266
    mov  dword [img_off],eax
267
    mov  dword [img_off+4],ebx
268
    mul  ebx
269
    lea  ebp,[eax+2*eax]
270
    mov  esi,color
271
if color eqtype 0
272
    mov  ecx,color/65536
273
else
274
    mov  ecx,esi
275
    shr  ecx,16
276
end if
277
    xor  edi,edi
278
cop:
279
    mov  word [img_off+8+edi],si
280
    add  edi,2
281
    mov  byte [img_off+8+edi],cl
282
    inc  edi
283
    cmp  edi,ebp
284
    jne  cop
285
}
286
 
287
 
288
 
289
 
290
macro convbmp bmp_load_area,bmp_soi
291
{
292
local status,bps,dwps,soi,sop,eop,eos,process,fileinfo,string,end_bmp
293
local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
294
local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
295
local noaddword
296
;local qwe,bmpfn
297
 
298
;  convert:
299
    movzx eax,word [bmp_load_area+28]
300
    mul  dword [bmp_load_area+18]
301
    mov  ebx,32
302
    div  ebx
303
    test edx,edx
304
    je   noaddword
305
    inc  eax
306
  noaddword:
307
    mov  dword [dwps],eax  ;dwps-doublewords per string
308
    shl  eax,2
309
    mov  dword [bps],eax   ;bps-bytes per string
310
 
311
    cmp dword [bmp_load_area+34],0
312
    jne  yespicsize  ;if picture size is defined
313
    mul dword [bmp_load_area+22]
314
    mov dword [bmp_load_area+34],eax
315
 
316
  yespicsize:
317
    mov  eax,bmp_load_area
318
    mov  ebx,eax
319
    add  ebx, [bmp_load_area+2];file size
320
    inc  ebx
321
    mov  dword [bmp_soi],ebx   ;soi-start of image area for drawing
322
    add  eax, [bmp_load_area+10]
323
    mov  dword [sop],eax   ;sop-start of picture in file
324
    add  eax, [bmp_load_area+34]
325
    mov  dword [eop],eax   ;eop-end of picture in file
326
    mov  eax, [bmp_load_area+18]
327
    lea  eax,[eax+2*eax]   ;3x pixels in eax
328
 
329
    mov  edi,dword [bmp_soi]   ;initializing
330
    mov  esi,dword [eop]
331
    sub  esi,dword [bps]
332
 
333
 
334
  nextstring:
335
    push edi
336
    cmp  word [bmp_load_area+28],24
337
    jne  convertno32
338
 
339
    mov  ecx,[dwps]
340
    cld
341
    rep movsd
342
  convert1:
343
    pop  edi
344
    sub  esi,dword [bps]
345
    sub  esi,dword [bps]
346
    cmp  esi,dword [sop]
347
    jb   end_bmp;nomorestring
348
    add  edi,eax
349
    jmp  nextstring
350
 
351
;  nomorestring:
352
;    jmp end_bmp
353
 
354
  convertno32:
355
    mov  ebx,bmp_load_area
356
    add  ebx, [bmp_load_area+14]
357
    add  ebx,14          ;start of color table
358
    push esi
359
    add  esi,dword [bps]
360
    mov  dword [eos],esi
361
    pop  esi
362
  nextelem:
363
    push eax
364
    movzx eax,byte [esi]
365
    cmp  word [bmp_load_area+28],4
366
    je   convert4bpp
367
    cmp  word [bmp_load_area+28],1
368
    je   convert1bpp
369
    call converttable
370
  convert2:
371
    pop  eax
372
    inc  esi
373
    cmp  esi,dword [eos]
374
    jae  convert1
375
    add  edi,3
376
    jmp  nextelem
377
 
378
  convert4bpp:
379
    shl  ax,4
380
    shr  al,4
381
    push ax
382
    movzx eax,ah
383
    call converttable
384
    add  edi,3
385
    pop  ax
386
    movzx eax,al
387
    call converttable
388
    jmp  convert2
389
 
390
  convert1bpp:
391
    mov  ecx,eax
392
    mov  edx,7
393
  nextbit:
394
    xor  eax,eax
395
    bt   ecx,edx
396
    jnc  noaddelem
397
    inc  eax
398
  noaddelem:
399
    push edx
400
    call converttable
401
    pop  edx
402
    dec  edx
403
    cmp  edx,0xffffffff
404
    je   convert2
405
    add  edi,3
406
    jmp  nextbit
407
 
408
  converttable:
409
    shl  eax,2
410
    add  eax,ebx
411
    mov  edx, dword [eax]
412
    mov  dword [edi],edx
413
    ret
414
 
415
 
416
; DATA AREA
417
 
418
;status   dd 0  ;bit0=1 if file thread is created
419
bps      dd 0
420
dwps     dd 0
421
;soi      dd 0
422
sop      dd 0
423
eop      dd 0
424
eos      dd 0
425
;process  dd 0
426
 
427
end_bmp:
428
;    mov eax,dword [soi]
429
;    mov dword [bmp_soi],eax
430
 
431
}
432
 
433
 
434
 
435
 
436
; LOADBMP - Load bmp image from file
437
; (SYNTAX)  LOADBMP 'file_path',temp_area(rb 0x10000),load_area,dd soi
438
; (SAMPLE)  LOADBMP '/rd/1/menuet.bmp',temp_area,I_END,tsoi
439
; ( NOTE )  Macros create on Base of
440
;           Picture browser by lisovin@26.ru & Ivan Poddubny
441
;           SOI - Start of image
442
 
443
macro loadbmp bmp_file_name,bmp_temp_area,bmp_load_area,bmp_soi
444
{
445
local status,bps,dwps,soi,sop,eop,eos,process,fileinfo,string,end_bmp
446
local converttable,noaddelem,nextbit,convert1bpp,convert4bpp,convert2
447
local nextelem,convertno32,nomorestring,convert1,nextstring,yespicsize
448
local noaddword
449
;local qwe,bmpfn
450
 
451
    mov  dword [fileinfo+8],1 ; how many blocks to read (1)
452
    mov  eax,58
453
    mov  ebx,fileinfo
485 heavyiron 454
    mcall
31 halyavin 455
    mov  eax,[bmp_load_area+2]
456
    shr  eax,9 ; поделим на 512 и прибавим 1 - получим число блоков
457
    inc  eax
458
    mov  dword [fileinfo+8],eax
459
    mov  eax,58
460
    mov  ebx,fileinfo
485 heavyiron 461
    mcall
31 halyavin 462
 
463
;     jmp  qwe
464
;bmpfn db bmp_file_name
465
;qwe:
466
;     mov eax,6
467
;     mov ebx,bmpfn
468
;     mov ecx,0
469
;     mov edx,0xFFFFFF
470
;     mov esi,bmp_load_area
471
;     mov edi,0
485 heavyiron 472
;     mcall
31 halyavin 473
 
474
;  convert:
475
    movzx eax,word [bmp_load_area+28]
476
    mul dword [bmp_load_area+18]
477
    mov  ebx,32
478
    div  ebx
479
    test edx,edx
480
    je   noaddword
481
    inc  eax
482
  noaddword:
483
    mov  dword [dwps],eax  ;dwps-doublewords per string
484
    shl  eax,2
485
    mov  dword [bps],eax   ;bps-bytes per string
486
 
487
    cmp dword [bmp_load_area+34],0
488
    jne  yespicsize  ;if picture size is defined
489
    mul dword [bmp_load_area+22]
490
    mov dword [bmp_load_area+34],eax
491
 
492
  yespicsize:
493
    mov  eax,bmp_load_area
494
    push eax
495
    add  eax, [bmp_load_area+2];file size
496
    inc  eax
497
    mov  dword [soi],eax   ;soi-start of image area for drawing
498
    pop  eax
499
    add  eax, [bmp_load_area+10]
500
    mov  dword [sop],eax   ;sop-start of picture in file
501
    add  eax, [bmp_load_area+34]
502
    mov  dword [eop],eax   ;eop-end of picture in file
503
    mov  eax, [bmp_load_area+18]
504
    mov  ebx,3
505
    mul  ebx             ;3x pixels in eax
506
 
507
    mov  edi,dword [soi]   ;initializing
508
    mov  esi,dword [eop]
509
    sub  esi,dword [bps]
510
 
511
 
512
  nextstring:
513
    push edi
514
    cmp word [bmp_load_area+28],24
515
    jne  convertno32
516
 
517
    mov  ecx,[dwps]
518
    cld
519
    rep movsd
520
  convert1:
521
    pop  edi
522
    sub  esi,dword [bps]
523
    sub  esi,dword [bps]
524
    cmp  esi,dword [sop]
525
    jb   nomorestring
526
    add  edi,eax
527
    jmp  nextstring
528
 
529
  nomorestring:
530
    jmp end_bmp
531
 
532
  convertno32:
533
    mov  ebx,bmp_load_area
534
    add  ebx, [bmp_load_area+14]
535
    add  ebx,14          ;start of color table
536
    push esi
537
    add  esi,dword [bps]
538
    mov  dword [eos],esi
539
    pop  esi
540
  nextelem:
541
    push eax
542
    movzx eax,byte [esi]
543
    cmp word [bmp_load_area+28],4
544
    je   convert4bpp
545
    cmp word [bmp_load_area+28],1
546
    je   convert1bpp
547
    call converttable
548
  convert2:
549
    pop  eax
550
    inc  esi
551
    cmp  esi,dword [eos]
552
    jae  convert1
553
    add  edi,3
554
    jmp  nextelem
555
 
556
  convert4bpp:
557
    shl  ax,4
558
    shr  al,4
559
    push ax
560
    movzx eax,ah
561
    call converttable
562
    add  edi,3
563
    pop  ax
564
    movzx eax,al
565
    call converttable
566
    jmp  convert2
567
 
568
  convert1bpp:
569
    mov  ecx,eax
570
    mov  edx,7
571
  nextbit:
572
    xor  eax,eax
573
    bt   ecx,edx
574
    jnc  noaddelem
575
    inc  eax
576
  noaddelem:
577
    push edx
578
    call converttable
579
    pop  edx
580
    dec  edx
581
    cmp  edx,0xffffffff
582
    je   convert2
583
    add  edi,3
584
    jmp  nextbit
585
 
586
  converttable:
587
    shl  eax,2
588
    add  eax,ebx
589
    mov  edx, dword [eax]
590
    mov  dword [edi],edx
591
    ret
592
 
593
 
594
; DATA AREA
595
 
596
;status   dd 0  ;bit0=1 if file thread is created
597
bps      dd 0
598
dwps     dd 0
599
soi      dd 0
600
sop      dd 0
601
eop      dd 0
602
eos      dd 0
603
;process  dd 0
604
 
605
; DATA AREA
606
fileinfo:
607
     dd 0
608
     dd 0
609
     dd 1          ;number of blocks  of 512 bytes
610
     dd bmp_load_area
611
     dd bmp_temp_area
612
string:
613
  db bmp_file_name,0
614
  db '                                            '
615
  db '                                            '
616
  db '                                            '
617
  db '                                            ',0
618
 
619
 
620
end_bmp:
621
    mov eax,dword [soi]
622
    mov dword [bmp_soi],eax
623
 
624
}