diff --git a/libvm/Makefile b/libvm/Makefile index 6d8b038..2e66895 100644 --- a/libvm/Makefile +++ b/libvm/Makefile @@ -2,11 +2,11 @@ CC = gcc CFLAGS=-O3 -all: explink expdump emulator as +all: svmln expdump emulator svmas .PHONY: as clean run -explink: explink.c +svmln: svmln.c $(CC) -g -o bin/$@ $^ $(CFLAGS) expdump: expdump.c mnemonics.c disassembler.c @@ -15,9 +15,9 @@ expdump: expdump.c mnemonics.c disassembler.c emulator: emulator.c vm.c $(CC) -g -o bin/$@ $^ -lSDL $(CFLAGS) -as: +svmas: $(MAKE) -C as - + test: exp ./exp -o test.exp $(ARGS) hexdump -C test.exp diff --git a/libvm/as/Makefile b/libvm/as/Makefile index 4f39397..458dba8 100644 --- a/libvm/as/Makefile +++ b/libvm/as/Makefile @@ -1,6 +1,6 @@ -all: as +all: svmas -as: as.c tokens.c ../mnemonics.c ../disassembler.c +svmas: as.c tokens.c ../mnemonics.c ../disassembler.c gcc -g -o ../bin/$@ $^ tokens.c: tokens.y diff --git a/libvm/bin/build b/libvm/bin/build deleted file mode 100644 index 2981a21..0000000 --- a/libvm/bin/build +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -ASMFILE=$1.asm -BINFILE=`echo $ASMFILE | sed "s|\.asm\$|\.bin|"` -EXPFILE=`echo $BINFILE | sed "s|\.bin\$|\.exp|"` - -echo $ASMFILE -echo $BINFILE -echo $EXPFILE - -./bin/as -o $BINFILE $ASMFILE -Ls -./bin/explink -o $EXPFILE -c $BINFILE -rm $BINFILE \ No newline at end of file diff --git a/libvm/emulator.c b/libvm/emulator.c index 953da7e..9342357 100644 --- a/libvm/emulator.c +++ b/libvm/emulator.c @@ -19,6 +19,9 @@ bool instaquit = false; bool debugMode = false; bool visualMode = false; +void swap_buffers(); +SDL_Surface *screen = NULL; + /** * An assertion the VM does. * @param assertion If zero, the assertion failed. @@ -52,6 +55,10 @@ uint32_t vm_syscall(spu_t *process, cmdinput_t *info) */ uint32_t vm_hwio(spu_t *process, cmdinput_t *info) { + switch(info->info) + { + case 1: swap_buffers(); break; + } return 0; } @@ -99,8 +106,8 @@ void update_input(SDL_Event *ev) void initialize_vm() { // Initialize memory - mainCore.memoryBase = 0x00; // Linear memory, start at 0x00 - mainCore.memorySize = 0x4000000; // 64 MB; + mainCore.memoryBase = 0x00; // Linear memory, start at 0x00 + mainCore.memorySize = 0x4000000; // 64 MB; mainCore.memory = malloc(mainCore.memorySize); // Initialize code execution @@ -167,6 +174,9 @@ bool load_exp(const char *fileName) return true; } +int executionsPerSimulationStep = 50; +bool autoSwapBuffers = false; + void run_visual_mode() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -174,7 +184,7 @@ void run_visual_mode() } atexit(SDL_Quit); - SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); + screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); SDL_WM_SetCaption("DasOS Virtual Platform", NULL); SDL_Event ev; @@ -188,27 +198,21 @@ void run_visual_mode() uint32_t start = SDL_GetTicks(); do { - for (int i = 0; i < 50 && running; i++) + for (int i = 0; i < executionsPerSimulationStep && running; i++) { update_vm(); } } while (running && (SDL_GetTicks() - start) <= 32); - { // copy screen - SDL_LockSurface(screen); - memcpy( - screen->pixels, - (uint8_t*)mainCore.memory + 4096, - screen->h * screen->pitch); - SDL_UnlockSurface(screen); - } - - SDL_Flip(screen); + if(autoSwapBuffers) swap_buffers(); } if(instaquit) return; + // Draw the current VRAM state + swap_buffers(); + SDL_WM_SetCaption("DasOS Virtual Platform - STOPPED", NULL); running = true; @@ -228,6 +232,20 @@ void run_visual_mode() } } +void swap_buffers() +{ + if(screen == NULL) + return; + SDL_LockSurface(screen); + memcpy( + screen->pixels, + (uint8_t*)mainCore.memory + 4096, + screen->h * screen->pitch); + SDL_UnlockSurface(screen); + + SDL_Flip(screen); +} + void run_text_mode() { while (running) @@ -244,7 +262,7 @@ int main(int argc, char **argv) opterr = 0; int c; - while ((c = getopt(argc, argv, "dV")) != -1) + while ((c = getopt(argc, argv, "dVs:R")) != -1) { switch (c) { @@ -254,6 +272,14 @@ int main(int argc, char **argv) case 'V': visualMode = 1; break; + case 'R': + autoSwapBuffers = true; + break; + case 's': + executionsPerSimulationStep = atoi(optarg); + if(executionsPerSimulationStep <= 0) + executionsPerSimulationStep = 50; + break; case '?': if (optopt == 'o' || optopt == 'c' || optopt == 'd') fprintf(stderr, "Option -%c requires an argument.\n", optopt); @@ -266,6 +292,12 @@ int main(int argc, char **argv) abort(); } } + + if(optind >= argc) { + fprintf(stderr, "No initial RAM-file.\n"); + exit(1); + } + for (int index = optind; index < argc; index++) { fprintf(stdout, "Loading %s...\n", argv[index]); diff --git a/libvm/explink.c b/libvm/svmln.c similarity index 100% rename from libvm/explink.c rename to libvm/svmln.c diff --git a/libvm/test.asm b/libvm/test.asm index a718919..6429b48 100644 --- a/libvm/test.asm +++ b/libvm/test.asm @@ -2,12 +2,17 @@ ; Simple memory transform-and-copy program ; _start: - push 0xFFFF00 + + push 0xFFFF00 cpget jmp @cls - push 0x00FFFF + hwio [ci:1] ; refresh screen + + push 0x00FFFF cpget jmp @cls + hwio [ci:1] ; refresh screen + jmp @_start syscall