Skip to content

Commit 95eebcb

Browse files
committed
better dev experience and docs
1 parent 7e2509b commit 95eebcb

File tree

11 files changed

+79
-55
lines changed

11 files changed

+79
-55
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
target
2-
fateful-cache
2+
.fateful-cache
33
zig-cache
44
zig-out
55
/.vscode

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Fateful is a CLI tool foring with my custom CPU, F8ful.
55
It contains an emulator and an assembler.
66
Fateful can be installed through [cargo](https://github.com/rust-lang/cargo) via `cargo install --git https://github.com/commonkestrel/fateful`.
77

8+
Running a program has two steps: assembly and emulation.
9+
To assemble a program, run `fateful assemble <program>.asm -o <program>.bin`
10+
If this is successful, you can emulate the program with `fateful emulate <program>.bin`
11+
The emulator is a REPL that contains various commands expalined (below)[#emulator].
12+
The most important command for emulating a program is `RUN`.
13+
Inputting `RUN 0` will run the assembly program as fast as possible until a halt is detected.
14+
815
## Assembler
916

1017
The assembler can be used with the `fateful asm` or `fateful assemble` command to assembler f8ful assembly into f8ful machine code.
@@ -464,6 +471,9 @@ jnz 1
464471

465472
### Built-in Macros
466473

474+
Built-in macros are a group of macros included by default in every program.
475+
The details of each macro can be found in (src/assembler/macros.asm)[./src/assembler/macros.asm].
476+
467477
* [PUSH](#push-macro)
468478
* [POP](#pop-macro)
469479
* [PUSHA](#pusha-macro)
@@ -889,11 +899,24 @@ The input parameter provides the number of slots that the peripheral has been at
889899
#### Reading and Writing
890900

891901
Peripherals can be written through a function with the signiture `void write(unsigned char, unsigned char)`.
902+
This function is called whenever the CPU writes to the given address or the address is `POKE`ed.
892903
The first parameter is the slot index that is being written to, and the second parameter is the value being written.
893904

894-
Peripherals can be read from with a function with the signiture `unsigned char read(unsigned char)`
905+
Peripherals can be read from with a function with the signiture `unsigned char read(unsigned char)`.
906+
This function is called whenever the CPU reads from the given address or the address is `PEEK`ed at.
895907
The input parameter is the slot index that is being read from, and the return value should be the value at the slot.
896908

909+
#### Drop
910+
911+
Peripherals are dropped through a function with the signiture `void drop()`.
912+
This function is called when every address this peripheral is attached to is `DROP`ed, or the emulator is quit.
913+
This function *must* clean up any seperate threads before returning or the emulator will crash.
914+
915+
#### Reset
916+
917+
Peripherals are reset through a function with the signiture `void reset()`.
918+
This functions is called whenever the emulator resets the CPU.
919+
897920
### Errors
898921

899922
Errors are only checked upon initialization - after both `init` and `stateful_init`.

examples/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Examples
2+
3+
This directory contains various examples to demonstrate the functionality of the emulator:
4+
5+
## Box
6+
7+
`box.asm` showcases many of the features of the language and emulator,
8+
including multiplication, conditional jumps, drawing to the screen, etc.
9+
10+
This example draws a border with Unicode box-drawing characters along with a simple hello world:
11+
![box.asm output](../misc/box.png)
12+
13+
## Fib
14+
15+
`fib.asm` is a fibonacci sequence calculator that calculates the nth fibonacci number, where n=`COUNT`.
16+
The result is stored in the `D` register.
17+
18+
This example also showcases the `test` functionality of the emulator,
19+
which will check that the final values of the registers match the expected values.
20+
21+
## Mult
22+
23+
`mult.asm` showcases multiplication through the [`math`](https://github.com/commonkestrel/fateful_math ) library.
24+
This example calls the `mul16` "function" with the arguments `5` and `120`,
25+
storing the high and low bytes of the result in the `H` and `L` registers respectively.
26+
27+
## Screen
28+
29+
`screen.asm` is a relatively small program meant to show off the screen-drawing capabilities.
30+
This program loops through every character in the character set and prints them to the screen.
31+
32+
This can be useful to see what looks nice together and get a feel for the character set of the emulator:
33+
![screen.asm output](../misc/screen.png)

examples/box.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@define WALL 0xBA
1414
@define DASH 0xCD
1515

16-
/// math = ./math
16+
/// math = https://github.com/commonkestrel/fateful_math
1717
@include <math/mul.asm>
1818

1919
@cseg

examples/mul.asm

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// Multiplies 5 and 120, storing the result in the H and L registers.
2+
///
3+
/// h: 0x02
4+
/// l: 0x58
5+
6+
/// math = https://github.com/commonkestrel/fateful_math
7+
@include <math/mul.asm>
8+
9+
@cseg
10+
@org 0x0000
11+
_start:
12+
push 5, 0, 120, 0
13+
call [mul16]
14+
pop H, L
15+
halt

examples/mult.asm

-10
This file was deleted.

math/mul.asm

-41
This file was deleted.

misc/box.png

15.7 KB
Loading

misc/screen.png

23.5 KB
Loading

shell.nix

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{ pkgs ? import <nixpkgs> {} }:
22

33
pkgs.mkShell {
4+
nativeBuildInputs = with pkgs; [
5+
pkg-config
6+
];
7+
48
buildInputs = with pkgs; [
59
openssl.dev
610
openssl

src/assembler/include.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{note, spanned_error};
1515
use clio::Input;
1616
use git2::Repository;
1717

18-
const CACHE_DIR: &str = "fateful-cache";
18+
const CACHE_DIR: &str = ".fateful-cache";
1919

2020
#[derive(Debug)]
2121
pub struct Lib {

0 commit comments

Comments
 (0)