ECE291 Computer Engineering II Lockwood, Spring 1999

Team Members:
Nick Bhavsar:    Graphics, MIDI
Joe Petrovic:    Background Graphics, Menus
Josh Bishop:     Sound effects, Status Bar Graphics
Sergio Solomon:  AI, Graphics



Introduction:
Quester is going to be a 2-D side scrolling air fighting game. Players will be able to upgrade their weapons and fight various enemies and bosses. Real time game play, music (MIDI and WAV), and 320x200x256 graphics are some of the features we plan to implement.

We plan to make a fun interactive game that can be played by the whole family. We will use the mouse to control the main ship to provide smooth animation and real time precise control. Both the left and right mouse buttons will be used to shoot main guns or missiles respectively. Previous MPs did not require timing execution. We plan to implement our game on a timing basis such that game play is not affected by CPU speed. We also plan to implement sounds, double buffering for quicker graphics to the screen, and Artificial Intelligence all of which were not present in previous MPs.

Implementation:
The program will loop continuously polling the timer (speed up for quicker game play) to see when updates to the screen should be made. Mouse interrupts will update the position of the ship in real-time. Components include the main ship, enemies, guns, missiles, status bar, and background screens. We will implement the ship and its weapons using two parallel arrays. The first will store the images, the other will contain properties for each object.  Correct indexing will need to be used to access each array.



Acknowledgements:
Quester used various sources to contribute to the gameplay.  The timing procedures were implemented after John Lockwood's INT8 timer.  The graphics and sound images were found on the web.  (www.classicgames.net)  The sound procedures were either taken from or modified versions of sb291lib, and the sbtest.  The 291 labnote book was used as reference throughout the creating of the game.

Variables
BackStart: Tells where the background should start.  This is an absolute value telling what bit map and what column of that bitmap should be the first column of the background.  For instance, if BackStart is equal to 322, then the first column of the background should be in the second bit map, third column.

ScreenBuffer: This is a 64k buffer that holds the data that will be placed on the screen.  This is a temporary holding place where the background, ships gunfire, status bar, etc. will all be written to first.  Then, all that information will be written to the video memory at segment A000h at one time.  This will get rid of the flickering.

Lives: holds number of remaining lives
Score: holds score tally
Health: holds remaining health

WavNames Array: holds names of sound effects used
WavLength Array: holds corresponding lengths

WavHeader: WAV file header size

We have many more variables, however documenting them right now is not very useful as they will be modified before the final write up is complete.  The main variable structures we have created are described below:

OBJECTTYPE STRUC
   Xa               DW      1    ; Upper X coord of Object
   Ya               DW      1    ; Upper Y coord of Object
   Xb               DW      31   ; Lower X coord of Object
   Yb               DW      31   ; Lower Y coord of Object
   CurPosition      DW      0    ; current\next position of enemy
   Strength         DB      1    ; hits till enemy dies/offscreen
   Active           DB      0    ; show on screen
   Path             DW      STOP ; type of path enemy is currently taking
                                 ; path types include: AI, Diagonal, Stop,
                                 ; & Straight
   Points           DW      1    ; points for kill
   Speed            DB      1    ; amount of pixels of movement
OBJECTTYPE ENDS
 

; Indexes
FarAsteroidIndex0  EQU 0 ; Index of the first asteroid
FarNumAsteroids  EQU 3  ; 0-FarNumAsteroids are indexed 0, 1, 2, 3

OptionIndex   EQU 5    ; Index for the option

GunIndex   EQU 6  ;4-11 are guns
MissileIndex   EQU 16

ShipIndex   EQU 17  ; Leave room for indexing of NumShips
NumShips   EQU 4  ; One less than the number of ship

FuelIndex  EQU 21  ; Index for Fuel image - this is where collision check will begin
OptionUpgradeIndex   EQU 22   ; must be one less than EnemyIndex
EnemyIndex   EQU 23
NumEnemies   EQU 16  ; Indexed up from EnemyIndex to EnemyIndex+NumEnemies
NumShipEnemies  EQU 6

TargetIndex  EQU 44
CloseAsteroidIndex0  EQU 45
CloseNumAsteroids EQU 3  ; 0-FarNumAsteroids are indexed.  33, 34, 35, 36

HitIndex  EQU 50  ; Hit is image of when a ship gets hit

ExplodeIndex0  EQU 51
NumExplosions  EQU 7    ; 47- Are declared for explosion

InitialMousePosition  EQU 32100   ; Center left of the screen
BackgroundSpeed  EQU 7   ;Number of ticks before a background scroll
GameSpeed  EQU 40   ; Number of ticks before any update to the screen (Make sure midpak is on)
OptionDelay   EQU 15     ; Not an index, it is the delay for the option to wait following the ship
NumUpgradeMissiles   EQU 5
MissileAccelSpeed EQU 1
FarAsteroidMaxSpeed EQU 3  ; Don't change, must be 2^n-1
CloseAsteroidMaxSpeed EQU 3
AsteroidTurnLevel EQU 50 ; Distance from Top and bottom that makes asteroids turn
DelayTillBoss  EQU 0 ; Minutes till boss
DelayTillFuel  EQU 511 ; Make a power of 2 minus 1
BossStrength  EQU 8
ValueFuelUpgrade EQU 25 ; Increase the fuel by this much when you get fuel upgrade
AutoFuelDrainRate EQU 1 ; Power of 2 minus 1 at which the number of seconds before a strength bar is removed
GamePlaySong   EQU 0 ; Index of song to be played in main game
BossPlaySong  EQU 5

; MainShip Attributes
ShipStrength EQU 63   ; AKA Fuel and max fuel value (must be power of 2 minus 1)
ShipXa       EQU  4
ShipYa       EQU  11
ShipXb       EQU  29-ShipXa
ShipYb       EQU  18-ShipYa

GunSpeed     EQU 10
GunXa        EQU 4
GunYa        EQU 12
GunXb        EQU 28-GunXA
GunYb        EQU 17-GunYa

MissileStrength EQU 5
MissileSpeed EQU 3
MissileXa       EQU 8
MissileYa       EQU 10
MissileXb       EQU 23-MissileXa
MissileYb       EQU 22-MissileYa

; OptionUpgrade Attributes
OptionUpgradeStrength EQU 50
OptionUpgradeXa  EQU 8
OptionUpgradeYa  EQU 10
OptionUpgradeXb  EQU 23-OptionUpgradeXa
OptionUpgradeYb  EQU 22-OptionUpgradeYa
 

; Enemy Attributes
SuperSpeed      EQU 1

Enemy_0Speed    EQU  1
Enemy_0Strength EQU 5
Enemy_0Points   EQU 50
Enemy_0SpawnRate EQU 255
Enemy_0Xa       EQU 5
Enemy_0Ya       EQU 9
Enemy_0Xb       EQU 31-Enemy_0Xa
Enemy_0Yb       EQU 21-Enemy_0Ya

Enemy_1Speed    EQU  1
Enemy_1Strength EQU 5
Enemy_1Points   EQU 100
Enemy_1SpawnRate EQU 255
Enemy_1Xa       EQU 5
Enemy_1Ya       EQU 9
Enemy_1Xb       EQU 31-Enemy_1Xa
Enemy_1Yb       EQU 21-Enemy_1Ya

Enemy_2Speed    EQU  1
Enemy_2Strength EQU 3
Enemy_2Points   EQU 75
Enemy_2SpawnRate EQU 255
Enemy_2Xa       EQU 5
Enemy_2Ya       EQU 9
Enemy_2Xb       EQU 31-Enemy_2Xa
Enemy_2Yb       EQU 21-Enemy_2Ya

Enemy_3Speed    EQU  1
Enemy_3Strength EQU 2
Enemy_3Points   EQU 75
Enemy_3SpawnRate EQU 255
Enemy_3Xa       EQU 5
Enemy_3Ya       EQU 9
Enemy_3Xb       EQU 31-Enemy_3Xa
Enemy_3Yb       EQU 21-Enemy_3Ya

Enemy_4Speed    EQU  1
Enemy_4Strength EQU 5
Enemy_4Points   EQU 35
Enemy_4SpawnRate EQU 255
Enemy_4Xa       EQU 5
Enemy_4Ya       EQU 9
Enemy_4Xb       EQU 31-Enemy_4Xa
Enemy_4Yb       EQU 21-Enemy_4Ya

Enemy_5Speed    EQU  1
Enemy_5Strength EQU 2
Enemy_5Points   EQU 50
Enemy_5SpawnRate EQU 255
Enemy_5Xa       EQU 5
Enemy_5Ya       EQU 9
Enemy_5Xb       EQU 31-Enemy_5Xa
Enemy_5Yb       EQU 21-Enemy_5Ya

Enemy_6Speed    EQU  1
Enemy_6Strength EQU 2
Enemy_6Points   EQU 100
Enemy_6SpawnRate EQU 255
Enemy_6Xa       EQU 4
Enemy_6Ya       EQU 11
Enemy_6Xb       EQU 28-Enemy_6Xa
Enemy_6Yb       EQU 23-Enemy_6Ya

Enemy_7Speed    EQU  1
Enemy_7Strength EQU 3
Enemy_7Points   EQU 100
Enemy_7SpawnRate EQU 255
Enemy_7Xa       EQU 15
Enemy_7Ya       EQU 0
Enemy_7Xb       EQU 31-Enemy_7Xa
Enemy_7Yb       EQU 31-Enemy_7Ya

Enemy_8Speed    EQU  1
Enemy_8Strength EQU 10
Enemy_8Points   EQU 100
Enemy_8SpawnRate EQU 255
Enemy_8Xa       EQU 5
Enemy_8Ya       EQU 9
Enemy_8Xb       EQU 31-Enemy_8Xa
Enemy_8Yb       EQU 31-Enemy_8Ya

Enemy_9Speed    EQU  1
Enemy_9Strength EQU 10
Enemy_9Points   EQU 100
Enemy_9SpawnRate EQU 255
Enemy_9Xa       EQU 5
Enemy_9Ya       EQU 9
Enemy_9Xb       EQU 31-Enemy_9Xa
Enemy_9Yb       EQU 31-Enemy_9Ya

Enemy_10Speed    EQU  1
Enemy_10Strength EQU 10
Enemy_10Points   EQU 100
Enemy_10SpawnRate EQU 255
Enemy_10Xa       EQU 5
Enemy_10Ya       EQU 9
Enemy_10Xb       EQU 31-Enemy_10Xa
Enemy_10Yb       EQU 31-Enemy_10Ya

Enemy_11Speed    EQU  1
Enemy_11Strength EQU 10
Enemy_11Points   EQU 100
Enemy_11SpawnRate EQU 255
Enemy_11Xa       EQU 5
Enemy_11Ya       EQU 9
Enemy_11Xb       EQU 31-Enemy_11Xa
Enemy_11Yb       EQU 31-Enemy_11Ya

Enemy_12Speed    EQU  1
Enemy_12Strength EQU 10
Enemy_12Points   EQU 100
Enemy_12SpawnRate EQU 255
Enemy_12Xa       EQU 5
Enemy_12Ya       EQU 9
Enemy_12Xb       EQU 31-Enemy_12Xa
Enemy_12Yb       EQU 31-Enemy_12Ya

Enemy_13Speed    EQU  1
Enemy_13Strength EQU 10
Enemy_13Points   EQU 100
Enemy_13SpawnRate EQU 255
Enemy_13Xa       EQU 5
Enemy_13Ya       EQU 9
Enemy_13Xb       EQU 31-Enemy_13Xa
Enemy_13Yb       EQU 31-Enemy_13Ya

Enemy_14Speed    EQU  1
Enemy_14Strength EQU 10
Enemy_14Points   EQU 100
Enemy_14SpawnRate EQU 255
Enemy_14Xa       EQU 5
Enemy_14Ya       EQU 9
Enemy_14Xb       EQU 31-Enemy_14Xa
Enemy_14Yb       EQU 31-Enemy_14Ya

Enemy_15Speed    EQU  1
Enemy_15Strength EQU 10
Enemy_15Points   EQU 100
Enemy_15SpawnRate EQU 255
Enemy_15Xa       EQU 5
Enemy_15Ya       EQU 9
Enemy_15Xb       EQU 31-Enemy_15Xa
Enemy_15Yb       EQU 31-Enemy_15Ya

Enemy_16Speed    EQU  1
Enemy_16Strength EQU 10
Enemy_16Points   EQU 100
Enemy_16SpawnRate EQU 255
Enemy_16Xa       EQU 5
Enemy_16Ya       EQU 9
Enemy_16Xb       EQU 31-Enemy_16Xa
Enemy_16Yb       EQU 31-Enemy_16Ya
 

VidGrSEG   EQU 0A000h

CR   EQU 13
LF   EQU 10

; Directions
AI   EQU 777
UP_RIGHT   EQU 1-320
UP_LEFT    EQU -1-320
DOWN_RIGHT   EQU 320+1
DOWN_LEFT   EQU 320-1
STOP    EQU 0
LEFT    EQU -1
RIGHT    EQU 1
UP   EQU -320
DOWN    EQU 320

VARIABLES
Errormsg   db 'Error Opening File', '$'    ; Error messages used in file I/O
Errormsg2  db 'Error Reading File', '$'
Errormsg3  db 'Error In Midifile File', '$'

BackStart  dw 0     ; Joes
ErrMsg1   db  'LoadBMP Error: File Not Found','$'
OldCurPos  dw 0

exitflag   db 0
Mouseleftdown db 0
MouseRightDown db 0

NumberOfMissiles db ? ; Declare the number of missiles initially to NumMissles
AnimatedShip  dw 0    ; Indexes the cycle through animation
AnimatedExplode dw 0    ; Indexes the cycle through animation
bossready  db 0 ; Decision of if the boss is active or not
Bosskilledus db 0

; timing stuff
oldv     DD  ? ; Old Vector (far pointer to old interrupt function)
millicount dw  0
count    DW  0 ; Interrupt counter (1/18th second)
clock_ticks    DW  0
counter        DW  0
scount    DW  0 ; Second counter
mcount    DW  0 ; Minute counter
LargePrime  dw 65141 ; Really big primenumber used to seed random number generator

SizeObjectType DB Sizeof ObjectType

object OBJECTTYPE 64 dup (< >) ; 64 images/structs of objectype
OptionArray DW OptionDelay dup (InitialMousePosition)  ; Used to give delay option (Stores previous linear address)
SongArray  DW offset MidiFile_0
     DW offset MidiFile_1
     DW offset MidiFile_2
     DW offset MidiFile_3
     DW offset MidiFile_4
     DW offset MidiFile_5
     DW offset MidiFile_6
     DW offset MidiFile_7
     DW offset MidiFile_8

Parray    DB   768*2 DUP (?)   ; Array to hold 2 entire palettes
 

PlayerScore dw 0 ; my score for the player, whatever Josh is using
NumberLives db 8 ; number of ships/lives
MidiWorking  DB 1   ; Tells if the midi was activated

scorestring db 'Score '
healthstring   db 'Fuel  '
livesstring db 'Lives '
missilestring  db 'Missiles '
 

printablescore db 7 dup (?)
printablemissile  db 7 dup (?)
 
 



Procedures:
(MP4 code converted to 256, and addition code added)

InstallTimer
Inputs: None
Outputs: count - gets count rate
         clock_ticks - set to zero
Notes: Installs MyTimer onto INT 8. Uses the format form John Lockwood's INT8.asm file
       Also uses resources from ECE class resources page the pit.txt file from
       PC game encyclopedia(webpage www.ece.uiuc.edu/~ece291/class..pit.txt). Other
       procedures also using John Lockwood and webpage format: DeInstallTimer and MyTimer
Author: Sergio Solomon

DeInstallTimer
Inputs: Oldv - has old segment:offset of INT8 address
Outputs: None
Notes: DeInstalls the timer interrupt. Makes everything good again
       by Deinstalling Routine (Reinstall old vector)
Author: Sergio Solomon

Waitfortick
Inputs: None
Outputs: millicount - incremented
Notes: Used to get Main sychronized with timer. Will wait for next clocktick
       before leaving procedure. Updates millicount used by other routines.
Author: Sergio Solomon

Random200Num
Inputs: None
Outputs: CX - stores random number b/w 0 and 200
Notes: Returns a random num between 0 and 200 - or close. Doesn't use DIV and uses
        LargePrime number found from ECE291 class resources page
Author: Nick Bhavsar
 

Random320Num
Inputs: None
Outputs: CX - stores random number b/w 0 and 320
Notes: Returns a random num between 0 and 320 - or close. Doesn't use DIV and uses
       LargePrime number found from ECE291 class resources page
Author: Nick Bhavsar

GetTick
Inputs: None
Outputs: CX 0 random tick from system timer
Notes: Returns tick in cx
Author: Sergio Solomon

ResetTimer
Inputs: None
Outputs: count - set to zero
         scount - set to zero
         mcount - set to zero
Notes: Reset these variables to zero for the begining of the game
Author: Nick Bhavsar

MidiResume
Thanks to MidPack - easy midi solutions
Owner: Nick Bhavsar
Function #12: ResumePlaying -> resume playing stopped sequence.
INPUT: AX = 70Bh Command number.
Outputs: None
Description: Resumes play of a midi that is already loaded

MidiPlay
Credits to MidPak
Onwer: Nick Bhavsar
Function #3: PlaySequence, plays a sequence from the currently registered xmidi file.

INPUT: AX = 702h Command number.
       BX = SEQ  Sequence number, numbered starting from zero.

OUTPUT:AX = 1  Sequence is being played.
       AX = 0  Sequence not available.
Description: Plays a midi that is already loaded

MidiStop
Onwer: Nick Bhavsar
Function #6: MidiStop, stop playing current MIDI sequence.
INPUT AX = 705h Command.
OUTPUT: None.
Description: Stops a midi from currently playing

MidiRegister
Function #5, RegisterXmidi, Register an XMIDI file by address for playback.

 INPUT: AX = 704h Command number.
  BX = Offset Offset portion of far address of XMIDI data.
  CX = Segment Segment portion of far address of XMIDI data.
  SI = Low len Low word of length of XMIDI data.
  DI = High len High word of length of XMIDI data.

OUTPUT: AX = 0  Unable to register XMIDI data.
 AX = 1  XMIDI file registered resident.  This means
   that the XMIDI file was able to be held
   entirely in MIDPAK's internal buffer area.
   The application can throw away the memory
   associated with this XMIDI file because
   MIDPAK has made a copy of it for itself.
   This is very useful in virtual memory
   environments where the application program
   does not always have fixed addresses in
   memory.  It also allows MIDPAK to play
  back MIDI files in the background from DOS.

 AX = 2  XMIDI file was registered to the appilcation.
   The caller is responsible for making sure that
   this fixed memory address is always contains
   the data as passed.
 Onwer: Nick Bhavsar
 Registers a midi file into memory

MidiStatus
Owner: Nick Bhavsar
Inputs: BX - which song to load
Outputs: None
Description: Loads midi data into midi segment

Function #13: SequenceStatus -> report sequence status.

 INPUT: AX = 70Ch Command number.
 OUTPUT: AX = Status.
  SEQ_STOPPED 0  // equates for SequenceStatus()
  SEQ_PLAYING 1  // Sequence is currently playing.
  SEQ_DONE 2  // A sequence is DONE playing.
 Owner: Nick Bhavsar
 Description: Gets the status of the midi file currently loaded
 

InitMouse
Owner: Nick Bhavsar
Inputs: None
Outputs: None
Desscription Initializes Mouse and shows it on the screen near the left center of the screen

CalcNewPosition
Owner: Nick Bhavsar
Inputs: DI - Objects current position
        CX - Object's Path
        DL - Object's Speed
Outputs: DI - New position
Description: Inputs the objects current position and calculates the new position based on the
               speed and path.  The formula is: New_Position = Old_Position + Speed*Path

FloodOptionArray
Owner: Nick Bhavsar
Inputs: AX - Value to fill the option array
Outputs: Filled option array
Description: Fills the option array so that when the ship's position is instantly changed
             ; the lag effect does not happen - useful in the begining of the game so that the
             ; option does not sit in the middle of the screen while the ship is centered

FindNonActiveGun
Owner: Nick Bhavsar
Inputs: None
Ouputs: BX - Returns the index of a gun shot that can be display
Description: Allows more than one gun shot to appear one the screen at one time,
             ; but does not allow more than specified number (MissileIndex-GunIndex)

FindNonActiveGun
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Draws the pixelized rope between the ship and the option

DrawRope
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Draws the pixelized rope between the ship and the option

CheckAsteroidDir
Owner: Nick Bhavsar
Inputs: DI - Ships current position
Ouputs: None
Description: Checks if the position of the ship should cause a direction change of the asteroids

ShipUpdate
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Updates the position of the ship and updates the asteroids

OptionUpdate
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Moves the option so that it follows the ship

Mousemove
Inputs: None
Ouputs: None
Description: ; Checks mouse activity and sets appropriate values

ExplodeUpdate
Owner: Nick Bhavsar
Inputs: DI - Animate the explosion at this position
Ouputs: None
Description: Spawns an animation that will be updated on the timing base

RandomAsteroidLocation
Owner: Nick Bhavsar
Inputs: None
Ouputs: DI - Location of Asteroid for random spawn
Description: Returns a location either the right side of the screen if the ship is in the center
             ; or location at the top of the screen if the ship is near the top
             ; or location at the bottom of the screen if the ship is near the bottom

UpdateAsteroidLocation
Owner: Nick Bhavsar
Inputs: AX - Path of the asteroids (All asteroids are always the same)
Ouputs: None
Description: Calls functions which change the direction of all the asteroids

FarActivateAsteroid
Owner: Nick Bhavsar
Inputs: AX - Index of the asteroid to index
Ouputs: None
Description: Activates an asteroid and calls function to spawn it

CloseActivateAsteroid
Owner: Nick Bhavsar
Inputs: AX - Index of the asteroid to index
Ouputs: None
Description: Activates an asteroid and calls function to spawn it

RandomAsteroid
Owner: Nick Bhavsar
Inputs: None
Ouputs: Spawns asteroids and changes ImageArray and Object structure
Description: Spawns all random asteroids calling other asteroid functions

ShowHit
Owner: Nick Bhavsar
Inputs: AX - Index of the object that got hit
Ouputs: None
Description: Activates the hit image around the ship that was shot

SpawnFuel
Owner: Nick Bhavsar
Inputs: None
Ouputs: ImageArray and ObjectArray
Description: Spawns fuel upgrade every few seconds

SpawnEnemies
Owner: Nick Bhavsar
Inputs: None
Ouputs: Changes Object structure if an enemy is spawned
Description: Spawns enemies at random times and spawns fuel

LoadOneImage
Owner: Nick Bhavsar
Inputs: DX - Offset of the imagefile
      ; AX - Index of the image for the image array
Ouputs: None
Description: Loads one image into the image array

DeActivateEveryone
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Deactivates all objects on the screen - used after a death or before
             ; the boss is spawned

ActivateEndBoss
Owner: Nick Bhavsar
Inputs: None
Ouputs: None
Description: Activates the end boss tiles and spawns all enemies with AI

CheckBossReady
Owner: Nick Bhavsar
Inputs: None
Ouputs: Returns bossready flag: 0 - not ready, 1 - ready for end boss
Description: Checks if the gameplay is ready for the end boss

SetupGamePlay
Owner: Nick Bhavsar
Inputs: None
Ouputs: Initializes ImageArray, Object structure
Description: Sets the entire gameplay up to default values in varconst.asm
 

FadeOut:
Owner: Nick Bhavsar and Sergio Solomon
Inputs: none
Outputs: Black Screen
Description: Fades the screen to black and waits so the fade is the same time on all PC's

FadeIn
; Owner: Nick Bhavsar and Sergio Solomon
; Inputs: BX - the number of lines to fade the screen in from
; Outputs: None
; Description: Draws lines across the screen to appear like a fade

DoFadeIn
Owner: Nick Bhavsar and Sergio Solomon
Inputs: None
Outputs: None
Description: Fades the entire screen from the blacked out screen to the background

LoadBMP:
Purpose:     Load a 256 color BMP file from disk to memory
Input:       DX: Pointer to the null terminated string with the file name
Output:      Contents of file stored in Variable BMP
Description: INT 21h used to open and read a file from the disk. The contents of the file
             will be stored in the variable called BMP.
Owner:       Nick Bhavsar

DrawBox
Purpose:     Draw a filled square on the screen
Inputs:      AL: Color, 0-255
             DI: Screen location (top left corner)
Output:      Writes directly to screen
Description: Draws a 32x32 filled square on the screen using the palette number specified in
             AL.
Owner:       Nick Bhavsar

StoreBMP
Purpose:     Convert BMP data and store to image array.
Inputs:      AX: Image Number (0..63)
             DS:SI: Pointer to BMP data (Segment:Offset)
Output:      1024 bytes written to AXth element of ImageArray
Description: Converts a 256 color, 32x32-pixel BMP image to a VGA mode-13h
             formatted array of bytes and stores the data in an array.
Owner:       Nick Bhavsar

DrawBMP
Purpose:     Write an image to the screen
Inputs:      AX: Image Number (0..63)
             DI: Screen location (top-left corner)
             Variable ImageArray
Output:      Draws directly to screen
Description: Draws the AXth image from ImageArray to the VGA display.
             DI is specified as a offset on a mode-13h screen.
Owner:       Nick Bhavsar

XyConvert
Purpose:     Converts X, Y coordinates to a linear memory address
Inputs:      BX: X coordinate
             CX: Y coordinate
Output:      DI - linear address
Description: Multiplies the Y coordinate by 320 and adds the X coordinate offset
Owner:       Nick Bhavsar

DiConvert
Purpose:     Converts a linear memory address to X, Y coordinates
Inputs:      DI - linear address
Output:      BX - X Coordinate
             CX - Y Coordinate
Description: Divides the linear address by 320, the remainder is the X Coordinate, and the
             Quotient is the Y coordinates
Owner:       Nick Bhavsar

CalcNewPosition
Purpose:     Calculates the new position of an object (used for Animation)
Inputs:      CX - Path
             DL - Speed
          DI - Current Position
Output:      DI - New Position after calculated movement
Description: Equations for movement New_Position = Old_Position + Speed*Path
Owner:       Nick Bhavsar

PlayerIndex
Purpose:     Calculate the new index for Object Array
Inputs:      BX - Current Index of Image Array (0-63)
Output:      BX - New Index for Object Array (0-63*SizeofObject)
Description: Calculation equations: New_Index = Old_Index * SizeofObject.  By using this
             function, if the size of the Object Structure changes, no code changes will need
             do be made
Owner:       Nick Bhavsar

UpdateEveryone
Purpose:     Draw all active elements to the screen
Inputs:      None
Output:      Active elements drawn to the screen
Description: Loops through Object Array checking if elements are active, and calls UpdateObject
             for all Active elements with correct index
Owner:       Nick Bhavsar and Sergio Solomon

PlayerUpdate
Inputs: AX - Object index in imagearray
Outputs: None
Notes: PlayerObject will update a general object's coordinates in object array
       and draw that object to screen.
Author: Sergio Solomon

CollisionCheck
Input:  AX - Object that is being tested(near a possible collision) aka colling object
Output: BX - Corrected enemy index that had collision if there was one else BX is set
         to zero.
Notes:  CollisionCheck will go through each active enemy and decide if a
         collision occured. Collisions are based on the MP5 tag method except that
         instead of a bulky 32x32 box for the objects boundaries, each object has
         specific coordinates making the "hits" more realisitic.
         collisions more real.
Author: Sergio Solomon
 

EnemyHit
Input: AX - Weapon index(gun or missile)
     BX - object index(already calculated)
Outputs: None
Notes: EnemyHit takes cares of status of the enemy object that was just hit.
        EnemyHit first checks if the enemy is dead. If the enemy is dead then it starts
        an explosion at the enemies position and deactivates it, else the enemy's strength
        is subtracted from the weapon strength.
Author: Sergio Solomon and Nick Bhavsar

MainShipHit
Inputs: BX  - Corrected object index that hit ship
Output: None
Notes:  MainShip hit processes the logic when it hits another object. Depending upon
         the object hit, the main ship will die, or upgrade itself with a power-up
Author: Sergio Solomon and Nick Bhavsar

MissileAI
Inputs: None
Outputs: None
Notes: MissileAI will find (and try) to kill first active enemy that is in range of
        missile. Which means it will loop through all the enemies and target the
        first active enemy that is in front of missile's path.
Author: Sergio Solomon

UpdateObject
Purpose:     Draws the specified element to the screen after checking boundary conditions
Inputs:      AX - Index of the Image to be drawn to the screen
Output:      Draws the BMP of the specified image to the screen
Description: Checks if the specified element is being asked to be drawn outside of the screen
             boundaries - if so set the element to inactive.  Otherwise calculate the objects
             new position and display the image on the screen
Owner:       Nick Bhavsar

Mousemove
Purpose:     Updates the position of the ship
Inputs:      None
Output:      Updates the ship's position and sets guns or missiles to active if necessary
Description: Polls the mouse for current position, and checks if the left mouse button is
             pressed to initiate a gun shot routine.  Right mouse button initiates a missile
Owner:       Nick Bhavsar

LoadOneImage
Purpose:     Loads one image into the image array
Inputs:      DX - Offset of the image file
          AX - Index of the image to image array
Output:      Image stored in image array
Description: Load the Image using LoadBMP, then store it using StoreBMP
Owner:       Nick Bhavsar

SetupGamePlay
Purpose:     Loads all images before game play and sets default values from constants
Inputs:      None
Output:      ImageArray loaded and default values for ObjectArray set
Description: Call LoadOneImage for each image.  Set ObjectArray for each object
Owner:       Nick Bhavsar

InstallTimer
Purpose:     Installs timer interrupt at variable frequency (possible higher than 18.2/sec)
Inputs:      None
Output:      CPU Timer is altered
Description: CPU Timer is quickened to allow accurate timing game play
Owner:       Sergio Solomon, Nick Bhavsar (modifying John Lockwood's INT8 source code)

DeInstallTimer
Purpose:     Uninstalls timer interrupt
Inputs:      None
Output:      CPU Timer is set back to the default
Description: Restore previous timing interrupt
Owner:       Sergio Solomon, Nick Bhavsar (modifying John Lockwood's INT8 source code)

MyTimer
Purpose:     Increment count variable
Inputs:      None
Output:      Count variable is incremented to a specified value then reset to 0
Description: Increment the count variable up to a specified value, then reset it to 0
Owner:       Sergio Solomon, Nick Bhavsar (modifying John Lockwood's INT8 source code)

Gmode
Purpose:     This is a simple macro that changes the display mode to 320x200 with 256 colors.
Inputs:      None
Output:      None
Owner:       Joe Petrovic

DrawScreen
Purpose:     This function transfers the content of the ScreenBuffer to the screen.  This
             function is called after all functions that write to the graphics buffer are
             called.
Inputs:      ScreenBuffer
Output:      Writes to video memory at segment A000h
Owner:       Joe Petrovic

DrawBackground
Purpose:     This function writes the background to the ScreenBuffer. The background scrolls
             during the game so the background is either made up of a single bitmap with 64k of
             data or a part of two bitmaps each with 64k of data.  This function decides which
             bitmap(s) to write and which part of each bitmap to write depending on the value
             of BackStart.
Inputs:      Background bitmap data stored in CPU memory BackStart
Output:      ScreenBuffer
Owner:       Joe Petrovic

LoadBack
LoadBack  Written by: Joe Petrovic
Inputs:  None
Outputs:  "back1" and "back2"
This procedure loads the two background bitmaps into segments of memory

LoadMenu
Written by Joe Petrovic
Inputs:  MMenu.bmp MMenu1.bmp MMenu2.bmp
Outputs:  ScreenBuffer, back1 and back2
This function loads the main menu file (MMenu.bmp) and puts in ScreenBuffer.  It
also stores the contents of MMenu1.bmp in back1 and MMenu2 in back2.  These two
files will by used for the animation of the main menu.

DrawCursor
Written by Joe Petrovic
Inputs: CX = Column position of mouse. DX = Row position of mouse.
Outputs: ScreenBuffer, OldCurPos, Back1
This procdure takes the cursor icon from back1 and puts it in ScreenBuffer using the screen
coordinates of the mouse.

EraseCursor
Written by Joe Petrovic
Inputs: OldCurPos, Back1
Outputs: ScreenBuffer
This procedure erases the cursor.  This procedure is called before the DrawCursor procedure is
called.  It erases the cursor at the previous mouse location so that the old cursor does not
remain on the screen.

DrawDoor1
Written by Joe Petrovic
Inputs: Back2
Outputs: ScreenBuffer
This procedure simulates door1 (game start door) opening.

CloseDoor1
Written by Joe Petrovic
;Inputs: Back2
;Outputs: ScreenBuffer
;This procedure simulates door1 (game start door) closing.

DrawDoor2
Written by Joe Petrovic
Inputs: Back2
Outputs: ScreenBuffer
This procedure simulates door2 (exit game door) opening.

CloseDoor2
Written by Joe Petrovic
Inputs: Back2
Outputs: ScreenBuffer
This procedure simulates door2 (exit game door) closing.

DrawFolder
Written by Joe Petrovic
Inputs: Back1
Outputs: ScreenBuffer
This procedure simulates the folder in the guys hand opening.

CloseFolder
Written by Joe Petrovic
Inputs: Back1
Outputs: ScreenBuffer
This procedure simulates the folder in the guys hand closing.

DrawCmenu;DrawCMenu  Written by Joe Petrovic
Written by Joe Petrovic
Inputs:  CMenu.bmp
Outputs:  (Draws to screen)
This procedure displays the credits menu.  It loads the bitmap that the menu is stored in,
move it to screen buffer, displays it on the screen, and waits for LMB before returning to
the main menu.

DrawImenu
Written by Joe Petrovic
Inputs:  IMenu.bmp
Outputs:  (Draws to screen)
This procedure displays the instruction menu.  It loads the bitmap that the menu is stored in,
move it to screen buffer, displays it on the screen, and waits for LMB before returning to
the main menu.

EnemyAI
Purpose:     Makes any object on screen except main ship smart. The intelligence
             comes for the equation of a line y =m*x + b. It finds a straight line
             and adjsuts the objects speed to proceed to that line by moving up, down
             left, or right.
Inputs:      BX - Index to object Array
             SI - Index to object that AI is trying to follow
Outputs:     None
Description: Updates Speed and Path attributes of ObjectType
Owner:       Sergio Solomon

EnemyUpdate
Inputs: AX  - Index of enemy to update
Outputs: None
Notes: EnemyUpdate will update the coordinates of all enemies. Once again this is a
        general procedure that updates all enemies but calls specific procedures to
        update the actual coordinates.
Author: Sergio Solomon

New_Enemy
Purpose:     Sets attributes for a an enemy to appear on the screen.
Inputs:      BX - correct index to object array
             AH - strength value
             AL - speed value
             DX - Points(default if set to 1)
             SI - initial row position
Outputs:     Updates ObjectArray
Description: Makes new enemy on the screen
Owner:       Sergio Solomon

CalcEnemyPosition
Inputs: BX - Corrected index of object to calculate its position
Outputs: None
Notes: CalcObjectPosition will calculate an objects new position. Will not actually
        calculate the position but uses a helper function to do the work for it. This
        procedure just helps make the code easier to read and saves the preservation of
        reagisters in other procedures.
Author: Sergio Solomon
 

Collision_Check
Purpose:     When gunfire is on the screen this procedure will check all active
             objects and the objects that have coordinates near the gunfire will
                 become deactivated. Will also do collision checking for the main ship.
             Will be similar to MP5 tag boundaries
Inputs:      BX - gunfire index
Outputs:     AL - 0 if false, AL - 1 if true(collision)
Description: Goes through each active enemy and decide if a collision occurred
Owner:       Sergio Solomon

PrintvBiosChar
Purpose:     Prints an ASCII character to the screen
Inputs:      AH - color of char
             AL - ASCII value of char
             DI - screen offset to print at
Outputs:     Prints character to screen
Notes:       Character comes from vBIOS font set and is 8x8
Owner:       Josh Bishop

ShowLives
;Inputs: none
;Outputs: NumberLives to screen
;Description: prints "Lives " and then shows lives left with
;  ship icons that are defined pixel-wise in proc.
;  uses PrintBiosChar
;Author: Josh Bishop

ShowScore
Purpose:     Displays score on screen
Inputs:      Variable Score
Outputs:     Display on screen
Notes:       Uses PrintvBiosChar to display numbers
Owner:       Josh Bishop

ShowHealth
Inputs: none
Outputs: Fuel to screen
Description: prints "Fuel " and then the amount of fuel remaining
  shown by bars on the screen.  determined by ship's strength
  value in object array when indexed by PlayerIndex
Author: Josh Bishop

ShowMissile
Inputs: none
Outputs: NumberOfMissiles to screen
Description: prints "Missiles " and then number of missiles left to screen
  according to NumberOfMissiles variable. uses PrintBiosChar
Author: Josh Bishop
 

PrintBiosChar
Inputs: ah = color of char
     al = ascii value of char
     di = offset to print at
Outputs: vBIOS character on screen
Description: uses font table in video bios to print
             characters to screen
Author: Josh Bishop

OpenWav
Input: bx = # of file to open
Output: eax = data length = bytes of Sound Data.
Description: OpenWav opens a wav file and advances to the beginning of data
  modified only slightly from sbtest.asm to allow for dynamic file loading
Author: Josh Bishop

PlaySound
Inputs: bx = # of file to play
Outputs: sound to DSP
Description: modified from main of sbtest.asm to play wav file opened by
    WavOpen.  Adapts Loop structure to a procedure by resetting variables
    upon exit and extracting sound stop procedures to allow for real time
    playback during gameplay
Author: Josh Bishop

SBlib291
We used the SBLib291 functions for sound

Main
Purpose:     Loops through main menu and game engine
Input:       None
Output:      Exit
Owner:       Team

MAIN PROC FAR
    mov    ax, cseg                ; Initialize Default Segment register
    mov     ds, ax

    Call InitMouse
    Call Installtimer        ; Insert my ISR

    GMODE
GetOut:

    Call LoadMMenu ;Load the main menu bitmap into Screen Buffer and Main Menu execution

StartGame:
    mov Bosskilledus, 0
    Call ResetTime

    Call SetupGamePlay

    Call    DrawBackground
    Call    DrawScreen

    Call    DoFadeIn           ; Fade to original colors

    mov bx, GamePlaySong           ; BX index of what song to play
    Call MidiLoad
    mov bx, GamePlaySong
    Call MidiRegister
    Call MidiPlay

    mov exitflag, 0

RunProgram:
 ; waits until interrupt is called
 Call Waitfortick

 Call MouseMove        ; Update CurPosition, Exit status, and shoot if called
 cmp ExitFlag, 1
 JE GetOut

 mov   ax, ShipIndex
 Call  CollisionCheck ; for main ship
 cmp   bx, 0
 je    MainShipOkay
 call  MainShipHit
 jmp   DontUpdate

MainShipOkay:
 cmp bossready, 1
 JE DontBackscroll

 mov ax, count
 Test ax, BackgroundSpeed
 JNE DontBackscroll

 ADD BackStart,1
 inc AnimatedShip
 JMP DontBackscroll

DontBackscroll:
 mov ax, scount
 and ax, 1
 cmp ax, 1  ; Every other second check for midistatus done
 jne UpdateEveryonelabel

 Call Checkbossready ; Checks if the time limit for the boss is there and
    ; sets bossready flag, and fades out to boss screen

 cmp MidiWorking, 1      ; Nick checks if the midi file is done playing to loop it continuously
 JNE UpdateEveryonelabel    ; If the Midi file is not working, then dont check to see if loop continuously
 Call MidiStatus
 cmp ax, 1
 JE UpdateEveryonelabel
 mov bx, 8           ; BX index of what song to play
 Call MidiLoad
 mov bx, 8     ; Reloads entire midi after playing it once
 Call MidiRegister
 Call MidiPlay

 JMP UpdateEveryonelabel

UpdateEveryonelabel:
 Call SpawnEnemies       ; Spawns Enemies randomly

 Call DrawBackground
 Call RandomAsteroid
 Call UpdateEveryone

 Call CheckBossDead
 mov  ExitFlag, al  ; Still escape with both mouse buttons

 Call ShowScore
 Call ShowHealth
 Call ShowLives
 Call ShowMissile

 Call DrawScreen

DontUpdate:
    cmp Bosskilledus, 1
    JE StartGame

    cmp ExitFlag, 1
    JNE RunProgram

    JMP GetOut

LeaveGame:

    Call MidiStop       ; Stop playing current midi file
    Call FadeOut          ; Fade screen to black
    Call DeInstallTimer         ; Restore original INT8
    TMODE           ; Switch back to text-mode video
    call    dosxit                  ; Exit to DOS

MAIN ENDP
 
 



ScreenShot:
The following screen shot is a display of game play.  We have not selected a background image,
so right now this is the default one.  Also the images will be displayed using invisible pixels so they will not appears as cubes.  I left them as cubes below so you can easily see the images.

MENU Screen Shot