org 100h section .text %macro init_gfx 0 mov ax,0x13 int 0x10 %endmacro %macro usleep 2 ; usecs hi, lo mov ax,0x8600 mov cx, %1 mov dx, %2 int 0x15 %endmacro %macro create_texture 0 mov di,texture mov dx,4 mov bx,80 mov cx,20 mov ax,1 %%again: rep stosb mov cx,ax mov ax,1 sub ax,cx mov cx,20 dec bx jnz %%again mov cx,ax mov ax,1 sub ax,cx mov bx,80 mov cx,20 dec dx jnz %%again %endmacro %macro blit 5 ; src, x,y, w,h mov ax,0xA000 mov es,ax mov si,%1 mov di,%2+320*%3 mov bx,%4 mov cx,%5 %%again: rep movsb add di,320-%4 mov cx,%4 dec bx jnz %%again %endmacro %macro cls 0 mov ax,0xA000 mov es,ax mov si,0 mov di,0 mov cx,320*200 mov ax,0 rep stosb %endmacro %macro puts 1 ; str mov dx,%1 mov ah,0x09 int 0x21 %endmacro %macro exit 0 int 0x20 %endmacro start: ; program code init_gfx ; create_texture ; blit texture, 100, 100, 80, 80 ; usleep 0x1,0xFFFF ; cls ; exit mov ax,0xA000 mov es,ax mov cx,360 ; mov cx,45 ; loop for different angles loop1: mov word [angle],cx push cx mov ax,word [angle2] sub ax,3 mov word [angle2],ax usleep 0,0x0100 cls ; loop over the points mov si,24+24 more_pnts: call xform_display sub si,6 jne more_pnts pop cx loop loop1 exit xform_display: ; d - dist of screen from COP ; x / z = sx / d ; d * (x/z) = screen-x mov ax,0 mov word [tmp1w],ax fild word [tmp1w] fild word [angle] fild word [Rads] fdivp ; deg2rad fsincos ; sin(a) and cos(a) ; fp[2] = sin(a) ; fp[1] = cos(a) ; fp[0] = 0 ; Goal: x = -y *sin + x * cos fild word [si+Points-6] ; y fmulp ; y *= sin(a) ; fp[2] = y * sin(a) ; fp[1] = cos(a) ; fp[0] = 0 fistp dword [tmp1d] fild word [si+Points-4] ; x fmulp ; x * cos(a) fild dword [tmp1d] ; fp[2] = y * sin(a) ; fp[1] = x * cos(a) ; fp[0] = 0 fsubp fsubp fistp dword [tmp1d] ; tmp1d = 0 - (y * sin(a) - x * cos(a)) ; tmp1d = -y * sin(a) + x * cos(a)) fild word [angle] fild word [Rads] fdivp ; deg2rad fsincos ; sin(a) and cos(a) ; fp[1] = sin(a) ; fp[0] = cos(a) ; Goal: y = x * sin + y * cos fild word [si+Points-4] ; x fmulp ; x *= sin(a) ; fp[1] = x * sin(a) ; fp[0] = cos(a) fistp dword [tmp2d] fild word [si+Points-6] ; y fmulp ; y * cos(a) fild dword [tmp2d] ; fp[1] = x * sin(a) ; fp[0] = y * cos(a) faddp fistp dword [tmp2d] ; tmp2d = x * sin(a) + y * cos(a) mov ax,0 mov word [tmp1w],ax fild word [tmp1w] fild word [angle] fild word [Rads] fdivp ; deg2rad fsincos ; sin(a) and cos(a) ; fp[2] = sin(a) ; fp[1] = cos(a) ; fp[0] = 0 ; Goal: y = -z * sin + y * cos fild word [si+Points-2] ; z fmulp ; z *= sin(a) ; fp[2] = z * sin(a) ; fp[1] = cos(a) ; fp[0] = 0 fistp dword [tmp3d] fild word [tmp2d] ; y fmulp ; y * cos(a) fild dword [tmp3d] ; fp[2] = z * sin(a) ; fp[1] = y * cos(a) ; fp[0] = 0 fsubp fsubp fistp dword [tmp3d] ; tmp3d = -z * sin(a) + y * cos(a) fild word [angle] fild word [Rads] fdivp ; deg2rad fsincos ; sin(a) and cos(a) ; fp[1] = sin(a) ; fp[0] = cos(a) ; Goal: z = y * sin + z * cos fild word [tmp2d] ; y fmulp ; y *= sin(a) ; fp[1] = y * sin(a) ; fp[0] = cos(a) fistp dword [tmp4d] fild word [si+Points-2] ; z fmulp ; z * cos(a) fild dword [tmp4d] ; fp[1] = y * sin(a) ; fp[0] = z * cos(a) faddp fistp dword [tmp4d] ; tmp4d = y * sin(a) + z * cos(a) ; fild word [si+Points-6] ; y ; fmulp ; y *= sin(a) ; fistp dword [tmp2d] ; fild word [si+Points-4] ; x ; fmulp ; x * cos(a) ; fistp dword [tmp1d] ;mov ax,[si+Points-4] ; tmp2w] ;mov bx,[si+Points-6] ; tmp2w] mov cx,[tmp3d] ; [si+Points-2] ; z add cx,150 ;mov cx,[si+Points-2] ; z ; X mov ax,0 mov ax,[tmp1d] ; x mov dx,45 imul dx idiv cx add ax,160 mov di,ax ; Y mov ax,[tmp4d] ; [tmp2d] ; y ;mov ax,[tmp2d] ; y mov dx,45 imul dx idiv cx add ax,100 mov dx,320 imul dx add di,ax ; draw mov ax,1 stosb stosb add di,318 stosb stosb ret section .data ;Hello db 'Hello world', 0xD, 0xA, '$' Rads dw 58 ; Dist dw 45 Points dw -50,-50,-50, -50,50,-50, -50,50,50, -50,-50,50 Points2 dw 50,-50,-50, 50,50,-50, 50,50,50, 50,-50,50 section .bss ; uninitialized data angle: resw 1 angle2: resw 1 tmp1w: resw 1 tmp2w: resw 1 tmp1d: resd 1 tmp2d: resd 1 tmp3d: resd 1 tmp4d: resd 1 sine: resd 1 cosine: resd 1 texture: resb 6400 ; 80x80 offscreen: resb 64000