commit
1ee3b32637
6 changed files with 60 additions and 36 deletions
|
@ -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,7 +15,7 @@ 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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]);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue