Giter VIP home page Giter VIP logo

assembler-6's Introduction

Gameboy Assembler

Small assembler for Gameboy assembly programs written in Swift.
Assembly syntax mostly follows other assemblers, but is probably not compatible.
Takes an assembly file as input, produces a binary, which can be executed in a Gameboy emulator.
Is fairly feature complete, supports all of the instruction set. Still missing some nice-to-have features, see the todo below.

Example program

Here is a small example Gameboy program, which displays a smiley sprite on screen:

# Simple smiley
# Displays a smiley sprite in the upper left corner of the screen

bg_tile_map = 0x9800
bg_tile_data = 0x9000

[org(0x4000)] graphics: db 0x00, 0x24, 0x24, 0x00, 0x81, 0x7e, 0x00, 0x00
[org(0x100)] start: nop; jp main
[org(0x134)] game_title: db "SMILEY"

[org(0x150)] main:
	# Set LCDC (bit 7: operation on, bit 0: bg and win on)
	ld hl, 0xff40
	ld [hl], (1 | (1 << 7))

	# Set first bg tile
	ld h, (bg_tile_map >> 8)
	ld l, (bg_tile_map & 0xff)
	ld [hl], 1

	# Set the tile data
	ld h, (bg_tile_data >> 8)
	ld l, ((bg_tile_data & 0xff) + 16)
	ld b, 8
	ld de, 0x4000
	loop:
		ld a, [de]
		inc de
		ld [hl+], a
		ld [hl+], a
		dec b
		jp nz, loop

	# Set bg palette data
	ld hl, 0xff47
	ld [hl], 0xe4
	end: jp end

[org(0x7fff)] pad: db 0x00

This is how it looks:

Smiley example screenshot

There are more examples in the examples folder:

Smiley sprite | Hello world | Directional pad movement

Usage

Quick start:

git clone [email protected]:ulrikdamm/Assembler.git
cd Assembler
swift build -c release
./.build/release/Assembler input.asm

You can compile the app from the Xcode project or by running swift build (the executable will be in .build/debug/Assembler)
You compile source code with Assembler input.asm. It also contains a dynamic framework which you can import into a macOS or iOS app.

Project status

The assembler is stable and able to produce working binaries. See below for which features are supported and which are yet to come.

New in version 1.2

๐Ÿ†• Optional linker output showing all symbol locations (run with --output-symbols)
๐Ÿ†• Relative jumps (jr)
๐Ÿ†• Updated syntax (uses [] instead of () for direct memory access, as in ld a, [0xff46])
๐Ÿ†’ Example code showing gamepad input and DMA transfers
๐Ÿ†— Fixed problems with loads between a and memory that wouldn't assemble properly

New in version 1.1

๐Ÿ†• Ability to use labels in expressions (e.g. ld a, (data_end - data))
๐Ÿ†• Allows empty labels (useful for the first point)
๐Ÿ†• Better command line interface, allows relative paths
๐Ÿ†’ Updated examples
๐Ÿ†— Fixed loading of values between A and memory addresses (e.g. ld a, (0xff00 + 0x44))

Implemented features

โœ… Assembly parsing
โœ… Code generation
โœ… Linking
โœ… All of the Gameboy instruction set
โœ… Error reporting with line numbers
โœ… Command line interface
โœ… Constant defines
โœ… Build-time expressions
โœ… Strings

Todo

โžก๏ธ Imports and file modules
โžก๏ธ Smart layout of disconnected blocks in linker
โžก๏ธ Support for variables though ds (define storage)

Wish list

๐Ÿ’Ÿ More awesome example programs
๐Ÿ’Ÿ Sprite importer (manually entering pixel hex codes suck. Maybe a way of defining sprites in ASCII art?)
๐Ÿ’Ÿ Graphical code editor

Contributing

Right now it's still a personal project, and I might not be accepting pull requests for new features. Bug fixes and more tests are welcome though.

If you find a bug or a missing feature, feel free to submit an issue.

assembler-6's People

Contributors

ulrikdamm avatar

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.