Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add RISC5 interrupt implementation #23

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7f979be
add RISC5 interrupt implementation
charlesap Mar 24, 2021
5234e8b
announce that this is a fork
charlesap Aug 14, 2021
2a9d0f3
introduce github build action
charlesap Aug 14, 2021
3702188
install dependencies, build, test
charlesap Aug 14, 2021
1335fd6
fix indent
charlesap Aug 14, 2021
d6bb850
add MacOS build
charlesap Aug 14, 2021
e615413
add Windows build step
charlesap Aug 14, 2021
529c951
install dependencies for Windows
charlesap Aug 15, 2021
849f8a3
add Makefile for Visual Studio
charlesap Aug 15, 2021
0913125
try cmake for visual studio
charlesap Aug 15, 2021
10831d8
try regular make for visual studio
charlesap Aug 15, 2021
1e117b0
remove incorrect include paths for Windows
charlesap Aug 15, 2021
fab4a02
adjust makefile
charlesap Aug 15, 2021
5efdb27
move visual studio makefile into src directory
charlesap Aug 15, 2021
b2df0c8
simplify makefile for vs
charlesap Aug 15, 2021
1093741
try bare compile for windows
charlesap Aug 15, 2021
074a8b1
find visual studio and enter the development shell
charlesap Aug 15, 2021
9e359b7
compile with local .h files
charlesap Aug 15, 2021
c0b4e70
attempt a release action
charlesap Aug 20, 2021
f489be7
remove Windows from ci for now
charlesap Aug 20, 2021
6524336
adjust action method of setting environment variable
charlesap Aug 20, 2021
f7ba471
update get-tag
charlesap Aug 20, 2021
ecf3854
update binary path for release
charlesap Aug 20, 2021
3206b5c
change resultant binary name to risc-on-<host os>
charlesap Aug 20, 2021
b6b6884
add link to artifacts in README
charlesap Aug 20, 2021
9f0025f
add version argument
charlesap Aug 31, 2021
9a351de
align version with today release
charlesap Aug 31, 2021
ace63f7
update README
charlesap Aug 31, 2021
f4697d2
add io register write for exiting emulator
charlesap Sep 4, 2021
3ac5a8a
instrument risc_run to exit via sdl_main to avoid segmentation fault
charlesap Sep 4, 2021
0649fc1
point to latest release
charlesap Sep 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Test
on: [push]
jobs:
Ubuntu-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
run: |
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev

- name: Build
run: |
make

- name: Test
run: |
ls -alh ./risc

MacOS-build:
runs-on: macOS-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
run: |
brew install SDL2

- name: Build
run: |
make

- name: Test
run: |
ls -alh ./risc

99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
# Trigger the workflow on the new 'v*' tag created
push:
tags:
- "v*"

jobs:
create_release:
name: Create Github Release
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false

- name: Output Release URL File
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
- name: Save Release URL File for publish
uses: actions/upload-artifact@v1
with:
name: release_url
path: release_url.txt

build_artifact:
needs: [create_release]
name: ${{ matrix.os }}-build-${{ github.ref }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set tag name
uses: olegtarasov/[email protected]
id: tag
with:
tagRegex: "v(.*)"
tagRegexGroup: 1

- name: Build binary
run: |
mkdir dist

- if: matrix.os == 'ubuntu-latest'
name: Install ubuntu dependencies and build
run: |
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
make
cp ./risc dist/risc-ubuntu-latest

- if: matrix.os == 'macOS-latest'
name: Install macOS dependencies and build
run: |
brew install SDL2
make
cp ./risc dist/risc-macOS-latest

- name: Load Release URL File from release job
uses: actions/download-artifact@v1
with:
name: release_url

- name: Set binary path name
run: echo "BINARY_PATH=./dist/risc-${{ matrix.os }}" >> $GITHUB_ENV

- name: Get Release File Name & Upload URL
id: get_release_info
run: |
echo "::set-output name=upload_url::$(cat release_url/release_url.txt)"

- name: Upload Release Asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ${{ env.BINARY_PATH }}
asset_name: risc-on-${{ runner.os }}
asset_content_type: application/octet-stream


10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Oberon RISC Emulator
# Oberon RISC Emulator Integrated Oberon Fork

Forked from [Peter De Wachter's RISC emulator in C](https://github.com/pdewacht/oberon-risc-emu) with miscelaneous features added

* CAUTION: More features are not always better features!

Latest risc binary for Ubuntu: [risc-on-Linux](https://github.com/io-core/oberon-risc-emu/releases/download/v2021.9.4/risc-on-Linux) (Requires SDL2 installed via apt)

Latest risc binary for macOS: [risc-on-macOS](https://github.com/io-core/oberon-risc-emu/releases/download/v2021.9.4/risc-on-macOS) (Requires SDL2 installed via homebrew)

This is an emulator for the Oberon RISC machine. For more information,
[see Niklaus Wirth's site](https://www.inf.ethz.ch/personal/wirth/). For
Expand Down
41 changes: 41 additions & 0 deletions src/Makefile.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CC = cl
CFLAGS = -D_WIN32 -Zi -W4 -WX -D_CRT_SECURE_NO_WARNINGS -MD \
-DSTATIC_BUFSIZ= -DS_IRUSR=0 -DS_IWUSR=0 \
-wd4146 -wd4100 -wd4996 -nologo




RISC_CFLAGS = $(CFLAGS)

RISC_SOURCE = \
sdl-main.c \
sdl-ps2.c sdl-ps2.h \
risc.c risc.h risc-boot.inc \
risc-fp.c risc-fp.h \
disk.c disk.h \
pclink.c pclink.h \
raw-serial.c raw-serial.h \
sdl-clipboard.c sdl-clipboard.h

all: risc.exe

XOBJS:= $(patsubst %.c,%.obj,$(filter %.c, $(RISC_SOURCE)) )

OBJS:= $(patsubst %.c,%.obj,$(filter %.c, $(RISC_SOURCE)) )

%.obj:%.c
$(CC) -c $(RISC_CFLAGS) $< -Fo$@

risc.exe:$(RISC_SOURCE)
$(CC) -c $(RISC_CFLAGS) sdl-main.c
dir
dir src

foo:
link -debug:full $(OBJS) sdl2main.lib sdl2.lib getopt.lib -SUBSYSTEM:WINDOWS -out:$@

clean:
-del /s *.obj
-del *.exe
-del *.pdb
51 changes: 47 additions & 4 deletions src/risc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ struct RISC {
uint32_t PC;
uint32_t R[16];
uint32_t H;
bool Z, N, C, V;
uint32_t SPC; // SPC: Saved PC
bool SZ, SN, SC, SV; // : Saved Condition Codes
bool Z, N, C, V, I, E, P; // I: Interrupt mode
// E: Interrupts enabled
// P: Interrupt pending

uint32_t mem_size;
uint32_t display_start;

uint32_t shutdown;
uint32_t progress;
uint32_t current_tick;
uint32_t mouse;
Expand Down Expand Up @@ -158,22 +163,37 @@ void risc_set_switches(struct RISC *risc, int switches) {
}

void risc_reset(struct RISC *risc) {
risc->shutdown = 0;
risc->PC = ROMStart/4;
}

void risc_run(struct RISC *risc, int cycles) {
void risc_trigger_interrupt(struct RISC *risc) {
risc->P = true;
}

int risc_run(struct RISC *risc, int cycles) {
risc->progress = 20;
// The progress value is used to detect that the RISC cpu is busy
// waiting on the millisecond counter or on the keyboard ready
// bit. In that case it's better to just pause emulation until the
// next frame.
for (int i = 0; i < cycles && risc->progress; i++) {
for (int i = 0; i < cycles && risc->progress && (risc->shutdown == 0); i++) {
risc_single_step(risc);
}
return risc->shutdown;
}

static void risc_single_step(struct RISC *risc) {
uint32_t ir;
if (risc->P && risc->E && ! risc->I ) {
risc->SPC = risc->PC;
risc->SZ = risc->Z;
risc->SN = risc->N;
risc->SC = risc->C;
risc->SV = risc->V;
risc->I = true;
risc->PC = 1;
}
if (risc->PC < risc->mem_size / 4) {
ir = risc->RAM[risc->PC];
} else if (risc->PC >= ROMStart/4 && risc->PC < ROMStart/4 + ROMWords) {
Expand Down Expand Up @@ -359,7 +379,23 @@ static void risc_single_step(struct RISC *risc) {
case 4: t ^= risc->C | risc->Z; break;
case 5: t ^= risc->N ^ risc->V; break;
case 6: t ^= (risc->N ^ risc->V) | risc->Z; break;
case 7: t ^= true; break;
case 7: t ^= true;
if (((ir & ubit) == 0) && ((ir & 0x00000010) == 0x10) && risc->I) { // IRET
risc->PC = risc->SPC;
risc->Z = risc->SZ;
risc->N = risc->SN;
risc->C = risc->SC;
risc->V = risc->SV;
risc->I = false;
risc->P = false;
return;
}else{
if (((ir & ubit) == 0) && ((ir & 0x00000020) == 0x20)) { // STI and CLI
risc->E = (ir & 1) == 1 ? true: false;
return;
}
}
break;
default: abort(); // unreachable
}
if (t) {
Expand Down Expand Up @@ -551,6 +587,13 @@ static void risc_store_io(struct RISC *risc, uint32_t address, uint32_t value) {
risc->spi_selected = value & 3;
break;
}
case 32: {
// halt with value
// SDL_Quit();
//exit(value);
risc->shutdown = 1;
break;
}
case 40: {
// Clipboard control
if (risc->clipboard) {
Expand Down
3 changes: 2 additions & 1 deletion src/risc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void risc_set_clipboard(struct RISC *risc, const struct RISC_Clipboard *clipboar
void risc_set_switches(struct RISC *risc, int switches);

void risc_reset(struct RISC *risc);
void risc_run(struct RISC *risc, int cycles);
void risc_trigger_interrupt(struct RISC *risc);
int risc_run(struct RISC *risc, int cycles);
void risc_set_time(struct RISC *risc, uint32_t tick);
void risc_mouse_moved(struct RISC *risc, int mouse_x, int mouse_y);
void risc_mouse_button(struct RISC *risc, int button, bool down);
Expand Down
34 changes: 24 additions & 10 deletions src/sdl-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#define CPU_HZ 25000000
#define FPS 60
#define MSPF 1000/FPS

static uint32_t BLACK = 0x657b83, WHITE = 0xfdf6e3;
//static uint32_t BLACK = 0x000000, WHITE = 0xFFFFFF;
Expand Down Expand Up @@ -62,6 +63,7 @@ struct KeyMapping key_map[] = {
};

static struct option long_options[] = {
{ "version", no_argument, NULL, 'V' },
{ "zoom", required_argument, NULL, 'z' },
{ "fullscreen", no_argument, NULL, 'f' },
{ "leds", no_argument, NULL, 'L' },
Expand All @@ -86,6 +88,7 @@ static void usage() {
puts("Usage: risc [OPTIONS...] DISK-IMAGE\n"
"\n"
"Options:\n"
" --version Print the version of the emulator\n"
" --fullscreen Start the emulator in full screen mode\n"
" --zoom REAL Scale the display in windowed mode\n"
" --leds Log LED state on stdout\n"
Expand Down Expand Up @@ -120,7 +123,7 @@ int main (int argc, char *argv[]) {
bool boot_from_serial = false;

int opt;
while ((opt = getopt_long(argc, argv, "z:fLm:s:I:O:S", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "z:fLmV:s:I:O:S", long_options, NULL)) != -1) {
switch (opt) {
case 'z': {
double x = strtod(optarg, 0);
Expand All @@ -129,6 +132,12 @@ int main (int argc, char *argv[]) {
}
break;
}
case 'V': {
fullscreen = true;
printf("2021.8.31\n");
exit(0);
break;
}
case 'f': {
fullscreen = true;
break;
Expand Down Expand Up @@ -334,20 +343,25 @@ int main (int argc, char *argv[]) {
}
}
}

int sd = 0;
risc_set_time(risc, frame_start);
risc_run(risc, CPU_HZ / FPS);

for (int i=0; i<MSPF; i++) {
sd = risc_run(risc, CPU_HZ / 1000 * MSPF);
if(sd == 1){
SDL_Quit();
exit(0);
}
uint32_t frame_end = SDL_GetTicks();
int delay = frame_start + MSPF - frame_end;
if (delay > 0) {
SDL_Delay(delay);
}
risc_trigger_interrupt(risc);
}
update_texture(risc, texture, &risc_rect);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, &risc_rect, &display_rect);
SDL_RenderPresent(renderer);

uint32_t frame_end = SDL_GetTicks();
int delay = frame_start + 1000/FPS - frame_end;
if (delay > 0) {
SDL_Delay(delay);
}
}
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions tag-and-push-to-github.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git tag -a v202x.x.xx -m "tag message"
git push origin v202x.x.xx