Merge pull request #1 from MasterQ32/master

Just merge #2
This commit is contained in:
Morten Delenk 2016-07-02 17:25:11 +02:00 committed by GitHub
commit 1ee3b32637
6 changed files with 60 additions and 36 deletions

View file

@ -2,11 +2,11 @@
CC = gcc CC = gcc
CFLAGS=-O3 CFLAGS=-O3
all: explink expdump emulator as all: svmln expdump emulator svmas
.PHONY: as clean run .PHONY: as clean run
explink: explink.c svmln: svmln.c
$(CC) -g -o bin/$@ $^ $(CFLAGS) $(CC) -g -o bin/$@ $^ $(CFLAGS)
expdump: expdump.c mnemonics.c disassembler.c expdump: expdump.c mnemonics.c disassembler.c
@ -15,9 +15,9 @@ expdump: expdump.c mnemonics.c disassembler.c
emulator: emulator.c vm.c emulator: emulator.c vm.c
$(CC) -g -o bin/$@ $^ -lSDL $(CFLAGS) $(CC) -g -o bin/$@ $^ -lSDL $(CFLAGS)
as: svmas:
$(MAKE) -C as $(MAKE) -C as
test: exp test: exp
./exp -o test.exp $(ARGS) ./exp -o test.exp $(ARGS)
hexdump -C test.exp hexdump -C test.exp

View file

@ -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/$@ $^ gcc -g -o ../bin/$@ $^
tokens.c: tokens.y tokens.c: tokens.y

View file

@ -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

View file

@ -19,6 +19,9 @@ bool instaquit = false;
bool debugMode = false; bool debugMode = false;
bool visualMode = false; bool visualMode = false;
void swap_buffers();
SDL_Surface *screen = NULL;
/** /**
* An assertion the VM does. * An assertion the VM does.
* @param assertion If zero, the assertion failed. * @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) uint32_t vm_hwio(spu_t *process, cmdinput_t *info)
{ {
switch(info->info)
{
case 1: swap_buffers(); break;
}
return 0; return 0;
} }
@ -99,8 +106,8 @@ void update_input(SDL_Event *ev)
void initialize_vm() void initialize_vm()
{ {
// Initialize memory // Initialize memory
mainCore.memoryBase = 0x00; // Linear memory, start at 0x00 mainCore.memoryBase = 0x00; // Linear memory, start at 0x00
mainCore.memorySize = 0x4000000; // 64 MB; mainCore.memorySize = 0x4000000; // 64 MB;
mainCore.memory = malloc(mainCore.memorySize); mainCore.memory = malloc(mainCore.memorySize);
// Initialize code execution // Initialize code execution
@ -167,6 +174,9 @@ bool load_exp(const char *fileName)
return true; return true;
} }
int executionsPerSimulationStep = 50;
bool autoSwapBuffers = false;
void run_visual_mode() void run_visual_mode()
{ {
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@ -174,7 +184,7 @@ void run_visual_mode()
} }
atexit(SDL_Quit); 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_WM_SetCaption("DasOS Virtual Platform", NULL);
SDL_Event ev; SDL_Event ev;
@ -188,27 +198,21 @@ void run_visual_mode()
uint32_t start = SDL_GetTicks(); uint32_t start = SDL_GetTicks();
do { do {
for (int i = 0; i < 50 && running; i++) for (int i = 0; i < executionsPerSimulationStep && running; i++)
{ {
update_vm(); update_vm();
} }
} while (running && (SDL_GetTicks() - start) <= 32); } while (running && (SDL_GetTicks() - start) <= 32);
{ // copy screen if(autoSwapBuffers) swap_buffers();
SDL_LockSurface(screen);
memcpy(
screen->pixels,
(uint8_t*)mainCore.memory + 4096,
screen->h * screen->pitch);
SDL_UnlockSurface(screen);
}
SDL_Flip(screen);
} }
if(instaquit) if(instaquit)
return; return;
// Draw the current VRAM state
swap_buffers();
SDL_WM_SetCaption("DasOS Virtual Platform - STOPPED", NULL); SDL_WM_SetCaption("DasOS Virtual Platform - STOPPED", NULL);
running = true; 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() void run_text_mode()
{ {
while (running) while (running)
@ -244,7 +262,7 @@ int main(int argc, char **argv)
opterr = 0; opterr = 0;
int c; int c;
while ((c = getopt(argc, argv, "dV")) != -1) while ((c = getopt(argc, argv, "dVs:R")) != -1)
{ {
switch (c) switch (c)
{ {
@ -254,6 +272,14 @@ int main(int argc, char **argv)
case 'V': case 'V':
visualMode = 1; visualMode = 1;
break; break;
case 'R':
autoSwapBuffers = true;
break;
case 's':
executionsPerSimulationStep = atoi(optarg);
if(executionsPerSimulationStep <= 0)
executionsPerSimulationStep = 50;
break;
case '?': case '?':
if (optopt == 'o' || optopt == 'c' || optopt == 'd') if (optopt == 'o' || optopt == 'c' || optopt == 'd')
fprintf(stderr, "Option -%c requires an argument.\n", optopt); fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@ -266,6 +292,12 @@ int main(int argc, char **argv)
abort(); abort();
} }
} }
if(optind >= argc) {
fprintf(stderr, "No initial RAM-file.\n");
exit(1);
}
for (int index = optind; index < argc; index++) for (int index = optind; index < argc; index++)
{ {
fprintf(stdout, "Loading %s...\n", argv[index]); fprintf(stdout, "Loading %s...\n", argv[index]);

View file

@ -2,12 +2,17 @@
; Simple memory transform-and-copy program ; Simple memory transform-and-copy program
; ;
_start: _start:
push 0xFFFF00
push 0xFFFF00
cpget cpget
jmp @cls jmp @cls
push 0x00FFFF hwio [ci:1] ; refresh screen
push 0x00FFFF
cpget cpget
jmp @cls jmp @cls
hwio [ci:1] ; refresh screen
jmp @_start jmp @_start
syscall syscall