📄 mos3de01.asm
字号:
mov [pxadd],eax
mov [pyadd],dword 0
; End If
psidenot10:
; ------------
; If Pside = 2 Then
cmp [pside],dword 2
jne psidenot20
; Px = Pwidth%
; Py = Pheight%
mov edi,[pwidth]
mov esi,[pheight]
mov [px],edi
mov [py],esi
; Pxadd = 0
; Pyadd = -Pheight% / Lineheight%
mov [pxadd],dword 0
mov eax,0
sub eax,[pheight]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx ; result now in eax
mov [pyadd],eax
; End If
psidenot20:
; ------------
; If Pside = 3 Then
cmp [pside],dword 3
jne psidenot30
; Px = 0
; Py = Pheight%
mov [px],dword 0
mov edi,[pheight]
mov [py],edi
; Pxadd = Pwidth% / Lineheight%
; Pyadd = 0
mov eax,[pwidth]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx ; result now in eax
mov [pxadd],eax
mov [pyadd],dword 0
; End If
psidenot30:
; ------------
; If Pside = 4 Then
cmp [pside],dword 4
jne psidenot40 ; jne
; Px = 0
; Py = 0
mov [px],dword 0
mov [py],dword 0
; Pxadd = 0
; Pyadd = Pheight% / Lineheight%
mov [pxadd],dword 0
mov eax,[pheight]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx
mov [pyadd],eax
; End If
psidenot40:
; ------------
; x = X1% Shl 16
mov edx,[x1] ; used for x
mov edi,[px] ; used for px
mov esi,[py] ; used for py
sal edx,16
;mov [x],edx
;------
; For y% = 0 To Lineheight%
mov eax,0
for0lineheight0:
; Ytopy%=Ytop%+y%
mov ebx,[ytop]
mov [ytopy],ebx
add [ytopy],eax
; If Ytopy%<0 Then Ytopy%=0 ; prevent read pre array
cmp [ytopy], dword 0
jge isnot00
mov [ytopy],dword 0
isnot00:
; Lefttable(Ytopy%, 0) = x Sar 16 ;polygon x
mov ecx,[ytopy]
imul ecx,16
add ecx,lefttable
mov [ecx],edx
sar dword[ecx],16
; Lefttable(Ytopy%, 1) = Px ;picture x
add ecx,4
mov [ecx],edi
; Lefttable(Ytopy%, 2) = Py ;picture y
add ecx,4
mov [ecx],esi
; x = x + Xadd ;Next polygon x
; Px = Px + Pxadd ;Next picture x
; Py = Py + Pyadd ;Next picture y
add edx,[v_xadd]
add edi,[pxadd]
add esi,[pyadd]
;------
; Next
inc eax
cmp eax,[lineheight]
jl for0lineheight0
;End Function
popa
ret
; -------------------------------------------------------------------------
; -------------------------------------------------------------------------
;Function ScanRightSide (X1%, X2%, Ytop%, Lineheight%, Pside)
scan_right_side:
pusha
mov eax,[y1]
mov [ytop],eax
; Lineheight% = Lineheight% + 1 ; prevent divide by zero
inc dword[lineheight]
; Xadd = (X2% - X1%) Shl 16
mov edi,[x2]
sub edi,[x1]
sal edi,16
; Xadd = Xadd / Lineheight%
mov eax,edi ; whole
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx ; result now in eax
mov [v_xadd],eax
; ------------
; If Pside = 1 Then
cmp [pside],dword 1
jne psidenot11
; Px = 0
; Py = 0
mov [px],dword 0
mov [py],dword 0
; Pxadd = Pwidth% / Lineheight%
; Pyadd = 0
mov eax,[pwidth]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx ; result now in eax
mov [pxadd],eax
mov [pyadd],dword 0
; End If
psidenot11:
; ------------
; If Pside = 2 Then
cmp [pside],dword 2
jne psidenot21
; Px = Pwidth%
; Py = 0
mov edi,[pwidth]
mov [px],edi
mov [py],dword 0
; Pxadd = 0
; Pyadd = Pheight% / Lineheight%
mov [pxadd],dword 0
mov eax,[pheight]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx ; result now in eax
mov [pyadd],eax
; End If
psidenot21:
; ------------
; If Pside = 3 Then
cmp [pside],dword 3
jne psidenot31
; Px = Pwidth%
; Py = Pheight%
mov edi,[pwidth]
mov [px],edi
mov esi,[pheight]
mov [py],esi
; Pxadd = -Pwidth% / Lineheight%
; Pyadd = 0
mov eax,0
sub eax,[pwidth]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,3 ; prevent div 0
idiv ebx ; result now in eax
mov [pxadd],eax
mov [pyadd],dword 0
; End If
psidenot31:
; ------------
; If Pside = 4 Then
cmp [pside],dword 4
jne psidenot41 ; jne
; Px = 0
; Py = Pheight%
mov [px],dword 0
mov esi,[pheight]
mov [py],esi
; Pxadd = 0
; Pyadd = -Pheight% / Lineheight%
mov [pxadd],dword 0
mov eax,0
sub eax,[pheight]
cdq
mov ebx,[lineheight] ; divisor
;or ebx,1
idiv ebx
mov [pyadd],eax
; End If
psidenot41:
push edx
push edi
push esi
; ------------
; x = X1% Shl 16
mov edx,[x1] ; used for x
mov edi,[px] ; used for px
mov esi,[py] ; used for py
sal edx,16
cmp [lineheight],dword 100 ; lineheight is up to 33 mio ???
jle okok
mov eax,[lineheight]
mov [wonder+4],eax
okok:
;------
; For y% = 0 To Lineheight%
mov eax,0
for0lineheight1b:
; Ytopy%=Ytop%+y%
mov ebx,[ytop]
mov [ytopy],ebx
add [ytopy],eax
; If Ytopy%<0 Then Ytopy%=0 ; prevent read pre array
cmp [ytopy], dword 0
jg isnot01
mov [ytopy],dword 0
isnot01:
; righttable(Ytopy%, 0) = x Sar 16 ;polygon x
mov ecx,[ytopy]
imul ecx,16
add ecx,righttable
mov [ecx],edx
sar dword[ecx],16
; righttable(Ytopy%, 1) = Px ;picture x
add ecx,4
mov [ecx],edi
; righttable(Ytopy%, 2) = Py ;picture y
add ecx,4
mov [ecx],esi
; x = x + Xadd ;Next polygon x
; Px = Px + Pxadd ;Next picture x
; Py = Py + Pyadd ;Next picture y
add edx,[v_xadd]
add edi,[pxadd]
add esi,[pyadd]
;------
; Next
inc eax
cmp eax,[lineheight]
jl for0lineheight1b
dbg2:
pop esi
pop edi
pop edx
;End Function
popa
ret
; -------------------------------------------------------------------------
; well I'm shure the following Sub CAN and SHOULD be optimized a LOT.
;Function TextureMap()
texture_map:
pusha
; For y% = Miny% To Maxy%
mov eax,[miny]
for_miny_maxy:
; If y>0 And y<=239
cmp eax,0
jle clipy
cmp eax,239
jg clipy
mov [y],eax
; Polyx1% = Lefttable((y%), 0)
mov ebx,eax
sal ebx,4
add ebx,lefttable
mov ecx,[ebx]
mov [polyx1],ecx
; Px1 = Lefttable(y%, 1)
add ebx,4
mov ecx,[ebx]
mov [px1],ecx
; Py1 = Lefttable(y%, 2)
add ebx,4
mov ecx,[ebx]
mov [py1],ecx
; Polyx2% = Righttable((y%), 0)
mov ebx,eax
sal ebx,4
add ebx,righttable
mov ecx,[ebx]
mov [polyx2],ecx
; Px2 = Righttable(y%, 1)
add ebx,4
mov ecx,[ebx]
mov [px2],ecx
; Py2 = Righttable(y%, 2)
add ebx,4
mov ecx,[ebx]
mov [py2],ecx
; Linewidth% = Polyx2% - Polyx1%
mov ecx,[polyx2]
sub ecx,[polyx1]
; Linewidth%=Linewidth% Or 1
or ecx,1
mov [linewidth],ecx
; Pxadd = ((Px2 - Px1)) / Linewidth%
mov eax,[px2]
sub eax,[px1]
cdq
mov ebx,[linewidth] ; divisor
or ebx,1
idiv ebx ; should be idiv ... probs
mov [pxadd],eax
; Pyadd = ((Py2 - Py1)) / Linewidth%
mov eax,[py2]
sub eax,[py1]
cdq
mov ebx,[linewidth] ; divisor
or ebx,1
idiv ebx ; should be idiv ...probs
mov [pyadd],eax
mov edi,[px1]
mov esi,[py1]
; For x% = Polyx1% To Polyx2%
mov eax,[polyx1]
cmp eax,[polyx2]
jge clipxfully
for_polyx1_polyx2:
; If x>0 And x<=319
cmp eax,0
jl clipx
cmp eax,319
jg clipx
; Col%=ReadPixelFast((Px1 Shr 16),(Py1 Shr 16),imgtxt)
mov ebx,edi
sar ebx,16 ; is eq (px1 shr 16)*64
and ebx,63
sal ebx,2 ; is x
mov ecx,esi
sar ecx,16
and ecx,63
sal ecx,8 ; y
add ecx,ebx
add ecx,tex1 ; adr of texturepixel now in ecx
mov edx,[ecx]; rgb now in edx
; WritePixelFast x%,y%,Col%
mov ebx,[y]
mov [tempdiv],ebx
shl dword [tempdiv],6
shl ebx,10
sub ebx,[tempdiv]
;this was imul ebx,960 ; *1024 - *64
add ebx,eax
add ebx,eax
add ebx,eax
add ebx,0x80000
or [ebx],edx
; EndIf
clipx:
; Px1 = Px1 + Pxadd
; Py1 = Py1 + Pyadd
add edi,dword [pxadd]
add esi,dword [pyadd]
; Next x
inc eax
cmp eax,[polyx2]
jl for_polyx1_polyx2
clipxfully:
mov eax,[y]
; EndIf
clipy:
; Next y
inc eax
cmp eax,[maxy]
jl for_miny_maxy
;End Function
popa
ret
; -------------------------------------------------------------------------
put_screen:
pusha
mov eax,7
mov ebx,0x80000
mov ecx,320*65536+240
mov edx,5*65536+20
int 0x40
popa
ret
clear_screen:
push ebx
mov ebx,0x80000
cls:
mov [ebx],dword 0
add ebx,4
cmp ebx,0x80000+(320*240*3)
jl cls
pop ebx
ret
; -------------------------------------------------------------------------
; DATA AREA
; cube.inc includes the mesh 3D Data, in this case a simple cube. Any Model
; is theoreticly possible. Check the File, the Format is trivial.
; The Quads should not intersect for a bearable z-sorting. The Quads must be
; clockwise.
include "CUBE.INC"
;;------------------------------
grid: ; 32*32 Blocks, Map: 0 = Air, 1 to 5 = Wall
; this is a relict from an other program. I leave it here to keep
; the Navigation Subs compatible (planning to recycle them)
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
db 1,0,0,0,1,0,0,0,0,0,0,3,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8
db 5,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8
db 1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,1,0,0,0,0,3,3,3,3,0,0,0,0,0,0,8
db 5,0,1,2,3,4,5,6,7,8,2,1,3,3,3,0,5,0,2,1,2,3,0,0,0,0,0,0,0,0,0,8
db 1,0,0,0,0,0,0,0,0,0,2,3,0,0,0,0,5,0,0,0,0,3,0,0,0,0,0,0,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0,0,0,0,6,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1
db 5,0,0,0,0,0,0,5,0,0,0,1,0,0,0,0,6,0,5,1,0,2,0,0,4,4,0,4,4,0,0,1
db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,6,0,0,5,0,2,0,0,0,4,0,4,0,0,0,1
db 1,0,0,0,0,0,0,4,0,0,0,3,0,3,3,3,6,0,0,1,0,1,0,0,4,4,0,4,4,0,0,1
db 5,0,0,0,1,0,0,4,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,4,0,0,0,4,4,0,1
db 1,1,0,1,1,1,1,4,1,0,1,3,0,0,0,0,6,0,0,1,0,1,0,4,0,0,0,0,0,4,0,1
db 5,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,6,0,0,5,0,1,0,4,0,0,0,0,0,4,0,1
db 1,0,0,0,1,0,0,5,0,0,0,3,0,0,0,0,6,1,5,1,0,1,0,4,4,0,0,0,4,4,0,1
db 5,0,0,0,0,0,0,5,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,4,4,4,4,4,0,0,1
db 1,4,1,4,1,4,1,4,1,4,1,3,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
db 2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
sinus:
dd 0,11,22,34,45,57,68,80,91,102
dd 114,125,137,148,160,171,182,194,205,217
dd 228,240,251,263,274,285,297,308,320,331
dd 342,354,365,377,388,400,411,422,434,445
dd 457,468,479,491,502,514,525,536,548,559
dd 571,582,593,605,616,628,639,650,662,673
dd 685,696,707,719,730,741,753,764,775,787
dd 798,810,821,832,844,855,866,878,889,900
dd 912,923,934,946,957,968,979,991,1002,1013
dd 1025,1036,1047,1059,1070,1081,1092,1104,1115,1126
dd 1138,1149,1160,1171,1183,1194,1205,1216,1228,1239
dd 1250,1261,1272,1284,1295,1306,1317,1328,1340,1351
dd 1362,1373,1384,1396,1407,1418,1429,1440,1451,1463
dd 1474,1485,1496,1507,1518,1529,1541,1552,1563,1574
dd 1585,1596,1607,1618,1629,1640,1651,1663,1674,1685
dd 1696,1707,1718,1729,1740,1751,1762,1773,1784,1795
dd 1806,1817,1828,1839,1850,1861,1872,1883,1894,1905
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -