void ui_init(SDL_Surface *screen, button **buttons, bool edgeload, bool pause, bool keyboard, bool printer) { static button btn[nbuttons]; *buttons=btn; for(unsigned int i=0;i<nbuttons;i++) { btn[i].img=NULL; btn[i].tooltip=NULL; } char title[64]; snprintf(title, 64, "Spiffy - ZX Spectrum %s", name_from_machine(zx_machine)); SDL_WM_SetCaption(title, "Spiffy"); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_FillRect(screen, &(SDL_Rect){0, y_cntl, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+1, screen->w, 63}, SDL_MapRGB(screen->format, 0, 0, 0)); // controls area SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+64, screen->w, 16}, SDL_MapRGB(screen->format, 63, 63, 63)); // status bar if(keyboard) { for(unsigned int i=0;i<10;i++) km[i]=configIMG_Load(kmn[i]); SDL_FillRect(screen, &(SDL_Rect){0, y_keyb, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160}, SDL_MapRGB(screen->format, 0, 0, 0)); if(km[0]) SDL_BlitSurface(km[0], NULL, screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160}); } if(printer) { SDL_FillRect(screen, &(SDL_Rect){0, y_prnt, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_FillRect(screen, &(SDL_Rect){0, y_prnt+1, screen->w, 119}, SDL_MapRGB(screen->format, 31, 31, 31)); // printer area SDL_FillRect(screen, &(SDL_Rect){32, y_prnt+100, 256, 20}, SDL_MapRGB(screen->format, 191, 191, 195)); // printer paper } FILE *fimg; string img; fimg=configopen("buttons/load.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[0]=(button){.img=pbm_string(img), .posn={116, y_cntl+2, 17, 17}, .col=0x8f8f1f, .tooltip="Load a tape image or snapshot"}; free_string(&img); fimg=configopen("buttons/flash.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[1]=(button){.img=pbm_string(img), .posn={136, y_cntl+2, 17, 17}, .col=edgeload?0xffffff:0x1f1f1f, .tooltip=edgeload?"Disable edge-loader":"Enable edge-loader"}; free_string(&img); fimg=configopen("buttons/play.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[2]=(button){.img=pbm_string(img), .posn={156, y_cntl+2, 17, 17}, .col=0x3fbf5f, .tooltip="Play the virtual tape"}; free_string(&img); fimg=configopen("buttons/next.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[3]=(button){.img=pbm_string(img), .posn={176, y_cntl+2, 17, 17}, .col=0x07079f, .tooltip="Skip to the next tape block"}; free_string(&img); fimg=configopen("buttons/stop.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[4]=(button){.img=pbm_string(img), .posn={196, y_cntl+2, 17, 17}, .col=0x3f0707, .tooltip="Stop the tape at the end of each block"}; free_string(&img); fimg=configopen("buttons/rewind.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[5]=(button){.img=pbm_string(img), .posn={216, y_cntl+2, 17, 17}, .col=0x7f076f, .tooltip="Rewind to the beginning of the tape"}; free_string(&img); fimg=configopen("buttons/pause.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[6]=(button){.img=pbm_string(img), .posn={8, y_cntl+44, 17, 17}, .col=pause?0xbf6f07:0x7f6f07, .tooltip=pause?"Unpause the emulation":"Pause the emulation"}; free_string(&img); fimg=configopen("buttons/reset.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[7]=(button){.img=pbm_string(img), .posn={28, y_cntl+44, 17, 17}, .col=0xffaf07, .tooltip="Reset the Spectrum"}; free_string(&img); fimg=configopen("buttons/bug.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[8]=(button){.img=pbm_string(img), .posn={48, y_cntl+44, 17, 17}, .col=0xbfff3f, .tooltip="Start the debugger"}; free_string(&img); #ifdef AUDIO btn[9].posn=(SDL_Rect){76, 321, 7, 6}; btn[10].posn=(SDL_Rect){76, 328, 7, 6}; btn[11].posn=(SDL_Rect){136, 321, 7, 6}; btn[12].posn=(SDL_Rect){136, 328, 7, 6}; fimg=configopen("buttons/record.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[13]=(button){.img=pbm_string(img), .posn={8, y_cntl+24, 17, 17}, .col=0x7f0707, .tooltip="Record audio"}; drawbutton(screen, btn[13]); free_string(&img); #endif /* AUDIO */ fimg=configopen("buttons/snap.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[14]=(button){.img=pbm_string(img), .posn={68, y_cntl+44, 17, 17}, .col=0xbfbfbf, .tooltip="Save a snapshot"}; drawbutton(screen, btn[14]); free_string(&img); fimg=configopen("buttons/trec.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[15]=(button){.img=pbm_string(img), .posn={236, y_cntl+2, 17, 17}, .col=0x4f0f0f, .tooltip="Record tape"}; drawbutton(screen, btn[15]); free_string(&img); fimg=configopen("buttons/feed.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[16]=(button){.img=pbm_string(img), .posn={88, y_cntl+44, 17, 17}, .col=printer?0x3f276f:0x170f1f, .tooltip=printer?"ZX Printer: Paper feed":"ZX Printer is disabled"}; drawbutton(screen, btn[16]); free_string(&img); fimg=configopen("buttons/js_c.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[17]=(button){.img=pbm_string(img), .posn={108, y_cntl+44, 9, 9}, .col=0x3fff3f, .tooltip="Select CURSOR keystick"}; free_string(&img); fimg=configopen("buttons/js_s.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[18]=(button){.img=pbm_string(img), .posn={116, y_cntl+44, 9, 9}, .col=0x3f3f3f, .tooltip="Select SINCLAIR keystick"}; free_string(&img); fimg=configopen("buttons/js_k.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[19]=(button){.img=pbm_string(img), .posn={108, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Select KEMPSTON keystick"}; free_string(&img); fimg=configopen("buttons/js_x.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[20]=(button){.img=pbm_string(img), .posn={116, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Disable keystick"}; free_string(&img); ksupdate(screen, *buttons, JS_C); fimg=configopen("buttons/bw.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[21]=(button){.img=pbm_string(img), .posn={128, y_cntl+44, 17, 17}, .col=0x9f9f9f, .tooltip="Enable Black&White filter"}; drawbutton(screen, btn[21]); free_string(&img); fimg=configopen("buttons/scan.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[22]=(button){.img=pbm_string(img), .posn={148, y_cntl+44, 17, 17}, .col=0x5f5fcf, .tooltip="Enable TV Scanlines filter"}; drawbutton(screen, btn[22]); free_string(&img); fimg=configopen("buttons/blur.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[23]=(button){.img=pbm_string(img), .posn={168, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Horizontal Blur filter"}; drawbutton(screen, btn[23]); free_string(&img); fimg=configopen("buttons/vblur.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[24]=(button){.img=pbm_string(img), .posn={188, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Vertical Blur filter"}; drawbutton(screen, btn[24]); free_string(&img); fimg=configopen("buttons/misg.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[25]=(button){.img=pbm_string(img), .posn={208, y_cntl+44, 17, 17}, .col=0x1f5f1f, .tooltip="Enable Misaligned Green filter"}; drawbutton(screen, btn[25]); free_string(&img); fimg=configopen("buttons/slow.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[26]=(button){.img=pbm_string(img), .posn={228, y_cntl+44, 17, 17}, .col=0x8f8faf, .tooltip="Enable Slow Fade filter"}; drawbutton(screen, btn[26]); free_string(&img); fimg=configopen("buttons/pal.pbm", "rb"); img=sslurp(fimg); if(fimg) fclose(fimg); btn[27]=(button){.img=pbm_string(img), .posn={248, y_cntl+44, 17, 17}, .col=0x4f4f4f, .tooltip="Enable PAL Chroma Distortion filter"}; drawbutton(screen, btn[27]); free_string(&img); for(unsigned int i=0;i<9;i++) drawbutton(screen, btn[i]); }
static Boolean __SCDynamicStoreAddSession(SCDynamicStorePrivateRef storePrivate) { kern_return_t kr = KERN_SUCCESS; CFDataRef myName; /* serialized name */ xmlData_t myNameRef; CFIndex myNameLen; CFDataRef myOptions = NULL; /* serialized options */ xmlData_t myOptionsRef = NULL; CFIndex myOptionsLen = 0; int sc_status = kSCStatusFailed; mach_port_t server; if (!_SCSerializeString(storePrivate->name, &myName, (void **)&myNameRef, &myNameLen)) { goto done; } /* serialize the options */ if (storePrivate->options != NULL) { if (!_SCSerialize(storePrivate->options, &myOptions, (void **)&myOptionsRef, &myOptionsLen)) { CFRelease(myName); goto done; } } /* open a new session with the server */ server = MACH_PORT_NULL; updateServerPort(storePrivate, &server, &sc_status); while (server != MACH_PORT_NULL) { // if SCDynamicStore server available if (!storePrivate->serverNullSession) { // if SCDynamicStore session kr = configopen(server, myNameRef, (mach_msg_type_number_t)myNameLen, myOptionsRef, (mach_msg_type_number_t)myOptionsLen, &storePrivate->server, (int *)&sc_status); } else { // if NULL session if (storePrivate->server == MACH_PORT_NULL) { // use the [main] SCDynamicStore server port kr = mach_port_mod_refs(mach_task_self(), server, MACH_PORT_RIGHT_SEND, +1); if (kr == KERN_SUCCESS) { storePrivate->server = server; sc_status = kSCStatusOK; } else { storePrivate->server = MACH_PORT_NULL; } } else { // if the server port we used returned an error storePrivate->server = MACH_PORT_NULL; kr = MACH_SEND_INVALID_DEST; } } if (kr == KERN_SUCCESS) { break; } // our [cached] server port is not valid if ((kr != MACH_SEND_INVALID_DEST) && (kr != MIG_SERVER_DIED)) { // if we got an unexpected error, don't retry sc_status = kr; break; } updateServerPort(storePrivate, &server, &sc_status); } __MACH_PORT_DEBUG(TRUE, "*** SCDynamicStoreAddSession", storePrivate->server); // clean up CFRelease(myName); if (myOptions != NULL) CFRelease(myOptions); done : switch (sc_status) { case kSCStatusOK : return TRUE; case BOOTSTRAP_UNKNOWN_SERVICE : SCLog(TRUE, (kr == KERN_SUCCESS) ? LOG_DEBUG : LOG_ERR, CFSTR("SCDynamicStore server not available")); sc_status = kSCStatusNoStoreServer; break; default : SCLog(TRUE, (kr == KERN_SUCCESS) ? LOG_DEBUG : LOG_ERR, CFSTR("SCDynamicStoreAddSession configopen(): %s"), SCErrorString(sc_status)); break; } _SCErrorSet(sc_status); return FALSE; }