Skip to content

Instantly share code, notes, and snippets.

@VerySweetBread
Last active January 10, 2023 17:35
Show Gist options
  • Save VerySweetBread/e8a20694645bfcf25b7707140594dc5a to your computer and use it in GitHub Desktop.
Save VerySweetBread/e8a20694645bfcf25b7707140594dc5a to your computer and use it in GitHub Desktop.
include 'macros.inc'
SIZE equ 500
DEGREES equ 1
FPS equ 60
KOS_APP_START
CODE
call repaint
get_central_coordinates:
mov eax, 68
mov ebx, 11
int 40h
mov eax, 68
mov ebx, 12
mov ecx, 1024
int 40h
mov [buffer_pointer], eax
mov eax, 9
mov ebx, [buffer_pointer]
mov ecx, -1
int 40h
mov ebx, [buffer_pointer]
xor edx, edx
mov ecx, 2
mov eax, [ebx+0x3E]
div ecx
mov [center_x], eax
xor edx, edx
mov eax, [ebx+0x42]
div ecx
mov [center_y], eax
mov eax, 68
mov ebx, 13
mov ecx, [buffer_pointer]
int 40h
_loop:
call repaint
call _wait
mov eax, 11
int 40h
cmp eax, 3
je but_handler
jmp _loop
but_handler:
mov eax, 14
int 40h
cmp eax, 1
jne @f
mov eax, -1
int 40h
@@:
ret
_wait:
mov eax, 5
mov ebx, 100/FPS
int 40h
ret
; Stack: word angle
rotate:
push ebp
mov ebp, esp
pusha
mov eax, dots-4*4
.loop:
add eax, 4*4
push word [ebp+2*4] ; angle esp+2*4
push dword [eax] ; x esp+4
push dword [eax+2*4] ; z esp
fld dword [esp+4]
fild word [esp+2*4]
fmul [torad]
fcos
fmulp
fld dword [esp]
fild word [esp+2*4]
fmul [torad]
fsin
fmulp
fsubp
fstp dword [eax]
fld dword [esp+4]
fild word [esp+2*4]
fmul [torad]
fsin
fmulp
fld dword [esp]
fild word [esp+2*4]
fmul [torad]
fcos
fmulp
faddp
fstp dword [eax+2*4]
add esp, 4+4+2
cmp [eax+4*4], dword 0
jne .loop
popa
pop ebp
ret 2
repaint:
mov eax, 12
mov ebx, 1
int 40h
mov eax, 0
mov ebx, SIZE
mov ecx, SIZE
mov edx, 0x34FFFFFF
mov esi, 0x80FFFFFF
mov edi, title
int 40h
push word DEGREES
call rotate
mov eax, dots-4*4
mov ebx, pr_dots-2*4
@@:
add eax, 4*4
add ebx, 2*4
push eax
push ebx
call project
cmp [eax+4*4], dword 0
jne @b
mov eax, lines-2
@@:
add eax, 2
push eax
call process_lines
cmp [eax+2], word 0
jne @b
mov eax, 12
mov ebx, 2
int 40h
ret
; Stack: addres to pair of bytes
process_lines:
push ebp
mov ebp, esp
pusha
mov eax, [ebp+2*4]
mov al, [eax] ; 1st dot id
mov bl, 2*4
mul bl
add eax, pr_dots
mov ebx, [eax+4]
mov eax, [eax]
push eax ebx
mov eax, [ebp+2*4]
mov al, [eax+1] ; 2nd dot id
mov bl, 2*4
mul bl
add eax, pr_dots
mov ebx, [eax+4]
mov eax, [eax]
push eax ebx
call draw_lines
popa
pop ebx
ret 4
draw_lines:
push ebp
mov ebp, esp
pusha
mov eax, 38
mov ebx, [ebp+5*4] ; 1st x
sal ebx, 16
add ebx, [ebp+3*4] ; 2nd x
mov ecx, [ebp+4*4] ; 1st y
sal ecx, 16
add ecx, [ebp+2*4] ; 2nd y
mov edx, 0
int 40h
popa
pop ebx
ret 4*4
; Stack: dot pointer, projected dot pointer
project:
push ebp
mov ebp, esp
pusha
mov eax, [ebp+3*4] ; Dot pointer
mov ebx, [ebp+2*4] ; Projected dot pointer
sub esp, 4
fld dword [eax] ; x
fmul [focal] ; x*focal
fld dword [eax+2*4] ; z
fadd [focal] ; z+focal
fdivp ; x*focal/(z+focal)
fistp dword [esp]
mov ecx, [esp]
add ecx, [center_x]
mov [ebx], ecx
fld dword [eax+1*4] ; y
fmul [focal] ; x*focal
fld dword [eax+2*4] ; z
fadd [focal] ; z+focal
fdivp ; y*focal/(z+focal)
fistp dword [esp]
mov ecx, [esp]
add ecx, [center_y]
mov [ebx+4], ecx
add esp, 4
popa
pop ebp
ret 2*4
DATA
title db "3D test", 0
focal dd 100.0
torad dd 0.0174533 ; pi/180
dots:
dd -50.0, -50.0, -50.0, 1
dd 50.0, -50.0, -50.0, 1
dd -50.0, 50.0, -50.0, 1
dd 50.0, 50.0, -50.0, 1
dd -50.0, -50.0, 50.0, 1
dd 50.0, -50.0, 50.0, 1
dd -50.0, 50.0, 50.0, 1
dd 50.0, 50.0, 50.0, 1
dd 0, 0, 0, 0
lines:
db 0, 1 ; First square
db 0, 2
db 1, 3
db 2, 3
db 4, 5 ; Second squere
db 4, 6
db 5, 7
db 6, 7
db 0, 4 ; Connection
db 1, 5
db 2, 6
db 3, 7
db 0, 7 ; Diagonals
db 1, 6
db 2, 5
db 3, 4
dw 0
UDATA
center_x rd 1
center_y rd 1
pr_dots:
rd 2*9
buffer_pointer rd 1
KOS_APP_END
@VerySweetBread
Copy link
Author

изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment