Subversion Repositories Kolibri OS

Rev

Rev 6619 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6619 Rev 6648
Line 1... Line 1...
1
; application : View3ds ver. 0.066 - tiny .3ds and .asc files viewer
1
; application : View3ds ver. 0.067 - tiny .3ds and .asc files viewer
2
;		with a few graphics effects demonstration.
2
;               with a few graphics effects demonstration.
3
; compiler    : FASM
3
; compiler    : FASM
4
; system      : KolibriOS
4
; system      : KolibriOS
5
; author      : Macgub aka Maciej Guba
5
; author      : Macgub aka Maciej Guba
6
; email       : macgub3@wp.pl
6
; email       : macgub3@wp.pl
Line 52... Line 52...
52
	dd     0x0		; I_Icon
52
	dd     0x0		; I_Icon
53
 
53
 
Line 54... Line 54...
54
START:	  ; start of execution
54
START:	  ; start of execution
55
	cld
55
	cld
56
	mov    eax,14
56
     ;   mov    eax,14   ; window size according to cur res ...
57
	int    0x40
57
     ;   int    0x40
58
	sub    eax,150 shl 16 + 150
58
     ;   sub    eax,150 shl 16 + 150
-
 
59
	mov    eax, 600 shl 16 + 600 ; ... or set manually
59
	mov    [size_y_var],ax
60
	mov    [size_y_var],ax
60
	shr    ax,1
61
	shr    ax,1
61
	mov    [vect_y],ax
62
	mov    [vect_y],ax
Line -... Line 63...
-
 
63
 
62
 
64
 
63
	shr    ax,1
65
	shr    ax,2
-
 
66
	movzx  ebx,ax
64
	movzx  ebx,ax
67
	lea    ebx,[ebx*3]
65
	push   ebx
68
	push   ebx
66
	fninit
69
	fninit
67
	fild   dword[esp]
70
	fild   dword[esp]
68
	fstp   [rsscale]
71
	fstp   [rsscale]
Line 72... Line 75...
72
	mov    [size_x_var],ax
75
	mov    [size_x_var],ax
73
	shr    ax,1
76
	shr    ax,1
74
	mov    [vect_x],ax
77
	mov    [vect_x],ax
75
 
78
 
Line -... Line 79...
-
 
79
	mov    eax, 20 shl  16 + 20
-
 
80
	mov    [x_start],eax
-
 
81
 
Line 76... Line 82...
76
 
82
 
77
	call   alloc_buffer_mem
83
	call   alloc_buffer_mem
78
	call   read_param
84
	call   read_param
79
	call   read_from_disk	 ; read, if all is ok eax = 0
85
	call   read_from_disk	 ; read, if all is ok eax = 0
Line 105... Line 111...
105
	call   alloc_mem_for_tp
111
	call   alloc_mem_for_tp
106
     end if
112
     end if
107
	call   read_from_file
113
	call   read_from_file
108
    .opt:
114
    .opt:
109
	call   optimize_object1     ;  proc in file b_procs.asm
115
 
-
 
116
 
-
 
117
     ;   call   alloc_buffer_mem ; alloc memfor screnn and z buffer
-
 
118
 
-
 
119
	call   optimize_object1     ;  proc in file b_procs.asm
110
				    ;  set point(0,0,0) in center and  calc all coords
120
				    ;  set point(0,0,0) in center and  calc all coords
111
				    ;  to be in <-1.0,1.0>
121
				    ;  to be in <-1.0,1.0>
112
	call   normalize_all_light_vectors
122
	call   normalize_all_light_vectors
113
	call   init_triangles_normals2
123
	call   init_triangles_normals2
114
	call   init_point_normals
124
	call   init_point_normals
115
	call   init_envmap2
125
	call   init_envmap2
116
	call   init_envmap_cub
126
	call   init_envmap_cub
117
	call   generate_texture2
127
	call   generate_texture2
118
	call   init_sincos_tab
128
	call   init_sincos_tab
119
 
129
	call   do_color_buffer	 ; intit color_map
120
	call   do_color_buffer	 ; intit color_map
-
 
121
	mov    edi,bumpmap
130
	mov    edi,bumpmap
122
	call   calc_bumpmap
131
	call   calc_bumpmap
123
	call   calc_bumpmap_coords   ; bump and texture mapping
132
	call   calc_bumpmap_coords   ; bump and texture mapping
124
	call   draw_window
133
	call   draw_window
125
 
134
	mov	[draw_win_at_first],0
-
 
135
 
Line 126... Line 136...
126
still:
136
still:
Line 127... Line 137...
127
 
137
 
128
	mov	eax,23		; wait here for event with timeout
138
	mov	eax,23		; wait here for event with timeout
Line 142... Line 152...
142
 
152
 
Line 143... Line 153...
143
	jmp	noclose
153
	jmp	noclose
Line 144... Line 154...
144
 
154
 
-
 
155
    red:   ; redraw
-
 
156
	mov	eax,9  ; get process info
-
 
157
	mov	ebx,procinfo
-
 
158
	mov	ecx,-1
-
 
159
	int	0x40
-
 
160
	mov	eax,[procinfo+42]    ; read params of window
-
 
161
	sub	eax,115
-
 
162
	mov	[size_x_var],ax
-
 
163
	shr	ax,1
-
 
164
	mov	[vect_x],ax
-
 
165
;
-
 
166
	mov	eax,[procinfo+46]
-
 
167
	sub	eax,30
-
 
168
	mov	[size_y_var],ax
-
 
169
	shr	ax,1
-
 
170
	mov	[vect_y],ax
-
 
171
 
-
 
172
	mov	eax,[procinfo+34]
-
 
173
	mov	[x_start],ax
-
 
174
	mov	eax,[procinfo+38]
-
 
175
	mov	[y_start],ax
145
    red:			; redraw
176
	call	alloc_buffer_mem ;realloc mem for scr & z buffs
Line 146... Line 177...
146
	call	draw_window
177
	call	draw_window
Line 147... Line 178...
147
 
178
 
Line 705... Line 736...
705
    loop    .dc
736
    loop    .dc
706
    pop eax
737
    pop eax
707
 
738
 
Line 708... Line 739...
708
    mov     eax,7	    ; put image
739
    mov     eax,7	    ; put image
709
    mov     ebx,screen
740
    mov     ebx,[screen_ptr]
710
    mov     ecx,[size_y_var]
741
    mov     ecx,[size_y_var]
711
  ;  mov     ecx,SIZE_X shl 16 + SIZE_Y
742
  ;  mov     ecx,SIZE_X shl 16 + SIZE_Y
712
    mov     edx,5 shl 16 + 25
743
    mov     edx,5 shl 16 + 25
713
    int     0x40
744
    int     0x40
Line 763... Line 794...
763
 
794
 
Line 764... Line 795...
764
 
795
 
-
 
796
 
-
 
797
alloc_buffer_mem:
-
 
798
    mov     eax, 68
-
 
799
    mov     ebx, 11
-
 
800
    int     0x40    ;  -> create heap, to be sure
-
 
801
 
-
 
802
 
-
 
803
    movzx    ecx,word[size_x_var]
-
 
804
    movzx    eax,word[size_y_var]
-
 
805
    mul      ecx
-
 
806
   ; add      eax,100
-
 
807
    push     eax
-
 
808
    lea      ecx,[eax*3]
-
 
809
    mov      eax,68
-
 
810
    mov      ebx,20
-
 
811
    mov      edx,[screen_ptr]
-
 
812
    cmp      [draw_win_at_first],1
-
 
813
    jne      @f
-
 
814
    xor      edx,edx
-
 
815
  @@:
-
 
816
    int      0x40
-
 
817
    mov      [screen_ptr],eax
-
 
818
 
-
 
819
    pop      ecx
-
 
820
    shl      ecx,2
-
 
821
    mov      eax,68
-
 
822
    mov      ebx,20
-
 
823
    mov      edx,[Zbuffer_ptr]
-
 
824
    cmp      [draw_win_at_first],1
-
 
825
    jne      @f
-
 
826
    xor      edx,edx
-
 
827
  @@:
-
 
828
    int      0x40
-
 
829
    mov      [Zbuffer_ptr],eax
-
 
830
 
765
 
831
if 0
766
alloc_buffer_mem:
832
;old Menuet style alloc
-
 
833
    movzx    ecx,word[size_x_var]
767
    movzx    ecx,word[size_x_var]
834
    movzx    eax,word[size_y_var]
768
    movzx    eax,word[size_y_var]
835
    add      eax,200
769
    mul      ecx
836
    mul      ecx
770
    lea      ecx,[eax*3]
837
    lea      ecx,[eax*3]
771
    add      ecx,16
838
    add      ecx,16
Line 780... Line 847...
780
    mov      [screen_ptr],MEM_END
847
    mov      [screen_ptr],MEM_END
781
    mov      [Zbuffer_ptr],MEM_END
848
    mov      [Zbuffer_ptr],MEM_END
782
    pop      ecx
849
    pop      ecx
783
    add      [Zbuffer_ptr],ecx
850
    add      [Zbuffer_ptr],ecx
784
ret
851
end if
-
 
852
ret
785
 
853
 
Line 786... Line 854...
786
update_flags:
854
update_flags:
787
; updates flags and writing flag description
855
; updates flags and writing flag description
788
; in	ah - button number
856
; in    ah - button number
Line 1646... Line 1714...
1646
	movsd  ; copy end mark too
1714
	movsd  ; copy end mark too
1647
ret
1715
ret
1648
 
1716
 
Line 1649... Line 1717...
1649
clrscr:
1717
clrscr:
1650
	mov	edi,screen
1718
	mov	edi,[screen_ptr]
1651
	movzx	ecx,word[size_x_var]
1719
	movzx	ecx,word[size_x_var]
1652
	movzx	eax,word[size_y_var]
1720
	movzx	eax,word[size_y_var]
1653
	imul	ecx,eax
1721
	imul	ecx,eax
1654
	lea	ecx,[ecx*3]
1722
	lea	ecx,[ecx*3]
1655
	shr	ecx,2
1723
	shr	ecx,2
Line 1914... Line 1982...
1914
	mov	ebx,dword[xx2]
1982
	mov	ebx,dword[xx2]
1915
	ror	ebx,16
1983
	ror	ebx,16
1916
	mov	ecx,dword[xx3]
1984
	mov	ecx,dword[xx3]
1917
	ror	ecx,16
1985
	ror	ecx,16
1918
	lea	edi,[screen]
1986
	mov	edi,[screen_ptr]
1919
	cmp	[catmull_flag],0
1987
	cmp	[catmull_flag],0
1920
	je	@f
1988
	je	@f
1921
  ;	 lea	 esi,[Z_buffer]
1989
  ;      lea     esi,[Z_buffer]
1922
	mov	esi,[Zbuffer_ptr]
1990
	mov	esi,[Zbuffer_ptr]
1923
	call	gouraud_triangle_z
1991
	call	gouraud_triangle_z
1924
	jmp	.end_draw
1992
	jmp	.end_draw
Line 1982... Line 2050...
1982
	ror	ebx,16
2050
	ror	ebx,16
1983
	mov	ecx,dword[xx3]
2051
	mov	ecx,dword[xx3]
1984
	ror	ecx,16
2052
	ror	ecx,16
1985
       ; mov	 edi,screen
2053
       ; mov     edi,screen
1986
	lea	edi,[screen]
2054
	mov	edi,[screen_ptr]
1987
	cmp	[catmull_flag],0
2055
	cmp	[catmull_flag],0
1988
	je	@f
2056
	je	@f
1989
   ;	 lea	 esi,[Z_buffer]
2057
   ;     lea     esi,[Z_buffer]
1990
	mov	esi,[Zbuffer_ptr]
2058
	mov	esi,[Zbuffer_ptr]
1991
	push	word[zz3]
2059
	push	word[zz3]
1992
	push	word[zz2]
2060
	push	word[zz2]
Line 2046... Line 2114...
2046
	mov	ebx,dword[xx2]
2114
	mov	ebx,dword[xx2]
2047
	ror	ebx,16
2115
	ror	ebx,16
2048
	mov	ecx,dword[xx3]
2116
	mov	ecx,dword[xx3]
2049
	ror	ecx,16
2117
	ror	ecx,16
2050
	mov	edi,screen
2118
	mov	edi,[screen_ptr]
2051
	mov	esi,envmap
2119
	mov	esi,envmap
2052
	cmp	[catmull_flag],0
2120
	cmp	[catmull_flag],0
2053
	je	@f
2121
	je	@f
2054
  ;	 mov	 edx,Z_buffer
2122
  ;      mov     edx,Z_buffer
2055
	mov	edx,[Zbuffer_ptr]
2123
	mov	edx,[Zbuffer_ptr]
2056
	call	tex_triangle_z
2124
	call	tex_triangle_z
Line 2182... Line 2250...
2182
	mov	ebx,dword[xx2]
2250
	mov	ebx,dword[xx2]
2183
	ror	ebx,16
2251
	ror	ebx,16
2184
	mov	ecx,dword[xx3]
2252
	mov	ecx,dword[xx3]
2185
	ror	ecx,16
2253
	ror	ecx,16
2186
	mov	edi,screen
2254
	mov	edi,[screen_ptr]
2187
	mov	esi,envmap
2255
	mov	esi,envmap
2188
	mov	edx,bumpmap	       ;BUMP_MAPPING
2256
	mov	edx,bumpmap	       ;BUMP_MAPPING
2189
 
2257
 
Line 2190... Line 2258...
2190
	cmp	[catmull_flag],0
2258
	cmp	[catmull_flag],0
2191
	je	@f
2259
	je	@f
Line 2222... Line 2290...
2222
	mov	ebx,dword[xx2]
2290
	mov	ebx,dword[xx2]
2223
	ror	ebx,16
2291
	ror	ebx,16
2224
	mov	ecx,dword[xx3]
2292
	mov	ecx,dword[xx3]
2225
	ror	ecx,16
2293
	ror	ecx,16
2226
	mov	edi,screen
2294
	mov	edi,[screen_ptr]
2227
	mov	esi,texmap
2295
	mov	esi,texmap
2228
	cmp	[catmull_flag],0
2296
	cmp	[catmull_flag],0
2229
	je	@f
2297
	je	@f
2230
   ;	 mov	 edx,Z_buffer
2298
   ;     mov     edx,Z_buffer
2231
	mov	edx,[Zbuffer_ptr]
2299
	mov	edx,[Zbuffer_ptr]
2232
	call	tex_triangle_z
2300
	call	tex_triangle_z
Line 2336... Line 2404...
2336
	mov	ebx,dword[xx2]
2404
	mov	ebx,dword[xx2]
2337
	ror	ebx,16
2405
	ror	ebx,16
2338
	mov	ecx,dword[xx3]
2406
	mov	ecx,dword[xx3]
2339
	ror	ecx,16
2407
	ror	ecx,16
2340
	mov	edi,screen
2408
	mov	edi,[screen_ptr]
2341
	mov	edx,texmap
2409
	mov	edx,texmap
2342
	mov	esi,[Zbuffer_ptr]
2410
	mov	esi,[Zbuffer_ptr]
2343
 
2411
 
Line 2344... Line 2412...
2344
	call	tex_plus_grd_triangle
2412
	call	tex_plus_grd_triangle
Line 2397... Line 2465...
2397
	mov	ebx,dword[xx2]
2465
	mov	ebx,dword[xx2]
2398
	ror	ebx,16
2466
	ror	ebx,16
2399
	mov	ecx,dword[xx3]
2467
	mov	ecx,dword[xx3]
2400
	ror	ecx,16
2468
	ror	ecx,16
2401
	mov	edi,screen
2469
	mov	edi,[screen_ptr]
2402
	mov	esi,texmap
2470
	mov	esi,texmap
2403
	mov	edx,envmap
2471
	mov	edx,envmap
2404
 
2472
 
Line 2405... Line 2473...
2405
	call	two_tex_triangle_z
2473
	call	two_tex_triangle_z
2406
	jmp	.end_draw
2474
	jmp	.end_draw
Line 2479... Line 2547...
2479
	mov	ebx,dword[xx2]
2547
	mov	ebx,dword[xx2]
2480
	ror	ebx,16
2548
	ror	ebx,16
2481
	mov	ecx,dword[xx3]
2549
	mov	ecx,dword[xx3]
2482
	ror	ecx,16
2550
	ror	ecx,16
2483
	mov	edi,screen
2551
	mov	edi,[screen_ptr]
2484
	mov	esi,envmap
2552
	mov	esi,envmap
2485
	mov	edx,bumpmap
2553
	mov	edx,bumpmap
2486
 
2554
 
Line 2487... Line 2555...
2487
	call bump_tex_triangle_z
2555
	call bump_tex_triangle_z
Line 2525... Line 2593...
2525
;	 add	 eax,[edges_counter]	 ;   I mean chosing overlapped	edges.
2593
;        add     eax,[edges_counter]     ;   I mean chosing overlapped  edges.
2526
;	 mov	 bl,[eax]		 ;
2594
;        mov     bl,[eax]                ;
2527
;	 test	 bl,00000001b		 ;
2595
;        test    bl,00000001b            ;
2528
;	 jz	 @f			 ;
2596
;        jz      @f                      ;
2529
	mov	edi,screen
2597
	mov	edi,[screen_ptr]
2530
	mov	esi,[Zbuffer_ptr]
2598
	mov	esi,[Zbuffer_ptr]
2531
 
2599
 
Line 2532... Line 2600...
2532
	mov	eax,[col1]
2600
	mov	eax,[col1]
2533
	movzx	bx,al
2601
	movzx	bx,al
2534
	push	bx		  ; b
2602
	push	bx		  ; b
Line 2560... Line 2628...
2560
;	 mov	 bl,[eax]
2628
;        mov     bl,[eax]
2561
;	 test	 bl,00000010b
2629
;        test    bl,00000010b
2562
;	 jz	 @f
2630
;        jz      @f
2563
 
2631
 
Line 2564... Line 2632...
2564
	mov	edi,screen
2632
	mov	edi,[screen_ptr]
2565
	mov	esi,[Zbuffer_ptr]
2633
	mov	esi,[Zbuffer_ptr]
Line 2566... Line 2634...
2566
 
2634
 
2567
	mov	eax,[col1]
2635
	mov	eax,[col1]
2568
	movzx	bx,al
2636
	movzx	bx,al
Line 2596... Line 2664...
2596
;	 mov	 bl,[eax]		;
2664
;        mov     bl,[eax]               ;
2597
;	 test	 bl,00000100b		;
2665
;        test    bl,00000100b           ;
2598
;	 jz	 @f			;
2666
;        jz      @f                     ;
2599
 
2667
 
Line 2600... Line 2668...
2600
	mov	edi,screen
2668
	mov	edi,[screen_ptr]
2601
	mov	esi,[Zbuffer_ptr]
2669
	mov	esi,[Zbuffer_ptr]
Line 2602... Line 2670...
2602
 
2670
 
2603
	mov	eax,[col3]
2671
	mov	eax,[col3]
2604
	movzx	bx,al
2672
	movzx	bx,al
Line 3105... Line 3173...
3105
	int	0x40
3173
	int	0x40
3106
 
3174
 
Line 3107... Line 3175...
3107
	; DRAW WINDOW
3175
	; DRAW WINDOW
3108
	mov	eax,0		; function 0 : define and draw window
3176
	mov	eax,0  ; function 0 : define and draw window
-
 
3177
	mov	bx,[x_start]
-
 
3178
	shl	ebx,16
-
 
3179
	mov	cx,[y_start]
-
 
3180
	shl	ecx,16
3109
	mov	ebx,50*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size]
3181
;ebx -  [x start] *65536 + [x size]
3110
	mov	ecx,50*65536;+SIZE_Y;+30    ; [y start] *65536 + [y size]
3182
;ecx -  [y start] *65536 + [y size]
3111
	mov	bx,[size_x_var]
3183
	mov	bx,[size_x_var]
3112
	add	bx,115
3184
	add	bx,115
3113
	mov	cx,[size_y_var]
3185
	mov	cx,[size_y_var]
3114
	add	cx,30
3186
	add	cx,30
-
 
3187
    ; @@:
3115
	mov	edx,0x14000000	; color of work area RRGGBB,8->color gl
3188
	mov	edx,0x13000000	; color of work area RRGGBB,8->color gl
3116
	mov	edi,labelt	; WINDOW LABEL
3189
	mov	edi,labelt	; WINDOW LABEL
3117
	int	0x40
3190
	int	0x40
Line 3118... Line 3191...
3118
 
3191