Now, we would like to write our own similar 8-bit retro games!
In this post, we will focus on the Sega SC-3000 home computer using the BASIC programming language for its simplicity and ease-of-use.
In order to write Sega BASIC code on a modern-day computer, you will need an emulator installed and a copy of the Sega BASIC Level 3 ROM, or Sega BASIC IIIb, as it's also known.
While there are many emulators available for Sega platforms, only one emulator seems to be compatible with the Sega BASIC Level 3 ROM, that is: Meka
|
If you receive the error The program can't start becuase MSVCR71.dll is missing from your computer then copy MSVCR71.dll file from C:\Windows\Microsoft.NET\Framework\v1.1.4322 to C:\Windows\SysWOW64.
Note: select Debug menu | Check Enabled to enable the Z80 debugger for better developer experience.
Configuration
Meka may be challenging to work with, especially if you have dual monitors. In order to alternate windowed / full screen mode, make changes to the meka.blt file, similar to the following:
[HQ2X::WIN] res = 1024x768 driver = auto_win refresh_rate = 20 blitter = hq2x stretch |
|
Sega BASIC
Next, download the Sega BASIC Level 3 ROM:
|
Setup
Each time Meka is launched, activate the Sega keyboard to begin typing:
|
For example the "&" character is Shift+6 not Shift+7 on the Sega keyboard.
Hello World
Type in the first BASIC program: the obligatory "Hello World":
NEW 10 PRINT "HELLO WORLD" 20 GOTO 10 RUNHello World will be printed down the screen indefinitely. Press the "End" key to break.
Note: there can only be one active program in memory at any one time.
Shortcuts
Here is short list of keyboard shortcuts that may be useful when using the Sega BASIC Level 3 ROM:
Key Scroll lock End key Arrow keys Backspace Shift + Backspace |
Action soft reset (keeps code in memory) break current program execution move cursor around text screen delete character to left of cursor insert character to right of cursor |
Also, the Sega keyboard has a special function key that simplifies the typing of entire BASIC commands, for example, press of the "FUNC" key and one other key combination:
Command LIST RUN |
Shortcut Tab + Backspace Tab + ` (backtick) |
State
After typing in the first BASIC program, it will remain in memory until the Sega computer is powered off. In order to maintain program state across sessions, simply save state, close and load state next session.
|
Important: there can only be one copy of the state file at any one time.
Therefore, it is up to you to archive your state files accordingly!
Documentation
The Sega SC-3000 Survivors web site contains links to much documentation: manuals, magazines and books. SMS Power web site also has more magazines scans for Sega 8-bit preservation and fanaticism!
Example
As an example, let's write the main loop of a simple "Shoot 'em up" style game that simply moves a target sprite around the screen based on user input; preferably the joystick.
Controller
If you have a joystick connected to your computer, e.g. wireless Xbox 360 controller;
Configure the controller for best game play experience:
|
|
NEW 10 PRINT STICK(1) 20 GOTO 10 RUNZeros will be printed down the screen indefinitely: move the joystick in different directions;
Output: a value between 1 to 8 will be printed on-screen. Press the "End" key to break.
Sample
The following code sample is reminiscent of the Sega BASIC "Shoot 'em up" game titled "3D City" (1988). While we will not dissect the full program at this time, we will replicate the main loop accordingly.
Type in the following program exactly as is:
10 REM SEGA BASIC PROGRAMMING 20 GOSUB 300 30 ST=1 40 SZ=16:MAG1 50 ML=0:MU=0 60 MR=256-SZ:MD=192-SZ 70 TX=MR/2:TY=MD/2 80 SCREEN 2,2:CLS 90 COLOR,1,(0,0)-(255,191),1 100 REM MAIN LOOP 110 SPRITE 0,(TX,TY),0,9 120 VX=0:VY=0 130 S1=STICK(1):FR=STRIG(1):A$=INKEY$ 140 IF S1=3 OR A$=CHR$(28) THEN VX=1:GOSUB 200 150 IF S1=7 OR A$=CHR$(29) THEN VX=-1:GOSUB 200 160 IF S1=1 OR A$=CHR$(30) THEN VY=-1:GOSUB 200 170 IF S1=5 OR A$=CHR$(31) THEN VY=1:GOSUB 200 180 IF FR=1 OR A$=CHR$(32) THEN END 190 GOTO 100 200 REM MOVEMENT 210 VX=VX*ST:VY=VY*ST 220 TX=TX+VX:TY=TY+VY 230 IF TX <= ML THEN TX=ML 240 IF TX >= MR THEN TX=MR 250 IF TY <= MU THEN TY=MU 260 IF TY >= MD THEN TY=MD 270 RETURN 300 RESTORE 350 310 FOR S=0 TO 3:READ S$:PATTERN S#S,S$:NEXT S 320 RETURN 350 DATA 000039202100012A, 2A01002120390000 360 DATA 00009C0484008054, 54800084049C0000 RUNThe graphics screen clears black and positions a red target sprite. Use the controller, or arrow keys, to move the target sprite left, right, up and down. Press the left fire button or space bar to end program. As you can see, the current per-pixel sprite movement is smooth but extremely slow!
Therefore, increase the movement step; change line 30 of the code to the following:
30 ST=2 30 ST=4 30 ST=8 30 ST=16 etc.
RUN
Also, the movement step can be changed dynamically at runtime by manipulating memory directly:
|
Next, add the following lines of code to the original program:
34 AD=&HEFF0 38 POKE AD,ST 205 ST=PEEK(AD) RUNProgram runs as before. However, this time experiment: enter hexadecimal values at the Memory Editor address &HEFF0 for example: 02, 04, 08, 10 etc. to see the movement step effects on the target sprite.
Finally, save the state of Meka for future use: Main menu, Save State.
Summary
In this post, BASIC programming was introduced on the Sega SC-3000 for simplicity and ease-of-use.
However, games written in BASIC suffer from the disadvantage that they are too slow for applications such as sprite movement; these may be sped up by increasing the step but precision of control is lost.
This can be resolved by using machine code routines for parts of the program where BASIC is too slow. This will be the topic in the next post.
2 comments:
Hi Mahasiswa,
Your welcome. Glad you enjoyed the article.
Cheers,
Steve.
Dear Sir Steve.
I send a e-mail to you a few days ago. I need your help.
Best Regards.
Post a Comment