Mercurial > vba-clojure
changeset 22:8870086b716c
remote.cpp must include config.h
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 04 Mar 2012 17:35:30 -0600 |
parents | e0545ef33bb9 |
children | bf9169ad4222 |
files | commands.sh correct.sh src/gba/remote.cpp wrong.sh |
diffstat | 4 files changed, 519 insertions(+), 495 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/commands.sh Sun Mar 04 17:35:30 2012 -0600 1.3 @@ -0,0 +1,9 @@ 1.4 +# This buffer is for notes you don't want to save, and for Lisp evaluation. 1.5 +# If you want to create a file, visit that file with C-x C-f, 1.6 +# then enter the text in that file's own buffer. 1.7 + 1.8 + 1.9 +./VisualBoyAdvance ../../../pokemon-escape/roms/Pokemon\ Yellow\ \(U\)\ \[C\]\[\!\].gbc 1.10 + 1.11 + 1.12 +./VisualBoyAdvance --recordmovie=./rlm.vbm ../../../pokemon-escape/roms/Pokemon\ Yellow\ \(U\)\ \[C\]\[\!\].gbc
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/correct.sh Sun Mar 04 17:35:30 2012 -0600 2.3 @@ -0,0 +1,9 @@ 2.4 +cd ./src/gba 2.5 + 2.6 +g++ -DHAVE_ARPA_INET_H=1 \ 2.7 + -DHAVE_NETINET_IN_H=1 \ 2.8 + -fno-exceptions \ 2.9 + -I. -I../../../src/gba -I../.. -I../../../src \ 2.10 + -g -O2 \ 2.11 + -MT remote.o -MD -MP -MF .deps/remote.Tpo -c \ 2.12 + -o remote.o ../../../src/gba/remote.cpp
3.1 --- a/src/gba/remote.cpp Sun Mar 04 16:56:20 2012 -0600 3.2 +++ b/src/gba/remote.cpp Sun Mar 04 17:35:30 2012 -0600 3.3 @@ -1,6 +1,7 @@ 3.4 #include <cstdlib> 3.5 #include <cstdio> 3.6 #include <cstring> 3.7 +#include <config.h> 3.8 3.9 #ifndef WIN32 3.10 # include <unistd.h> 3.11 @@ -51,150 +52,147 @@ 3.12 #if (defined WIN32 && !defined SDL) 3.13 void remoteSetSockets(SOCKET l, SOCKET r) 3.14 { 3.15 - remoteSocket = r; 3.16 - remoteListenSocket = l; 3.17 + remoteSocket = r; 3.18 + remoteListenSocket = l; 3.19 } 3.20 3.21 #endif 3.22 3.23 int remoteTcpSend(char *data, int len) 3.24 { 3.25 - return send(remoteSocket, data, len, 0); 3.26 + return send(remoteSocket, data, len, 0); 3.27 } 3.28 3.29 int remoteTcpRecv(char *data, int len) 3.30 { 3.31 - return recv(remoteSocket, data, len, 0); 3.32 + return recv(remoteSocket, data, len, 0); 3.33 } 3.34 3.35 bool remoteTcpInit() 3.36 { 3.37 - if (remoteSocket == -1) 3.38 - { 3.39 + if (remoteSocket == -1) 3.40 + { 3.41 #ifdef WIN32 3.42 - WSADATA wsaData; 3.43 - int error = WSAStartup(MAKEWORD(1, 1), &wsaData); 3.44 + WSADATA wsaData; 3.45 + int error = WSAStartup(MAKEWORD(1, 1), &wsaData); 3.46 #endif // WIN32 3.47 - int s = socket(PF_INET, SOCK_STREAM, 0); 3.48 + int s = socket(PF_INET, SOCK_STREAM, 0); 3.49 3.50 - remoteListenSocket = s; 3.51 + remoteListenSocket = s; 3.52 3.53 - if (s < 0) 3.54 - { 3.55 - fprintf(stderr, "Error opening socket\n"); 3.56 - exit(-1); 3.57 - } 3.58 - int tmp = 1; 3.59 - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp)); 3.60 + if (s < 0) 3.61 + { 3.62 + fprintf(stderr, "Error opening socket\n"); 3.63 + exit(-1); 3.64 + } 3.65 + int tmp = 1; 3.66 + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp)); 3.67 3.68 - // char hostname[256]; 3.69 - // gethostname(hostname, 256); 3.70 + // char hostname[256]; 3.71 + // gethostname(hostname, 256); 3.72 3.73 - // hostent *ent = gethostbyname(hostname); 3.74 - // unsigned long a = *((unsigned long *)ent->h_addr); 3.75 + // hostent *ent = gethostbyname(hostname); 3.76 + // unsigned long a = *((unsigned long *)ent->h_addr); 3.77 3.78 - sockaddr_in addr; 3.79 - addr.sin_family = AF_INET; 3.80 - addr.sin_port = htons(remotePort); 3.81 - addr.sin_addr.s_addr = htonl(0); 3.82 - int count = 0; 3.83 - while (count < 3) 3.84 - { 3.85 - if (bind(s, (sockaddr *)&addr, sizeof(addr))) 3.86 - { 3.87 - addr.sin_port = htons(ntohs(addr.sin_port)+1); 3.88 - } 3.89 - else 3.90 - break; 3.91 - } 3.92 - if (count == 3) 3.93 - { 3.94 - fprintf(stderr, "Error binding \n"); 3.95 - exit(-1); 3.96 - } 3.97 + sockaddr_in addr; 3.98 + addr.sin_family = AF_INET; 3.99 + addr.sin_port = htons(remotePort); 3.100 + addr.sin_addr.s_addr = htonl(0); 3.101 + int count = 0; 3.102 + while (count < 3) 3.103 + { 3.104 + if (bind(s, (sockaddr *)&addr, sizeof(addr))) 3.105 + { 3.106 + addr.sin_port = htons(ntohs(addr.sin_port)+1); 3.107 + } 3.108 + else 3.109 + break; 3.110 + } 3.111 + if (count == 3) 3.112 + { 3.113 + fprintf(stderr, "Error binding \n"); 3.114 + exit(-1); 3.115 + } 3.116 3.117 - fprintf(stderr, "Listening for a connection at port %d\n", 3.118 - ntohs(addr.sin_port)); 3.119 + fprintf(stderr, "Listening for a connection at port %d\n", 3.120 + ntohs(addr.sin_port)); 3.121 3.122 - if (listen(s, 1)) 3.123 - { 3.124 - fprintf(stderr, "Error listening\n"); 3.125 - exit(-1); 3.126 - } 3.127 - 3.128 + if (listen(s, 1)) 3.129 + { 3.130 + fprintf(stderr, "Error listening\n"); 3.131 + exit(-1); 3.132 + } 3.133 + socklen_t len = sizeof(addr); 3.134 3.135 #ifdef WIN32 3.136 - int flag = 0; 3.137 - ioctlsocket(s, FIONBIO, (unsigned long *)&flag); 3.138 + int flag = 0; 3.139 + ioctlsocket(s, FIONBIO, (unsigned long *)&flag); 3.140 #endif // WIN32 3.141 - 3.142 - socklen_t len = sizeof(addr); 3.143 - 3.144 - int s2 = accept(s, (sockaddr *)&addr, &len); 3.145 - if (s2 > 0) 3.146 - { 3.147 - fprintf(stderr, "Got a connection from %s %d\n", 3.148 - inet_ntoa((in_addr)addr.sin_addr), 3.149 - ntohs(addr.sin_port)); 3.150 + int s2 = accept(s, (sockaddr *)&addr, &len); 3.151 + if (s2 > 0) 3.152 + { 3.153 + fprintf(stderr, "Got a connection from %s %d\n", 3.154 + inet_ntoa((in_addr)addr.sin_addr), 3.155 + ntohs(addr.sin_port)); 3.156 + } 3.157 + else 3.158 + { 3.159 +#ifdef WIN32 3.160 + int error = WSAGetLastError(); 3.161 +#endif // WIN32 3.162 + } 3.163 + char dummy; 3.164 + recv(s2, &dummy, 1, 0); 3.165 + if (dummy != '+') 3.166 + { 3.167 + fprintf(stderr, "ACK not received\n"); 3.168 + exit(-1); 3.169 + } 3.170 + remoteSocket = s2; 3.171 + // close(s); 3.172 } 3.173 - else 3.174 - { 3.175 -#ifdef WIN32 3.176 - int error = WSAGetLastError(); 3.177 -#endif // WIN32 3.178 - } 3.179 - char dummy; 3.180 - recv(s2, &dummy, 1, 0); 3.181 - if (dummy != '+') 3.182 - { 3.183 - fprintf(stderr, "ACK not received\n"); 3.184 - exit(-1); 3.185 - } 3.186 - remoteSocket = s2; 3.187 - // close(s); 3.188 - } 3.189 - return true; 3.190 + return true; 3.191 } 3.192 3.193 void remoteTcpCleanUp() 3.194 { 3.195 - if (remoteSocket > 0) 3.196 - { 3.197 - fprintf(stderr, "Closing remote socket\n"); 3.198 - close(remoteSocket); 3.199 - remoteSocket = -1; 3.200 - } 3.201 - if (remoteListenSocket > 0) 3.202 - { 3.203 - fprintf(stderr, "Closing listen socket\n"); 3.204 - close(remoteListenSocket); 3.205 - remoteListenSocket = -1; 3.206 - } 3.207 + if (remoteSocket > 0) 3.208 + { 3.209 + fprintf(stderr, "Closing remote socket\n"); 3.210 + close(remoteSocket); 3.211 + remoteSocket = -1; 3.212 + } 3.213 + if (remoteListenSocket > 0) 3.214 + { 3.215 + fprintf(stderr, "Closing listen socket\n"); 3.216 + close(remoteListenSocket); 3.217 + remoteListenSocket = -1; 3.218 + } 3.219 } 3.220 3.221 int remotePipeSend(char *data, int len) 3.222 { 3.223 - int res = write(1, data, len); 3.224 - return res; 3.225 + int res = write(1, data, len); 3.226 + return res; 3.227 } 3.228 3.229 int remotePipeRecv(char *data, int len) 3.230 { 3.231 - int res = read(0, data, len); 3.232 - return res; 3.233 + int res = read(0, data, len); 3.234 + return res; 3.235 } 3.236 3.237 bool remotePipeInit() 3.238 { 3.239 - char dummy; 3.240 - read(0, &dummy, 1); 3.241 - if (dummy != '+') 3.242 - { 3.243 - fprintf(stderr, "ACK not received\n"); 3.244 - exit(-1); 3.245 - } 3.246 + char dummy; 3.247 + read(0, &dummy, 1); 3.248 + if (dummy != '+') 3.249 + { 3.250 + fprintf(stderr, "ACK not received\n"); 3.251 + exit(-1); 3.252 + } 3.253 3.254 - return true; 3.255 + return true; 3.256 } 3.257 3.258 void remotePipeCleanUp() 3.259 @@ -202,514 +200,514 @@ 3.260 3.261 void remoteSetPort(int port) 3.262 { 3.263 - remotePort = port; 3.264 + remotePort = port; 3.265 } 3.266 3.267 void remoteSetProtocol(int p) 3.268 { 3.269 - if (p == 0) 3.270 - { 3.271 - remoteSendFnc = remoteTcpSend; 3.272 - remoteRecvFnc = remoteTcpRecv; 3.273 - remoteInitFnc = remoteTcpInit; 3.274 - remoteCleanUpFnc = remoteTcpCleanUp; 3.275 - } 3.276 - else 3.277 - { 3.278 - remoteSendFnc = remotePipeSend; 3.279 - remoteRecvFnc = remotePipeRecv; 3.280 - remoteInitFnc = remotePipeInit; 3.281 - remoteCleanUpFnc = remotePipeCleanUp; 3.282 - } 3.283 + if (p == 0) 3.284 + { 3.285 + remoteSendFnc = remoteTcpSend; 3.286 + remoteRecvFnc = remoteTcpRecv; 3.287 + remoteInitFnc = remoteTcpInit; 3.288 + remoteCleanUpFnc = remoteTcpCleanUp; 3.289 + } 3.290 + else 3.291 + { 3.292 + remoteSendFnc = remotePipeSend; 3.293 + remoteRecvFnc = remotePipeRecv; 3.294 + remoteInitFnc = remotePipeInit; 3.295 + remoteCleanUpFnc = remotePipeCleanUp; 3.296 + } 3.297 } 3.298 3.299 void remoteInit() 3.300 { 3.301 - if (remoteInitFnc) 3.302 - remoteInitFnc(); 3.303 + if (remoteInitFnc) 3.304 + remoteInitFnc(); 3.305 } 3.306 3.307 void remotePutPacket(char *packet) 3.308 { 3.309 - char *hex = "0123456789abcdef"; 3.310 - char buffer[1024]; 3.311 + char *hex = "0123456789abcdef"; 3.312 + char buffer[1024]; 3.313 3.314 - int count = strlen(packet); 3.315 + int count = strlen(packet); 3.316 3.317 - unsigned char csum = 0; 3.318 + unsigned char csum = 0; 3.319 3.320 - char *p = buffer; 3.321 - *p++ = '$'; 3.322 + char *p = buffer; 3.323 + *p++ = '$'; 3.324 3.325 - for (int i = 0; i < count; i++) 3.326 - { 3.327 - csum += packet[i]; 3.328 - *p++ = packet[i]; 3.329 - } 3.330 - *p++ = '#'; 3.331 - *p++ = hex[csum>>4]; 3.332 - *p++ = hex[csum & 15]; 3.333 - *p++ = 0; 3.334 - // printf("Sending %s\n", buffer); 3.335 - remoteSendFnc(buffer, count + 4); 3.336 + for (int i = 0; i < count; i++) 3.337 + { 3.338 + csum += packet[i]; 3.339 + *p++ = packet[i]; 3.340 + } 3.341 + *p++ = '#'; 3.342 + *p++ = hex[csum>>4]; 3.343 + *p++ = hex[csum & 15]; 3.344 + *p++ = 0; 3.345 + // printf("Sending %s\n", buffer); 3.346 + remoteSendFnc(buffer, count + 4); 3.347 3.348 - char c = 0; 3.349 - remoteRecvFnc(&c, 1); 3.350 - /* 3.351 - if(c == '+') 3.352 - printf("ACK\n"); 3.353 - else if(c=='-') 3.354 - printf("NACK\n"); 3.355 - */ 3.356 + char c = 0; 3.357 + remoteRecvFnc(&c, 1); 3.358 + /* 3.359 + if(c == '+') 3.360 + printf("ACK\n"); 3.361 + else if(c=='-') 3.362 + printf("NACK\n"); 3.363 + */ 3.364 } 3.365 3.366 void remoteOutput(char *s, u32 addr) 3.367 { 3.368 - char buffer[16384]; 3.369 + char buffer[16384]; 3.370 3.371 - char *d = buffer; 3.372 - *d++ = 'O'; 3.373 + char *d = buffer; 3.374 + *d++ = 'O'; 3.375 3.376 - if (s) 3.377 - { 3.378 - char c = *s++; 3.379 - while (c) 3.380 + if (s) 3.381 { 3.382 - sprintf(d, "%02x", c); 3.383 - d += 2; 3.384 - c = *s++; 3.385 + char c = *s++; 3.386 + while (c) 3.387 + { 3.388 + sprintf(d, "%02x", c); 3.389 + d += 2; 3.390 + c = *s++; 3.391 + } 3.392 } 3.393 - } 3.394 - else 3.395 - { 3.396 - char c = debuggerReadByte(addr); 3.397 - addr++; 3.398 - while (c) 3.399 + else 3.400 { 3.401 - sprintf(d, "%02x", c); 3.402 - d += 2; 3.403 - c = debuggerReadByte(addr); 3.404 - addr++; 3.405 + char c = debuggerReadByte(addr); 3.406 + addr++; 3.407 + while (c) 3.408 + { 3.409 + sprintf(d, "%02x", c); 3.410 + d += 2; 3.411 + c = debuggerReadByte(addr); 3.412 + addr++; 3.413 + } 3.414 } 3.415 - } 3.416 - remotePutPacket(buffer); 3.417 - // fprintf(stderr, "Output sent %s\n", buffer); 3.418 + remotePutPacket(buffer); 3.419 + // fprintf(stderr, "Output sent %s\n", buffer); 3.420 } 3.421 3.422 void remoteSendSignal() 3.423 { 3.424 - char buffer[1024]; 3.425 - sprintf(buffer, "S%02x", remoteSignal); 3.426 - remotePutPacket(buffer); 3.427 + char buffer[1024]; 3.428 + sprintf(buffer, "S%02x", remoteSignal); 3.429 + remotePutPacket(buffer); 3.430 } 3.431 3.432 void remoteSendStatus() 3.433 { 3.434 - char buffer[1024]; 3.435 - sprintf(buffer, "T%02x", remoteSignal); 3.436 - char *s = buffer; 3.437 - s += 3; 3.438 - for (int i = 0; i < 15; i++) 3.439 - { 3.440 - u32 v = reg[i].I; 3.441 - sprintf(s, "%02x:%02x%02x%02x%02x;", i, 3.442 - (v & 255), 3.443 - (v >> 8) & 255, 3.444 - (v >> 16) & 255, 3.445 - (v >> 24) & 255); 3.446 - s += 12; 3.447 - } 3.448 - u32 v = armNextPC; 3.449 - sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255), 3.450 - (v >> 8) & 255, 3.451 - (v >> 16) & 255, 3.452 - (v >> 24) & 255); 3.453 - s += 12; 3.454 - CPUUpdateCPSR(); 3.455 - v = reg[16].I; 3.456 - sprintf(s, "19:%02x%02x%02x%02x;", (v & 255), 3.457 - (v >> 8) & 255, 3.458 - (v >> 16) & 255, 3.459 - (v >> 24) & 255); 3.460 - s += 12; 3.461 - *s = 0; 3.462 - // printf("Sending %s\n", buffer); 3.463 - remotePutPacket(buffer); 3.464 + char buffer[1024]; 3.465 + sprintf(buffer, "T%02x", remoteSignal); 3.466 + char *s = buffer; 3.467 + s += 3; 3.468 + for (int i = 0; i < 15; i++) 3.469 + { 3.470 + u32 v = reg[i].I; 3.471 + sprintf(s, "%02x:%02x%02x%02x%02x;", i, 3.472 + (v & 255), 3.473 + (v >> 8) & 255, 3.474 + (v >> 16) & 255, 3.475 + (v >> 24) & 255); 3.476 + s += 12; 3.477 + } 3.478 + u32 v = armNextPC; 3.479 + sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255), 3.480 + (v >> 8) & 255, 3.481 + (v >> 16) & 255, 3.482 + (v >> 24) & 255); 3.483 + s += 12; 3.484 + CPUUpdateCPSR(); 3.485 + v = reg[16].I; 3.486 + sprintf(s, "19:%02x%02x%02x%02x;", (v & 255), 3.487 + (v >> 8) & 255, 3.488 + (v >> 16) & 255, 3.489 + (v >> 24) & 255); 3.490 + s += 12; 3.491 + *s = 0; 3.492 + // printf("Sending %s\n", buffer); 3.493 + remotePutPacket(buffer); 3.494 } 3.495 3.496 void remoteBinaryWrite(char *p) 3.497 { 3.498 - u32 address; 3.499 - int count; 3.500 - sscanf(p, "%x,%x:", &address, &count); 3.501 - // printf("Binary write for %08x %d\n", address, count); 3.502 + u32 address; 3.503 + int count; 3.504 + sscanf(p, "%x,%x:", &address, &count); 3.505 + // printf("Binary write for %08x %d\n", address, count); 3.506 3.507 - p = strchr(p, ':'); 3.508 - p++; 3.509 - for (int i = 0; i < count; i++) 3.510 - { 3.511 - u8 b = *p++; 3.512 - switch (b) 3.513 + p = strchr(p, ':'); 3.514 + p++; 3.515 + for (int i = 0; i < count; i++) 3.516 { 3.517 - case 0x7d: 3.518 - b = *p++; 3.519 - debuggerWriteByte(address, (b^0x20)); 3.520 - address++; 3.521 - break; 3.522 - default: 3.523 - debuggerWriteByte(address, b); 3.524 - address++; 3.525 - break; 3.526 + u8 b = *p++; 3.527 + switch (b) 3.528 + { 3.529 + case 0x7d: 3.530 + b = *p++; 3.531 + debuggerWriteByte(address, (b^0x20)); 3.532 + address++; 3.533 + break; 3.534 + default: 3.535 + debuggerWriteByte(address, b); 3.536 + address++; 3.537 + break; 3.538 + } 3.539 } 3.540 - } 3.541 - // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); 3.542 - remotePutPacket("OK"); 3.543 + // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); 3.544 + remotePutPacket("OK"); 3.545 } 3.546 3.547 void remoteMemoryWrite(char *p) 3.548 { 3.549 - u32 address; 3.550 - int count; 3.551 - sscanf(p, "%x,%x:", &address, &count); 3.552 - // printf("Memory write for %08x %d\n", address, count); 3.553 + u32 address; 3.554 + int count; 3.555 + sscanf(p, "%x,%x:", &address, &count); 3.556 + // printf("Memory write for %08x %d\n", address, count); 3.557 3.558 - p = strchr(p, ':'); 3.559 - p++; 3.560 - for (int i = 0; i < count; i++) 3.561 - { 3.562 - u8 v = 0; 3.563 - char c = *p++; 3.564 - if (c <= '9') 3.565 - v = (c - '0') << 4; 3.566 - else 3.567 - v = (c + 10 - 'a') << 4; 3.568 - c = *p++; 3.569 - if (c <= '9') 3.570 - v += (c - '0'); 3.571 - else 3.572 - v += (c + 10 - 'a'); 3.573 - debuggerWriteByte(address, v); 3.574 - address++; 3.575 - } 3.576 - // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); 3.577 - remotePutPacket("OK"); 3.578 + p = strchr(p, ':'); 3.579 + p++; 3.580 + for (int i = 0; i < count; i++) 3.581 + { 3.582 + u8 v = 0; 3.583 + char c = *p++; 3.584 + if (c <= '9') 3.585 + v = (c - '0') << 4; 3.586 + else 3.587 + v = (c + 10 - 'a') << 4; 3.588 + c = *p++; 3.589 + if (c <= '9') 3.590 + v += (c - '0'); 3.591 + else 3.592 + v += (c + 10 - 'a'); 3.593 + debuggerWriteByte(address, v); 3.594 + address++; 3.595 + } 3.596 + // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); 3.597 + remotePutPacket("OK"); 3.598 } 3.599 3.600 void remoteMemoryRead(char *p) 3.601 { 3.602 - u32 address; 3.603 - int count; 3.604 - sscanf(p, "%x,%x:", &address, &count); 3.605 - // printf("Memory read for %08x %d\n", address, count); 3.606 + u32 address; 3.607 + int count; 3.608 + sscanf(p, "%x,%x:", &address, &count); 3.609 + // printf("Memory read for %08x %d\n", address, count); 3.610 3.611 - char buffer[1024]; 3.612 + char buffer[1024]; 3.613 3.614 - char *s = buffer; 3.615 - for (int i = 0; i < count; i++) 3.616 - { 3.617 - u8 b = debuggerReadByte(address); 3.618 - sprintf(s, "%02x", b); 3.619 - address++; 3.620 - s += 2; 3.621 - } 3.622 - *s = 0; 3.623 - remotePutPacket(buffer); 3.624 + char *s = buffer; 3.625 + for (int i = 0; i < count; i++) 3.626 + { 3.627 + u8 b = debuggerReadByte(address); 3.628 + sprintf(s, "%02x", b); 3.629 + address++; 3.630 + s += 2; 3.631 + } 3.632 + *s = 0; 3.633 + remotePutPacket(buffer); 3.634 } 3.635 3.636 void remoteStepOverRange(char *p) 3.637 { 3.638 - u32 address; 3.639 - u32 final; 3.640 - sscanf(p, "%x,%x", &address, &final); 3.641 + u32 address; 3.642 + u32 final; 3.643 + sscanf(p, "%x,%x", &address, &final); 3.644 3.645 - remotePutPacket("OK"); 3.646 + remotePutPacket("OK"); 3.647 3.648 - remoteResumed = true; 3.649 - do 3.650 - { 3.651 - CPULoop(1); 3.652 - if (debugger) 3.653 - break; 3.654 - } 3.655 - while (armNextPC >= address && armNextPC < final); 3.656 + remoteResumed = true; 3.657 + do 3.658 + { 3.659 + CPULoop(1); 3.660 + if (debugger) 3.661 + break; 3.662 + } 3.663 + while (armNextPC >= address && armNextPC < final); 3.664 3.665 - remoteResumed = false; 3.666 + remoteResumed = false; 3.667 3.668 - remoteSendStatus(); 3.669 + remoteSendStatus(); 3.670 } 3.671 3.672 void remoteWriteWatch(char *p, bool active) 3.673 { 3.674 - u32 address; 3.675 - int count; 3.676 - sscanf(p, ",%x,%x#", &address, &count); 3.677 + u32 address; 3.678 + int count; 3.679 + sscanf(p, ",%x,%x#", &address, &count); 3.680 3.681 - fprintf(stderr, "Write watch for %08x %d\n", address, count); 3.682 + fprintf(stderr, "Write watch for %08x %d\n", address, count); 3.683 3.684 - if (address < 0x2000000 || address > 0x3007fff) 3.685 - { 3.686 - remotePutPacket("E01"); 3.687 - return; 3.688 - } 3.689 + if (address < 0x2000000 || address > 0x3007fff) 3.690 + { 3.691 + remotePutPacket("E01"); 3.692 + return; 3.693 + } 3.694 3.695 - if (address > 0x203ffff && address < 0x3000000) 3.696 - { 3.697 - remotePutPacket("E01"); 3.698 - return; 3.699 - } 3.700 + if (address > 0x203ffff && address < 0x3000000) 3.701 + { 3.702 + remotePutPacket("E01"); 3.703 + return; 3.704 + } 3.705 3.706 - u32 final = address + count; 3.707 + u32 final = address + count; 3.708 3.709 - if (address < 0x2040000 && final > 0x2040000) 3.710 - { 3.711 - remotePutPacket("E01"); 3.712 - return; 3.713 - } 3.714 - else if (address < 0x3008000 && final > 0x3008000) 3.715 - { 3.716 - remotePutPacket("E01"); 3.717 - return; 3.718 - } 3.719 + if (address < 0x2040000 && final > 0x2040000) 3.720 + { 3.721 + remotePutPacket("E01"); 3.722 + return; 3.723 + } 3.724 + else if (address < 0x3008000 && final > 0x3008000) 3.725 + { 3.726 + remotePutPacket("E01"); 3.727 + return; 3.728 + } 3.729 3.730 - for (int i = 0; i < count; i++) 3.731 - { 3.732 - if ((address >> 24) == 2) 3.733 - freezeWorkRAM[address & 0x3ffff] = active; 3.734 - else 3.735 - freezeInternalRAM[address & 0x7fff] = active; 3.736 - address++; 3.737 - } 3.738 + for (int i = 0; i < count; i++) 3.739 + { 3.740 + if ((address >> 24) == 2) 3.741 + freezeWorkRAM[address & 0x3ffff] = active; 3.742 + else 3.743 + freezeInternalRAM[address & 0x7fff] = active; 3.744 + address++; 3.745 + } 3.746 3.747 - remotePutPacket("OK"); 3.748 + remotePutPacket("OK"); 3.749 } 3.750 3.751 void remoteReadRegisters(char *p) 3.752 { 3.753 - char buffer[1024]; 3.754 + char buffer[1024]; 3.755 3.756 - char *s = buffer; 3.757 - int i; 3.758 - // regular registers 3.759 - for (i = 0; i < 15; i++) 3.760 - { 3.761 - u32 v = reg[i].I; 3.762 - sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255, 3.763 - (v >> 16) & 255, (v >> 24) & 255); 3.764 - s += 8; 3.765 - } 3.766 - // PC 3.767 - u32 pc = armNextPC; 3.768 - sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255, 3.769 - (pc >> 16) & 255, (pc >> 24) & 255); 3.770 - s += 8; 3.771 + char *s = buffer; 3.772 + int i; 3.773 + // regular registers 3.774 + for (i = 0; i < 15; i++) 3.775 + { 3.776 + u32 v = reg[i].I; 3.777 + sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255, 3.778 + (v >> 16) & 255, (v >> 24) & 255); 3.779 + s += 8; 3.780 + } 3.781 + // PC 3.782 + u32 pc = armNextPC; 3.783 + sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255, 3.784 + (pc >> 16) & 255, (pc >> 24) & 255); 3.785 + s += 8; 3.786 3.787 - // floating point registers (24-bit) 3.788 - for (i = 0; i < 8; i++) 3.789 - { 3.790 - sprintf(s, "000000000000000000000000"); 3.791 - s += 24; 3.792 - } 3.793 + // floating point registers (24-bit) 3.794 + for (i = 0; i < 8; i++) 3.795 + { 3.796 + sprintf(s, "000000000000000000000000"); 3.797 + s += 24; 3.798 + } 3.799 3.800 - // FP status register 3.801 - sprintf(s, "00000000"); 3.802 - s += 8; 3.803 - // CPSR 3.804 - CPUUpdateCPSR(); 3.805 - u32 v = reg[16].I; 3.806 - sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255, 3.807 - (v >> 16) & 255, (v >> 24) & 255); 3.808 - s += 8; 3.809 - *s = 0; 3.810 - remotePutPacket(buffer); 3.811 + // FP status register 3.812 + sprintf(s, "00000000"); 3.813 + s += 8; 3.814 + // CPSR 3.815 + CPUUpdateCPSR(); 3.816 + u32 v = reg[16].I; 3.817 + sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255, 3.818 + (v >> 16) & 255, (v >> 24) & 255); 3.819 + s += 8; 3.820 + *s = 0; 3.821 + remotePutPacket(buffer); 3.822 } 3.823 3.824 void remoteWriteRegister(char *p) 3.825 { 3.826 - int r; 3.827 + int r; 3.828 3.829 - sscanf(p, "%x=", &r); 3.830 + sscanf(p, "%x=", &r); 3.831 3.832 - p = strchr(p, '='); 3.833 - p++; 3.834 + p = strchr(p, '='); 3.835 + p++; 3.836 3.837 - char c = *p++; 3.838 + char c = *p++; 3.839 3.840 - u32 v = 0; 3.841 + u32 v = 0; 3.842 3.843 - u8 data[4] = {0, 0, 0, 0}; 3.844 + u8 data[4] = {0, 0, 0, 0}; 3.845 3.846 - int i = 0; 3.847 + int i = 0; 3.848 3.849 - while (c != '#') 3.850 - { 3.851 - u8 b = 0; 3.852 - if (c <= '9') 3.853 - b = (c - '0') << 4; 3.854 - else 3.855 - b = (c + 10 - 'a') << 4; 3.856 - c = *p++; 3.857 - if (c <= '9') 3.858 - b += (c - '0'); 3.859 - else 3.860 - b += (c + 10 - 'a'); 3.861 - data[i++] = b; 3.862 - c = *p++; 3.863 - } 3.864 + while (c != '#') 3.865 + { 3.866 + u8 b = 0; 3.867 + if (c <= '9') 3.868 + b = (c - '0') << 4; 3.869 + else 3.870 + b = (c + 10 - 'a') << 4; 3.871 + c = *p++; 3.872 + if (c <= '9') 3.873 + b += (c - '0'); 3.874 + else 3.875 + b += (c + 10 - 'a'); 3.876 + data[i++] = b; 3.877 + c = *p++; 3.878 + } 3.879 3.880 - v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); 3.881 + v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); 3.882 3.883 - // printf("Write register %d=%08x\n", r, v); 3.884 - reg[r].I = v; 3.885 - if (r == 15) 3.886 - { 3.887 - armNextPC = v; 3.888 - if (armState) 3.889 - reg[15].I = v + 4; 3.890 - else 3.891 - reg[15].I = v + 2; 3.892 - } 3.893 - remotePutPacket("OK"); 3.894 + // printf("Write register %d=%08x\n", r, v); 3.895 + reg[r].I = v; 3.896 + if (r == 15) 3.897 + { 3.898 + armNextPC = v; 3.899 + if (armState) 3.900 + reg[15].I = v + 4; 3.901 + else 3.902 + reg[15].I = v + 2; 3.903 + } 3.904 + remotePutPacket("OK"); 3.905 } 3.906 3.907 void remoteStubMain() 3.908 { 3.909 - if (!debugger) 3.910 - return; 3.911 + if (!debugger) 3.912 + return; 3.913 3.914 - if (remoteResumed) 3.915 - { 3.916 - remoteSendStatus(); 3.917 - remoteResumed = false; 3.918 - } 3.919 - 3.920 - while (true) 3.921 - { 3.922 - char buffer[1024]; 3.923 - int res = remoteRecvFnc(buffer, 1024); 3.924 - 3.925 - if (res == -1) 3.926 + if (remoteResumed) 3.927 { 3.928 - fprintf(stderr, "GDB connection lost\n"); 3.929 -#ifdef SDL 3.930 - dbgMain = debuggerMain; 3.931 - dbgSignal = debuggerSignal; 3.932 -#endif 3.933 - debugger = false; 3.934 - break; 3.935 + remoteSendStatus(); 3.936 + remoteResumed = false; 3.937 } 3.938 3.939 - // fprintf(stderr, "Received %s\n", buffer); 3.940 - char *p = buffer; 3.941 - char c = *p++; 3.942 - char pp = '+'; 3.943 - remoteSendFnc(&pp, 1); 3.944 + while (true) 3.945 + { 3.946 + char buffer[1024]; 3.947 + int res = remoteRecvFnc(buffer, 1024); 3.948 3.949 - if (c != '$') 3.950 - continue; 3.951 - c = *p++; 3.952 - switch (c) 3.953 - { 3.954 - case '?': 3.955 - remoteSendSignal(); 3.956 - break; 3.957 - case 'D': 3.958 - remotePutPacket("OK"); 3.959 + if (res == -1) 3.960 + { 3.961 + fprintf(stderr, "GDB connection lost\n"); 3.962 #ifdef SDL 3.963 - dbgMain = debuggerMain; 3.964 - dbgSignal = debuggerSignal; 3.965 + dbgMain = debuggerMain; 3.966 + dbgSignal = debuggerSignal; 3.967 #endif 3.968 - remoteResumed = true; 3.969 - debugger = false; 3.970 - return; 3.971 - case 'e': 3.972 - remoteStepOverRange(p); 3.973 - break; 3.974 - case 'k': 3.975 - remotePutPacket("OK"); 3.976 + debugger = false; 3.977 + break; 3.978 + } 3.979 + 3.980 + // fprintf(stderr, "Received %s\n", buffer); 3.981 + char *p = buffer; 3.982 + char c = *p++; 3.983 + char pp = '+'; 3.984 + remoteSendFnc(&pp, 1); 3.985 + 3.986 + if (c != '$') 3.987 + continue; 3.988 + c = *p++; 3.989 + switch (c) 3.990 + { 3.991 + case '?': 3.992 + remoteSendSignal(); 3.993 + break; 3.994 + case 'D': 3.995 + remotePutPacket("OK"); 3.996 #ifdef SDL 3.997 - dbgMain = debuggerMain; 3.998 - dbgSignal = debuggerSignal; 3.999 + dbgMain = debuggerMain; 3.1000 + dbgSignal = debuggerSignal; 3.1001 #endif 3.1002 - debugger = false; 3.1003 - emulating = false; 3.1004 - return; 3.1005 - case 'C': 3.1006 - remoteResumed = true; 3.1007 - debugger = false; 3.1008 - return; 3.1009 - case 'c': 3.1010 - remoteResumed = true; 3.1011 - debugger = false; 3.1012 - return; 3.1013 - case 's': 3.1014 - remoteResumed = true; 3.1015 - remoteSignal = 5; 3.1016 - CPULoop(1); 3.1017 - if (remoteResumed) 3.1018 - { 3.1019 - remoteResumed = false; 3.1020 - remoteSendStatus(); 3.1021 - } 3.1022 - break; 3.1023 - case 'g': 3.1024 - remoteReadRegisters(p); 3.1025 - break; 3.1026 - case 'P': 3.1027 - remoteWriteRegister(p); 3.1028 - break; 3.1029 - case 'M': 3.1030 - remoteMemoryWrite(p); 3.1031 - break; 3.1032 - case 'm': 3.1033 - remoteMemoryRead(p); 3.1034 - break; 3.1035 - case 'X': 3.1036 - remoteBinaryWrite(p); 3.1037 - break; 3.1038 - case 'H': 3.1039 - remotePutPacket("OK"); 3.1040 - break; 3.1041 - case 'q': 3.1042 - remotePutPacket(""); 3.1043 - break; 3.1044 - case 'Z': 3.1045 - if (*p++ == '2') 3.1046 - { 3.1047 - remoteWriteWatch(p, true); 3.1048 - } 3.1049 - else 3.1050 - remotePutPacket(""); 3.1051 - break; 3.1052 - case 'z': 3.1053 - if (*p++ == '2') 3.1054 - { 3.1055 - remoteWriteWatch(p, false); 3.1056 - } 3.1057 - else 3.1058 - remotePutPacket(""); 3.1059 - break; 3.1060 - default: 3.1061 - { 3.1062 - *(strchr(p, '#') + 3) = 0; 3.1063 - fprintf(stderr, "Unknown packet %s\n", --p); 3.1064 - remotePutPacket(""); 3.1065 - break; 3.1066 - } 3.1067 + remoteResumed = true; 3.1068 + debugger = false; 3.1069 + return; 3.1070 + case 'e': 3.1071 + remoteStepOverRange(p); 3.1072 + break; 3.1073 + case 'k': 3.1074 + remotePutPacket("OK"); 3.1075 +#ifdef SDL 3.1076 + dbgMain = debuggerMain; 3.1077 + dbgSignal = debuggerSignal; 3.1078 +#endif 3.1079 + debugger = false; 3.1080 + emulating = false; 3.1081 + return; 3.1082 + case 'C': 3.1083 + remoteResumed = true; 3.1084 + debugger = false; 3.1085 + return; 3.1086 + case 'c': 3.1087 + remoteResumed = true; 3.1088 + debugger = false; 3.1089 + return; 3.1090 + case 's': 3.1091 + remoteResumed = true; 3.1092 + remoteSignal = 5; 3.1093 + CPULoop(1); 3.1094 + if (remoteResumed) 3.1095 + { 3.1096 + remoteResumed = false; 3.1097 + remoteSendStatus(); 3.1098 + } 3.1099 + break; 3.1100 + case 'g': 3.1101 + remoteReadRegisters(p); 3.1102 + break; 3.1103 + case 'P': 3.1104 + remoteWriteRegister(p); 3.1105 + break; 3.1106 + case 'M': 3.1107 + remoteMemoryWrite(p); 3.1108 + break; 3.1109 + case 'm': 3.1110 + remoteMemoryRead(p); 3.1111 + break; 3.1112 + case 'X': 3.1113 + remoteBinaryWrite(p); 3.1114 + break; 3.1115 + case 'H': 3.1116 + remotePutPacket("OK"); 3.1117 + break; 3.1118 + case 'q': 3.1119 + remotePutPacket(""); 3.1120 + break; 3.1121 + case 'Z': 3.1122 + if (*p++ == '2') 3.1123 + { 3.1124 + remoteWriteWatch(p, true); 3.1125 + } 3.1126 + else 3.1127 + remotePutPacket(""); 3.1128 + break; 3.1129 + case 'z': 3.1130 + if (*p++ == '2') 3.1131 + { 3.1132 + remoteWriteWatch(p, false); 3.1133 + } 3.1134 + else 3.1135 + remotePutPacket(""); 3.1136 + break; 3.1137 + default: 3.1138 + { 3.1139 + *(strchr(p, '#') + 3) = 0; 3.1140 + fprintf(stderr, "Unknown packet %s\n", --p); 3.1141 + remotePutPacket(""); 3.1142 + break; 3.1143 + } 3.1144 + } 3.1145 } 3.1146 - } 3.1147 } 3.1148 3.1149 void remoteStubSignal(int sig, int number) 3.1150 { 3.1151 - remoteSignal = sig; 3.1152 - remoteResumed = false; 3.1153 - remoteSendStatus(); 3.1154 - debugger = true; 3.1155 + remoteSignal = sig; 3.1156 + remoteResumed = false; 3.1157 + remoteSendStatus(); 3.1158 + debugger = true; 3.1159 } 3.1160 3.1161 void remoteCleanUp() 3.1162 { 3.1163 - if (remoteCleanUpFnc) 3.1164 - remoteCleanUpFnc(); 3.1165 + if (remoteCleanUpFnc) 3.1166 + remoteCleanUpFnc(); 3.1167 } 3.1168
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/wrong.sh Sun Mar 04 17:35:30 2012 -0600 4.3 @@ -0,0 +1,8 @@ 4.4 +cd ./src/gba 4.5 + 4.6 +g++ -DHAVE_CONFIG_H \ 4.7 + -I. -I../../../src/gba -I../.. -I../../../src \ 4.8 + -DSDL -DSYSCONFDIR=\"/usr/local/etc\" \ 4.9 + -fno-exceptions -g -O2 \ 4.10 + -MT remote.o -MD -MP -MF .deps/remote.Tpo -c \ 4.11 + -o remote.o ../../../src/gba/remote.cpp