NROM_Mapper::NROM_Mapper(Cartridge *cart) : Memory_Mapper(cart) { prg_banks.resize(NUM_BANKS); set_mirrored(cart->get_header().get_prg_rom_size_16KB()); load_prg(cart->get_prg_rom()); cartridge = NULL; }
bool Loader::emulate() { if(booted_up_) { switch(format_) { case kBasic: load_basic(); break; case kPRG: load_prg(); break; default: break; } return false; } else { /* at this point BASIC is ready */ if(cpu_->pc() == 0xa65c) booted_up_ = true; } return true; }
int autostart_prg_with_ram_injection(const char *file_name, fileio_info_t *fh) { /* clean up old injection */ if (inject_prg != NULL) { free_prg(inject_prg); } /* load program file into memory */ inject_prg = load_prg(file_name, fh); return (inject_prg == NULL) ? -1 : 0; }
int autostart_prg_with_disk_image(const char *file_name, fileio_info_t *fh, log_t log, const char *image_name) { const int drive = 8; const int secondary = 1; autostart_prg_t *prg; vdrive_t *vdrive; int i; int old_tde_state; int file_name_size; BYTE data; unsigned int disk_image_type; int result, result2; /* identify disk image type */ switch (drive_get_disk_drive_type(drive - 8)) { case DRIVE_TYPE_1540: case DRIVE_TYPE_1541: case DRIVE_TYPE_1541II: case DRIVE_TYPE_1551: case DRIVE_TYPE_1570: case DRIVE_TYPE_2031: disk_image_type = DISK_IMAGE_TYPE_D64; break; case DRIVE_TYPE_2040: case DRIVE_TYPE_3040: case DRIVE_TYPE_4040: disk_image_type = DISK_IMAGE_TYPE_D67; break; case DRIVE_TYPE_1571: case DRIVE_TYPE_1571CR: disk_image_type = DISK_IMAGE_TYPE_D71; break; case DRIVE_TYPE_1581: case DRIVE_TYPE_2000: case DRIVE_TYPE_4000: disk_image_type = DISK_IMAGE_TYPE_D81; break; case DRIVE_TYPE_8050: disk_image_type = DISK_IMAGE_TYPE_D80; break; case DRIVE_TYPE_8250: case DRIVE_TYPE_1001: disk_image_type = DISK_IMAGE_TYPE_D82; break; default: log_error(log, "No idea what disk image format to use."); return -1; } /* read prg file */ prg = load_prg(file_name, fh, log); if (prg == NULL) { return -1; } /* disable TDE */ resources_get_int("DriveTrueEmulation", &old_tde_state); if (old_tde_state != 0) { log_message(log, "Turning true drive emulation off."); resources_set_int("DriveTrueEmulation", 0); } do { result = -1; /* create empty image */ if (vdrive_internal_create_format_disk_image(image_name, (char *)"AUTOSTART", disk_image_type) < 0) { log_error(log, "Error creating autostart disk image: %s", image_name); break; } /* attach disk image */ if (file_system_attach_disk(drive, image_name) < 0) { log_error(log, "Could not attach disk image: %s", image_name); break; } /* get vdrive */ vdrive = file_system_get_vdrive((unsigned int)drive); if (vdrive == NULL) { break; } /* get file name size */ file_name_size = strlen((const char *)fh->name); if (file_name_size > 16) { file_name_size = 16; } /* open file on disk */ if (vdrive_iec_open(vdrive, (const BYTE *)fh->name, file_name_size, secondary, NULL) != SERIAL_OK) { log_error(log, "Could not open file"); break; } result2 = 0; /* write PRG data to file */ for (i = -2; i < (int)prg->size; i++) { switch (i) { case -2: data = (BYTE)prg->start_addr; break; case -1: data = (BYTE)(prg->start_addr >> 8); break; default: data = prg->data[i]; break; } if (vdrive_iec_write(vdrive, data, secondary) != SERIAL_OK) { log_error(log, "Could not write file"); result2 = -1; break; } } /* close file */ if (vdrive_iec_close(vdrive, secondary) != SERIAL_OK) { log_error(log, "Could not close file"); break; } result = result2; } while (0); /* free prg file */ free_prg(prg); /* re-enable TDE */ if (old_tde_state != 0) { log_message(log, "Turning true drive emulation on."); resources_set_int("DriveTrueEmulation", old_tde_state); } /* ready */ return result; }
int autostart_prg_with_disk_image(const char *file_name, fileio_info_t *fh, const char *image_name) { const int drive = 8; const int secondary = 1; autostart_prg_t *prg; vdrive_t *vdrive; int i; int old_tde_state; int file_name_size; BYTE lo,hi; /* read prg file */ prg = load_prg(file_name, fh); if (prg == NULL) { return -1; } /* disable TDE */ resources_get_int("DriveTrueEmulation", &old_tde_state); if (old_tde_state != 0) resources_set_int("DriveTrueEmulation", 0); /* create empty image */ if (vdrive_internal_create_format_disk_image(image_name, (char *)"AUTOSTART", DISK_IMAGE_TYPE_D64) <0 ) { //log_error(log, "Error creating autostart disk image: %s", image_name); free_prg(prg); return -1; } /* attach disk image */ if (file_system_attach_disk(drive, image_name) < 0) { //log_error(log, "Could not attach disk image: %s", image_name); free_prg(prg); return -1; } /* copy file to disk */ vdrive = file_system_get_vdrive((unsigned int)drive); if (vdrive == NULL) { free_prg(prg); return -1; } /* get file name size */ file_name_size = strlen((const char *)fh->name); if (file_name_size > 16) { file_name_size = 16; } /* open file on disk */ if (vdrive_iec_open(vdrive, (const BYTE *)fh->name, file_name_size, secondary, NULL) != SERIAL_OK) { //log_error(log, "Could not open file"); free_prg(prg); return -1; } /* write start address to file */ lo = (BYTE)(prg->start_addr & 0xff); hi = (BYTE)((prg->start_addr >> 8) & 0xff); if ((vdrive_iec_write(vdrive, lo, secondary) != SERIAL_OK) || (vdrive_iec_write(vdrive, hi, secondary) != SERIAL_OK)) { //log_error(log, "Could not write file"); free_prg(prg); return -1; } /* write PRG data to file */ for (i = 0; i < prg->size; i++) { if (vdrive_iec_write(vdrive, prg->data[i], secondary) != SERIAL_OK) { //log_error(log, "Could not write file"); free_prg(prg); return -1; } } /* close file */ if (vdrive_iec_close(vdrive, secondary) != SERIAL_OK) { //log_error(log, "Could not close file"); free_prg(prg); return -1; } /* free prg file */ free_prg(prg); /* re-enable TDE */ if (old_tde_state != 0) resources_set_int("DriveTrueEmulation", old_tde_state); /* ready */ return 0; }
void draw_options(C64 *TheC64) { char *imagefile; char loadprg[255]; int i; static int cursor_pos=3; static Prefs *prefs=NULL; int update_prefs=0; uint16 bg, fg; static int getfilename=0; static int xfiletype; static int set_buttons; static int menu_y=3; static int menu_x=5; static int is_moving=0; static int threshold=10; static int stepping=2; #ifndef SPMP static int gpcpu_speed=133; #endif static int load_snapshot=0; static int save_snapshot=0; enum { D64, LOADSTAR, LOADER, PRG, RESET64, BLANK1, SOUND, BRIGHTNESS, CONTRAST, FRAMESKIP, LIMITSPEED, JOYSTICK, EMU1541CPU, BLANK2, BUTTONS, #ifndef SPMP CHATBOARD, #endif BLANK3, LOAD_SNAP, SAVE_SNAP, BLANK4, #ifndef SPMP DEBUG, RESETGP, #endif NUM_OPTIONS, #ifndef SPMP CPU_SPEED, /* WTF does this come after NUM_OPTIONS?? */ #endif }; const char *option_txt[NUM_OPTIONS+5]; option_txt[SOUND]= "Sound "; option_txt[BRIGHTNESS]= "Brightness "; option_txt[CONTRAST]= "Contrast "; option_txt[FRAMESKIP]= "Frameskip "; option_txt[LIMITSPEED]= "Limit speed "; option_txt[JOYSTICK]= "Joystick in port "; option_txt[EMU1541CPU]= "1541 CPU emulation "; option_txt[D64]= "Attach d64/t64/dir... "; option_txt[LOADSTAR]= "Load first program "; option_txt[LOADER]= "Load d64/dir browser "; option_txt[PRG]= "Load .prg file... "; option_txt[SAVE_SNAP]= "Save snapshot... "; option_txt[LOAD_SNAP]= "Load snapshot... "; #ifndef SPMP option_txt[CPU_SPEED]= "gp32 CPU speed "; option_txt[CHATBOARD]= "Chatboard "; #endif option_txt[BUTTONS]= "Set buttons... "; option_txt[RESET64]= "Reset C=64 "; #ifndef SPMP option_txt[DEBUG]= "Debug console "; option_txt[RESETGP]= "Restart GP32 "; #endif option_txt[BLANK1]= " "; option_txt[BLANK2]= " "; option_txt[BLANK3]= " "; option_txt[BLANK4]= " "; option_txt[NUM_OPTIONS]= " "; option_txt[NUM_OPTIONS+1]= " "; option_txt[NUM_OPTIONS+2]= " "; option_txt[NUM_OPTIONS+3]= " "; option_txt[NUM_OPTIONS+4]= NULL; char brightness_txt[3]=" "; char frameskip_txt[3]=" "; char contrast_txt[4]=" . "; uint8 menu_bg=14; uint8 menu_fg=6; uint8 menu_selbg=7; uint8 menu_selfg=6; if(load_snapshot||save_snapshot) { int sn=draw_snapshotui(TheC64, save_snapshot, prefs->DrivePath[0]); if(sn==-1) { // exit from snapshot ui load_snapshot=0; save_snapshot=0; } else if(!sn) { // snapshot ui stays open return; } else { // exit snapshot and options ui load_snapshot=0; save_snapshot=0; options_enabled=0; return; } } if(getfilename) { imagefile=filerequest(NULL); if(imagefile==NULL) { return; } else if (imagefile==(char *)-1) { getfilename=0; } else { if(xfiletype==0) { //printf("setting DrivePath[0] to -%s-\n", imagefile); strcpy(prefs->DrivePath[0], imagefile); update_prefs=1; cursor_pos=menu_y+LOADSTAR; } else if(xfiletype==1) { for(i=strlen(imagefile); i>0; i--) { if(imagefile[i]=='/') break; } strcpy(loadprg, "\rLOAD\""); strcat(loadprg, imagefile+i+1); strcat(loadprg, "\",8,1\rRUN\r"); imagefile[i]='\0'; strcpy(prefs->DrivePath[0], imagefile); for(i=0; loadprg[i]; i++) loadprg[i]=toupper(loadprg[i]); kbd_buf_feed(loadprg); update_prefs=1; options_enabled=0; } getfilename=0; } } if(set_buttons) { if(draw_buttonsui()) set_buttons=0; button_state&=~X_PRESSED; return; } if(prefs==NULL) prefs=new Prefs(ThePrefs); for(i=0; option_txt[i]; i++) { if(cursor_pos==(menu_y+i)) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, option_txt[i], bg, fg, menu_x, menu_y+i, 0); } // sound state if(prefs->SIDType==SIDTYPE_NONE) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "Off ", bg, fg, menu_x+20, menu_y+SOUND, 0); if(prefs->SIDType==SIDTYPE_DIGITAL) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "On ", bg, fg, menu_x+24, menu_y+SOUND, 0); bg=menu_bg; fg=menu_fg; // brightness brightness_txt[0]=(char)(0x30+((brightness%100)/10)); brightness_txt[1]=(char)(0x30+((brightness%100)%10)); text_out8((uint8 *)gp.pixels, brightness_txt, bg, fg, menu_x+20, menu_y+BRIGHTNESS, 0); // contrast contrast_txt[0]=(char)(0x30+((contrast%100)/10)); contrast_txt[2]=(char)(0x30+((contrast%100)%10)); text_out8((uint8 *)gp.pixels, contrast_txt, bg, fg, menu_x+20, menu_y+CONTRAST, 0); // frameskip frameskip_txt[0]=(char)(0x30+(((prefs->SkipFrames-1)%100)/10)); frameskip_txt[1]=(char)(0x30+(((prefs->SkipFrames-1)%100)%10)); text_out8((uint8 *)gp.pixels, frameskip_txt, bg, fg, menu_x+20, menu_y+FRAMESKIP, 0); // limit speed if(prefs->LimitSpeed==false) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "Off ", bg, fg, menu_x+20, menu_y+LIMITSPEED, 0); if(prefs->LimitSpeed==true) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "On ", bg, fg, menu_x+24, menu_y+LIMITSPEED, 0); bg=menu_bg; fg=menu_fg; // current joyport if(current_joystick==0) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "1 ", bg, fg, menu_x+20, menu_y+JOYSTICK, 0); if(current_joystick==1) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "2 ", bg, fg, menu_x+24, menu_y+JOYSTICK, 0); // 1541 cpu if(prefs->Emul1541Proc==false) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "Off ", bg, fg, menu_x+20, menu_y+EMU1541CPU, 0); if(prefs->Emul1541Proc==true) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "On ", bg, fg, menu_x+24, menu_y+EMU1541CPU, 0); // reset type if(prefs->FastReset==false) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "slow", bg, fg, menu_x+20, menu_y+RESET64, 0); if(prefs->FastReset==true) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "fast", bg, fg, menu_x+24, menu_y+RESET64, 0); #ifndef SPMP // chatboard if(!chatboard_enabled) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "Off ", bg, fg, menu_x+20, menu_y+CHATBOARD, 0); if(chatboard_enabled) { bg=menu_selbg; fg=menu_selfg; } else { bg=menu_bg; fg=menu_fg; } text_out8((uint8 *)gp.pixels, "On ", bg, fg, menu_x+24, menu_y+CHATBOARD, 0); #endif i=menu_y+NUM_OPTIONS+1; // display attached file bg=menu_bg; fg=menu_fg; text_out8((uint8 *)gp.pixels, "drive 8 img: ", bg, fg, menu_x, i++, 0); text_out8((uint8 *)gp.pixels, prefs->DrivePath[0], bg, fg, menu_x, i++, 0); text_out8((uint8 *)gp.pixels, "Press select to load", bg, fg, menu_x, i++, 0); if(button_state&X_PRESSED) { button_state&=~(X_PRESSED); if(cursor_pos==menu_y+LOADSTAR) { kbd_buf_feed("\rLOAD\":*\",8,1:\rRUN\r"); options_enabled=0; } if(cursor_pos==menu_y+LOADER) { load_prg(TheC64, c64loader, sizeof(c64loader)); kbd_buf_feed("\rLOAD\"X\",8,1\rRUN\r"); options_enabled=0; } if(cursor_pos==menu_y+D64) { getfilename=1; xfiletype=0; } else if(cursor_pos==menu_y+PRG) { getfilename=1; xfiletype=1; } else if(cursor_pos==menu_y+RESET64) { TheC64->Reset(); options_enabled=0; } else if(cursor_pos==menu_y+SAVE_SNAP) { //remove("/smfs/gpmm/c64/frodo/snap1"); //TheC64->SaveSnapshot("/smfs/gpmm/c64/frodo/snap1"); //options_enabled=0; save_snapshot=1; } else if(cursor_pos==menu_y+LOAD_SNAP) { //TheC64->LoadSnapshot("/smfs/gpmm/c64/frodo/snap1"); //options_enabled=0; load_snapshot=1; } else if(cursor_pos==menu_y+BUTTONS) { set_buttons=1; #ifndef SPMP } else if(cursor_pos==menu_y+DEBUG) { switch_console(); #endif /*} else if(cursor_pos==10) { app_execute(prefs->DrivePath[0]);*/ #ifndef SPMP } else if(cursor_pos==menu_y+RESETGP) { gp32reboot(); #endif } } if(button_state&UP_PRESSED) { if(is_moving==0||((is_moving>threshold)&&(is_moving%stepping==0))) { if(cursor_pos>menu_y) cursor_pos--; } is_moving++; } else if(button_state&DOWN_PRESSED) { if(is_moving==0||((is_moving>threshold)&&(is_moving%stepping==0))) { if(cursor_pos<menu_y+NUM_OPTIONS-1) cursor_pos++; } is_moving++; } else { is_moving=0; } if(button_state&LEFT_PRESSED) { #ifndef SPMP if(cursor_pos==menu_y+CPU_SPEED) { if(gpcpu_speed==133) { gpcpu_speed=100; printf("setting cpu speed to 100mhz\n"); //cpu_speed(102000000, (43<<12) | (1<<4) | 1, 2); } } #endif if(cursor_pos==menu_y+SOUND) { prefs->SIDType=SIDTYPE_NONE; update_prefs=1; } if(cursor_pos==menu_y+BRIGHTNESS) { if(brightness>0) { brightness--; //ui_set_palette(); } } if(cursor_pos==menu_y+CONTRAST) { if(contrast>0) { contrast--; //ui_set_palette(); } } if(cursor_pos==menu_y+FRAMESKIP) { if(prefs->SkipFrames>1) { prefs->SkipFrames--; update_prefs=1; } } if(cursor_pos==menu_y+LIMITSPEED) { prefs->LimitSpeed=false; update_prefs=1; } if(cursor_pos==menu_y+JOYSTICK) { current_joystick=0; } if(cursor_pos==menu_y+EMU1541CPU) { prefs->Emul1541Proc=false; update_prefs=1; } if(cursor_pos==menu_y+RESET64) { prefs->FastReset=false; update_prefs=1; } #ifndef SPMP if(cursor_pos==menu_y+CHATBOARD) { disable_chatboard(); } #endif } else if(button_state&RIGHT_PRESSED) { #ifndef SPMP if(cursor_pos==menu_y+CPU_SPEED) { if(gpcpu_speed==100) { gpcpu_speed=133; printf("setting cpu speed to 133mhz\n"); //cpu_speed(133500000, (81<<12) | (2<<4) | 1, 2); } } #endif if(cursor_pos==menu_y+SOUND) { prefs->SIDType=SIDTYPE_DIGITAL; update_prefs=1; } if(cursor_pos==menu_y+BRIGHTNESS) { if(brightness<25) { brightness++; //ui_set_palette(); } } if(cursor_pos==menu_y+CONTRAST) { if(contrast<100) { contrast++; //ui_set_palette(); } } if(cursor_pos==menu_y+FRAMESKIP) { if(prefs->SkipFrames<100) { prefs->SkipFrames++; update_prefs=1; } } if(cursor_pos==menu_y+LIMITSPEED) { prefs->LimitSpeed=true; update_prefs=1; } if(cursor_pos==menu_y+JOYSTICK) { current_joystick=1; } if(cursor_pos==menu_y+EMU1541CPU) { prefs->Emul1541Proc=true; update_prefs=1; } if(cursor_pos==menu_y+RESET64) { prefs->FastReset=true; update_prefs=1; } #if 0 if(cursor_pos==menu_y+CHATBOARD) { enable_chatboard(); } #endif } if(update_prefs) { //printf("updating prefs\n"); TheC64->NewPrefs(prefs); ThePrefs=*prefs; delete prefs; prefs=NULL; update_prefs=0; } }