Difference between revisions of "Programming methods used in games"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
(Hardware Scrolling)
(Firmware)
 
(43 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
This section describes specific programming methods which are used in games and the games that use them.
 
This section describes specific programming methods which are used in games and the games that use them.
 +
 +
=== Sampled Sound ===
 +
 +
Sampled music:
 +
* Prehistorik 2
 +
* Xyphoes Fantasy
 +
 +
The sampled speech is often stored as 4-bit values with 2 values packed into each byte. Each value is sent to one of the AY volume registers at a fixed rate.
 +
 +
Sampled speech:
 +
* Chase HQ
 +
* Bad Dudes vs Dragon Ninja
 +
* Robocop
 +
* Ghost Hunters
 +
* Advanced Pinball Simulator
  
 
=== Rasters ===
 
=== Rasters ===
Line 7: Line 22:
 
Examples:
 
Examples:
  
Zynaps.
+
* Zynaps
 +
* 007 The Living Daylights
  
 
=== Hardware Double Buffer  ===
 
=== Hardware Double Buffer  ===
Line 24: Line 40:
  
 
However, page flipping eats up a lot of memory area (which is crucial especially for 64Kb machines). This explains why a lot of games can have small game-areas !
 
However, page flipping eats up a lot of memory area (which is crucial especially for 64Kb machines). This explains why a lot of games can have small game-areas !
 +
 +
For example:
 +
Pac-Man Emulator
  
 
=== Scrolling ===
 
=== Scrolling ===
Line 39: Line 58:
 
Parallax or Multi Layer Scroll is an effect where there are 2 layers of tiles which scroll, one has priority over the other and often they move at different scroll rates.
 
Parallax or Multi Layer Scroll is an effect where there are 2 layers of tiles which scroll, one has priority over the other and often they move at different scroll rates.
  
The following games have parallax or multi layer scroll.
+
For example, the following games have parallax or multi layer scroll:
  
 
* Wizard Willy
 
* Wizard Willy
* Teenage Mutant Hero Turtles  
+
* Teenage Mutant Hero Turtles
 +
* Astro Marine Corps (AMC)
 +
* Turrican I and II
 +
* Shadow Dancer
  
 
==== Software Scrolling ====
 
==== Software Scrolling ====
Line 67: Line 89:
 
More recent games (e.g. Prehistorik 2, Super Cauldron) use the rupture technique when doing vertical scroll to ensure the display is a constant number of scan lines in height, and so the refresh rate is always the same.  
 
More recent games (e.g. Prehistorik 2, Super Cauldron) use the rupture technique when doing vertical scroll to ensure the display is a constant number of scan lines in height, and so the refresh rate is always the same.  
  
Older games adjust R5 and don't use rupture (e.g. LED Storm, Legend of Kage), the time for a frame therefore varies by up to 7 extra scan-lines. This means the VSYNC to the monitor also varies in position by up to 7 extra scan-lines, and thestability of the image is then dependent on how the monitor handles the VSYNC.  
+
Older games adjust R5 and don't use rupture (e.g. LED Storm, Legend of Kage), the time for a frame therefore varies by up to 7 extra scan-lines. This means the VSYNC to the monitor also varies in position by up to 7 extra scan-lines, and the stability of the image is then dependent on how the monitor handles the VSYNC.  
  
 
If the game uses a status panel, there are 2 ways to handle this.
 
If the game uses a status panel, there are 2 ways to handle this.
1. Redraw the panel when the screen is scrolled to compensate for it.
+
# Redraw the panel when the screen is scrolled to compensate for it.
2. Use rupture technique, the panel is in a different part of RAM and will not be affected by the scroll.
+
# Use rupture technique, the panel is in a different part of RAM and will not be affected by the scroll.
  
 
This following is an incomplete list of games using hardware scrolling. From this list it can be seen that hardware scrolling has been used from 1984 :
 
This following is an incomplete list of games using hardware scrolling. From this list it can be seen that hardware scrolling has been used from 1984 :
Line 162: Line 184:
 
| Yes
 
| Yes
 
|-
 
|-
 +
 +
| [[Cessna Over Moscow]]
 +
| 1987
 +
| No
 +
| Yes
 +
| No
 +
| No
 +
| Yes
 +
|-
 +
 +
 
| [[Cyborgs]]  
 
| [[Cyborgs]]  
 
| 1991  
 
| 1991  
Line 183: Line 216:
 
| Yes  
 
| Yes  
 
| No  
 
| No  
 +
| No
 +
| Yes
 +
|-
 +
| [[Edge Grinder]]
 +
| 2011
 +
| No
 +
| Yes
 +
| Yes
 
| No
 
| No
 
| Yes
 
| Yes
Line 207: Line 248:
 
| No  
 
| No  
 
| No
 
| No
 +
| Yes
 
|-
 
|-
 
| [[Glen Hoddle Soccer]]  
 
| [[Glen Hoddle Soccer]]  
Line 214: Line 256:
 
| No
 
| No
 
| No
 
| No
| No
+
| Yes
 
|-
 
|-
 
| [[Gothic]]  
 
| [[Gothic]]  
Line 227: Line 269:
 
| No  
 
| No  
 
| Yes  
 
| Yes  
| No
+
| Yes
 
| No
 
| No
 
| Yes
 
| Yes
Line 293: Line 335:
 
| No  
 
| No  
 
| No
 
| No
 +
| Yes
 
|-
 
|-
 
| [[Mission Genocide]]  
 
| [[Mission Genocide]]  
Line 347: Line 390:
 
| Yes  
 
| Yes  
 
| Yes  
 
| Yes  
 +
| Yes
 +
|-
 +
| [[Profanation]]
 +
| 1987
 +
| Yes
 +
| Yes
 +
| Yes
 +
| Yes
 
| Yes
 
| Yes
 
|-
 
|-
Line 357: Line 408:
 
| Yes
 
| Yes
 
|-
 
|-
| [[Realm!]]  
+
| [[Rastan]]  
| 1987  
+
| 1987
 
| Yes  
 
| Yes  
 
| Yes  
 
| Yes  
Line 365: Line 416:
 
| Yes
 
| Yes
 
|-
 
|-
| [[The Return of the Jedi|Return of the Jedi (The)]]  
+
| [[Realm!]]  
| 1989
+
| 1987
| Diagonal
+
| Yes
| scroll!
+
| Yes
 
| No  
 
| No  
 
| No  
 
| No  
| Yes
 
 
|-
 
|-
 
| [[Rick Dangerous 2]]  
 
| [[Rick Dangerous 2]]  
Line 409: Line 459:
 
| No  
 
| No  
 
| No  
 
| No  
 +
| Yes
 +
|-
 +
 +
| [[Star Sabre]]
 +
| 2007
 +
| No
 +
| Yes
 +
| No
 +
| No
 +
| Yes
 +
|-
 +
| [[The Return of the Jedi|Return of the Jedi (The)]]
 +
| 1989
 +
| Diagonal
 +
| scroll!
 +
| No
 +
| No
 +
| Yes
 +
|-
 +
| [[Thing on a Spring]]
 +
| 1986
 +
| No
 +
| Yes
 +
| Yes
 +
| No
 
| Yes
 
| Yes
 
|-
 
|-
Line 457: Line 532:
 
| No  
 
| No  
 
| No
 
| No
 +
|-
 +
| [[Star Sabre]]
 +
| 2007
 +
| No
 +
| Yes
 +
| No
 +
| Yes
 +
| Yes
 
|-
 
|-
 
| [[Street Machine]]  
 
| [[Street Machine]]  
Line 496: Line 579:
 
| Yes
 
| Yes
 
|-
 
|-
 +
| [[Top Level]]
 +
 +
| Yes
 +
| No
 +
| No
 +
| No
 +
|-
 +
 +
| [[Twin World]]
 +
| 1990
 +
| Yes
 +
| No
 +
| No
 +
| No
 +
| Yes
 +
|-
 +
 
| [[Ultima Ratio]]  
 
| [[Ultima Ratio]]  
 
| 1987  
 
| 1987  
Line 501: Line 601:
 
| No  
 
| No  
 
| No  
 
| No  
 +
| No
 +
| Yes
 +
|-
 +
| [[Unitrax]]
 +
| 1987
 
| Yes  
 
| Yes  
 +
| Yes
 +
| No
 +
| No
 
| Yes
 
| Yes
 
|-
 
|-
Line 508: Line 616:
 
| Diagonal  
 
| Diagonal  
 
| scroll!  
 
| scroll!  
 +
| No
 +
| No
 +
| Yes
 +
|-
 +
| [[Vikings (The)]]
 +
| 1986
 +
| Yes
 +
| Yes
 
| No  
 
| No  
 
| No  
 
| No  
Line 518: Line 634:
 
| No  
 
| No  
 
| Yes  
 
| Yes  
 +
| Yes
 +
|-
 +
| [[Wonderboy]]
 +
| 1987
 +
| No
 +
| Yes
 +
| No
 +
| No
 
| Yes
 
| Yes
 
|-
 
|-
Line 542: Line 666:
 
It is worth noting that some monitors are more tolerant to longer or shorter frames so the result may appear correctly on them and not on others.
 
It is worth noting that some monitors are more tolerant to longer or shorter frames so the result may appear correctly on them and not on others.
 
In addition some games may have been programmed and tested on only 1 CRTC type so may not work on others.
 
In addition some games may have been programmed and tested on only 1 CRTC type so may not work on others.
 +
 +
Wonderboy sets R4 every frame to the same value - reason unknown. But it doesn't use Rupture, because if this code is removed it works fine.
  
 
This is a an incomplete list of games that use this technique, but according to this list the earliest games used this technique was 1987:
 
This is a an incomplete list of games that use this technique, but according to this list the earliest games used this technique was 1987:
Line 550: Line 676:
 
| ''Year''  
 
| ''Year''  
 
| ''Confirmed''
 
| ''Confirmed''
 +
|-
 +
| [[007 The Living  Daylights|007 The Living  Daylights]]
 +
| 1987
 +
| Yes
 
|-
 
|-
 
| [[Action Force|Action Force]]  
 
| [[Action Force|Action Force]]  
Line 574: Line 704:
 
| 1988
 
| 1988
 
|  
 
|  
 +
|-
 +
| [[European 5-A-Side]]
 +
| 1988
 +
|
 +
|-
 +
| [[F1 Tornado Simulator]]
 +
| 1991
 +
| No
 
|-
 
|-
 
| [[Grell and Falla|Grell and Falla]]  
 
| [[Grell and Falla|Grell and Falla]]  
Line 586: Line 724:
 
| 1989  
 
| 1989  
 
| Yes
 
| Yes
 +
|-
 +
| [[Para Academy]]
 +
| 1990
 +
| No
 
|-
 
|-
 
| [[Prehistorik 2|Prehistorik 2]]  
 
| [[Prehistorik 2|Prehistorik 2]]  
 
| 1992  
 
| 1992  
 
| Yes
 
| Yes
 +
|-
 +
| [[Q10 Tank Buster]]
 +
| 1991
 +
| Yes
 +
|-
 +
| [[Rastan]]
 +
| 1987
 +
| Yes
 
|-
 
|-
 
| [[Rockford]]  
 
| [[Rockford]]  
 
| 1988
 
| 1988
 
| Yes  
 
| Yes  
 +
|-
 +
| [[Santa's Christmas Capers]]
 +
| 1990
 +
| Yes
 
|-
 
|-
 
| [[Skate Ball|Skate Ball]]  
 
| [[Skate Ball|Skate Ball]]  
Line 626: Line 780:
 
| [[Twin World (Ubi Soft)|Twin World (Ubi Soft)]]  
 
| [[Twin World (Ubi Soft)|Twin World (Ubi Soft)]]  
 
| 1990  
 
| 1990  
| Yes
 
|-
 
| [[Ultima Ratio|Ultima Ratio]]
 
| 1987
 
 
| Yes
 
| Yes
 
|-
 
|-
Line 637: Line 787:
 
|-
 
|-
 
| [[Warhawk|Warhawk]]  
 
| [[Warhawk|Warhawk]]  
| 1987
 
| Yes
 
|-
 
| [[Wonder Boy|Wonder Boy]]
 
 
| 1987  
 
| 1987  
 
| Yes
 
| Yes
Line 649: Line 795:
 
|-
 
|-
 
|}
 
|}
 +
 +
==32 KB V-RAM Hardware Scrolling==
 +
Using two full 16 KB blocks. One at &0000 and one at &C000 allows smooth 32 KB hardware scrolling, horizontally and vertically. R3 of the CRTC is used.
 +
 +
===Games===
 +
*[[Return_of_the_Sisters]]
 +
*[[Gerelakos]]
  
 
==Firmware==
 
==Firmware==
Line 656: Line 809:
 
This list is not exhaustive.
 
This list is not exhaustive.
  
*Xevious
+
*[[Xevious]]
 +
 
 +
[[Category:Programming]]

Latest revision as of 12:06, 30 January 2024

This section describes specific programming methods which are used in games and the games that use them.

Sampled Sound

Sampled music:

  • Prehistorik 2
  • Xyphoes Fantasy

The sampled speech is often stored as 4-bit values with 2 values packed into each byte. Each value is sent to one of the AY volume registers at a fixed rate.

Sampled speech:

  • Chase HQ
  • Bad Dudes vs Dragon Ninja
  • Robocop
  • Ghost Hunters
  • Advanced Pinball Simulator

Rasters

Rasters is a colour changing effect.

Examples:

  • Zynaps
  • 007 The Living Daylights

Hardware Double Buffer

Most good CPC games use the hardware double buffer technique in order to display sprites and/or to scroll the play area smoothly.

In particular, two memory areas (instead of one) are reserved for the screen ram.

In each frame, one of the two screens is displayed while the other is not visible but is drawn to. After the draw is done, the screens are exchanged using the hardware, so that the previously invisible one is now visible and the previously visible one is invisible.

The exchange is done using the hardware specifically by changing the screen-offset, Reg 12 and 13 of the CRTC).

This process is repeated.

The big advantage of this technique is that we can use a whole frame (or more) machine-time for our code (with no problems that arise when we alter screen ram at the same time the electron beam displays it on the monitor such as tearing or flickering).

However, page flipping eats up a lot of memory area (which is crucial especially for 64Kb machines). This explains why a lot of games can have small game-areas !

For example: Pac-Man Emulator

Scrolling

The following types of scroll are used:

1. The player controls a character on the screen. When the character is moved the screen scrolls but the character remains in the same position on the screen. If they get to the edge of the map, they may walk up to the sides of the screen. If they walk back the other way when they reach a particular point on the screen it starts to scroll again and they remain in the same position.

2. The player controls a character on the screen. When the character is moved towards the edges of the screen, the scroll moves a whole screen in width or height. The character is now on the opposite side. e.g. the character moves left, the screen scrolls by a whole screen width, the character is now on the right. The screen only scrolls when they get close to the sides.

3. The screen always scrolls. The player controls a character who is either static or moves freely around the screen.

Parallax/Multi Layer Scroll

Parallax or Multi Layer Scroll is an effect where there are 2 layers of tiles which scroll, one has priority over the other and often they move at different scroll rates.

For example, the following games have parallax or multi layer scroll:

  • Wizard Willy
  • Teenage Mutant Hero Turtles
  • Astro Marine Corps (AMC)
  • Turrican I and II
  • Shadow Dancer

Software Scrolling

The screen is scrolled using the CPU only. This can be done by moving the data on the screen, or re-drawing it in a different position to give the illusion of scrolling.

Examples:

  • Robocop
  • Batman the Movie.

Hardware Scrolling

Hardware scrolling is performed by changing the CRTC registers R12 and R13 to define the start address of the screen. The display is automatically wrapped at 16K, so continuous incrementation of these values will scroll the screen and wrap around. The code must then update the display for new graphics.

The scrolling is in CRTC character sizes.

  • 1 CRTC char horizontally is 2 bytes of RAM at a time which corresponds to 4 mode 0 pixels, 8 mode 1 pixels or 16 mode 2 pixels.
  • The height of a CRTC char is defined by CRTC Register 9 (Max Raster), which is normally set to 7. Resulting in 8 scanlines per character.

Horizontal scrolling can be made smoother by using R3 (Hsync Width), in addition to using R12 and R13 and makes the scrolling effectively half a CRTC char (therefore 2 mode 0 pixels, 4 mode 1 pixels or 8 mode 2 pixels). This can be done by changing the HSYNC width values between 5 and 6. The movement is an effect of how the monitor handles the HSYNC. This effect works well on Amstrad monitors, doesn't work on modern TFT screens and produces a black and white image on a MP-2 modulator because of the adjusted HSYNC timing.

Vertical scrolling can be made smoother by using R5 (Vertical Adjust). This works on all monitors.

More recent games (e.g. Prehistorik 2, Super Cauldron) use the rupture technique when doing vertical scroll to ensure the display is a constant number of scan lines in height, and so the refresh rate is always the same.

Older games adjust R5 and don't use rupture (e.g. LED Storm, Legend of Kage), the time for a frame therefore varies by up to 7 extra scan-lines. This means the VSYNC to the monitor also varies in position by up to 7 extra scan-lines, and the stability of the image is then dependent on how the monitor handles the VSYNC.

If the game uses a status panel, there are 2 ways to handle this.

  1. Redraw the panel when the screen is scrolled to compensate for it.
  2. Use rupture technique, the panel is in a different part of RAM and will not be affected by the scroll.

This following is an incomplete list of games using hardware scrolling. From this list it can be seen that hardware scrolling has been used from 1984 :

Title Year Vertical Horizontal R3 R5 Confirmed
3D Stunt Rider 1985 No Yes No No Yes
Action Force 1988 No Yes No No Yes
Amazing Shrinking Man (The) 1986 Yes Yes No No Yes
Anarchy 1988 No Yes No No
Axys: The Last Battle 1991 Yes No No Yes Yes
BMX Kidz 1988 No Yes No No Yes
Bob Morane Science Fiction 1987 Yes Yes No No
Boulder Dash 1984 Yes Yes No No Yes
Builderland 1991 No Yes No No
Canadair 1987 No Yes No No Yes
Cessna Over Moscow 1987 No Yes No No Yes
Cyborgs 1991 Yes Yes Yes Yes Yes
DJ Puff's Volcanic Eruption 1992 Yes Yes No No No
Doctor Who and the Mines of Terror 1986 Yes Yes No No Yes
Edge Grinder 2011 No Yes Yes No Yes
Energy Warrior 1987 No Yes No No Yes
FlySpy 1986 Yes Yes No No
Fusion 2 1988 No Yes No No Yes
Glen Hoddle Soccer 1985 No Yes No No Yes
Gothic 1988 Yes Yes No Yes
Ghosts 'n' Goblins 1986 No Yes Yes No Yes
Ghouls 'n' Ghosts 1989 No Yes No No Yes
Into The Eagle's Nest 1987 Yes Yes No No Yes
Jinks 1988 No Yes Yes No Yes
Killer Cobra 1987 No Yes Yes No Yes
Led Storm 1988 Yes No No Yes Yes
Legend of Kage 1986 Yes Yes Yes Yes Yes
Leviathan 1987 Diagonal scroll! No No Yes
Le 5eme Axe 1985 Yes Yes No No Yes
Mission Genocide 1987 Yes No No Yes Yes
Monty Python's Flying Circus 1990 Yes Yes No No Yes
Octoplex 1989 Yes Yes No Yes(?) Yes
Out of This World 1987 No Yes Yes No Yes
Paraplane 1992 Yes Yes No No
Plate-Forme 1988 No Yes No No Yes
Prehistorik 2 1992 Yes Yes Yes Yes Yes
Profanation 1987 Yes Yes Yes Yes Yes
Prohibition 1987 Yes Yes No No Yes
Rastan 1987 Yes Yes No No Yes
Realm! 1987 Yes Yes No No
Rick Dangerous 2 1990 No Yes No No
Rig Attack 1985 No Yes No No Yes
Rockford 1988 Yes Yes No No Yes
Roland on the Ropes 1984 Yes Yes No No
Sentinel (The) 1987 Yes Yes No No Yes
Star Sabre 2007 No Yes No No Yes
Return of the Jedi (The) 1989 Diagonal scroll! No No Yes
Thing on a Spring 1986 No Yes Yes No Yes
Skate Ball 1989 No Yes No No Yes
Skateboard Kidz 1988 Yes No No Yes Yes
Skate Rock 1987 No Yes No No Yes
Skate Wars 1990 No Yes No Yes Yes
Sly Spy Secret Agent 1990 Yes Yes No No Yes
Star Avenger 1984 No Yes No No
Star Sabre 2007 No Yes No Yes Yes
Street Machine 1986 Yes Yes No No Yes
Striker in the Crypts of Trogan 1992 Yes Yes No No
Super Cauldron 1992 Yes Yes Yes Yes Yes
Titan 1988 Yes Yes No No
Tornado Low Level 1985 Yes Yes No No Yes
Top Level Yes No No No
Twin World 1990 Yes No No No Yes
Ultima Ratio 1987 Yes No No No Yes
Unitrax 1987 Yes Yes No No Yes
Vector Ball 1988 Diagonal scroll! No No Yes
Vikings (The) 1986 Yes Yes No No Yes
Warhawk 1987 Yes No No Yes Yes
Wonderboy 1987 No Yes No No Yes
Xeno 1986 No Yes No No Yes

Rupture (or splitscreen)

A CRTC programming technique used to split the screen into more than one block vertically.

The sizes of each block are defined using CRTC register R4. Vsync is turned off in all but one block (by setting CRTC R7 to a value larger than R4). The start address of each block can be changed using CRTC registers R12 and R13.

This allows each block to reference different ram or to hardware scroll one block while another is static.

This method requires careful timing for the CRTC register updates, it also needs testing on all CRTC because there are differences of when each will accept and use the values programmed. However, the result can be made to work on all with more simple ruptures. Care must also be taken to ensure the timings are setup for a 50Hz screen.

It is worth noting that some monitors are more tolerant to longer or shorter frames so the result may appear correctly on them and not on others. In addition some games may have been programmed and tested on only 1 CRTC type so may not work on others.

Wonderboy sets R4 every frame to the same value - reason unknown. But it doesn't use Rupture, because if this code is removed it works fine.

This is a an incomplete list of games that use this technique, but according to this list the earliest games used this technique was 1987:

Title Year Confirmed
007 The Living Daylights 1987 Yes
Action Force 1988 Yes
Axys 1991 Yes
Dynamic Duo 1988
DJ Puff's Volcanic Eruption 1992 Yes
Energy Warrior 1987 Yes
Enlightenment: Druid 2 1988
European 5-A-Side 1988
F1 Tornado Simulator 1991 No
Grell and Falla 1992
Mission Genocide 1987 Yes
Octoplex 1989 Yes
Para Academy 1990 No
Prehistorik 2 1992 Yes
Q10 Tank Buster 1991 Yes
Rastan 1987 Yes
Rockford 1988 Yes
Santa's Christmas Capers 1990 Yes
Skate Ball 1989 Yes
Skatewars 1989
Skateboard Kidz 1988 Yes
Snowstrike 1990
Storm Warrior 1989 Yes
Super Cauldron 1992 Yes
Turrican 1990 Yes
Twin World (Ubi Soft) 1990 Yes
Usagi Yojimbo 1988 Yes
Warhawk 1987 Yes
Xyphoes Fantasy 1991 Yes

32 KB V-RAM Hardware Scrolling

Using two full 16 KB blocks. One at &0000 and one at &C000 allows smooth 32 KB hardware scrolling, horizontally and vertically. R3 of the CRTC is used.

Games

Firmware

The following games are known to use firmware functions. This probably explains why they are poor. If the programmer had used the hardware directly they would have lots more cycles free which they could have used to make the game better.

This list is not exhaustive.