From d97c31db621896f1b0af849714639ed95105f680 Mon Sep 17 00:00:00 2001 From: paul eeepc Date: Wed, 7 Dec 2016 19:19:34 -0600 Subject: [PATCH] Determining overall operation READ/WRITE. --- host/source/cartridge.c | 42 +++++++++++++++++++++++++++++++++++++++++ host/source/enums.h | 6 ++++++ host/source/erase.c | 4 ---- host/source/inlprog.c | 27 +++++++++++++++++++++----- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/host/source/cartridge.c b/host/source/cartridge.c index eb12a7d..fb3d436 100644 --- a/host/source/cartridge.c +++ b/host/source/cartridge.c @@ -117,6 +117,8 @@ int detect_console( cartridge *cart, USBtransfer *transfer ) return SUCCESS; error: + //always end with resetting i/o + io_reset( transfer ); return -1; } @@ -133,14 +135,54 @@ error: int detect_mirroring( cartridge *cart, USBtransfer *transfer ) { + //always start with resetting i/o + io_reset( transfer ); if ( cart->console == NES_CART ) { //For now just assume mirroring is fixed until start adding support for other mappers cart->mirroring = MIR_FIXED; } + //always end with resetting i/o + io_reset( transfer ); + return SUCCESS; //error: + //always end with resetting i/o + //io_reset( transfer ); +// return -1; +} + + +//detecting mapper and memories ends up being one big operation +int detect_map_mem( cartridge *cart, USBtransfer *transfer ) +{ + //always start with resetting i/o + io_reset( transfer ); + + if ( cart->console == NES_CART && cart->mirroring = MIR_FIXED ) { + //if INL-ROM discrete board with EXP0->PRG-ROM /WE + //EXP0 pullup test should pass + if( exp0_pullup_test(transfer) == SUCCESS ){ + + } else { + //Potentially some other discrete board without EXP0->WE flash control + + //Some ASIC mappers have fixed mirroring as well + + } + //for NROM flashing first verify EXP0 pull up will clock /WE properly + + } + + //always end with resetting i/o + io_reset( transfer ); + + return SUCCESS; + +//error: + //always end with resetting i/o + //io_reset( transfer ); // return -1; } diff --git a/host/source/enums.h b/host/source/enums.h index 1fba389..4b132a0 100644 --- a/host/source/enums.h +++ b/host/source/enums.h @@ -19,5 +19,11 @@ enum mirroring { MIR_MMC3 }; +enum operations { + READ = 10, + WRITE, + CHECK +}; + #endif diff --git a/host/source/erase.c b/host/source/erase.c index 8fa7c87..5454bc5 100644 --- a/host/source/erase.c +++ b/host/source/erase.c @@ -9,11 +9,7 @@ int erase_nes( USBtransfer *transfer ) io_reset(transfer); - //for NROM flashing first verify EXP0 pull up will clock /WE properly - check( !exp0_pullup_test(transfer), "EXP0 pullup test failed can't erase PRG-ROM" ); - nes_init(transfer); - dictionary_call_debug( transfer, DICT_NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA, USB_IN, NULL, 1); dictionary_call_debug( transfer, DICT_NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55, USB_IN, NULL, 1); diff --git a/host/source/inlprog.c b/host/source/inlprog.c index 395765f..9823673 100644 --- a/host/source/inlprog.c +++ b/host/source/inlprog.c @@ -51,12 +51,12 @@ int main(int argc, char *argv[]) char *C_value = NULL; //program chr file char *L_value = NULL; //LIBUSB debugging value char *K_value = NULL; //connect to kazzo firmware version # - char *O_value = NULL; //start programming at offset base value + char *O_value = NULL; //start read/writing at offset base value char *P_value = NULL; //program prg file char *S_value = NULL; //program SNES binary file char *W_value = NULL; //program WRAM/SRAM file - + int operation = 0; //used to denote the overall operation being requested flash/dump/verify etc int index = 0; int rv = 0; opterr = 0; @@ -139,15 +139,31 @@ int main(int argc, char *argv[]) //TODO display better help message if (h_flag) { - printf("you've asked for help but the help message still needs created...\n"); + printf("You've asked for help but the help message still needs created...\n"); return 0; } + //Determine overall operation being performed based on user args + //Also don't want to continue if conflicting args are being used + + //flags about input files only used for writes + if ( p_flag || i_value || C_value || P_value || S_value || W_value ) { + check( d_value == NULL, "input args conflict can't program and dump in same operation."); + operation = WRITE; + } + + //flags about output files used for reads + if ( d_value ) { + check( e_flag == 0, "input args conflict can't erase and dump in same operation."); + operation = READ; + } + //context set to NULL since only acting as single user of libusb libusb_context *context = NULL; //create USBtransfer struct to hold all transfer info USBtransfer *transfer = malloc( sizeof(USBtransfer)); + //create usb device handle pointer to interact with retro-prog //libusb_device_handle *rprog_handle = NULL; transfer->handle = NULL; @@ -189,16 +205,16 @@ int main(int argc, char *argv[]) cartridge *cart = malloc( sizeof(cartridge)); check_mem(cart); - //set all cart elements to UNKNOWN + //set all cart elements to UNKNOWN and allocate memory object within init_cart_elements(cart); + // -x flag turns off all autodection if (!x_flag) { //attempt to detect board inserted in device check(!detect_console( cart, transfer ), "Problem detecting cartridge."); //detect mapper as much as possible - //TODO first step is mirroring for NES boards check(!detect_mirroring( cart, transfer ), "Problem detecting cart mirroring."); //TODO first step for SNES is mapping mode @@ -206,6 +222,7 @@ int main(int argc, char *argv[]) //By this point we know a lot about the cartridge but for things like NES discrete //mappers we'll have to play around with the memory to determine exact mapper //detect board manufacturer/flash memories as much as possible + check(!detect_map_mem( cart, transfer ), "Problem detecting cart map & memory."); //detect rom sizes as much as possible