Much of dumping code for PRG-ROM completed but have some bugs with setting buff elements working on debugging...
This commit is contained in:
parent
4db2929c3b
commit
49ec51e767
|
|
@ -1,5 +1,8 @@
|
|||
#include "buffer.h"
|
||||
|
||||
//used by buffer manager to know what buffer to send to USB/memory
|
||||
buffer *cur_buff;
|
||||
|
||||
//used to communicate to usbFunctionWrite which buffer object
|
||||
//it should be filling
|
||||
buffer *cur_usb_load_buff;
|
||||
|
|
@ -12,26 +15,26 @@ uint8_t incoming_bytes_remain;
|
|||
uint8_t operation;
|
||||
|
||||
//min define of two buffers
|
||||
static buffer buff0;
|
||||
static buffer buff1;
|
||||
buffer buff0;
|
||||
buffer buff1;
|
||||
#if ( defined(NUM_BUFFERS_4) || (defined(NUM_BUFFERS_8)) )
|
||||
static buffer buff2;
|
||||
static buffer buff3;
|
||||
buffer buff2;
|
||||
buffer buff3;
|
||||
#endif
|
||||
#ifdef NUM_BUFFERS_8
|
||||
static buffer buff4;
|
||||
static buffer buff5;
|
||||
static buffer buff6;
|
||||
static buffer buff7;
|
||||
buffer buff4;
|
||||
buffer buff5;
|
||||
buffer buff6;
|
||||
buffer buff7;
|
||||
#endif
|
||||
|
||||
//max raw buffer size is only limited based on buffer struct
|
||||
//raw buffer memory to which smaller buffers will be created from
|
||||
//set pointers and lengths to prevent buffer conflicts
|
||||
static uint8_t raw_buffer[NUM_RAW_BANKS * RAW_BANK_SIZE]; //8 banks of 32bytes each 256Bytes total
|
||||
uint8_t raw_buffer[NUM_RAW_BANKS * RAW_BANK_SIZE]; //8 banks of 32bytes each 256Bytes total
|
||||
|
||||
//buffer status stores allocation status of each raw buffer 32Byte bank
|
||||
static uint8_t raw_bank_status[NUM_RAW_BANKS];
|
||||
uint8_t raw_bank_status[NUM_RAW_BANKS];
|
||||
|
||||
|
||||
|
||||
|
|
@ -51,11 +54,12 @@ static uint8_t raw_bank_status[NUM_RAW_BANKS];
|
|||
//uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint16_t *rlen)
|
||||
uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint8_t *rlen)
|
||||
{
|
||||
buffer *called_buff = &buff0; //used to point to buffer that was called based on opcode
|
||||
buffer *called_buff; //= &buff0; //used to point to buffer that was called based on opcode
|
||||
uint8_t *rptr = rv; //used for return pointer set to small rv buffer by default
|
||||
|
||||
//some opcodes place buffer number in misc/data
|
||||
if ( (spacket->opcode > BUFFN_INMISC_MIN) && (spacket->opcode < BUFFN_INMISC_MAX) ) {
|
||||
// called_buff = &buff1;
|
||||
switch ( spacket->miscdata ) {
|
||||
//2 buffers minimum support
|
||||
case 0: called_buff = &buff0; break;
|
||||
|
|
@ -175,6 +179,7 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint8_t *rlen)
|
|||
uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff,
|
||||
uint8_t operMSB, uint8_t operLSB, uint8_t miscdata )
|
||||
{
|
||||
|
||||
switch (opcode) {
|
||||
case RAW_BUFFER_RESET:
|
||||
raw_buffer_reset();
|
||||
|
|
@ -224,6 +229,10 @@ uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff,
|
|||
*rvalue = raw_bank_status[operLSB];
|
||||
*rlength += 1;
|
||||
break;
|
||||
case GET_BUFF_OPERATION:
|
||||
*rvalue = operation;
|
||||
*rlength += 1;
|
||||
break;
|
||||
case GET_PRI_ELEMENTS:
|
||||
rvalue[0] = buff->last_idx;
|
||||
rvalue[1] = buff->status;
|
||||
|
|
@ -309,19 +318,28 @@ uint8_t * buffer_payload( setup_packet *spacket, buffer *buff, uint8_t hostsetbu
|
|||
|
||||
//buffer in use depends on opcode which was decoded prior to calling into hostsetbuff
|
||||
//if buffer number not designated by host buffer.c gets to decide
|
||||
if ( hostsetbuff != ~FALSE ) {
|
||||
if ( hostsetbuff == FALSE ) {
|
||||
//buffer.c gets to decide buffer in use
|
||||
//TODO implement some fancy double buffering code
|
||||
//for now just designate buffer 0
|
||||
if ( endpoint == ENDPOINT_IN) {
|
||||
//reads
|
||||
rtnpointer = buff0.data;
|
||||
buff0.status = USB_UNLOADING;
|
||||
} else {//writes
|
||||
cur_usb_load_buff = &buff0;
|
||||
buff0.status = USB_LOADING;
|
||||
if ( cur_buff->status == DUMPED ) {
|
||||
rtnpointer = cur_buff->data;
|
||||
cur_buff->status = USB_UNLOADING;
|
||||
} else {
|
||||
//problem, buffers not prepared or initialized
|
||||
*rlength = USB_NO_MSG;
|
||||
operation = PROBLEM;
|
||||
}
|
||||
buff0.cur_byte = 0;
|
||||
} else {//writes
|
||||
//cur_usb_load_buff = &buff0;
|
||||
cur_usb_load_buff = cur_buff;
|
||||
//buff0.status = USB_LOADING;
|
||||
cur_buff->status = USB_LOADING;
|
||||
}
|
||||
//buff0.cur_byte = 0;
|
||||
cur_buff->cur_byte = 0;
|
||||
|
||||
} else { //host determined the buffer to use
|
||||
if ( endpoint == ENDPOINT_IN) {
|
||||
|
|
@ -355,6 +373,7 @@ uint8_t * buffer_payload( setup_packet *spacket, buffer *buff, uint8_t hostsetbu
|
|||
* Pre: static instantitions of raw_buffer, raw_bank_status, and buff0-7
|
||||
* Post:all raw buffer ram unallocated
|
||||
* buffer status updated to UNALLOC
|
||||
* operation set to RESET
|
||||
* Rtn: None
|
||||
*/
|
||||
void raw_buffer_reset( )
|
||||
|
|
@ -391,6 +410,8 @@ void raw_buffer_reset( )
|
|||
buff7.id = UNALLOC;
|
||||
#endif
|
||||
|
||||
operation = RESET;
|
||||
|
||||
}
|
||||
|
||||
/* Desc:Embeded subtitute for malloc of a buffer object
|
||||
|
|
@ -462,6 +483,7 @@ uint8_t allocate_buffer( buffer *buff, uint8_t new_id, uint8_t base_bank, uint8_
|
|||
buff->multiple = 0;
|
||||
buff->add_mult = 0;
|
||||
buff->mapper = 0;
|
||||
buff->mapvar = 0;
|
||||
buff->function = 0;
|
||||
|
||||
//set buffer data pointer to base ram address
|
||||
|
|
@ -570,7 +592,6 @@ void update_buffers()
|
|||
{
|
||||
uint8_t result = 0;
|
||||
static uint8_t num_buff;
|
||||
static buffer *cur_buff;
|
||||
|
||||
//when dumping we don't actually know when the buffer has been fully
|
||||
//read back through USB IN transfer. But we know when the next buffer
|
||||
|
|
@ -596,14 +617,71 @@ void update_buffers()
|
|||
//now we can get_next_buff by passing cur_buff
|
||||
}
|
||||
if (operation == STARTDUMP) {
|
||||
//prepare both buffers to dump
|
||||
// cur_buff->cur_byte = 0;
|
||||
// cur_buff->status = DUMPING;
|
||||
// //send first buffer off to dump
|
||||
// result = dump_page( cur_buff );
|
||||
// if (result != SUCCESS) {
|
||||
// cur_buff->status = PROBLEM;
|
||||
// } else {
|
||||
// cur_buff->status = DUMPED;
|
||||
// //increment page_num so everything is ready for next dump
|
||||
// cur_buff->page_num += cur_buff->reload;
|
||||
// }
|
||||
//now it's ready and just waiting for IN transfer
|
||||
//pretend the last buffer is in USB transfer and
|
||||
//we're waiting to have that dump until the first buffer starts USB transfer
|
||||
|
||||
//do all the same things that would happen between buffers to start things moving
|
||||
//pretend the last buffer is unloading via USB right now
|
||||
//so that operation == DUMPING code gets run for the first time but appears like
|
||||
//it's not the first time.
|
||||
//to do this, set cur_buff to last buff and set it's status to USB_UNLOADING
|
||||
for ( result=1; result<num_buff; result++ ) {
|
||||
cur_buff = get_next_buff( cur_buff, num_buff );
|
||||
}
|
||||
cur_buff->status = USB_UNLOADING;
|
||||
//that will now trigger operation == DUMPING to dump first buffer
|
||||
|
||||
//don't want to reenter start initialiation again
|
||||
operation = DUMPING;
|
||||
}
|
||||
if (operation == STARTFLASH) {
|
||||
//don't want to reenter start initialiation again
|
||||
operation = FLASHING;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//this will get entered on first and all successive calls
|
||||
if ( operation == DUMPING ) {
|
||||
//buffer_payload will pass cur_buff to usb driver on next IN transfer
|
||||
//on receipt of the IN transfer buffer_payload sets:
|
||||
// cur_buff->status = USB_UNLOADING;
|
||||
// So that's what we're waiting on before sending next buffer to dump
|
||||
if ( cur_buff->status == USB_UNLOADING ) {
|
||||
//move on to next buffer now that last one is at USB
|
||||
//WARNING!!! this current design won't work well if there's only one buffer
|
||||
//Because the buffer getting read via USB will get stopped on by next dump
|
||||
//So things won't really work with only one buffer
|
||||
cur_buff = get_next_buff( cur_buff, num_buff );
|
||||
cur_buff->cur_byte = 0;
|
||||
cur_buff->status = DUMPING;
|
||||
//send buffer off to dump
|
||||
result = dump_page( cur_buff );
|
||||
if (result != SUCCESS) {
|
||||
cur_buff->status = PROBLEM;
|
||||
} else {
|
||||
cur_buff->status = DUMPED;
|
||||
//increment page_num so everything is ready for next dump
|
||||
//TODO make buffer_update function to handle everything
|
||||
cur_buff->page_num += cur_buff->reload;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//to start let's sense dumping operation by buffer status
|
||||
//host updates status of buffer, then we go off and dump as appropriate
|
||||
//might be best to add some opcode to kick things off.
|
||||
|
|
@ -674,6 +752,9 @@ void update_buffers()
|
|||
|
||||
//update it's status so buffer is ready for reuse.
|
||||
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ int reset_buffers( USBtransfer *transfer )
|
|||
* Pre: buffers must be reset
|
||||
* Post:All buffers and raw sram unallocated
|
||||
* Sets id, status to EMPTY, and last_idx.
|
||||
* sets reload to sum of buffers
|
||||
* All other elements set to zero
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
|
|
@ -44,12 +45,9 @@ int allocate_buffers( USBtransfer *transfer, int num_buffers, int buff_size ) {
|
|||
numbanks= buff_size/RAW_BANK_SIZE;
|
||||
buff1id = 0x80;
|
||||
buff1basebank= numbanks; //buff1 starts right after buff0
|
||||
} else {
|
||||
sentinel("Not setup to handle this buffer config");
|
||||
}
|
||||
|
||||
//allocate buffer0
|
||||
rv = dictionary_call_debug( transfer, DICT_BUFFER, ALLOCATE_BUFFER0,
|
||||
rv = dictionary_call( transfer, DICT_BUFFER, ALLOCATE_BUFFER0,
|
||||
( (buff0id<<8)|(buff0basebank) ), numbanks,
|
||||
USB_IN, NULL, 1);
|
||||
if ( rv != SUCCESS ){
|
||||
|
|
@ -57,7 +55,7 @@ int allocate_buffers( USBtransfer *transfer, int num_buffers, int buff_size ) {
|
|||
return rv;
|
||||
}
|
||||
//allocate buffer1
|
||||
rv = dictionary_call_debug( transfer, DICT_BUFFER, ALLOCATE_BUFFER1,
|
||||
rv = dictionary_call( transfer, DICT_BUFFER, ALLOCATE_BUFFER1,
|
||||
( (buff1id<<8)|(buff1basebank) ), numbanks,
|
||||
USB_IN, NULL, 1);
|
||||
if ( rv != SUCCESS ){
|
||||
|
|
@ -65,9 +63,99 @@ int allocate_buffers( USBtransfer *transfer, int num_buffers, int buff_size ) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
//set reload (value added to page_num after each load/dump to sum of buffers
|
||||
// 2 * 128 = 256 -> reload = 1
|
||||
//set buffer0
|
||||
dictionary_call( transfer, DICT_BUFFER, SET_RELOAD_PAGENUM0, 0x0000, 0x01,
|
||||
USB_IN, NULL, 1);
|
||||
//set buffer1
|
||||
dictionary_call( transfer, DICT_BUFFER, SET_RELOAD_PAGENUM1, 0x0000, 0x01,
|
||||
USB_IN, NULL, 1);
|
||||
|
||||
|
||||
} else {
|
||||
sentinel("Not setup to handle this buffer config");
|
||||
}
|
||||
|
||||
|
||||
return SUCCESS;
|
||||
error:
|
||||
return ~SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* Desc:Set buffer mem_type and part_num
|
||||
* Pre: buffer is allocated
|
||||
* Post:both value set to buffer number passed in
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int set_mem_n_part( USBtransfer *transfer, int buff_num, int mem_type, int part_num )
|
||||
{
|
||||
return dictionary_call( transfer, DICT_BUFFER, SET_MEM_N_PART,
|
||||
//( (mem_type<<8) | (part_num) ), buff_num, USB_IN, NULL, 1);
|
||||
( (mem_type<<8) | (part_num) ), 1, USB_IN, NULL, 1);
|
||||
// 0xAABB, buff_num, USB_IN, NULL, 1);
|
||||
}
|
||||
|
||||
/* Desc:Set buffer mapper and map_var
|
||||
* Pre: buffer is allocated
|
||||
* Post:both value set to buffer number passed in
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int set_map_n_mapvar( USBtransfer *transfer, int buff_num, int mapper, int map_var )
|
||||
{
|
||||
return dictionary_call( transfer, DICT_BUFFER, SET_MAP_N_MAPVAR,
|
||||
( (mapper<<8) | (map_var) ), buff_num, USB_IN, NULL, 1);
|
||||
// 0xCCDD, buff_num, USB_IN, NULL, 1);
|
||||
}
|
||||
|
||||
/* Desc:Set buffer manager operation
|
||||
* Pre: buffers are allocated and elements set ready to start operation
|
||||
* Post:operation starts on device
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int set_buff_operation( USBtransfer *transfer, int operation )
|
||||
{
|
||||
return dictionary_call( transfer, DICT_BUFFER, SET_BUFFER_OPERATION, operation,
|
||||
NILL, USB_IN, NULL, 1);
|
||||
}
|
||||
|
||||
/* Desc:Payload IN transfer
|
||||
* Pre: buffers are allocated operation started
|
||||
* Post:payload of length stored in data
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int payload_in( USBtransfer *transfer, uint8_t *data, int length )
|
||||
{
|
||||
return dictionary_call( transfer, DICT_BUFFER, BUFF_PAYLOAD, NILL, NILL,
|
||||
USB_IN, data, length);
|
||||
}
|
||||
|
||||
/* Desc:Get buffer elements and print them
|
||||
* Pre: buffers are allocated
|
||||
* Post:
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int get_buff_elements( USBtransfer *transfer, int buff_num )
|
||||
{
|
||||
printf("pri buff%d:", buff_num);
|
||||
dictionary_call_debug( transfer, DICT_BUFFER, GET_PRI_ELEMENTS, NILL, buff_num,
|
||||
USB_IN, NULL, 8);
|
||||
printf("sec buff%d:", buff_num);
|
||||
dictionary_call_debug( transfer, DICT_BUFFER, GET_SEC_ELEMENTS, NILL, buff_num,
|
||||
USB_IN, NULL, 8);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/* Desc:Get buffer opertationt
|
||||
* Pre:
|
||||
* Post:
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int get_buff_operation( USBtransfer *transfer )
|
||||
{
|
||||
printf("operation:");
|
||||
dictionary_call_debug( transfer, DICT_BUFFER, GET_BUFF_OPERATION, NILL, NILL,
|
||||
USB_IN, NULL, RV_DATA0_IDX+1);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,11 @@
|
|||
|
||||
int reset_buffers( USBtransfer *transfer );
|
||||
int allocate_buffers( USBtransfer *transfer, int num_buffers, int buff_size );
|
||||
int set_mem_n_part( USBtransfer *transfer, int buff_num, int mem_type, int part_num );
|
||||
int set_map_n_mapvar( USBtransfer *transfer, int buff_num, int mapper, int map_var );
|
||||
int set_buff_operation( USBtransfer *transfer, int operation );
|
||||
int payload_in( USBtransfer *transfer, uint8_t *data, int length );
|
||||
int get_buff_elements( USBtransfer *transfer, int buff_num );
|
||||
int get_buff_operation( USBtransfer *transfer );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,12 +10,19 @@
|
|||
//Once final mapper is known store header data in rom file and start dumping!
|
||||
int dump_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart )
|
||||
{
|
||||
int num_buffers = 2;
|
||||
int buff_size = 128;
|
||||
int buff0 = 0;
|
||||
int buff1 = 1;
|
||||
int i;
|
||||
uint8_t data[buff_size];
|
||||
|
||||
|
||||
debug("dumping cart");
|
||||
|
||||
//TODO provide user arg to force all these checks passed
|
||||
//first check if any provided args differ from what was detected
|
||||
check( cart->console != UNKNOWN,
|
||||
"cartridge not detected, must provide console if autodetection is off");
|
||||
check( (cart->console != UNKNOWN), "cartridge not detected, must provide console if autodetection is off");
|
||||
|
||||
if ( rom->console != UNKNOWN ) {
|
||||
check( rom->console == cart->console,
|
||||
|
|
@ -26,6 +33,9 @@ int dump_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart )
|
|||
"request mapper dump doesn't match detected mapper");
|
||||
}
|
||||
|
||||
//start with reset and init
|
||||
io_reset( transfer );
|
||||
nes_init( transfer );
|
||||
//Run some CRC's to determine size of memories
|
||||
|
||||
//setup buffers and manager
|
||||
|
|
@ -33,28 +43,83 @@ int dump_cart( USBtransfer* transfer, rom_image *rom, cartridge *cart )
|
|||
check(! reset_buffers( transfer ), "Unable to reset device buffers");
|
||||
//need to allocate some buffers for dumping
|
||||
//2x 128Byte buffers
|
||||
int num_buffers = 2;
|
||||
int buff_size = 128;
|
||||
check(! allocate_buffers( transfer, num_buffers, buff_size ), "Unable to allocate buffers");
|
||||
|
||||
//set buffer elements as needed
|
||||
//set reload which gets added to page_num after each buffer read
|
||||
//set reload to 256 = 1 when translated to page_num (done in allocate buffers funct)
|
||||
//set page_num to non-zero if offset arg sent
|
||||
//set mem_type and part_num to designate how to get/write data
|
||||
//check(! set_mem_n_part( transfer, buff0, MASKROM, PRGROM ), "Unable to set mem_type and part");
|
||||
//check(! set_mem_n_part( transfer, buff1, MASKROM, PRGROM ), "Unable to set mem_type and part");
|
||||
check(! set_mem_n_part( transfer, buff0, 0x12, 0x34 ), "Unable to set mem_type and part");
|
||||
check(! set_mem_n_part( transfer, buff1, 0x56, 0x78 ), "Unable to set mem_type and part");
|
||||
//set multiple and add_mult only when flashing
|
||||
//set mapper, map_var, and function to designate read/write algo
|
||||
|
||||
//just dump visible NROM memory to start
|
||||
//check(! set_map_n_mapvar( transfer, buff0, NROM, NILL ), "Unable to set mapper and map_var");
|
||||
//check(! set_map_n_mapvar( transfer, buff1, NROM, NILL ), "Unable to set mapper and map_var");
|
||||
check(! set_map_n_mapvar( transfer, buff0, 0x89, 0xAB ), "Unable to set mapper and map_var");
|
||||
check(! set_map_n_mapvar( transfer, buff1, 0xCD, 0XEF ), "Unable to set mapper and map_var");
|
||||
|
||||
//tell buffers what function to use for dumping
|
||||
//TODO when start implementing other mappers
|
||||
|
||||
//debugging print out buffer elements
|
||||
get_buff_operation( transfer );
|
||||
get_buff_elements( transfer, buff0 );
|
||||
get_buff_elements( transfer, buff1 );
|
||||
|
||||
debug("setting operation STARTDUMP");
|
||||
//inform buffer manager to start dumping operation now that buffers are initialized
|
||||
check(! set_buff_operation( transfer, STARTDUMP ), "Unable to set buffer operation");
|
||||
|
||||
get_buff_operation( transfer );
|
||||
get_buff_elements( transfer, buff0 );
|
||||
get_buff_elements( transfer, buff1 );
|
||||
//manager updates buffer status' so they'll start dumping
|
||||
//once they're full manager prepares them to be read back on USB payloads
|
||||
//once the next payload request happens manager knows last buffer can start dumping again
|
||||
//buffer updates it's elements and goes off to dump next page
|
||||
|
||||
debug("first payload");
|
||||
check(! payload_in( transfer, data, buff_size ), "Error with payload IN");
|
||||
check(! append_to_file( rom, data, buff_size ), "Error with file append");
|
||||
|
||||
get_buff_operation( transfer );
|
||||
get_buff_elements( transfer, buff0 );
|
||||
get_buff_elements( transfer, buff1 );
|
||||
|
||||
debug("second payload");
|
||||
check(! payload_in( transfer, data, buff_size ), "Error with payload IN");
|
||||
check(! append_to_file( rom, data, buff_size ), "Error with file append");
|
||||
|
||||
get_buff_operation( transfer );
|
||||
get_buff_elements( transfer, buff0 );
|
||||
get_buff_elements( transfer, buff1 );
|
||||
|
||||
//now just need to call series of payload IN transfers to retrieve data
|
||||
//for( i=0; i<(32*KByte/buff_size); i++) {
|
||||
// for( i=0; i<(8*KByte/buff_size); i++) {
|
||||
// //payload transfer in and append to file
|
||||
// if ( i % 32 == 0 ) debug("payload in #%d", i);
|
||||
// check(! payload_in( transfer, data, buff_size ), "Error with payload IN");
|
||||
// check(! append_to_file( rom, data, buff_size ), "Error with file append");
|
||||
// }
|
||||
debug("payload done");
|
||||
|
||||
//TODO flush file from time to time..?
|
||||
|
||||
|
||||
//tell buffer manager when to stop
|
||||
//reset buffers and setup to dump CHR-ROM
|
||||
|
||||
//close file in main
|
||||
|
||||
//reset io at end
|
||||
io_reset( transfer );
|
||||
|
||||
return SUCCESS;
|
||||
error:
|
||||
return ~SUCCESS;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int close_rom( rom_image *rom )
|
||||
{
|
||||
debug("flushing");
|
||||
fflush(rom->fileptr);
|
||||
debug("closing");
|
||||
return fclose( rom->fileptr );
|
||||
}
|
||||
|
||||
int detect_file( rom_image *rom )
|
||||
{
|
||||
int rv = 0;
|
||||
|
|
@ -105,3 +113,23 @@ int create_file( rom_image *rom, char *filename )
|
|||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Desc:Append data to rom file
|
||||
* Pre: rom file created and opened
|
||||
* Post:data of length appended to file
|
||||
* file still open
|
||||
* Rtn: SUCCESS if no errors
|
||||
*/
|
||||
int append_to_file( rom_image *rom, uint8_t *data, int length )
|
||||
{
|
||||
int rv = 0;
|
||||
//size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
rv = fwrite( data, sizeof(data[0]), length, rom->fileptr );
|
||||
|
||||
check( (rv == length), "Error appending to file, %dB out written when trying to write %d", rv, length);
|
||||
|
||||
return SUCCESS;
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <libusb.h>
|
||||
|
||||
//TODO put defintions in separate project wide .h file
|
||||
#include "cartridge.h"
|
||||
|
|
@ -39,5 +38,7 @@ void init_rom_elements(rom_image *rom);
|
|||
int open_rom( rom_image *rom, char *filename );
|
||||
int detect_file( rom_image *rom );
|
||||
int create_file( rom_image *rom, char *filename );
|
||||
int append_to_file( rom_image *rom, uint8_t *data, int length );
|
||||
int close_rom( rom_image *rom );
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -263,6 +263,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
//collected as much info as can dump cart without reading any data
|
||||
check( !dump_cart( transfer, rom, cart ), "Error while dumping cart");
|
||||
debug("done dumping, closing");
|
||||
|
||||
check(! close_rom( rom ), "Problem closing file");
|
||||
rom->fileptr = NULL;
|
||||
debug("closed");
|
||||
}
|
||||
|
||||
if ( p_value ) {
|
||||
|
|
|
|||
|
|
@ -20,14 +20,6 @@
|
|||
#include "dictionary.h"
|
||||
#include "shared_enums.h"
|
||||
|
||||
//SST 39SF0x0 manf/prod IDs
|
||||
#define SST_MANF_ID 0xBF
|
||||
#define SST_PROD_128 0xB5
|
||||
#define SST_PROD_256 0xB6
|
||||
#define SST_PROD_512 0xB7
|
||||
|
||||
//SRAM manf/prod ID
|
||||
#define SRAM 0xAA
|
||||
|
||||
//KByte for easy math
|
||||
#define KByte 1024
|
||||
|
|
|
|||
|
|
@ -4,6 +4,43 @@ int test_function( USBtransfer *transfer )
|
|||
{
|
||||
|
||||
debug("testing");
|
||||
|
||||
//debug("uninit");
|
||||
//get_buff_elements( transfer, 0 );
|
||||
//get_buff_elements( transfer, 1 );
|
||||
|
||||
/*
|
||||
check(! reset_buffers( transfer ), "Unable to reset device buffers");
|
||||
//need to allocate some buffers for dumping
|
||||
//2x 128Byte buffers
|
||||
check(! allocate_buffers( transfer, 2, 128 ), "Unable to allocate buffers");
|
||||
|
||||
debug("reset and allocate");
|
||||
get_buff_elements( transfer, 0 );
|
||||
get_buff_elements( transfer, 1 );
|
||||
|
||||
check(! set_mem_n_part( transfer, 0, 0x12, 0x34 ), "Unable to set mem_type and part");
|
||||
debug("set buff0 mem_n_part");
|
||||
get_buff_elements( transfer, 0 );
|
||||
get_buff_elements( transfer, 1 );
|
||||
check(! set_mem_n_part( transfer, 1, 0x56, 0x78 ), "Unable to set mem_type and part");
|
||||
debug("set buff1 mem_n_part");
|
||||
get_buff_elements( transfer, 0 );
|
||||
get_buff_elements( transfer, 1 );
|
||||
|
||||
check(! set_map_n_mapvar( transfer, 0, 0x89, 0xAB ), "Unable to set mapper and map_var");
|
||||
debug("set buff0 map_n_mapvar");
|
||||
get_buff_elements( transfer, 0 );
|
||||
get_buff_elements( transfer, 1 );
|
||||
check(! set_map_n_mapvar( transfer, 1, 0xCD, 0XEF ), "Unable to set mapper and map_var");
|
||||
debug("set buff1 map_n_mapvar");
|
||||
|
||||
get_buff_operation( transfer );
|
||||
get_buff_elements( transfer, 0 );
|
||||
get_buff_elements( transfer, 1 );
|
||||
*/
|
||||
/*
|
||||
|
||||
dictionary_call( transfer, DICT_IO, IO_RESET, 0, 0, USB_IN, NULL, 1);
|
||||
dictionary_call( transfer, DICT_IO, NES_INIT, 0, 0, USB_IN, NULL, 1);
|
||||
dictionary_call( transfer, DICT_IO, EXP0_PULLUP_TEST, 0, 0, USB_IN, NULL, 8);
|
||||
|
|
@ -95,7 +132,6 @@ int test_function( USBtransfer *transfer )
|
|||
printf(" %x",load_in[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
//clock_t tstart, tstop;
|
||||
//printf("load_in data:");
|
||||
//for (i=0; i<254; i++) {
|
||||
|
|
@ -173,7 +209,7 @@ int test_function( USBtransfer *transfer )
|
|||
printf("\n");
|
||||
|
||||
dictionary_call( transfer, DICT_IO, IO_RESET, 0, 0, USB_IN, NULL, 1);
|
||||
|
||||
*/
|
||||
// dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER2, 0x3508, 4);
|
||||
// dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER3, 0x4A0C, 4);
|
||||
// dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0);
|
||||
|
|
@ -291,4 +327,7 @@ int test_function( USBtransfer *transfer )
|
|||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "shared_enums.h"
|
||||
#include "shared_dictionaries.h"
|
||||
#include "dictionary.h"
|
||||
#include "buffer.h"
|
||||
|
||||
//uncomment to DEBUG this file alone
|
||||
#define DEBUG
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@
|
|||
//designate what buffer to fill with miscdata byte
|
||||
//no return value as it's write OUT only
|
||||
//operandMSB:LSB actually contains first 2 bytes
|
||||
#define BUFF_NODESG_PAYLOAD 0x41
|
||||
#define BUFF_PAYLOADN 0x41
|
||||
|
||||
|
||||
//#define BUFF_PAYLOADN_MAX 0x4F
|
||||
|
|
@ -185,6 +185,9 @@
|
|||
//return value status of that raw bank (set to bank id if allocated)
|
||||
#define RAW_BANK_STATUS 0x60
|
||||
|
||||
//retrieve buffer manager current operation variable
|
||||
#define GET_BUFF_OPERATION 0x61
|
||||
|
||||
|
||||
|
||||
//#define BUFF_OPCODE_RV_MAX 0x6F
|
||||
|
|
|
|||
|
|
@ -56,6 +56,20 @@ enum operations {
|
|||
CHECK
|
||||
};
|
||||
|
||||
//SST 39SF0x0 manf/prod IDs
|
||||
#define SST_MANF_ID 0xBF
|
||||
#define SST_PROD_128 0xB5
|
||||
#define SST_PROD_256 0xB6
|
||||
#define SST_PROD_512 0xB7
|
||||
|
||||
|
||||
//SRAM manf/prod ID
|
||||
#define SRAM 0xAA
|
||||
|
||||
|
||||
//MASK ROM read only
|
||||
#define MASKROM 0xDD
|
||||
|
||||
enum buff_mem_type {
|
||||
PRGROM = 10,
|
||||
CHRROM,
|
||||
|
|
@ -66,6 +80,7 @@ enum buff_mem_type {
|
|||
|
||||
//buffer status values
|
||||
#define EMPTY 0x00
|
||||
#define RESET 0x01
|
||||
#define PROBLEM 0x10
|
||||
#define USB_UNLOADING 0x80
|
||||
#define USB_LOADING 0x90
|
||||
|
|
|
|||
Loading…
Reference in New Issue