Skip to content

The framework is still under development

The documentation in this section refers to the Game Bub Core Framework as of v1.1-beta. The framework is not finalized, and may change based on developer feedback.

Reference: Interfaces

As described in Core Structure, cores select from and configure a variety of interfaces to interact with the hardware via the framework.

import chisel3._
import net.gamebub.framework.Core
import net.gamebub.framework.interface._

class MyCore extends Module with Core {
  val io = IO(new Bundle {
    // Hardware interfaces are declared as elements of this Bundle
  })
}
Port Name Interface Class Required
clocks ClocksV0 Yes
video VideoV0 Yes
host HostV0 Yes
audio AudioV0 No
input InputBasicV0 No
InputExtendedV0 No
vibrate VibrateV0 No
cartridge CartridgePortV0 No
link LinkPortV0 No
pmod PmodV0 No
sram SramV0 No
sdram SdramV0 No
videoFilter VideoFilterBasicV0 No

Clocks (clocks: ClocksV0)

Required. This interface provides the root 50 MHz clock to the core, and allows the core to provide necessary clocks to the framework (system clock, display clock, SPI clock).

The system clock, generated by the core, is the clock used with all interfaces, unless otherwise specified.

Parameters

  • clockSystemHz: Frequency in Hz of the system clock.
  • clockDisplayHz: Frequency in Hz of the LCD interface clock. Must fall within the range returned by ClocksV0.getClockDisplayHz(...).
  • clockSpiHz: Frequency in Hz of the clock used to sample the MCU SPI bus. Must be at least 160 MHz.

Helpers

  • ClocksV0.getClockDisplayHz: (Double) => (Int, Int): provides a tuple of the minimum and maximum allowable display clock frequencies (in Hz), based on the given frame period in seconds (e.g. 1.0 / 60.0).

Port Signals

Signal Direction Type Description
clockIn50M Input Clock 50 MHz reference clock input
clockOutSystem Output Clock System clock
clockOutDisplay Output Clock Display clock
clockOutSpi Output Clock Host MCU SPI clock
locked Output Bool High when the core's clocks are stable and locked (i.e. PLL output)

Video (video: VideoV0)

Required. This interface allows the core to produce video output. The signals are referenced to the system clock.

Parameters

  • videoWidth: Width of the active video signal (in pixels)
  • videoHeight: Height of the active video signal (in pixels)
  • colorDepthR: Bit-depth of the red channel
  • colorDepthG: Bit-depth of the green channel
  • colorDepthB: Bit-depth of the blue channel
  • framePeriod: Video frame period (in seconds), e.g. 1.0 / 60.0

Port Signals

Signal Direction Type Description
data.r Output UInt Video data: red channel
data.g Output UInt Video data: green channel
data.b Output UInt Video data: blue channel
dataEnable Output Bool High during video output
vblank Output Bool Pulse high at the end of each frame
hblank Output Bool Pulse high at the end of each line

Host (host: HostV0)

Required. This interface allows the host MCU to communicate with the core. There are two main interfaces: the memory interface, and the command interface. Both interfaces use the system clock.

The memory interface is a simple memory interface (no pipelining or bursting), where a single 32-bit address is transmitted, along with a 32-bit data word read or write. enable goes high to indicate a new request is starting, with the given address, and whether it is a read (write low) or write (write high). Writes also come with dataWrite. When the core has completed the request, it must raise done. If the request was a read, dataRead must also be valid.

All memory accesses take at least two cycles: the first cycle starts when enable goes high, and the earliest it can end is on the second cycle (when done goes high). However, if the core needs additional time to handle the request, it can delay raising done until the third, fourth, or a later cycle.

The next transaction can start immediately on the cycle after done goes high.

Addresses beginning with 0xFxxxxxxx are reserved for use by the framework. Except as explicitly specified (e.g. for the command interface), the core must not map its own registers or memory at these addresses.

There are two command interfaces: commandHost (for Host -> Core commands), and commandCore (for Core -> Host) commands. Each provides a separate request / response channel.

The command interfaces are described in the next page, Reference: Host/Core Commands.

Port Signals

Signal Direction Type Description
mem.enable Input Bool High when a transaction is going on
mem.write Input Bool High if the transaction is a write, low if it is a read
mem.address Input UInt(32.W) The 32-bit byte address
mem.dataWrite Input UInt(32.W) 32-bit data written by the host
mem.dataRead Output UInt(32.W) 32-bit data read by the host, valid when done goes high
mem.done Output Bool High for one cycle when the transaction is completed
commandHost.request Input Bool High during a host-initiated request
commandHost.busy Output Bool Set high when the core acknowledges the request
commandHost.done Output Bool Set high when the core completes the request
commandHost.error Output Bool Set high if the request completes in an error
commandCore.request Output Bool High during a core-initiated request
commandCore.busy Input Bool High when the host acknowledges the request
commandCore.done Input Bool High when the host completes the request
commandCore.error Input Bool High if the requested completed in an error

Audio (audio: AudioV0)

Optional. This interface allows the core to produce audio output. The signals are referenced to the system clock.

The sample rate is always 48000 Hz, so the core should update left and right at 48 kHz.

Port Signals

Signal Direction Type Description
left Output SInt(16.W) 16-bit signed PCM audio sample for the left channel
right Output SInt(16.W) 16-bit signed PCM audio sample for the right channel

Input (input: InputBasicV0 or InputExtendedV0)

Optional. This interface allows the core to receive player input. All input signals are synchronized into the system clock domain, and button signals are active-high.

Multiple interfaces are available, depending on the input needs of the core. At most one interface can be selected.

Button presses are gated by core focus: button input is suppressed when the user is navigating the in-core menu.

Basic Input (InputBasicV0)

This interface offers 12 digital buttons (matching the built-in buttons). All gamepads connected through the Dock are merged together into a single set of buttons.

This is a simpler interface for cores that don't require analog sticks / triggers, and don't require multiple independent gamepads.

Port Signals

Signal Direction Type Description
buttons.a Input Bool Action button 'A'
buttons.b Input Bool Action button 'B'
buttons.x Input Bool Action button 'X'
buttons.y Input Bool Action button 'Y'
buttons.up Input Bool D-Pad button 'Up'
buttons.down Input Bool D-Pad button 'Down'
buttons.left Input Bool D-Pad button 'Left'
buttons.right Input Bool D-Pad button 'Right'
buttons.l Input Bool Shoulder button 'L'
buttons.r Input Bool Shoulder button 'R'
buttons.start Input Bool Menu button 'Start'
buttons.select Input Bool Menu button 'Select'

Extended Input (InputExtendedV0)

This interface offers up to 4 independent gamepad slots. Each slot has its own digital buttons, analog sticks, and analog triggers.

When the device is not docked, slots(0) is a gamepad that represents the built-in buttons.

When the device is docked, each slot represents a different gamepad connected to the Dock. When a controller connects, it's assigned the lowest free slot (0 to 3), and keeps its slot assignment until it disconnects.

Parameters

  • numSlots: Number of input slots to use, from 1 to 4 (default: 1).

InputExtendedV0.DeviceType Enum

  • None = 0: no device in this slot
  • Handheld = 1: built-in handheld controls
  • DigitalGamepad = 2: external gamepad without analog sticks
  • AnalogGamepad = 3: external gamepad with analog sticks

Port Signals

For each slot i (from 0 to numSlots - 1):

Signal Direction Type Description
slots(i).active Input Bool High when a device is present in this slot (deviceType =/= DeviceType.None)
slots(i).deviceType Input InputExtendedV0.DeviceType Connected device type
slots(i).buttons.a Input Bool Action button 'A'
slots(i).buttons.b Input Bool Action button 'B'
slots(i).buttons.x Input Bool Action button 'X'
slots(i).buttons.y Input Bool Action button 'Y'
slots(i).buttons.up Input Bool D-Pad button 'Up'
slots(i).buttons.down Input Bool D-Pad button 'Down'
slots(i).buttons.left Input Bool D-Pad button 'Left'
slots(i).buttons.right Input Bool D-Pad button 'Right'
slots(i).buttons.l1 Input Bool Shoulder button 'L1'
slots(i).buttons.r1 Input Bool Shoulder button 'R1'
slots(i).buttons.l2 Input Bool Shoulder / trigger button 'L2'
slots(i).buttons.r2 Input Bool Shoulder / trigger button 'R2'
slots(i).buttons.l3 Input Bool Left stick click 'L3'
slots(i).buttons.r3 Input Bool Right stick click 'R3'
slots(i).buttons.start Input Bool Menu button 'Start'
slots(i).buttons.select Input Bool Menu button 'Select'
slots(i).analog.leftX Input SInt(8.W) Left stick X axis (-127 left to +127 right, centered at 0)
slots(i).analog.leftY Input SInt(8.W) Left stick Y axis (-127 up to +127 down, centered at 0)
slots(i).analog.rightX Input SInt(8.W) Right stick X axis (-127 left to +127 right, centered at 0)
slots(i).analog.rightY Input SInt(8.W) Right stick Y axis (-127 up to +127 down, centered at 0)
slots(i).analog.leftTrigger Input UInt(8.W) Left analog trigger (0 released to 255 fully pressed)
slots(i).analog.rightTrigger Input UInt(8.W) Right analog trigger (0 released to 255 fully pressed)

Vibrate (vibrate: VibrateV0)

Optional. This interface allows the core to produce haptic feedback (vibration).

The mode can be either:

  • Off (0b00)
  • On (0b01)
  • Brake (0b10)

Port Signals

Signal Direction Type Description
mode Output VibrateV0.Mode() Output to the vibration motor

Cartridge Port (cartridge: CartridgePortV0)

Optional. This interface allows the core to access the cartridge slot. Note that cartridge power must be enabled in the core.json metadata file.

Cartridge pins go through level shifters, and the I/O voltage is controlled automatically by the hardware based on a shape-detecting switch in the cartridge slot.

For each direction signal, high (1) indicates output from FPGA to cartridge, 0 indicates input from cartridge to FPGA.

Port Signals

Signal Direction Type Description
enabled Output Bool High to enable cartridge level shifters.
switch Input Bool High when a DMG/CGB cartridge is inserted (5 V), low otherwise (3.3 V)
bank0In / bank0Out In / Out UInt(8.W) Address bus lines A16 through A23.
bank0Dir Output Bool Direction for Bank 0
bank1In / bank1Out In / Out UInt(8.W) Address/Data bus lines AD8 through AD15.
bank1Dir Output Bool Direction for Bank 1
bank2In / bank2Out In / Out UInt(8.W) Address/Data bus lines AD0 through AD7.
bank2Dir Output Bool Direction for Bank 2
bank3In / bank3Out In / Out UInt(4.W) Control pins: bit 0 = nCS1, 1 = nRD, 2 = nWR, 3 = PHI
bank3Dir Output Bool Direction for Bank 3 control pins
pin30In / pin30Out In / Out Bool Pin 30: nRST / nCS2
pin30Dir Output Bool Direction for Pin 30
pin31In / pin31Out In / Out Bool Pin 31: VIN / nIRQ
pin31Dir Output Bool Direction for Pin 31

Optional. This interface allows the core to access the link port. The voltage is automatically controlled by the cartridge shape-detector switch.

For each direction signal, high (1) indicates output, 0 indicates input.

Port Signals

Signal Direction Type Description
soIn, soOut, soDir In / Out / Out Bool SO pin
siIn, siOut, siDir In / Out / Out Bool SI pin
sdIn, sdOut, sdDir In / Out / Out Bool SD pin
scIn, scOut, scDir In / Out / Out Bool SC pin

PMOD (pmod: PmodV0)

Optional. This interface allows the core to access the PMOD connector at the top of the device. All I/Os are 3.3 V and unbuffered.

For each direction signal, high (1) indicates output, 0 indicates input.

Port Signals

Signal Direction Type Description
in Input UInt(4.W) Input from PMOD header
out Output UInt(4.W) Output to PMOD header
dir Output UInt(4.W) Pin direction mask

SDRAM (sdram: SdramV0)

Optional. This interface allows the core to access SDRAM memory chips.

For each direction signal, high (1) indicates output, 0 indicates input.

The number of SDRAM chips available varies by hardware revision. The horizontal retail version ("Rev4") has 2x 32 MiB SDRAM chips, with separate chip-select and clock-enable lines.

Parameters

  • addressWidth: Row/column address bus width (default: 13)
  • dataWidth: Data bus width (default: 16)
  • bankWidth: Bank address width (default: 2)
  • chips: Number of parallel chips / chip-select lines (default: 1, must be <= SdramV0.numChips)

Helpers

  • SdramV0.numChips: Int: exposes the number of SDRAM chips available on the target (1 on Rev1–3, 2 on Rev4)

Port Signals

Signal Direction Type Description
clock Output Clock SDRAM clock
cke Output UInt Clock enable (one bit per chip)
cs Output UInt Active-low chip select (one bit per chip)
ras, cas, we Output Bool Active-low command strobe lines
dqm Output UInt Active-high data byte mask
bank Output UInt Bank address
address Output UInt Address bus
dataIn Input UInt Data bus input
dataOut Output UInt Data bus output
dataDir Output Bool Data bus direction

SRAM (sram: SramV0)

Optional. This interface allows the core to access asynchronous SRAM memory chips.

For each direction signal, high (1) indicates output, 0 indicates input.

Game Bub Rev4 has a 512 KiB, 16-bit data bus asynchronous SRAM chip.

Parameters

  • addressWidth: Address bus width (default: 18)
  • dataWidth: Data bus width (default: 16)

Port Signals

Signal Direction Type Description
ceN Output Bool Active-low chip enable
weN Output Bool Active-low write enable
oeN Output Bool Active-low output enable
writeMaskN Output UInt Active-low byte write masks
address Output UInt Address bus
dataIn Input UInt Data bus input
dataOut Output UInt Data bus output
dataDir Output Bool Data bus direction

Video Filter (videoFilter: VideoFilterBasicV0)

Optional. This interface allows the core to apply filter effects to video output after scaling.

These signals are in the display clock domain, not the system clock domain.

Parameters

  • colorInDepthR: Bit-depth of the red channel (must match video)
  • colorInDepthG: Bit-depth of the green channel (must match video)
  • colorInDepthB: Bit-depth of the blue channel (must match video)
  • latency: Latency from filter input to output (in clock cycles)

Port Signals

Signal Direction Type Description
clock Input Clock Display clock
reset Input Reset Filter reset signal (active-high)
dataIn.r Input UInt Input color data (red channel)
dataIn.g Input UInt Input color data (green channel)
dataIn.b Input UInt Input color data (blue channel)
dataOut.r Output UInt(8.W) Output color data (red channel)
dataOut.g Output UInt(8.W) Output color data (green channel)
dataOut.b Output UInt(8.W) Output color data (blue channel)