• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JavaScript based Gameboy Assembler

A JavaScript Gameboy Assembler

gbasm is a JavaScript based compiler for Gameboy z80 assembly code.

gbasm is mainly being developed for and tested with Tuff.

Installation and Usage

  1. Install Node.js
  2. Now install gbasm by running npm install -g gbasm
Usage: gbasm [options] [sources]

   --outfile, -o <s>: The name of the output rom file (default: game.gb)
      --optimize, -O: Enable instruction optimizations
   --mapfile, -m <s>: Generates a ASCII overview of the mapped ROM space
   --symfile, -s <s>: Generates a symbol map compatible with debuggers
  --jsonfile, -j <s>: Generates a JSON data dump of all sections with their data, labels, instructions etc.
        --silent, -S: Surpresses all logging
         --debug, -d: Enable support for custom "msg" debug opcodes',
       --verbose, -v: Surpresses all logging
           --version: Displays version information
              --help: Displays this help text

Output Options

  • __ --outfile / -o __

    Specifies the filename of the generated ROM image.

  • __ --optimize / -O __

    Turns on assembly optimizations which are automatically performed during linkage.

  • __ --mapfile / -m__

    Generates a ASCII overview of the mapped ROM areas.

  • __ --symfile / -s __

    Generates a symbol map file for use with Debuggers (e.g. bgb)

  • __ --debug / -d __

    Enables support for custom msg opcodes for use with Debuggers (e.g. bgb)

    ; This will log "Debug Message" when run in the debugger
    msg "Debug Message"

    Note: The msg opcode will be ignored when compiling without the flag.

  • __ --jsonfile / -j __

    Generates a json file that contains the fully linked ROM data serialized into a detailed format useable for further, custom processing.

Compatibility Notes

gbasm is mostly compatible with rgbds but there are some deviations and additions:

General

  • gbasm is a multipass compiler, meaning the all sources files and definitions are parsed before resolving any names or sizes.

Syntax

  • The load accumulator and increment/decrement hl type instructions only take hli and hld as their second operand
  • Memory operands do only support [ and ] in their syntax
  • All names and labels which start with an underscore are treated as being local / private to the file they were defined in

Macros

  • Most of the pre-defined macros from rgbds are available (e.g. COS, STRLWR etc.)

  • User defined macros come in two flavors:

    1. Expression Macros

    These macros contain only a single expression statement and can be used as values everywhere a built-in macro could be used:

    MACRO add(@a, @b)
      @a + @b
    ENDMACRO
    
    DB add(2, 5) ; essentially DB 7

    Expression Macros can take Numbers and Strings as their arguments.

    1. Expansion Macros

    These are macros in the classical sense which just expand into additional assembler code:

    MACRO header()
      DB $11,$22,$33,$44,$55
      DW $1234,$4567
    ENDMACRO
    
    header(); expands into the DB and DW diretives above

    In addition to Strings and Numbers, expansion macros can also take Registers as their arguments.

    MACRO ld16(@number, @a, @b)
      ld @a,@number >> 8
      ld @b,@number & $ff
    ENDMACRO
    
    ld16($1234, b, c); turns into ld b,$12 and ld c,$34

Instructions

gbasm supports additional meta instructions at the source code level, which will be compiled down to multiple native instructions.

These aim at increasing the readability of the source.

addw

Adds a 8-bit operand to a 16-bit register using only the Accumulator:

; ld      a,$ff
; add     a,l
; ld      l,a
; adc     a,h
; sub     l
; ld      h,a
addw  hl,$ff
addw  bc,$ff
addw  de,$ff

; add     a,l
; ld      l,a
; adc     a,h
; sub     l
; ld      h,a
addw  hl,a
addw  bc,a
addw  de,a

; ld      a,reg
; add     a,l
; ld      l,a
; adc     a,h
; sub     l
; ld      h,a
addw  hl,reg
addw  bc,reg
addw  de,reg

incx

Extended increment of a memory address, using the Accumulator as an intermediate register (destroying its contents):

; ld a,[$0000]
; inc a
; ld [$0000],a
incx [$0000]

decx

Extended decrement of a memory address, using the Accumulator as an intermediate register (destroying its contents):

; ld a,[$0000]
; dec a
; ld [$0000],a
decx [$0000]

ldxa

Extended memory loads using the Accumulator as an intermediate register (destroying its contents):

; ld  a,[hli]
; ld  R,a
ldxa  b,[hli]
ldxa  c,[hli]
ldxa  d,[hli]
ldxa  e,[hli]
ldxa  h,[hli]
ldxa  l,[hli]

; ld  a,[hld]
; ld  R,a
ldxa  b,[hld]
ldxa  c,[hld]
ldxa  d,[hld]
ldxa  e,[hld]
ldxa  h,[hld]
ldxa  l,[hld]

; ld  a,R
; ld  [hli],a
ldxa  [hli],b
ldxa  [hli],c
ldxa  [hli],d
ldxa  [hli],e
ldxa  [hli],h
ldxa  [hli],l

; ld   a,R
; ld   [hld],a
ldxa  [hld],b
ldxa  [hld],c
ldxa  [hld],d
ldxa  [hld],e
ldxa  [hld],h
ldxa  [hld],l

; ld  a,$ff
; ld  [$0000],a
ldxa  [$0000],$ff

; ld  a,$ff
; ld  [hli],a
ldxa  [hli],$ff

; ld  a,$ff
; ld  [hld],a
ldxa  [hld],$ff

; ld  a,R
; ld  [$0000],a
ldxa  [$0000],b
ldxa  [$0000],c
ldxa  [$0000],d
ldxa  [$0000],e
ldxa  [$0000],h
ldxa  [$0000],l

; ld  a,[hli]
; ld  [$0000],a
ldxa  [$0000],[hli]

; ld  a,[hld]
; ld  [$0000],a
ldxa  [$0000],[hld]

; ld  a,[$0000]
; ld  [$0000],a
ldxa  [$0000],[$0000]

; ld  a,[$0000]
; ld  R,a
ldxa  b,[$0000]
ldxa  c,[$0000]
ldxa  d,[$0000]
ldxa  e,[$0000]
ldxa  h,[$0000]
ldxa  l,[$0000]

; ld  a,[$0000]
; ld  [hli],a
ldxa  [hli],[$0000]

; ld  a,[$0000]
; ld  [hld],a
ldxa  [hld],[$0000]

License

Licensed under MIT.

More Repositories

1

JavaScript-Garden

A collection of documentation about the most quirky parts of the JavaScript language.
CSS
3,445
star
2

Tuff.gb

Tuff - An original game for the Nintendo GameBoy
Assembly
305
star
3

Maple.js

WebSocket based Multiplayer Architecture for Node.js
JavaScript
267
star
4

BiSON.js

Bandwidth optimized binary encoding for JavaScript
JavaScript
252
star
5

NodeGame-Shooter

Asteroids meets tons of color, meets multiplayer, meets HTML5 and falls in love with Node.
JavaScript
193
star
6

twitter-text-python

Twitter text processing library (auto linking and extraction of usernames, lists and hashtags). Based on the Java implementation by Matt Sanford
Python
91
star
7

cobalt-rs

Low level, UDP based networking library for rust.
Rust
57
star
8

cursive_table_view

A basc table view compnent for cursive.
Rust
49
star
9

Fomatto

JavaScript string interpolation and formatting.
JavaScript
48
star
10

cursive_tree_view

A tree view implementation for cursive.
Rust
46
star
11

cursive_calendar_view

A basic calendar view implementation for cursive.
Rust
26
star
12

Fluff.js

2D Game Engine using OpenGL and V8.
C++
25
star
13

debug_stub_derive

A drop-in replacement for #[derive(Debug)] with support for members which do not implement `fmt::Debug`.
Rust
23
star
14

NodeGame-Orbit

Eufloria inspired game prototype powered with Node.js.
JavaScript
19
star
15

neko.js

Classes so easy, cats could use them!
JavaScript
17
star
16

bonsaiden.github.com

The site without kittens!
13
star
17

fareon

A minimal FPS Server / Client Framework
JavaScript
11
star
18

box

A simple Physics Engine
JavaScript
10
star
19

lithium

A WebSocket library for both Node.js and the Browser.
JavaScript
9
star
20

gbcartridge

Schematics and PCB Layout for a replicate Gameboy Development Cartridge
C
9
star
21

I8080

Yet another 8080 emulator....
C
9
star
22

gfm

A GitHub flavored Markdown Editor with live Preview
JavaScript
9
star
23

Tuff-NES

A homebrew NES game, which is a port of my old Java Game Tuff.
Assembly
8
star
24

TerrainGeometry

A TerrainGeometry for Three.js
JavaScript
7
star
25

noir

A rust based, DSL alike and request driven, black box testing library for HTTP APIs.
Rust
7
star
26

vim

My .vim stuffs
Vim Script
6
star
27

Norum

2D paltformer engine/demo written in C.
C
6
star
28

NodeGame-Tactics

Massive (*cough*) RTS with Node and WebSocket.
JavaScript
5
star
29

step

Lockstep multiplayer server test code
JavaScript
5
star
30

Tuff

A small 2D Game in Black & White. Featuring old school GameBoy resolution, Metroid style world exploration and PowerUps.
Java
5
star
31

Class

A Class Factory for JavaScript.
JavaScript
5
star
32

Bonsai-Game-Library

A small Java based Library/Engine for creating 2D Games featuring Applet support.
Java
5
star
33

aabb

AABB Collision System
Lua
4
star
34

discord-bot

Work in progess Discord Bot for Audio Playback and other things.
Rust
4
star
35

luma

Minimal game engine using opengl and lua
C
4
star
36

Coding-Kitten

Stackoverflow Chatbot
JavaScript
4
star
37

emblem

Server / Client library for HTML5 realtime multiplayer games.
JavaScript
3
star
38

gbasm-rs

A WIP Gameboy Assembler written in Rust
Rust
3
star
39

Mia

A flexible and customizable documentation generator based on esprima
JavaScript
3
star
40

ShoTech

Tech Demo for Multiplayer Asteroids thing (WIP)
JavaScript
3
star
41

pydep

pydep - Simple dependency listing and graph generation for Python modules.
3
star
42

wombat

V8 / Allegro Game Engine Thing
C++
2
star
43

Atarashii

Atarashii - Twitter on your GNOME Desktop.
Python
2
star
44

ik-prototype

Procedural Animation Prototype with IK and Ragdolls
Rust
2
star
45

lufa

A staticly typed language compiling to JavaScript
JavaScript
2
star
46

NodeGame-Hack

A Single / Multiplayer game where you take control over nodes in a network and hack your way to victory!
JavaScript
2
star
47

mk8

Mario Kart 8 Kart Calculator - http://bonsaiden.github.io/mk8/
JavaScript
2
star
48

Project-Iar

WebGL Danmaku!
JavaScript
2
star
49

substrat

Simple, automatic build system for single page web applications.
JavaScript
2
star
50

rts.rs

An oldschool RTS game prototype
Rust
2
star
51

NodeGame-Lazers

2D Top Down Multiplayer Shooter with lazers!
JavaScript
2
star
52

lobby-server

Rust
2
star
53

cobalt-entity

Rust
1
star
54

dungeon

Randomly generated Zelda esque dungeons.
Rust
1
star
55

vectroid.gb

Assembly
1
star
56

glider

F-Zero Style Gameplay Prototype
Rust
1
star
57

cobalt

A minimal client / server framework for creating multiplayer games.
JavaScript
1
star
58

lufai

Because the other one became a mess...
1
star
59

file-pattern

A flexible library for pattern matching on filenames and paths.
JavaScript
1
star
60

neovim-config

Vim Script
1
star
61

.vim

Vim Files
Vim Script
1
star
62

td-shooter-rs

WIP 2D multiplayer shooter tech demo.
Rust
1
star
63

featureful

Automatically verify your test implementations against cucumber feature specs.
JavaScript
1
star
64

vorbis-enc

Encode audio streams into ogg vorbis files.
Rust
1
star
65

ThreeGame

A basic Three.js Game Template
JavaScript
1
star
66

kuusi

Platformer based on Allegro and Lua
Lua
1
star
67

trace.js

Basic Type Tracing Prototype for JS Code
JavaScript
1
star
68

network-test-rs

Rust
1
star