flashing page working, verified by reading back again.

currently instruct buffer to dump/flash by setting its function accordingly
This commit is contained in:
paul eeepc 2016-12-01 00:45:10 -06:00
parent 937435220a
commit a24d728cea
4 changed files with 115 additions and 7 deletions

View File

@ -492,10 +492,6 @@ void update_buffers()
//now it can be read back in next IN transfer
}
//lets ignore flashing for now, prob best to dump first so can check results when trying to flash..
return;
//for now lets use one buffer to flash a cartridge
//later try a second one to double buffer, might not actually matter much..
// buffer *buff = &buff0;
@ -509,7 +505,7 @@ void update_buffers()
//enough for usbFunction write to not notice
} else {
//if there are no full buffers yet simply exit
return;
//return;
}
//found a buffer that's full and ready to flash onto cart
@ -520,7 +516,19 @@ void update_buffers()
//update any other necessary elements
//send it off to it's flashing routine
result = flash_page( buff );
if ( buff->function == FLASHING ) {
buff->cur_byte = 0;
//to start lets just dump the first page of PRG-ROM
result = flash_page( buff );
if (result == SUCCESS) {
buff->status = DUMPED;
}
//now it can be read back in next IN transfer
}
//now that it's flashed perform verifications if needed

View File

@ -9,6 +9,36 @@
*/
uint8_t flash_page( buffer *buff ) {
uint8_t addrH = (buff->page_num | 0x80); //or in $8000 to set equiv CPU address
uint8_t read;
//lets start just reading first page of PRG-ROM then get fancy
while (buff->cur_byte < buff->last_idx) {
//write unlock sequence first
discrete_exp0_prgrom_wr( 0x55, 0x55, 0xAA );
discrete_exp0_prgrom_wr( 0x2A, 0xAA, 0x55 );
discrete_exp0_prgrom_wr( 0x55, 0x55, 0xA0 );
//then flash byte
discrete_exp0_prgrom_wr( addrH, buff->cur_byte, buff->data[buff->cur_byte] );
//then spin until write finished
read = nes_cpu_rd(addrH,buff->cur_byte);
while ( read != nes_cpu_rd(addrH,buff->cur_byte) ) {
read = nes_cpu_rd(addrH,buff->cur_byte);
}
//byte stable, now verify proper value
if ( read == buff->data[buff->cur_byte] ) {
buff->cur_byte++;
_LED_OFF();
} else {//don't increment, retry
_LED_OP();
_LED_ON();
}
}
return SUCCESS;

View File

@ -5,7 +5,37 @@ int erase_nes( USBtransfer *transfer )
debug("erasing");
dictionary_call( transfer, IO, IO_RESET, 0, 0, USB_IN, NULL, 1);
dictionary_call( transfer, IO, NES_INIT, 0, 0, USB_IN, NULL, 1);
dictionary_call( transfer, IO, EXP0_PULLUP_TEST,0, 0, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0x80, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0xAA, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x2AAA, 0x55, USB_IN, NULL, 1);
dictionary_call( transfer, NES, DISCRETE_EXP0_PRGROM_WR, 0x5555, 0x10, USB_IN, NULL, 1);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
dictionary_call( transfer, NES, NES_CPU_RD, 0x8000, 0, USB_IN, NULL, 2);
//dictionary_call( transfer, IO, IO_RESET, 0, 0);
//dictionary_call( transfer, IO, NES_INIT, 0, 0);
//dictionary_call( transfer, IO, EXP0_PULLUP_TEST, 0, 0);

View File

@ -85,7 +85,7 @@ int test_function( USBtransfer *transfer )
dictionary_call( transfer, USB, 0, 0, 0, USB_IN, NULL, 3);
debug("send payload0");
dictionary_call( transfer, BUFFER, BUFF_OUT_PAYLOAD_2B_INSP, 0xA5C3, 0, USB_OUT, &load_out[2], 254);
dictionary_call( transfer, BUFFER, BUFF_OUT_PAYLOAD_2B_INSP, 0xa5c3, 0, USB_OUT, &load_out[2], 254);
debug("read payload0");
dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_IN, load_in, 254);
@ -126,6 +126,46 @@ int test_function( USBtransfer *transfer )
debug("read payload0");
dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_IN, load_in, 254);
dictionary_call( transfer, BUFFER, SET_FUNCTION, 0, 0, USB_IN, NULL, 1);
printf("load_in data:");
for (i=0; i<254; i++) {
printf(" %x",load_in[i]);
}
printf("\n");
printf("load_out with data:");
for (i=0; i<256; i++) {
printf(" %x",load_out[i]);
}
printf("\n");
debug("send payload0");
dictionary_call( transfer, BUFFER, BUFF_OUT_PAYLOAD_2B_INSP, 0xa5c3, 0, USB_OUT, &load_out[2], 254);
debug("set func");
dictionary_call( transfer, BUFFER, SET_FUNCTION, FLASHING, 0, USB_IN, NULL, 1);
debug("get sec");
dictionary_call( transfer, BUFFER, GET_SEC_ELEMENTS, 0, 0, USB_IN, NULL, 8);
dictionary_call( transfer, BUFFER, GET_SEC_ELEMENTS, 0, 1, USB_IN, NULL, 8);
debug("read payload0");
dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_IN, load_in, 254);
printf("load_in data:");
for (i=0; i<254; i++) {
printf(" %x",load_in[i]);
}
printf("\n");
debug("set func");
dictionary_call( transfer, BUFFER, SET_FUNCTION, DUMPING, 0, USB_IN, NULL, 1);
debug("get sec");
dictionary_call( transfer, BUFFER, GET_SEC_ELEMENTS, 0, 0, USB_IN, NULL, 8);
dictionary_call( transfer, BUFFER, GET_SEC_ELEMENTS, 0, 1, USB_IN, NULL, 8);
debug("read payload0");
dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_IN, load_in, 254);
printf("load_in data:");
for (i=0; i<254; i++) {
printf(" %x",load_in[i]);