| CS306 |
Processing Systems and Structures |
B. Klaydman |
Final Project
Word School
Updated on 4-20-2002
Updated again on 4-21-2002
Team members:
Project leader and programmer: Boris Klaydman.
This is a single user project and was implemented solely by me.
This implementation includes:
- Displaying of images on the screen
- Reading and processing user input
- Logic and interrupt handing
- Responsibilities also included graphic files and user interface design
Introduction
This project is an Assembler implementation of educational game for
pre-school age children. When player loads the game he or she is
presented with a random picture that represents a word.
The child has three attempts to guess the correct letter.
Each time the child presses a letter it is graphically displayed
on the screen with a corresponding message letting him/her know if
the guess was right. If the number of guesses exceeds three or child
guesses correctly the new image loaded and the game starts over.
Problem Description:
The most challenging aspect of the project is the time frame (only a week
left with 3 other labs due on the same week) and total isolation (working
on the project alone). The project is designed to as practice of displaying
graphic image files on the screen using assembler. The PCX format was
chosen as primary graphic format of images that the user interface is
composed of. In the project the programmer has to deal with processing
of the user input, refreshing small positions of the screen, randomly
selecting objects for displaying. The scope of the problem is limited,
but it extendable. Other options may include use of sound, transitions
between images, and creating different modes of the game. For example,
the game can be changed with some effort to a math game, where the user
has to guess the result of the simple calculations, but this option requires
a team of at least 2 people to be done in time.
Implementation:
Since the main focus of the problem is loading and displaying of the PCX
files and the target to the game is letter recognition, there will be two
main byte sizes arrays that hold the names of the files to process. The
names of the files are null terminated and contain only 8 characters for
easy access using the shift operation (SHL BX, 3 multiplies by 8).
Array of picture files:
Pict db 'p00.pcx', 0
db 'p01.pcx', 0
db 'p02.pcx', 0
db ............
db 'p26.pcx', 0
Array of letter files:
Lett db 'L00.pcx', 0
db 'L01.pcx', 0
db 'L02.pcx', 0
db ............
db 'L26.pcx', 0
; Holds array of picture that represent answers to a question
Ansr db 'an0.pcx', 0
db 'an1.pcx', 0
db 'an2.pcx', 0
db 'an3.pcx', 0
; Holds array of picture that represent guess number
Tryn db 'tr0.pcx', 0
db 'tr1.pcx', 0
db 'tr2.pcx', 0
db 'tr3.pcx', 0
Screen db 'screen.pcx', 0 ; The main screen
The main procedure loops until user presses the escape key. During each
iteration of the loop the input from the user is processed and the screen
is updated accordingly. The main component of the project is the PCX loading
routine. This routine loads image files from the disk and displays them
starting from position specified by DX. The size of current picture is
specified in variables:
XSize dw 0 ; Size of currently loaded picture
PicStart dw 0 ; End position of current picture on the screen
PicEnd dw 0 ; End position of current picture on the screen
To clear the parts of the screen the empty images are loaded and displayed
in correct places. The whole algorithm of the project is based on splitting
the screen into small pieces and loading them in correct places and order.
Additional constants:
; Video Memory Segments (Store in ES)
VIDTEXTSEG EQU 0B800h ; Text-mode video
VIDGRSEG EQU 0A000h ; Graphics video
SCREENSTART EQU 0; Starting position of screen on the screen
SCREENEND EQU 320*200; Ending position of screen on the screen
SCREENWIDTH EQU 320 ; Width of screen on the screen
LETTERSTART EQU 30*320 -187 ; Starting position of letters on the screen
LETTEREND EQU 30*320 -187 + 121*320 + 130; Ending position of letters on the screen
LETTERWIDTH EQU 130 ; Width of letters on the screen
PICTURESTART EQU 37*320 ; Starting position of pictures on the screen
PICTUREEND EQU 37*320 + 125*320 + 186; Ending position of pictures on the screen
PICTUREWIDTH EQU 186 ; Width of pictures on the screen
TRYSTART EQU 175*320 + 80; Starting position of tries on the screen
TRYEND EQU 175*320 + 80 + 24*320 + 22; Ending position of tries on the screen
TRYWIDTH EQU 22 ; Width of tries picture on the screen
ANSSTART EQU 160*320 ; Starting position of answers on the screen
ANSEND EQU 160*320 + 40*320 + 200; Ending position of answers on the screen
ANSWIDTH EQU 200 ; Width of tries answers on the screen
Procedures:
main
- Purpose:
- Input:
- Output:
- Registers:
- Assumptions:
- Assumes that graphic files are all in the same directory with the program
- Notes:
- Description:
- This is the main section of the program. It is responsible for processing
any keyboard input and calling appropriate routines. First main changes
the video mode to graphic mode, then it clears the graphic screen by drawing
appropriate pictures in right places. Then a random number in chosen in
range 0 to 25 (for representation of the current letter), appropriate
picture for the letter is loaded and maximum 3 guesses of the letter allowed
by the loop. The main procedure was extended. Now the game has 3 parts.
The first one is described above. The second part of the game loads images
and corresponding letters so the child can memorize them. The third part
lets the child press a letter and shows both the picture and letter that
corresponds to this picture.
clearScreen
- Purpose:
- Writes the default content on the screen
- Input:
- Output:
- Registers:
- Assumptions:
- Assumes that graphic files are all in the same directory with the program
- Notes:
- Description:
- The procedure sets DX to point to the correct name for default pictures,
set their sizes and correct locations and repeatedly calls the
DisplayPicture to clear the screen.
displayPicture
- Purpose:
- Loads and displays a PCX file of specified size starting from specified location
- Input:
- [PicEnd] - has ending point on the screen
- [PicStart] - has starting point on the screen
- [XSize] - has the width of the picture
- DX - First byte of the of the name of the file to load
- Output:
- Writes to PCX image on the screen
- Registers:
- Assumptions:
- Picture must be in the same directory with the program
- Notes:
- Handles the file read errors, but in that case no image is displayed
- Description:
- The header of the PCX file is skippedand and each pixel on the screen
set accordingly, which draws the picture on the screen. The supplied
size of the picture used for correct pixel placement.
randomNum
- Purpose:
- Generate a random number in range 1 to 26 for file section
- Input:
- Output:
- BX - contains value 1 to 26
- Registers:
- Assumptions:
- Notes:
- Description:
- Sets BX to a value between 1 and 26 for correct file access operation
by using the IN command from prot 40h and manipulating the result.
showLetter
- Purpose:
- Shows user entered letter on the screen
- Input:
- BX - contains a index (between 0 and 26) of selected letter
- Output:
- Registers:
- Assumptions:
- Notes:
-
When BX = 0 the letter is replaced with default question mark
- Description:
- Set DX and picture dimentions according to the value in BX for
displaying correct picture in correct place and calls the displayPicture that does
the work.
showPicture
- Purpose:
- Shows user a picture that represents a letter on the screen
- Input:
- BX - contains a index (between 0 and 26) of selected letter
- Output:
- Registers:
- Assumptions:
- Notes:
-
When BX = 0 the picture is deleted by drawing an empty picture on the screen
- Description:
- Set DX and picture dimentions according to the value in BX for
displaying correct picture in correct place and calls the displayPicture that does
the work.
showGuessNum
- Purpose:
- Shows guess number on the screen
- Input:
- AL - contains code of the guess number (0 - clear, 1 - try #1, 2 - try #2 , 3 - try #3)
- Output:
- Registers:
- Assumptions:
- Notes:
- Description:
- Set DX and picture dimentions according to the value in AL for displaying correct
picture (Guess number) in correct place and calls the DisplayPicture
that does the work.
showGuess
- Purpose:
- Shows responce to a guess - correct or incorrect
- Input:
- AL - contains code of the guess (0 - clear, 1 - try again, 2 - correct , 3 - wrong)
- Output:
- Registers:
- Assumptions:
- Notes:
- Description:
- Set DX and picture dimentions according to the value in AL for displaying correct
picture (Guess-related message) in correct place and calls the DisplayPicture
that does the work.
External Routines:
In the project some of the library functions from MP5 are used:
- The kbdin is used to process the input
- dosxit to exit the program
- showPCX Found this code on the internet and converted it to a SetPallet
procedure that is called only once in the beginning of the program to set the pallet.
The code for actual drawing of the pictures on the screen is my and it is original.
The modifications were done on 4-21-2002 after my procedure was complete. Thanks
to Eric Meidel, Nathan Jachimiec, and Peter Johnson for modifing the MASM code
that they also found on the net and making it possible for me to use as setPallet
procedure in my program.