My favorites | Sign in
Project Logo
                
Search
for
Updated Dec 03, 2008 by odin243
Labels: Featured, Phase-Implementation
ProcedureInitial  

Procedure/routine documentation: Initial:

Writer's name: Thomas Tharp

Most recent update Date: 12 Nov. 2008

Brief description: This procedure initializes all global variables used in the game. Calling it will reset all global variables, so it is suitable for use at the beginning of the program or when clearing the board / starting a new game.

Inputs: N/A

Preconditions: The global variables listed below must exist. rows and cols must already have been inputted and checked for validity.

I use:

Outputs and Postconditions:

I Change in computer:

Routine(s) I call: Multiply

Routine(s) that call me: Called from main.

Status: Currently Debugging

The below code includes the block declarations of the globals (based on their maximum theoretical values), the code for Initial, and the code for Multiply (since Initial relies on Multiply).

Internal documentation:

;//--- --- T.T. Initial() begin--- ---;
;//globals
Squares: .block 60
PipeV: .block 66
PipeH: .block 80
PipeHMax: .block 2
PipeVMax: .block 2
SqrsMax: .block 2
rows: .word 0x0003;// This is just for testing purposes, In reality these will both 
cols: .word 0x000A;// be ".block 2" and filled in by main
;//---int Multiply(int M1, int M2)---;
M1: .equate 4
M2: .equate 2
MProd: .equate 6

Multiply: lda 0x0000,i
sta MProd,s
lda M1,s
Mwhile: BREQ MendWHLE
asra
sta M1,s
BRC Mone
BR MendONE
Mone: lda MProd,s
adda M2,s
sta MProd,s
MendONE: lda M2,s
asla
sta M2,s
lda M1,s
BR Mwhile
MendWHLE: RET0
;//--- end Multiply---;

;//--- void Initial(); ---;
Tcount: .equate 0;
Tvars: .equate 2;
Initial: subsp Tvars,i
lda rows,d
sta -4,s
lda cols,d
sta -6,s
subsp 6,i
call Multiply
addsp 6,i
lda -2,s
adda -1,i
asla
sta SqrsMax,d
ldx 0,i
stx Tcount,s
Twhile1: CPX SqrsMax,d
BRGT Tend1
lda 0,i
sta Squares,x
addx 2,i
BR Twhile1
Tend1: lda rows,d
sta -4,s
lda cols,d
adda 1,i
sta -6,s
subsp 6,i
call Multiply
addsp 6,i
lda -2,s
adda -1,i
asla
sta PipeVMax,d
ldx 0,i
stx Tcount,s
Twhile2: CPX PipeVMax,d
BRGT Tend2
lda 0,i
sta PipeV,x
addx 2,i
BR Twhile2
Tend2: lda rows,d
adda 1,i
sta -4,s
lda cols,d
sta -6,s
subsp 6,i
call Multiply
addsp 6,i
lda -2,s
adda -1,i
asla
sta PipeHMax,d
ldx 0,i
stx Tcount,s
Twhile3: CPX PipeHMax,d
BRGT Tend3
lda 0,i
sta PipeH,x
addx 2,i
BR Twhile3
Tend3: addsp Tvars
RET0
;//--- end Initial ---;
;//--- ---  T.T. Initial() end --- ---;

The following code contains some sample arrays that can be used for testing purposes. These are all dot commands, so if you use these you'll need to assemble and load each time you want to test your code.

1. This is a representation of the game with 4 cols, 3 rows, and no moves. For the arrays, each line represents one element (since each index has a word).

rows: .word 3
cols: .word 4
PipeHMax: .word 30
PipeVMax: .word 28
SqrsMax: .word 22

PipeH: .ascii "\x00\x00"
PipeH02:.ascii"\x00\x00"
PipeH04:.ascii"\x00\x00"
PipeH06:.ascii"\x00\x00"
PipeH08:.ascii"\x00\x00"
PipeH10:.ascii"\x00\x00"
PipeH12:.ascii"\x00\x00"
PipeH14:.ascii"\x00\x00"
PipeH16:.ascii"\x00\x00"
PipeH18:.ascii"\x00\x00"
PipeH20:.ascii"\x00\x00"
PipeH22:.ascii"\x00\x00"
PipeH24:.ascii"\x00\x00"
PipeH26:.ascii"\x00\x00"
PipeH28:.ascii"\x00\x00"
PipeH30:.ascii"\x00\x00"

PipeV: .ascii "\x00\x00"
PipeV02:.ascii"\x00\x00"
PipeV04:.ascii"\x00\x00"
PipeV06:.ascii"\x00\x00"
PipeV08:.ascii"\x00\x00"
PipeV10:.ascii"\x00\x00"
PipeV12:.ascii"\x00\x00"
PipeV14:.ascii"\x00\x00"
PipeV16:.ascii"\x00\x00"
PipeV18:.ascii"\x00\x00"
PipeV20:.ascii"\x00\x00"
PipeV22:.ascii"\x00\x00"
PipeV24:.ascii"\x00\x00"
PipeV26:.ascii"\x00\x00"
PipeV28:.ascii"\x00\x00"

Squares: .ascii "\x00\x00"
Squars02:.ascii "\x00\x00"
Squars04:.ascii "\x00\x00"
Squars06:.ascii "\x00\x00"
Squars08:.ascii "\x00\x00"
Squars10:.ascii "\x00\x00"
Squars12:.ascii "\x00\x00"
Squars14:.ascii "\x00\x00"
Squars16:.ascii "\x00\x00"
Squars18:.ascii "\x00\x00"
Squars20:.ascii "\x00\x00"
Squars22:.ascii "\x00\x00"

2. This one is a representation of the same game with about half the pipes completed, two squares done, and player characters 'A' and 'B'.

rows: .word 3
cols: .word 4
PipeHMax: .word 30
PipeVMax: .word 28
SqrsMax: .word 22
PipeH: .ascii "\xFF\xFF"
PipeH02:.ascii"\xFF\xFF"
PipeH04:.ascii"\xFF\xFF"
PipeH06:.ascii"\xFF\xFF"
PipeH08:.ascii"\x00\x00"
PipeH10:.ascii"\xFF\xFF"
PipeH12:.ascii"\x00\x00"
PipeH14:.ascii"\xFF\xFF"
PipeH16:.ascii"\xFF\xFF"
PipeH18:.ascii"\x00\x00"
PipeH20:.ascii"\x00\x00"
PipeH22:.ascii"\xFF\xFF"
PipeH24:.ascii"\x00\x00"
PipeH26:.ascii"\x00\x00"
PipeH28:.ascii"\x00\x00"
PipeH30:.ascii"\xFF\xFF"

PipeV: .ascii "\x00\x00"
PipeV02:.ascii"\xFF\xFF"
PipeV04:.ascii"\xFF\xFF"
PipeV06:.ascii"\x00\x00"
PipeV08:.ascii"\xFF\xFF"
PipeV10:.ascii"\xFF\xFF"
PipeV12:.ascii"\x00\x00"
PipeV14:.ascii"\x00\x00"
PipeV16:.ascii"\xFF\xFF"
PipeV18:.ascii"\xFF\xFF"
PipeV20:.ascii"\x00\x00"
PipeV22:.ascii"\xFF\xFF"
PipeV24:.ascii"\x00\x00"
PipeV26:.ascii"\x00\x00"
PipeV28:.ascii"\xFF\xFF"


Squares: .ascii "\x00\xF0"
Squars02:.ascii "\x41\xFF"
Squars04:.ascii "\x00\xC3"
Squars06:.ascii "\x00\xFC"
Squars08:.ascii "\x00\x0F"
Squars10:.ascii "\x00\xC0"
Squars12:.ascii "\x00\x30"
Squars14:.ascii "\x42\xFF"
Squars16:.ascii "\x00\xF0"
Squars18:.ascii "\x00\x03"
Squars20:.ascii "\x00\x0C"
Squars22:.ascii "\x00\xF0"

3. And here's the game with all but one move made.

rows: .word 3
cols: .word 4
PipeHMax: .word 30
PipeVMax: .word 28
SqrsMax: .word 22
PipeH: .ascii "\xFF\xFF"
PipeH02:.ascii"\xFF\xFF"
PipeH04:.ascii"\xFF\xFF"
PipeH06:.ascii"\xFF\xFF"
PipeH08:.ascii"\xFF\xFF"
PipeH10:.ascii"\xFF\xFF"
PipeH12:.ascii"\xFF\xFF"
PipeH14:.ascii"\xFF\xFF"
PipeH16:.ascii"\xFF\xFF"
PipeH18:.ascii"\xFF\xFF"
PipeH20:.ascii"\xFF\xFF"
PipeH22:.ascii"\xFF\xFF"
PipeH24:.ascii"\xFF\xFF"
PipeH26:.ascii"\x00\x00"
PipeH28:.ascii"\xFF\xFF"
PipeH30:.ascii"\xFF\xFF"

PipeV: .ascii "\xFF\xFF"
PipeV02:.ascii"\xFF\xFF"
PipeV04:.ascii"\xFF\xFF"
PipeV06:.ascii"\xFF\xFF"
PipeV08:.ascii"\xFF\xFF"
PipeV10:.ascii"\xFF\xFF"
PipeV12:.ascii"\xFF\xFF"
PipeV14:.ascii"\xFF\xFF"
PipeV16:.ascii"\xFF\xFF"
PipeV18:.ascii"\xFF\xFF"
PipeV20:.ascii"\xFF\xFF"
PipeV22:.ascii"\xFF\xFF"
PipeV24:.ascii"\xFF\xFF"
PipeV26:.ascii"\xFF\xFF"
PipeV28:.ascii"\xFF\xFF"


Squares: .ascii "\x42\xFF"
Squars02:.ascii "\x41\xFF"
Squars04:.ascii "\x42\xFF"
Squars06:.ascii "\x41\xFF"
Squars08:.ascii "\x41\xFF"
Squars10:.ascii "\x41\xFF"
Squars12:.ascii "\x42\xFF"
Squars14:.ascii "\x42\xFF"
Squars16:.ascii "\x41\xFF"
Squars18:.ascii "\x00\xF3"
Squars20:.ascii "\x41\xFF"
Squars22:.ascii "\x42\xFF"

Comment by siev...@wells.edu, Nov 15, 2008

OK, this makes these extremely useful and easy to use!


Sign in to add a comment
Hosted by Google Code