int MastExit() { MastSetRom(NULL,0); // Exit space for the machine state memset(&Masta,0,sizeof(Masta)); if (pMastb!=NULL) free(pMastb); pMastb=NULL; memset(&Mastz,0,sizeof(Mastz)); return 0; }
static PyObject *pydega_load_rom(PyObject *self, PyObject *args) { const char *file; unsigned char *rom; int romlength; int rv; if (!PyArg_ParseTuple(args, "s", &file)) return NULL; rv = MastLoadRom(file, &rom, &romlength); if (rv != 0) return PyErr_SetFromErrno(PyExc_IOError); MastSetRom(rom, romlength); Py_RETURN_NONE; }
int MastInit() { MdrawInit(); // Init space for the machine state memset(&Masta,0,sizeof(Masta)); pMastb=(struct Mastb *)malloc(sizeof(*pMastb)); if (pMastb==NULL) return 1; memset(&Mastz,0,sizeof(Mastz)); MastSetRom(NULL,0); #ifdef EMU_Z80JB MastSetMemHandlers(); Z80Init(); #elif defined(EMU_DRZ80) MastSetMemHandlers(); DrZ80_Init(); #endif return 0; }
int main(int argc, char** argv) { unsigned char* rom; int romlength; int done=0; SDL_Event event; int key; SDL_AudioSpec aspec; unsigned char* audiobuf; int paused=0, frameadvance=0; // options int autodetect=1; int sound=1; setlocale(LC_CTYPE, ""); readonly = 0; MPyEmbed_SetArgv(argc, argv); while(1) { int option_index=0; int copt; static struct option long_options[] = { {"help",0,0,0}, {"version",no_argument,NULL,'v'}, {"gamegear",no_argument,NULL,'g'}, {"sms",no_argument,NULL,'m'}, {"pal",no_argument,NULL,'p'}, {"japan",no_argument,NULL,'j'}, {"nosound",no_argument,NULL,'q'}, {"fullscreen",no_argument,NULL,'f'}, {"readonly",no_argument,NULL,'r'}, {"sram",no_argument,NULL,'s'}, {0,0,0,0} }; copt=getopt_long(argc,argv,"vgmpjqfrs",long_options,&option_index); if(copt==-1) break; switch(copt) { case 0: if(strcmp(long_options[option_index].name,"help")==0) usage(); break; case 'v': printf("%s",VERSION "\n"); exit(0); case 'g': autodetect=0; MastEx |= MX_GG; break; case 'm': autodetect=0; MastEx &= ~MX_GG; break; case 'p': MastEx |= MX_PAL; framerate=50; break; case 'j': MastEx |= MX_JAPAN; break; case 'q': sound=0; break; case 'f': vidflags |= SDL_FULLSCREEN; break; case 'r': readonly = 1; break; case 's': MastEx |= MX_SRAM; break; case '?': usage(); break; } } if(optind==argc) { fprintf(stderr,APPNAME ": no ROM image specified.\n"); exit(1); } atexit(SDL_Quit); if(sound) SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); else SDL_Init(SDL_INIT_VIDEO); MastInit(); MastLoadRom(argv[optind], &rom, &romlength); MastSetRom(rom,romlength); if (autodetect) MastFlagsFromHeader(); MastHardReset(); memset(&MastInput,0,sizeof(MastInput)); width=MastEx&MX_GG?160:256; height=MastEx&MX_GG?144:192; thescreen=SDL_SetVideoMode(width, height, 15, SDL_SWSURFACE|vidflags); if(sound) { MsndRate=44100; MsndLen=(MsndRate+(framerate>>1))/framerate; //guess aspec.freq=MsndRate; aspec.format=AUDIO_S16; aspec.channels=2; aspec.samples=1024; audiobuf=malloc(aspec.samples*aspec.channels*2*64); memset(audiobuf,0,aspec.samples*aspec.channels*2); aspec.callback=MsndCall; pMsndOut=malloc(MsndLen*aspec.channels*2); aspec.userdata=audiobuf; if(SDL_OpenAudio(&aspec,NULL)) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); sound=0; } SDL_PauseAudio(0); MsndInit(); } else {