mach85

package module
v0.0.0-...-1445691 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: MIT Imports: 19 Imported by: 0

README

mach85

Latest development work can be found here:

https://github.com/blackchip-org/retro-cs

Build Status

Mach-85: The Virtual Machinery Playpen. Inspired by the Vintage Computer Club.

This has no practical value.

Emulates a CPU in the 6502 family. And maybe some Commodore stuff too. Of the 64 variety.

Installation

Requirements:

  • go
  • SDL2
  • ROMs
Ubuntu

Known to work on Ubuntu 18.04. Earlier versions have problems getting go and SDL to work together.

Install go and SDL2 with:

sudo apt-get install -y \
    golang \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    libsdl2-ttf-dev \
    libsdl2-gfx-dev
macOS

Install Homebrew.

Install go and SDL2 with:

brew install \
    go \
    sdl2{,_image,_mixer,_ttf,_gfx} \
    pkg-config
Setup
mkdir -p ~/go/src/github.com/blackchip-org
cd ~/go/src/github.com/blackchip-org
git clone https://github.com/blackchip-org/mach85.git
cd mach85
go get
ROMs

Find ROMs from somewhere and place in the rom directory. Filenames should be as follows:

  • kernal.rom
  • basic.rom
  • chargen.rom
Run
go run cmd/mach85/main.go

Documentation

Don't use this undocumented documentation.

Progress

The classic game of Monopole written in BASIC works:

monopole

No graphics, no sound, no timings.

More to come? We shall see.

Documentation

Index

Constants

View Source
const (
	AddrProcessorPort        = uint16(0x0001)
	AddrBasicVariableStorage = uint16(0x002d)
	AddrBasicArrayStorage    = uint16(0x002f)
	AddrStopKey              = uint16(0x0091)
	AddrKeyboardBufferLen    = uint16(0x00c6)
	AddrStack                = uint16(0x0100)
	AddrKeyboardBuffer       = uint16(0x0277)
	AddrBorderColor          = uint16(0xd020)
	AddrBackgroundColor      = uint16(0xd021)
	AddrResetVector          = uint16(0xfffc)
	AddrISR                  = uint16(0xff48)
	AddrNmiVector            = uint16(0xfffa)
	AddrIrqVector            = uint16(0xfffe)
)
View Source
const (
	KeyCursorDown  = uint8(0x11)
	KeyCursorLeft  = uint8(0x9d)
	KeyCursorRight = uint8(0x1d)
	KeyCursorUp    = uint8(0x91)
)
View Source
const (
	CmdBreakpoint          = "b"
	CmdDisassemble         = "d"
	CmdGo                  = "g"
	CmdHalt                = "h"
	CmdLoad                = "l"
	CmdLoadProgram         = "lp"
	CmdLoadBasic           = "lb"
	CmdMemory              = "m"
	CmdMemoryShifted       = "M"
	CmdNext                = "n"
	CmdScreenMemory        = "sm"
	CmdScreenMemoryShifted = "SM"
	CmdPokePeek            = "p"
	CmdPokePeekWord        = "pw"
	CmdStep                = "s"
	CmdQuit                = "q"
	CmdQuitLong            = "quit"
	CmdRegisters           = "r"
	CmdTrace               = "t"
	CmdZap                 = "z"
)

Variables

View Source
var (
	Black      = color.RGBA{0x00, 0x00, 0x00, 0xff}
	White      = color.RGBA{0xff, 0xff, 0xff, 0xff}
	Red        = color.RGBA{0x88, 0x00, 0x00, 0xff}
	Cyan       = color.RGBA{0xaa, 0xff, 0xee, 0xff}
	Purple     = color.RGBA{0xcc, 0x44, 0xcc, 0xff}
	Green      = color.RGBA{0x00, 0xcc, 0x55, 0xff}
	Blue       = color.RGBA{0x00, 0x00, 0xaa, 0xff}
	Yellow     = color.RGBA{0xee, 0xee, 0x77, 0xff}
	Orange     = color.RGBA{0xdd, 0x88, 0x55, 0xff}
	Brown      = color.RGBA{0x66, 0x44, 0x00, 0xff}
	LightRed   = color.RGBA{0xff, 0x77, 0x77, 0xff}
	DarkGray   = color.RGBA{0x33, 0x33, 0x33, 0xff}
	Gray       = color.RGBA{0x77, 0x77, 0x77, 0xff}
	LightGreen = color.RGBA{0xaa, 0xff, 0x66, 0xff}
	LightBlue  = color.RGBA{0x00, 0x88, 0xff, 0xff}
	LightGray  = color.RGBA{0xbb, 0xbb, 0xbb, 0xff}
)
View Source
var PetsciiShiftedDecoder = func(code uint8) (rune, bool) {
	ch := petsciiShifted[code]
	return ch, isPrintable(code) && ch != replacementChar
}
View Source
var PetsciiUnshiftedDecoder = func(code uint8) (rune, bool) {
	ch := petsciiUnshifted[code]
	return ch, isPrintable(code) && ch != replacementChar
}
View Source
var ScreenShiftedDecoder = func(code uint8) (rune, bool) {
	return decoder(code, PetsciiShiftedDecoder)
}
View Source
var ScreenUnshiftedDecoder = func(code uint8) (rune, bool) {
	return decoder(code, PetsciiUnshiftedDecoder)
}

Functions

func CharGen

func CharGen(renderer *sdl.Renderer, chargen MemoryChunk) (*sdl.Texture, error)

Types

type CPU

type CPU struct {
	PC uint16 // Program counter
	A  uint8  // Accumulator
	X  uint8  // X register
	Y  uint8  // Y register
	SP uint8  // Stack pointer

	C bool // Carry flag
	Z bool // Zero flag
	I bool // Interrupt disable flag
	D bool // Decimal mode flag
	B bool // Break flag
	V bool // Overflow flag
	N bool // Signed flag
	// contains filtered or unexported fields
}

CPU is the MOS Technology 6502 series processor.

func New6510

func New6510(mem *Memory) *CPU

func (*CPU) IRQ

func (c *CPU) IRQ()

func (*CPU) Next

func (c *CPU) Next() error

func (*CPU) Reset

func (c *CPU) Reset()

func (*CPU) SR

func (c *CPU) SR() uint8

func (*CPU) SetSR

func (c *CPU) SetSR(v uint8)

func (*CPU) String

func (c *CPU) String() string

type Chunk

type Chunk int
const (
	RAM0 Chunk = iota
	RAM1
	RAM2
	RAM3
	RAM4
	RAM5
	RAM6
	IO
	Open
	BasicROM
	KernalROM
	CharROM
	CartLoROM
	CartHiROM
)

type Decoder

type Decoder func(uint8) (rune, bool)

type Device

type Device interface {
	Service() error
}

type Disassembler

type Disassembler struct {
	PC uint16
	// contains filtered or unexported fields
}

func NewDisassembler

func NewDisassembler(mem *Memory) *Disassembler

func (*Disassembler) LoadSource

func (d *Disassembler) LoadSource(source *Source)

func (*Disassembler) Next

func (d *Disassembler) Next() Operation

type Instruction

type Instruction int
const (
	Illegal Instruction = iota // illegal instruction
	Adc                        // add with carry
	And                        // bitwise And with accumulator
	Asl                        // arithmetic shift left
	Bit                        // test bits
	Bmi                        // branch on minus
	Bcc                        // branch on carry clear
	Bcs                        // branch on carry set
	Beq                        // branch on equal
	Bne                        // branch on not equal
	Bpl                        // branch on plus
	Brk                        // break
	Bvc                        // branch on overflow clear
	Bvs                        // branch on overflow set
	Clc                        // clear carry
	Cld                        // clear decimal mode
	Cli                        // clear interrupt
	Clv                        // clear overflow
	Cmp                        // compare accumulator
	Cpx                        // compare x register
	Cpy                        // compare y register
	Dec                        // decrement memory
	Dex                        // decrement x
	Dey                        // decrement y
	Eor                        // bitwise exclusive or
	Inc                        // increment memory
	Inx                        // increment x
	Iny                        // increment y
	Jmp                        // jump
	Jsr                        // jump to subroutine
	Lda                        // load accumulator
	Ldx                        // load x register
	Ldy                        // load y register
	Lsr                        // logical shift right
	Nop                        // no operation
	Ora                        // bitwise or with accumulator
	Pha                        // push accumulator
	Php                        // push processor status
	Pla                        // pull accumulator
	Plp                        // pull processor status
	Rol                        // rotate left
	Ror                        // rotate right
	Rti                        // return from interrupt
	Rts                        // return from subroutine
	Sbc                        // subrtact with carry
	Sec                        // set carry
	Sed                        // set decimal mode
	Sei                        // set interrupt
	Sta                        // store accumulator
	Stx                        // store x register
	Sty                        // store y register
	Tax                        // transfer a to x
	Tay                        // transfer a to y
	Tsx                        // transfer stack pointer to x
	Txs                        // transfer x to stack pointer
	Txa                        // transfer x to a
	Tya                        // transfer y to a
)

Instructions

func (Instruction) String

func (i Instruction) String() string

type JiffyClock

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

func NewJiffyClock

func NewJiffyClock(cpu *CPU) *JiffyClock

func (*JiffyClock) Service

func (c *JiffyClock) Service() error

type Keyboard

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

func NewKeyboard

func NewKeyboard(mach *Mach85) *Keyboard

func (*Keyboard) SDLEvent

func (k *Keyboard) SDLEvent(event sdl.Event) error

type Mach85

type Mach85 struct {
	Trace       func(op Operation)
	Breakpoints map[uint16]bool
	Memory      *Memory
	Status      Status
	Err         error
	StopOnBreak bool
	QuitOnStop  bool
	OnStop      func()
	// contains filtered or unexported fields
}

func New

func New() *Mach85

func (*Mach85) AddDevice

func (m *Mach85) AddDevice(d Device)

func (*Mach85) AddInput

func (m *Mach85) AddInput(i SDLInput)

func (*Mach85) Init

func (m *Mach85) Init() error

func (*Mach85) Reset

func (m *Mach85) Reset()

func (*Mach85) Run

func (m *Mach85) Run()

func (*Mach85) Start

func (m *Mach85) Start()

func (*Mach85) Stop

func (m *Mach85) Stop()

type Memory

type Memory struct {
	Base MemoryChunk
}

func NewMemory

func NewMemory(base MemoryChunk) *Memory

func (*Memory) Dump

func (m *Memory) Dump(start uint16, end uint16, decode Decoder) string

func (*Memory) Import

func (m *Memory) Import(address uint16, data []uint8)

func (*Memory) Load

func (m *Memory) Load(address uint16) uint8

func (*Memory) Load16

func (m *Memory) Load16(address uint16) uint16

func (*Memory) Load16Z

func (m *Memory) Load16Z(address uint8) uint16

func (*Memory) Store

func (m *Memory) Store(address uint16, value uint8)

func (*Memory) Store16

func (m *Memory) Store16(address uint16, value uint16)

func (*Memory) StoreN

func (m *Memory) StoreN(address uint16, values ...uint8)

type Memory64

type Memory64 struct {
	Chunks [14]MemoryChunk
	Game   bool // pin 8
	ExROM  bool // pin 9
}

func NewMemory64

func NewMemory64() *Memory64

func (*Memory64) Init

func (m *Memory64) Init() error

func (*Memory64) Load

func (m *Memory64) Load(address uint16) uint8

func (*Memory64) Mode

func (m *Memory64) Mode() uint8

func (*Memory64) Reset

func (m *Memory64) Reset()

func (*Memory64) SetMode

func (m *Memory64) SetMode(value uint8) uint8

func (*Memory64) Store

func (m *Memory64) Store(address uint16, value uint8)

type MemoryChunk

type MemoryChunk interface {
	Load(address uint16) uint8
	Store(address uint16, value uint8)
}

type Mode

type Mode int
const (
	Absolute Mode = iota
	AbsoluteX
	AbsoluteY
	Accumulator
	Immediate
	Implied
	Indirect
	IndirectX
	IndirectY
	Relative
	ZeroPage
	ZeroPageX
	ZeroPageY
)

type Monitor

type Monitor struct {
	Disassembler *Disassembler
	Prompt       string
	// contains filtered or unexported fields
}

func NewMonitor

func NewMonitor(mach *Mach85) *Monitor

func (*Monitor) Go

func (m *Monitor) Go()

func (*Monitor) Run

func (m *Monitor) Run() error

type NullMemory

type NullMemory struct {
	Value uint8
}

func (NullMemory) Load

func (m NullMemory) Load(address uint16) uint8

func (NullMemory) Store

func (m NullMemory) Store(address uint16, value uint8)

type Operation

type Operation struct {
	Address     uint16
	Instruction Instruction
	Mode        Mode
	Operand     uint16
	Bytes       []uint8
	Comment     string
}

func (Operation) String

func (o Operation) String() string

type RAM

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

func NewRAM

func NewRAM(size int) *RAM

func (*RAM) Load

func (r *RAM) Load(address uint16) uint8

func (*RAM) Store

func (r *RAM) Store(address uint16, value uint8)

type ROM

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

func NewROM

func NewROM(bytes []uint8) *ROM

func (*ROM) Load

func (r *ROM) Load(address uint16) uint8

func (*ROM) Store

func (r *ROM) Store(address uint16, value uint8)

type SDLInput

type SDLInput interface {
	SDLEvent(sdl.Event) error
}

type Source

type Source struct {
	Comments map[uint16]string `json:"comments"`
}

func NewSource

func NewSource() *Source

type Status

type Status int
const (
	Init Status = iota
	Halt
	Run
	Break
	Breakpoint
	Trap
)

func (Status) String

func (s Status) String() string

type Video

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

func NewVideo

func NewVideo(mem *Memory) (*Video, error)

func (*Video) Service

func (v *Video) Service() error

type Watchdog

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

func NewWatchdog

func NewWatchdog(mach *Mach85) *Watchdog

func (*Watchdog) Service

func (w *Watchdog) Service() error

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

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