GithubHelp home page GithubHelp logo

a2asm's Introduction

a2asm - A simple 6502 assembler

a2asm is a 6502 assembler written in Go and licensed under the MIT License.

As mentioned in Juiced.GS, it supports a "subset of the classic Merlin assembler syntax... sufficient to assemble all of the examples from Roger Wagner's Assembly Lines book."

Copyright 2020โ€“2022, Taeber Rapczak [email protected].

Quickstart

$ go build -o a2asm cmd/a2asm/main.go
$ ./a2asm --help

Usage: a2asm [-headless] <ASSEMBLY_FILE>

Converts MERLIN-type assembly into 6502 binary. A 4-byte, DOS 3.3 header
comprising the origin and length is prefixed unless -headless is used.

$ ./a2asm 6502progs/bell.s >BELL.A2

Tips

After editing your program, you can use AppleCommander and LinApple to test it out on an emulated Apple //e:

$ edit 6502progs/hello.s
$ java -jar ac.jar -e disk.dsk HELLO
10  PRINT  CHR$(4);"BRUN TEST"
$ java -jar ac.jar -d disk.dsk TEST
$ ./a2asm 6502progs/hello.s | java -jar ac.jar -dos disk.dsk TEST B
$ linapple --autoboot --conf $PWD/linapple.conf --d1 $PWD/disk.dsk

Testing

To run the unit tests, you can simply execute:

$ go test

To compare against the Assembly Lines programs, you'll need to extract them from the DSK images to the current folder then run:

$ ./compareall.bash

Motivation

I wanted to learn 6502 assembly on a recently acquired Apple //e. I bought Assembly Lines by Roger Wagner (edited by Chris Torrence) and was introduced to the original, Merlin assembler. It was great to learn with.

When I decided to try and write my own programs, I found it easier to iterate using VIM and LinApple on my Ubuntu laptop. I found CC65 and their CA65 assembler with its modern ideas on programming the 6502. I was soon lost in their documentation and eventually ended up switching to using C as it seemed to be the easier path. After porting about 50% of the line-editor ed to the Apple //e, however, I found out that the C code that had worked in my emulator, didn't work on the real hardware!

Somewhere along the way I forgot that I was just trying to learn 6502 assembly and maybe using a "modern" assembler wasn't the appropriate tool for the job.

So, I wrote this assembler. I wrote tests to ensure every program of Roger Wagner assembles correctly. I have not added any more features, so while it uses Merlin-style syntax, it is not 100% Merlin compatible.

a2asm's People

Contributors

taeber avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

a2asm's Issues

Bad output when calling JMP to a label that's yet to be defined

	ORG $800
	JSR MAIN
	JMP EXIT
EXIT	EQU $3D0
INIT	EQU $FB2F
HOME	EQU $FC58
MAIN	JSR INIT
	JSR HOME
	RTS

Should assemble to:

20 06 08 4C D0 03 20 2F
FB 20 58 FC 60
20 06 08 4C 06 08 20 2F
FB 20 58 FC 60

Note: JMP EXIT becomes JMP $806 instead of JMP $3D0. Confirmed that MERLIN produces the expected result.

Fix high-byte subtraction

PRPLA EQU $FDE2
      LDX #>PRPLA-1

Should assemble to A2 FD, not A2 FE.

I think this is happening because num is unsigned, so -1 becomes 0xFFFF (then saved as 0xFF).

Adding 0xFF to 0xFDE2 results in 0xFEE1 and the high-byte 0xFE is returned.

Repro

func TestHighByteSubtraction(t *testing.T) {
	out := bytes.NewBuffer(nil)
	prg := strings.NewReader(`
PRPLA	EQU $FDE2
	LDX #>PRPLA-1
	`)

	_, err := Assemble(out, prg, true)
	if err != nil {
		t.Error(err)
		return
	}

	// 0000-	A2 FD   	LDX #>PRPLA-1
	expected := []byte("\xA2\xFD")

	actual := out.Bytes()
	if !bytes.Equal(expected, actual) {
		t.Errorf("Expected %v; got %v", expected, actual)
	}
}

Add support for literals in arithmetic

XPOS	EQU 1
YPOS	EQU 0
	LDA SHIPS+XPOS,X
	RTS
SHIPS	DFB 00,00

Should assemble to BD 04 80 60 00 00, but fails with error:

expected hex, binary, or decimal literal; got XPOS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.