ECE 291
Computer Engineering II
Prof: John Lockwood: Spring 1999
 
 
Procedures:
 
The following is a list of the main procedures and subroutines we will be using for "THE x86 MAZE". We have defined each routines' author, purpose, inputs, outputs, assumptions (if any), and description.  WE have decided to publish our source code, please refer to this for further detail.  
 
 
Main_Draw_Screen
 
BY: Asher C. Martin & Robert Ikeoka 
PURPOSE: THIS FUNCTION IS CALLED FROM WITHIN OUR MAIN LOOP.  IT DECIDES WHETHER TO LOAD A IMAGE OR TEXT.
INPUT: THIS PROC. LOOKS AT THE VALUES OF VIDEO_MODE & UPDATE_SCREEN.  DEPENDING ON THESE VALUES IT WILL DISPLAY THE CORRECT VIDEO MODE.
OUTPUT: MAIN SCREEN SEG
ASSUMPTIONS: NONE
DESCRIPTION: THIS PROCEDURE REGULATES HOW OFTEN THE SCREEN IS UPDATED AND WHAT SORT OF UPDATES NEED TO BE MADE DEPENDING ON THE VARIABLES SET SUCH AS VIDEO_MODE AND the UPDATE_SCREEN FLAGS.
 
 
Main_Engine
 
BY: Asher C. Martin & Robert Ikeoka
PURPOSE: This function is called from within our main loop. THE MAIN PROGRAM ENGINE KEEPS TRACK OF THE PLAYER, DRAWS THE TILES, DRAWS THE PLAYER NUMBER, LEVEL, AND FIGURES OUT THE GENERAL PLACEMENT OF EVERTHING ON THE SCREEN
INPUT: JUST ABOUT EVERYTHING
OUTPUT: EVERYTHING IS SENT TO THE MAIN_SCREEN_SEG
ASSUMPTIONS: NONE
DESCRIPTION: This function is called each time the main loop is run.  It is dependent on the system timer as to how often.  It positions the player on the screen and analizes if this position is valid.  It also keeps track of enemy positions. 
 
CALLS:
DISP_PLAYER, SYSTEM_TIMER, DISP_ENEMY, DISP_OBSTICLES, UPDATE_MAIN_MAP, UPDATE_SMALL_MAP.
 
 
Initialize_AI
 
BY: Robert Ikeoka
INPUT: mazemap.dat
OUTPUT: ai_seg:MazeMap, ai_seg:VectorMap, ai_seg:horizontalsize, ai_seg:vertical size
DESCRIPTION: Loads the map file "mazemap.dat" into memory, and creates a "vector map" that will be able to determine what directions players will be able to move, as well as what kind of cell they are in (border, start, end, etc.). The procedure also determines the width and height of the map. map file format 
 "width in ascii" cr,lf 
 "height in ascii", cr, lf 
 "map data", cr, lf
 
 
Install_Timer
 
BY: Robert Ikeoka
INPUT: NONE
OUTPUT: oldint08vector, oldint1cvector
DESCRIPTION: Installs the timer interrupt patch: for both int 08h and 1ch
 
My08Int
 
BY: Robert Ikeoka
INPUT: NONE
OUTPUT: NONE
DESCRIPTION: Patch for the bios int 8 procedure, does not emulate the bios, it will not manage clock time.  causes an int1c every ms. by setting the clock counter to a value that when in divide-by-N mode will interrupt every 1ms
 
 
My1CInt
 
BY: Robert Ikeoka
INPUT: timer_count
OUTPUT: timer_count
DESCRIPTION: Patch for the default int 1c procedure, keeps track of the count in the variable timer count.
 
 
Uninstall_Timer
 
BY: Robert Ikeoka
INPUT: Old08Vector
OUTPUT: Old08Vector
DESCRIPTION: Restores default int handlers for int 08h and 1ch
 
 
Delay
 
BY: Robert Ikeoka
INPUT: ax,  "Delay time ms.", Timer_count
OUTPUT: Old1cVector
DESCRIPTION: Delays the number of ms given in ax
 
 
AI_Move
 
BY: Robert Ikeoka
INPUT: Player <Player Array> 
                         ai_seg:horizontal_size 
                         ai_seg:Vector_Map 
                         ai_seg:aiDirections 
                         ai_seg:aihead 
                         ai_seg:aitail 
                         ai_seg:aiQueueMap
OUTPUT: Player <Player Array> 
                         ai_seg:horizontal_size 
                         ai_seg:Vector_Map 
                         ai_seg:aiDirections 
                         ai_seg:aihead 
                         ai_seg:aitail 
                         ai_seg:aiQueueMap
DESCRIPTION: Allows the computer to move.  Uses a depth first traversal routine.
 
 
Test_IF_Valid_Position
 
BY: Robert Ikeoka
INPUT: Player <Player ARRAY>, ax playernum
OUTPUT: Player<Player Array> with new player position & updated old position 
DESCRIPTION: Procedure determines if a move is possible
 
 
Update_Statistics
 
BY: Robert Ikeoka
INPUT: Player <Player ARRAY>, ax playernum
OUTPUT: Player<Player Array>
DESCRIPTION: Procedure keeps track of statistics
 
 
Draw_Player_Image
 
BY: Asher C. Martin
PURPOSE: THIS FUNCTION SENDS THE PLAYERS IMAGE TO THE MAIN_SCREEN_SEG
INPUT: FROM = DS:[SI] (LOCATION OF THE IMAGE)
OUTPUT: TO = (ES=MAIN_SCREEN_SEG):[DI] LOCATION ON THE SCREEN 
ASSUMPTIONS: NONE
DESCRIPTION: THIS FUNCTION IS A HELPER FUNCTION OF DISP_PLAYER. IT IS USED TO DIVIDE UP THE WORK OF DISP_PLAYER.
 
 
Draw_Screen
 
BY: Asher C. Martin
PURPOSE: THIS FUNCTION LOADS A IMAGE TO THE SCREEN FROM THE MAIN_SCREEN_SEG (WE ARE DOUBLE BUFFERING)
INPUT: Whatever is in the MAIN_SCREEN_SEG is sent to the screen!
OUTPUT: IMAGE starting at A000:0000 in MODE 13h on a 320x200x256SCREEN
ASSUMPTIONS: THIS FUNCTION IS A HELPER FUNCTION OF MAIN_DRAW_PCX. IT ASSUMES THAT THE MAIN_SCREEN HAS BEEN UPDATED BY *EVERY*FUNCTION AND THAT THE UPDATE SCREEN FLAG IS SET.
DESCRIPTION: THIS IS THE PRIMARY WORK HORSE THAT DRAWS THE SCREEN AND  DECODES THE PCX IMAGE LOCATED IN THE MAIN_SCREEN_SEG  (MODIFIED VERSION OF THE LAB MANUALS CODE)
 
 
Main_GPS
 
BY: Asher C. Martin
INPUT: Nothing
OUTPUT: Nothing
ASSUMPTIONS: NONE
DESCRIPTION: THIS IS OUR "GLOBAL POSITIONING SYSTEM" OF THE PLAYER'S,ENEMIES, AND OBSTACLES IN THE MAZE.  IT ALSO KEEPS TRACK OF PRIMARY VARS. SUCH AS INPUTVALID AND IF THE USER INTENDS TO EXIT.
 
 
Disp_Player
 
BY: Asher C. Martin
PURPOSE: This procedure displays the player on the screen.  IT ALSO UPDATES THE AI.
INPUT: Function is executed on a key press or when the update_screen flag is set (by set we mean == 1)
OUTPUT: Disp_Player updates the computers maze map at GS:MAZEMAP[DI] (VERY IMPORTANT!)
ASSUMPTIONS: This function assumes that the Current_Position is within the rage of the var. Next_Position.
DESCRIPTION: This function is a central part of the Main_Game_Engine function it calculates, tests, and moves the player. 
CALLS:
This function CALLS Test_If_Valid_Position to test if the player has moved to a new valid position THAT IS ALSO VALID. DRAW_PLAYER_IMAGE IS ALSO A HELPER FUNCTION.
 
 
Clear_Screen
 
BY: Asher C. Martin
PURPOSE: This procedure clears the screen
INPUT: TAKES THE VALUE IN VAR. VIDSEG SCREEN IS CLEARED 
OUTPUT: DEPENDING ON THE VIDEO_MODE FLAG THIS FUNCTION WILL  CLEAR  DIFFERENT SIZES OF SCREENS
ASSUMPTIONS: NONE
DESCRIPTION: THIS PROCEDURE IS USED AT THE END OF OUR PROG. TO CLEAR  THE 320X200X256 OR ASCII TEXT DISPLAY 
 
 
Draw_Tile
 
BY: Asher C. Martin & Robert Ikeoka
PURPOSE: THIS FUNCTION DRAWS A TILE TO MAIN_screen_seg
INPUT: DI = LOCATION ON THE SCREEN 
BL = THE ASCII VALUE TO PRINT
OUTPUT: VIDEO DISPLAY
DESCRIPTION: THIS IS THE PRIMARY WORK HORSE THAT DRAWS THE TILES TO THE SCREEN
 

 

Place_Tile
 
BY: Robert Ikeoka
PURPOSE: THIS FUNCTION DECIDES WHERE TO DRAW A TILE 
INPUT: mazemap[di]
OUTPUT: ax = tile value 
di = offset to place tile
DESCRIPTION: THIS IS THE PRIMARY WORK HORSE THAT INTERFACES THE AI WITH THE GRAPHICS.
 
 
Wav_Play
 
BY: Ajay Ladsaria
Purpose: To play wav file 
INPUT:
bx= index in WavTable of wav file to play
OUTPUT: The wav file is played
 
Wav_Setup
 
BY: Michael Urman
Purpose: To find the buffer half that does not contain the page boundary 
and call sb_init and sb_setcallback
INPUT:
none
OUTPUT: Dma is ready so now a call to wav_play can be made
 
 
Wav_Close
 
BY: Ajay Ladsaria
Purpose: To close the wavfile last being played
INPUT:
none
OUTPUT: calls int21 to close wavfile
 
 
LoadBuffer
 
BY: Ajay Ladsaria
Purpose: To load wavfile into DMA buffer
INPUT:
none, uses fileno which is the handle of the wavfile
OUTPUT: calls int21 to load into the DMA buffer
 
 
 
Openwav
 
BY: Ajay Ladsaria although virtually the same as sbtest.asm by Michael 
Urman
Purpose: To open wavfile for loading
INPUT:
bx= index in wavtable of the wav to open
OUTPUT: calls int21 to open the wavfile
 
 
SoundHandler
 
BY: Ajay Ladsaria 
Purpose: none, it is needed because sblib291 requires it
INPUT:
none
OUTPUT: none
 
 
Xmidi_Upkeep
 
BY: Ajay Ladsaria 
Purpose: if the xmidi being played has finished, it starts it again
INPUT:
none
OUTPUT: none
 
Xmidi_Play
 
BY: Ajay Ladsaria 
Purpose: To play xmidi files
INPUT:
bx=index in XmidiTable that has the offset of the xmidi file to play
OUTPUT: Xmidi can be heard in the background 
This procdure calls int66 from midpak
 
 
Xmidi_Stop
 
BY: Ajay Ladsaria 
Purpose: Stops the currently playing xmidi
INPUT:
none
OUTPUT: Xmidi that is playing is stopped 
calls in66 as defined in midpak
 
 
Main_Draw_Ascii
 
BY: Asher C. Martin
PURPOSE: THIS FUNCTION LOADS ARRAY MAZEMAP[DI] WITH THE ASCII EQUIVALENT OF THE VIDEO DISPLAY.
INPUT: NONE
OUTPUT: IF VIDEO_MODE == 0 THAN WE DISPLAY IT AT B800:[DI]
ASSUMPTIONS: NONE
DESCRIPTION: THIS FUNCTION IS USED TO LOAD THE AI WITH INFO TO PROCESS.  IT IS ALSO USED FOR TESTING PURPOSES THROUGHOUTOUR FINAL PROJECT.
 
 
Load_File
 
BY: Asher C. Martin
PURPOSE: THIS FUNCTION LOADS A PCX FILE TO ES:[DI]. IN OUR CASE ES:[DI] IS USUALLY THE MAIN_SCREEN_SEG.
INPUT: DX = OFFSET OF THE FILE NAME TO LOAD
OUTPUT: IMAGE IS LOADED TO ES:[DI] (DESTINATION)
ASSUMPTIONS: NONE
DESCRIPTION: THIS FUNCTION IS OUR QUICK WAY OF LOADING A FILE TO A SEGMENT OF OUR CHOOSING.  THIS WAY WE CAN TAKE OUR PROG. BEYOND THE 64K REAL MODE LIMITATION. 
NOTE: PCX DECODE IS THE SAME AS THE LAB MANUAL. 
 
 
Test_If_Valid_Position
 
BY: Asher C. Martin
PURPOSE: This procedure returns the status of the position.
INPUT: Position to test MUST be in DI (ES is VIDSEG)
OUTPUT: AX = 0 if invalid position AX = 1 if valid position
ASSUMPTIONS: NONE
 
 
Install_Kbd
 
BY: Asher C. Martin
PURPOSE: THIS FUNCTION Installs the Keyboard Handler AT 0000:[9*4].
INPUT: Nothing
OUTPUT: SAVES A POINTER TO THE OLD KEYBOARD HANDLER IN A VAR. CALLED OLDKBDV.
ASSUMPTIONS: NONE
DESCRIPTION: THIS FUNCTION INSTALLS OUR KEYBOARD... PRIMARY INPUT DEVICE.
 
 
Uninstall_Kbd
 
BY: Asher C. Martin
PURPOSE: Uninstall's the Keyboard Handler
INPUT: Nothing
OUTPUT: Nothing
 
 
Install_Network
 
BY: Mudassar Bashir
DESCRIPTION: This function initializes the network for use by NETBIOS. It is also respossible for returning the player number [which is generated by NetINIT in the al register.
INPUT: None
OUTPUT: Player number in the al register.
CALLS:
NetINIT, SendPacket 
 
 
Main_Net
 
BY: Mudassar Bashir
DESCRIPTION: This function transmits HELLO packets that let  Netbios know that a player wants to join the game every  two seconds. After a particular player has joined the game, this function sends UPDATE packets on all players every nine seconds. If a particular player wants to quit the game, this function sends a GOODBYE message indicating that a player wants to leave the game.
INPUT: None
OUTPUT: Network constantly updated.
CALLS:
SendPacket 
 
 
Uninstall_Network
 
BY: Mudassar Bashir
DESCRIPTION: Call library function Netrelease to free network resources.
INPUT: None
OUTPUT: Network constantly updated.
CALLS:
NetRelease
 
 
NetPost
 
BY: Mudassar Bashir
DESCRIPTION: The function NetPost will be responsible for taking care of interpreting the incoming Netbios packets. What the netpost function does depends on the type of the incoming packet. If the incoming packet is a HELLO packet, netpost adds the new player to the game. If the incoming packet is an UPDATE packet, netpost will update the position of that player. Finally, If the incoming packet is a GOODBYE packet, then netpost will delete that player from the game. It is similar to the Netpost function for mp5 and so appropriate credit should go to the ECE 291 staff for providing a good model for the netpost function.
Purpose: To recieve and interpret incoming datagrams.
INPUT:
None
OUTPUT: Network constantly updated.
CALLS:
None
 

;-------------------------------------------------------------------------
;/////////////////////////ECE291 FINAL PROJECT////////////////////////////
;-------------------------------------------------------------------------
;       VERSION: 7.0 
; LAST CHAGE BY: Asher C. Martin
;          DATE: 4-29-99 / 2:30 AM
;       DETAILS: Everything works just as it should!  We have Wav,
;                networking, AI, Midi, Scrolling, Tiles... the list
;                goes on and on!  I'm very happy with our project!
;                GREAT JOB EVERYONE!
;
;         --------------------------------------------------------------
;         |    Asher C. Martin: Game Engine, GUI MAZE, Menus, & I/O    |
;         |   Mudassar Bashir: Network, NETBIOS, Interfacing, Menus    |
;         |   Robert H. Ikeoka: MAZE AI, Player Movement, & Strategy   |
;         |     Ajay Ladsaria: Sound FX, GUI MAZE, & Game Engine       |      
;         --------------------------------------------------------------
;         |        University of Illinois Urbana-Champaign             |
;         |            E-MAIL: martin2@acm.uiuc.edu                    |
;         |         http://fermi.isdn.uiuc.edu/maze.html               |
;         |     ftp://feynman.isdn.uiuc.edu/ece291/Final_Project       |
;         |   NOTE: Only team members are allowed to use the ftp site  |  
;         --------------------------------------------------------------

.MODEL LARGE  ; Allow Multiple Segments to be defined
.486          ; Enable code with 32-bit registers and 486 CPU Features

;-------------------------------------------------------------------------
;////////////////////////////////Constants////////////////////////////////
;-------------------------------------------------------------------------

;ASCII values for common characters
TIMERSPEED      EQU  10
BEEP     EQU  7
CR       EQU  13
LF       EQU  10
ESCKEY   EQU  27
BSKEY    EQU  8
SEMI     EQU  59
NumBorderImages EQU  16
graphicsmaX     equ  64+16
GRAPHICSMASK    EQU  128*0+64*0+32*1+16*1+8*1+4*1+2*1+1*1
VISITEDSTART EQU     64
SPACE    EQU  32
VIDSEG   EQU  0B800h
startdk  equ  320*4+5
BASE_8253 equ 40h
TIMER_0_8253 equ BASE_8253 + 0
MODE_8253 equ     BASE_8253 + 3
OCW3  equ 20h
IRR  equ 20h
SCREENTEXTWIDTH  EQU 80
SCREENTEXTHEIGHT EQU    25
SCREENTILEWIDTH  EQU 14
SCREENTILEHEIGHT EQU    12
SCREENTILESTART  EQU 4*320+7
SCREENMINIWIDTH  EQU 70
SCREENMINIHEIGHT EQU  60
SCREENMINISTART  EQU 82*320+243
TILESIZE         EQU   16
MINICOLOR        EQU  128
numofplayers equ    128
MYPNUMD    EQU     40
AIPNUMD    EQU     numofplayers - 1
AICONSTSPEED    EQU     10
aimaxspeed      equ     5000
timermax equ 10000
;-------------------------------------------------------------------------
;///////////////////////////Handy General MACROS /////////////////////////
;-------------------------------------------------------------------------

include macros.inc

;-------------------------------------------------------------------------
;//////////////////////////////Externals//////////////////////////////////
;-------------------------------------------------------------------------
; -- LIB291 Routines -- 
extrn dspmsg:near, dspout:near, kbdin:near ;SendPacket:near
extrn rsave:near, rrest:near, binasc:near, DOSXIT:near
extrn SB_Init:near, SB_Clean:near, SB_Play:near, SB_Stop:near
extrn SB_SetCallback:near, SB_SingleCycle:near

;-------------------------------------------------------------------------
;////////////////////////////////PUBLICs//////////////////////////////////
;-------------------------------------------------------------------------
 

;-------------------------------------------------------------------------
;////////////////////////////Stack Segment////////////////////////////////
;-------------------------------------------------------------------------

stkseg  segment stack                 ; *** STACK SEGMENT ***
        db      256 dup ('STACK   ')   ; Allocate bytes of stack memory
stkseg  ends

;-------------------------------------------------------------------------
;//////////////////////////////MAIN SCREEN SEG////////////////////////////
;-------------------------------------------------------------------------
;* BY: Asher C. Martin
MAIN_SCREEN_SEG segment public
        MAIN_SCREEN db      65535 dup (0)
MAIN_SCREEN_SEG ends

;-------------------------------------------------------------------------
;////////////////////////////DOUBLE BUFFER SEG////////////////////////////
;-------------------------------------------------------------------------
;* BY: Asher C. Martin
DOUBLE_BUFFER_SEG segment public
        DOUBLE_BUFFER db      65535 dup (0)
DOUBLE_BUFFER_SEG ends

;-------------------------------------------------------------------------
;//////////////////////////Player Image Segment///////////////////////////
;-------------------------------------------------------------------------                         
;* BY: Asher C. Martin
SPRITE_SEG segment public               
  SPRITE_ARRAY db       65535 dup (0) ; Allocate memory to hold images
SPRITE_SEG ends

;-------------------------------------------------------------------------
;///////////////////////Background Image Segment//////////////////////////
;-------------------------------------------------------------------------                         
;* BY: Asher C. Martin
TILE_SEG segment public               
  TILE_ARRAY db                 65535 dup (0) ; Allocate memory to hold images
TILE_SEG ends

;-------------------------------------------------------------------------
;/////////////////////////////Pallete Segment/////////////////////////////
;-------------------------------------------------------------------------
;* by: Robert Ikeoka
Pal_Seg segment public
 Pal db 256 dup(3 dup (0))
Pal_Seg ends

;-------------------------------------------------------------------------
;/////////////////////////AI VECTOR Segment///////////////////////////////
;-------------------------------------------------------------------------
ai_seg segment public
 horizontalsize  db 80       ; note map sizes will be limited to a max dimension of 255 X 255
 verticalsize   db 25       ; however actuall memory allocation limits the size to 10000 cells
 Vectormap  db 10000 dup ('A')
 MazeMap    db 10600 dup ('A')
        GraphicsMap     db 10000 dup (0)
 aiVisitedmap    db 10000 dup (0)
 aiStackmap      db 10000 dup (0)
 aisp       dw 0
        aimovestarted    dw 0
 ailinearpos  dw 0
 aistackreverse  db 0
ai_seg ends

;-------------------------------------------------------------------------
;//////////////////////////Sound Buffer Segment///////////////////////////
;-------------------------------------------------------------------------
;* by: Ajay Ladsaria
soundbuffer_seg segment public
  sndbuf db 4096 dup (10,20,50,80,90,80,50,20) ; 16k of sine wave
soundbuffer_seg ends

XmidiBufSeg segment public
  xmidibuf      db      65535 dup (?)   ; 64k of buffer for xmidi data
XmidiBufSeg ends

;-------------------------------------------------------------------------
;////////////////////////////////TEMP Segment/////////////////////////////
;-------------------------------------------------------------------------                         
;* BY: Asher C. Martin
TEMP_SEG segment public
  TEMP_ARRAY db 64 dup( 1024 dup(1) ) ; Allocate memory to hold images
TEMP_SEG ends

;-------------------------------------------------------------------------
;/////////////////////////////Code/Data segment///////////////////////////
;-------------------------------------------------------------------------
cseg    segment public 'CODE'         ; *** CODE SEGMENT ***
        assume  cs:cseg, ds:cseg, ss:stkseg, es:nothing
crlf DB CR,LF,'$'       ; New Line
 

;-------------------------------------------------------------------------
;/////////////////////////////////Variables///////////////////////////////
;-------------------------------------------------------------------------

;* LIST OF IMAGES THAT ARE LOADED FROM FILES
 INTRO DB 'INTRO.PCX',0 ; NOTE: FILENAMES MUST
 MENU DB 'MENU.PCX',0  ; END WITH A 0 BYTE
        MAIN_BG DB      'MAIN.PCX',0
        TILE    DB      'TILE.PCX',0
 SPRITE  DB 'SPRITE.PCX',0
 ASHER DB 'ASHER.PCX',0
 ROBERT  DB 'ROBERT.PCX',0
 AJAY DB 'AJAY.PCX',0
 MOE DB 'MOE.PCX',0

;* LIST OF MENU IMAGES THAT ARE LOADED FROM FILES
 M1 DB 'M1.PCX',0
 M2 DB 'M2.PCX',0
 M3 DB 'M3.PCX',0
 M4 DB 'M4.PCX',0
 M5 DB 'M5.PCX',0
 OPTIONS DB 'OPTIONS.PCX',0
 CONTROLS DB 'CONTROLS.PCX',0
 NETWORK DB 'NETWORK.PCX',0

;* ASHER'S PERSONAL VARS.

        xcoord   db 0
        ycoord   db 0
 xcoordint  db 0
 ycoordint  db 0
        xcoordtext      db 0
        ycoordtext      db 0
        xcoordMINI      db 0
        ycoordMINI      db 0
 

 ; CURRENT <X,Y> POSITION OF PLAYER
   x_pos dw 100  ; PLAYER  X POSITION
   y_pos dw 100 ; PLAYER  Y POSITION

 ; NEW <X,Y> POSITION OF PLAYER
   x_NEW dw 320/2  ; PLAYER  X POSITION
   y_NEW dw 200/2 ; PLAYER  Y POSITION
 
 ; PAST <X,Y> POSITION OF PLAYER (AT START SAME AS CURRENT)
   x_past dw 320/2    ; PLAYER  PAST X POSITION
   y_past dw 200/2 ; PLAYER  PAST Y POSITION

 ; PAST POSITION OF PLAYER
   x_mov   dw 0   ; +1 IF LAST MOVE WAS RIGHT 
          ; -1 IF LAST MOVE WAS LEFT

 ASCII_Player  db '@'  ; ASCII CHAR REPS. THE PLAYER
        myPlayer db MYPNUMD
        aiPlayer db AIPNUMD
        curPlayer db myPNUMD
        

   y_mov   dw 0  ; +1 IF LAST MOVE WAS UP
              ; -1 IF LAST MOVE WAS DOWN

;* ROBERT's PERSONAL VARIABLES
        CURMAZENUM      db 0
        MAZEMAPOFFSETS  dw offset MazeMapFIleName0, offset MazeMAPFILENAME1
                        dw offset MazeMapFIleName2, offset MazeMAPFILENAME3
                        dw offset MazeMapFIleName4, offset MazeMAPFILENAME5
                        dw offset MazeMapFIleName6, offset MazeMAPFILENAME7
                        dw offset MazeMapFIleName8, offset MazeMAPFILENAME9
        MAZEMAPFILENAME0 db 'maze0.dat',0
        MAZEMAPFILENAME1 db 'maze1.dat',0
        MAZEMAPFILENAME2 db 'maze2.dat',0
        MAZEMAPFILENAME3 db 'maze3.dat',0
        MAZEMAPFILENAME4 db 'maze4.dat',0
        MAZEMAPFILENAME5 db 'maze5.dat',0
        MAZEMAPFILENAME6 db 'maze6.dat',0
        MAZEMAPFILENAME7 db 'maze7.dat',0
        MAZEMAPFILENAME8 db 'maze8.dat',0
        MAZEMAPFILENAME9 db 'maze9.dat',0
        Initialize_AIerrormsg db 'Error opening file, or error reading file!' ; 42 characters
 Initialize_AIerrormsg2 db 'Error processing file.' ; 22 characters
 delaycount dw 0
 INTCOUNTER DW 10
 prevpos  dw  0
 old1cVector     dd 0
 old08Vector dd      0
        modegraphics   db      0
        sleepallowed    db      1
        aimoveallowed   db      0
        aiintmoveallowed   db      0
        TIMERVARSPEED   DW      TIMERSPEED
        AISPEED         DW      AICONSTSPEED
        AIVARSPEED      DW      AIconstSPEED
        AIRESTART       db      0
        AIREINITIALIZE  db      0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                     * MOE's PERSONAL VARIABLES *                       ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-------------------------------------------------------------------------
;                           Network Variables                            ;
;-------------------------------------------------------------------------
; Note : All of Moe's functions and variables are located in individual  ;
;        files marked as written by Moe.                                 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

;-------------------------------------------------------------------------
;///////////////////// ;* AJAY's PERSONAL VARIABLES///////////////////////
;-------------------------------------------------------------------------

xmidifile0       db      'music.xmi',0   ; null terminate file names
;-------------------------------------------------------------------------
;/////////////////////////////////////////////////////////////////////////
;-------------------------------------------------------------------------

  Next_Position dw 80*2+1 ; CURRENT POSITION OF THE PLAYER ACCORDING TO DI
  Current_Position     dw 80*2+1  ; OLD POSITION OF THE PLAYER ACCORDING TO DI
  
  Update_Screen db 1  ; VAR. USED TO INDICATE IF SCREEN SHOULD 
  Video_Mode    db 1
  Change_Mode   db 2  ; 1 is text, 2 is video
        ; BE UPDATED OR NOT 

TotalNumO       dw  0h      ; TOTAL NUMBER OF OPERANDS ENTERED BY
                ; THE USER (USED IN DispResult)

color           db  0Ah         ; BACKGROUND COLOR IN TEXT MODE

Ops             dw  0h          ; (ASHER)

inputValid      db  0           ; 0: Not ready
                                ; 1: Ready
                                ;-1: Esc key pressed

oldKbdV         dd  ?           ;far pointer to default keyboard
                                ;  interrupt function

oldMouseV       dd ?            ;far pointer to default mouse (ASHER)
                                ;  interrupt function

DispMode        dw  10          ; Operate in decimal mode by default
 

bottomOfStack   dw  0           ; Offset of stack at beginning of program
                                ; Used to calculate current number of 
                                ; operands on the stack
SHIFT_TOGGLE    db 0h                                
operandsStr     db  'Operands: ','$'                                

NumO            db  7 dup(?)

OutputBuffer    db 16 dup(?),'$' ; Contains formatted output
                                 ; (Should be terminated with '$')
  
                                 
MAXBUFLENGTH    EQU 24
InputBuffer     db  MAXBUFLENGTH dup(?),'$' ; Contains one line of user input
BufLength       dw ?                       ; Actual length of InputBuffer

EXIT_FLAG db  0

;-------------------------------------------------------------------------
;////////////////////////////Source Includes//////////////////////////////
;-------------------------------------------------------------------------

;* HARDWARE INSTALLERS FILES
include timer.asm
include IKbd.asm
include initai.asm

; UNINSTALL HARDWARE
;include Uninstall_Timer.asm
include UKbd.asm
include Uninstall_Mouse.asm
;include Uninstall_Sound.asm

;* SOUND CALLS
include Xmidi.asm
include wcode.asm
;include Main_Sound.asm

;* HANDLERS
include Mouse_Handler.asm

;* MENU FUNCTION FILE
include menu.asm                   ; Written by Moe

;* NETWORK FILES
include network.asm                 ; Written by Moe   
include net_variables.asm           ; Written by Moe
include playertype.asm              ; Written by Moe
include messages.asm                ; Written by Moe
include netpost.asm                 ; Written by Moe

;* AI FILES
include aimove.asm
include move_p.asm
include airestart.asm

;* FUNCTIONS CALLED FROM MAIN LOOP
include Main_GPS.asm

;* GAME ENGINE CALLS
include Main_E.asm
include KbdHandler.asm
include Disp_Player.asm
include Test_If_Valid_Position.asm
include Clear_Screen.asm
include Update.asm
 

;* GRAPHICS INCLUDE FILES
include place_t.asm
include images.asm
include draw_s.asm
include Main_Draw_Ascii.asm
include Main_D.asm
include Main_Draw_PCX.asm
include Load_File.asm   ; NEW
include Draw_P.asm ; DRAW_PLAYER_IMAGE
INCLUDE DRAW_E.ASM ; DRAW_ENEMY_IMAGE
include Draw_T.asm
;include slowmove.asm
include Draw_PA.asm
include Draw_PM.asm
include mainmini.asm
 

;-------------------------------------------------------------------------
;////////////////////////////////Messages/////////////////////////////////
;-------------------------------------------------------------------------

Install_Net_Msg         db 'NetBIOS NETWORK *NOT* INSTALLED',CR,LF,'$'
Install_Sound_Msg       db 'SOUND FX *NOT* INSTALLED',CR,LF,'$'

Net_MSG                 db 'GOOD XMIT','$'

Exit_MSG        db '         <<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>',CR,LF
                db '         <<  Asher C. Martin: Game Engine, GUI MAZE, Menus, & I/O    >>',CR,LF
                db '         <<  Mudassar Bashir: Network, NETBIOS, Interfacing, Menus   >>',CR,LF
                db '         << Robert H. Ikeoka: MAZE AI, Player Movement, & Strategy   >>',CR,LF
                db '         <<    Ajay Ladsaria: Sound FX, GUI MAZE, & Game Engine      >>',CR,LF      
                db '         <<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>',CR,LF
                db '         <<       University of Illinois Urbana-Champaign            >>',CR,LF
                db '         <<           E-MAIL: martin2@acm.uiuc.edu                   >>',CR,LF
                db '         <<  http://www.ews.uiuc.edu/~martin2/research/ece291.html   >>',CR,LF
                db '         <<    ftp://feynman.isdn.uiuc.edu/ece291/Final_Project      >>',CR,LF
                db '         <<  NOTE: Only team members are allowed to use the ftp site >>',CR,LF  
                db '         <<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>=<<=>><<=>>=<<=>>',CR,LF,'$'
                
AnyKey_Msg              db ' PRESS ANY KEY ENTER "THE x86 MAZE"',CR,LF,'$'               

;-------------------------------------------------------------------------
;//////////////////////////////Procedures/////////////////////////////////
;-------------------------------------------------------------------------

; NOTE: Add your procedure as a file... (DO NOT ADD IT HERE)

;-------------------------------------------------------------------------
;///////////////////////////////START MAIN////////////////////////////////
;-------------------------------------------------------------------------

Main PROC far
 
   MOV     AX,CS
        MOV     DS,AX
        

        ;mov     ax,2
        ;int     33h

 mov bx, 0     ;determines which midi will be played
    ;could be selected from a menu
    ;right now only handles zero

        CALL    xmidi_play
        call    xmidi_upkeep
 

        call    InitTimer
        CALL    Install_Network
        
        mov     ax,200
        call    sleep
 GMODE
 
 CALL INSTALL_IMAGES

 CALL    Install_Kbd
;* MENU SYSTEM        
 MOV DX, OFFSET MENU
        MOV     AX, SEG MAIN_SCREEN
 MOV ES, AX
 CALL LOAD_FILE
 CALL Draw_Screen

; inster menu here
 

 CMP PLAY_MENU, 1
 JNE DONT_PLAY_MENU
 CALL MenuProcessor
;* MENU SYSTEM

        mov     al, myplayer
        mov     curplayer,al

        call    wav_setup

        mov     ax,seg mazemap
        mov     gs,ax

        CALL    Initialize_AI ; Preps the Main Ai routines

;        MOV     VIDEO_MODE, 1 ; SO THAT WE START IN VIDEO MODE
;        MOV     Update_Screen, 1 ; SO THAT THE SCREEN IS UPDATED ON
     ; STARTUP
;/////////////////////////
; START MAIN PROGRAM LOOP
;/////////////////////////

Main_Loop:
        CMP     EXIT_FLAG, 1
        JE      End_Main_Loop

        call    xmidi_upkeep
        call    wav_close               ;closing wav file

        CALL    Main_Net
        CALL    Main_GPS        ; CHECK GLOBAL STATIS (IF EXIT THAN EXIT)

        CMP     EXIT_FLAG, 1
        JE      End_Main_Loop
        Call    ai_move         ; GPS ALSO DEALS WITH MENUS
 
        CALL    Main_Engine     ; ASHER's  NOTE: Must be after Main_Draw_Screen
        CALL    Main_Draw_Screen; ASHER's & ROBERT's
        cmp     aireinitialize,1
        jne     testairestart
        call   initialize_ai
testairestart:
        cmp     airestart,1
        jne     testsleepallowed
        call   ai_restart
testsleepallowed:
        cmp     sleepallowed,0
        je      pastsleepmain
        mov     AX,TIMERvarSPEED
        CALL    sleep
pastsleepmain:

        CMP     EXIT_FLAG, 0
        JE      MAIN_LOOP

;/////////////////////////
;  END MAIN PROGRAM LOOP
;/////////////////////////

End_Main_Loop:
        ;CALL Conclusion
        call    xmidi_stop      ;stops the xmidi that is playing
        call    sb_stop         ;stops any wavs playing
        call    sb_clean        ;leaves the sound card the way it originally was

 TMODE
        ;UNINSTALL HARDWARE, NEWTORK, & SOUND
        call    Uninstall_Network
        CALL    NETRELEASE
        CALL    Uninstall_Kbd
        call    UninstallTimer
 

        MOV DX, OFFSET Exit_MSG
        CALL  DSPMSG
  
        mov ah,01
        mov cx,0607h
        int 10h

        Call DOSXIT ; EXIT PROG.
  
Main ENDP

cseg    ENDS
        END MAIN

;-------------------------------------------------------------------------
;//////////////////////////////THE END////////////////////////////////////
;-------------------------------------------------------------------------

 

Autohor: Asher C. Martin 
Last updated: 4/19/1999