Newer
Older
Import / research / 4k-asm / render_backup_2.asm
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


  push  word [si+Points-4] ; x
  push  word [si+Points-6] ; y
  call  setup_angle
	fsubp
  fsubp
  fistp dword [tmp1d]
  ; tmp1d = -y * sin(a) + x * cos(a))
  
  push  word [si+Points-6] ; y
  push  word [si+Points-4] ; x
  call  setup_angle
	faddp
	faddp
  fistp dword [tmp2d]
  ; tmp2d = x * sin(a) + y * cos(a)


  push  word [tmp2d]       ; y
  push  word [si+Points-2] ; z
  call  setup_angle
	fsubp
	fsubp
  fistp dword [tmp3d]
  ; tmp3d = -z * sin(a) + y * cos(a)
	
  push  word [si+Points-2] ; z
  push  word [tmp2d]       ; y
  call  setup_angle
	faddp
	faddp
  fistp dword [tmp4d]
  ; tmp4d = y * sin(a) + z * cos(a)



  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


setup_angle:
  mov   ax,0
  mov   word [tmp1w],ax
  fild  word [tmp1w]
  fild  word [angle]
	fild  word [Rads]
  fdivp               ; deg2rad
  fsincos             ; sin(a) and cos(a)
  
  mov   bp,sp
  mov   ax,word [bp-2]
  mov   word [tmp1w],ax
  fild  word [tmp1w]
  fmulp
  ; fp[2] = y * sin(a)
  ; fp[1] = cos(a)
  ; fp[0] = 0

  fistp dword [tmp0d]
  mov   ax,word [bp-4]
  mov   word [tmp1w],ax
  fild  word [tmp1w]
  fmulp
  fild  dword [tmp0d]
  ; fp[2] = y * sin(a)
  ; fp[1] = x * cos(a)
  ; fp[0] = 0
  
  mov   ax,0
  retn 4


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
  tmp0d:     resd 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