Search › A-Z › G › Ghosts'n Goblins
Ghosts'n Goblins
Ghosts'n Goblins (Capcom, 1985) is the notoriously hard run-and-jump platformer in which the knight Arthur battles zombies, ogres and demons to rescue Princess Prin-Prin — losing his armour to a single hit. This build is a from-scratch emulation of the pre-CPS Capcom arcade board in the browser: a Motorola 6809 main CPU that runs the game and a Zilog Z80 sound CPU, driving two scrolling tilemaps, the 16×16 sprite hardware and a 256-colour RAM palette. It boots straight into attract mode and is wired to the emulators.org in-frame debugger, so you can single-step the main 6809, read and write its registers and the 64K memory, and set execution breakpoints and write watchpoints.
Board ported from MAME's capcom/gng.cpp ↗
Runs on: Web browser
Ghosts'n Goblins Online Emulator
Play Ghosts'n Goblins using JavaScript directly in your browser.
Controls
Configurations
| Configuration | Emulator | Machine | OS | Legal | |
|---|---|---|---|---|---|
| Ghosts'n Goblins | Ghosts'n Goblins | Ghosts'n Goblins | grey | Open ⛶ |
Machine emulated
The Ghosts'n Goblins arcade board (Capcom, 1985) is a pre-CPS design: a Motorola 6809 main CPU at 1.5 MHz running the game and a Zilog Z80 sound CPU at 3 MHz driving two YM2203 FM/PSG chips. The video hardware is a scrolling 32×32 background of 16×16 three-bit tiles, a 32×32 foreground of 8×8 two-bit characters (score and text) split for priority against the sprites, and up to 128 four-bit 16×16 sprites read from a buffered copy of CPU RAM, all coloured through a 256-entry 12-bit RAM palette and scanned as a 256×224 raster.
Chips
Notes
Embedding
Ghosts'n Goblins is Capcom's 1985 arcade machine: a Motorola 6809 main CPU at 1.5 MHz that runs the game, and a Zilog Z80 sound CPU at 3 MHz driving two YM2203s. This build is a from-scratch JavaScript emulation whose board is a port of MAME's capcom/gng.cpp. The 6809 core is the vendored JSVecX e6809 interpreter; the sound Z80 is Molly Howell's MIT Z80.js. The whole board runs from a host-owned loop, so the debugger can pause and single-step it.
Boot. Constructing the machine fetches the ROMs, decodes the character / tile / sprite graphics, resets the 6809 and starts the loop; the board comes up in attract mode:
var m = new GhostsnGoblins({ canvas, romBase, manifest });
m.boot(); // fetch ROMs, decode GFX, reset the 6809, run
// each animation frame runs one 60Hz field of the 6809, then draws the screen
The machine object. Everything the host and debugger need is a field or method on the machine:
| Member | Kind | What it does |
|---|---|---|
m.cpu | field | The main 6809 core (JSVecX e6809). Its registers are plain fields: reg_a, reg_b, reg_dp, reg_cc, reg_pc, and the 16-bit reg_x/reg_y/reg_u/reg_s (read/write .value). |
m.sound | field | The sound Z80. It runs so its soundlatch handshake stays live; audio itself is stubbed (the YM2203s are not synthesised). |
m.dbgRead(a) / m.dbgWrite(a,v) | method | Side-effect-free read of the main 64K bus and the CPU write path -- what the debugger's memory views read and poke. |
m.setInput(id, down) | method | Drive a control (up, down, left, right, jump, fire, coin, start1, start2) into the input ports. |
EMU_BOOT.transport | field | The pause / resume / step / breakpoint / watchpoint surface the shared debugger drives. |
Video. The screen is two tilemaps and a sprite list: a scrolling 32×32 background of 16×16 three-bit tiles, a 32×32 foreground of 8×8 two-bit characters (score and text), and up to 128 four-bit 16×16 sprites read from a buffered copy of sprite RAM. Colour is a 256-entry 12-bit RAM palette the CPU writes at 0x3800/0x3900. The renderer draws into a 256×256 buffer and blits the visible 256×224 window to the canvas.
Debugger integration
Because the whole board is ordinary JavaScript and the host owns the run loop, the debugger's controls need no changes to the CPU core: the loop can pause, single-step and check breakpoints between any two instructions. window.EMU_BOOT.transport maps the shared debugger onto the main 6809:
- pause / resume / isPaused -- stop or restart the
requestAnimationFrameloop. - stepInsn(n) -- run exactly n 6809 instructions through the core's
e6809_sstep(irq_i, irq_f)entry, honouring a pending vblank IRQ so stepping off the game's wait loop drops into the interrupt handler. - step(n) -- advance n whole 60 Hz fields of the 6809 (plus the sound Z80).
- breakpoints -- a
Setof PC values checked before each instruction; a match pauses before the instruction runs. - watchpoints -- the 6809's single memory-write path flags a hit when a watched address is written, and the loop pauses on it.
The registers window reads the e6809 core's fields live and writes them straight back: A, B and the D pair, the X/Y/U/S index and stack registers, PC, the direct-page register DP, and the E F H I N Z V C condition-code flags. Memory reads use dbgRead, which returns work RAM, the two video RAMs, the banked and fixed program ROM and the input ports without side effects, so inspecting memory never disturbs the sprite-DMA trigger or the sound latch. The 6809 disassembler is the shared decoder at /debugger/src/cpus/m6809.js (base page plus the 0x10/0x11 prefix pages, every addressing mode) -- reused unchanged, since the 6809 is already a first-class debugger CPU.
Architecture
The Ghosts'n Goblins board (Capcom, 1985) is a pre-CPS design built from two CPUs and Capcom's early tile/sprite hardware:
- Main CPU -- Motorola 6809 at 1.5 MHz (12 MHz / 2 device clock, ÷4 internally). Work and sprite RAM at
0x0000–0x1fff, the character RAM at0x2000and the scrolling background RAM at0x2800, the input ports and the video/sound registers in the0x3000page, a 8 KB banked ROM window at0x4000(five banks) and fixed ROM to0xffff. A vblank IRQ each field drives the game. This is the CPU the debugger targets. - Sound CPU -- a Zilog Z80 at 3 MHz with its own 2 KB RAM, fed a one-byte command through a latch the main CPU writes at
0x3a00, and taking a periodic interrupt four times a field. It drives two YM2203 FM/PSG chips. (Audio is stubbed here; the Z80 still runs so the latch handshake stays live.) - Tilemaps -- an 8×8 two-bit character foreground (score / text, transparent pen 3) and a scrolling 16×16 three-bit background, the background split into two priority halves so some of its pens sit in front of the sprites and the rest behind. The 6809 sets the background scroll at
0x3b08–0x3b0b. - Sprites -- up to 128 four-bit 16×16 sprites, drawn from a buffer that a small DMA circuit copies out of CPU RAM when the 6809 addresses
0x3c00(what earlier MAME builds mistook for a watchdog). - Palette -- 256 colours in RAM, 12-bit RGB written as two bytes per entry at
0x3800(ext) and0x3900(base) in theRRRRGGGGBBBBxxxxformat; there are no colour PROMs.
A single 74LS259 addressed latch at 0x3d00 holds the screen-flip bit, the sound-CPU reset line and the coin counters. The graphics ROMs are decoded to one-byte-per-pixel tiles once at boot.