--- generator/main/ui-console.c 2020/03/04 04:46:43 1.1.1.1 +++ generator/main/ui-console.c 2020/03/04 04:46:53 1.1.1.2 @@ -6,6 +6,10 @@ sorry - I counted lines from 0 when I wrote the code... strictly speaking this is confusing... (it confuses me) */ +/* there must be a uip-xxx.c file to go with this user interface - all + platform dependent calls are in the uip file - see uip.h for the calls + required */ + #include #include #include @@ -38,12 +42,14 @@ uint32 ui_fkeys = 0; -uint8 ui_vdpsimple = 0; /* 0=raster, 1=cell based plotter */ -uint8 ui_clearnext = 0; /* flag indicating redraw required */ -uint8 ui_fullscreen = 0; /* does the user want full screen or not */ -uint8 ui_info = 1; /* does the user want info onscreen or not */ -uint8 ui_vsync = 0; /* does the user want us to wait for vsync */ -t_interlace ui_interlace = DEINTERLACE_WEAVEFILTER; /* type of de-interlace */ +uint8 ui_vdpsimple = 0; /* 0=raster, 1=cell based plotter */ +uint8 ui_clearnext = 0; /* flag indicating redraw required */ +uint8 ui_fullscreen = 0; /* does the user want full screen or not */ +uint8 ui_info = 1; /* does the user want info onscreen or not */ +uint8 ui_vsync = 0; /* does the user want us to wait for vsync */ +t_binding ui_bindings[2]; /* keyboard/joystick bindings for players */ + +t_interlace ui_interlace = DEINTERLACE_WEAVEFILTER; /*** forward reference declarations ***/ @@ -53,7 +59,7 @@ void ui_exithandler(void); void ui_newframe(void); void ui_convertdata(uint8 *indata, uint16 *outdata, unsigned int pixels); void ui_plotsprite_acorn(uint16 *logo, uint16 width, uint16 height, - uint16 x, uint16 y); + uint16 x, uint16 y); int ui_unpackfont(void); uint16 ui_plotstring(const char *text, uint16 xpos, uint16 ypos); uint16 ui_plotint2(uint8 num, uint16 xpos, uint16 ypos); @@ -67,8 +73,9 @@ void ui_render_x2(uint16 *linedata, uint unsigned int linewidth, unsigned int pixels); void ui_render_x2h(uint16 *linedata, uint16 *olddata, uint8 *screen, unsigned int linewidth, unsigned int pixels); -void ui_irender_weavefilter(uint16 *evendata, uint16 *odddata, uint8 *screen, - unsigned int linewidth, unsigned int pixels); +void ui_irender_weavefilter(uint16 *evendata, uint16 *odddata, + uint8 *screen, unsigned int linewidth, + unsigned int pixels); void ui_basicbits(void); void ui_licensescreen(void); void ui_imagescreen(void); @@ -81,6 +88,7 @@ void ui_resetscreen_main(void); int ui_saveimage(const char *type, char *filename, int buflen, int *xsize, int *ysize); int ui_setcolourbits(const char *str); +int ui_setcontrollers(const char *str); /* we store up log lines and dump them right at the end for allegro */ #ifdef ALLEGRO @@ -89,26 +97,27 @@ void ui_printlog(void); /*** static variables ***/ -static uint8 ui_vga = 0; /* flag for whether in VGA more or not */ -static uint8 ui_frameskip = 0; /* 0 for dynamic */ -static uint8 ui_actualskip = 0; /* the last skip we did (1..) */ -static uint8 ui_state = 0; /* 0=stop, 1=paused, 2=play */ +static uint8 ui_vga = 0; /* flag for whether in VGA more or not */ +static uint8 ui_frameskip = 0; /* 0 for dynamic */ +static uint8 ui_actualskip = 0; /* the last skip we did (1..) */ +static uint8 ui_state = 0; /* 0=stop, 1=paused, 2=play */ static uint32 ui_palcache[192]; -static char *ui_initload = NULL; /* filename to load on init */ +static char *ui_initload = NULL; /* filename to load on init */ static char ui_loglines[UI_LOGLINES][UI_LOGLINESIZE]; static uint32 ui_logline = 0; -static uint8 ui_plotfield = 0; /* flag indicating plotting this field */ -static uint8 ui_plotprevfield = 0; /* did we plot the previous field? */ -static uint16 *ui_font; /* unpacked font */ -static uint8 bigbuffer[8192]; /* stupid no-vsnprintf platforms */ -static uint16 ui_logcount = 0; /* log counter */ -static t_uipinfo ui_uipinfo; /* uipinfo filled in by uip 'sub-system' */ -static uint16 *ui_screen0; /* pointer to screen block for bank 0 */ -static uint16 *ui_screen1; /* pointer to screen block for bank 1 */ -static uint16 *ui_newscreen; /* pointer to new screen block */ -static int ui_saverom; /* flag to save rom and quit */ +static uint8 ui_plotfield = 0; /* flag indicating plotting this field */ +static uint8 ui_plotprevfield = 0; /* did we plot the previous field? */ +static uint16 *ui_font; /* unpacked font */ +static uint8 bigbuffer[8192]; /* stupid no-vsnprintf platforms */ +static uint16 ui_logcount = 0; /* log counter */ +static t_uipinfo ui_uipinfo; /* uipinfo filled in by uip 'sub-system' */ +static uint16 *ui_screen0; /* pointer to screen block for bank 0 */ +static uint16 *ui_screen1; /* pointer to screen block for bank 1 */ +static uint16 *ui_newscreen; /* pointer to new screen block */ +static int ui_saverom; /* flag to save rom and quit */ +static int ui_joysticks = 0; /* number of joysticks */ -static uint16 ui_screen[3][320*240]; /* screen buffers */ +static uint16 ui_screen[3][320 * 240]; /* screen buffers */ /*** Program entry point ***/ @@ -117,68 +126,79 @@ int ui_init(int argc, char *argv[]) int i; int ch; - for(i = 0; i < UI_LOGLINES; i++) + ui_bindings[0].joystick = -1; /* -1 = use keyboard */ + ui_bindings[0].keyboard = 0; /* 0 = main keyboard */ + ui_bindings[1].joystick = -1; /* -1 = use keyboard */ + ui_bindings[1].keyboard = -1; /* -1 = no keyboard */ + + for (i = 0; i < UI_LOGLINES; i++) ui_loglines[i][0] = '\0'; if (ui_unpackfont() == -1) { fprintf(stderr, "Failed to unpack font, out of memory?\n"); return 1; } - while ((ch = getopt(argc, argv, "i:c:w:f:sd:v:l:")) != -1) { + while ((ch = getopt(argc, argv, "i:c:w:f:sd:v:l:j:k:")) != -1) { switch (ch) { - case 'c': /* set colour bit positions */ - if (ui_setcolourbits(optarg)) { - fprintf(stderr, "-c option not understood, must be " - "'red,green,blue'\n"); - return 1; - } - break; - case 'i': /* de-interlacing mode */ - if (!strcasecmp(optarg, "bob")) { - ui_interlace = DEINTERLACE_BOB; - } else if (!strcasecmp(optarg, "weave")) { - ui_interlace = DEINTERLACE_WEAVE; - } else if (!strcasecmp(optarg, "weave-filter")) { - ui_interlace = DEINTERLACE_WEAVEFILTER; - } else { - fprintf(stderr, "-i option not understood, must be " - "bob|weave|weave-filter\n"); - return 1; - } - break; - case 'd': /* enable sound debug mode */ - /* re-write this to cope with comma separated items later */ - if (!strcasecmp(optarg, "sound")) - sound_debug = 1; - break; - case 's': /* save raw format rom */ - ui_saverom = 1; - break; - case 'l': /* set min fields / audio latency */ - sound_minfields = atoi(optarg); - break; - case 'f': /* set max fields / audio fragments */ - sound_maxfields = atoi(optarg); - break; - case 'k': /* set frame skip */ - ui_frameskip = atoi(optarg); - break; - case 'v': /* set log verbosity level */ - gen_loglevel = atoi(optarg); - break; - case 'w': /* saved game work dir */ - chdir(optarg); /* for the moment this will do */ - break; - case '?': - default: - ui_usage(); + case 'c': /* set colour bit positions */ + if (ui_setcolourbits(optarg)) { + fprintf(stderr, "-c option not understood, must be " + "'red,green,blue'\n"); + return 1; + } + break; + case 'i': /* de-interlacing mode */ + if (!strcasecmp(optarg, "bob")) { + ui_interlace = DEINTERLACE_BOB; + } else if (!strcasecmp(optarg, "weave")) { + ui_interlace = DEINTERLACE_WEAVE; + } else if (!strcasecmp(optarg, "weave-filter")) { + ui_interlace = DEINTERLACE_WEAVEFILTER; + } else { + fprintf(stderr, "-i option not understood, must be " + "bob|weave|weave-filter\n"); + return 1; + } + break; + case 'd': /* enable sound debug mode */ + /* re-write this to cope with comma separated items later */ + if (!strcasecmp(optarg, "sound")) + sound_debug = 1; + break; + case 'j': /* configure keyboard bindings */ + if (ui_setcontrollers(optarg)) { + fprintf(stderr, "-j option not understood\n"); + return 1; + } + break; + case 's': /* save raw format rom */ + ui_saverom = 1; + break; + case 'l': /* set min fields / audio latency */ + sound_minfields = atoi(optarg); + break; + case 'f': /* set max fields / audio fragments */ + sound_maxfields = atoi(optarg); + break; + case 'k': /* set frame skip */ + ui_frameskip = atoi(optarg); + break; + case 'v': /* set log verbosity level */ + gen_loglevel = atoi(optarg); + break; + case 'w': /* saved game work dir */ + chdir(optarg); /* for the moment this will do */ + break; + case '?': + default: + ui_usage(); } } - argc-= optind; - argv+= optind; - + argc -= optind; + argv += optind; + if (argc < 1 || argc > 3) ui_usage(); - if ((ui_initload = malloc(strlen(argv[0])+1)) == NULL) { + if ((ui_initload = malloc(strlen(argv[0]) + 1)) == NULL) { fprintf(stderr, "Out of memory\n"); return 1; } @@ -192,6 +212,34 @@ int ui_init(int argc, char *argv[]) LOG_CRITICAL(("Failed to initialise platform dependent UI")); return 1; } + ui_joysticks = uip_initjoysticks(); + LOG_VERBOSE(("%d joysticks detected", ui_joysticks)); + + if (ui_bindings[0].joystick >= ui_joysticks) { + LOG_CRITICAL(("Invalid joystick selected for first player")); + return 1; + } + if (ui_bindings[1].joystick >= ui_joysticks) { + LOG_CRITICAL(("Invalid joystick selected for second player")); + return 1; + } + if (ui_bindings[0].joystick == ui_bindings[1].joystick && + ui_bindings[0].joystick >= 0) { + LOG_CRITICAL(("The same joystick was selected for both players!")); + return 1; + } + if (ui_bindings[0].joystick == -1 && ui_bindings[0].joystick == -1) { + if (ui_bindings[0].keyboard == ui_bindings[1].keyboard) { + LOG_CRITICAL(("The same keyboard position was selected for " + "both players!")); + return 1; + } + if ((ui_bindings[0].keyboard == 0 && ui_bindings[1].keyboard != -1) || + (ui_bindings[1].keyboard == 0 && ui_bindings[0].keyboard != -1)) { + LOG_CRITICAL(("Invalid keyboard configuration")); + return 1; + } + } /* ui_newscreen is where the emulation data is rendered to - it is then compared with ui_screen0 or ui_screen1 depending on which screen bank it is being written to, and the delta changes are sent @@ -208,30 +256,32 @@ int ui_init(int argc, char *argv[]) void ui_usage(void) { fprintf(stderr, "Generator is (c) James Ponder 1997-2001, all rights " - "reserved. " VERSTRING "\n\n"); + "reserved. " VERSTRING "\n\n"); fprintf(stderr, "generator [options] \n\n"); fprintf(stderr, " -v can be: 0 = none, 1 = critical, " - "2 = normal, 3 = verbose\n"); + "2 = normal, 3 = verbose\n"); fprintf(stderr, " -d sound - turns on debug mode for sound\n"); fprintf(stderr, " -l is the number of video fields worth " - "of sound to\n try to keep buffered (default 5)\n"); + "of sound to\n try to keep buffered (default 5)\n"); fprintf(stderr, " -f is the number of video fields worth " - "of sound to\n allow buffered (approx) (default 10)\n"); + "of sound to\n allow buffered (approx) (default 10)\n"); fprintf(stderr, " -w indicates where saved games are stored " - "(default is current dir)\n"); + "(default is current dir)\n"); fprintf(stderr, " -c [,,] sets the colour bit positions of where " - "red, green and blue\n 5-bit values should be shifted " - "to (default 10,5,0 for 15-bit modes)\n"); + "red, green and blue\n 5-bit values should be shifted " + "to (default 10,5,0 for 15-bit modes)\n"); fprintf(stderr, " -i selects de-interlace mode, one of: bob " - "weave weave-filter\n"); + "weave weave-filter\n"); fprintf(stderr, " -k forces the frame step (1=all frames, 2=every other," - " etc.)\n"); + " etc.)\n"); + fprintf(stderr, " -j , sets the input device for each joypad " + "(default key0,none)\n"); fprintf(stderr, " -s will save the ROM to the work directory in raw " - "format\n\n"); + "format\n\n"); fprintf(stderr, " ROM types supported: .rom or .smd interleaved " - "(autodetected)\n"); + "(autodetected)\n"); fprintf(stderr, " Sound latency will be kept between -l and -a values. " - "If you are having sound\n problems try -l 20 -f 30\n"); + "If you are having sound\n problems try -l 20 -f 30\n"); exit(1); } @@ -242,8 +292,8 @@ void ui_printlog(void) char *p; printf("**** Last lines logged:\n"); - for (i = ui_logline; i < (UI_LOGLINES+ui_logline); i++) { - p = ui_loglines[(i < UI_LOGLINES) ? i : (i-UI_LOGLINES)]; + for (i = ui_logline; i < (UI_LOGLINES + ui_logline); i++) { + p = ui_loglines[(i < UI_LOGLINES) ? i : (i - UI_LOGLINES)]; if (*p) printf("%s\n", p); } @@ -279,21 +329,68 @@ int ui_setcolourbits(const char *str) snprintf(s, sizeof(s), "%s", str); - if ((green = strchr(str, ',')) == NULL) + if ((green = strchr(s, ',')) == NULL) return -1; *green++ = '\0'; if ((blue = strchr(green, ',')) == NULL) return -1; - *blue++= '\0'; + *blue++ = '\0'; if ((r = atoi(s)) < 0 || r > 15 || - (g = atoi(green)) < 0 || g > 15 || - (b = atoi(blue)) < 0 || b > 15) + (g = atoi(green)) < 0 || g > 15 || (b = atoi(blue)) < 0 || b > 15) return -1; if (uip_setcolourbits(r, g, b)) return -1; return 0; } +/* set controllers for input device from user setting. + usage: , + where either can be: joy0, joy1, joy2, joy3 - joypad number + key0 - main keyboard + key1 - left side of keyboard + key2 - right side of keyboard + none - no keyboard + */ + +int ui_setcontrollers(const char *str) +{ + char *cont0, *cont1; + char s[32]; + int i; + char *p; + + snprintf(s, sizeof(s), "%s", str); + cont0 = s; + if ((cont1 = strchr(s, ',')) == NULL) + return -1; + *cont1++ = '\0'; + + for (i = 0; i < 2; i++) { + p = (i == 0 ? cont0 : cont1); + if (!strncasecmp(p, "key", 3)) { + if (p[3] < '0' || p[3] > '2') + return -1; + if (p[4]) + return -1; + ui_bindings[i].joystick = -1; + ui_bindings[i].keyboard = p[3] - '0'; + } else if (!strncasecmp(p, "joy", 3)) { + if (p[3] < '0' || p[3] > '1') + return -1; + if (p[4]) + return -1; + ui_bindings[i].joystick = p[3] - '0'; + ui_bindings[i].keyboard = -1; + } else if (!strcasecmp(p, "none")) { + ui_bindings[i].joystick = -1; + ui_bindings[i].keyboard = -1; + } else { + return -1; + } + } + return 0; +} + /*** ui_drawbox - plot a box ***/ void ui_drawbox(uint16 colour, uint16 x, uint16 y, uint16 width, @@ -302,15 +399,15 @@ void ui_drawbox(uint16 colour, uint16 x, uint16 *p, *q; unsigned int i; - p = (uint16 *)(ui_uipinfo.screenmem_w+y*ui_uipinfo.linewidth+x*2); - q = (uint16 *)((uint8 *)p+(height-1)*ui_uipinfo.linewidth); + p = (uint16 *)(ui_uipinfo.screenmem_w + y * ui_uipinfo.linewidth + x * 2); + q = (uint16 *)((uint8 *)p + (height - 1) * ui_uipinfo.linewidth); for (i = 0; i < width; i++) *p++ = *q++ = colour; - p = (uint16 *)(ui_uipinfo.screenmem_w+y*ui_uipinfo.linewidth+x*2); + p = (uint16 *)(ui_uipinfo.screenmem_w + y * ui_uipinfo.linewidth + x * 2); for (i = 0; i < height; i++) { p[0] = colour; - p[width-1] = colour; - p = (uint16 *)((uint8 *)p+ui_uipinfo.linewidth); + p[width - 1] = colour; + p = (uint16 *)((uint8 *)p + ui_uipinfo.linewidth); } } @@ -322,20 +419,20 @@ int ui_unpackfont(void) unsigned char packed; uint16 *cdata; - if ((ui_font = malloc(128*6*10*2)) == NULL) /* 128 chars, 6x, 10y, 16bit */ + if ((ui_font = malloc(128 * 6 * 10 * 2)) == NULL) /* 128 chars, 6x, 10y, 16bit */ return -1; - for (c = 0; c < 128; c++) { /* 128 characters */ - cdata = ui_font+c*6*10; - for (y = 0; y < 10; y++) { /* 10 pixels height */ - packed = generator_font[c*10+y]; + for (c = 0; c < 128; c++) { /* 128 characters */ + cdata = ui_font + c * 6 * 10; + for (y = 0; y < 10; y++) { /* 10 pixels height */ + packed = generator_font[c * 10 + y]; for (x = 0; x < 6; x++) { /* 6 pixels width */ - *cdata++ = (packed & 1<<(7-x)) ? 0xffff : 0; + *cdata++ = (packed & 1 << (7 - x)) ? 0xffff : 0; } } } return 0; } - + /*** ui_plotint2 - plot a 2-char wide integer ***/ uint16 ui_plotint2(uint8 num, uint16 xpos, uint16 ypos) @@ -354,21 +451,22 @@ uint16 ui_plotstring(const char *text, u { const unsigned char *p; const uint16 *cdata; - unsigned int x,y; + unsigned int x, y; uint16 *scr; for (p = text; *p; p++) { if (*p > 128) - cdata = ui_font+'.'*6*10; + cdata = ui_font + '.' * 6 * 10; else - cdata = ui_font+(*p)*6*10; + cdata = ui_font + (*p) * 6 * 10; for (y = 0; y < 10; y++) { - scr = (uint16 *)(ui_uipinfo.screenmem_w+(ypos+y)*ui_uipinfo.linewidth - +xpos*2); + scr = + (uint16 *)(ui_uipinfo.screenmem_w + + (ypos + y) * ui_uipinfo.linewidth + xpos * 2); for (x = 0; x < 6; x++) *scr++ = *cdata++; } - xpos+= 6; + xpos += 6; } return xpos; } @@ -376,7 +474,7 @@ uint16 ui_plotstring(const char *text, u /*** ui_plotsprite - plot a sprite ***/ void ui_plotsprite_acorn(uint16 *logo, uint16 width, uint16 height, - uint16 x, uint16 y) + uint16 x, uint16 y) { uint16 a, b; uint16 *p, *q; @@ -384,14 +482,16 @@ void ui_plotsprite_acorn(uint16 *logo, u uint8 red, green, blue; for (b = 0; b < height; b++) { - p = (uint16 *)(ui_uipinfo.screenmem_w+(y+b)*ui_uipinfo.linewidth+x*2); + p = + (uint16 *)(ui_uipinfo.screenmem_w + (y + b) * ui_uipinfo.linewidth + + x * 2); for (a = 0; a < width; a++) { - word = (((uint8 *)logo)[1]<<8) | ((uint8 *)logo)[0]; - green = (word>>5) & 0x1f; + word = (((uint8 *)logo)[1] << 8) | ((uint8 *)logo)[0]; + green = (word >> 5) & 0x1f; red = word & 0x1f; - blue = (word>>10) & 0x1f; - *p++ = red<> 10) & 0x1f; + *p++ = red << ui_uipinfo.redshift | green << ui_uipinfo.greenshift | + blue << ui_uipinfo.blueshift; logo++; } } @@ -401,9 +501,9 @@ void ui_plotsprite_acorn(uint16 *logo, u void ui_setupscreen(void) { - uint16 grey = 24<tm_hour, 610, 470); ui_plotint2(tm_p->tm_min, 628, 470); /* - if (!ui_fullscreen) { - int y, i, s; - for (i = 0; i < 8; i++) { - for (s = 0; s < 4; s++) { - ui_plotstring((sound_keys[i] & (1<>4)<<(ui_uipinfo.greenshift+1); - ui_palcache[col+64] = /* hilight */ - (p[0]&0xE)<>4)<> 4) << (ui_uipinfo.greenshift + 1); + ui_palcache[col + 64] = /* hilight */ + (p[0] & 0xE) << ui_uipinfo.blueshift | + (p[1] & 0xE) << ui_uipinfo.redshift | + ((p[1] & 0xE0) >> 4) << ui_uipinfo.greenshift | (16 << ui_uipinfo.blueshift) | (16 << ui_uipinfo.redshift) | (16 << ui_uipinfo.greenshift); - ui_palcache[col+128] = /* shadow */ - (p[0]&0xE)<>4)<> 4) << ui_uipinfo.greenshift; } } @@ -699,18 +812,18 @@ void ui_convertdata(uint8 *indata, uint1 ui_checkpalcache(0); /* not scaled, 16bpp - we do 4 pixels at a time */ - for (ui = 0; ui < pixels>>2; ui++) { - indata_val = ((uint32 *)indata)[ui]; /* 4 bytes of in data */ + for (ui = 0; ui < pixels >> 2; ui++) { + indata_val = ((uint32 *)indata)[ui]; /* 4 bytes of in data */ outdata1 = (ui_palcache[indata_val & 0xff] | - ui_palcache[(indata_val>>8) & 0xff]<<16); - outdata2 = (ui_palcache[(indata_val>>16) & 0xff] | - ui_palcache[(indata_val>>24) & 0xff]<<16); + ui_palcache[(indata_val >> 8) & 0xff] << 16); + outdata2 = (ui_palcache[(indata_val >> 16) & 0xff] | + ui_palcache[(indata_val >> 24) & 0xff] << 16); #ifdef WORDS_BIGENDIAN - ((uint32 *)outdata)[(ui<<1)] = outdata2; - ((uint32 *)outdata)[(ui<<1)+1] = outdata1; + ((uint32 *)outdata)[(ui << 1)] = outdata2; + ((uint32 *)outdata)[(ui << 1) + 1] = outdata1; #else - ((uint32 *)outdata)[(ui<<1)] = outdata1; - ((uint32 *)outdata)[(ui<<1)+1] = outdata2; + ((uint32 *)outdata)[(ui << 1)] = outdata1; + ((uint32 *)outdata)[(ui << 1) + 1] = outdata2; #endif } } @@ -723,10 +836,10 @@ void ui_render_x1(uint16 *linedata, uint unsigned int ui; uint32 inval; - if (0==1) { - memcpy(screen, linedata, pixels*2); + if (0 == 1) { + memcpy(screen, linedata, pixels * 2); } else { - for (ui = 0; ui < pixels>>1; ui++) { + for (ui = 0; ui < pixels >> 1; ui++) { inval = ((uint32 *)linedata)[ui]; /* two words of input data */ if (inval != ((uint32 *)olddata)[ui]) { ((uint32 *)screen)[ui] = inval; @@ -744,29 +857,29 @@ void ui_render_x2(uint16 *linedata, uint uint32 inval, outval, mask; uint8 *screen2 = screen + linewidth; - for (ui = 0; ui < pixels>>1; ui++) { - inval = ((uint32 *)linedata)[ui]; /* two words of input data */ - mask = inval ^ ((uint32 *)olddata)[ui]; /* check for changed data */ + for (ui = 0; ui < pixels >> 1; ui++) { + inval = ((uint32 *)linedata)[ui]; /* two words of input data */ + mask = inval ^ ((uint32 *)olddata)[ui]; /* check for changed data */ if (mask & 0xffff) { outval = inval & 0xffff; - outval|= outval<<16; + outval |= outval << 16; #ifdef WORDS_BIGENDIAN - ((uint32 *)screen)[(ui<<1)+1] = outval; /* write first two words */ - ((uint32 *)screen2)[(ui<<1)+1] = outval; + ((uint32 *)screen)[(ui << 1) + 1] = outval; /* write first two words */ + ((uint32 *)screen2)[(ui << 1) + 1] = outval; #else - ((uint32 *)screen)[(ui<<1)] = outval; /* write first two words */ - ((uint32 *)screen2)[(ui<<1)] = outval; + ((uint32 *)screen)[(ui << 1)] = outval; /* write first two words */ + ((uint32 *)screen2)[(ui << 1)] = outval; #endif } if (mask & 0xffff0000) { outval = inval & 0xffff0000; - outval|= outval>>16; + outval |= outval >> 16; #ifdef WORDS_BIGENDIAN - ((uint32 *)screen)[(ui<<1)] = outval; /* write second two words */ - ((uint32 *)screen2)[(ui<<1)] = outval; + ((uint32 *)screen)[(ui << 1)] = outval; /* write second two words */ + ((uint32 *)screen2)[(ui << 1)] = outval; #else - ((uint32 *)screen)[(ui<<1)+1] = outval; /* write second two words */ - ((uint32 *)screen2)[(ui<<1)+1] = outval; + ((uint32 *)screen)[(ui << 1) + 1] = outval; /* write second two words */ + ((uint32 *)screen2)[(ui << 1) + 1] = outval; #endif } } @@ -781,26 +894,26 @@ void ui_render_x2h(uint16 *linedata, uin uint32 inval, outval, mask; mask = 0xffffffff; - for (ui = 0; ui < pixels>>1; ui++) { - inval = ((uint32 *)linedata)[ui]; /* two words of input data */ + for (ui = 0; ui < pixels >> 1; ui++) { + inval = ((uint32 *)linedata)[ui]; /* two words of input data */ if (olddata) - mask = inval ^ ((uint32 *)olddata)[ui]; /* check for changed data */ + mask = inval ^ ((uint32 *)olddata)[ui]; /* check for changed data */ if (mask & 0xffff) { outval = inval & 0xffff; - outval|= outval<<16; + outval |= outval << 16; #ifdef WORDS_BIGENDIAN - ((uint32 *)screen)[(ui<<1)+1] = outval; /* write first two words */ + ((uint32 *)screen)[(ui << 1) + 1] = outval; /* write first two words */ #else - ((uint32 *)screen)[(ui<<1)] = outval; /* write first two words */ + ((uint32 *)screen)[(ui << 1)] = outval; /* write first two words */ #endif } if (mask & 0xffff0000) { outval = inval & 0xffff0000; - outval|= outval>>16; + outval |= outval >> 16; #ifdef WORDS_BIGENDIAN - ((uint32 *)screen)[(ui<<1)] = outval; /* write second two words */ + ((uint32 *)screen)[(ui << 1)] = outval; /* write second two words */ #else - ((uint32 *)screen)[(ui<<1)+1] = outval; /* write second two words */ + ((uint32 *)screen)[(ui << 1) + 1] = outval; /* write second two words */ #endif } } @@ -815,29 +928,29 @@ void ui_irender_weavefilter(uint16 *even uint32 evenval, oddval, e_r, e_g, e_b, o_r, o_g, o_b; uint32 outval, w1, w2; - for (ui = 0; ui < pixels>>1; ui++) { - evenval = ((uint32 *)evendata)[ui]; /* two words of input data */ - oddval = ((uint32 *)odddata)[ui]; /* two words of input data */ + for (ui = 0; ui < pixels >> 1; ui++) { + evenval = ((uint32 *)evendata)[ui]; /* two words of input data */ + oddval = ((uint32 *)odddata)[ui]; /* two words of input data */ e_r = (evenval >> ui_uipinfo.redshift) & 0x001f001f; e_g = (evenval >> ui_uipinfo.greenshift) & 0x001f001f; e_b = (evenval >> ui_uipinfo.blueshift) & 0x001f001f; o_r = (oddval >> ui_uipinfo.redshift) & 0x001f001f; o_g = (oddval >> ui_uipinfo.greenshift) & 0x001f001f; o_b = (oddval >> ui_uipinfo.blueshift) & 0x001f001f; - outval = (((e_r+o_r)>>1) & 0x001f001f) << ui_uipinfo.redshift | - (((e_g+o_g)>>1) & 0x001f001f) << ui_uipinfo.greenshift | - (((e_b+o_b)>>1) & 0x001f001f) << ui_uipinfo.blueshift; + outval = (((e_r + o_r) >> 1) & 0x001f001f) << ui_uipinfo.redshift | + (((e_g + o_g) >> 1) & 0x001f001f) << ui_uipinfo.greenshift | + (((e_b + o_b) >> 1) & 0x001f001f) << ui_uipinfo.blueshift; w1 = (outval & 0xffff); - w1|= w1<<16; + w1 |= w1 << 16; w2 = outval & 0xffff0000; - w2|= w2>>16; + w2 |= w2 >> 16; #ifdef WORDS_BIGENDIAN - ((uint32 *)screen)[(ui<<1)] = w2; - ((uint32 *)screen)[(ui<<1)+1] = w1; - LOG_CRITICAL(("this code hasn't been checked")); + ((uint32 *)screen)[(ui << 1)] = w2; + ((uint32 *)screen)[(ui << 1) + 1] = w1; + LOG_CRITICAL(("this code hasn't been checked")); #else - ((uint32 *)screen)[(ui<<1)] = w1; - ((uint32 *)screen)[(ui<<1)+1] = w2; + ((uint32 *)screen)[(ui << 1)] = w1; + ((uint32 *)screen)[(ui << 1) + 1] = w2; #endif } } @@ -845,19 +958,25 @@ void ui_irender_weavefilter(uint16 *even /*** ui_line - it is time to render a line ***/ void ui_line(unsigned int line) -{ +{ static uint8 gfx[320]; - unsigned int yoffset = (vdp_reg[1] & 1<<3) ? 0 : 8; + unsigned int yoffset = (vdp_reg[1] & 1 << 3) ? 0 : 8; unsigned int width = (vdp_reg[12] & 1) ? 320 : 256; if (ui_plotfield && !ui_vdpsimple) { /* we are plotting this frame, and we're not doing a simple plot at the end of it all */ - if (((vdp_reg[12]>>1) & 3) == 3) - vdp_renderline(line, gfx, vdp_oddframe); /* interlace */ - else + switch ((vdp_reg[12] >> 1) & 3) { + case 0: /* normal */ + case 1: /* interlace simply doubled up */ + case 2: /* invalid */ vdp_renderline(line, gfx, 0); - ui_convertdata(gfx, ui_newscreen+line*320, width); + break; + case 3: /* interlace with double resolution */ + vdp_renderline(line, gfx, vdp_oddframe); + break; + } + ui_convertdata(gfx, ui_newscreen + line * 320, width); } } @@ -868,18 +987,18 @@ void ui_endfield(void) static int counter = 0; unsigned int line; unsigned int width = (vdp_reg[12] & 1) ? 320 : 256; - uint8 gfx[(320+16)*(240+16)]; + uint8 gfx[(320 + 16) * (240 + 16)]; if (ui_plotfield) { if (ui_vdpsimple) { /* cell mode - entire frame done here */ - vdp_renderframe(gfx+(8*(320+16))+8, 320+16); /* plot frame */ + vdp_renderframe(gfx + (8 * (320 + 16)) + 8, 320 + 16); /* plot frame */ for (line = 0; line < vdp_vislines; line++) { - ui_convertdata(gfx+8+(line+8)*(320+16), - ui_newscreen+line*320, width); + ui_convertdata(gfx + 8 + (line + 8) * (320 + 16), + ui_newscreen + line * 320, width); } } - ui_rendertoscreen(); /* plot ui_newscreen to screen */ + ui_rendertoscreen(); /* plot ui_newscreen to screen */ } if (ui_frameskip == 0) { /* dynamic frame skipping */ @@ -895,23 +1014,23 @@ void ui_endfield(void) void ui_rendertoscreen(void) { - uint16 **oldscreenpp = uip_whichbank() ? &ui_screen1 : &ui_screen0; + uint16 **oldscreenpp = uip_whichbank()? &ui_screen1 : &ui_screen0; uint16 *scrtmp; uint16 *newlinedata, *oldlinedata; unsigned int line; unsigned int nominalwidth = (vdp_reg[12] & 1) ? 320 : 256; - unsigned int yoffset = (vdp_reg[1] & 1<<3) ? 0 : 8; + unsigned int yoffset = (vdp_reg[1] & 1 << 3) ? 0 : 8; unsigned int xoffset = (vdp_reg[12] & 1) ? 0 : 32; uint8 *screen; - uint16 *evenscreen; /* interlace: lines 0,2,etc. */ - uint16 *oddscreen; /* lines 1,3,etc. */ + uint16 *evenscreen; /* interlace: lines 0,2,etc. */ + uint16 *oddscreen; /* lines 1,3,etc. */ for (line = 0; line < vdp_vislines; line++) { - newlinedata = ui_newscreen+line*320; - oldlinedata = *oldscreenpp+line*320; + newlinedata = ui_newscreen + line * 320; + oldlinedata = *oldscreenpp + line * 320; if (ui_fullscreen) { - screen = (ui_uipinfo.screenmem_w+xoffset*4+ - ui_uipinfo.linewidth*2*(line+yoffset)); + screen = (ui_uipinfo.screenmem_w + xoffset * 4 + + ui_uipinfo.linewidth * 2 * (line + yoffset)); switch ((vdp_reg[12] >> 1) & 3) { /* interlace mode */ case 0: case 1: @@ -923,10 +1042,10 @@ void ui_rendertoscreen(void) /* work out which buffer contains the odd and even fields */ if (vdp_oddframe) { oddscreen = ui_newscreen; - evenscreen = uip_whichbank() ? ui_screen0 : ui_screen1; + evenscreen = uip_whichbank()? ui_screen0 : ui_screen1; } else { evenscreen = ui_newscreen; - oddscreen = uip_whichbank() ? ui_screen0 : ui_screen1; + oddscreen = uip_whichbank()? ui_screen0 : ui_screen1; } switch (ui_interlace) { case DEINTERLACE_BOB: @@ -934,28 +1053,27 @@ void ui_rendertoscreen(void) ui_uipinfo.linewidth, nominalwidth); break; case DEINTERLACE_WEAVE: - ui_render_x2h(evenscreen+line*320, NULL, screen, + ui_render_x2h(evenscreen + line * 320, NULL, screen, ui_uipinfo.linewidth, nominalwidth); - ui_render_x2h(oddscreen+line*320, NULL, - screen+ui_uipinfo.linewidth, + ui_render_x2h(oddscreen + line * 320, NULL, + screen + ui_uipinfo.linewidth, ui_uipinfo.linewidth, nominalwidth); break; case DEINTERLACE_WEAVEFILTER: - ui_irender_weavefilter(evenscreen+line*320, /* line */ - oddscreen+line*320, /* line+1 */ - screen, - ui_uipinfo.linewidth, nominalwidth); - ui_irender_weavefilter(oddscreen+line*320, /* line+1 */ - evenscreen+line*320+320, /* line+2 */ - screen+ui_uipinfo.linewidth, + ui_irender_weavefilter(evenscreen + line * 320, /* line */ + oddscreen + line * 320, /* line+1 */ + screen, ui_uipinfo.linewidth, nominalwidth); + ui_irender_weavefilter(oddscreen + line * 320, /* line+1 */ + evenscreen + line * 320 + 320, /* line+2 */ + screen + ui_uipinfo.linewidth, ui_uipinfo.linewidth, nominalwidth); break; } break; } } else { - screen = (ui_uipinfo.screenmem_w+320+xoffset*2+ - ui_uipinfo.linewidth*(120+line+yoffset)); + screen = (ui_uipinfo.screenmem_w + 320 + xoffset * 2 + + ui_uipinfo.linewidth * (120 + line + yoffset)); ui_render_x1(newlinedata, oldlinedata, screen, ui_uipinfo.linewidth, nominalwidth); } @@ -971,13 +1089,13 @@ void ui_rendertoscreen(void) void ui_basicbits(void) { - uint16 grey = 24<= '1' && c <= '9') { /* this is a function call! */ - if ((save ? state_save : state_load)(c - '0') == 0) + if ((save ? state_save : state_load) (c - '0') == 0) return 1; uip_clearmiddle(); if (save) @@ -1172,7 +1295,8 @@ void ui_imagescreen_main(void) uip_clearmiddle(); snprintf(buf, sizeof(buf), "Successfully saved %s", filename); ui_plotstring(buf, 160, 120); - snprintf(buf, sizeof(buf), "(%d x %d 24 bit raw image)", xsize, ysize); + snprintf(buf, sizeof(buf), "(%d x %d 24 bit raw image)", + xsize, ysize); ui_plotstring(buf, 160, 130); ui_plotstring("Press any key to continue", 160, 150); uip_getchar(); @@ -1204,13 +1328,13 @@ int ui_saveimage(const char *type, char uint16 *line; /* get the bank that we're not writing/reading to now */ scr = (ui_uipinfo.screenmem_w == ui_uipinfo.screenmem0) ? - ui_uipinfo.screenmem1 : ui_uipinfo.screenmem0; + ui_uipinfo.screenmem1 : ui_uipinfo.screenmem0; for (y = 0; y < 480; y++) { line = (uint16 *)(scr + y * ui_uipinfo.linewidth); for (i = 0; i < 640; i++) { - out[0] = ((line[i]>>ui_uipinfo.redshift) & 0x1f) << 3; - out[1] = ((line[i]>>ui_uipinfo.greenshift) & 0x1f) << 3; - out[2] = ((line[i]>>ui_uipinfo.blueshift) & 0x1f) << 3; + out[0] = ((line[i] >> ui_uipinfo.redshift) & 0x1f) << 3; + out[1] = ((line[i] >> ui_uipinfo.greenshift) & 0x1f) << 3; + out[2] = ((line[i] >> ui_uipinfo.blueshift) & 0x1f) << 3; count = write(fd, out, 3); if (count == -1) { LOG_CRITICAL(("Error whilst writing to output image file: %s", @@ -1228,15 +1352,15 @@ int ui_saveimage(const char *type, char *ysize = 480; } else if (!strcasecmp(type, "game")) { uint16 data; - uint16 *scr = uip_whichbank() ? ui_screen0 : ui_screen1; + uint16 *scr = uip_whichbank()? ui_screen0 : ui_screen1; *xsize = (vdp_reg[12] & 1) ? 320 : 256; *ysize = vdp_vislines; for (y = 0; y < *ysize; y++) { for (i = 0; i < *xsize; i++) { - data = scr[320*y+i]; - out[0] = ((data>>ui_uipinfo.redshift) & 0x1f) << 3; - out[1] = ((data>>ui_uipinfo.greenshift) & 0x1f) << 3; - out[2] = ((data>>ui_uipinfo.blueshift) & 0x1f) << 3; + data = scr[320 * y + i]; + out[0] = ((data >> ui_uipinfo.redshift) & 0x1f) << 3; + out[1] = ((data >> ui_uipinfo.greenshift) & 0x1f) << 3; + out[2] = ((data >> ui_uipinfo.blueshift) & 0x1f) << 3; count = write(fd, out, 3); if (count == -1) { LOG_CRITICAL(("Error whilst writing to output image file: %s", @@ -1299,14 +1423,14 @@ int ui_saveimage(const char *type, char } #endif -LOG_FUNC(debug3, 7, "DEBG "); -LOG_FUNC(debug2, 6, "DEBG "); -LOG_FUNC(debug1, 5, "DEBG "); -LOG_FUNC(user, 4, "USER "); -LOG_FUNC(verbose, 3, "---- "); -LOG_FUNC(normal, 2, "---- "); +LOG_FUNC(debug3, 7, "DEBG "); +LOG_FUNC(debug2, 6, "DEBG "); +LOG_FUNC(debug1, 5, "DEBG "); +LOG_FUNC(user, 4, "USER "); +LOG_FUNC(verbose, 3, "---- "); +LOG_FUNC(normal, 2, "---- "); LOG_FUNC(critical, 1, "CRIT "); -LOG_FUNC(request, 0, "---- "); /* this generates a warning, such is life */ +LOG_FUNC(request, 0, "---- "); /* this generates a warning, such is life */ /*** ui_err - log error message and quit ***/ @@ -1320,12 +1444,12 @@ void ui_err(const char *text, ...) vfprintf(stderr, text, ap); va_end(ap); putc(10, stderr); - exit(0); /* don't exit(1) because windows makes an error then! */ + exit(0); /* don't exit(1) because windows makes an error then! */ } /*** ui_setinfo - there is new cart information ***/ -char *ui_setinfo(t_cartinfo *cartinfo) +char *ui_setinfo(t_cartinfo * cartinfo) { return NULL; } @@ -1335,9 +1459,9 @@ char *ui_setinfo(t_cartinfo *cartinfo) int ui_topbit(unsigned long int bits) { long int bit = 31; - unsigned long int mask = 1<<31; + unsigned long int mask = 1 << 31; - for (; bit >= 0; bit--, mask>>= 1) { + for (; bit >= 0; bit--, mask >>= 1) { if (bits & mask) return bit; }