home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Party 1994: Try This At Home
/
disk_image.bin
/
source
/
placesrc
/
pallo.asm
< prev
next >
Wrap
Assembly Source File
|
1995-03-13
|
23KB
|
905 lines
; COURTESY OF JMAGlC of COMPLEX (jmagic@freenet.hut.fi)
; ============================================================================
ideal
jumps
model small
Extrn flatman:Far
stack 100h
codeseg
p486
rowmu = 2
y_max = 200*2/(rowmu+1) ; 200*2/(rowmu+1)
pagez = 60
veny = (y_max/pagez)+1
if veny eq 0
veny = 1
endif
pagesh = 200*y_max
x_max = 320
x_center = 4*24 ; x_max/2
y_center = (y_max)/2 ; 70*2/(rowmu+1) ; y_max/2
;x_scale = 2310
;y_scale = 2310*2/(rowmu+1)
points = 8
include 'sintbl.dw'
xmsaddress dd 0
scrnofs dd 0
rotx dw 0
roty dw 512
rotz dw 0
tx dw 0
ty dw 0
tz dw 18300 ; 10240 +256*13
holoholo dw 0
stylero dw 0
;============================================================================
pol_l dw 256 dup (0) ; polygon left edge
pol_r dw 256 dup (0) ; polygon right edge
texture_l dw 256 dup (0) ; polygon left edge texture pos
texture_r dw 256 dup (0) ; polygon right edge texture pos
delta_x dw 0 ; x2-x1
delta_y dw 0 ; y2-y1
_x1 dw 0
_y1 dw 0
label _t1 word
_tx1 db 0
_ty1 db 0
_txd dw 0
_tyd dw 0
fixed_low dw 0
fixed_high dw 0
tf_addx dw 0
tf_addy dw 0
tex_lo dw 0
tex_hi dw 0
sxa dd 0
sya dd 0
looprow dw 0
loopti dw 0
label edgemark word
db 0
tbl db 0 ; 0=left, 1=right side
stacko dw 0 ; sp save
label PolyCords word
dw 4*2 dup (0)
label TextureCords byte
db 1, 1
db 64, 1
db 64, 64
db 1, 64
textureseg dw 0
macro line p1, p2
local @@hoilaa, @@noswap, @@1, @@2, @@fryit, @@draw16loop, @@draw4loop, @@drawloop1, @@drawloop, @@piirra, @@3, @@2_1, @@2_0, @@dido, @@puis, @@null, @@bah, @@koinas
mov [ds:tbl], 1
x1=[ds:p1*4+PolyCords]
y1=[ds:p1*4+PolyCords+2]
x2=[ds:p2*4+PolyCords]
y2=[ds:p2*4+PolyCords+2]
tx1=[ds:p1*2+TextureCords]
ty1=[ds:p1*2+TextureCords+1]
tx2=[ds:p2*2+TextureCords]
ty2=[ds:p2*2+TextureCords+1]
xor ax, ax
xor bx, bx
mov al, tx2
mov bl, tx1
sub ax, bx
mov [_txd], ax
xor ax, ax
xor ebx, ebx
mov al, ty2
mov bl, ty1
sub ax, bx
mov [_tyd], ax
mov dl, tx1
mov dh, ty1
mov si, dx
mov dx, x1
mov cx, y1
mov ax, x2
sub ax, dx ; x1
mov bx, y2
sub bx, cx ; y1
jns @@noswap
neg ax
neg bx
neg [_txd]
neg [_tyd]
mov dl, tx2
mov dh, ty2
mov si, dx
mov dx, x2
mov cx, y2
dec [ds:tbl] ; toggle side
@@noswap:
mov [ds:_t1], si
mov [ds:_x1], dx
mov [ds:_y1], cx
or bx, bx
jz @@null
movsx eax, ax ; [delta_x]
cdq
shl eax, 16
idiv ebx
or eax, eax
js $+4
inc eax
mov [dword ptr ds:fixed_low], eax
add cx, [ds:edgemark]
lea di, [offset pol_l+ecx*2]
movsx eax, [word ptr _txd]
cdq
shl eax, 16
idiv ebx
shr eax, 8
mov [tf_addx], ax
movsx eax, [word ptr _tyd]
cdq
shl eax, 16
idiv ebx
shr eax, 8
mov [tf_addy], ax
@@koinas:
mov ax, [word tf_addx]
xor si, si
xor cx, cx
mov bp, [ds:_x1]
mov dx, [ds:_t1]
@@drawloop: ; aint it sucky, eh...
add si, [ds:fixed_low]
mov [di], bp
adc bp, [ds:fixed_high]
mov [di+512*2], dx
add cl, al ; [byte tf_addx]
adc dl, ah ; [byte tf_addx+1]
add ch, [byte tf_addy]
adc dh, [byte tf_addy+1]
add di, 2
dec bx
jns @@drawloop
jmp @@puis
@@null:
lea di, [offset pol_l+ecx*2]
lea bx, [eax+edx]
mov [di], dx
mov [di+256*2], bx
@@puis:
endm
macro getminmax y0, y1, y2, y3
local @@1, @@2
mov cx, 32767 ; min
xor dx, dx ; max
macro testvalue
local @@notless, @@notmore
cmp ax, cx
jg $+4
mov cx, ax
cmp ax, dx
jl $+4
mov dx, ax
endm
mov ax, y0
testvalue
mov ax, y1
testvalue
mov ax, y2
testvalue
mov ax, y3
testvalue
test cx, cx
jns $+4
xor cx, cx
cmp dx, y_max
jle $+5
mov dx, y_max
@@2:
endm
dumdum dw 0
proc rendertexture
mov cx, [cs:si+256*2]
sub cx, [cs:si]
cmp cx, 1
jl @@puis
mov [cs:loopti], cx
mov edi, ebx
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
mov ax, [cs:si+512*2]
xchg dl, ah
mov bx, [cs:si+768*2]
xchg cl, bh
shl eax, 16 ; begin x
shl edx, 16 ; begin y
shl ebx, 16 ; end x
shl ecx, 16 ; end y
sub ebx, eax
sub ecx, edx
mov eax, ebx
xor ebx, ebx
mov bx, [cs:loopti]
inc bx
cdq
idiv ebx ; x adder
mov [cs:sxa], eax
mov eax, ecx
cdq
idiv ebx ; y adder
mov [cs:sya], eax
xor ebx, ebx
mov bx, [word cs:si] ; pol edge start
add edi, ebx
xor edx, edx
mov bx, [cs:si+512*2]
xchg dl, bh
mov ebp, [cs:sya]
mov esi, [cs:sxa]
rol ebp, 16
rol esi, 16
xchg si, bp
xor dh, dh
mov ch, [byte cs:loopti]
shr ch, 3
jz @@nomolotus
shr dh, 1
@@inner1:
i=0
rept 4
adc edx, esi
mov al, [ds:bx]
adc ebx, ebp
mov bh, dl
adc edx, esi
mov ah, [ds:bx]
adc ebx, ebp
mov [es:edi+i], ax
mov bh, dl
i=i+2
endm
adc dh, dh
add edi, i
shr dh, 1
dec ch
jnz @@inner1
adc dh, dh
and [cs:loopti], 7
@@nomolotus:
mov ch, [byte cs:loopti]
shr ch, 1
jz @@innersingle
shr dh, 1
@@inner2:
adc edx, esi
mov al, [ds:bx]
adc ebx, ebp
mov bh, dl
adc edx, esi
mov ah, [ds:bx]
lea edi, [edi+2]
adc ebx, ebp
mov bh, dl
mov [es:edi-2], ax
dec ch
jnz @@inner2
@@innersingle:
test [cs:loopti], 1
jz @@PUIS
mov al, [ds:bx]
mov [es:edi], al
@@puis:
ret
endp
kunt dw 0
proc filltpoly4 ; fill texture mapped polygon
; line x1, y1, c1, x2, y2, c2
; parameters in POLYCORD
push cs
pop ds
mov al, [byte ds:color]
mov [byte ds:color+1], al
line 0, 1
line 1, 2
line 2, 3
line 3, 0
getminmax [ds:0*4+PolyCords+2], [ds:1*4+PolyCords+2], [ds:2*4+PolyCords+2], [ds:3*4+PolyCords+2]
dec dx
sub dx, cx
js @@nicht
mov [ds:kunt], dx
mov ax, [ds:color]
mov bx, ax
shl eax, 16
mov ax, bx
lea si, [offset pol_l+ecx*2]
shl cx, 3 ; \
lea cx, [ecx+ecx*4] ; multiply by 8*5*5 = 200
lea cx, [ecx+ecx*4] ; /
xor ebx, ebx
mov bx, cx
add ebx, [cs:xmsaddress]
add ebx, [cs:scrnofs]
push 0
pop es
mov ds, [cs:textureseg]
@@w8_1:
cmp si, offset pol_l ; above screen?
jb @@b
cmp si, offset pol_l+y_max*2 ; below screen?
ja @@b
push si ebx
call rendertexture
pop ebx si
@@blorb:
inc si
inc si
@@b:
add ebx, 200 ; 200 wide lines
dec [cs:kunt]
jns @@w8_1
@@nicht:
push cs
pop ds
ret
endp
macro fillpoly a1, a2, a3, a4
local @@tri_done, @@noco
push cs
pop ds
;(x3-x1)*(y2-y1)-(x2-x1)*(y3-y1)
mov ax, [word ds:cord_x+(a3)*2] ;x2
sub ax, [word ds:cord_x+(a1)*2] ;x0
mov bx, [word ds:cord_y+(a2)*2] ;y1
sub bx, [word ds:cord_y+(a1)*2] ;y0
imul bx
mov cx, ax
mov ax, [word ds:cord_x+(a2)*2] ;x1
sub ax, [word ds:cord_x+(a1)*2] ;x0
mov bx, [word ds:cord_y+(a3)*2] ;y2
sub bx, [word ds:cord_y+(a1)*2] ;y0
imul bx
sub cx, ax
jns @@tri_done
neg cx
add cx, 1700
lea cx, [ecx+ecx*2]
shr cx, 12
and cx, 7
or cx, cx
jz $+3
inc cx
shl cx, 10
add [cs:textureseg], cx
@@noco:
mov ax, [word cord_y+(a1)*2]
rol eax, 16
mov ax, [word cord_x+(a1)*2]
mov [dword PolyCords+0*4], eax
mov ax, [word cord_y+(a2)*2]
rol eax, 16
mov ax, [word cord_x+(a2)*2]
mov [dword PolyCords+1*4], eax
mov ax, [word cord_y+(a3)*2]
rol eax, 16
mov ax, [word cord_x+(a3)*2]
mov [dword PolyCords+2*4], eax
mov ax, [word cord_y+(a4)*2]
rol eax, 16
mov ax, [word cord_x+(a4)*2]
mov [dword PolyCords+3*4], eax
call filltpoly4
@@tri_done:
endm
cord_x dw points dup(0)
cord_y dw points dup(0)
scrpage dw 0
gg=2048+1024 ; +512+256
cc=2048
label dots word
dw -cc, cc, -cc
dw cc, cc, -cc
dw cc, -cc, -cc
dw -cc, -cc, -cc
dw -cc, cc, cc
dw cc, cc, cc
dw cc, -cc, cc
dw -cc, -cc, cc
macro setborder clr
; if you
endm
kolor db 0
color dw 0
palette db 'texture_pal' , 32*3 dup (0)
────────────────────────────────────────────────────────────────────────────
; FOLLOWING ROTATION ROUTINE IS ORIGINALLY FROM VLA'S VECTOR SOURCE!
; It's fast enough for stupid cube rotation and I'm not intending to
; release my own rotation routines before I really need to :)
────────────────────────────────────────────────────────────────────────────
;DESTROYS: ax,dx,si,di,es,ds
;Input: BX= X CX= Y BP= Z
;OutPut:BX= X CX= Y BP= Z
proc RotateXYZ
; X-rotation
; Y := cos(Xan) * y - sin(Xan) * z
; Z := sin(Xan) * y + cos(Xan) * z
mov si,[RotX]
add si,si ; si = angle x
mov ax,[Cosine+si] ; ax = cos(angle x)
imul cx ; ax = cos(angle x) * y
mov di,dx
shl edi,16
mov di,ax ; store for later use
mov ax,[Sine+si] ; ax = sin(angle x)
imul bp ; ax = sin(angle x) * z
shl edx,16
mov dx,ax
sub edi,edx ; di = di-ax = cos(vx)*y - sin(vz)*z
sar edi,8 ; remove the (co)sin "256-factor"
push di ; es = x-coordinate
mov ax,[sine+si] ; ax = sin(angle x)
imul cx ; ax = sin(angle x) * y
mov di,dx
shl edi,16
mov di,ax
mov ax,[cosine+si] ; ax = cos(angle x)
imul bp ; ax = cos(angle x) * z
shl edx,16
mov dx,ax
add edi,edx ; di = di-ax = sin(vx)*y + cos(vx)*z
sar edi,8 ; remove the (co)sin "256-factor"
pop cx ; update y
mov bp,di ; update z
; Y-rotation
; X := cos(vy) * xc + sin(vy) * zc
; Z := -sin(vy) * xc + cos(vy) * zc
mov si,[RotY]
add si,si ; si = angle y
mov ax,[Cosine+si] ; ax = cos(angle y)
imul bx ; ax = cos(angle y) * x
mov di,dx
shl edi,16
mov di,ax ; store for later use
mov ax,[Sine+si] ; ax = sin(angle y)
imul bp ; ax = sin(angle y) * z
shl edx,16
mov dx,ax
add edi,edx ; di = di+ax = cos(vy)*x + sin(vy)*z
sar edi,8 ; remove the (co)sin "256-factor"
push di ; es = x-coordinate
mov ax,[Sine+si] ; ax = sin(angle y)
neg ax ; ax =-sin(angle y)
imul bx ; ax =-sin(angle y) * x
mov di,dx
shl edi,16
mov di,ax
mov ax,[Cosine+si] ; ax = cos(angle y)
imul bp ; ax = cos(angle y) * z
shl edx,16
mov dx,ax
add edi,edx ; di = di-ax = sin(vy)*x - cos(vy)*z
sar edi,8 ; remove the (co)sin "256-factor"
pop bx ; update x
mov bp,di ; update z
; Z-rotation
; X := cos(vz) * xc - sin(vz) * yc
; Y := sin(vz) * xc + cos(vz) * yc
mov si,[RotZ]
add si,si ; si = angle z
mov ax,[Cosine+si] ; ax = cos(angle z)
imul bx ; ax = cos(angle z) * x
mov di,dx
shl edi,16
mov di,ax
mov ax,[Sine+si] ; ax = sin(angle z)
imul cx ; ax = sin(angle z) * y
shl edx,16
mov dx,ax
sub edi,edx ; di = di-ax = cos(vz)*x - sin(vz)*y
sar edi,8 ; remove the (co)sin "256-factor"
push di ; es = x-coordinate
mov ax,[Sine+si] ; ax = sin(angle z)
imul bx ; ax = sin(angle z) * x
mov di,dx
shl edi,16
mov di,ax
mov ax,[Cosine+si] ; ax = cos(angle z)
imul cx ; ax = cos(angle z) * y
shl edx,16
mov dx,ax
add edi,edx ; di = di+ax = sin(vz)*x+cos(vz)*y
sar edi,8 ; remove the (co)sin "256-factor"
pop bx ; update x
mov cx,di ; update y
ret
ENDP
────────────────────────────────────────────────────────────────────────────
proc rotatecord
xor si, si
and [RotX], 1023
and [RotY], 1023
and [RotZ], 1023
rotcordloop1:
push si
;BX= X CX= Y BP= Z
;BX= X CX= Y BP= Z
mov bx, si
add si, si
add si, bx
mov bx, [dots+si]
mov cx, [dots+2+si]
mov bp, [dots+4+si]
call RotateXYZ
pop si
mov ax, [cs:tz]
sub bp, ax
mov ax,bx
mov bx, (512-20)
imul bx
idiv bp ;x
add ax, x_center
mov [cord_x+si], ax
mov ax,cx
mov bx, (512*2)/(rowmu+1)
imul bx
idiv bp ;y
add ax, y_center
mov [cord_y+si], ax
inc si
inc si
cmp si, points*2
jb rotcordloop1
ret
endp
proc draw_glenz
mov [cs:textureseg], picseg ; psykomössö
fillpoly 0, 4, 5, 1
mov [cs:textureseg], picseg
fillpoly 7, 3, 2, 6
mov [cs:textureseg], picseg
fillpoly 1, 5, 6, 2
mov [cs:textureseg], picseg
fillpoly 3, 7, 4, 0
mov [cs:textureseg], picseg+4 ; muija
fillpoly 0, 1, 2, 3
mov [cs:textureseg], picseg+8 ; skull
fillpoly 5, 4, 7, 6
ret
endp
macro calcofs
mov ax, [cs:scrpage]
mov bx, pagesh
mul bx
shl edx, 16
mov dx, ax
mov [cs:scrnofs], edx
endm
proc clearpage
calcofs
cld
push 0
pop ds
mov cx, (y_max+1)*5
xor si, si
mov edi, [cs:scrnofs]
add edi, [cs:xmsaddress]
xor eax, eax
@@m1:
i=0
rept 10
mov [edi+i], eax
i=i+4
endm
add edi, i
dec cx
jnz @@m1
ret
endp
proc rubbercopyscr
push 0
pop ds
push 0a000h
pop es
cld
mov esi, [cs:xmsaddress]
mov ebx, [cs:scrnofs]
mov di, 320*28-8*6
add [cs:scrpage], 1
cmp [cs:scrpage], pagez
jb @blorb1
sub [cs:scrpage], pagez
@blorb1:
mov cx, (y_max+1)/veny
@@a:
add ebx, pagesh
cmp ebx, pagez*pagesh
jb @blorb
sub ebx, pagez*pagesh
@blorb:
add esi, ebx
mov dh, veny
@@b:
add di, (80-(5*10))*4
mov dl, 5
@@c:
i=0
rept 10
mov eax, [esi+i]
; add eax, 20h
stosd
i=i+4
endm
add esi, 10*4
; add di, 10*4
dec dl
jnz @@c
dec dh
jnz @@b
sub esi, ebx
dec cx
jnz @@a
ret
endp
proc dothetwist
calcofs
setborder 5
call rotatecord
setborder 4
call clearpage
setborder 1
call draw_glenz
setborder 12
setborder 0
mov dx, 3dah
in al, dx
test al, 8
jnz $-3
in al, dx
test al, 8
jz $-3
call rubbercopyscr
ret
endp
proc remaptexture
mov bx, 8
@@koo:
mov ax, picseg
mov ds, ax
mov ax, picseg
mov cx, bx
shl cx, 10
add ax, cx
mov es, ax
mov dh, 8
sub dh, bl
shl dh, 5
mov dl, dh
mov di, dx
shl edx, 16
mov dx, di
xor di, di
mov cx, 256*64/4
@@map:
mov eax, [ds:di]
and eax, 1f1f1f1fh
add eax, edx
stosd
dec cx
jnz @@map
dec bx
jnz @@koo
ret
endp
proc fadetus
mov ch, 7
@@p1:
mov si, offset palette
mov dx, 3c8h
mov al, 7
sub al, ch
shl al, 5
out dx, al
inc dx
mov cl, 32*3
@@p2:
mov al, ch
add al, ch
shr al, 2
add al, ch
shr al, 1
add al, ch
add al, ch
add al, 7
mul [byte cs:si]
shr ax, 5
out dx, al
inc si
dec cl
jnz @@p2
dec ch
jnz @@p1
ret
endp
doop dw 100
proc main
mov ax, 0
mov bx, (pagez*pagesh/1024)
call flatman
push cs
pop ds
mov [cs:xmsaddress], eax
call remaptexture
mov ax, 13h
int 10h
call fadetus
mov dx, 3c8h
xor al, al
out dx, al
inc dx
mov al, 08
out dx, al
mov al, 15
out dx, al
mov al, 13
out dx, al
; mov [cs:stylero], 70*2
;la2:
; call dothetwist
; dec [cs:stylero]
; jnz la2
l2:
;; uncomment these for "depth wobbling"
; add [cs:holoholo], 12
; mov bx, [cs:holoholo]
; add bx, 512
; and bx, 1023
; add bx, bx
; mov ax, [cs:sine+bx]
; sal ax, 4
; add ax, 18500+3700
; mov [cs:tz], ax
add [cs:rotx], 2 ; try different values,
add [cs:roty], 1 ; large values cause distortion...
add [cs:rotz], 5 ;
call dothetwist
in al, 60h
cmp al, 1h
jnz l2
puis:
mov ax, 1
call flatman
mov ax, 3
int 10h
mov ax, 4c00h
int 21h
endp
segment picseg use32
db 'texture_pic'
db 256*64*8 dup (0)
ends picseg
end main