Bryan Blackford - bblackfo@ucsc.edu
CMPE12 F09 - Lab 10 - Erick
Lab 10 (final): SAVE THE UNIVERSE
== Program Description ==
Blast your way through hordes of enemy ships to confront and destroy the boss in order to SAVE THE UNIVERSE.
Note: The rightmost switch resets the game, it must be off (down) to begin.
== Program Creation ==
= Language/Platform (same as lab 9) =
S.T.U. was written in assembly language for the HC-11,
using emacs (which is much better than vi) for text editing,
hc11build for compiling,
v2_18g3.asm as the library providing subroutines
= Setup =
- Hardware Setup (same as lab9) -
1. Connect the hc11 microcontroller kit to the PC via serial cable.
2. Connect the hc11 power.
- Compilation -
1. from a unix command prompt run "hc11build lab9.asm"
- Downloading Program to HC11 -
1. using teraterm or somesuch terminal, open a connection to the HC11 via serial interface.
2. Press Ctrl+X to reset the hc11.
3. Press D and enter to open the file download window.
4. Drag and drop "lab9.s19" (created by hc11build) into the file download window.
5. When it completes, press E and enter to execute the program.
= Operation =
1. Pilot your ship up and down using the left most switch.
2. Fire your ship's destructo beam by pressuring the interrupt key.
3. Either blast or avoid your way through enemies.
4. The LEDs indicate your position on the level, moving from left to right.
5. As the boss approaches, the LEDs will flash.
6. When the boss appears, LEDs will indicate boss health.
7. After defeating the boss, your score will be shown.
8. The rightmost switch is the reset switch, flip it up and down anytime to start over.
== Assembly Code ==
= Organization =
- .data -
At the head of the asm is the block comments with my contact and app info.
The code starts with variable definitions in the .sect .data section.
Variables include:
16 bit arrays (2 indices per element) for the x and y position of bullets, the x position and type for enemy ships/bosses.
Positions are stored in 16 bit words, as the level is 255 characters wide, but there were problems with comparisons with 2's complement numbers going from -128 to 127.
Counters for the timer, score, boss health.
Line1 and Line2 are the rendering buffers for the LCD. These will be discussed below.
Booleans such as PlayerHit, which indicates if the player ran into something (noob).
Iterators which are used to step through the bullet and enemy arrays.
InitValues, which are loaded at startup, useful for the reset switch.
chDraw is used to pass an argument into DrawCharacter
- .text -
Next is the .sect.text section, which contains the hc11 instructions comprising the application.
The application starts with main: which is where the reset switch jumps to.
Immediately, variables are loaded with their initial values, and welcome text is displayed. Pulse accumulator and Interrupt button initialization also takes place (based on pacc_ex.asm)
Then the bullet and enemy arrays are initialized (DNE indicates does not exist)
Then the enemies are created. This is the least friendly subroutine.
Next is the loop: this starts with some counting to waste time and slow down the game. I learned later about a jsr WAIT, but this worked, so I left it alone.
The first thing I did when I started writing this game was creating the jsr calls that comes next. I didn't know how they would be implemented, but I knew that's what they should do. This formed the basis for the functions and made for rapid development.
This application uses many subroutines, such as:
MoveEnemies: iterates through the enemy array and moves or changes enemies as necessary. This is where the boss moves through the 20 types which relate to the 20 positions the boss may occupy. Types 50-59 are the same, but each time the boss takes a step, the type changes, so that after 10 steps, the type becomes 60, and types 60-69 step backwards on the top line. Also determines if enemies have moved offscreen to the left, and gets rid of them as such.
CheckHits: collision checking between bullets and enemies, then between enemies and the player. There is functionality for a blast which the boss would fire at the player, with the blast being another enemy which would step forward, and this worked well when it wasn't crashing the hc11, so I commented it out!
MoveBullets: iterates through bullets, moving them forward as bullets are want to do. Also determines if they have run off the screen to the right, as there are only 8 bullets on screen at a time, we musnt waste the precious 8 on offscreen bulletage.
MoveLevel: simply increments the LevelPos counter, assuming the player hasn't crashed or reached the end (boss)
ClearLines: blanks out Line1 and Line2 (16 character arrays) to prepare them for rendering.
RenderLines: draws characters to Line1/Line2. First the player (position determined by switch) then bullets and enemies.
DrawLinesToLCD: simply LCDLINE's Line1 and Line2.
DrawLinesToConsole: same, plus score and other info sometimes. Mainly for debugging. I should have commented this out and just left useful information on the console, but I was weary from code.
UpdateLEDs: updates der LED array. Uses an inefficient table of values. I used approximately the least efficient method imaginable, to illustrate a point, yeah they'll buy that..
WriteScore: writes the score? who named these functions?
- anyways -
After all the functions are called, the boss health is checked for death, player hit checked for death, switches checked for reset, and we're done.
== Summary ==
I now feel confident enough with my newfound assembly c0d3 skillz to port Quake to the HC11. We're gonna need more memory.
== Thants! ==
This class and lab have been really entertaining, I'm grateful to have such classy teachers and TA's. Ciao!