+ else if (strcmp(argv[1], "jump") == 0)
+ {
+ if (argc != 3)
+ usage(argv[0]);
+
+ addr = atoi_or_die(argv[2]);
+ }
+ else if (strcmp(argv[1], "io") == 0)
+ {
+ unsigned int cmd = 0, value, iosize;
+ unsigned char *p = data;
+
+ for (i = 2; i < argc; ) {
+ if (argv[i][0] == 'r')
+ cmd = IOSEQ_R8;
+ else if (argv[i][0] == 'w')
+ cmd = IOSEQ_W8;
+ else
+ usage(argv[0]);
+
+ iosize = atoi_or_die(&argv[i][1]);
+ if (iosize == 32)
+ cmd += 2;
+ else if (iosize == 16)
+ cmd += 1;
+ else if (iosize != 8)
+ usage(argv[0]);
+ *p++ = cmd;
+ i++;
+
+ addr = atoi_or_die(argv[i]);
+ *p++ = addr >> 16;
+ *p++ = addr >> 8;
+ *p++ = addr >> 0;
+ i++;
+
+ if (cmd == IOSEQ_W8 || cmd == IOSEQ_W16 || cmd == IOSEQ_W32) {
+ value = atoi_or_die(argv[i]);
+ switch (iosize) {
+ case 32:
+ *p++ = value >> 24;
+ *p++ = value >> 16;
+ case 16:
+ *p++ = value >> 8;
+ case 8:
+ *p++ = value >> 0;
+ }
+ i++;
+ }
+
+ count++;
+ }
+ }
+ else if (strcmp(argv[1], "loadstate") == 0)
+ {
+ unsigned char chunk;
+ char header[12];
+ gzFile f;
+ int len;
+
+ if (argc != 3)
+ usage(argv[0]);
+
+ f = gzopen(argv[2], "rb");
+ if (f == NULL) {
+ perror("gzopen");
+ return 1;
+ }
+
+ checked_gzread(f, header, sizeof(header));
+ if (strncmp(header, "PicoSEXT", 8) != 0) {
+ fprintf(stderr, "bad header\n");
+ return 1;
+ }
+
+ while (!gzeof(file))
+ {
+ ret = gzread(f, &chunk, 1);
+ if (ret == 0)
+ break;
+ checked_gzread(f, &len, 4);
+ //printf("%2d %x\n", chunk, len);
+ switch (chunk) {
+ case 3: // VRAM
+ checked_gzread(f, data, len);
+ size += len;
+ break;
+ case 5: // CRAM
+ checked_gzread(f, data + 0x10000, len);
+ size += len;
+ break;
+ case 6: // VSRAM
+ checked_gzread(f, data + 0x10080, len);
+ size += len;
+ break;
+ case 8: // video
+ checked_gzread(f, data + 0x10100, len);
+ data[size+0] &= ~1; // no display disable
+ data[size+1] |= 0x40; // no blanking
+ size += 0x20;
+ break;
+ default:
+ if (chunk > 64+8) {
+ fprintf(stderr, "bad chunk: %d\n", chunk);
+ return 1;
+ }
+ gzseek(f, len, SEEK_CUR);
+ break;
+ }
+ }
+ gzclose(f);
+ if (size != 0x10120) {
+ fprintf(stderr, "bad final size: %x\n", size);
+ return 1;
+ }
+ // unbyteswap *RAMs (stored byteswapped)
+ for (i = 0; i < 0x10100; i += 2) {
+ int tmp = data[i];
+ data[i] = data[i + 1];
+ data[i + 1] = tmp;
+ }
+ }
+ else if (strcmp(argv[1], "recvvram") == 0)
+ {
+ if (argc != 3)
+ usage(argv[0]);
+
+ file = fopen(argv[2], "wb");
+ if (file == NULL) {
+ fprintf(stderr, "can't open file: %s\n", argv[2]);
+ return 1;
+ }
+
+ size = 0x10000;
+ memset(data, 0, size);
+ }