GalaforceAtomDevDiary
From Retrosoftware
(→Keyboard/joystick) |
(→Keyboard/joystick) |
||
| Line 32: | Line 32: | ||
====Keyboard/joystick==== | ====Keyboard/joystick==== | ||
| - | < | + | <i>Keyboard:</i><br> |
The keyboard scan routine of the Atom is very elementary. There are 2 options to scan the keyboard matrix. The first method is calling OSRDCH and the OS waits until a key is pressed and returns the ASCII code. This is usefull for key input but not for gaming. Gaming needs the keyboard matrix to be scanned and returns the code of a pressed key or returns a code is no key is pressed. There is a call in the F-ROM to do this but it only returns the first key in the matrix which is pressed. Actually you need a keyscan routine which returns if a certain key is pressed and that's not available for the Atom. This is why I wrote a new keyscan routine equal to the BBC/Electron version: | The keyboard scan routine of the Atom is very elementary. There are 2 options to scan the keyboard matrix. The first method is calling OSRDCH and the OS waits until a key is pressed and returns the ASCII code. This is usefull for key input but not for gaming. Gaming needs the keyboard matrix to be scanned and returns the code of a pressed key or returns a code is no key is pressed. There is a call in the F-ROM to do this but it only returns the first key in the matrix which is pressed. Actually you need a keyscan routine which returns if a certain key is pressed and that's not available for the Atom. This is why I wrote a new keyscan routine equal to the BBC/Electron version: | ||
<br> | <br> | ||
Revision as of 17:30, 26 September 2011
Contents |
Galaforce Acorn Atom Development Diary
by Kees van Oss
16 August 2011
Galaforce is a shooting game for the BBC/Electron written by Kevin Edwards and distributed by Superior in 1986.
This is a brave attempt to rewrite the source so Galaforce can be played on an Acorn Atom.
Atom vs BBC/Electron
To convert a BBC/Electron game to the Atom, you have to deal with a few things:
- Graphics
- Sound
- Keyboard/joystick
Graphics
There is a big difference between the BBC/Electron and Atom graphic modes. Galaforce is written to run in MODE2 on a BBC and in MODE5 on an Electron.
Resolution:
The first difference is the graphic resolution. MODE2/5 have a resolution of 160 x 256 pixels while the max resolution in colour mode CLEAR4a on an Atom is 128 x 192 pixels. If you compare MODE2 with MODE5 then you'll notice that MODE5 is ideal to convert to CLEAR4a on an Atom, the only thing you have to do is reduce the resolution. MODE2 is also possible but then you also have to reduce the nr of colours from 8 to 4.
Colours:
The second difference is the max nr of colours which can be displayed simultaniously on the screen. A BBC/Electron can display 8 colours in MODE2 and 4 colours in MODe5 while the Atom can display 4 colours in CLEAR4a.
Also the interpretation of bits vs colour is different between the BBC/Electron and the Atom, see table below:
Colour pallette:
The third big difference is the colour pallete. On a BBC/Electron, you can redefine the colours by changing the colour pallete. The Atom has 2 sets of 4 colours which can not be changed. That's why all coloured games on an Atom always have the same colours
Sound
Sound is a very big problem on the Atom. A BBC or Electron have a soundchip to produce sound on multiple channels. You have to send data to this chip and it plays a sound with envelope for a certain duration. The Atom only has a bit connected to a beeper. To produce a tone, you have to toggle this bit with a certain frequency for a certain duration. This means that the Atom needs 100% CPU time to produce a tone.
It is possible to play a very short tone while gameplay without slowing down the game to long. Music can be played if no other processing time is needed so the processor is 100% available for the music. To play some sounds and music, I had to write a sound routine which can be called with a certain pitch, octave and duration.
Keyboard/joystick
Keyboard:
The keyboard scan routine of the Atom is very elementary. There are 2 options to scan the keyboard matrix. The first method is calling OSRDCH and the OS waits until a key is pressed and returns the ASCII code. This is usefull for key input but not for gaming. Gaming needs the keyboard matrix to be scanned and returns the code of a pressed key or returns a code is no key is pressed. There is a call in the F-ROM to do this but it only returns the first key in the matrix which is pressed. Actually you need a keyscan routine which returns if a certain key is pressed and that's not available for the Atom. This is why I wrote a new keyscan routine equal to the BBC/Electron version:
LDX #keyval LDY#$FF JSR osbyte
Joystick:
The Atom has no joystick support at all because there's no standard defined. I have written a routine to scan a joystick connected to PORTB of Charlie Robsons AtoMMC interface. The connections must be like this:
AtoMMC Joystick ----------------- PB0 - Right PB1 - Left PB2 - Down PB3 - Up PB4 - Jump PB5 - nc PB6 - nc PB7 - nc GND - GND
If you have a kernal version lower then v2.2, you have to add pull-up resistors to PB0,1,2,3,4 because the pull-up function of the PIC controller was not activated before v2.2.
Program
Kevin Edwards was so generous to send his original source files for the BBC version to Samwise. Because Galaforce was developed back in '86, these files have to be compiled on an original BBC. The binary files are saved to disk.
The binary is build out of MASTER file:
0 REM SAVE"MASTER"
10 MODE7:HIMEM=&7EA0:VDU28,0,24,39,19
20 PRINT'"Game 1.00"
30 *LOAD CONST 1900
40 PAGE=&1900:GOSUB 0
50 *LOAD ZPWORK 1900
60 PAGE=&1900:GOSUB 0
70 *LOAD ABSWORK 1900
80 PAGE=&1900:GOSUB 0
90 FOR pass=4 TO 6 STEP 2
100 P%=&B00:O%=&3000:C%=P%:S%=O%
110 PRINT:FORL=1TO2:VDU141:PRINT"Pass = ";pass:NEXT
120 READfile$
130 IF file$="THE-END" RESTORE:GOTO 170
140 OSCLI"LOAD "+file$+" 1900"
150 PAGE=&1900:GOSUB 0
160 GOTO 120
170 NEXT pass
180 PRINT'"Finished"
190 PRINT"Code start = &";~C%
200 PRINT"End of code = &";~P%-1
210 PRINT"Length = &";~P%-C%;" (";P%-C%;") bytes."
220 PRINT"Bytes left = &";~&297A-P%;" (";&297A-P%;") bytes."
230 OSCLI("LOAD O.SPFONT "+STR$~(S%-&200))
240 OSCLI("LOAD O.DIGITS "+STR$~(S%-&100))
250 OSCLI("LOAD GRAPHIC "+STR$~(S%+&297A-C%))
260 *L.:2.O.DOWN 5500
270 OSCLI("SAVE GAME "+STR$~(S%-&200)+" "+STR$~(&3200-C%+S%)+" 4000 1900")
280 PRINT" CH."CHR$34":2.ALLENV1"CHR$34
290 END
300 DATA SPRITES,INIT,ALIENS1
310 DATA ALIENS2,ALIENS3,ALIENS4,ROUT1,ROUT2,ROUT3,ROUT4,STARS
320 DATA BOMBS1,BOMBS2,CHARP,FLAGS
330 DATA MUSIC1,MUSIC2,:2.MUSIC3,:2.TITLE,:2.HIGH
340 DATA WAVE,PATT,PATDAT,VECTORS
350 DATA THE-END
Description of the files:
- MASTER, This is the main file for creating the binaries
- CONST, Declaration of game constants
- ZPWORK, Declaration of zeropage variables
- ABSWORK, Declaration of game variables
- SPRITES, Routine to erase/plot sprite
- INIT, Initialisation of game variables and main program loop
- ALIENS1/2/3/4, Initialize, process, plot, move, explode aliens
- ROUT1/2/3/4, Check keys/joystick for action, check collisions, handle demo movements and loop intro screens
- STARS, Star initialisation + scrolling
- BOMBS1/2, process my/alien bombs
- CHARP, Character/string printing
- FLAGS, Plot/erase flags for wavenr
- MUSIC1/2, Handles music and soundeffects
- TITLE, Display title in double height/width font
- HIGH, Handle highscore and name input
- WAVE, Definition of patterns per wave
- PATT, Initial data pattern + pointer to moving patterndata
- PATDAT, Moving pattern data
- VECTORS, Table for fast lookup PATT and PATTDAT data
Unfortunately not all files were included (see MISSING). Because I could not get in touch with Kevin, I had to 'reverse engineer' these files from the BBC and Electron binaries. Now I have all files complete.
- MUSIC3, Handles music and soundeffects *** MISSING ***
- DIGITS, score digit image from 0-9 for score and high score *** MISSING ***
- GRAPHIC, sprite image file *** MISSING ***
- DOWN, routine to download the code after loading it into memory *** MISSING ***
Font
The Galaforce font has 39 characters consisting of digits, letters and symbols and are stored in the file SPFONT.
- Digits 0-9, character code 0-9
- Letters A-Z , character code 10-35
- Symbols '.', '-' and SPACE, character code 36-38
You can print single-or double size characters.
To print double size characters, every pixel is scaled to 2 x 2 pixels.
Every pixel is shifted out of the Storage byte and put on screen as a coloured pixel.
A character (5 x 8) is stored 90 degrees rotated (8 x 5).
A character on the screen is 6 x 8 pixels so there's 1 pixel space between 2 characters.
The letter G is stored like this:
Sprites
Alien waves
Screenshots
Galaforce Intro screenshot Posted: 16:22, 17 Aug 2011 | Galaforce High Score screenshot Posted: 16:22, 17 Aug 2011 | Galaforce Gamestart screenshot Posted: 15:51, 03 Sep 2011 |