Social Shields

RamPlay Core

RamPlayer

What RamPlay Core is

RamPlay Core is the system that every RamPlay platform runs on, as Linux distributions run on the Linux kernel. It emulates the console: a W65C02S, 16 KB of RAM, a VIA, a cartridge slot and the display protocol. It does not include a shelf, a shop or any other user interface. Platforms add those. Core is open source (MIT), and anyone can build a platform on it. RamPlayer is the RamPlay project's own platform.

No cartridge

A bare console

This console is core plus a canvas and a keyboard. Its code is shown below.

Cartridge
none
Frame
0
PC
$0000
Bytes sent
0

Arrows move. Z is A, X is B, Enter is Start.

The interface

These are exported from ramplay-core. The README lists the rest.

makeCart(bytes)Check a 32768-byte image and read its header.
createMachine()A console with the power off and the slot empty.
insertCart(m, cart)Put a cartridge in. removeCart takes it out.
powerOn(m)Clear RAM and start from the reset vector. reset keeps RAM.
setButtons(m, bits)Hold buttons. BTN names the bits.
runFrame(m)Run 33333 cycles, to the next VBLANK.
renderFrame(m.picture, px)The frame as 160 x 128 RGB565 pixels.
m.soundsSOUND commands since you last looked. You play them.
read, write, peekThe bus, for a debugger or a grader.
stepInstruction(m)One CPU instruction. disassemble names it.
embedCart, extractCartA cartridge as a PNG picture, both ways.
coverOf(rom), labelOf(rom)The cartridge's own picture, for a shelf.

Example

import {
  createMachine, makeCart, insertCart, powerOn,
  setButtons, runFrame, renderFrame, toRGBA,
} from 'ramplay-core';

const m = createMachine();
const made = makeCart(bytes);     // a .rpl file
if (made.ok) {
  insertCart(m, made.cart);
  powerOn(m);
}

const px = new Uint16Array(160 * 128);
const image = new ImageData(160, 128);
setInterval(() => {
  setButtons(m, held);            // BTN.LEFT | BTN.A
  runFrame(m);
  renderFrame(m.picture, px);
  toRGBA(px, image.data);
  ctx.putImageData(image, 0, 0);
}, 1000 / 30);

Without the canvas lines, the same code runs in Node. The tests run cartridges this way.

Platforms

RamPlayer The RamPlay project's platform, in the browser: a shelf of cartridges, a cartridge shop, covers, upload and review. Open

Read more