ECE291

Computer Engineering II

Kalbarczyk, Fall 1999

Machine Problem 3: Text-Mode Pong

Assigned Tuesday, October 12, 1999
Purpose Text-Mode Graphics, Keyboard and Timer Interrupts
Points 50
Due Date Tuesday October 26, 1999 - 5:00pm

Introduction

Pong, while not the first videogame, was the first coin-op arcade game and the first mainstream videogame that was available to almost everyone. Pong was the impetus for the development of the video gaming industry, almost single-handedly creating both the home and the arcade videogame markets.

For your next MP, you will design a different kind of Pong. In addition to the paddles and the ball moving back and forth, you will have blocks placed in between, that fall off as the ball bounces off them giving the ball a more random behavior.

Problem Description

As we are working in text-mode, a few rules need to be set ( just to make our lives easier). 

Gold Star for implementation of different angles and velocities...

Implementation

A word about Double Buffering:

A word about the Random Generator Algorithm:

A word about Interrupt Service Routines:

A word about the AI:

A word about Bouncing off Edges:

A word about handling the Timer:

A word about the Timer Chip:

The computer has a number of timer chips ( for a variety of purposes ). One such timer chip is used by the system to update your clock. This chip fires an interrupt 18 times a second.

We can change this frequency to any multiple of 18 as follows:

Case 1:

MOV    AX, 0000h
OUT     40h, AL
MOV    AL, AH
OUT     40h, AL

This will set the timer to fire 18 * 1 times a second.
Case 2:

MOV    AX, 4000h
OUT     40h, AL
MOV    AL, AH
OUT     40h, AL

This will set the timer to fire 18 * 4 times a second.
Case 3:

MOV    AX, 2000h
OUT     40h, AL
MOV    AL, AH
OUT     40h, AL

This will set the timer to fire 18 * 8 times a second.
Case 4:

MOV    AX, 1000h
OUT     40h, AL
MOV    AL, AH
OUT     40h, AL

This will set the timer to fire 18 * 16 times a second.

Remember our I/O bus is only 8-bit, hence we have to send them in two parts. The pattern should be evident. We send via AX the bit mask for the appropriate speed. Don't forget to reset it in your TimerUninstall function !!

Procedures


Preliminary Procedure

Monitor the newsgroup and this on-line section for revisions to the MP or to the write-up

Final Steps

  1. Verify that your program meets all requirements for handin.
  2. Print a copy of the MP3 grading sheet.
  3. Demonstrate MP3.EXE to a TA or to the instructor.
  4. Be prepared to answer questions about any aspect of the operation of your program. The TAs will not accept an MP if you cannot fully explain all operations of your code.
  5. Handin in your program by running:
    A:\Handin YourWindowsLogin
  6. Print MP3.ASM. Make sure that you print out your code 4 pages per page and double sided. If you don't know how to do this ask a TA for assistance.
  7. Staple the MP3 grading sheet to the front of your MP3.ASM file and give both to the same TA that approved your demonstration.

MP3.ASM

TITLE ECE291	Your Name	Today's Date
COMMENT % Text Mode Pong
	  ECE291: Machine Problem 3
	  Prof. Zbigniew Kalbarczyk
	  Guest Author: Karan Mehra
	  University of Illinois
	  Dept. of Electrical & Computer Engineering
	  Fall 1999

	  Ver. 1.0
	%
;====== Constants =========================================================
; -- Scan Codes for Keyboard Characters --
ESCKEY EQU 01
UPKEY  EQU 72
DNKEY  EQU 80
ENTER  EQU 28

BEL EQU 07h
CR  EQU 0Dh
LF  EQU 0Ah
public BEL, CR, LF, ESCKEY, UPKEY, DNKEY, ENTER
;====== Externals =========================================================
; -- LIB291 Routines (Free) ---
extrn rsave:near, rrest:near, binasc:near, dspout:near, dspmsg:near, MP3XIT:near
; the following library procedures must be replaced with your own code
extrn LibKbdInstall:near, LibKbdUninstall:near, LibKbdHandler:near
extrn LibTimerInstall:near, LibTimerUninstall:near, LibTimerHandler:near
extrn LibDrawScreen:near, LibGenerateGame:near, LibMP3Main:near
extrn LibUpdateBall:near, LibUpdatePlayers:near, LibUpdateMap:near
; these procedures need to be public so the library may call them
public KbdInstall
public KbdUninstall
public KbdHandler
public TimerInstall
public TimerUninstall
public TimerHandler
public DrawScreen
public GenerateGame
public UpdateBall
public UpdatePlayers
public UpdateMap
;====== Stack ========================================================
stkseg segment stack ; *** STACK SEGMENT ***
	
	db 64 dup ('STACK ') ; 64*8 = 512 Bytes of Stack
stkseg ends
;====== Begin Code/Data ==============================================
cseg segment public 'CODE' ; *** CODE SEGMENT ***
	assume cs:cseg, ds:cseg, ss:stkseg, es:nothing
;====== Variables ====================================================
keyCode 	db 0 		; scan Code of the key
keyStatus 	db 0 		; status of the key
				;   1 => Pressed
				;   0 => Released
paddleLength 	db 5 		; length of the PONG paddle

playerPos 	dw 480-2 	; position of the player's paddle

compPos 	dw 480 		; position of the computer's paddle

AIstatus 	db ? 		; to make our AI a li'l dumb

ballPosX 	dw ? 		; X co-ordinate of the ball
incrementX 	dw 6 		; X increment

ballPosY 	dw ? 		; X co-ordinate of the ball
incrementY 	dw 1 		; Y increment
livesRemaining 	db 9
lifePos 	dw 160-2 	; screen offset where the score needs to be displayed
score 		dw 0
scoreBuffer 	db 7 DUP(' '),'$'
scorePos 	dw 160*24+16 	; screen offset where the lives remaining
				; needs to be displayed
oldKbdV 	dd ? 		; far pointer to default keyboard
				; interrupt function
oldTimerV 	dd ? 		; far pointer to default timer
				; interrupt function
timerTick 	db 0 		; synchronizing the clock and the timer
timerFlag 	db 0 		; timer variable
updateFlag 	db 0 		; another timer variable

include bground.dat 		; 2000 byte character array to define our
				; wallpaper

; these variables need to be public so the library may use them
public keyCode, keyStatus, paddleLength
public playerPos, compPos, AIstatus
public ballPosX, incrementX, ballPosY, incrementY
public livesRemaining, lifePos, score, scoreBuffer, scorePos
public oldKbdV, oldTimerV, timerTick, timerFlag, updateFlag
;====== Procedures ========================================================
; -- remember to sufficiantly comment your functions --
KbdInstall PROC NEAR
	CALL LibKbdInstall ; comment this call out and replace it with your own code
	RET
KbdInstall ENDP
;------------------------------------------------------------------------
KbdUninstall PROC NEAR
	CALL LibKbdUninstall ; comment this call out and replace it with your own code
	RET
KbdUninstall ENDP
;------------------------------------------------------------------------
KbdHandler PROC NEAR
	; your code goes here
KbdHandler ENDP
;------------------------------------------------------------------------
TimerInstall PROC NEAR
	CALL LibTimerInstall ; comment this call out and replace it with your own code
	RET
TimerInstall ENDP
;------------------------------------------------------------------------
TimerUninstall PROC NEAR
	CALL LibTimerUninstall ; comment this call out and replace it with your own code
	RET
TimerUninstall ENDP
;------------------------------------------------------------------------
TimerHandler PROC NEAR
	; your code goes here
TimerHandler ENDP
;------------------------------------------------------------------------
DrawScreen PROC NEAR
	CALL LibDrawScreen ; comment this call out and replace it with your own code
	RET
DrawScreen ENDP
;------------------------------------------------------------------------
UpdateMap PROC NEAR
	CALL LibUpdateMap ; comment this call out and replace it with your own code
	RET
UpdateMap ENDP
;------------------------------------------------------------------------
UpdateBall PROC NEAR
	CALL LibUpdateBall ; comment this call out and replace it with your own code
	RET
UpdateBall ENDP
;------------------------------------------------------------------------
UpdatePlayers PROC NEAR
	CALL LibUpdatePlayers ; comment this call out and replace it with your own code
	RET
UpdatePlayers ENDP
;------------------------------------------------------------------------
GenerateGame PROC NEAR
	CALL LibGenerateGame ; comment this call out and replace it with your own code
	RET
GenerateGame ENDP
;------------------------------------------------------------------------
MP3Main PROC NEAR
	CALL LibMP3Main ; comment this call out and replace it with your own code
	RET

MP3Main ENDP
;====== Main Procedure ====================================================
MAIN PROC FAR
	MOV AX, CSEG 	; Use common code and data segment
	MOV DS, AX
	
	MOV AX, 0B800h 	; Use extra segment to access video screen
	MOV ES, AX
	MOV AH, 01h 	; hide text cursor
	MOV CX, 2000h
	INT 10h
	CALL MP3Main
	
	MOV AX, 0700h 	;
	MOV CX, 160*25 	; clearing
	MOV DI, 0 	; the
			; screen
	REP STOSW 	;

	CALL MP3XIT
MAIN ENDP
CSEG ENDS
	END MAIN