asm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: BSD-2-Clause Imports: 14 Imported by: 2

Documentation

Overview

Package asm implements a 6502 macro assembler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assemble

func Assemble(r io.Reader, filename string, out io.Writer, options Option) (*Assembly, *SourceMap, error)

Assemble reads data from the provided stream and attempts to assemble it into 6502 byte code.

func AssembleFile added in v0.2.0

func AssembleFile(path string, options Option, out io.Writer) error

AssembleFile reads a file containing 6502 assembly code, assembles it, and produces a binary output file and a source map file.

Types

type Assembly

type Assembly struct {
	Code   []byte   // Assembled machine code
	Errors []string // Errors encountered during assembly
}

Assembly contains the assembled machine code and other data associated with the machine code.

func (*Assembly) ReadFrom

func (a *Assembly) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads machine code from a binary input source.

func (*Assembly) WriteTo

func (a *Assembly) WriteTo(w io.Writer) (n int64, err error)

WriteTo saves machine code as binary data into an output writer.

type Export

type Export struct {
	Label   string
	Address uint16
}

An Export describes an exported address.

type Option

type Option uint

Option type used by the Assembly function.

const (
	Verbose Option = 1 << iota // verbose output during assembly
)

Options for the Assemble function.

type SourceLine

type SourceLine struct {
	Address   int // Machine code address
	FileIndex int // Source code file index
	Line      int // Source code line number
}

A SourceLine represents a mapping between a machine code address and the source code file and line number used to generate it.

type SourceMap

type SourceMap struct {
	Origin  uint16
	Size    uint32
	CRC     uint32
	Files   []string
	Lines   []SourceLine
	Exports []Export
}

A SourceMap describes the mapping between source code line numbers and assembly code addresses.

func NewSourceMap

func NewSourceMap() *SourceMap

NewSourceMap creates an empty source map.

func (*SourceMap) ClearRange

func (s *SourceMap) ClearRange(origin, size int)

ClearRange clears portions of the source map that reference the address range between `origin` and `origin+size`.

func (*SourceMap) Find

func (s *SourceMap) Find(addr int) (filename string, line int, err error)

Find searches the source map for a source code line corresponding to the requested address.

func (*SourceMap) Merge

func (s *SourceMap) Merge(s2 *SourceMap)

Merge merges another source map (s2) into this source map.

func (*SourceMap) ReadFrom

func (s *SourceMap) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads the contents of an assembly source map.

func (*SourceMap) WriteTo

func (s *SourceMap) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the contents of an assembly source map to an output stream.

Jump to

Keyboard shortcuts

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