add scaffolding around calling vbEmulate in a loop

This commit is contained in:
Simon Gellis 2024-10-09 23:13:34 -04:00
parent ee9a6874d9
commit 8d6f380f6b
2 changed files with 29 additions and 4 deletions

32
main.c
View File

@ -1,14 +1,24 @@
#include <cmdbuf.h> #include <cmdbuf.h>
#include <errno.h>
#include <netinet/in.h>
#include <request.h> #include <request.h>
#include <response.h> #include <response.h>
#include <server.h> #include <server.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <netinet/in.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <vb.h> #include <vb.h>
#define BUFLEN 8096 #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) { int server(int connfd, VB *sim) {
RdbRequest req; RdbRequest req;
@ -26,6 +36,8 @@ int server(int connfd, VB *sim) {
while (1) { while (1) {
CommandBuf cmd; CommandBuf cmd;
int brk;
uint32_t cycles;
read_result = rdb_request_read(&req, &cmd); read_result = rdb_request_read(&req, &cmd);
if (read_result == read_result_error) { if (read_result == read_result_error) {
return -1; return -1;
@ -34,8 +46,17 @@ int server(int connfd, VB *sim) {
return 0; return 0;
} else if (read_result == read_result_pending) { } else if (read_result == read_result_pending) {
if (running) { 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; continue;
} else { } else {
@ -115,7 +136,10 @@ int main(int argc, char** argv) {
if (readROM(sim, argv[1])) { if (readROM(sim, argv[1])) {
return 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) { if (argc > 2) {
char *end; char *end;

View File

@ -4,6 +4,7 @@ build:
-I include -I ../vbtest \ -I include -I ../vbtest \
-Werror -std=c90 -Wall -Wextra -Wpedantic \ -Werror -std=c90 -Wall -Wextra -Wpedantic \
-Wno-unused-parameter -Wno-unused-function \ -Wno-unused-parameter -Wno-unused-function \
-D _POSIX_C_SOURCE=199309L \
-o ./build/rdb -o ./build/rdb
clean: clean:
@rm -rf build @rm -rf build