add scaffolding around calling vbEmulate in a loop
This commit is contained in:
parent
ee9a6874d9
commit
8d6f380f6b
32
main.c
32
main.c
|
@ -1,14 +1,24 @@
|
|||
#include <cmdbuf.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <request.h>
|
||||
#include <response.h>
|
||||
#include <server.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <vb.h>
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Reference in New Issue