From 8d6f380f6b302bd1840be7a47dc365f7da4aea1e Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Wed, 9 Oct 2024 23:13:34 -0400 Subject: [PATCH] add scaffolding around calling vbEmulate in a loop --- main.c | 32 ++++++++++++++++++++++++++++---- makefile | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 7707343..24c1346 100644 --- a/main.c +++ b/main.c @@ -1,14 +1,24 @@ #include +#include +#include #include #include #include #include #include -#include +#include #include #include #define BUFLEN 8096 +#define MAX_STEP_CYCLES 20000 + +int sleep_nanos(long int ns) { + struct timespec time; + time.tv_sec = ns / 1000000000; + time.tv_nsec = ns % 1000000000; + return nanosleep(&time, NULL); +} int server(int connfd, VB *sim) { RdbRequest req; @@ -26,6 +36,8 @@ int server(int connfd, VB *sim) { while (1) { CommandBuf cmd; + int brk; + uint32_t cycles; read_result = rdb_request_read(&req, &cmd); if (read_result == read_result_error) { return -1; @@ -34,8 +46,17 @@ int server(int connfd, VB *sim) { return 0; } else if (read_result == read_result_pending) { if (running) { - printf("pretend the emulator is running now\n"); - sleep(1); + /* + cycles = MAX_STEP_CYCLES; + brk = vbEmulate(sim, &cycles); + */ + cycles = 0; + brk = 0; + if (brk) { + /* We hit a breakpoint */ + } else { + sleep_nanos((MAX_STEP_CYCLES - cycles) * 50); + } } continue; } else { @@ -115,7 +136,10 @@ int main(int argc, char** argv) { if (readROM(sim, argv[1])) { return 1; } - vbSetProgramCounter(sim, 0x07000000); + /* relevant state at the start of the physics sim's main */ + vbSetProgramCounter(sim, 0x070002ba); + vbSetProgramRegister(sim, 3, 0x0500ffc0); + vbSetProgramRegister(sim, 4, 0x05008000); if (argc > 2) { char *end; diff --git a/makefile b/makefile index 8bc2214..3719db8 100644 --- a/makefile +++ b/makefile @@ -4,6 +4,7 @@ build: -I include -I ../vbtest \ -Werror -std=c90 -Wall -Wextra -Wpedantic \ -Wno-unused-parameter -Wno-unused-function \ + -D _POSIX_C_SOURCE=199309L \ -o ./build/rdb clean: @rm -rf build