FABIEN SANGLARD'S WEBSITE

ABOUT  CONTACT  RSS  GIVE


May 30, 2020
A tale of Ghosts'n Goblins'n Crocodiles

When he was a kid, Sébastien Harelle was given a computer. It was Christmas 1988 and "ordinateurs" were finally starting to find their ways inside French homes.

It was not Sébastien's first contact with such a machine. As early as 1985, following Laurent Fabius's "Computers for Everybody" plan[1], all elementary schools introduced children to Logo programming via star-connected[2] Thomson MO5s.

This computer did not have network capability but it was full-fledged with a monitor and a floppy disc unit integrated in the keyboard. Turning it on brought up a blue background and yellow text home-screen displaying "BASIC 1.0 Ready" and a prompt.

Soon he was spending entire evenings at his desk. Besides programming, there was an immense catalog of games available. After inserting a floppy disk and typing "RUN DISC"[3], he was welcomed to the realms of Gryzor, Barbarian, and Renegade.

Sébastien did not know it at the time but like many other French kids he would end up developing an ever-lasting appreciation for that machine, the Amstrad CPC.

Amstrad, the King of 8-bit in France and UK

If you are not from France or the UK and if you were not born in the late 70s, chances are you have no idea what an Amstrad CPC is. To put it in one sentence, Amstrad took the 8-bit home computer market by storm in the mid-80s thanks to great advertising and low prices.

It is Christmas 1985 and you want to buy your kids a computer. On one side, you have a C64 with 64KiB RAM for $149. It can display 16 colors and also has features you don't understand like hardware sprites and soft-scrolling. You will also have to buy a floppy drive ($272) and a TV ($293). On the other side, you have an Amstrad CPC 464 with similar specs except it comes with a screen, has a higher resolution and only costs $472[4][5][6]. Which one do you buy?

My concept was simple: Mum and Dad don’t want little Johnny taking over the TV set, so our computer should come with its own monitor, have a full-sized keyboard and a built-in cassette mechanism for loading software and hit a target price of £199. This way, little Johnny could have it in his bedroom, freeing up the family TV.

- Alan Sugar (Amstrad founder)[7]

Amstrad double-page heavy advertising of the tape based CPC 464 (1985).
Alan Sugar's formula worked. Perhaps beyond his wildest expectations. After its release in April 1984, the 464 was shipped to 1 million customers. Amstrad doubled down the next year in August 1985 with its CPC 6128 featuring 128 KiB of RAM, a drive using floppies instead of tapes, and a sleeker black and white design. From 1985 to 1990 Amstrad reportedly shipped around 3 millions units. During that time period, if you were talking about computers during recess, it was likely an Amstrad.
Amstrad's CPC 6128, good for gaming (yea!) and education (they wished!). Trivia: How much of an influence these machines had on French and British kids? Let's just say that some of them may have designed their keyboard to harbor Amstrad colors.
Ergodox evidence A-1.

Amstrad CPC architecture

Based on a Z80 CPU running at 4Mhz with 64KiB RAM, the CPC was the finest machine to program. Besides built-in BASIC, its great asset was its video system which resolution far surpassed its competitors. The ZX-Spectrum could reach 256×192 and the C64 320x200. The CPC on the other end had three modes offering 160x200/16colors, 320x200/4colors, and 640x200/2colors.

What was even better about the CRTC system is that developer could pick the palette colors. It was a little bit weird with its three shade per channel but it results in 27 colors available.

                 
                 
                 
The uncanny 27 values colorspace of the Amstrad CPC. When it came to animation and video-games however, the great asset turned to be a great in-balance. If the CRTC supported double buffering at the cost of half the total RAM, the CPU still had to write 16KiB to draw a whole screen. That was twice the amount of a ZX-Spectrum without the hardware sprites of a C64.

Line|ROW1 ROW2 ROW3 ROW4 ROW5 ROW6 ROW7 ROW8        
====|=======================================
 1  |C000 C800 D000 D800 E000 E800 F000 F800
 2  |C050 C850 D050 D850 E050 E850 F050 F850
 3  |C0A0 C8A0 D0A0 D8A0 E0A0 E8A0 F0A0 F8A0
 4  |C0F0 C8F0 D0F0 D8F0 E0F0 E8F0 F0F0 F8F0
 5  |C140 C940 D140 D940 E140 E940 F140 F940
 6  |C190 C990 D190 D990 E190 E990 F190 F990
 7  |C1E0 C9E0 D1E0 D9E0 E1E0 E9E0 F1E0 F9E0
 8  |C230 CA30 D230 DA30 E230 EA30 F230 FA30
 9  |C280 CA80 D280 DA80 E280 EA80 F280 FA80
10  |C2D0 CAD0 D2D0 DAD0 E2D0 EAD0 F2D0 FAD0
11  |C320 CB20 D320 DB20 E320 EB20 F320 FB20
12  |C370 CB70 D370 DB70 E370 EB70 F370 FB70
13  |C3C0 CBC0 D3C0 DBC0 E3C0 EBC0 F3C0 FBC0
14  |C410 CC10 D410 DC10 E410 EC10 F410 FC10
15  |C460 CC60 D460 DC60 E460 EC60 F460 FC60
16  |C4B0 CCB0 D4B0 DCB0 E4B0 ECB0 F4B0 FCB0
17  |C500 CD00 D500 DD00 E500 ED00 F500 FD00
18  |C550 CD50 D550 DD50 E550 ED50 F550 FD50
19  |C5A0 CDA0 D5A0 DDA0 E5A0 EDA0 F5A0 FDA0
20  |C5F0 CDF0 D5F0 DDF0 E5F0 ED50 F550 FD50
21  |C640 CE40 D640 DE40 E640 EE40 F640 FE40
22  |C690 CE90 D690 DE90 E690 EE90 F690 FE90
23  |C6E0 CEE0 D6E0 DEE0 E6E0 EEE0 F6E0 FEE0
24  |C730 CF30 D730 DF30 E730 EF30 F730 FF30
25  |C780 CF80 D780 DF80 E780 EF80 F780 FF80 

The task of animation was considerably complicated by the convoluted video layout expected by the CRTC.

Regardless of the mode, the screen is always 200 pixels tall and always divided in 25 lines of characters (each 8 rows tall). The table on the right shows where a CRTC starting at 0xC000 would expect each row for each line of character.

Rows are not expected sequentially but 8-way interleaved. That means that a simple BASIC program to clear the screen by filling 16KiB linearly would first draw Line1, row1 (at 0xC000) then, 8 pixels below, Line2, row1 (at 0xC050), then Line3, row1 (at 0xC0A0), and so on.

FOR i=&C000 TO &FFFF:POKE i,255:NEXT[8]

This description does not even factor in when the CRTC start address has been changed or when the screen have been scrolled left or right.

You may have a hard time imagining how to move sprites with such a system. Working with only a raster interrupt, a character based (8 pixels) scroller, and a CPU did not deter game developers. Far from shying away, they deployed treasures of ingenuity resulting in a list of 1,776 games[9] of which many came from the world of arcades.

Enters Ghosts'n Goblins

Ghosts and Goblins was released in arcades during Fall 1985 by Capcom. It was so well received that it became a franchise currently counting twelve titles[10].

To rescue an abducted lover, the hero had to face hordes of Zombies, Magicians, Skeletons, Red Arremers, and Flying Knights to name only a few. Bosses such as Unicorns, Dragons, Satan, and the chief Astaroth were gorgeous and well-animated. The PCB's Motorola 6809 1Mhz was rather weak but boosted by huge DMA "object" movers[11], it commanded a resolution of 256x224 with 256 colors[12] and hordes of huge sprites at 60fps. It was splendid.

It was also an unforgiving game. Enemies popped from everywhere with hard to predict patterns and privileged aiming directions. Dodging attacks was difficult since once triggered the trajectory of a jump could not be adjusted. Get hit once and your armor explodes, leaving you running around in your undies. Get hit another time and you have to start over.
Ghosts'n Goblins, arcade, 1985. The game was ported to home computers the following year. Thanks to its Blitter co-processor, the 16-bit Amiga reached stellar quality[13] with the Atari ST not too far behind[14]. However when it came to PC[15], C64[16] and CPC[17], the quality of the ports dropped sharply.

On these three platforms, the story was butchered to the point it is unclear why the hero is running around and facing monsters. There is no introduction where Astaroth captures the princess and therefore no story. The game was also considerably shorter since out of the six levels from the arcade, only four made it home. The C64 version could be completed in 7mn.

Ghosts'n Goblins on CPC

Explanation credit: cpc-power.com[18].

The CPC version of Ghosts'n Goblins is interesting to study because it is both terrible and terrific.

It is terrible in terms of polish. The hero awkwardly jumps without bending his knees. Arthur cannot lose his armor and dies upon first hit. There is no start and no end. To be fair, it is likely the development team was given at best a few weeks to do it all without access to any of the original assets.

That being said, the game is terrific in terms of what the engine does in order to improve the framerate.

As alluded earlier, the CPC's Z80 could not refresh a whole screen without dropping to a single digit framerate. Yet, adamant to run in full screen with huge sprites, developer Nigel Alderton came up with a trick. He used Mode 0 (160x200 w/ 16 colors) but chose to split each nibble in two. Four colors are used for the background and 12 colors are aliased into three for the sprites.
00-00 00-01 00-10 00-11 01-XX 10-XX 11-XX
The technique allows only seven colors on screen but enable to move sprites without having to write back the background which saves RAM and CPU cycles.

Even though it left some TV modulator screaming in pain[19], Nigel also managed to smooth out the normally choppy (2 byte increment) hardware scroll. While the scroller moves the logical screen left, he used careful timing to move the physical location to the right.

The death of Amstrad

Besides issues with the fillrate, CPC developers had to deal with what I call the "Atari ST curse" where despite having 128KiB of RAM, CPC 6128 games only used 64KiB out of the 128KiB available in order to be compatible with the 1 million CPC 464 already on the market.

To make things worse, despite some polished titles such as Gryzor and Renegade, the practice of Speccy ports[20] where ZX Spectrum games were shoved straight into CPCs gave ammunition to Amstrad haters. The platform developed a bad gaming rep.

As a remedy the British company released in September 1990 a "Plus" range made of the 464+, the 6128+, and the GX4000. If the technology was still based on a Z80 CPU, the video system was augmented to a 12-bit RGB (32 colors out of 4,096) and an ASIC chip which gifted developers with 16 hard sprites, soft scrolling, and DMA transfer to feed the audio chip automagically.
Amstrad GX4000. (Photo credit: wikipedia.com). Unfortunately, by that time the industry had started to enter the 16-bit era. The 8-bit Z80 machines from Amstrad suffered when compared to Sega's Genesis and Nintendo's Super Famicom. Customers shunned the "+" line and developers dragged their feet by producing 27, mostly sub-par, games which were often "Direct Disk to Cartridge" ports[21].

Discounted within a few months after their introduction, without a real opportunity to show what they could produce, the "+" machines were an engineering success but a commercial failure from which Amstrad never recovered.

Retro-gaming movement and the resurgence of the CPC scene

After the demise of the CPC, Sébastien and his generation moved onto other platforms. It would be years until Seb would become reacquainted with the world of Amstrad via cpcwiki.eu forum. In the Retrogaming movement, going under the nickname "Xifos", Seb found himself surrounded with people who shared his love for the CPCs but also occasionally read diverging opinions.

In the past fifteen years it has become trendy in the retro-gaming world to bad mouth the Amstrad CPC. The "+" range in particular is mocked and I thought it was not justified from a technical standing point. The only flaw really was to have been released a few years too late.

I came across some of these people bad mouthing the CPC around the same time I noticed that someone had done a port of Ghosts'n Goblins on Colecovision.

I thought it would be a good game to demonstrate what could really be done with the CPC+.

- Sébastien Harelle

GHOSTS'N GOBLINS ON CPC+

And so it happened. Almost on a lark, Seb embarked in a project to make the best port of Ghosts'n Goblins he could for the platform he loved. If at first he was not sure in which direction to go, things clarified themselves quickly.

I started to tinker with the 6128+ to get myself used to the new capabilities and particularly the ASIC. Eventually another CPC enthusiast named TotO suggested to produce a cartridge targeting the GX4000. I especially liked the idea since the console is by far the most hated piece of hardware in the "Plus" range.

2016 is when Ghosts'n Goblins on GX4000 really got started. At first there was the question of what would be the RAM budget. The GX4000 and 464+ could receive a memory extension but I decided against it since it would not have been commercially viable back in the days. I elected to use the stock configuration which is 64KiB.

Then came the question of the cartridge storage capacity. I also wanted to use what game developers of the time had which was either 128KiB or 256KiB.

In terms of framerate, the goal was to max out the TV. The console was never released on NTSC so that meant running at the 50Hz of PAL.

- Sébastien Harelle

Besides setting the target hardware constraints, Seb's most important design decision was to establish the screen layout. He ended up reconfiguring the CRTC and using the raster interrupt to switch resolution mid-frame.

The CRTC is set to display 200 rows of 80 bytes which result in either 640, 320, or 160 horizontal pixels depending on the mode. Counting in characters this means the screen is 40x26 characters but you can reconfigure the CRTC to display more (overscan) or less. I chose to use 32x28 (so a bit more narrower and taller).

There is a top part which is 32x4 characters in Mode 1 (256x32) for the HUD and a bottom part which is 32x24 characters in Mode 0 (128x192 -8 horizontally for scrolling).

It is advantageous to have 64 bytes lines (instead of 80) since it simplify screen addressing, especially when scrolling. Using a narrower screen made of 64 bytes was common during the years 1985-1993.

- Sébastien Harelle

While manipulating the CRTC was something already doable with the CPC, what is more interesting is the new hardware in the CPC+.

Ghosts'n Goblins GX4000 internals

From an engineering perspective, the GX4000 was a tour-de-force. It managed to preserve 100% backward capability while providing augmenting capabilities. The video system for example remains unchanged with Mode 0, 1, and 2. However thanks to the ASIC an extra layer of sprites with its own palette could be added on top of the background[22].
GX4000 architecture.

The powerhouse of the machine of course is the ASIC chip which allows 16 sprites of 16x16 pixels in 15 colors using a color palette separate for the rest of the video system. There is a little bit of inefficiency where the ASIC expects a sprite pixel to be encoded on a byte (8 bits) even though only a nibble (4 bits) is used. Instead of 16 sprites of 256 bytes each it would have been preferable to have 32 sprites of 128 bytes.

The sprites count limitation is important. You can't just use soft sprites (a.k.a drawn in the background layer) when you run out of hard sprites. For example the colors of the sprite may not be available in the background palette.

The soft scrolling capability solves many problems although there are a few subtle things to get everything right.

There is this common misconception that the GX4000 handles soft scrolling fully. In fact, it works a lot like the CPC hardware scroller except you can easily add a delay to the 8 pixels offset resulting in a smooth one pixel offset. But you still have to handle cycling and shifting yourself.

Also, the scroller does not allow increment to a resolution inferior to the current mode. Since the background is in mode 0 I make the background move only every other frame to get the desired visual scrolling speed.

The raster interrupt splits the screen in two vertically with the HUD in Mode 1 128*32 and the rest of the screen in Mode 0 128*192 so you have to be careful when scrolling to keep the upper part static.

In terms of audio, the DMA has three channels to automatically feed the three audio channels. These are taken care of by Arkos player which Targhan used for the music.

- Sébastien Harelle
Sprites bounding box. Arthur and most enemies use two each.
To save on RAM and storage, I kept the sprites "compressed" (1 pixel/nibble) and only decompress them when they are transferred from RAM to the ASIC. I did not use multiplexing because it did not help much but I used compounding like when Satan appears in the intro which consumes six sprites.

To reduce sprite consumption, I made elements that spawn but don't move (plant enemies, bonuses, ...) be "soft sprites" backed into the background.

Another side effect of the hard sprite limitation is that I originally had Arthur limited to having on shot in-flight. Since the sheltering-in-place I have managed to add a second one but I have not released it.

- Sébastien Harelle

Toolchain and packaging

To program the game I started with a plain C file and hand-tuned some functions with inline ASM. Using SDCC compiler and WinApe emulator allowed to iterate fast. A build + deployment took 30 seconds.

For the gameplay and sprites, my starting point was the arcade version. I designed the maps with tilestudio and drew the sprites with PaintShop Pro 5. I did not have an artist to draw any of the assets so I did it all by myself.

I also received numerous mini contributions from the CPC community. TotO for example did the HUD but I also received help from Fano, Ast, ArnoldEmu, Vingazole, Templeton, Ced, and Kukulkan (I hope I did not forget anybody).

- Sébastien Harelle
The cartridge ended up at 256KiB with 16 blocks of 16KiB. All data pertaining to a level is grouped into blocks to ease loading/unloading.

block 0    : code.
block 1    : Add-on code, HUD assets, Dragon assets, Scoareboard assets.
block 2    : Mirrored hard-sprites data.
block 3    : Hard-sprites data.
block 4    : Title screen (splash).
block 5-11 : Level 1-7 (gfx, map, enemies).
block 12   : Mirrored Hard-sprite data (boss)
block 13   : Hard-sprites data (boss)
block 14   : Misc gfx data, Musics, SFX.
block 15   : Arkos audio player, More music.

- Sébastien Harelle

Musics and Sound effects

Even though it was not his specialty, Xifos produced music and sound effects. That was until he released a preview which Julien Névo, a.k.a Targhan, came across.

I came across Xifos preview when he posted it on the CPC Wiki. I was impressed with it but I pointed out that the music that he had came up with was not on par with the quality of the rest of his game.

I asked if I could contribute and Xifos accepted. We were very efficient in the sense that I completed all the music within two weeks in early May 2018.

I worked 100% with STarKos directly on a real CPC because I did not feel confident to use Arkos Tracker 2 yet. Since Xifos used Arkos Tracker 1 (AT1) player, I just had to export to this format and my music was in the game!

- Julien Névo

Shipping it!

In May 2018, after two years of work, Sébastien and Julien shipped their project[23]. The high quality of the game was a testimony to a relentless effort fueled by passion and dedication.
Ghosts'n Goblins GX4000. Better 35 years later than never! The community praised the professional quality. All six levels, all animations, all bosses, and all the weapons were there. The 32 colors were used wisely, the music was amazing, and the framerate high. I highly recommend to get WinAPE emulator and play it.

This is the Ghosts'n Goblins the Amstrad deserves.

- Xyphoe[24]
It's bloody fantastic! [...] This proves what the system could have done then.

- Novabug[25]
"Ghosts'n Goblins" receives a spectacular remake for the Amstrad GX4000!

- gx4000.co.uk[26]

"What is the moral of this story?" you may ask. I think it is pretty clear. Next time you are thinking about bad-mouthing the CPC, think twice. It may take two years but someone will make you eat your words!

Epilogue

In March 2004, John Carmack shared an uplifting opinion about people still developing for the Jaguar, long after the Atari console had been discontinued.

There is something noble about developing on a dead platform -- it is so completely for the joy of the development, without any commercial motivation.

- John Carmack

When does a platform truly "dies"? A "dead language" is defined as "a language which is no longer in everyday spoken use". By analogy, a platform would die not when it ceases to be profitable or when it is obsolete, but when people stop playing it and caring about it.

Now the question becomes "what draws people to retro-computing?". Is it nostalgia, the diversity, the creativity, the simplicity, or is it inexplicably fun?

I thought about it and I could not come up with a definitive answer. One thing, however is certain. For those who grew up with them, these machines will go on to live "forever".

References

^ [ 1]Plan informatique pour tous
^ [ 2]Nanoréseau
^ [ 3]Some twisted titles required 'ùCPM'.
^ [ 4]L'Ordinateur Individuel Sep 86, p23
^ [ 5]L'Ordinateur Individuel Sep 86, p24
^ [ 6]L'Ordinateur Individuel Sep 86, p25
^ [ 7]You’re NOT fired: The story of Amstrad’s amazing CPC 464
^ [ 8]How to write an Amstrad CPC emulator
^ [ 9]List of Amstrad CPC games
^ [10]Ghosts'n Goblins series
^ [11]Mame Gng Driver (gng.cpp)
^ [12]Mame Gng Palette (gng.cpp)
^ [13]Ghosts'n Goblins Amiga 500 longplay by World-of-Longplays
^ [14]Ghosts'n Goblins Atari ST longplay by Greenlog
^ [15]Ghosts'n Goblins PC longplay by World-of-Longplays
^ [16]Ghosts'n Goblins C64 longplay by Zeusdaz
^ [17]Ghosts'n Goblins CPC longplay by World-of-Longplays
^ [18]Ghosts'N Goblins CPC Mode 0, 7 colors
^ [19]Ghosts'n Goblins Hardware Scroll, The Amstrad User magazine
^ [20]Speccy Ports
^ [21]CPC, Direct Disk to Cartridge
^ [22]L'ASIC
^ [23]Ghosts'n Goblins GX4000 is out !
^ [24]Xyphoe review
^ [25]Novabug review
^ [26]gx4000.co.uk announcement


*