hardware

package
v0.0.0-...-5e7dcd9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIZE_PROG = 256
	SIZE_DATA = 4096
	FILE_MODE = 0650
)
View Source
const (
	CKI_UP    = 0
	CKI_DOWN  = 1
	CKI_LEFT  = 2
	CKI_RIGHT = 3
	CKI_A     = 4
	CKI_B     = 5
	CKI_X     = 6
	CKI_Y     = 7
)

Key indices

View Source
const (
	FPG_P1_DPAD = 0x0 // Player 1 Direction-Pad
	FPG_P1_BTNS = 0x1 // Player 1 Buttons
	FPG_P2_DPAD = 0x2 // Player 2 Direction-Pad
	FPG_P2_BTNS = 0x3 // Player 2 Buttons

	FPG_SCR_X   = 0x4 // Screen X Coord
	FPG_SCR_Y   = 0x5 // Screen Y Coord
	FPG_SCR_VAL = 0x6 // Screen Pixel Value
	FPG_SCR_OPT = 0x7 // Screen Options

	FPG_SND_VOL = 0x8 // Sound Card Volume
	FPG_SND_PTC = 0x9 // Sound Card Pitch
	FPG_SND_OPT = 0xA // Sound Card reserved

	FPG_RAND = 0xB // Pseudo-Random Number

	FPG_DSK_H   = 0xC // High-nyble of disk address   \
	FPG_DSK_M   = 0xD // Middle-nyble of disk address  } 12-bit Address
	FPG_DSK_L   = 0xE // Low-nyble of disk address    /
	FPG_DSK_VAL = 0xF // Value of the selected disk nyble
)

F-page Addresses

View Source
const (
	OCTAVE_2 = 0
	OCTAVE_3 = 1
	OCTAVE_4 = 2
	OCTAVE_5 = 3
)
View Source
const (
	WAVE_SQUARE   = 0
	WAVE_TRIANGLE = 1
	WAVE_SAWTOOTH = 2
	WAVE_NOISE    = 3
)
View Source
const (
	PERIPHERAL_PAGE = 0xF
)
View Source
const PNUM_CHAR = "#"
View Source
const SEMITONE_INTERVAL = 1.059463

Variables

View Source
var ALL_INS = [16]Instruction{
	{
		Opcode: "BRK",
		Binary: 0b0000,
		Nargs:  0,
	},
	{
		Opcode: "LDA imm.",
		Binary: 0b0001,
		Nargs:  1,
	},
	{
		Opcode: "LDA mem.",
		Binary: 0b0010,
		Nargs:  2,
	},
	{
		Opcode: "STA",
		Binary: 0b0011,
		Nargs:  2,
	},
	{
		Opcode: "IDC",
		Binary: 0b0100,
		Nargs:  2,
	},
	{
		Opcode: "ADD",
		Binary: 0b0101,
		Nargs:  2,
	},
	{
		Opcode: "---",
		Binary: 0b0110,
		Nargs:  0,
	},
	{
		Opcode: "---",
		Binary: 0b0111,
		Nargs:  0,
	},
	{
		Opcode: "NOT",
		Binary: 0b1000,
		Nargs:  0,
	},
	{
		Opcode: "ORA",
		Binary: 0b1001,
		Nargs:  2,
	},
	{
		Opcode: "AND",
		Binary: 0b1010,
		Nargs:  2,
	},
	{
		Opcode: "SHF",
		Binary: 0b1011,
		Nargs:  1,
	},
	{
		Opcode: "SLP",
		Binary: 0b1100,
		Nargs:  2,
	},
	{
		Opcode: "BNE",
		Binary: 0b1101,
		Nargs:  2,
	},
	{
		Opcode: "JMP imm.",
		Binary: 0b1110,
		Nargs:  2,
	},
	{
		Opcode: "JMP mem.",
		Binary: 0b1111,
		Nargs:  2,
	},
}

All Instructions

View Source
var BMP_NO_CART = [16]uint16{
	0b0000000000000000,
	0b0001000101111000,
	0b0001100101001000,
	0b0001010101001000,
	0b0001001101001000,
	0b0001000101001000,
	0b0001000101111000,
	0b0000000000000000,
	0b0000000000000000,
	0b0110111011101110,
	0b0100101010100100,
	0b0100101010100100,
	0b0100111011000100,
	0b0100101010100100,
	0b0110101010100100,
	0b0000000000000000,
}

"No Cart" Screen

View Source
var MON_CLR = rl.SkyBlue

Functions

func SaveCartToFile

func SaveCartToFile(filename string, cart Cart) error

Types

type Cart

type Cart struct {
	Program    [SIZE_PROG]Nybble
	Data       [SIZE_DATA]Nybble
	IsWritable bool
}

func LoadCartFromFile

func LoadCartFromFile(filename string) (*Cart, error)

func (*Cart) GetListener

func (c *Cart) GetListener(vm *Machine) ([]byte, RAMListener)

func (*Cart) Reset

func (c *Cart) Reset()

func (*Cart) Tick

func (c *Cart) Tick(vm *Machine)

type Command

type Command struct {
	Ins  Instruction
	Args []Nybble
}

type Controller

type Controller struct {
	PlayerNr   int
	Keys       []string
	DPadNybble Nybble
	BtnsNybble Nybble
}

func NewController

func NewController(playerNr int) *Controller

func (*Controller) ButtonStatus

func (c *Controller) ButtonStatus(cki int) Nybble

Returns the status (0/1) of whether a given button is pressed

func (*Controller) GetListener

func (c *Controller) GetListener(vm *Machine) ([]byte, RAMListener)

func (*Controller) Reset

func (c *Controller) Reset()

func (*Controller) Tick

func (c *Controller) Tick(vm *Machine)

type Instruction

type Instruction struct {
	Opcode string
	Binary Nybble
	Nargs  int
}

func (Instruction) String

func (i Instruction) String() string

type Machine

type Machine struct {
	Accumulator  Nybble
	RAM          [16][16]Nybble
	RAMListeners map[byte][]RAMListener
	Program      []Command
	Cart         *Cart
	InsPointer   byte

	IsRunning bool
	// contains filtered or unexported fields
}

The actual 4RCH virtual machine

func NewMachine

func NewMachine() *Machine

func (*Machine) AddRAMListener

func (vm *Machine) AddRAMListener(trigAddrs []byte, lnr RAMListener)

func (*Machine) ExecuteCommand

func (vm *Machine) ExecuteCommand(cmd Command)

func (*Machine) LoadCartridge

func (vm *Machine) LoadCartridge(c *Cart)

func (*Machine) LoadCartridgeFile

func (vm *Machine) LoadCartridgeFile(filename string)

Tries to load a cartridge from a file

func (*Machine) PlugIn

func (vm *Machine) PlugIn(prph Peripheral)

func (*Machine) Reset

func (vm *Machine) Reset()

func (*Machine) Tick

func (vm *Machine) Tick()

Tells the VM to perform one action

func (*Machine) TickPeripherals

func (vm *Machine) TickPeripherals()

type MemMonitor

type MemMonitor struct {
	// contains filtered or unexported fields
}

func NewMemMonitor

func NewMemMonitor(hexAddrs []string) *MemMonitor

Creates a memory monitor from a list of hex addresses

func (*MemMonitor) GetListener

func (mon *MemMonitor) GetListener(vm *Machine) ([]byte, RAMListener)

func (*MemMonitor) Reset

func (mon *MemMonitor) Reset()

func (*MemMonitor) Tick

func (mon *MemMonitor) Tick(vm *Machine)

type Nybble

type Nybble uint8

type Peripheral

type Peripheral interface {
	Tick(vm *Machine)
	GetListener(vm *Machine) ([]byte, RAMListener)
	Reset()
}

type RAMListener

type RAMListener func(val Nybble)

type Screen

type Screen struct {
	// contains filtered or unexported fields
}

func NewScreen

func NewScreen(fg, bg rl.Color, scale int32) *Screen

func (*Screen) Clear

func (s *Screen) Clear()

func (*Screen) DrawBMP

func (s *Screen) DrawBMP(bmp [16]uint16)

func (*Screen) DrawVRAM

func (s *Screen) DrawVRAM()

func (*Screen) GetListener

func (s *Screen) GetListener(vm *Machine) ([]byte, RAMListener)

func (*Screen) Invert

func (s *Screen) Invert()

func (*Screen) Reset

func (s *Screen) Reset()

func (*Screen) Tick

func (s *Screen) Tick(vm *Machine)

type SoundCard

type SoundCard struct {
	// contains filtered or unexported fields
}

func NewSoundCard

func NewSoundCard(masterVol float32, sampleFiles [4]string) *SoundCard

func (*SoundCard) GetListener

func (sc *SoundCard) GetListener(vm *Machine) ([]byte, RAMListener)

func (*SoundCard) PlayTone

func (sc *SoundCard) PlayTone(t Tone)

Plays a beep with a given pitch, octave, waveform and volume

func (*SoundCard) Reset

func (sc *SoundCard) Reset()

func (*SoundCard) StopAll

func (sc *SoundCard) StopAll()

func (*SoundCard) Terminate

func (sc *SoundCard) Terminate()

func (*SoundCard) Tick

func (sc *SoundCard) Tick(vm *Machine)

type Tone

type Tone struct {
	Wave   Nybble
	Octave Nybble
	Pitch  Nybble
	Volume Nybble
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL