Madmartigan: 3-D graphics
; the InvisibleType structure will be used to temporarily
store an object
; with any invisible pixels
InvisibleType STRUC
texture_type dw ? ; object's texture
type
pos_x dw ? ; object's x-position
pos_y dw ? ; object's y-position
distance REAL4 ? ; object's distance
from player
stripnumber dw ? ; strip number of the
objects texture
InvisibleType ENDS
tempreal REAL4 ? ; global variable used to for temp
storage of type REAL4
BackGrnd dw BGSeg ; Value of Background Segment
MapLoc dw 0 ; Offset to current map array
WorldSize dw 0 ; Size of the current map
; used by Ray_Caster
cell_x dw ? ; x-coord of cell we are inspecting
cell_y dw ? ; y-coord of cell we are inspecting
Player_X dw ? ; player's location and orientation in
Player_Y dw ? ; texture-sized cells
Player_Angle dw ? ; (for graphics rountines)
INVISIBLE_PIXEL db ? ; palatte number to never draw on
screen
NumInvisibles dw ? ; number of invisible object found
Invisibles_Array InvisibleType MAX_INVISIBLES dup(< >) ;
Invisible Array
; LIFO structure for objects with invisible pixels
Table_Invisible_Offset dw 00 ; Zeroth Invisible
texture has offset 12*0
dw 12 ; .
dw 24 ; .
dw 36 ; .
dw 48 ; Fouth
Invisible texture has offset 12*4
dw 60
dw 72
dw 84
; used by DrawStrip for quickly finding location in texture
files
; = row width * texture height * row# + offset to middle of
texture
Texture_Table dw 320*64*0+64*0+320*31
dw 320*64*0+64*1+320*31
dw 320*64*0+64*2+320*31
dw 320*64*0+64*3+320*31
dw 320*64*0+64*4+320*31
dw 320*64*1+64*0+320*31
dw 320*64*1+64*1+320*31
dw 320*64*1+64*2+320*31
dw 320*64*1+64*3+320*31
dw 320*64*1+64*4+320*31
dw 320*64*2+64*0+320*31
dw 320*64*2+64*1+320*31
dw 320*64*2+64*2+320*31
dw 320*64*2+64*3+320*31
dw 320*64*2+64*4+320*31
; used by Ray_Caster for fast computation
tan_table REAL4 1921
dup(?) ; tangent tables used to compute initial
inv_tan_table REAL4 1921 dup(?) ;
intersections with ray
y_step
REAL4 1921 dup(?) ; x and y steps, used to find
intersections
x_step
REAL4 1921 dup(?) ; after initial one is found
inv_cos_table REAL4 1921 dup(?) ; used to
compute strip number and next cells
inv_sin_table REAL4 1921 dup(?) ; used to
compute strip number and next cells
correction_table REAL4 1921 dup(?) ; used to cancel out
fishbowl effect
RAY_INCREMENT REAL4
3.272e-4 ; offset to prevent divide
by zero operations
INFINITY REAL4 1.0e8
POWER_NEGTEN REAL4 1.0e-10
Macros:
ModeGraph proc near ; Switch to Graphics Mode
mov ax, 0013h
int 10h
ret
ModeGraph endp
ModeText proc near ; Switch to Text Mode
mov ax, 1202h
mov bl, 30h
int 10h
mov ax, 3
int 10h
mov ax, 1112h
mov bl, 0
int 10h
ret
ModeText endp
Procedures:
RayCaster - Fred Koopmans
Purpose:
Send out 320 x and y rays (for each columne on the screen) until
an object is found
calculate the distance to the object, and where in the object the
ray hit, and daw
one column of that object accordingly.
Inputs:
x_pos - player's current x position in the map
y_pos - player's current y position in the map
view_angle - player's current angle
Outputs:
writes to the screen buffer through calls of DrawStrip
LoadPCX - Fred Koopmans
Purpose:
Opens, decodes, and loads a 320x200x256 color z-soft PCX file
Set's the vga palette
to the colors used in the file. Uses the scrath segment
temporarily to store the file while reading.
Inputs:
ax = Destination segment address.
dx = pointer to a null-terminated string containing the filename
Outputs:
Fills destination with image data.
Fills SVGA palette registers with image color.
SetUpGameData - Fred Koopmans
Purpose:
Load images for gameplay and initialize world values.
Inputs:
DataSet : level number to use (always 2 in our case).
Outputs:
BGSeg contains uncompressed background and player textures
MapLoc contains the address of the start of the map
INVISIBLE_PIXEL is set to the palette number which is never
drawn.
BuildTables - Fred Koopmans
Purpose:
Builds all the trip tables that we will need during gametime
computation to improve
on speed during the game
Input:
none
Output:
Tables are filled with the right values
ShowScreenBuffer - Fred Koopmans
Purpose:
Transfer image data from the buffer to the screen
Inputs:
None
Outputs:
Image is written to the screen
Check_Invisible - Fred Koopmans
Purpose:
Determines whether or not a given texture contains any invisible
pixels
Inputs:
AX = texture number
Outputs:
ax = 1 if the texture contains invisible pixels, else ax = 0
Push_Invisible - Fred Koopmans
Purpose:
This function saves all the relevant information of an object
with invisible pixels
so that it can be obtained and drawn later
Input:
hit_type - word - texture number of the object
x - word - x-coordinate in the map
y - word - y-coordinate in the map
dist - REAL4 - distance from player to the object
stripnum - the strip number in the texture that we will want to
draw
Output:
pushes the object information into the Invisibles_Array
Notes:
if an attempt is made to save the same object twice, the closer
srtip should be saved
Pop_Invisible - Fred Koopmans
Purpose:
removes the invisible object on the top of the stack and load the
data
into register and memory locations
Inputs:
none
Outputs:
dist_x - objects distance from player
bx - stripnum
dx - hit type
Convert_Values - Fred Koopmans
Purpose:
Convert position and angle from game values to graphics values
Input:
My_X ; game values of position and angle
My_Y
MY_angle
Outputs:
Position_X ; graphics values of position and angle
Position_Y
Position_Angle
PlayerValue - Fred Koopmans
Purpose:
Check the world map and return the value, and whether of not it
is a valid value
Inputs:
BlockX and BlockY are the x and y coordinates in the map
Outputs:
Ax = player number
DI = valid flag 1 if valide, 0 if invalid
WorldValue - Fred Koopmans
Purpose:
Check the world map and return the value, and whether of not it
is a valid value
Inputs:
BlockX and BlockY are the x and y coordinates in the map
Outputs:
ax = texture number
cx = invalid flag
DrawStrip - Fred Koopmans
Purpose:
Draw a scaled stip of the desired texture into the desired
location of the screen buffer
Input:
Scale - height the strip (0-200)
X - column on the screen to draw the strip
StripNum - the strip number (0-63) of the texture
TexNum - the number of the texture to be drawn (0,15)
TexSeg - The segment where the texture can be found
Output:
draws a stip directly to the buffer