~swisschili/toolchain-6502

eb39d68b89b55ddbcd6b6b41673b4c9059410938 — swissChili 4 months ago
Move wiki to its own branch
A  => .build.yml +27 -0
@@ 1,27 @@
image: ubuntu/lts
packages:
  - build-essential
  - cmake
  - libsdl2-dev
  - libreadline-dev
  - libglew-dev
sources:
  - https://github.com/swissChili/6502
tasks:
  - setup: |
      cd 6502
      mkdir build
      cd build
      cmake .. -DCMAKE_BUILD_TYPE=Release
  - build: |
      cd 6502/build
      make -j
      ./6502 -h
  - pack: |
      cd 6502/build
      cpack
      dpkg -I 6502.deb
artifacts:
  - 6502/build/6502
  - 6502/build/as/6502-as
  - 6502/build/6502.deb

A  => .gitignore +6 -0
@@ 1,6 @@
**/.~*
**/.#*
build
**/#*#
**/*~
**/~*
\ No newline at end of file

A  => .gitmodules +3 -0
@@ 1,3 @@
[submodule "nuklear"]
	path = nuklear
	url = https://github.com/Immediate-Mode-UI/Nuklear.git

A  => CNAME +1 -0
@@ 1,1 @@
6502.swisschili.sh
\ No newline at end of file

A  => LICENSE +23 -0
@@ 1,23 @@
Copyright 2020 swissChili

Redistribution and use in source and binary forms, with or without modification, are permitted 
provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and 
the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
and the following disclaimer in the documentation and/or other materials provided with the 
distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse 
or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file

A  => README.md +70 -0
@@ 1,70 @@
# [6502 Toolchain](https://6502.swisschili.sh)

[![Screenshot](screenshot.png)](https://6502.swisschili.sh)

This project aims to create a portable toolchain for developing,
testing and debugging programs for the 6502 processor. An assembler
may be implemented in the future but no work has been done on that
yet.

The `instructions.h` header is generated from `6502.csv` and contains
definitions of every 6502 opcode, its mnemonic and addressing mode.
It is built automatically by cmake. 

## Dependencies

- POSIX Threads
- POSIX Messsage Queues
- SDL2
- OpenGL 3
- GLEW
- GNU Readline
- Nuklear (included)

## License

```
Copyright 2020 swissChili

Redistribution and use in source and binary forms, with or without modification, are permitted 
provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and 
the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
and the following disclaimer in the documentation and/or other materials provided with the 
distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse 
or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

---

```
 ____________________________________
/ On the subject of C program        \
| indentation: "In My Egotistical    |
| Opinion, most people's C programs  |
| should be indented                 |
| six feet downward and covered with |
| dirt."                             |
|                                    |
\ -- Blair P. Houghton               /
 ------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
```

A  => as/CMakeLists.txt +18 -0
@@ 1,18 @@
cmake_minimum_required(VERSION 3.0)

project(6502 VERSION 0.1.0 LANGUAGES C)

include(TestBigEndian)
test_big_endian(BIG_ENDIAN)


if (${BIG_ENDIAN})
	add_compile_definitions(BIG_ENDIAN)
else()
	add_compile_definitions(LITTLE_ENDIAN)
endif()


add_executable(6502-as main.c as.h as.c pp.c map.h map.c hash.c hash.c)

install(TARGETS 6502-as)

A  => as/test/colors.s +13 -0
@@ 1,13 @@
;;; Shows some nice colors on the screen

	LDY #$0
loop:
	TYA
	STA $200, Y
	STA $300, Y
	STA $400, Y
	STA $500, Y
	INY
	CMP #$ff
	BCC loop
	BRK

A  => as/test/disco.s +22 -0
@@ 1,22 @@
; Taken from 6502asm.com


start:
	inx							; 600
	txa							; 601
	sta $200, y					; 602
	sta $300, y					; 605
	sta $400, y					; 608
	sta $500, y					; 60b
	iny							; 60e
	tya							; 60f
	cmp 16						; 610
	bne do						; 612
	iny							; 614
	jmp start					; 615
do:
	iny							; 618
	iny							; 619
	iny							; 61a
	iny							; 61b
	jmp start					; 61c

A  => as/test/test-abs-jump.s +16 -0
@@ 1,16 @@
;;; This program should test for a bug involving endianness.

start:
	lda #$FF
	sta $200					; Put something on the screen, just to see
	jmp second-pixel
	brk

second-pixel:
	lda #$E0					; Red
	sta $201
	sta $220
	sta $221					; Draw a box around the white pixel

loop:							; Infinite loop
	jmp loop

A  => as/test/test.s +22 -0
@@ 1,22 @@
;;; This file is meant to test the parsing capabilities of the assembler.
;;; It should contain every address mode to its parsing, as well as a
;;; range of instructions to test.

;;; When the assembler supports macros, those will be tested here as well.

start:
	lda #$32 					; Store $32 in a
	tax							; Transfer a to x
	stx $200					; Store x at $200
	jmp ($FFAA)					; Jump to the address at $FFAA
second_label:
	lda $30, X
	inc
	adc #$3
	bne start
	jsr another_subroutine
	tax
	brk

another_subroutine:
	rts

A  => building.md +29 -0
@@ 1,29 @@
@parent = page.html
@title = Building

# Building from source

You need the following libraries installed to build the emulator:

`pthread` `rt` `m` `SDL2` `GL` `GLEW` `GLU` `readline`

The first three will be included on any POSIX compliant operating system (OS X, Linux, BSD, etc).
To install SDL2, visit its <a href="https://www.libsdl.org/">website</a> or use your distributions
package manager.

<br>
You also need `awk` installed if you want to modify the `6502.csv` file from which parts of the
emulator are generated. If you don't want to do this, run cmake with `-DGEN_INSTRUCTIONS_HEADER=OFF`

<br>
You may be able to build this on Windows using Cygwin or MinGW, but I haven't tested that.

<br>
Run the usual commands to build with cmake:
```
$ mkdir build
$ cd build
$ cmake ..
$ make -j
$ ./6502 # you built it, nice
```

A  => colors.dat +0 -0
A  => debugger.md +45 -0
@@ 1,45 @@
@parent = page.html
@title = Debugger

# Debugger commands

These are the commands that the debugger CLI supports. Due to the asynchronous nature
of the debugger and emulator, commands can be run even while the emulator is actively
executing the program. For instance, try running the `disco.asm` <a href="/examples.html">
example</a> and typing `set A #$0` into the debugger while it's running with a screen
attached, you will be able to modify the program in real time!

<br>
Or, run the emulator on an empty file, and run `set $200 #$FF` to write to the frame
buffer. You can even draw a picture by hand using just the debugger!

<br>
The GUI debugger actually just sends commands like these to the emulator using a
message queue, and you can do the same. Look in `/dev/mqueue` for the message queue
the emulator is using, and try sending a debug command as a null-terminated string
to the queue, you should be able to interact with the emulator from a different
process in real time.

#### `step`, `s`

Step through one CPU instruction

#### `show [$addr]`, `print [$addr]`

Show the value at `$addr` in memory, or, if no address given, show value of all registers.

#### `set $addr #$val`, `set reg #$val`

Set either `$addr` or register `reg` to `#$val`.

#### `run`

Run the emulator.

#### `pause`

Stop running the emulator.

#### `quit`, `exit`

Quit the debugger, emulator, and the screen (if running).

A  => demo.webm +0 -0
A  => disco.dat +0 -0
A  => examples.md +56 -0
@@ 1,56 @@
@parent = page.html
@title = Examples

# Example Programs

Download the compiled programs and try them out in the emulator!

### Colors

Draws every supported color on the screen.
<a href="colors.dat" download>Download</a>

```
	LDY #$0
loop:
	TYA
	STA $200, Y
	STA $300, Y
	STA $400, Y
	STA $500, Y
	INY
	CMP #$ff
	BCC loop
	BRK
```

### Disco

Epilepsy warning: lots of flashing colors. Due to how much faster this emulator is
than the one this program was written for, it's more of just flashing colors than
what it originally looked like.
<a href="disco.dat" download>Download</a>

```
; Taken from 6502asm.com

start:
	inx
	txa
	sta $200, y
	sta $300, y
	sta $400, y
	sta $500, y
	iny
	tya
	cmp 16
	bne do
	iny
	jmp start
do:
	iny
	iny
	iny
	iny
	jmp start
```

A  => index.md +42 -0
@@ 1,42 @@
@parent = page.html
@title = Home

# 6502 Toolchain

<center>
	<video controls="true">
		<source src="demo.webm" type="video/webm">
	</video>
</center>

This project aims to create a fast, powerful, and easy to use toolchain for writing, debugging,
and running programs for the 6502 processor. It features a graphical and CLI debugger, disassembler,
and emulator.


## Features

### 8 bit color

That's 16 times more colors than <a href="http://6502asm.com/" target="_blank">the competition</a>!

### Graphical debugger

Easily step through, run, and debug your programs using a fast graphical debugger. A traditional
CLI debugger is also available.

### Fully multithreaded

The graphical debugger, cli debugger, and screen are all fully asynchronous. That means your
debugger stays fast, even when the emulator is running at full capacity.
It will soon be possible to even debug an already running instance of the emulator!

### *Fast*

This emulator is incredibly fast. So fast that programs written for other emulators don't work
properly half the time because of how fast it is! At some point I will add an option to slow
the emulator down so it is comparable to other emulators.

<br>

So what are you waiting for? Download the emulator now, or build it from source.
\ No newline at end of file

A  => nuklear +1 -0
@@ 1,1 @@
Subproject commit d9ddd1810f8e43911c06f4f86eab3053db757adc

A  => screenshot.png +0 -0
A  => styles.scss +172 -0
@@ 1,172 @@
$code: #f2f4f4;

$bg: #1d1F21;
$fg: #abb2bf;

$black:   #1e2127;
$red:     #e06c75;
$green:   #a0ea98;
$yellow:  #d1ed8b;
$blue:    #81A1C1;
$magenta: #cb80ce;
$cyan:    #87dfe5;
$white:   #abb2bf;

@import url('https://rsms.me/inter/inter.css');
html
{
	font-family: 'Inter', sans-serif;
}

@supports (font-variation-settings: normal)
{
	html
	{
		font-family: 'Inter var', sans-serif;
	}
}

body
{
	display: grid;
	place-items: center center
}


h4 code
{
	font-size: 1.5em;
}

code
{
	background: $code;
	border-radius: 5px;
	padding: 3px 5px 3px 5px;
}

a,
a:visited
{
	color: #0242f2;
	text-decoration: underline;

	&:hover
	{
		color: #0056b3;
		text-decoration: none;
	}
}

.container
{
	width: 60em;
}

.nav
{
	font-size: 1.5rem;
	display: flex;
	flex-direction: row;

	.wide
	{
		flex: 1;
		font-weight: bold;
	}
}

.split
{
	display: grid;
	grid-template-columns: 16em auto;

	.sidebar
	{
		margin-right: 1em;
	}
}

video
{
	width: 100%;
}

@media screen and (max-width: 58em)
{
	.split
	{
		display: flex;
		flex-direction: column;

		.sidebar
		{
			margin-right: none;
		}
	}

	.container
	{
		width: calc(100% - 2em);
		margin: 1em;
	}
}

.hljs
{
	display: block;
	overflow-x: auto;
	background: $code;
	padding: 1em;
	color: $black;
	font-size: 1rem;
	font-family: monospace;
	font-variant-ligatures: normal;
	font-weight: 500;
}
.hljs-comment, .hljs-quote
{
	font-style: italic;
	color: $green;
}
.hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-regexp, .hljs-deletion
{
	font-weight: 500;
}
.hljs-variable, .hljs-template-variable, .hljs-tag
{
	font-weight: 600;
}
.hljs-number, .hljs-builtin-name, .hljs-literal, .hljs-type, .hljs-params, .hljs-link
{
	font-weight: 400;
	font-style: italic;
}
.hljs-attribute
{
	font-weight: 700;
}
.hljs-string,  .hljs-symbol, .hljs-bullet, .hljs-addition
{
	font-style: italic;
	color: $red;
}
.hljs-title, .hljs-section
{
	font-style: underline;
	color: $blue;
}
.hljs-keyword, .hljs-built_in, .hljs-selector-tag
{
	color: $blue;
	font-weight: bold;
}
.hljs-emphasis
{
	font-weight: 700;
}
.hljs-strong
{
	font-weight: 700;
	opacity: 1;
}

A  => test-abs-jump.bin +0 -0
A  => test.dat +0 -0
A  => usage.md +46 -0
@@ 1,46 @@
@parent = page.html
@title = Usage

# Basic Usage

The `6502` command takes some arguments that control how it functions. Each flag is documented
here. Note that only UNIX style flags are supported, not GNU style. This uses the standard
`getopt()` function, so flags work the same as any UNIX command.

#### `-g`

Opens a GUI debugger window.

#### `-s`

Opens a window that shows the emulators screen. Cannot be used in conjunction with `-g`.

#### `-H`

Keep the emulator running after the CPU halts (after an interrupt is triggered). Useful
for debugging short programs. Does nothing when used with `-D`.

#### `-d`

Disassemble the input file, printing the whole disassembly to `stdout`. You probably want
to use this with `-n`

#### `-r`

Run the input file. Can be used in conjunction with `-s` to run and display the output.

#### `-D`

Open CLI debugger. Can be used with `-s` to view screen while debugging. 

#### `-i input`

Read `input` into the CPUs memory.

#### `-n number_of_instructions`

Disassemble only `number_of_instructions` instructions.

#### `-h, -?`

Print a help message.