m68k

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

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

Go to latest
Published: May 10, 2018 License: BSD-3-Clause Imports: 7 Imported by: 1

README

go-m68k

GoDoc Build Status Go Report Card

This project contains a number of tools and libraries for emulating the Motorola 68000 chipset; used in devices like the Apple Macintosh, Sega Megadrive and Commodore Amiga.

WARNING This project is an incomplete work in progress.

The goal of this project is less about performance or competing with existing emulators. It's more about enabling a better development and learning experience for novices like me.

Installation

$ go get github.com/cavaliercoder/go-m68k/...

Example

Compile the following Motorola 68000 assembly using a supported compiler:

* Test 68000 simulator program

WRCHAR  EQU     6                       Trap # for write D1.B char to screen

        ORG $1000

        LEA      MESSAGE(PC),A0         Point A0 to start of message
NEXT    MOVE.B  (A0)+,D1                Get character, increment pointer
        BEQ.S   FINISH                  Exit if end
        MOVE.B  #WRCHAR,D0              Set up trap to write to screen
        TRAP    #15                     Write char. to screen
        BRA.S   NEXT                    ..and loop back
FINISH  STOP    #$2700                  Halt
MESSAGE DC.B    'Hello world!',$0D,$0A,0

        END     $1000

Run the program:

$ m68k hello-world.h68
Hello world!

Documentation

Overview

Package m68k provides an emulator of the Motorola 68000 microprocessor.

Index

Constants

View Source
const (
	SizeByte = iota
	SizeWord
	SizeLong
)
View Source
const (
	StatusCarry    = uint32(1) << iota // C
	StatusOverflow                     // V
	StatusZero                         // Z
	StatusNegative                     // N
	StatusExtend                       // X

	StatusMask = 0xA71F // Section 1.3.2
)

Status Register bits. See section 1.1.4.

View Source
const (
	CondTrue = iota
	CondFalse
	CondHigh
	CondLowOrSame
	CondCarryClear
	CondCarrySet
	CondNotEqual
	CondEqual
	CondOverflowClean
	CondOverflowSet
	CondPlus
	CondMinus
	CondGreaterOrEqual
	CondLessThan
	CondGreaterThan
	CondLessOrEqual
)

Comparison conditions. See table 3-19.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int

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

Int represents the M68000 internal encoding of an integer and provides methods for emulating the its arithmetic behaviors.

func NewInt

func NewInt(v uint32, sz int) Int

NewInt returns a new Int initialized with bits v, of size sz.

func (Int) Add

func (i Int) Add(v Int) Int

Add returns the sum of two integers and sets its status code to enable overflow and carry detection, etc. The number of bits mutated is limited by the width of the operand. For example, if a Byte is added to a Word, only the eight least significant bits will be modified by the function. The first 24 bit of the result will equal the first 24 of the Int.

func (Int) Byte

func (i Int) Byte() byte

Byte returns the 8 least significant bits of the integer as a byte.

func (Int) IsNegative

func (i Int) IsNegative() bool

IsNegative returns true if the sign it is set for the integer.

func (Int) Long

func (i Int) Long() uint32

Long returns all 32 bits of the integer as a uint32.

func (Int) SignBit

func (i Int) SignBit() uint32

SignBit returns only the sign bit of the integer, or zero if it is not set.

func (Int) SignExtend

func (i Int) SignExtend(sz int) Int

SignExtend returns an Int extended to the given size using signed arithmetic.

func (Int) SignedLong

func (i Int) SignedLong() int32

SignedLong returns all 32 bits of the integer as an int32.

func (Int) Size

func (i Int) Size() int

func (Int) Status

func (i Int) Status() uint32

func (Int) Sub

func (i Int) Sub(v Int) Int

Sub returns the difference between two integers, similarly to Add.

func (Int) Word

func (i Int) Word() uint16

Word returns the 16 least significant bits of the integer as a uint16.

type Processor

type Processor struct {
	D  [8]uint32        // Data registers
	A  [8]uint32        // Address registers
	SR uint32           // Status Register
	PC uint32           // Program Counter
	M  *m68kmem.Decoder // System memory controller

	// TraceWriter specifies where trace log output should be written to. If
	// TraceWriter is nil, no logging is performed.
	TraceWriter io.Writer
	// contains filtered or unexported fields
}

A Processor emulates the Motorola 68000 microprocessor.

func (*Processor) RegisterTrapHandler

func (c *Processor) RegisterTrapHandler(vector int, f TrapHandler) error

func (*Processor) Reset

func (c *Processor) Reset()

Reset resets all processor and memory state.

func (*Processor) Run

func (c *Processor) Run() (err error)

Run executes any program loaded into memory, starting from the program counter value, running until completion.

func (*Processor) RunState

func (c *Processor) RunState() RunState

RunState returns the current run state of the Processor.

func (*Processor) Step

func (c *Processor) Step() (err error)

Step executes the single instruction located at the address specified by the program counter register.

func (*Processor) Stop

func (c *Processor) Stop() (err error)

Stop instructs the processor to stop processing instructions.

type RunState

type RunState uint32

RunState specifies the current running state of the Processor.

const (
	// RunStateStopped indicates that the Processor is no longer incrementing the
	// program counter and executing instructions.
	RunStateStopped RunState = iota

	// RunStateRunning indicates that the Processor is currently executing
	// instructions until interrupted.
	RunStateRunning
)

type TrapHandler

type TrapHandler interface {
	Trap(c *Processor, vector int) error
}

type TrapHandlerFunc

type TrapHandlerFunc func(c *Processor, vector int) error

func (TrapHandlerFunc) HandleTrap

func (f TrapHandlerFunc) HandleTrap(p *Processor, v int) error

Directories

Path Synopsis
cmd
Package dump contains functions for printing the internal state of a Motorola 68000 processor emulator for debug purposes.
Package dump contains functions for printing the internal state of a Motorola 68000 processor emulator for debug purposes.
Package m68ktest provides functions for testing Go code against the Motorola 68000 chipset emulator.
Package m68ktest provides functions for testing Go code against the Motorola 68000 chipset emulator.
Package sim provides a simple simulator for interacting with the Motorola 68000 emulator package.
Package sim provides a simple simulator for interacting with the Motorola 68000 emulator package.
Package srec provides decoding of the Motorola S-Record file format.
Package srec provides decoding of the Motorola S-Record file format.

Jump to

Keyboard shortcuts

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