|
Example 8 Rebound
|
|
Introduction
I have had on my harddisc for a long time a game called "rebound". I do not know
exactly where it came from, but I suspect it was either on a cover disc or downloaded from a
BBS. It dates from 1992, and judging by the style of programming, it was either originally
written for a BBC micro, or it was written by a person brought up on the Beeb.
If you are the author, please get in contact with me so that I may properly credit
you.
It seemed, to me, to be a perfect project for conversion to assembler for several reasons:
- It is a 'whole' application in it's own right, and it isn't too large.
- It allows us to branch out into floating point mathematics instructions.
- And, it is totally frivolous!
I won't detail the internal workings, as it is commented to distraction. :-)
Improvements
The following improvements have been made, over the BASIC original:
- Seeds the randomiser (always useful!)
- Restores the original state of the redefined character, upon exit.
- Better (ie, controlled) exit handler
- Contrains the length of the high score name, so user can't output a long name and
really mess up the layout.
- Floating point now done natively on the floating point co-processor.
As Angel once said, "Works in theory!" - most of you will be using the
FPEmulator. :-)
Uses IEEE single precision floating point so should not be that slow.
Still, faster than BASIC.
- Timed delay loop, so game should work at roughly the same speed on ALL RISC OS
machines, irrespective of processor or memory speed, refresh rate, or cache.
- Doesn't do anything 'funny', so should work on any RISC OS machine with FPEmulator
loaded - RISC OS 2 to RISC OS 4, any processor.
- Provides a default name if user doesn't bother to enter anything.
- At the "SPACE for another game" prompt, it will take anything not
Space as a request to exit.
- Switches the cursor back on when awaiting name input, to indicate that something is
supposed to happen.
- Calls "Wimp_CommandWindow", so you don't get that "Press
Space or click mouse to continue" prompt...
Comments
I'm sure it can be optimised, but I don't see a necessity for it as the program is really
quite small - a mere 1680 bytes. If you do wish to optimise, here are some ideas:
- Shift blocks to make better use of fall-through.
For example:
In .game_loop
, BL to .draw_screen
.
After .draw_screen
, move .border_commands
elsewhere, then
let it just fall into .game
. Don't forget to fiddle the
LDMFD/STMFD's to account for this.
- Turn all that "OS_BinaryToDecimal" stuff to a routine which can be
called when needed.
While you're at it, change it to use "OS_ConvertInteger4" and you
should be able to use "OS_Write0" for the string, should save you
another instruction there (no need to tell it how LONG the string is!).
- The character definition code. Push it all into
.buffer
, then use a
looping LDRB to pass it to "OS_WriteC". It'll have the same
effect, but look tidier. And, as .buffer
is essentially workspace, it
doesn't matter if it later gets overwritten...
The 1K challenge
The "rebound1K" version is a challenge. You see, often you get a 'challenge' in
which to write something in 1K, or in 4K. Whether or not this is possible depends not only
upon your coding skill, but also upon your optimisation skill. Cutting strings took out some
space. Ripping out stuff like the high score name and the time delay (blah blah) took us
closer. Then the above optimisations, only more extreme. And it got us down to exactly 1024
bytes.
A lot of the gloss and nicities have gone, but the game is just as playable (though the
speed is now dependent upon the screen VSync rate).
Why 1K? Because it represents an amount of memory that was typical in early machines. Look
in a computer book written in the late sixties. Mainframes did their work with tape drives
and 4K of memory. It is a 'throwaway' amount these days, yet still a good challenge to code
something useful, yet squeeze it into a mere 256 instructions (or less, if you have output
to describe).
Last, but not least...
Many thanks to Stewart Brodie for the floating point routines. Calling FNfp()
is so much easier than using the PRMs to try to figure out what the instruction
should be...
Return to assembler index
Copyright © 2000 Richard Murray