| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <stdio.h> |
| #include <string.h> |
| #include <ctype.h> |
| #include "integer.h" |
| #include "dump_hex.h" |
| #include "c64.h" |
| #include "u64.h" |
| #include "c64_crt.h" |
| #include "flash.h" |
| #include "keyboard_c64.h" |
| #include "config.h" |
| #if U64 |
| #include "u64_machine.h" |
| #endif |
|
|
| #ifndef CMD_IF_SLOT_BASE |
| #define CMD_IF_SLOT_BASE *((volatile uint8_t *)(CMD_IF_BASE + 0x0)) |
| #define CMD_IF_SLOT_ENABLE *((volatile uint8_t *)(CMD_IF_BASE + 0x1)) |
| #endif |
|
|
| #ifndef NO_FILE_ACCESS |
| #include "filemanager.h" |
| #include "FreeRTOS.h" |
| #include "task.h" |
| #include "filetype_crt.h" |
| #include "modem.h" |
| #endif |
|
|
| #ifndef RECOVERYAPP |
| extern bool connectedToU64; |
| #endif |
|
|
| |
| static const char *reu_size[] = { "128 KB", "256 KB", "512 KB", "1 MB", "2 MB", "4 MB", "8 MB", "16 MB" }; |
| static const char *reu_offset[] = { "0 KB", "128 KB", "256 KB", "512 KB", "1 MB", "2 MB", "4 MB", "8 MB", "16 MB" }; |
| static const char *buttons[] = { "Reset|Menu|Freezer", "Freezer|Menu|Reset" }; |
| static const char *timing1[] = { "20ns", "40ns", "60ns", "80ns", "100ns", "120ns", "140ns", "160ns", "180ns", "200ns", "220ns", "240ns", "260ns", "280ns", "300ns", "320ns" }; |
| static const char *timing2[] = { "16ns", "32ns", "48ns", "64ns", "80ns", "96ns", "112ns", "128ns", "144ns", "160ns", "176ns", "192ns", "208ns", "224ns", "240ns", "256ns" }; |
| static const char *timing3[] = { "15ns", "30ns", "45ns", "60ns", "75ns", "90ns", "105ns", "120ns" }; |
| static const char *cartmodes[] = { "Auto", "Internal", "External", "Manual" }; |
| static const char *bus_modes[] = { "Quiet", "Writes", "Dynamic", "Dyn. & Writes", "Compatibility" }; |
| static const uint8_t bus_mode_values[] = { 0x00, 0x01, 0x02, 0x03, 0x05 }; |
| static const char *bus_sharing[] = { "Internal", "External", "Both" }; |
| static const char *en_dis_geo[] = { "Disabled", "Enabled", "GeoRAM Mode" }; |
|
|
| struct t_cfg_definition c64_config[] = { |
| { CFG_C64_CART_CRT, CFG_TYPE_STRFUNC,"Cartridge", "%s", (const char **)C64 :: list_crts, 0, 30, (int)"" }, |
| #if U64 |
| { CFG_C64_CART_PREF, CFG_TYPE_ENUM, "Cartridge Preference", "%s", cartmodes, 0, 3, 0 }, |
| { CFG_BUS_MODE, CFG_TYPE_ENUM, "Bus Operation Mode", "%s", bus_modes, 0, 4, 0 }, |
| { CFG_BUS_SHARING_ROM, CFG_TYPE_ENUM, "Bus Sharing - ROMs", "%s", bus_sharing, 0, 2, 2 }, |
| { CFG_BUS_SHARING_IO1, CFG_TYPE_ENUM, "Bus Sharing - I/O1", "%s", bus_sharing, 0, 2, 2 }, |
| { CFG_BUS_SHARING_IO2, CFG_TYPE_ENUM, "Bus Sharing - I/O2", "%s", bus_sharing, 0, 2, 2 }, |
| { CFG_BUS_SHARING_IRQ, CFG_TYPE_ENUM, "Bus Sharing - Interrupts", "%s", bus_sharing, 0, 2, 2 }, |
| #endif |
| { CFG_C64_FASTRESET, CFG_TYPE_ENUM, "Fast Reset", "%s", en_dis, 0, 1, 0 }, |
| #if U64 |
| { CFG_C64_KERNFILE, CFG_TYPE_STRFUNC, "Kernal ROM", "%s", (const char **)C64 :: list_kernals, 0, 30, (int)"kernal.bin" }, |
| { CFG_C64_BASIFILE, CFG_TYPE_STRFUNC, "Basic ROM", "%s", (const char **)C64 :: list_basics, 0, 30, (int)"basic.bin" }, |
| { CFG_C64_CHARFILE, CFG_TYPE_STRFUNC, "Char ROM", "%s", (const char **)C64 :: list_chars, 0, 30, (int)"chars.bin" }, |
| #else |
| { CFG_C64_KERNFILE, CFG_TYPE_STRFUNC, "Alternate Kernal", "%s", (const char **)C64 :: list_kernals, 0, 30, (int)"" }, |
| #endif |
| { CFG_C64_REU_EN, CFG_TYPE_ENUM, "RAM Expansion Unit", "%s", en_dis_geo, 0, 2, 0 }, |
| { CFG_C64_REU_SIZE, CFG_TYPE_ENUM, "REU Size", "%s", reu_size, 0, 7, 4 }, |
| { CFG_C64_REU_PRE, CFG_TYPE_ENUM, "REU Preload", "%s", en_dis, 0, 1, 0 }, |
| { CFG_C64_REU_IMG, CFG_TYPE_STRING, "REU Preload Image", "%s", NULL, 0, 31, (int)"/Usb0/preload.reu" }, |
| { CFG_C64_REU_OFFS, CFG_TYPE_ENUM, "REU Preload Offset", "%s", reu_offset, 0, 8, 0 }, |
| { CFG_C64_MAP_SAMP, CFG_TYPE_ENUM, "Map Ultimate Audio $DF20-DFFF","%s", en_dis, 0, 1, 0 }, |
| { CFG_C64_DMA_ID, CFG_TYPE_VALUE, "DMA Load Mimics ID:", "%d", NULL, 8, 31, 8 }, |
| #ifndef U64 |
| { CFG_C64_SWAP_BTN, CFG_TYPE_ENUM, "Button order", "%s", buttons, 0, 1, 1 }, |
| #endif |
| #if CLOCK_FREQ == 62500000 |
| { CFG_C64_TIMING, CFG_TYPE_ENUM, "CPU Addr valid after PHI2", "%s", timing2, 0, 15, 6 }, |
| { CFG_C64_TIMING1, CFG_TYPE_ENUM, "CPU Addr valid after PHI1", "%s", timing2, 0, 15, 6 }, |
| { CFG_SERVE_PHI1, CFG_TYPE_ENUM, "Force 2 MHz support", "%s", en_dis, 0, 1, 0 }, |
| |
| { CFG_KERNAL_SHADOW,CFG_TYPE_ENUM, "Kernal Shadow RAM", "%s", en_dis, 0, 1, 1 }, |
| { CFG_C64_PHI2_REC, CFG_TYPE_ENUM, "PHI2 edge recovery", "%s", en_dis, 0, 1, 0 }, |
| #elif CLOCK_FREQ == 50000000 |
| { CFG_C64_TIMING, CFG_TYPE_ENUM, "CPU Addr valid after PHI2", "%s", timing1, 0, 15, 4 }, |
| { CFG_C64_TIMING1, CFG_TYPE_ENUM, "CPU Addr valid after PHI1", "%s", timing1, 0, 15, 4 }, |
| { CFG_SERVE_PHI1, CFG_TYPE_ENUM, "Force 2 MHz support", "%s", en_dis, 0, 1, 0 }, |
| |
| { CFG_KERNAL_SHADOW,CFG_TYPE_ENUM, "Kernal Shadow RAM", "%s", en_dis, 0, 1, 1 }, |
| { CFG_C64_PHI2_REC, CFG_TYPE_ENUM, "PHI2 edge recovery", "%s", en_dis, 0, 1, 0 }, |
| #endif |
| { CFG_CMD_ENABLE, CFG_TYPE_ENUM, "Command Interface", "%s", en_dis, 0, 1, 0 }, |
| |
| #if DEVELOPER > 0 |
| { CFG_C64_DO_SYNC, CFG_TYPE_ENUM, "Perform VIC sync at DMA RUN", "%s", en_dis, 0, 1, 0 }, |
| #endif |
| { CFG_TYPE_END, CFG_TYPE_END, "", "", NULL, 0, 0, 0 } |
| }; |
|
|
| extern uint8_t _chars_bin_start; |
|
|
| static unsigned char fastresetPatch[] = { 0xa2, 0x00, 0xa0, 0xa0, 0xad, 0x00, 0x80, 0x49, 0xff, 0x8d, 0x00, 0x80, 0xcd, 0x00, 0x80, 0xf0, 0x02, 0xa0, 0x80, 0x4c, 0x8c, 0xfd }; |
| static unsigned char fastresetOrg[] = { 0xe6, 0xc2, 0xb1, 0xc1, 0xaa, 0xa9, 0x55, 0x91, 0xc1, 0xd1, 0xc1, 0xd0, 0x0f, 0x2a, 0x91, 0xc1, 0xd1, 0xc1, 0xd0, 0x08, 0x8a, 0x91, 0xc1, 0xc8, 0xd0, 0xe8, 0xf0, 0xe4, 0x98, 0xaa, 0xa4, 0xc2, 0x18, 0x20, 0x2D, 0xfe, 0xa9, 0x08, 0x8d, 0x82, 0x02, 0xa9, 0x04, 0x8d, 0x88, 0x02, 0x60 }; |
|
|
| C64::C64() |
| { |
| flash = get_flash(); |
|
|
| register_store(0x43363420, "C64 and Cartridge Settings", c64_config); |
| cfg->set_alt_name("Cartridge and ROM Settings"); |
| cfg->set_sort_order(SORT_ORDER_CFG_MEM); |
|
|
| #ifdef U64 |
| cfg->set_change_hook(CFG_C64_CART_PREF, C64::setCartPref); |
| setCartPref(cfg->find_item(CFG_C64_CART_PREF)); |
| #endif |
|
|
| setup_config_menu(); |
|
|
| char_set = (uint8_t *) &_chars_bin_start; |
| keyb = new Keyboard_C64(this, &CIA1_DPB, &CIA1_DPA, &CIA1_DPA); |
| screen = new Screen_MemMappedCharMatrix((char *) C64_SCREEN, (char *) C64_COLORRAM, 40, 25); |
|
|
| C64_STOP_MODE = STOP_COND_FORCE; |
| C64_MODE = MODE_NORMAL; |
| isFrozen = false; |
| backupIsValid = false; |
| buttonPushSeen = false; |
| client = 0; |
| available = false; |
| clear_cart_definition(¤t_cart_def); |
|
|
| #ifndef U64 |
| #ifdef OS |
| if (!phi2_present()) { |
| printf("No PHI2 clock detected.. Stand alone mode. Stopped = %d\n", C64_STOP); |
| xTaskCreate(C64 :: init_poll_task, "C64 Init poll task", 500, this, PRIO_BACKGROUND, NULL); |
| } |
| #endif |
| #else |
| if (!phi2_present()) { |
| printf("U64, and no PHI2? Something is seriously wrong!!\n"); |
| } |
| #endif |
| } |
|
|
| int C64 :: setCartPref(ConfigItem *item) |
| { |
| if (!item) { |
| return 0; |
| } |
| |
| if (item->getValue() == 3) { |
| item->store->enable(CFG_BUS_SHARING_ROM); |
| item->store->enable(CFG_BUS_SHARING_IO1); |
| item->store->enable(CFG_BUS_SHARING_IO2); |
| item->store->enable(CFG_BUS_SHARING_IRQ); |
| } else { |
| item->store->disable(CFG_BUS_SHARING_ROM); |
| item->store->disable(CFG_BUS_SHARING_IO1); |
| item->store->disable(CFG_BUS_SHARING_IO2); |
| item->store->disable(CFG_BUS_SHARING_IRQ); |
| } |
| return 1; |
| } |
|
|
| void C64 :: init(void) |
| { |
| effectuate_settings(); |
|
|
| if (getFpgaCapabilities() & CAPAB_ULTIMATE64) { |
| init_system_roms(); |
| init_cartridge(); |
| } else if (strlen(cfg->get_string(CFG_C64_CART_CRT)) || strlen(cfg->get_string(CFG_C64_KERNFILE)) || cfg->get_value(CFG_C64_REU_EN) == 2 || is_in_reset()) { |
| init_cartridge(); |
| } |
| available = true; |
| } |
|
|
| bool C64 :: is_stopped(void) |
| { |
| return ((C64_STOP & C64_HAS_STOPPED) == C64_HAS_STOPPED); |
| } |
|
|
| void C64 :: start(void) |
| { |
| C64_STOP = 0; |
| } |
|
|
| #ifdef OS |
| void C64 :: init_poll_task(void *a) |
| { |
| C64 *obj = (C64 *)a; |
| while(!phi2_present()) { |
| ioWrite8(UART_DATA, '\\'); |
| vTaskDelay(100); |
| } |
| obj->init(); |
| obj->start(); |
| vTaskDelete(NULL); |
| } |
| #endif |
|
|
| C64::~C64() |
| { |
| if (isFrozen) { |
| restore_io(); |
| resume(); |
| isFrozen = false; |
| } |
|
|
| delete keyb; |
|
|
| if (screen) |
| delete screen; |
| } |
|
|
| void C64 :: resetConfigInFlash(int page) |
| { |
| |
| } |
|
|
| C64 *C64 :: getMachine(void) |
| { |
| static C64 *c64 = NULL; |
| if (!c64) { |
| #if U64 |
| c64 = new U64Machine(); |
| #else |
| c64 = new C64(); |
| #endif |
| } |
| return c64; |
| } |
|
|
| void C64::effectuate_settings(void) |
| { |
| |
| |
| C64_SWAP_CART_BUTTONS = cfg->get_value(CFG_C64_SWAP_BTN); |
|
|
| #if U64 |
| ConfigureU64SystemBus(); |
| #endif |
| set_emulation_flags(); |
| } |
|
|
|
|
| void C64::set_rom_config(uint8_t idx, const char *fname) |
| { |
| switch(idx) { |
| case 0: |
| cfg->set_string(CFG_C64_KERNFILE, fname); |
| break; |
| case 1: |
| cfg->set_string(CFG_C64_BASIFILE, fname); |
| break; |
| case 2: |
| cfg->set_string(CFG_C64_CHARFILE, fname); |
| break; |
| case 3: |
| cfg->set_string(CFG_C64_CART_CRT, fname); |
| } |
|
|
| cfg->write(); |
| if (idx < 3) { |
| init_system_roms(); |
| } |
| } |
|
|
| void C64::set_emulation_flags(void) |
| { |
| cart_def *def = ¤t_cart_def; |
|
|
| C64_REU_ENABLE = 0; |
| C64_SAMPLER_ENABLE = 0; |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| CMD_IF_SLOT_ENABLE = 0; |
| } |
|
|
| C64_REU_SIZE = cfg->get_value(CFG_C64_REU_SIZE); |
| if (cfg->get_value(CFG_C64_REU_EN) == 1) { |
| C64_REU_ENABLE = 1; |
| } |
| if (getFpgaCapabilities() & CAPAB_SAMPLER) { |
| printf("Sampler found in FPGA... IO map: "); |
| if (cfg->get_value(CFG_C64_MAP_SAMP)) { |
| printf("Enabled!\n"); |
| C64_SAMPLER_ENABLE = 1; |
| } else { |
| printf("disabled.\n"); |
| } |
| } |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| int choice = cfg->get_value(CFG_CMD_ENABLE); |
| CMD_IF_SLOT_ENABLE = !!choice; |
| CMD_IF_SLOT_BASE = 0x47; |
| } |
|
|
| #if U64 |
| C64_PHI2_EDGE_RECOVER = 0; |
| C64_TIMING_ADDR_VALID = 0xBB; |
| #else |
| uint8_t edge = cfg->get_value(CFG_C64_PHI2_REC) | (cfg->get_value(CFG_SERVE_PHI1) << 2); |
| C64_PHI2_EDGE_RECOVER = edge; |
| if (cfg->get_value(CFG_C64_TIMING1) >= 0) { |
| uint8_t byte = cfg->get_value(CFG_C64_TIMING) | (cfg->get_value(CFG_C64_TIMING1) << 4); |
| printf("Writing %b to timing register. %d/%d/%d\n", byte, cfg->get_value(CFG_C64_TIMING), cfg->get_value(CFG_C64_TIMING1), cfg->get_value(CFG_SERVE_PHI1)); |
| C64_TIMING_ADDR_VALID = byte; |
| } else { |
| C64_TIMING_ADDR_VALID = cfg->get_value(CFG_C64_TIMING); |
| } |
| #endif |
| printf("Cartridge registers:\n"); |
| dump_hex(((uint8_t *)(C64_CARTREGS_BASE + 0x0)), 16); |
| } |
|
|
| bool C64::exists(void) |
| { |
| if (phi2_present()) { |
| return true; |
| } |
| C64_STOP_MODE = STOP_COND_FORCE; |
| C64_MODE = MODE_NORMAL; |
| C64_STOP = 0; |
| return false; |
| } |
|
|
| void C64::determine_d012(void) |
| { |
| uint8_t b; |
| |
| |
|
|
| VIC_REG(26) = 0x01; |
| VIC_REG(25) = 0x81; |
|
|
| |
|
|
| vic_d012 = 0; |
| vic_d011 = 0; |
|
|
| b = 0; |
| while (!(VIC_REG(25) & 0x81)) { |
| if (!ioRead8(ITU_TIMER)) { |
| ioWrite8(ITU_TIMER, 200); |
| b++; |
| if (b == 40) |
| break; |
| } |
| } |
|
|
| vic_d012 = VIC_REG(18); |
| vic_d011 = VIC_REG(17); |
|
|
| VIC_REG(26) = 0x00; |
| VIC_REG(25) = 0x81; |
| } |
|
|
| void C64 :: goUltimax(void) |
| { |
| C64_MODE = MODE_ULTIMAX; |
| } |
|
|
| void C64 :: hard_stop(void) |
| { |
| if (!(C64_STOP & C64_HAS_STOPPED)) { |
| C64_STOP_MODE = STOP_COND_FORCE; |
| C64_STOP = 1; |
| |
| while (!(C64_STOP & C64_HAS_STOPPED)) |
| ; |
| } |
| wait_10us(2); |
| } |
|
|
| void C64::stop(bool do_raster) |
| { |
| int b, w; |
|
|
| |
|
|
| |
| stop_mode = 0; |
| raster = 0; |
| raster_hi = 0; |
| vic_irq_en = 0; |
| vic_irq = 0; |
|
|
| |
| C64_STOP_MODE = STOP_COND_BADLINE; |
|
|
| |
|
|
| if (do_raster) { |
| |
| ioWrite8(ITU_TIMER, 200); |
|
|
| |
| C64_STOP = 1; |
| |
|
|
| for (b = 0; b < 25;) { |
| if (C64_STOP & C64_HAS_STOPPED) { |
| |
| |
| goUltimax(); |
|
|
| printf("Ultimax set.. Now reading registers..\n"); |
| raster = VIC_REG(18); |
| raster_hi = VIC_REG(17); |
| vic_irq_en = VIC_REG(26); |
| vic_irq = VIC_REG(25); |
| stop_mode = 1; |
| printf("Mode=1\n"); |
| break; |
| } |
| if (!ioRead8(ITU_TIMER)) { |
| ioWrite8(ITU_TIMER, 200); |
| b++; |
| } |
| } |
| } |
|
|
| |
|
|
| |
| if (!stop_mode) { |
| C64_STOP_MODE = STOP_COND_RWSEQ; |
|
|
| |
| C64_STOP = 1; |
|
|
| ioWrite8(ITU_TIMER, 200); |
|
|
| for (w = 0; w < 100;) { |
| if (C64_STOP & C64_HAS_STOPPED) { |
| stop_mode = 2; |
| break; |
| } |
| |
| if (!ioRead8(ITU_TIMER)) { |
| ioWrite8(ITU_TIMER, 200); |
| w++; |
| } |
| } |
| } |
| |
|
|
| |
| |
| if (!stop_mode) { |
| C64_STOP_MODE = STOP_COND_FORCE; |
|
|
| |
| while (!(C64_STOP & C64_HAS_STOPPED)) |
| ; |
|
|
| stop_mode = 3; |
| } |
|
|
| if (do_raster) { |
| |
| |
| switch (stop_mode) { |
| case 1: |
| printf("Frozen on Bad line. Raster = %02x. VIC Irq Enable: %02x. Vic IRQ: %02x\n", raster, vic_irq_en, vic_irq); |
| if (vic_irq_en & 0x01) { |
| determine_d012(); |
| printf("Original d012/11 content = %02x %02x.\n", vic_d012, vic_d011); |
| } else { |
| vic_d011 = VIC_REG(17); |
| } |
| break; |
| case 2: |
| printf("Frozen on R/Wn sequence.\n"); |
| break; |
| case 3: |
| printf("Hard stop!!!\n"); |
| break; |
| default: |
| printf("Internal error. Should be one of the cases.\n"); |
| } |
| } |
| } |
|
|
| void C64::resume(void) |
| { |
| int dummy = 0; |
| uint8_t rast_lo; |
| uint8_t rast_hi; |
|
|
| if (!raster && !raster_hi) { |
| rast_lo = 0; |
| rast_hi = 0; |
| } else { |
| rast_lo = raster - 1; |
| rast_hi = raster_hi & 0x80; |
| if (!raster) |
| rast_hi = 0; |
| } |
|
|
| |
| if (stop_mode == 1) { |
| |
| |
| if (vic_irq & 0x01) { |
| VIC_REG(26) = 0x81; |
| VIC_REG(18) = rast_lo; |
| VIC_REG(17) = rast_hi; |
| while ((VIC_REG(18) != rast_lo) && ((VIC_REG(17) & 0x80) != rast_hi)) { |
| if (!ioRead8(ITU_TIMER)) { |
| ioWrite8(ITU_TIMER, 200); |
| dummy++; |
| if (dummy == 40) |
| break; |
| } |
| } |
| VIC_REG(18) = vic_d012; |
| VIC_REG(17) = vic_d011; |
| } else { |
| while ((VIC_REG(18) != rast_lo) && ((VIC_REG(17) & 0x80) != rast_hi)) { |
| if (!ioRead8(ITU_TIMER)) { |
| ioWrite8(ITU_TIMER, 200); |
| dummy++; |
| if (dummy == 40) |
| break; |
| } |
| } |
| VIC_REG(18) = vic_d012; |
| VIC_REG(17) = vic_d011; |
| VIC_REG(25) = 0x81; |
| } |
| VIC_REG(26) = vic_irq_en; |
|
|
| raster = VIC_REG(18); |
| vic_irq_en = VIC_REG(26); |
| vic_irq = VIC_REG(25); |
|
|
| C64_STOP_MODE = STOP_COND_BADLINE; |
|
|
| |
| C64_MODE = MODE_NORMAL; |
|
|
| |
| dummy = VIC_REG(0); |
|
|
| |
| C64_STOP = 0; |
|
|
| |
| } else { |
| C64_STOP_MODE = STOP_COND_FORCE; |
| |
| |
| C64_MODE = MODE_NORMAL; |
|
|
| C64_STOP = 0; |
| } |
| } |
|
|
| void C64::reset(void) |
| { |
| C64_MODE = MODE_NORMAL; |
| C64_MODE = C64_MODE_RESET; |
| ioWrite8(ITU_TIMER, 20); |
| while (ioRead8(ITU_TIMER)) |
| ; |
| C64_MODE = C64_MODE_UNRESET; |
| } |
|
|
| bool C64::is_in_reset(void) |
| { |
| return (C64_MODE & C64_MODE_RESET); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void C64::backup_io(void) |
| { |
| #ifdef OS |
| configASSERT( !backupIsValid ); |
| #endif |
| int i; |
| |
| goUltimax(); |
|
|
| |
| for (i = 0; i < NUM_VICREGS; i++) |
| vic_backup[i] = VIC_REG(i); |
|
|
| |
| VIC_CTRL = 0; |
| BORDER = 0; |
| BACKGROUND = 0; |
| SID_VOLUME = 0; |
| SID2_VOLUME = 0; |
| SID3_VOLUME = 0; |
|
|
| |
| |
| printf("CIA1 registers: "); |
| for (i = 0; i < 13; i++) { |
| if(i != 8 && i != 11) |
| printf("%b ", CIA1_REG(i)); |
| else |
| printf("--- "); |
| } |
| printf("\n"); |
|
|
| |
| for (i = 0; i < BACKUP_SIZE / 4; i++) { |
| ram_backup[i] = MEM_LOC[i]; |
| } |
| for (i = 0; i < COLOR_SIZE / 4; i++) { |
| color_backup[i] = COLOR_RAM[i]; |
| } |
| for (i = 0; i < COLOR_SIZE / 4; i++) { |
| screen_backup[i] = SCREEN_RAM[i]; |
| } |
|
|
| |
| for (i = 0; i < CHARSET_SIZE; i++) { |
| CHAR_DEST[i] = char_set[i]; |
| } |
|
|
| |
| cia_backup[0] = CIA2_DDRA; |
| cia_backup[1] = CIA2_DPA; |
| cia_backup[2] = CIA1_DDRA; |
| cia_backup[3] = CIA1_DDRB; |
| CIA1_DDRA = 0x00; |
| CIA1_DDRB = 0xFF; |
| cia_backup[5] = CIA1_DPB; |
| CIA1_DDRB = 0x00; |
| CIA1_DDRA = 0xFF; |
| cia_backup[4] = CIA1_DPA; |
| cia_backup[6] = CIA1_CRA; |
| cia_backup[7] = CIA1_CRB; |
|
|
| backupIsValid = true; |
| } |
|
|
| void C64::init_io(void) |
| { |
| printf("Init IO.\n"); |
|
|
| |
| CIA2_DDRA &= 0xFC; |
| |
|
|
| |
| CIA1_DDRB = 0x00; |
| CIA1_DDRA = 0xFF; |
|
|
| printf("CIA DDR: %b %b Mode: %b\n", CIA1_DDRB, CIA1_DDRA, C64_MODE); |
| CIA1_DDRA = 0xFF; |
| CIA1_DDRB = 0x00; |
| printf("CIA DDR: %b %b\n", CIA1_DDRB, CIA1_DDRA); |
|
|
| CIA1_CRA &= 0xFD; |
| CIA1_CRB &= 0xFD; |
|
|
| |
| |
| VIC_MMAP = 0x12; |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| VIC_REG(17) = 0x1B; |
| VIC_REG(18) = 0xF8; |
| VIC_REG(21) = 0x00; |
| VIC_REG(22) = 0xC8; |
| VIC_REG(32) = 0x00; |
| |
| |
| } |
|
|
| void C64::freeze(void) |
| { |
| if (!phi2_present()) |
| return; |
|
|
| stop(true); |
| backup_io(); |
| init_io(); |
|
|
| isFrozen = true; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| void C64::restore_io(void) |
| { |
| #ifdef OS |
| configASSERT( backupIsValid ); |
| #endif |
|
|
| int i; |
|
|
| |
| VIC_CTRL = 0; |
|
|
| |
| for (i = 0; i < BACKUP_SIZE / 4; i++) { |
| MEM_LOC[i] = ram_backup[i]; |
| } |
| for (i = 0; i < COLOR_SIZE / 4; i++) { |
| COLOR_RAM[i] = color_backup[i]; |
| } |
| for (i = 0; i < COLOR_SIZE / 4; i++) { |
| SCREEN_RAM[i] = screen_backup[i]; |
| } |
|
|
| |
| CIA2_DDRA = cia_backup[0]; |
| |
| CIA1_DDRA = cia_backup[2]; |
| CIA1_DDRB = cia_backup[3]; |
| CIA1_DPA = cia_backup[4]; |
| CIA1_DPB = cia_backup[5]; |
| CIA1_CRA = cia_backup[6]; |
| CIA1_CRB = cia_backup[7]; |
|
|
| printf("Set CIA1 %b %b %b %b %b %b\n", cia_backup[0], cia_backup[1], cia_backup[2], cia_backup[3], cia_backup[4], |
| cia_backup[5]); |
|
|
| |
| for (i = 0; i < NUM_VICREGS; i++) { |
| VIC_REG(i) = vic_backup[i]; |
| } |
|
|
| |
|
|
| SID_VOLUME = 15; |
| SID2_VOLUME = 15; |
| SID3_VOLUME = 15; |
| SID_DUMMY = 0; |
| SID2_DUMMY = 0; |
| SID3_DUMMY = 0; |
|
|
| backupIsValid = false; |
| } |
|
|
| void C64::init_system_roms(void) |
| { |
| C64_KERNAL_ENABLE = 0; |
| |
| #if U64 |
| extern uint8_t _default_kernal_65_start[]; |
| extern uint8_t _default_chars_bin_start[]; |
|
|
| FRESULT fres = FileManager :: getFileManager()->load_file(ROMS_DIRECTORY, cfg->get_string(CFG_C64_KERNFILE), (uint8_t *)U64_KERNAL_BASE, 8192, NULL); |
| if (fres != FR_OK) { |
| printf("Failed to load KERNAL ROM; loading default.\n"); |
| memcpy((void *)U64_KERNAL_BASE, (void *)_default_kernal_65_start, 8192); |
| } else if (cfg->get_value(CFG_C64_FASTRESET)) { |
| unsigned char *kernal = (unsigned char *)U64_KERNAL_BASE; |
| if (!memcmp((void *) (kernal+0x1d6c), (void *) fastresetOrg, sizeof(fastresetOrg))) { |
| memcpy((void *) (kernal+0x1d6c), (void *) fastresetPatch, 22); |
| } |
| } |
|
|
| FileManager :: getFileManager()->load_file(ROMS_DIRECTORY, cfg->get_string(CFG_C64_BASIFILE), (uint8_t *)U64_BASIC_BASE, 8192, NULL); |
| fres = FileManager :: getFileManager()->load_file(ROMS_DIRECTORY, cfg->get_string(CFG_C64_CHARFILE), (uint8_t *)U64_CHARROM_BASE, 4096, NULL); |
| if (fres != FR_OK) { |
| printf("Failed to load CHAR ROM; loading default.\n"); |
| memcpy((void *)U64_CHARROM_BASE, (void *)_default_chars_bin_start, 4096); |
| } |
|
|
| #else |
| uint8_t *temp = new uint8_t[8192]; |
| FRESULT fres = FileManager :: getFileManager()->load_file(ROMS_DIRECTORY, cfg->get_string(CFG_C64_KERNFILE), temp, 8192, NULL); |
| if (fres == FR_OK) { |
| enable_kernal(temp); |
| } else { |
| disable_kernal(); |
| } |
| delete[] temp; |
| #endif |
| } |
|
|
| |
| |
| |
| void C64::unfreeze() |
| { |
| if (!isFrozen) |
| return; |
|
|
| if (!phi2_present()) |
| return; |
|
|
| |
| restore_io(); |
| |
| resume(); |
|
|
| isFrozen = false; |
| } |
|
|
| void C64 :: start_cartridge(void *vdef) |
| { |
| cart_def *def = (cart_def *) vdef; |
|
|
| |
| |
| hard_stop(); |
|
|
| |
| |
| |
| goUltimax(); |
|
|
| VIC_REG(32) = 0; |
| VIC_REG(17) = 0; |
|
|
| |
| |
| C64_MODE = MODE_NORMAL; |
| C64_POKE(0x8005, 0); |
|
|
| |
| C64_MODE = C64_MODE_RESET; |
| C64_CARTRIDGE_TYPE = 0; |
| wait_ms(50); |
|
|
| #if U64 |
| |
| |
|
|
| if (def != 0) { |
| |
| C64_BUS_INTERNAL = 15; |
| C64_BUS_EXTERNAL = 0; |
| |
| } |
| #endif |
|
|
| C64_STOP_MODE = STOP_COND_FORCE; |
| C64_STOP = 0; |
|
|
|
|
| |
| |
| C64_CARTRIDGE_TYPE = 0; |
| C64_REU_ENABLE = 0; |
| C64_SAMPLER_ENABLE = 0; |
| CMD_IF_SLOT_ENABLE = 0; |
|
|
| init_system_roms(); |
| |
| if (def == 0) { |
| bool external = false; |
| #if U64 |
| |
| external = ConfigureU64SystemBus(); |
| #endif |
| if (!external) { |
| set_cartridge(NULL); |
| } |
| } else { |
| set_cartridge(def); |
| } |
| C64_MODE = C64_MODE_UNRESET; |
|
|
| isFrozen = false; |
| backupIsValid = false; |
| } |
|
|
| Screen *C64::getScreen(void) |
| { |
| |
| return screen; |
| } |
|
|
| bool C64::is_accessible(void) |
| { |
| return isFrozen; |
| } |
|
|
| Keyboard *C64::getKeyboard(void) |
| { |
| return keyb; |
| } |
|
|
| void C64::set_cartridge(cart_def *cart) |
| { |
| |
| uint8_t *cart_mem = get_cartridge_rom_addr(); |
|
|
| |
| clear_cart_definition(¤t_cart_def); |
| if (!cart) { |
| |
| cart_mem[5] = 0; |
| #ifndef RECOVERYAPP |
| const char *crt = cfg->get_string(CFG_C64_CART_CRT); |
| if (strlen(crt)) { |
| C64_CRT :: load_crt(CARTS_DIRECTORY, crt, ¤t_cart_def, cart_mem); |
| } else if (cfg->get_value(CFG_C64_REU_EN) == 2) { |
| current_cart_def.type = CART_TYPE_GEORAM; |
| current_cart_def.name = "GeoRAM Cartridge"; |
| current_cart_def.prohibit = CART_PROHIBIT_ALL_BUT_REU; |
| } |
| #endif |
| } else { |
| #ifndef RECOVERYAPP |
| if (cart->custom_addr) { |
| C64_CRT :: clear_crt(); |
| } |
| #endif |
| |
| current_cart_def = *cart; |
| } |
| cart_def *def = ¤t_cart_def; |
|
|
| |
| printf("Cartridge definition:\n"); |
| printf("Name: %s\n", def->name); |
| printf("Type: %d\n", def->type); |
| printf("Custom: %p (Length: %d)\n", def->custom_addr, def->length); |
| printf("Required: %4x\n", def->require); |
| printf("Prohibited: %4x\n", def->prohibit); |
|
|
| C64_CARTRIDGE_TYPE = (uint8_t) def->type; |
|
|
| set_emulation_flags(); |
|
|
| if (def->custom_addr) { |
| printf("Copying %d bytes from array %p to mem addr %p\n", def->length, def->custom_addr, cart_mem); |
| memcpy(cart_mem, def->custom_addr, def->length); |
| } |
|
|
| printf("Begin of cart init: Type: %b. REU: %b. REU_SZ: %b, UCI: %b (%4x), Mode: %b, Sampler: %b\n", |
| C64_CARTRIDGE_TYPE, C64_REU_ENABLE, C64_REU_SIZE, CMD_IF_SLOT_ENABLE, 0xDE00 + uint16_t(CMD_IF_SLOT_BASE * 4), C64_MODE, C64_SAMPLER_ENABLE); |
|
|
| |
| if(def->require & CART_REU) { |
| |
| C64_REU_ENABLE = 1; |
| } |
| if(def->require & CART_MAXREU) { |
| C64_REU_SIZE = 7; |
| C64_REU_ENABLE = 1; |
| } |
| if(def->require & CART_SAMPLER) { |
| C64_SAMPLER_ENABLE = 1; |
| } |
| if(def->require & CART_UCI) { |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| CMD_IF_SLOT_ENABLE = 1; |
| CMD_IF_SLOT_BASE = 0x47; |
| } |
| } |
| if(def->require & CART_UCI_DFFC) { |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| CMD_IF_SLOT_ENABLE = 1; |
| CMD_IF_SLOT_BASE = 0x7F; |
| } |
| } |
| if(def->require & CART_UCI_DE1C) { |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| CMD_IF_SLOT_ENABLE = 1; |
| CMD_IF_SLOT_BASE = 0x07; |
| } |
| } |
| #ifndef RECOVERYAPP |
| if (modem) { |
| if(def->require & CART_ACIA_DE) { |
| modem->reinit_acia(0xDE00); |
| } else if(def->require & CART_ACIA_DF) { |
| modem->reinit_acia(0xDF00); |
| } else { |
| modem->reinit_acia(0xFFFF); |
| } |
| } |
| #endif |
|
|
| #if U64 |
| if(def->require & CART_WMIRROR) { |
| EnableWriteMirroring(); |
| } |
| #endif |
| if (def->require & CART_KERNAL) { |
| uint8_t *src = get_cartridge_rom_addr(); |
| C64 :: getMachine()->enable_kernal(src); |
| } |
|
|
| def->disabled = 0; |
|
|
| if(def->prohibit & (CART_REU | CART_MAXREU)) { |
| if (C64_REU_ENABLE) { |
| def->disabled |= CART_REU; |
| } |
| C64_REU_ENABLE = 0; |
| } |
| if(def->prohibit & (CART_UCI | CART_UCI_DFFC | CART_UCI_DE1C)) { |
| if (getFpgaCapabilities() & CAPAB_COMMAND_INTF) { |
| if (CMD_IF_SLOT_ENABLE) { |
| def->disabled |= CART_UCI; |
| } |
| CMD_IF_SLOT_ENABLE = 0; |
| } |
| } |
| if(def->prohibit & CART_SAMPLER) { |
| if (C64_SAMPLER_ENABLE) { |
| def->disabled |= CART_SAMPLER; |
| } |
| C64_SAMPLER_ENABLE = 0; |
| } |
|
|
| #ifndef RECOVERYAPP |
| if (modem) { |
| if(def->prohibit & CART_ACIA_DE) { |
| if(modem->prohibit_acia(0xDE00)) { |
| def->disabled |= CART_ACIA_DE; |
| } |
| } |
| if(def->prohibit & CART_ACIA_DF) { |
| if(modem->prohibit_acia(0xDF00)) { |
| def->disabled |= CART_ACIA_DF; |
| } |
| } |
| } |
| #endif |
|
|
| |
| memset(get_cartridge_ram_addr(), 0x00, 65536); |
|
|
| printf("End of cart init: Type: %b. REU: %b. REU_SZ: %b, UCI: %b (%4x), Mode: %b, Sampler: %b\n", |
| C64_CARTRIDGE_TYPE, C64_REU_ENABLE, C64_REU_SIZE, CMD_IF_SLOT_ENABLE, 0xDE00 + uint16_t(CMD_IF_SLOT_BASE * 4), C64_MODE, C64_SAMPLER_ENABLE); |
| if (def->disabled) { |
| printf("---> Some features were disabled: %04x\n", def->disabled); |
| } |
| } |
|
|
| void C64::set_colors(int background, int border) |
| { |
| BORDER = uint8_t(border); |
| BACKGROUND = uint8_t(background); |
| } |
|
|
| void C64::enable_kernal(uint8_t *rom) |
| { |
| bool fastreset = (cfg->get_value(CFG_C64_FASTRESET) != 0); |
| if (fastreset && !memcmp((void *) (rom+0x1d6c), (void *) fastresetOrg, sizeof(fastresetOrg))) |
| memcpy((void *) (rom+0x1d6c), (void *) fastresetPatch, 22); |
|
|
| #if U64 |
| memcpy((void *)U64_KERNAL_BASE, rom, 8192); |
|
|
| #else |
| |
| |
| uint8_t *src = rom; |
| extern uint8_t __kernal_area; |
| uint8_t *dst = (&__kernal_area) + 1; |
| for (int j = 0; j < 4; j++) { |
| for (int i = j; i < 8192; i+=4) { |
| *(dst) = src[i]; |
| dst += 4; |
| } |
| } |
|
|
| |
| char *kern = (char *)&__kernal_area; |
| const char *ident = "KERNAL REPLACEMENT SHADOW RAM!\0\0\0\0"; |
| for(; *ident; ident += 4, kern += 4) { |
| kern[ 0] = ident[0]; |
| kern[ 8192] = ident[1]; |
| kern[16384] = ident[2]; |
| kern[24576] = ident[3]; |
| } |
|
|
| C64_KERNAL_ENABLE = 1 | (cfg->get_value(CFG_KERNAL_SHADOW) << 2); |
| #endif |
| } |
|
|
| void C64::disable_kernal() |
| { |
| C64_KERNAL_ENABLE = 0; |
|
|
| #if U64 |
| init_system_roms(); |
| #endif |
| } |
|
|
| void C64::init_cartridge() |
| { |
| if (!cfg) |
| return; |
|
|
| if (C64_STOP == 0) { |
| C64_MODE = C64_MODE_RESET; |
| } |
| C64_KERNAL_ENABLE = 0; |
| C64_CARTRIDGE_TYPE = 0; |
|
|
| init_system_roms(); |
|
|
| #if U64 |
| if (ConfigureU64SystemBus()) { |
| printf("External Cartridge Selected. Not initializing cartridge.\n"); |
| wait_ms(100); |
| C64_MODE = C64_MODE_UNRESET; |
| C64_STOP = 0; |
| return; |
| } |
| #endif |
|
|
| set_cartridge(NULL); |
|
|
| |
| |
| C64_CARTRIDGE_KILL = 2; |
| |
| |
| C64_CARTRIDGE_KILL = 2; |
|
|
| C64_MODE = C64_MODE_UNRESET; |
| C64_STOP = 0; |
| } |
|
|
| bool C64::buttonPush(void) |
| { |
| bool ret = buttonPushSeen; |
| buttonPushSeen = false; |
|
|
| return ret; |
| } |
|
|
| void C64::setButtonPushed(void) |
| { |
| buttonPushSeen = true; |
| } |
|
|
| void C64::checkButton(void) |
| { |
| static uint8_t button_prev; |
|
|
| |
| if (!available) { |
| return; |
| } |
| uint8_t buttons = ioRead8(ITU_BUTTON_REG) & ITU_BUTTONS; |
| if ((buttons & ~button_prev) & ITU_BUTTON1) { |
| buttonPushSeen = true; |
| } |
| button_prev = buttons; |
| } |
|
|
| #if U64 |
| bool C64 :: ConfigureU64SystemBus(void) |
| { |
| C64_BUS_BRIDGE = bus_mode_values[cfg->get_value(CFG_BUS_MODE)]; |
| uint8_t internal = 0; |
| uint8_t external = 0; |
| bool ext_cart = ((U64_CART_DETECT & 3) != 3); |
|
|
| switch (cfg->get_value(CFG_C64_CART_PREF)) { |
| case 0: |
| if (ext_cart) { |
| internal = 0; |
| external = 15; |
| } else { |
| internal = 15; |
| external = 0; |
| } |
| break; |
| case 1: |
| internal = 15; |
| external = 0; |
| ext_cart = false; |
| break; |
| case 2: |
| internal = 0; |
| external = 15; |
| break; |
|
|
| case 3: |
| ext_cart = false; |
|
|
| switch (cfg->get_value(CFG_BUS_SHARING_ROM)) { |
| case 0: |
| internal |= 0x04; |
| break; |
| case 1: |
| external |= 0x04; |
| break; |
| case 2: |
| internal |= 0x04; |
| external |= 0x04; |
| break; |
| } |
|
|
| switch (cfg->get_value(CFG_BUS_SHARING_IRQ)) { |
| case 0: |
| internal |= 0x08; |
| break; |
| case 1: |
| external |= 0x08; |
| break; |
| case 2: |
| internal |= 0x08; |
| external |= 0x08; |
| break; |
| } |
|
|
| switch (cfg->get_value(CFG_BUS_SHARING_IO1)) { |
| case 0: |
| internal |= 0x01; |
| break; |
| case 1: |
| external |= 0x01; |
| break; |
| case 2: |
| internal |= 0x01; |
| external |= 0x01; |
| break; |
| } |
|
|
| switch (cfg->get_value(CFG_BUS_SHARING_IO2)) { |
| case 0: |
| internal |= 0x02; |
| break; |
| case 1: |
| external |= 0x02; |
| break; |
| case 2: |
| internal |= 0x02; |
| external |= 0x02; |
| break; |
| } |
| } |
|
|
| C64_BUS_INTERNAL = internal; |
| C64_BUS_EXTERNAL = external; |
|
|
| return ext_cart; |
| } |
|
|
| void C64 :: EnableWriteMirroring(void) |
| { |
| C64_BUS_BRIDGE = 0x01 | bus_mode_values[cfg->get_value(CFG_BUS_MODE)]; |
| } |
| #endif |
|
|
| int C64 :: isMP3RamDrive(int drvNo) |
| { |
| uint8_t* reu = (uint8_t *)(REU_MEMORY_BASE); |
| uint8_t RealDrvType = reu[0xbb0e + drvNo]; |
| if (((reu[0xbb0e] == 0x03) && (reu[0xbb0f] == 0xA9) && (reu[0xbb10] == 0x06) && (reu[0xbb11] == 0x8D)) |
| #ifndef U64 |
| || ((reu[0xbb0e] == 0xDF) && (reu[0xbb0f] == 0xA5) && (reu[0xbb10] == 0x07) && (reu[0xbb11] == 0x8D)) |
| #endif |
| ) |
| { |
| RealDrvType = reu[0x798e + drvNo]; |
| if (RealDrvType > 0x83) |
| RealDrvType = 0; |
| } |
| |
| uint8_t ramBase = reu[0x7dc7 + drvNo] ; |
| int drvType = 0; |
| if (RealDrvType == 0x81) drvType = 1541; |
| if (RealDrvType == 0x82) drvType = 1571; |
| if (RealDrvType == 0x83) drvType = 1581; |
| if (RealDrvType == 0x84) drvType = DRVTYPE_MP3_DNP; |
| if (RealDrvType == 0xA4) drvType = DRVTYPE_MP3_DNP; |
| if (ramBase > 0x40) drvType = 0; |
| return drvType; |
| } |
|
|
| int C64 :: getSizeOfMP3NativeRamdrive(int devNo) |
| { |
| uint8_t* reu = (uint8_t *)(REU_MEMORY_BASE); |
| uint8_t DskDrvBaseL = reu[0xbafe + devNo]; |
| uint8_t DskDrvBaseH = reu[0xbafe + 4 + devNo]; |
| uint16_t dskDrvBase = (((uint16_t) DskDrvBaseH) << 8) | DskDrvBaseL; |
| uint8_t noTracks = reu[dskDrvBase + 0x84]; |
| return ((uint32_t) noTracks) << 16; |
| } |
|
|
| void C64 :: get_eeprom_data(uint8_t *buffer) |
| { |
| volatile uint8_t *eeprom = (volatile uint8_t *)(EEPROM_BASE); |
| *eeprom = 1; |
| memcpy(buffer, (void *)(eeprom + 2048), 2048); |
| } |
|
|
| void C64 :: set_eeprom_data(uint8_t *buffer) |
| { |
| volatile uint8_t *eeprom = (volatile uint8_t *)(EEPROM_BASE); |
| memcpy((void *)(eeprom + 2048), buffer, 2048); |
| *eeprom = 1; |
| } |
|
|
| bool C64 :: get_eeprom_dirty(void) |
| { |
| volatile uint8_t *eeprom = (volatile uint8_t *)(EEPROM_BASE); |
| bool dirty = (*eeprom != 0) ? true : false; |
| *eeprom = 1; |
| return dirty; |
| } |
|
|
| void C64 :: list_crts(ConfigItem *it, IndexedList<char *>& strings) |
| { |
| #ifndef NO_FILE_ACCESS |
| |
| char *empty = new char[1]; |
| *empty = 0; |
| strings.append(empty); |
|
|
| Path p; |
| p.cd(CARTS_DIRECTORY); |
| IndexedList<FileInfo *>infos(16, NULL); |
| FileManager *fm = FileManager :: getFileManager(); |
| FRESULT fres = fm->get_directory(&p, infos, NULL); |
| if (fres != FR_OK) { |
| return; |
| } |
|
|
| for(int i=0;i<infos.get_elements();i++) { |
| FileInfo *inf = infos[i]; |
| if (strcmp(inf->extension, "CRT") == 0) { |
| char *s = new char[1+strlen(inf->lfname)]; |
| strcpy(s, inf->lfname); |
| strings.append(s); |
| } |
| delete inf; |
| } |
| #endif |
| } |
|
|
| void C64 :: list_kernals(ConfigItem *it, IndexedList<char *>& strings) |
| { |
| #if !U64 |
| |
| char *empty = new char[1]; |
| *empty = 0; |
| strings.append(empty); |
| #endif |
|
|
| #ifndef NO_FILE_ACCESS |
| Path p; |
| p.cd(ROMS_DIRECTORY); |
| IndexedList<FileInfo *>infos(16, NULL); |
| FileManager *fm = FileManager :: getFileManager(); |
| FRESULT fres = fm->get_directory(&p, infos, NULL); |
| if (fres != FR_OK) { |
| return; |
| } |
|
|
| for(int i=0;i<infos.get_elements();i++) { |
| FileInfo *inf = infos[i]; |
| if (inf->size == 8192) { |
| char *s = new char[1+strlen(inf->lfname)]; |
| strcpy(s, inf->lfname); |
| strings.append(s); |
| } |
| delete inf; |
| } |
| #endif |
| } |
|
|
| void C64 :: list_basics(ConfigItem *it, IndexedList<char *>& strings) |
| { |
| |
| char *empty = new char[1]; |
| *empty = 0; |
| strings.append(empty); |
|
|
| #ifndef NO_FILE_ACCESS |
| Path p; |
| p.cd(ROMS_DIRECTORY); |
| IndexedList<FileInfo *>infos(16, NULL); |
| FileManager *fm = FileManager :: getFileManager(); |
| FRESULT fres = fm->get_directory(&p, infos, NULL); |
| if (fres != FR_OK) { |
| return; |
| } |
|
|
| for(int i=0;i<infos.get_elements();i++) { |
| FileInfo *inf = infos[i]; |
| if (inf->size == 8192) { |
| char *s = new char[1+strlen(inf->lfname)]; |
| strcpy(s, inf->lfname); |
| strings.append(s); |
| } |
| delete inf; |
| } |
| #endif |
| } |
|
|
| void C64 :: list_chars(ConfigItem *it, IndexedList<char *>& strings) |
| { |
| |
| char *empty = new char[1]; |
| *empty = 0; |
| strings.append(empty); |
|
|
| #ifndef NO_FILE_ACCESS |
| Path p; |
| p.cd(ROMS_DIRECTORY); |
| IndexedList<FileInfo *>infos(16, NULL); |
| FileManager *fm = FileManager :: getFileManager(); |
| FRESULT fres = fm->get_directory(&p, infos, NULL); |
| if (fres != FR_OK) { |
| return; |
| } |
|
|
| for(int i=0;i<infos.get_elements();i++) { |
| FileInfo *inf = infos[i]; |
| if (inf->size == 4096) { |
| char *s = new char[1+strlen(inf->lfname)]; |
| strcpy(s, inf->lfname); |
| strings.append(s); |
| } |
| delete inf; |
| } |
| #endif |
| } |
|
|
| void C64 :: measure_timing(uint8_t *buffer) |
| { |
| uint8_t *wp = buffer; |
|
|
| bool i_stopped_it = false; |
| if(!is_stopped()) { |
| stop(false); |
| i_stopped_it = true; |
| } |
|
|
| C64_POKE(0xD011, 0x0B); |
| wait_ms(20); |
|
|
| volatile uint8_t *measurement = (volatile uint8_t *)(CART_TIMING_BASE); |
| volatile uint32_t *screen = (volatile uint32_t *)(C64_MEMORY_BASE + 0x400); |
| volatile uint32_t *vic = (volatile uint32_t *)(C64_MEMORY_BASE + 0xD000); |
| uint32_t old, newval; |
| for (uint8_t edge=0x08; edge <= 0x0B; edge++) { |
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| old = *screen; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| *screen = 0x12345678; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| newval = *screen; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| *screen = old; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| old = *vic; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| *vic = 0x98765432; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| newval = *vic; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
|
|
| |
| C64_PHI2_EDGE_RECOVER = edge; |
| *vic = old; |
| for(int j=0;j<2048;j++) { |
| *(wp++) = measurement[j]; |
| } |
| } |
|
|
| C64_POKE(0xD011, 0x1B); |
|
|
| if (i_stopped_it) { |
| resume(); |
| } |
| } |
|
|
| void C64 :: setup_config_menu(void) |
| { |
| ConfigGroup *grp = ConfigGroupCollection :: getGroup("Memory Configuration", SORT_ORDER_CFG_MEM); |
| grp->append(cfg->find_item(CFG_C64_KERNFILE)); |
| #ifdef U64 |
| grp->append(cfg->find_item(CFG_C64_BASIFILE)->set_item_altname("BASIC ROM")); |
| grp->append(cfg->find_item(CFG_C64_CHARFILE)->set_item_altname("Character ROM")); |
| #endif |
| grp->append(cfg->find_item(CFG_C64_CART_CRT)); |
| grp->append(ConfigItem :: separator()); |
| grp->append(cfg->find_item(CFG_C64_REU_EN)); |
| grp->append(cfg->find_item(CFG_C64_REU_SIZE)->set_item_altname("Size")); |
| grp->append(ConfigItem :: separator()); |
| grp->append(cfg->find_item(CFG_CMD_ENABLE)); |
| grp->append(cfg->find_item(CFG_C64_MAP_SAMP)->set_item_altname("Ultimate Audio")); |
| grp->append(ConfigItem :: separator()); |
| } |
|
|