Compare commits

...

10 Commits

Author SHA1 Message Date
f53aa70d3d Update GitHub workflow 2024-02-04 17:12:10 +01:00
608f824155 Add nix flakes (makefile is kinda fucked up) 2024-02-04 17:07:19 +01:00
Ry
7777dfd3ae
Merge pull request #20 from eiowlta/main
Register Pointer Offsets, optional low hanging optimization, fixedwidth shift/bit operands
2023-07-23 14:28:22 -07:00
eiowlta
fac2865075 updated docs 2023-07-23 14:44:51 +03:00
eiowlta
3180f39514
Merge branch 'fox32-arch:main' into main 2023-07-23 14:37:31 +03:00
eiowlta
5bc6be0a70 single byte operands for bit functions, register pointer offsets 2023-07-21 18:00:07 +03:00
Ry
e9780d0a48 docs: Update cpu.md for new inc/dec instruction behavior 2023-07-20 22:55:20 -07:00
Ry
8dd95f2ffe
Merge pull request #19 from eiowlta/main
allow target field to be used to increment/decrement by 2, 4 or 8 for inc/dec
2023-07-20 16:00:16 -07:00
eiowlta
e734528c26 allow dst to be used to increment by 2, 4 or 8 2023-07-20 16:51:37 +03:00
Ry
4bedaa9028 Toggle debug output with F11 2023-07-11 23:02:57 -07:00
12 changed files with 763 additions and 228 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

View File

@ -1,42 +0,0 @@
on: [push]
name: run cputest
jobs:
fox32-run-cputest:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download latest fox32rom artifact
uses: dawidd6/action-download-artifact@v2
with:
repo: fox32-arch/fox32rom
workflow: fox32rom-unstable.yml
workflow_conclusion: success
- name: Download latest cputest artifact
uses: dawidd6/action-download-artifact@v2
with:
repo: fox32-arch/demos
workflow: demos-unstable.yml
workflow_conclusion: success
- name: Move fox32.rom into the root folder
run: |
mv fox32.rom/ download/
cp download/fox32.rom ./fox32.rom
- name: Install libsdl2-dev and vim
run: |
sudo apt update
sudo apt install -y libsdl2-dev vim
- name: Build
run: make
- name: Test
run: |
./fox32 --headless --rom cputest/cputest.bin | tee cputest.log
grep 'All tests passed' cputest.log

View File

@ -12,26 +12,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download latest fox32rom artifact
uses: dawidd6/action-download-artifact@v2
- uses: cachix/install-nix-action@v22
with:
repo: fox32-arch/fox32rom
workflow: fox32rom-unstable.yml
workflow_conclusion: success
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Move fox32.rom into the root folder
run: |
mv fox32.rom/ download/
cp download/fox32.rom ./fox32.rom
- name: Build fox32
run: nix build -L .#fox32
- name: Install libsdl2-dev and vim
run: |
sudo apt update
sudo apt install -y libsdl2-dev vim
- name: Build
run: make
- name: Patch
run: nix run nixpkgs#patchelf -- result/bin/fox32 --set-interpreter /lib64/ld-linux-x86-64.so.2 --output fox32
- name: Upload Artifact
uses: actions/upload-artifact@v2

3
.gitignore vendored
View File

@ -14,3 +14,6 @@ fox32.html
fox32.wasm
fox32.js
fox32.data
**/result
.direnv/

View File

@ -1,27 +1,9 @@
TARGET = linux
ifeq ($(TARGET),linux)
# default is used for CC
SDL2_CONFIG = sdl2-config
SDL2_CONFIG ?= sdl2-config
FOX32ROM_IN ?= fox32.rom
FOX32ROM_OUT = fox32rom.h
CFLAGS += -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags`
LDFLAGS += `$(SDL2_CONFIG) --libs`
else
ifeq ($(TARGET),mingw)
CC = x86_64-w64-mingw32-gcc
CFLAGS += -g -Ofast -std=c99 -Wall -Wextra -DWINDOWS
LDFLAGS += -lmingw32 -lSDL2main -lSDL2
TARGET_FILE_EXTENSION = .exe
else
ifeq ($(TARGET),wasm)
CC = emcc
CFLAGS += -O3 -std=c99 -Wall -Wextra
LDFLAGS += -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img
TARGET_EXTRADEPS = fox32os.img
TARGET_FILE_EXTENSION = .html
else
$(error unknown TARGET)
endif
endif
endif
CFILES = src/main.c \
src/bus.c \
@ -37,20 +19,19 @@ CFILES = src/main.c \
OBJS = $(addsuffix .o, $(basename $(CFILES)))
.PHONY: all
all: fox32$(TARGET_FILE_EXTENSION)
FOX32ROM_IN = fox32.rom
FOX32ROM_OUT = fox32rom.h
all: fox32
$(FOX32ROM_OUT): $(FOX32ROM_IN)
xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT)
cp $(FOX32ROM_IN) fox32.rom
xxd -i fox32.rom $(FOX32ROM_OUT)
rm -f fox32.rom
sed -i -e 's/fox32_rom/fox32rom/' $(FOX32ROM_OUT)
fox32$(TARGET_FILE_EXTENSION): $(TARGET_EXTRADEPS) $(OBJS)
fox32: $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS)
%.o: %.c $(FOX32ROM_OUT)
$(CC) -o $@ -c $< $(CFLAGS)
clean:
rm -rf fox32 fox32.exe fox32.wasm fox32.html fox32.data fox32.js fox32rom.h $(OBJS)
rm -rf fox32 $(FOX32ROM_OUT) $(OBJS)

View File

@ -118,7 +118,7 @@ data.16 0x8700 data.8 20 data.8 1
| 0x0C | ISE | none | 32 | set interrupt enable flag
| 0x0D | MSE | none | 32 | set MMU enable flag
| 0x10 | HALT | none | 8/16/32 | halt CPU
| 0x11 | INC | src | 8/16/32 | increment (add 1)
| 0x11 | INC | src | 8/16/32 | increment (add 1 << tgt in opcode encoding)
| 0x13 | OR | src+tgt | 8/16/32 | bitwise OR
| 0x14 | IMUL | src+tgt | 8/16/32 | multiply (signed)
| 0x15 | SRL | src+tgt | 8/16/32 | shift right logical (with zero extension)
@ -143,7 +143,7 @@ data.16 0x8700 data.8 20 data.8 1
| 0x2A | RET | none | 32 | return from function
| 0x2C | INT | src | 32 | raise interrupt
| 0x2D | TLB | src | 32 | flush TLB and set page directory pointer
| 0x31 | DEC | src | 8/16/32 | decrement (subtract 1)
| 0x31 | DEC | src | 8/16/32 | decrement (subtract 1 << tgt in opcode encoding)
| 0x32 | REM | src+tgt | 8/16/32 | calculate remainder of division (unsigned)
| 0x33 | NOT | src | 8/16/32 | bitwise NOT
| 0x34 | IDIV | src+tgt | 8/16/32 | divide (signed)
@ -162,6 +162,7 @@ data.16 0x8700 data.8 20 data.8 1
| 2 | word (32 bits)
| 3 | reserved
For SLA, SRA, SRL, ROR, ROL, BCL, BSE, BTS, src immediates are fixed to 8 bits
## Interrupts and Exceptions

View File

@ -1,7 +1,7 @@
# Encoding
```
size instr . cond dest src <src> <dest>
xx xxxxxx 0 xxx xx xx <8,16,32 bits> <8,16,32 bits>
size instr off cond dest src <src> <srcoff> <dest> <dstoff>
xx xxxxxx x xxx xx xx <8,16,32 bits> <8 bits> <8,16,32 bits> <8 bits>
```
@ -49,3 +49,6 @@ If the instruction doesn't allow variable sizes or a size was not specified, set
| 0b01 | register (pointer) |
| 0b10 | immediate |
| 0b11 | immediate (pointer) |
# Register Pointer Offset
The off field indicates that each operand of type 0b01 (register pointer) has an 8 bit immediate. This immediate is added to the value of the register before derefencing.

View File

@ -8,8 +8,8 @@ description of the fox32 CPU and instruction encoding details, see [cpu.md](./cp
### ADD: add
### SUB: subtract
### INC: increment (add 1)
### DEC: decrement (subtract 1)
### INC: increment (add 1/2/4/8)
### DEC: decrement (subtract 1/2/4/8)
### CMP: compare
### AND: bitwise AND
### OR: bitwise OR

528
flake.lock Normal file
View File

@ -0,0 +1,528 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": "systems_4"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_5": {
"inputs": {
"systems": "systems_5"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_6": {
"inputs": {
"systems": "systems_6"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_7": {
"inputs": {
"systems": "systems_7"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_8": {
"inputs": {
"systems": "systems_8"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"fox32asm": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1707042298,
"narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=",
"ref": "refs/heads/main",
"rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4",
"revCount": 68,
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
}
},
"fox32asm_2": {
"inputs": {
"flake-utils": "flake-utils_5",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1707042298,
"narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=",
"ref": "refs/heads/main",
"rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4",
"revCount": 68,
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
}
},
"fox32asm_3": {
"inputs": {
"flake-utils": "flake-utils_8",
"nixpkgs": "nixpkgs_6"
},
"locked": {
"lastModified": 1707042298,
"narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=",
"ref": "refs/heads/main",
"rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4",
"revCount": 68,
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32asm"
}
},
"fox32os": {
"inputs": {
"flake-utils": "flake-utils_2",
"fox32asm": "fox32asm",
"fox32rom": "fox32rom",
"foxtools": "foxtools",
"nixpkgs": "nixpkgs_5"
},
"locked": {
"lastModified": 1707047316,
"narHash": "sha256-bLXyUp8d1mOO5fa9ubjcP7fItfe+9PNPOATJ5nDAhrg=",
"ref": "refs/heads/main",
"rev": "1a89d1e48e22fa95d85c6575853b4f88f64e26aa",
"revCount": 211,
"type": "git",
"url": "https://githug.xyz/xenia/fox32os"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32os"
}
},
"fox32rom": {
"inputs": {
"flake-utils": "flake-utils_4",
"fox32asm": "fox32asm_2",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1706972604,
"narHash": "sha256-r5R3aoFtrctpPoQIE3ynLet9L34WUFlj2PRSKRgQAYg=",
"ref": "refs/heads/main",
"rev": "f4a7e18b2803ff65eb4182a248028bef6cda7546",
"revCount": 181,
"type": "git",
"url": "https://githug.xyz/xenia/fox32rom"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32rom"
}
},
"fox32rom_2": {
"inputs": {
"flake-utils": "flake-utils_7",
"fox32asm": "fox32asm_3",
"nixpkgs": "nixpkgs_7"
},
"locked": {
"lastModified": 1706972604,
"narHash": "sha256-r5R3aoFtrctpPoQIE3ynLet9L34WUFlj2PRSKRgQAYg=",
"ref": "refs/heads/main",
"rev": "f4a7e18b2803ff65eb4182a248028bef6cda7546",
"revCount": 181,
"type": "git",
"url": "https://githug.xyz/xenia/fox32rom"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox32rom"
}
},
"foxtools": {
"inputs": {
"flake-utils": "flake-utils_6",
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1707042981,
"narHash": "sha256-RJwtT0BUBM0XlpzUymrwvI5JAsP1drjggIjDJcnWq8o=",
"ref": "refs/heads/main",
"rev": "f690eb07c46d59c9430bc004f72f6fba271e2415",
"revCount": 43,
"type": "git",
"url": "https://githug.xyz/xenia/fox-tools"
},
"original": {
"type": "git",
"url": "https://githug.xyz/xenia/fox-tools"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_5": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_6": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_7": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_8": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"fox32os": "fox32os",
"fox32rom": "fox32rom_2",
"nixpkgs": "nixpkgs_8"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_5": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_6": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_7": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_8": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

44
flake.nix Normal file
View File

@ -0,0 +1,44 @@
{
description = "fox32 emulator";
inputs = {
fox32rom.url = "git+https://githug.xyz/xenia/fox32rom";
fox32os.url = "git+https://githug.xyz/xenia/fox32os";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, fox32rom, fox32os, flake-utils }:
flake-utils.lib.eachDefaultSystem (sys:
let pkgs = import nixpkgs { system = sys; };
rom = fox32rom.packages.${sys}.fox32rom;
deps = [ pkgs.SDL2.dev pkgs.xxd ];
os = fox32os.packages.${sys}.fox32os;
fox32 = pkgs.stdenv.mkDerivation {
name = "fox32";
src = ./.;
buildInputs = deps;
FOX32ROM_IN = "${rom}/bin/fox32.rom";
installPhase = ''
mkdir -p $out/bin
cp fox32 $out/bin/fox32
'';
};
fox32-with-os = pkgs.writeScriptBin "fox32-with-os" ''cp ${os}/bin/fox32os.img /tmp/fox32os.img && chmod u+w /tmp/fox32os.img && ${fox32}/bin/fox32 --disk /tmp/fox32os.img'';
in rec {
packages.fox32 = fox32;
packages.fox32-with-os = fox32-with-os;
packages.default = fox32;
devShells.default = pkgs.mkShell {
packages = deps;
shellHook = ''
export FOX32ROM_IN="${rom}/bin/fox32.rom"
'';
};
}
);
}

291
src/cpu.c
View File

@ -176,6 +176,7 @@ static void ptr_set32(void *ptr, uint32_t value) {
typedef struct {
uint8_t opcode;
uint8_t condition;
uint8_t offset;
uint8_t target;
uint8_t source;
uint8_t size;
@ -185,6 +186,7 @@ static asm_instr_t asm_instr_from(uint16_t half) {
asm_instr_t instr = {
(half >> 8),
(half >> 4) & 7,
(half >> 7) & 1,
(half >> 2) & 3,
(half ) & 3,
(half >> 14)
@ -604,7 +606,7 @@ static uint32_t vm_pop32(vm_t *vm) {
VM_POP_BODY(vm_read32, SIZE32)
}
#define VM_SOURCE_BODY(_vm_read, _size, _type, _move) \
#define VM_SOURCE_BODY(_vm_read, _size, _type, _move, _offset) \
uint32_t pointer_base = vm->pointer_instr_mut; \
switch (prtype) { \
case TY_REG: { \
@ -612,8 +614,9 @@ static uint32_t vm_pop32(vm_t *vm) {
return (_type) *vm_findlocal(vm, vm_read8(vm, pointer_base)); \
}; \
case TY_REGPTR: { \
if (_move) vm->pointer_instr_mut += SIZE8; \
return _vm_read(vm, *vm_findlocal(vm, vm_read8(vm, pointer_base))); \
if (_move) vm->pointer_instr_mut += SIZE8+_offset; \
return _vm_read(vm, *vm_findlocal(vm, vm_read8(vm, pointer_base)) \
+(_offset ? vm_read8(vm, pointer_base + 1) : 0)); \
}; \
case TY_IMM: { \
if (_move) vm->pointer_instr_mut += _size; \
@ -626,26 +629,26 @@ static uint32_t vm_pop32(vm_t *vm) {
} \
vm_unreachable(vm);
static uint8_t vm_source8(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read8, SIZE8, uint8_t, true)
static uint8_t vm_source8(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read8, SIZE8, uint8_t, true, offset)
}
static uint8_t vm_source8_stay(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read8, SIZE8, uint8_t, false)
static uint8_t vm_source8_stay(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read8, SIZE8, uint8_t, false, offset)
}
static uint16_t vm_source16(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read16, SIZE16, uint16_t, true)
static uint16_t vm_source16(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read16, SIZE16, uint16_t, true, offset)
}
static uint16_t vm_source16_stay(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read16, SIZE16, uint16_t, false)
static uint16_t vm_source16_stay(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read16, SIZE16, uint16_t, false, offset)
}
static uint32_t vm_source32(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read32, SIZE32, uint32_t, true)
static uint32_t vm_source32(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read32, SIZE32, uint32_t, true, offset)
}
static uint32_t vm_source32_stay(vm_t *vm, uint8_t prtype) {
VM_SOURCE_BODY(vm_read32, SIZE32, uint32_t, false)
static uint32_t vm_source32_stay(vm_t *vm, uint8_t prtype, uint8_t offset) {
VM_SOURCE_BODY(vm_read32, SIZE32, uint32_t, false, offset)
}
#define VM_TARGET_BODY(_vm_write, _localvalue) \
#define VM_TARGET_BODY(_vm_write, _localvalue, _offset) \
uint32_t pointer_base = vm->pointer_instr_mut; \
switch (prtype) { \
case TY_REG: { \
@ -655,8 +658,9 @@ static uint32_t vm_source32_stay(vm_t *vm, uint8_t prtype) {
return; \
}; \
case TY_REGPTR: { \
vm->pointer_instr_mut += SIZE8; \
_vm_write(vm, *vm_findlocal(vm, vm_read8(vm, pointer_base)), value); \
vm->pointer_instr_mut += SIZE8+_offset; \
_vm_write(vm, ( _offset ? vm_read8(vm, pointer_base + 1) : 0) + \
*vm_findlocal(vm, vm_read8(vm, pointer_base)), value); \
return; \
}; \
case TY_IMM: { \
@ -671,20 +675,20 @@ static uint32_t vm_source32_stay(vm_t *vm, uint8_t prtype) {
}; \
vm_unreachable(vm);
static void vm_target8(vm_t *vm, uint8_t prtype, uint8_t value) {
VM_TARGET_BODY(vm_write8, (*vm_findlocal(vm, local) & 0xFFFFFF00) | (uint32_t) value)
static void vm_target8(vm_t *vm, uint8_t prtype, uint8_t value, uint8_t offset) {
VM_TARGET_BODY(vm_write8, (*vm_findlocal(vm, local) & 0xFFFFFF00) | (uint32_t) value, offset)
}
static void vm_target8_zero(vm_t *vm, uint8_t prtype, uint8_t value) {
VM_TARGET_BODY(vm_write8, (uint32_t) value)
static void vm_target8_zero(vm_t *vm, uint8_t prtype, uint8_t value, uint8_t offset) {
VM_TARGET_BODY(vm_write8, (uint32_t) value, offset)
}
static void vm_target16(vm_t *vm, uint8_t prtype, uint16_t value) {
VM_TARGET_BODY(vm_write16, (*vm_findlocal(vm, local) & 0xFFFF0000) | (uint32_t) value)
static void vm_target16(vm_t *vm, uint8_t prtype, uint16_t value, uint8_t offset) {
VM_TARGET_BODY(vm_write16, (*vm_findlocal(vm, local) & 0xFFFF0000) | (uint32_t) value, offset)
}
static void vm_target16_zero(vm_t *vm, uint8_t prtype, uint16_t value) {
VM_TARGET_BODY(vm_write16, (uint32_t) value)
static void vm_target16_zero(vm_t *vm, uint8_t prtype, uint16_t value, uint8_t offset) {
VM_TARGET_BODY(vm_write16, (uint32_t) value, offset)
}
static void vm_target32(vm_t *vm, uint8_t prtype, uint32_t value) {
VM_TARGET_BODY(vm_write32, value)
static void vm_target32(vm_t *vm, uint8_t prtype, uint32_t value, uint8_t offset) {
VM_TARGET_BODY(vm_write32, value, offset)
}
static bool vm_shouldskip(vm_t *vm, uint8_t condition) {
@ -714,9 +718,11 @@ static bool vm_shouldskip(vm_t *vm, uint8_t condition) {
vm_panic(vm, FOX32_ERR_BADCONDITION);
}
static void vm_skipparam(vm_t *vm, uint32_t size, uint8_t prtype) {
static void vm_skipparam(vm_t *vm, uint32_t size, uint8_t prtype, uint8_t offset) {
if (prtype < TY_IMM) {
vm->pointer_instr_mut += SIZE8;
if (offset && prtype==TY_REGPTR)
vm->pointer_instr_mut += SIZE8;
} else if (prtype == TY_IMMPTR) {
vm->pointer_instr_mut += SIZE32;
} else {
@ -755,88 +761,95 @@ static void vm_skipparam(vm_t *vm, uint32_t size, uint8_t prtype) {
break; \
} \
}
#define VM_PRELUDE_1(_size) { \
if (vm_shouldskip(vm, instr.condition)) { \
vm_skipparam(vm, _size, instr.source); \
break; \
} \
#define VM_PRELUDE_1(_size) { \
if (vm_shouldskip(vm, instr.condition)) { \
vm_skipparam(vm, _size, instr.source, instr.offset); \
break; \
} \
}
#define VM_PRELUDE_2(_size) { \
if (vm_shouldskip(vm, instr.condition)) { \
vm_skipparam(vm, _size, instr.target); \
vm_skipparam(vm, _size, instr.source); \
break; \
} \
#define VM_PRELUDE_2(_size) { \
if (vm_shouldskip(vm, instr.condition)) { \
vm_skipparam(vm, _size, instr.target, instr.offset); \
vm_skipparam(vm, _size, instr.source, instr.offset); \
break; \
} \
}
#define VM_PRELUDE_BIT(_size) { \
if (vm_shouldskip(vm, instr.condition)) { \
vm_skipparam(vm, _size, instr.target, instr.offset); \
vm_skipparam(vm, SIZE8, instr.source, instr.offset); \
break; \
} \
}
#define VM_IMPL_JMP(_sourcemap) { \
VM_PRELUDE_1(SIZE32); \
vm->pointer_instr_mut = _sourcemap(vm_source32(vm, instr.source)); \
break; \
#define VM_IMPL_JMP(_sourcemap) { \
VM_PRELUDE_1(SIZE32); \
vm->pointer_instr_mut = _sourcemap(vm_source32(vm, instr.source, instr.offset)); \
break; \
}
#define VM_IMPL_LOOP(_sourcemap) { \
if ( \
!vm_shouldskip(vm, instr.condition) && \
(vm->registers[FOX32_REGISTER_LOOP] -= 1) != 0 \
) { \
vm->pointer_instr_mut = _sourcemap(vm_source32(vm, instr.source)); \
} else { \
vm_skipparam(vm, SIZE32, instr.source); \
} \
break; \
#define VM_IMPL_LOOP(_sourcemap) { \
if ( \
!vm_shouldskip(vm, instr.condition) && \
(vm->registers[FOX32_REGISTER_LOOP] -= 1) != 0 \
) { \
vm->pointer_instr_mut = _sourcemap(vm_source32(vm, instr.source, instr.offset)); \
} else { \
vm_skipparam(vm, SIZE32, instr.source, instr.offset); \
} \
break; \
}
#define VM_IMPL_CALL(_sourcemap) { \
VM_PRELUDE_1(SIZE32); \
uint32_t pointer_call = vm_source32(vm, instr.source); \
vm_push32(vm, vm->pointer_instr_mut); \
vm->pointer_instr_mut = _sourcemap(pointer_call); \
break; \
#define VM_IMPL_CALL(_sourcemap) { \
VM_PRELUDE_1(SIZE32); \
uint32_t pointer_call = vm_source32(vm, instr.source, instr.offset); \
vm_push32(vm, vm->pointer_instr_mut); \
vm->pointer_instr_mut = _sourcemap(pointer_call); \
break; \
}
// make sure NOT to update the stack pointer until the full instruction has
// been read, and the target has been written. otherwise a pagefault halfway
// through could wreak havoc.
#define VM_IMPL_POP(_size, _vm_target, _vm_pop) { \
VM_PRELUDE_1(_size); \
uint32_t oldsp = vm->pointer_stack; \
uint32_t val = _vm_pop(vm); \
uint32_t newsp = vm->pointer_stack; \
vm->pointer_stack = oldsp; \
_vm_target(vm, instr.source, val); \
vm->pointer_stack = newsp; \
break; \
#define VM_IMPL_POP(_size, _vm_target, _vm_pop) { \
VM_PRELUDE_1(_size); \
uint32_t oldsp = vm->pointer_stack; \
uint32_t val = _vm_pop(vm); \
uint32_t newsp = vm->pointer_stack; \
vm->pointer_stack = oldsp; \
_vm_target(vm, instr.source, val, instr.offset); \
vm->pointer_stack = newsp; \
break; \
}
#define VM_IMPL_PUSH(_size, _vm_source, _vm_push) { \
VM_PRELUDE_1(_size); \
_vm_push(vm, _vm_source(vm, instr.source)); \
break; \
#define VM_IMPL_PUSH(_size, _vm_source, _vm_push) { \
VM_PRELUDE_1(_size); \
_vm_push(vm, _vm_source(vm, instr.source, instr.offset)); \
break; \
}
#define VM_IMPL_MOV(_size, _vm_source, _vm_target) { \
VM_PRELUDE_2(_size); \
_vm_target(vm, instr.target, _vm_source(vm, instr.source)); \
break; \
#define VM_IMPL_MOV(_size, _vm_source, _vm_target) { \
VM_PRELUDE_2(_size); \
_vm_target(vm, instr.target, _vm_source(vm, instr.source, instr.offset), instr.offset); \
break; \
}
#define VM_IMPL_NOT(_size, _type, _vm_source_stay, _vm_target) { \
VM_PRELUDE_1(_size); \
_type v = _vm_source_stay(vm, instr.source); \
_type v = _vm_source_stay(vm, instr.source, instr.offset); \
_type x = ~v; \
_vm_target(vm, instr.source, x); \
_vm_target(vm, instr.source, x, instr.offset); \
vm->flag_zero = x == 0; \
break; \
}
#define VM_IMPL_INC(_size, _type, _vm_source_stay, _vm_target, _oper) { \
VM_PRELUDE_1(_size); \
_type v = _vm_source_stay(vm, instr.source); \
_type v = _vm_source_stay(vm, instr.source, instr.offset); \
_type x; \
bool carry = _oper(v, 1, &x); \
_vm_target(vm, instr.source, x); \
bool carry = _oper(v, 1 << instr.target, &x); \
_vm_target(vm, instr.source, x, instr.offset); \
vm->flag_carry = carry; \
vm->flag_zero = x == 0; \
break; \
@ -844,11 +857,11 @@ static void vm_skipparam(vm_t *vm, uint32_t size, uint8_t prtype) {
#define VM_IMPL_ADD(_size, _type, _type_target, _vm_source, _vm_source_stay, _vm_target, _oper) { \
VM_PRELUDE_2(_size); \
_type a = (_type) _vm_source(vm, instr.source); \
_type b = (_type) _vm_source_stay(vm, instr.target); \
_type a = (_type) _vm_source(vm, instr.source, instr.offset); \
_type b = (_type) _vm_source_stay(vm, instr.target, instr.offset); \
_type x; \
bool carry = _oper(b, a, &x); \
_vm_target(vm, instr.target, (_type_target) x); \
_vm_target(vm, instr.target, (_type_target) x, instr.offset); \
vm->flag_carry = carry; \
vm->flag_zero = x == 0; \
break; \
@ -856,45 +869,55 @@ static void vm_skipparam(vm_t *vm, uint32_t size, uint8_t prtype) {
#define VM_IMPL_AND(_size, _type, _type_target, _vm_source, _vm_source_stay, _vm_target, _oper) { \
VM_PRELUDE_2(_size); \
_type a = (_type) _vm_source(vm, instr.source); \
_type b = (_type) _vm_source_stay(vm, instr.target); \
_type a = (_type) _vm_source(vm, instr.source, instr.offset); \
_type b = (_type) _vm_source_stay(vm, instr.target, instr.offset); \
_type x = _oper(b, a); \
_vm_target(vm, instr.target, (_type_target) x); \
_vm_target(vm, instr.target, (_type_target) x, instr.offset); \
vm->flag_zero = x == 0; \
break; \
}
#define VM_IMPL_SHIFT(_size, _type, _type_target, _vm_source, _vm_source_stay, _vm_target, _oper){\
VM_PRELUDE_BIT(_size); \
_type a = (_type) vm_source8(vm, instr.source, instr.offset); \
_type b = (_type) _vm_source_stay(vm, instr.target, instr.offset); \
_type x = _oper(b, a); \
_vm_target(vm, instr.target, (_type_target) x, instr.offset); \
vm->flag_zero = x == 0; \
break; \
}
#define VM_IMPL_DIV(_size, _type, _type_target, _vm_source, _vm_source_stay, _vm_target, _oper) { \
VM_PRELUDE_2(_size); \
_type a = (_type) _vm_source(vm, instr.source); \
_type b = (_type) _vm_source_stay(vm, instr.target); \
_type a = (_type) _vm_source(vm, instr.source, instr.offset); \
_type b = (_type) _vm_source_stay(vm, instr.target, instr.offset); \
if (a == 0) { \
vm_panic(vm, FOX32_ERR_DIVZERO); \
break; \
} \
_type x = _oper(b, a); \
_vm_target(vm, instr.target, (_type_target) x); \
_vm_target(vm, instr.target, (_type_target) x, instr.offset); \
vm->flag_zero = x == 0; \
break; \
}
#define VM_IMPL_CMP(_size, _type, _vm_source) { \
VM_PRELUDE_2(_size); \
_type a = _vm_source(vm, instr.source); \
_type b = _vm_source(vm, instr.target); \
_type x; \
vm->flag_carry = CHECKED_SUB(b, a, &x); \
vm->flag_zero = x == 0; \
break; \
#define VM_IMPL_CMP(_size, _type, _vm_source) { \
VM_PRELUDE_2(_size); \
_type a = _vm_source(vm, instr.source, instr.offset); \
_type b = _vm_source(vm, instr.target, instr.offset); \
_type x; \
vm->flag_carry = CHECKED_SUB(b, a, &x); \
vm->flag_zero = x == 0; \
break; \
}
#define VM_IMPL_BTS(_size, _type, _vm_source) { \
VM_PRELUDE_2(_size); \
_type a = _vm_source(vm, instr.source); \
_type b = _vm_source(vm, instr.target); \
_type x = b & (1 << a); \
vm->flag_zero = x == 0; \
break; \
#define VM_IMPL_BTS(_size, _type, _vm_source) { \
VM_PRELUDE_BIT(_size); \
_type a = vm_source8(vm, instr.source, instr.offset); \
_type b = _vm_source(vm, instr.target, instr.offset); \
_type x = b & (1 << a); \
vm->flag_zero = x == 0; \
break; \
}
static void vm_debug(vm_t *vm, asm_instr_t instr, uint32_t ip, uint32_t sp) {
@ -948,20 +971,20 @@ static void vm_execute(vm_t *vm) {
case OP(SZ_WORD, OP_IN): {
VM_PRELUDE_2(SIZE32);
vm_target32(vm, instr.target, vm_io_read(vm, vm_source32(vm, instr.source)));
vm_target32(vm, instr.target, vm_io_read(vm, vm_source32(vm, instr.source, 0)), instr.offset);
break;
};
case OP(SZ_WORD, OP_OUT): {
VM_PRELUDE_2(SIZE32);
uint32_t value = vm_source32(vm, instr.source);
uint32_t port = vm_source32(vm, instr.target);
uint32_t value = vm_source32(vm, instr.source, instr.offset);
uint32_t port = vm_source32(vm, instr.target, instr.offset);
vm_io_write(vm, port, value);
break;
};
case OP(SZ_WORD, OP_RTA): {
VM_PRELUDE_2(SIZE32);
vm_target32(vm, instr.target, instr_base + vm_source32(vm, instr.source));
vm_target32(vm, instr.target, instr_base + vm_source32(vm, instr.source, instr.offset), instr.offset);
break;
};
@ -1060,29 +1083,29 @@ static void vm_execute(vm_t *vm) {
case OP(SZ_HALF, OP_OR): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_OR);
case OP(SZ_WORD, OP_OR): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_OR);
case OP(SZ_BYTE, OP_SLA): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_LEFT);
case OP(SZ_HALF, OP_SLA): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_LEFT);
case OP(SZ_WORD, OP_SLA): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_LEFT);
case OP(SZ_BYTE, OP_SRL): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_RIGHT);
case OP(SZ_HALF, OP_SRL): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_RIGHT);
case OP(SZ_WORD, OP_SRL): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_RIGHT);
case OP(SZ_BYTE, OP_SRA): VM_IMPL_AND(SIZE8, int8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_RIGHT);
case OP(SZ_HALF, OP_SRA): VM_IMPL_AND(SIZE16, int16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_RIGHT);
case OP(SZ_WORD, OP_SRA): VM_IMPL_AND(SIZE32, int32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_RIGHT);
case OP(SZ_BYTE, OP_SLA): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_LEFT);
case OP(SZ_HALF, OP_SLA): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_LEFT);
case OP(SZ_WORD, OP_SLA): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_LEFT);
case OP(SZ_BYTE, OP_SRL): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_RIGHT);
case OP(SZ_HALF, OP_SRL): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_RIGHT);
case OP(SZ_WORD, OP_SRL): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_RIGHT);
case OP(SZ_BYTE, OP_SRA): VM_IMPL_SHIFT(SIZE8, int8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_SHIFT_RIGHT);
case OP(SZ_HALF, OP_SRA): VM_IMPL_SHIFT(SIZE16, int16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_SHIFT_RIGHT);
case OP(SZ_WORD, OP_SRA): VM_IMPL_SHIFT(SIZE32, int32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_SHIFT_RIGHT);
case OP(SZ_BYTE, OP_ROL): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, ROTATE_LEFT8);
case OP(SZ_HALF, OP_ROL): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, ROTATE_LEFT16);
case OP(SZ_WORD, OP_ROL): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, ROTATE_LEFT32);
case OP(SZ_BYTE, OP_ROR): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, ROTATE_RIGHT8);
case OP(SZ_HALF, OP_ROR): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, ROTATE_RIGHT16);
case OP(SZ_WORD, OP_ROR): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, ROTATE_RIGHT32);
case OP(SZ_BYTE, OP_ROL): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, ROTATE_LEFT8);
case OP(SZ_HALF, OP_ROL): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, ROTATE_LEFT16);
case OP(SZ_WORD, OP_ROL): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, ROTATE_LEFT32);
case OP(SZ_BYTE, OP_ROR): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, ROTATE_RIGHT8);
case OP(SZ_HALF, OP_ROR): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, ROTATE_RIGHT16);
case OP(SZ_WORD, OP_ROR): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, ROTATE_RIGHT32);
case OP(SZ_BYTE, OP_BSE): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_BIT_SET);
case OP(SZ_HALF, OP_BSE): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_BIT_SET);
case OP(SZ_WORD, OP_BSE): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_BIT_SET);
case OP(SZ_BYTE, OP_BCL): VM_IMPL_AND(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_BIT_CLEAR);
case OP(SZ_HALF, OP_BCL): VM_IMPL_AND(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_BIT_CLEAR);
case OP(SZ_WORD, OP_BCL): VM_IMPL_AND(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_BIT_CLEAR);
case OP(SZ_BYTE, OP_BSE): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_BIT_SET);
case OP(SZ_HALF, OP_BSE): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_BIT_SET);
case OP(SZ_WORD, OP_BSE): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_BIT_SET);
case OP(SZ_BYTE, OP_BCL): VM_IMPL_SHIFT(SIZE8, uint8_t, uint8_t, vm_source8, vm_source8_stay, vm_target8, OPER_BIT_CLEAR);
case OP(SZ_HALF, OP_BCL): VM_IMPL_SHIFT(SIZE16, uint16_t, uint16_t, vm_source16, vm_source16_stay, vm_target16, OPER_BIT_CLEAR);
case OP(SZ_WORD, OP_BCL): VM_IMPL_SHIFT(SIZE32, uint32_t, uint32_t, vm_source32, vm_source32_stay, vm_target32, OPER_BIT_CLEAR);
case OP(SZ_BYTE, OP_CMP): VM_IMPL_CMP(SIZE8, uint8_t, vm_source8);
case OP(SZ_HALF, OP_CMP): VM_IMPL_CMP(SIZE16, uint16_t, vm_source16);
@ -1104,7 +1127,7 @@ static void vm_execute(vm_t *vm) {
};
case OP(SZ_WORD, OP_INT): {
VM_PRELUDE_1(SIZE32);
uint32_t intr = vm_source32(vm, instr.source);
uint32_t intr = vm_source32(vm, instr.source, instr.offset);
vm->pointer_instr = vm->pointer_instr_mut;
fox32_raise(vm, intr);
vm->pointer_instr_mut = vm->pointer_instr;
@ -1112,12 +1135,12 @@ static void vm_execute(vm_t *vm) {
};
case OP(SZ_WORD, OP_TLB): {
VM_PRELUDE_1(SIZE32);
set_and_flush_tlb(vm_source32(vm, instr.source));
set_and_flush_tlb(vm_source32(vm, instr.source, instr.offset));
break;
};
case OP(SZ_WORD, OP_FLP): {
VM_PRELUDE_1(SIZE32);
flush_single_page(vm_source32(vm, instr.source));
flush_single_page(vm_source32(vm, instr.source, instr.offset));
break;
};

View File

@ -8,8 +8,11 @@
#include <stdlib.h>
#include <string.h>
#include "cpu.h"
#include "keyboard.h"
extern fox32_vm_t vm;
typedef struct node_s {
struct node_s *prev;
struct node_s *next;
@ -150,6 +153,7 @@ keycode_t key_convert(int sdlcode) {
}
void key_pressed(int sdlcode) {
if (sdlcode == SDL_SCANCODE_F11) vm.debug = !vm.debug;
keycode_t code = key_convert(sdlcode);
if (code) key_put(code);
}