diff src/gba/remote.cpp @ 20:ecd30c5e2f5a

fix indentation for remote.cpp
author Robert McIntyre <rlm@mit.edu>
date Sun, 04 Mar 2012 14:35:54 -0600
parents f9f4f1b99eed
children e0545ef33bb9
line wrap: on
line diff
     1.1 --- a/src/gba/remote.cpp	Sun Mar 04 14:33:52 2012 -0600
     1.2 +++ b/src/gba/remote.cpp	Sun Mar 04 14:35:54 2012 -0600
     1.3 @@ -51,147 +51,147 @@
     1.4  #if (defined WIN32 && !defined SDL)
     1.5  void remoteSetSockets(SOCKET l, SOCKET r)
     1.6  {
     1.7 -	remoteSocket       = r;
     1.8 -	remoteListenSocket = l;
     1.9 +  remoteSocket       = r;
    1.10 +  remoteListenSocket = l;
    1.11  }
    1.12  
    1.13  #endif
    1.14  
    1.15  int remoteTcpSend(char *data, int len)
    1.16  {
    1.17 -	return send(remoteSocket, data, len, 0);
    1.18 +  return send(remoteSocket, data, len, 0);
    1.19  }
    1.20  
    1.21  int remoteTcpRecv(char *data, int len)
    1.22  {
    1.23 -	return recv(remoteSocket, data, len, 0);
    1.24 +  return recv(remoteSocket, data, len, 0);
    1.25  }
    1.26  
    1.27  bool remoteTcpInit()
    1.28  {
    1.29 -	if (remoteSocket == -1)
    1.30 +  if (remoteSocket == -1)
    1.31 +    {
    1.32 +#ifdef WIN32
    1.33 +      WSADATA wsaData;
    1.34 +      int     error = WSAStartup(MAKEWORD(1, 1), &wsaData);
    1.35 +#endif // WIN32
    1.36 +      int s = socket(PF_INET, SOCK_STREAM, 0);
    1.37 +
    1.38 +      remoteListenSocket = s;
    1.39 +
    1.40 +      if (s < 0)
    1.41 +	{
    1.42 +	  fprintf(stderr, "Error opening socket\n");
    1.43 +	  exit(-1);
    1.44 +	}
    1.45 +      int tmp = 1;
    1.46 +      setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp));
    1.47 +
    1.48 +      //    char hostname[256];
    1.49 +      //    gethostname(hostname, 256);
    1.50 +
    1.51 +      //    hostent *ent = gethostbyname(hostname);
    1.52 +      //    unsigned long a = *((unsigned long *)ent->h_addr);
    1.53 +
    1.54 +      sockaddr_in addr;
    1.55 +      addr.sin_family      = AF_INET;
    1.56 +      addr.sin_port        = htons(remotePort);
    1.57 +      addr.sin_addr.s_addr = htonl(0);
    1.58 +      int count = 0;
    1.59 +      while (count < 3)
    1.60 +	{
    1.61 +	  if (bind(s, (sockaddr *)&addr, sizeof(addr)))
    1.62 +	    {
    1.63 +	      addr.sin_port = htons(ntohs(addr.sin_port)+1);
    1.64 +	    }
    1.65 +	  else
    1.66 +	    break;
    1.67 +	}
    1.68 +      if (count == 3)
    1.69 +	{
    1.70 +	  fprintf(stderr, "Error binding \n");
    1.71 +	  exit(-1);
    1.72 +	}
    1.73 +
    1.74 +      fprintf(stderr, "Listening for a connection at port %d\n",
    1.75 +	      ntohs(addr.sin_port));
    1.76 +
    1.77 +      if (listen(s, 1))
    1.78 +	{
    1.79 +	  fprintf(stderr, "Error listening\n");
    1.80 +	  exit(-1);
    1.81 +	}
    1.82 +      socklen_t len = sizeof(addr);
    1.83 +
    1.84 +#ifdef WIN32
    1.85 +      int flag = 0;
    1.86 +      ioctlsocket(s, FIONBIO, (unsigned long *)&flag);
    1.87 +#endif // WIN32
    1.88 +      int s2 = accept(s, (sockaddr *)&addr, &len);
    1.89 +      if (s2 > 0)
    1.90 +	{
    1.91 +	  fprintf(stderr, "Got a connection from %s %d\n",
    1.92 +		  inet_ntoa((in_addr)addr.sin_addr),
    1.93 +		  ntohs(addr.sin_port));
    1.94 +	}
    1.95 +      else
    1.96  	{
    1.97  #ifdef WIN32
    1.98 -		WSADATA wsaData;
    1.99 -		int     error = WSAStartup(MAKEWORD(1, 1), &wsaData);
   1.100 +	  int error = WSAGetLastError();
   1.101  #endif // WIN32
   1.102 -		int s = socket(PF_INET, SOCK_STREAM, 0);
   1.103 -
   1.104 -		remoteListenSocket = s;
   1.105 -
   1.106 -		if (s < 0)
   1.107 -		{
   1.108 -			fprintf(stderr, "Error opening socket\n");
   1.109 -			exit(-1);
   1.110 -		}
   1.111 -		int tmp = 1;
   1.112 -		setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof(tmp));
   1.113 -
   1.114 -		//    char hostname[256];
   1.115 -		//    gethostname(hostname, 256);
   1.116 -
   1.117 -		//    hostent *ent = gethostbyname(hostname);
   1.118 -		//    unsigned long a = *((unsigned long *)ent->h_addr);
   1.119 -
   1.120 -		sockaddr_in addr;
   1.121 -		addr.sin_family      = AF_INET;
   1.122 -		addr.sin_port        = htons(remotePort);
   1.123 -		addr.sin_addr.s_addr = htonl(0);
   1.124 -		int count = 0;
   1.125 -		while (count < 3)
   1.126 -		{
   1.127 -			if (bind(s, (sockaddr *)&addr, sizeof(addr)))
   1.128 -			{
   1.129 -				addr.sin_port = htons(ntohs(addr.sin_port)+1);
   1.130 -			}
   1.131 -			else
   1.132 -				break;
   1.133 -		}
   1.134 -		if (count == 3)
   1.135 -		{
   1.136 -			fprintf(stderr, "Error binding \n");
   1.137 -			exit(-1);
   1.138 -		}
   1.139 -
   1.140 -		fprintf(stderr, "Listening for a connection at port %d\n",
   1.141 -		        ntohs(addr.sin_port));
   1.142 -
   1.143 -		if (listen(s, 1))
   1.144 -		{
   1.145 -			fprintf(stderr, "Error listening\n");
   1.146 -			exit(-1);
   1.147 -		}
   1.148 -		socklen_t len = sizeof(addr);
   1.149 -
   1.150 -#ifdef WIN32
   1.151 -		int flag = 0;
   1.152 -		ioctlsocket(s, FIONBIO, (unsigned long *)&flag);
   1.153 -#endif // WIN32
   1.154 -		int s2 = accept(s, (sockaddr *)&addr, &len);
   1.155 -		if (s2 > 0)
   1.156 -		{
   1.157 -			fprintf(stderr, "Got a connection from %s %d\n",
   1.158 -			        inet_ntoa((in_addr)addr.sin_addr),
   1.159 -			        ntohs(addr.sin_port));
   1.160 -		}
   1.161 -		else
   1.162 -		{
   1.163 -#ifdef WIN32
   1.164 -			int error = WSAGetLastError();
   1.165 -#endif // WIN32
   1.166 -		}
   1.167 -		char dummy;
   1.168 -		recv(s2, &dummy, 1, 0);
   1.169 -		if (dummy != '+')
   1.170 -		{
   1.171 -			fprintf(stderr, "ACK not received\n");
   1.172 -			exit(-1);
   1.173 -		}
   1.174 -		remoteSocket = s2;
   1.175 -		//    close(s);
   1.176  	}
   1.177 -	return true;
   1.178 +      char dummy;
   1.179 +      recv(s2, &dummy, 1, 0);
   1.180 +      if (dummy != '+')
   1.181 +	{
   1.182 +	  fprintf(stderr, "ACK not received\n");
   1.183 +	  exit(-1);
   1.184 +	}
   1.185 +      remoteSocket = s2;
   1.186 +      //    close(s);
   1.187 +    }
   1.188 +  return true;
   1.189  }
   1.190  
   1.191  void remoteTcpCleanUp()
   1.192  {
   1.193 -	if (remoteSocket > 0)
   1.194 -	{
   1.195 -		fprintf(stderr, "Closing remote socket\n");
   1.196 -		close(remoteSocket);
   1.197 -		remoteSocket = -1;
   1.198 -	}
   1.199 -	if (remoteListenSocket > 0)
   1.200 -	{
   1.201 -		fprintf(stderr, "Closing listen socket\n");
   1.202 -		close(remoteListenSocket);
   1.203 -		remoteListenSocket = -1;
   1.204 -	}
   1.205 +  if (remoteSocket > 0)
   1.206 +    {
   1.207 +      fprintf(stderr, "Closing remote socket\n");
   1.208 +      close(remoteSocket);
   1.209 +      remoteSocket = -1;
   1.210 +    }
   1.211 +  if (remoteListenSocket > 0)
   1.212 +    {
   1.213 +      fprintf(stderr, "Closing listen socket\n");
   1.214 +      close(remoteListenSocket);
   1.215 +      remoteListenSocket = -1;
   1.216 +    }
   1.217  }
   1.218  
   1.219  int remotePipeSend(char *data, int len)
   1.220  {
   1.221 -	int res = write(1, data, len);
   1.222 -	return res;
   1.223 +  int res = write(1, data, len);
   1.224 +  return res;
   1.225  }
   1.226  
   1.227  int remotePipeRecv(char *data, int len)
   1.228  {
   1.229 -	int res = read(0, data, len);
   1.230 -	return res;
   1.231 +  int res = read(0, data, len);
   1.232 +  return res;
   1.233  }
   1.234  
   1.235  bool remotePipeInit()
   1.236  {
   1.237 -	char dummy;
   1.238 -	read(0, &dummy, 1);
   1.239 -	if (dummy != '+')
   1.240 -	{
   1.241 -		fprintf(stderr, "ACK not received\n");
   1.242 -		exit(-1);
   1.243 -	}
   1.244 +  char dummy;
   1.245 +  read(0, &dummy, 1);
   1.246 +  if (dummy != '+')
   1.247 +    {
   1.248 +      fprintf(stderr, "ACK not received\n");
   1.249 +      exit(-1);
   1.250 +    }
   1.251  
   1.252 -	return true;
   1.253 +  return true;
   1.254  }
   1.255  
   1.256  void remotePipeCleanUp()
   1.257 @@ -199,514 +199,514 @@
   1.258  
   1.259  void remoteSetPort(int port)
   1.260  {
   1.261 -	remotePort = port;
   1.262 +  remotePort = port;
   1.263  }
   1.264  
   1.265  void remoteSetProtocol(int p)
   1.266  {
   1.267 -	if (p == 0)
   1.268 -	{
   1.269 -		remoteSendFnc    = remoteTcpSend;
   1.270 -		remoteRecvFnc    = remoteTcpRecv;
   1.271 -		remoteInitFnc    = remoteTcpInit;
   1.272 -		remoteCleanUpFnc = remoteTcpCleanUp;
   1.273 -	}
   1.274 -	else
   1.275 -	{
   1.276 -		remoteSendFnc    = remotePipeSend;
   1.277 -		remoteRecvFnc    = remotePipeRecv;
   1.278 -		remoteInitFnc    = remotePipeInit;
   1.279 -		remoteCleanUpFnc = remotePipeCleanUp;
   1.280 -	}
   1.281 +  if (p == 0)
   1.282 +    {
   1.283 +      remoteSendFnc    = remoteTcpSend;
   1.284 +      remoteRecvFnc    = remoteTcpRecv;
   1.285 +      remoteInitFnc    = remoteTcpInit;
   1.286 +      remoteCleanUpFnc = remoteTcpCleanUp;
   1.287 +    }
   1.288 +  else
   1.289 +    {
   1.290 +      remoteSendFnc    = remotePipeSend;
   1.291 +      remoteRecvFnc    = remotePipeRecv;
   1.292 +      remoteInitFnc    = remotePipeInit;
   1.293 +      remoteCleanUpFnc = remotePipeCleanUp;
   1.294 +    }
   1.295  }
   1.296  
   1.297  void remoteInit()
   1.298  {
   1.299 -	if (remoteInitFnc)
   1.300 -		remoteInitFnc();
   1.301 +  if (remoteInitFnc)
   1.302 +    remoteInitFnc();
   1.303  }
   1.304  
   1.305  void remotePutPacket(char *packet)
   1.306  {
   1.307 -	char *hex = "0123456789abcdef";
   1.308 -	char  buffer[1024];
   1.309 +  char *hex = "0123456789abcdef";
   1.310 +  char  buffer[1024];
   1.311  
   1.312 -	int count = strlen(packet);
   1.313 +  int count = strlen(packet);
   1.314  
   1.315 -	unsigned char csum = 0;
   1.316 +  unsigned char csum = 0;
   1.317  
   1.318 -	char *p = buffer;
   1.319 -	*p++ = '$';
   1.320 +  char *p = buffer;
   1.321 +  *p++ = '$';
   1.322  
   1.323 -	for (int i = 0; i < count; i++)
   1.324 -	{
   1.325 -		csum += packet[i];
   1.326 -		*p++  = packet[i];
   1.327 -	}
   1.328 -	*p++ = '#';
   1.329 -	*p++ = hex[csum>>4];
   1.330 -	*p++ = hex[csum & 15];
   1.331 -	*p++ = 0;
   1.332 -	//  printf("Sending %s\n", buffer);
   1.333 -	remoteSendFnc(buffer, count + 4);
   1.334 +  for (int i = 0; i < count; i++)
   1.335 +    {
   1.336 +      csum += packet[i];
   1.337 +      *p++  = packet[i];
   1.338 +    }
   1.339 +  *p++ = '#';
   1.340 +  *p++ = hex[csum>>4];
   1.341 +  *p++ = hex[csum & 15];
   1.342 +  *p++ = 0;
   1.343 +  //  printf("Sending %s\n", buffer);
   1.344 +  remoteSendFnc(buffer, count + 4);
   1.345  
   1.346 -	char c = 0;
   1.347 -	remoteRecvFnc(&c, 1);
   1.348 -	/*
   1.349 -	   if(c == '+')
   1.350 -	   printf("ACK\n");
   1.351 -	   else if(c=='-')
   1.352 -	   printf("NACK\n");
   1.353 -	 */
   1.354 +  char c = 0;
   1.355 +  remoteRecvFnc(&c, 1);
   1.356 +  /*
   1.357 +    if(c == '+')
   1.358 +    printf("ACK\n");
   1.359 +    else if(c=='-')
   1.360 +    printf("NACK\n");
   1.361 +  */
   1.362  }
   1.363  
   1.364  void remoteOutput(char *s, u32 addr)
   1.365  {
   1.366 -	char buffer[16384];
   1.367 +  char buffer[16384];
   1.368  
   1.369 -	char *d = buffer;
   1.370 -	*d++ = 'O';
   1.371 +  char *d = buffer;
   1.372 +  *d++ = 'O';
   1.373  
   1.374 -	if (s)
   1.375 +  if (s)
   1.376 +    {
   1.377 +      char c = *s++;
   1.378 +      while (c)
   1.379  	{
   1.380 -		char c = *s++;
   1.381 -		while (c)
   1.382 -		{
   1.383 -			sprintf(d, "%02x", c);
   1.384 -			d += 2;
   1.385 -			c  = *s++;
   1.386 -		}
   1.387 +	  sprintf(d, "%02x", c);
   1.388 +	  d += 2;
   1.389 +	  c  = *s++;
   1.390  	}
   1.391 -	else
   1.392 +    }
   1.393 +  else
   1.394 +    {
   1.395 +      char c = debuggerReadByte(addr);
   1.396 +      addr++;
   1.397 +      while (c)
   1.398  	{
   1.399 -		char c = debuggerReadByte(addr);
   1.400 -		addr++;
   1.401 -		while (c)
   1.402 -		{
   1.403 -			sprintf(d, "%02x", c);
   1.404 -			d += 2;
   1.405 -			c  = debuggerReadByte(addr);
   1.406 -			addr++;
   1.407 -		}
   1.408 +	  sprintf(d, "%02x", c);
   1.409 +	  d += 2;
   1.410 +	  c  = debuggerReadByte(addr);
   1.411 +	  addr++;
   1.412  	}
   1.413 -	remotePutPacket(buffer);
   1.414 -	//  fprintf(stderr, "Output sent %s\n", buffer);
   1.415 +    }
   1.416 +  remotePutPacket(buffer);
   1.417 +  //  fprintf(stderr, "Output sent %s\n", buffer);
   1.418  }
   1.419  
   1.420  void remoteSendSignal()
   1.421  {
   1.422 -	char buffer[1024];
   1.423 -	sprintf(buffer, "S%02x", remoteSignal);
   1.424 -	remotePutPacket(buffer);
   1.425 +  char buffer[1024];
   1.426 +  sprintf(buffer, "S%02x", remoteSignal);
   1.427 +  remotePutPacket(buffer);
   1.428  }
   1.429  
   1.430  void remoteSendStatus()
   1.431  {
   1.432 -	char buffer[1024];
   1.433 -	sprintf(buffer, "T%02x", remoteSignal);
   1.434 -	char *s = buffer;
   1.435 -	s += 3;
   1.436 -	for (int i = 0; i < 15; i++)
   1.437 -	{
   1.438 -		u32 v = reg[i].I;
   1.439 -		sprintf(s, "%02x:%02x%02x%02x%02x;", i,
   1.440 -		        (v & 255),
   1.441 -		        (v >> 8) & 255,
   1.442 -		        (v >> 16) & 255,
   1.443 -		        (v >> 24) & 255);
   1.444 -		s += 12;
   1.445 -	}
   1.446 -	u32 v = armNextPC;
   1.447 -	sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255),
   1.448 -	        (v >> 8) & 255,
   1.449 -	        (v >> 16) & 255,
   1.450 -	        (v >> 24) & 255);
   1.451 -	s += 12;
   1.452 -	CPUUpdateCPSR();
   1.453 -	v = reg[16].I;
   1.454 -	sprintf(s, "19:%02x%02x%02x%02x;", (v & 255),
   1.455 -	        (v >> 8) & 255,
   1.456 -	        (v >> 16) & 255,
   1.457 -	        (v >> 24) & 255);
   1.458 -	s += 12;
   1.459 -	*s = 0;
   1.460 -	//  printf("Sending %s\n", buffer);
   1.461 -	remotePutPacket(buffer);
   1.462 +  char buffer[1024];
   1.463 +  sprintf(buffer, "T%02x", remoteSignal);
   1.464 +  char *s = buffer;
   1.465 +  s += 3;
   1.466 +  for (int i = 0; i < 15; i++)
   1.467 +    {
   1.468 +      u32 v = reg[i].I;
   1.469 +      sprintf(s, "%02x:%02x%02x%02x%02x;", i,
   1.470 +	      (v & 255),
   1.471 +	      (v >> 8) & 255,
   1.472 +	      (v >> 16) & 255,
   1.473 +	      (v >> 24) & 255);
   1.474 +      s += 12;
   1.475 +    }
   1.476 +  u32 v = armNextPC;
   1.477 +  sprintf(s, "0f:%02x%02x%02x%02x;", (v & 255),
   1.478 +	  (v >> 8) & 255,
   1.479 +	  (v >> 16) & 255,
   1.480 +	  (v >> 24) & 255);
   1.481 +  s += 12;
   1.482 +  CPUUpdateCPSR();
   1.483 +  v = reg[16].I;
   1.484 +  sprintf(s, "19:%02x%02x%02x%02x;", (v & 255),
   1.485 +	  (v >> 8) & 255,
   1.486 +	  (v >> 16) & 255,
   1.487 +	  (v >> 24) & 255);
   1.488 +  s += 12;
   1.489 +  *s = 0;
   1.490 +  //  printf("Sending %s\n", buffer);
   1.491 +  remotePutPacket(buffer);
   1.492  }
   1.493  
   1.494  void remoteBinaryWrite(char *p)
   1.495  {
   1.496 -	u32 address;
   1.497 -	int count;
   1.498 -	sscanf(p, "%x,%x:", &address, &count);
   1.499 -	//  printf("Binary write for %08x %d\n", address, count);
   1.500 +  u32 address;
   1.501 +  int count;
   1.502 +  sscanf(p, "%x,%x:", &address, &count);
   1.503 +  //  printf("Binary write for %08x %d\n", address, count);
   1.504  
   1.505 -	p = strchr(p, ':');
   1.506 -	p++;
   1.507 -	for (int i = 0; i < count; i++)
   1.508 +  p = strchr(p, ':');
   1.509 +  p++;
   1.510 +  for (int i = 0; i < count; i++)
   1.511 +    {
   1.512 +      u8 b = *p++;
   1.513 +      switch (b)
   1.514  	{
   1.515 -		u8 b = *p++;
   1.516 -		switch (b)
   1.517 -		{
   1.518 -		case 0x7d:
   1.519 -			b = *p++;
   1.520 -			debuggerWriteByte(address, (b^0x20));
   1.521 -			address++;
   1.522 -			break;
   1.523 -		default:
   1.524 -			debuggerWriteByte(address, b);
   1.525 -			address++;
   1.526 -			break;
   1.527 -		}
   1.528 +	case 0x7d:
   1.529 +	  b = *p++;
   1.530 +	  debuggerWriteByte(address, (b^0x20));
   1.531 +	  address++;
   1.532 +	  break;
   1.533 +	default:
   1.534 +	  debuggerWriteByte(address, b);
   1.535 +	  address++;
   1.536 +	  break;
   1.537  	}
   1.538 -	//  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
   1.539 -	remotePutPacket("OK");
   1.540 +    }
   1.541 +  //  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
   1.542 +  remotePutPacket("OK");
   1.543  }
   1.544  
   1.545  void remoteMemoryWrite(char *p)
   1.546  {
   1.547 -	u32 address;
   1.548 -	int count;
   1.549 -	sscanf(p, "%x,%x:", &address, &count);
   1.550 -	//  printf("Memory write for %08x %d\n", address, count);
   1.551 +  u32 address;
   1.552 +  int count;
   1.553 +  sscanf(p, "%x,%x:", &address, &count);
   1.554 +  //  printf("Memory write for %08x %d\n", address, count);
   1.555  
   1.556 -	p = strchr(p, ':');
   1.557 -	p++;
   1.558 -	for (int i = 0; i < count; i++)
   1.559 -	{
   1.560 -		u8   v = 0;
   1.561 -		char c = *p++;
   1.562 -		if (c <= '9')
   1.563 -			v = (c - '0') << 4;
   1.564 -		else
   1.565 -			v = (c + 10 - 'a') << 4;
   1.566 -		c = *p++;
   1.567 -		if (c <= '9')
   1.568 -			v += (c - '0');
   1.569 -		else
   1.570 -			v += (c + 10 - 'a');
   1.571 -		debuggerWriteByte(address, v);
   1.572 -		address++;
   1.573 -	}
   1.574 -	//  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
   1.575 -	remotePutPacket("OK");
   1.576 +  p = strchr(p, ':');
   1.577 +  p++;
   1.578 +  for (int i = 0; i < count; i++)
   1.579 +    {
   1.580 +      u8   v = 0;
   1.581 +      char c = *p++;
   1.582 +      if (c <= '9')
   1.583 +	v = (c - '0') << 4;
   1.584 +      else
   1.585 +	v = (c + 10 - 'a') << 4;
   1.586 +      c = *p++;
   1.587 +      if (c <= '9')
   1.588 +	v += (c - '0');
   1.589 +      else
   1.590 +	v += (c + 10 - 'a');
   1.591 +      debuggerWriteByte(address, v);
   1.592 +      address++;
   1.593 +    }
   1.594 +  //  printf("ROM is %08x\n", debuggerReadMemory(0x8000254));
   1.595 +  remotePutPacket("OK");
   1.596  }
   1.597  
   1.598  void remoteMemoryRead(char *p)
   1.599  {
   1.600 -	u32 address;
   1.601 -	int count;
   1.602 -	sscanf(p, "%x,%x:", &address, &count);
   1.603 -	//  printf("Memory read for %08x %d\n", address, count);
   1.604 +  u32 address;
   1.605 +  int count;
   1.606 +  sscanf(p, "%x,%x:", &address, &count);
   1.607 +  //  printf("Memory read for %08x %d\n", address, count);
   1.608  
   1.609 -	char buffer[1024];
   1.610 +  char buffer[1024];
   1.611  
   1.612 -	char *s = buffer;
   1.613 -	for (int i = 0; i < count; i++)
   1.614 -	{
   1.615 -		u8 b = debuggerReadByte(address);
   1.616 -		sprintf(s, "%02x", b);
   1.617 -		address++;
   1.618 -		s += 2;
   1.619 -	}
   1.620 -	*s = 0;
   1.621 -	remotePutPacket(buffer);
   1.622 +  char *s = buffer;
   1.623 +  for (int i = 0; i < count; i++)
   1.624 +    {
   1.625 +      u8 b = debuggerReadByte(address);
   1.626 +      sprintf(s, "%02x", b);
   1.627 +      address++;
   1.628 +      s += 2;
   1.629 +    }
   1.630 +  *s = 0;
   1.631 +  remotePutPacket(buffer);
   1.632  }
   1.633  
   1.634  void remoteStepOverRange(char *p)
   1.635  {
   1.636 -	u32 address;
   1.637 -	u32 final;
   1.638 -	sscanf(p, "%x,%x", &address, &final);
   1.639 +  u32 address;
   1.640 +  u32 final;
   1.641 +  sscanf(p, "%x,%x", &address, &final);
   1.642  
   1.643 -	remotePutPacket("OK");
   1.644 +  remotePutPacket("OK");
   1.645  
   1.646 -	remoteResumed = true;
   1.647 -	do
   1.648 -	{
   1.649 -		CPULoop(1);
   1.650 -		if (debugger)
   1.651 -			break;
   1.652 -	}
   1.653 -	while (armNextPC >= address && armNextPC < final);
   1.654 +  remoteResumed = true;
   1.655 +  do
   1.656 +    {
   1.657 +      CPULoop(1);
   1.658 +      if (debugger)
   1.659 +	break;
   1.660 +    }
   1.661 +  while (armNextPC >= address && armNextPC < final);
   1.662  
   1.663 -	remoteResumed = false;
   1.664 +  remoteResumed = false;
   1.665  
   1.666 -	remoteSendStatus();
   1.667 +  remoteSendStatus();
   1.668  }
   1.669  
   1.670  void remoteWriteWatch(char *p, bool active)
   1.671  {
   1.672 -	u32 address;
   1.673 -	int count;
   1.674 -	sscanf(p, ",%x,%x#", &address, &count);
   1.675 +  u32 address;
   1.676 +  int count;
   1.677 +  sscanf(p, ",%x,%x#", &address, &count);
   1.678  
   1.679 -	fprintf(stderr, "Write watch for %08x %d\n", address, count);
   1.680 +  fprintf(stderr, "Write watch for %08x %d\n", address, count);
   1.681  
   1.682 -	if (address < 0x2000000 || address > 0x3007fff)
   1.683 -	{
   1.684 -		remotePutPacket("E01");
   1.685 -		return;
   1.686 -	}
   1.687 +  if (address < 0x2000000 || address > 0x3007fff)
   1.688 +    {
   1.689 +      remotePutPacket("E01");
   1.690 +      return;
   1.691 +    }
   1.692  
   1.693 -	if (address > 0x203ffff && address < 0x3000000)
   1.694 -	{
   1.695 -		remotePutPacket("E01");
   1.696 -		return;
   1.697 -	}
   1.698 +  if (address > 0x203ffff && address < 0x3000000)
   1.699 +    {
   1.700 +      remotePutPacket("E01");
   1.701 +      return;
   1.702 +    }
   1.703  
   1.704 -	u32 final = address + count;
   1.705 +  u32 final = address + count;
   1.706  
   1.707 -	if (address < 0x2040000 && final > 0x2040000)
   1.708 -	{
   1.709 -		remotePutPacket("E01");
   1.710 -		return;
   1.711 -	}
   1.712 -	else if (address < 0x3008000 && final > 0x3008000)
   1.713 -	{
   1.714 -		remotePutPacket("E01");
   1.715 -		return;
   1.716 -	}
   1.717 +  if (address < 0x2040000 && final > 0x2040000)
   1.718 +    {
   1.719 +      remotePutPacket("E01");
   1.720 +      return;
   1.721 +    }
   1.722 +  else if (address < 0x3008000 && final > 0x3008000)
   1.723 +    {
   1.724 +      remotePutPacket("E01");
   1.725 +      return;
   1.726 +    }
   1.727  
   1.728 -	for (int i = 0; i < count; i++)
   1.729 -	{
   1.730 -		if ((address >> 24) == 2)
   1.731 -			freezeWorkRAM[address & 0x3ffff] = active;
   1.732 -		else
   1.733 -			freezeInternalRAM[address & 0x7fff] = active;
   1.734 -		address++;
   1.735 -	}
   1.736 +  for (int i = 0; i < count; i++)
   1.737 +    {
   1.738 +      if ((address >> 24) == 2)
   1.739 +	freezeWorkRAM[address & 0x3ffff] = active;
   1.740 +      else
   1.741 +	freezeInternalRAM[address & 0x7fff] = active;
   1.742 +      address++;
   1.743 +    }
   1.744  
   1.745 -	remotePutPacket("OK");
   1.746 +  remotePutPacket("OK");
   1.747  }
   1.748  
   1.749  void remoteReadRegisters(char *p)
   1.750  {
   1.751 -	char buffer[1024];
   1.752 +  char buffer[1024];
   1.753  
   1.754 -	char *s = buffer;
   1.755 -	int   i;
   1.756 -	// regular registers
   1.757 -	for (i = 0; i < 15; i++)
   1.758 -	{
   1.759 -		u32 v = reg[i].I;
   1.760 -		sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
   1.761 -		        (v >> 16) & 255, (v >> 24) & 255);
   1.762 -		s += 8;
   1.763 -	}
   1.764 -	// PC
   1.765 -	u32 pc = armNextPC;
   1.766 -	sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255,
   1.767 -	        (pc >> 16) & 255, (pc >> 24) & 255);
   1.768 -	s += 8;
   1.769 +  char *s = buffer;
   1.770 +  int   i;
   1.771 +  // regular registers
   1.772 +  for (i = 0; i < 15; i++)
   1.773 +    {
   1.774 +      u32 v = reg[i].I;
   1.775 +      sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
   1.776 +	      (v >> 16) & 255, (v >> 24) & 255);
   1.777 +      s += 8;
   1.778 +    }
   1.779 +  // PC
   1.780 +  u32 pc = armNextPC;
   1.781 +  sprintf(s, "%02x%02x%02x%02x", pc & 255, (pc >> 8) & 255,
   1.782 +	  (pc >> 16) & 255, (pc >> 24) & 255);
   1.783 +  s += 8;
   1.784  
   1.785 -	// floating point registers (24-bit)
   1.786 -	for (i = 0; i < 8; i++)
   1.787 -	{
   1.788 -		sprintf(s, "000000000000000000000000");
   1.789 -		s += 24;
   1.790 -	}
   1.791 +  // floating point registers (24-bit)
   1.792 +  for (i = 0; i < 8; i++)
   1.793 +    {
   1.794 +      sprintf(s, "000000000000000000000000");
   1.795 +      s += 24;
   1.796 +    }
   1.797  
   1.798 -	// FP status register
   1.799 -	sprintf(s, "00000000");
   1.800 -	s += 8;
   1.801 -	// CPSR
   1.802 -	CPUUpdateCPSR();
   1.803 -	u32 v = reg[16].I;
   1.804 -	sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
   1.805 -	        (v >> 16) & 255, (v >> 24) & 255);
   1.806 -	s += 8;
   1.807 -	*s = 0;
   1.808 -	remotePutPacket(buffer);
   1.809 +  // FP status register
   1.810 +  sprintf(s, "00000000");
   1.811 +  s += 8;
   1.812 +  // CPSR
   1.813 +  CPUUpdateCPSR();
   1.814 +  u32 v = reg[16].I;
   1.815 +  sprintf(s, "%02x%02x%02x%02x",  v & 255, (v >> 8) & 255,
   1.816 +	  (v >> 16) & 255, (v >> 24) & 255);
   1.817 +  s += 8;
   1.818 +  *s = 0;
   1.819 +  remotePutPacket(buffer);
   1.820  }
   1.821  
   1.822  void remoteWriteRegister(char *p)
   1.823  {
   1.824 -	int r;
   1.825 +  int r;
   1.826  
   1.827 -	sscanf(p, "%x=", &r);
   1.828 +  sscanf(p, "%x=", &r);
   1.829  
   1.830 -	p = strchr(p, '=');
   1.831 -	p++;
   1.832 +  p = strchr(p, '=');
   1.833 +  p++;
   1.834  
   1.835 -	char c = *p++;
   1.836 +  char c = *p++;
   1.837  
   1.838 -	u32 v = 0;
   1.839 +  u32 v = 0;
   1.840  
   1.841 -	u8 data[4] = {0, 0, 0, 0};
   1.842 +  u8 data[4] = {0, 0, 0, 0};
   1.843  
   1.844 -	int i = 0;
   1.845 +  int i = 0;
   1.846  
   1.847 -	while (c != '#')
   1.848 -	{
   1.849 -		u8 b = 0;
   1.850 -		if (c <= '9')
   1.851 -			b = (c - '0') << 4;
   1.852 -		else
   1.853 -			b = (c + 10 - 'a') << 4;
   1.854 -		c = *p++;
   1.855 -		if (c <= '9')
   1.856 -			b += (c - '0');
   1.857 -		else
   1.858 -			b += (c + 10 - 'a');
   1.859 -		data[i++] = b;
   1.860 -		c         = *p++;
   1.861 -	}
   1.862 +  while (c != '#')
   1.863 +    {
   1.864 +      u8 b = 0;
   1.865 +      if (c <= '9')
   1.866 +	b = (c - '0') << 4;
   1.867 +      else
   1.868 +	b = (c + 10 - 'a') << 4;
   1.869 +      c = *p++;
   1.870 +      if (c <= '9')
   1.871 +	b += (c - '0');
   1.872 +      else
   1.873 +	b += (c + 10 - 'a');
   1.874 +      data[i++] = b;
   1.875 +      c         = *p++;
   1.876 +    }
   1.877  
   1.878 -	v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
   1.879 +  v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
   1.880  
   1.881 -	//  printf("Write register %d=%08x\n", r, v);
   1.882 -	reg[r].I = v;
   1.883 -	if (r == 15)
   1.884 -	{
   1.885 -		armNextPC = v;
   1.886 -		if (armState)
   1.887 -			reg[15].I = v + 4;
   1.888 -		else
   1.889 -			reg[15].I = v + 2;
   1.890 -	}
   1.891 -	remotePutPacket("OK");
   1.892 +  //  printf("Write register %d=%08x\n", r, v);
   1.893 +  reg[r].I = v;
   1.894 +  if (r == 15)
   1.895 +    {
   1.896 +      armNextPC = v;
   1.897 +      if (armState)
   1.898 +	reg[15].I = v + 4;
   1.899 +      else
   1.900 +	reg[15].I = v + 2;
   1.901 +    }
   1.902 +  remotePutPacket("OK");
   1.903  }
   1.904  
   1.905  void remoteStubMain()
   1.906  {
   1.907 -	if (!debugger)
   1.908 -		return;
   1.909 +  if (!debugger)
   1.910 +    return;
   1.911  
   1.912 -	if (remoteResumed)
   1.913 +  if (remoteResumed)
   1.914 +    {
   1.915 +      remoteSendStatus();
   1.916 +      remoteResumed = false;
   1.917 +    }
   1.918 +
   1.919 +  while (true)
   1.920 +    {
   1.921 +      char buffer[1024];
   1.922 +      int  res = remoteRecvFnc(buffer, 1024);
   1.923 +
   1.924 +      if (res == -1)
   1.925  	{
   1.926 -		remoteSendStatus();
   1.927 -		remoteResumed = false;
   1.928 +	  fprintf(stderr, "GDB connection lost\n");
   1.929 +#ifdef SDL
   1.930 +	  dbgMain   = debuggerMain;
   1.931 +	  dbgSignal = debuggerSignal;
   1.932 +#endif
   1.933 +	  debugger = false;
   1.934 +	  break;
   1.935  	}
   1.936  
   1.937 -	while (true)
   1.938 +      //    fprintf(stderr, "Received %s\n", buffer);
   1.939 +      char *p  = buffer;
   1.940 +      char  c  = *p++;
   1.941 +      char  pp = '+';
   1.942 +      remoteSendFnc(&pp, 1);
   1.943 +
   1.944 +      if (c != '$')
   1.945 +	continue;
   1.946 +      c = *p++;
   1.947 +      switch (c)
   1.948  	{
   1.949 -		char buffer[1024];
   1.950 -		int  res = remoteRecvFnc(buffer, 1024);
   1.951 -
   1.952 -		if (res == -1)
   1.953 -		{
   1.954 -			fprintf(stderr, "GDB connection lost\n");
   1.955 +	case '?':
   1.956 +	  remoteSendSignal();
   1.957 +	  break;
   1.958 +	case 'D':
   1.959 +	  remotePutPacket("OK");
   1.960  #ifdef SDL
   1.961 -			dbgMain   = debuggerMain;
   1.962 -			dbgSignal = debuggerSignal;
   1.963 +	  dbgMain   = debuggerMain;
   1.964 +	  dbgSignal = debuggerSignal;
   1.965  #endif
   1.966 -			debugger = false;
   1.967 -			break;
   1.968 -		}
   1.969 -
   1.970 -		//    fprintf(stderr, "Received %s\n", buffer);
   1.971 -		char *p  = buffer;
   1.972 -		char  c  = *p++;
   1.973 -		char  pp = '+';
   1.974 -		remoteSendFnc(&pp, 1);
   1.975 -
   1.976 -		if (c != '$')
   1.977 -			continue;
   1.978 -		c = *p++;
   1.979 -		switch (c)
   1.980 -		{
   1.981 -		case '?':
   1.982 -			remoteSendSignal();
   1.983 -			break;
   1.984 -		case 'D':
   1.985 -			remotePutPacket("OK");
   1.986 +	  remoteResumed = true;
   1.987 +	  debugger      = false;
   1.988 +	  return;
   1.989 +	case 'e':
   1.990 +	  remoteStepOverRange(p);
   1.991 +	  break;
   1.992 +	case 'k':
   1.993 +	  remotePutPacket("OK");
   1.994  #ifdef SDL
   1.995 -			dbgMain   = debuggerMain;
   1.996 -			dbgSignal = debuggerSignal;
   1.997 +	  dbgMain   = debuggerMain;
   1.998 +	  dbgSignal = debuggerSignal;
   1.999  #endif
  1.1000 -			remoteResumed = true;
  1.1001 -			debugger      = false;
  1.1002 -			return;
  1.1003 -		case 'e':
  1.1004 -			remoteStepOverRange(p);
  1.1005 -			break;
  1.1006 -		case 'k':
  1.1007 -			remotePutPacket("OK");
  1.1008 -#ifdef SDL
  1.1009 -			dbgMain   = debuggerMain;
  1.1010 -			dbgSignal = debuggerSignal;
  1.1011 -#endif
  1.1012 -			debugger  = false;
  1.1013 -			emulating = false;
  1.1014 -			return;
  1.1015 -		case 'C':
  1.1016 -			remoteResumed = true;
  1.1017 -			debugger      = false;
  1.1018 -			return;
  1.1019 -		case 'c':
  1.1020 -			remoteResumed = true;
  1.1021 -			debugger      = false;
  1.1022 -			return;
  1.1023 -		case 's':
  1.1024 -			remoteResumed = true;
  1.1025 -			remoteSignal  = 5;
  1.1026 -			CPULoop(1);
  1.1027 -			if (remoteResumed)
  1.1028 -			{
  1.1029 -				remoteResumed = false;
  1.1030 -				remoteSendStatus();
  1.1031 -			}
  1.1032 -			break;
  1.1033 -		case 'g':
  1.1034 -			remoteReadRegisters(p);
  1.1035 -			break;
  1.1036 -		case 'P':
  1.1037 -			remoteWriteRegister(p);
  1.1038 -			break;
  1.1039 -		case 'M':
  1.1040 -			remoteMemoryWrite(p);
  1.1041 -			break;
  1.1042 -		case 'm':
  1.1043 -			remoteMemoryRead(p);
  1.1044 -			break;
  1.1045 -		case 'X':
  1.1046 -			remoteBinaryWrite(p);
  1.1047 -			break;
  1.1048 -		case 'H':
  1.1049 -			remotePutPacket("OK");
  1.1050 -			break;
  1.1051 -		case 'q':
  1.1052 -			remotePutPacket("");
  1.1053 -			break;
  1.1054 -		case 'Z':
  1.1055 -			if (*p++ == '2')
  1.1056 -			{
  1.1057 -				remoteWriteWatch(p, true);
  1.1058 -			}
  1.1059 -			else
  1.1060 -				remotePutPacket("");
  1.1061 -			break;
  1.1062 -		case 'z':
  1.1063 -			if (*p++ == '2')
  1.1064 -			{
  1.1065 -				remoteWriteWatch(p, false);
  1.1066 -			}
  1.1067 -			else
  1.1068 -				remotePutPacket("");
  1.1069 -			break;
  1.1070 -		default:
  1.1071 -		{
  1.1072 -			*(strchr(p, '#') + 3) = 0;
  1.1073 -			fprintf(stderr, "Unknown packet %s\n", --p);
  1.1074 -			remotePutPacket("");
  1.1075 -			break;
  1.1076 -		}
  1.1077 -		}
  1.1078 +	  debugger  = false;
  1.1079 +	  emulating = false;
  1.1080 +	  return;
  1.1081 +	case 'C':
  1.1082 +	  remoteResumed = true;
  1.1083 +	  debugger      = false;
  1.1084 +	  return;
  1.1085 +	case 'c':
  1.1086 +	  remoteResumed = true;
  1.1087 +	  debugger      = false;
  1.1088 +	  return;
  1.1089 +	case 's':
  1.1090 +	  remoteResumed = true;
  1.1091 +	  remoteSignal  = 5;
  1.1092 +	  CPULoop(1);
  1.1093 +	  if (remoteResumed)
  1.1094 +	    {
  1.1095 +	      remoteResumed = false;
  1.1096 +	      remoteSendStatus();
  1.1097 +	    }
  1.1098 +	  break;
  1.1099 +	case 'g':
  1.1100 +	  remoteReadRegisters(p);
  1.1101 +	  break;
  1.1102 +	case 'P':
  1.1103 +	  remoteWriteRegister(p);
  1.1104 +	  break;
  1.1105 +	case 'M':
  1.1106 +	  remoteMemoryWrite(p);
  1.1107 +	  break;
  1.1108 +	case 'm':
  1.1109 +	  remoteMemoryRead(p);
  1.1110 +	  break;
  1.1111 +	case 'X':
  1.1112 +	  remoteBinaryWrite(p);
  1.1113 +	  break;
  1.1114 +	case 'H':
  1.1115 +	  remotePutPacket("OK");
  1.1116 +	  break;
  1.1117 +	case 'q':
  1.1118 +	  remotePutPacket("");
  1.1119 +	  break;
  1.1120 +	case 'Z':
  1.1121 +	  if (*p++ == '2')
  1.1122 +	    {
  1.1123 +	      remoteWriteWatch(p, true);
  1.1124 +	    }
  1.1125 +	  else
  1.1126 +	    remotePutPacket("");
  1.1127 +	  break;
  1.1128 +	case 'z':
  1.1129 +	  if (*p++ == '2')
  1.1130 +	    {
  1.1131 +	      remoteWriteWatch(p, false);
  1.1132 +	    }
  1.1133 +	  else
  1.1134 +	    remotePutPacket("");
  1.1135 +	  break;
  1.1136 +	default:
  1.1137 +	  {
  1.1138 +	    *(strchr(p, '#') + 3) = 0;
  1.1139 +	    fprintf(stderr, "Unknown packet %s\n", --p);
  1.1140 +	    remotePutPacket("");
  1.1141 +	    break;
  1.1142 +	  }
  1.1143  	}
  1.1144 +    }
  1.1145  }
  1.1146  
  1.1147  void remoteStubSignal(int sig, int number)
  1.1148  {
  1.1149 -	remoteSignal  = sig;
  1.1150 -	remoteResumed = false;
  1.1151 -	remoteSendStatus();
  1.1152 -	debugger = true;
  1.1153 +  remoteSignal  = sig;
  1.1154 +  remoteResumed = false;
  1.1155 +  remoteSendStatus();
  1.1156 +  debugger = true;
  1.1157  }
  1.1158  
  1.1159  void remoteCleanUp()
  1.1160  {
  1.1161 -	if (remoteCleanUpFnc)
  1.1162 -		remoteCleanUpFnc();
  1.1163 +  if (remoteCleanUpFnc)
  1.1164 +    remoteCleanUpFnc();
  1.1165  }
  1.1166