Game Play for Drag Racing '99
(all of the variables, functions, and macros on this page
were developed, debugged, and written by Ryan Lindsay)
Variables
WHICH_CAR db ? ; which car you are: AUTO_STOCK, MAN_STOCK, PRO_STOCK
; -- Lights --
PRE_STAGE db 0 ; 0 = light off, 1 = light on
STAGE db 0
YELLOW1 db 0
YELLOW2 db 0
YELLOW3 db 0
GREEN db 0 ; green light signifies the start of the race &
timers
BREAK db 0 ; break if go too far too soon
LIGHT_TIME dw 0 ; timer variable used for lights
; -- Car Variables --
SPEED dw 0 ; in mph
POSITION dw 0 ; in feet
ACCELERATION dw 0 ; in G's * 100
PRE_POSITION dw 0 ; in inches*10 - used for lights
RPM dw 0 ; (revs per minute)/100
OLD_GEAR db 0
GEAR db 0 ; gear that the car is in 1.. 3 or 1.. 4
CLUTCH dw 0 ; % of clutch engaged 0.. 100
THROTTLE dw 0 ; % throttle 0.. 100
TRACTION dw 100 ; % traction at wheels
DAMAGE dw 0 ; % damage to car 0.. 100
DIAL_IN dw 0 ; estimated ET from player in milliseconds
ELAPSED_TIME dw 0 ; in milliseconds
ELAPSED_CONTROL db 0 ; set to 1 to increment ELAPSED_TIME
REACTION_TIME dw 0 ; in ms
REACTION_CONTROL db 0 ; set to 1 to increment REACTION_TIME
; -- Interrupt Variables --
OLD_TIMER dd ? ; holds old timer address
OLD_COUNT db 0 ; old interrupt called from new interrupt @ 27Hz
GRAPHICS_CONTROL db 0 ; set to 1 in interrupt when graphics need
to be called
GRAPHICS_COUNT db 0 ; used by interrupt
SOUND_TIME dw ? ; used to make sure sound files are only called
SOUND_CONTROL db ? ; when supposed to
; -- Variables used for Calculations in UpdateCarVars--
FACCELERATION Real4 ? ; in G's
FSPEED Real4 ? ; in mph
FPOSITION Real4 ? ; in feet
FRPM Real4 ? ; in RPM
DELTA_T dw 0 ; timer used for calculations
; -- from file --
HORSEPOWER dw 100 dup(0) ; RPM range starts at 800; in intervals
of 100 RPM
TORQUE dw 100 dup(0) ; ft-lbfs (these 2 are from file)
FCORRECTED_POWER Real4 100 dup(?) ; in (mile-lbf/hour)/lbf --
calculated
FCORRECTED_TORQUE Real4 100 dup(?) ; in lbf-ft/(lbf-ft) : in G's
-- calculated
ONE_HUNDRED_SQUARED dw 100*100 ; constants, but can only load
ONE_THOUSAND dw 1000 ; word vars into FP registers
ONE_HUNDRED dw 100
FIZERO dw 0
FI_ONE dw 1
FEET_TO_IN dw 10*12 ; 10*(12 in/foot) conversion for UCV
HP_TO_TORQUE dw 5252 ; hp = Torque * RPM / 5252
FG_TO_MPHPS Real4 ? ; (mph/millisecond)/G : conversion for UCV
FMPH_TO_FEETPS Real4 ? ; mph -> ft/ms
WHEEL_RADIUS_HM Real4 ? ; wheel radius (in miles) * (60 min / 1
hour) * 2*pi
; -- from file --
CAR_WEIGHT dw ? ; lbfs
FGEAR_RATIO1 Real4 ? ; gear ratio
FGEAR_RATIO2 Real4 ?
FGEAR_RATIO3 Real4 ?
FGEAR_RATIO4 Real4 0.0 ; N/A on automatic transmission
FDIFF_RATIO Real4 ? ; differential ratio
FCORRECTED_GEAR_RATIO Real4 4 dup(?) ; diff ratio * gear ratio
for 4 gears
; -- from file --
FROLL_RES Real4 ? ; coefficient of rolling resistance
C_AREA dw ? ; cross-sectional area of car (for drag calcs)
FDRAG_COEF Real4 ? ; coefficent of aerodynamic drag
FENGINE_BRAKING Real4 ? ; deceleration due to engine braking
; -- File Variables --
DRA99AS_FILE db 'dra99as.car',0
DRA99MS_FILE db 'dra99ms.car',0
DRA99PS_FILE db 'dra99ps.car',0
FILE_BUFFER db 4000 dup(?)
FILE_LENGTH dw 0
NO_FILE_MSG db '...'
FILE_READERR_MSG db '...'
;-- Joystick/Mouse Variables --
JOY_YMSG db '...'
JOY_XMSG db '...'
JOY_ZMSG db '...'
JOY_HAVE_MSG db '...'
NO_JOY_MSG db '...'
INSTR_MSG db '...'
INSTRR db '...'
CREDIT_MSG db '...'
JOY_Y dw ? ; these are used to calibarate the joystick as well
JOY_YZERO dw ? ; as determine its relative position
JOY_YMAX dw ?
JOY_X dw ?
JOY_XMAX dw ?
JOY_XZERO dw ?
JOY_BUTTON_DOWN db 0 ; boolean variable to make sure one button
press =
; one button press (also used in new mouse function)
MOUSE_VAR DB 0 ; used to tell whether joystick (preffered) or
mouse is used
MOUSE_MSG db '...'
WHICH_CAR_MSG db '...'
PLAY_AGAIN_MSG db '...'
DEAD_MSG db '...'
; -- Time Slip Variables --
SIXTY_FOOT_TIME dw ?
EIGHTH_MILE_MPH dw ?
EIGHTH_MILE_TIME dw ?
THOUSAND_FOOT_TIME dw ?
SFT_MSG db '...'
EMT_MSG db '...'
EMM_MSG db '...'
TFT_MSG db '...'
QM_ET db '...'
QM_MPH db '...'
QM_RT db '...'
Procedurers and Macros
GetRatio macro
RRATIO ; puts gear ratio at [bx] into GEAR_RATIO
; [bx] is in the form 'A.BCD'
GetHP macro ; gets next Horsepower and Torque values & si <- si+2
SkipSpaces proc
near
; keeps incrementing bx until [bx] != a space or tab
;
; Input: bx points to a data array
; Output: bx points to 1st non-space/tab value
NextLine proc near
; Increments bx until bx points to Horsepower # on next line
;
; Input: bx points to data array
; Output: bx points to 2nd ascii number on next line (horsepower)
StoreHP proc near
; This function uses the variable WHICH_CAR to determine which
file
; to open (dra99{as/ms/ps}.car) and uses the values from this
file
; to store values in HORSEPOWER, TORQUE, ratios, and car weight.
;
; Input: WHICH_CAR
; Outputs: HORSEPOWER, TORQUE, CAR_WEIGHT, [FGEAR_RATIO4,]
FGEAR_RATIO3,
; FGEAR_RATIO2, FGEAR_RATIO1, and FDIFF_RATIO
CorrectHP proc
near
; This function performs pre-calculations to help UpdateCarVars
go faster.
;
; Inputs: HORSEPOWER, TORQUE, FGEAR_RATIO{1,2,3,4}, FDIFF_RATIO
; Outputs: FCORRECTED_POWER, FCORRECTED_TORQUE,
FCORRECTED_GEAR_RATIO,
; WHEEL_RADIUS_HM
CarTimerInstall
proc near
; Install CarTimer interrupt function
;
; Output: OLD_TIMER
; author: Preston White (obtained from Mike Basil)
CarTimerUnInstall
proc near
; Un-install CarTimer interrupt function
;
; Input: OLD_TIMER
; author: Preston White (obtained from Mike Basil)
CarTimer proc near
; This function is an interrupt that updates several timers
; once every 5 milliseconds and calls the old timer at ~ 18.2 Hz
; It also updates GRAPHICS_CONTROL and NETWORK_CONTROL.
;
; Inputs: OLD_TIMER, OLD_COUNT, GRAPHICS_COUNT, NETWORK_COUNT,
; ELAPSED_CONTROL, REACTION_CONTROL
; Outputs: ELAPSED_TIME, REACTION_TIME, LIGHT_TIME,
GRAPHICS_TIMER,
; NETWORK_TIMER, DELTA_T
UpdateLightVars
proc near
; This function updates the light variables.
;
; Inputs: LIGHT_TIME, PRE_STAGE, STAGE, YELLOW{1,2,3}, GREEN,
PRE_POSITION
; Outputs: PRE_STAGE, STAGE, YELLOW{1,2,3}, GREEN, BREAK
UpdateAcceleration
proc near
; This function determines the new acceleration.
;
; Inputs: RPM, FRPM, GEAR, FCORRECTED_GEAR_RATIO,
FCORRECTED_POWER
; FCORRECTED_TORQUE, CLUTCH, THROTTLE, TRACTION, SPEED
; FENGINE_BRAKING, FDRAG_COEF
; Outputs: FACCELERATION, ACCELERATION
UpdateCarVars proc
near
; This function uses the car variables to calculate the car's new
set of
; car variables.
;
; Inputs: FACCELERATION, GEAR, DELTA_T, FSPEED, FPOSITION, SPEED,
; FCORRECTED_GEAR_RATIO, WHEEL_RADIUS_HM, FG_TO_MPHPS,
; FMPH_TO_FEETPS, FEET_TO_IN, CLUTCH
; Outputs: FSPEED, SPEED, FPOSITION, POSITION, PRE_POSITION, RPM,
FRPM,
; THROTTLE, & resets DELTA_T
UpdateDamage proc
near
; Checks for miss-shifts and no-clutch shifts and updates DAMAGE
; accordingly.
;
; Inputs: CLUCTH, THROTTLE
; Output: DAMAGE
AutoShift proc
near
; This is the function that shifts the car when it's the
automatic stock car.
; Note: this is a very rough approximation of a torque
converter/trans pair.
;
; Inputs: RPM, GEAR
; Outputs: GEAR, CLUTCH
GetJoyPos macro
AXIS, POSITION_VAR
; Gets joystick position and returns in POSITION_VAR.
; AXIS = 1 for x-coord, 2 for y-coord
;
; author: Mark Feldman (obtained fropm ECE291 class resources web
page)
InitJoystick proc near
; This function prompts the user to move the joystick
appropriately and
; reads the joystick position.
;
; Input: input from user
; Outputs: JOY_YMAX, JOY_YZERO, JOY_Y, JOY_XMAX, JOY_XZERO, JOY_X
ReadJoystick proc
near
; This function reads the joystick position and whether a button
is
; being held down or not and updates CLUTCH and THROTTLE
accordingly
;
; Inputs: joystick position, JOY_YZERO, JOY_Y,
; JOY_XMAX, JOY_XZERO
; Outputs: CLUTCH, THROTTLE, GEAR
StartGame proc
near
; Initializes variables for start of game
;
; no input, very many outputs
LightGame proc
near
; Light Game if can't play real game
ReadMouse proc
near
; Reads mouse position. Basically an addition that was made to
make the game
; playable if you don't have the joystick. Using the mouse for
; manual cars is not a good form of input for this game.
;
; Input: from mouse, WHICH_CAR
; Outputs: THROTTLE, CLUTCH, GEAR
DisplayCarVariables
proc near
; Simply a debugging macro which diplays most of the the car
variables.