projected dot-cube in assembler
category: code [glöplog]
any ideas for optimization?
i did the same with just ploting the pixels and came to 41 bytes:
but the reason why i am asking is because i want the projection routine to work in real-time. hence doing rotation in pure assembly is the next step for the former routine.
  
Code:
org 100h
	mov al, 13h
	int 10h
	mov ax, 0a000h
	mov es, ax
	mov bx, -2
	mov cx, 8			;8 vertices
L1:	
	add bx, 6
	;translate z
	mov ax, [cube+bx]
	add ax, [fovz]
	mov [cube+bx], ax
	;X Coordinate
	mov ax, [cube+bx-4]		;put x-coord in ax
	mul word [fovz]			;ax=al*m8
	cwd
	idiv word [cube+bx]		;z-coord	;ax=ax/reg
	mov [proj], ax
	
	;Y Coordinate
	mov ax, [cube+bx-2]		;y-coord
	mul word [fovz]
	cwd
	idiv word [cube+bx]		;z-coord
	mov [proj+2], ax
	;plot projected coords
	push ax
	push bx
	;x-coord
	  mov bx, [proj]	;bx = x
	  add bx, 160		;bx = x + 160
	  mov si, bx		;si = x
	;y-coord
	  mov ax, 320
	  mov bx, [proj+2]	;bx = y
	  add bx, 100		;bx = y+100
	  mul bx		;ax = (y+100) * 320
	  add si, ax		;si = x+160 + (y+100) * 320
	  mov byte [es:si], 15
	pop bx
	pop ax
	loop L1
a:
	jmp a
fovz	dw 255
cube	dw -40, -40, -40
	dw 40, -40, -40
	dw 40, 40, -40
	dw -40, 40, -40
	dw -40, -40, 40
	dw 40, -40, 40
	dw 40, 40, 40
	dw -40, 40, 40
proj	times 2 dw 0
i did the same with just ploting the pixels and came to 41 bytes:
Code:
org 100h
	mov al, 13h
	int 10h
	les bp,[bx]
	mov cx, 8
L:	mov si, [cube+bx]
	mov byte [es:si+255], 15
	add bx, 2
	loop L
cube dw 16833, 16927, 21006, 21074, 42767, 42834, 46913, 47007
but the reason why i am asking is because i want the projection routine to work in real-time. hence doing rotation in pure assembly is the next step for the former routine.
if you're optimizing for size, you can just go for the equivalent of for(int i=0; i<8; i++) { x = (i&1)?-40:40; y = ... } instead of storing the coordinates
  
yes, good point. thank you
  
Quote:
I want the projection routine to work in real-time
is it not working in real-time now? What hardware are you using?
trc_wm: hm. dosbox. what? you dont see the dots?
  
its not tested on a real dos btw.
  
Avoud to use stored values, try to generate all on the fly.
You can save a lot of space
For 8 point it might be like
or even more aggressive
(gives cube 65x65x65)
  
You can save a lot of space
For 8 point it might be like
Code:
	inc bx
	mov al, 40
	test bl, 1
	jz AX
	sub al, 80
AX:	cbw
	push ax
	mov al, 40
	test bl, 2
	jz AY
	sub al, 80
AY:	cbw
	push ax
	mov al, 40
	test bl, 4
	jz AZ
	sub al, 80
AZ:	cbw
	push ax
	;pop them and project coordinates
	inc bx
	and bl, 7or even more aggressive
Code:
	inc bx
	test bl, 1
	salc
	xor al, 64
AX:	cbw
	push ax
	test bl, 2
	salc
	xor al, 64
AY:	cbw
	push ax
	test bl, 4
	salc
	xor al, 64
AZ:	cbw
	push ax
	
	...
	inc bx
	and bl, 7(gives cube 65x65x65)
Oops, change first "inc bx" to "L:"
and add at teh end "jmp L"
  
and add at teh end "jmp L"
trc_wm: sorry, i read your line wrong. yes its working in RL.
frag: fantastic! actually i need to understand whats going on in that code. if it is equal to gargaj's C-code then i understand. the salc and test-instructions i havent learned yet, so i don't yet fully understand em.
  
frag: fantastic! actually i need to understand whats going on in that code. if it is equal to gargaj's C-code then i understand. the salc and test-instructions i havent learned yet, so i don't yet fully understand em.
i need to wrap up the disassembler in Visual C/C++ and study those instructions. but i need a break now :)
  
props for showing actual effort. good luck.
  
dunno if this is shorter. it looked scary to implement that one frag.
anyway. this is what i got now
  
anyway. this is what i got now
Code:
	mov al, 128
L:	rol al, 1
	cmp al, 8
	jnz L2
	mov al, 1
L2:	mov word [cube+bx], 40
	test cl, al
	jnz L3
	mov word [cube+bx], -40
L3:	add bl, 2
	loop Ljust stripped a few byte(s). forgot
  
Code:
L:	rol al, 1
	cmp al, 8
	jnz L2
	mov al, 1
L2:	mov word [cube+bx], 40
	test cl, al
	jnz L3
	neg word [cube+bx]
L3:	add bl, 2
	loop Live changed to NASM. when i do a mul bx, cx for example. is bx the destination operand or does it mul bx and cx (bx*cx) and dest in ax? just wondering
  
just did it in ax. didnt bother
  
There are three "types" of imul:
  
- imul cx,bx,12345: cx = low 16 bits of (bx*12345)
 - imul bx,cx: bx = low 16 bits of (bx*cx)
 - imul bx: ax = low 16 bits of (ax*bx), dx = high 16 bits of (ax*bx)
 
very helpful, thanks rrrola
  
