Have PRG-ROM flashing working for NROM on AVR KAZZO
Need to get stm32 up and working, currently the usbFunctionWrite causes device descriptor request to fail on stm32 devices. So need to do some debugging there which I was expecting..
This commit is contained in:
parent
f4aa907e69
commit
82a6b606dd
|
|
@ -166,6 +166,7 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint8_t *rlen)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//opcodes which include designation of which buffer is being called in lower bits of opcode
|
//opcodes which include designation of which buffer is being called in lower bits of opcode
|
||||||
|
//TODO get rid of these opcodes, and just always put buffer number in miscdata!!
|
||||||
case BUFF_OPCODE_BUFN_MIN ... BUFF_OPCODE_BUFN_MAX:
|
case BUFF_OPCODE_BUFN_MIN ... BUFF_OPCODE_BUFN_MAX:
|
||||||
//mask out last three bits to detect buffer being called based on opcode number
|
//mask out last three bits to detect buffer being called based on opcode number
|
||||||
switch ( (spacket->opcode) & 0x07) {
|
switch ( (spacket->opcode) & 0x07) {
|
||||||
|
|
@ -298,13 +299,11 @@ uint8_t * buffer_payload( setup_packet *spacket, buffer *buff, uint8_t hostsetbu
|
||||||
//now only thing left to do is stuff 2 bytes from setup packet into the buffer if designated by the opcode
|
//now only thing left to do is stuff 2 bytes from setup packet into the buffer if designated by the opcode
|
||||||
if ( (cur_buff->status == USB_LOADING) &&
|
if ( (cur_buff->status == USB_LOADING) &&
|
||||||
((spacket->opcode == BUFF_OUT_PAYLOAD_2B_INSP)||(spacket->opcode == BUFF_OUT_PAYLOADN_2B_INSP)) ) {
|
((spacket->opcode == BUFF_OUT_PAYLOAD_2B_INSP)||(spacket->opcode == BUFF_OUT_PAYLOADN_2B_INSP)) ) {
|
||||||
//operandMSB:LSB actually contains first 2 bytes
|
//operandLSB:MSB actually contains first 2 bytes
|
||||||
//these two bytes don't count as part of transfer OUT byte count
|
//these two bytes don't count as part of transfer OUT byte count
|
||||||
//but they do count as part of buffer's byte count.
|
//but they do count as part of buffer's byte count.
|
||||||
// cur_usb_load_buff->data[0] = spacket->operandMSB;
|
cur_usb_load_buff->data[0] = spacket->operand;
|
||||||
cur_usb_load_buff->data[0] = (spacket->operand)>>8;
|
cur_usb_load_buff->data[1] = (spacket->operand)>>8;
|
||||||
// cur_usb_load_buff->data[1] = spacket->operandLSB;
|
|
||||||
cur_usb_load_buff->data[1] = spacket->operand;
|
|
||||||
cur_usb_load_buff->cur_byte += 2;
|
cur_usb_load_buff->cur_byte += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -670,7 +669,7 @@ void update_buffers()
|
||||||
|
|
||||||
last_buff->status = FLASHING;
|
last_buff->status = FLASHING;
|
||||||
//last_buff->cur_byte = 0;
|
//last_buff->cur_byte = 0;
|
||||||
//TODO CALL FLASHBUFF result = flash_buff( last_buff );
|
result = flash_buff( last_buff );
|
||||||
if (result != SUCCESS) {
|
if (result != SUCCESS) {
|
||||||
last_buff->status = result;
|
last_buff->status = result;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@
|
||||||
#include "operation.h"
|
#include "operation.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
|
#include "flash.h"
|
||||||
//#include "flash.h"
|
|
||||||
|
|
||||||
#define FALSE 0x00 //TODO remove this junk!
|
#define FALSE 0x00 //TODO remove this junk!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
#include "flash.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t write_page( uint8_t bank, uint8_t addrH, buffer *buff, write_funcptr wr_func, read_funcptr rd_func )
|
||||||
|
{
|
||||||
|
uint16_t cur = buff->cur_byte;
|
||||||
|
uint8_t n = buff->cur_byte;
|
||||||
|
uint8_t read;
|
||||||
|
// extern operation_info *oper_info;
|
||||||
|
|
||||||
|
while ( cur <= buff->last_idx ) {
|
||||||
|
//write unlock sequence
|
||||||
|
//need to make address and unlock data variable
|
||||||
|
//best for host to communcate these values
|
||||||
|
//actual value is part mapper dependent and part flash dependent
|
||||||
|
//mapper controlled address bits dictate where split is
|
||||||
|
//32KB banking A14-0 NES ctl, A15+ mapper ctl "bank" NROM, BNROM, ANROM
|
||||||
|
//addrH_dmask = 0b0111 1111 directly addressable addrH bits
|
||||||
|
//page2bankshft = A14->A8 = 7 shifts (equal to number of set bits in addrH_mask
|
||||||
|
//16KB banking A13-0 NES ctl, A14+ mapper ctl "bank" UxROM, MMC1
|
||||||
|
//addrH_dmask = 0b0011 1111
|
||||||
|
//page2bankshft = A13->A8 = 6 shifts
|
||||||
|
// 8KB banking A12-0 NES ctl, A13+ mapper ctl "bank" MMC3, FME7
|
||||||
|
//addrH_dmask = 0b0001 1111
|
||||||
|
//page2bankshft = A12->A8 = 5 shifts
|
||||||
|
// 4KB banking A11-0 NES ctl, A12+ mapper ctl "bank" ezNSF
|
||||||
|
//addrH_dmask = 0b0000 1111
|
||||||
|
//page2bankshft = A11->A8 = 4 shifts
|
||||||
|
wr_func( 0x5555, 0xAA );
|
||||||
|
// wr_func( oper_info->unlock1_AH, oper_info->unlock1_AL, oper_info->unlock1_data );
|
||||||
|
wr_func( 0x2AAA, 0x55 );
|
||||||
|
// wr_func( oper_info->unlock2_AH, oper_info->unlock2_AL, oper_info->unlock2_data );
|
||||||
|
wr_func( 0x5555, 0xA0 );
|
||||||
|
// wr_func( oper_info->command_AH, oper_info->command_AL, oper_info->command1_data );
|
||||||
|
wr_func( ((addrH<<8)| n), buff->data[n] );
|
||||||
|
|
||||||
|
do {
|
||||||
|
usbPoll();
|
||||||
|
read = rd_func((addrH<<8)|n);
|
||||||
|
|
||||||
|
} while( read != rd_func((addrH<<8)|n) );
|
||||||
|
//TODO verify byte is value that was trying to be flashed
|
||||||
|
//move on to next byte
|
||||||
|
n++;
|
||||||
|
cur++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buff->cur_byte = n;
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Desc:Flash buffer contents on to cartridge memory
|
||||||
|
* Pre: buffer elements must be updated to designate how/where to flash
|
||||||
|
* buffer's cur_byte must be cleared or set to where to start flashing
|
||||||
|
* mapper registers must be initialized
|
||||||
|
* Post:buffer page flashed/programmed to memory.
|
||||||
|
* Rtn: SUCCESS or ERROR# depending on if there were errors.
|
||||||
|
*/
|
||||||
|
uint8_t flash_buff( buffer *buff ) {
|
||||||
|
|
||||||
|
uint8_t addrH = buff->page_num; //A15:8 while accessing page
|
||||||
|
|
||||||
|
//First need to initialize mapper register bits
|
||||||
|
//Perhaps this only needs to be done on first buffer though..?
|
||||||
|
//Actually think this is best handled from buffer.c in operation == STARTFLASH
|
||||||
|
|
||||||
|
//TODO use mapper to set mapper controlled address bits
|
||||||
|
|
||||||
|
//need to calculate current bank and addrH
|
||||||
|
|
||||||
|
//TODO set unlock addresses based on what works for that mapper and how it's banks are initialized
|
||||||
|
|
||||||
|
//use mem_type to set addrH/X as needed for dump loop
|
||||||
|
//also use to get read function pointer
|
||||||
|
switch ( buff->mem_type ) {
|
||||||
|
case PRGROM: //$8000
|
||||||
|
write_page( 0, (0x80 | addrH), buff, discrete_exp0_prgrom_wr, nes_cpu_rd );
|
||||||
|
break;
|
||||||
|
case CHRROM: //$0000
|
||||||
|
//TODO write_page( 0, addrH, buff, nes_ppu_wr, nes_ppu_rd );
|
||||||
|
break;
|
||||||
|
case PRGRAM:
|
||||||
|
//addrH |= 0x60; //$6000
|
||||||
|
//buff->cur_byte = nes_cpu_page_wr_poll( buff->data, addrH, buff->id,
|
||||||
|
// buff->last_idx, ~FALSE );
|
||||||
|
break;
|
||||||
|
case SNESROM:
|
||||||
|
case SNESRAM:
|
||||||
|
//warn addrX = ((buff->page_num)>>8);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ERR_BUFF_UNSUP_MEM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//lets start just reading first page of PRG-ROM then get fancy
|
||||||
|
// while (buff->cur_byte < buff->last_idx) {
|
||||||
|
//
|
||||||
|
// //might be faster to put some of these in new pointers, but not sure..
|
||||||
|
// buff->data[buff->cur_byte] = nes_cpu_rd( addrH, buff->cur_byte );
|
||||||
|
// buff->cur_byte++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _flash_h
|
||||||
|
#define _flash_h
|
||||||
|
|
||||||
|
#include "pinport.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "nes.h"
|
||||||
|
#include "shared_dictionaries.h"
|
||||||
|
#include "shared_errors.h"
|
||||||
|
|
||||||
|
uint8_t flash_buff( buffer *buff ) ;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -12,8 +12,10 @@ typedef struct setup_packet{
|
||||||
|
|
||||||
|
|
||||||
//write function pointers
|
//write function pointers
|
||||||
typedef void (*write_funcptr) ( uint8_t addrH, uint8_t addrL, uint8_t data );
|
//typedef void (*write_funcptr) ( uint8_t addrH, uint8_t addrL, uint8_t data );
|
||||||
typedef uint8_t (*read_funcptr) ( uint8_t addrH, uint8_t addrL );
|
//typedef uint8_t (*read_funcptr) ( uint8_t addrH, uint8_t addrL );
|
||||||
|
typedef void (*write_funcptr) ( uint16_t addr, uint8_t data );
|
||||||
|
typedef uint8_t (*read_funcptr) ( uint16_t addr );
|
||||||
|
|
||||||
|
|
||||||
//~16 bytes per buffer...
|
//~16 bytes per buffer...
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ uint16_t usbFunctionSetup(uint8_t data[8]) {
|
||||||
// w/o checks: 512KByte = 17.9sec = 28.5KBps
|
// w/o checks: 512KByte = 17.9sec = 28.5KBps
|
||||||
// w/o checks: using 8bit rlen = 17.5sec = 29.2KBps
|
// w/o checks: using 8bit rlen = 17.5sec = 29.2KBps
|
||||||
// with checks: using 8bit rlen = 18sec = 28.3KBps
|
// with checks: using 8bit rlen = 18sec = 28.3KBps
|
||||||
//#define MAKECHECKS 0
|
//#define MAKECHECKS
|
||||||
|
|
||||||
#ifdef AVR_CORE
|
#ifdef AVR_CORE
|
||||||
USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) {
|
USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) {
|
||||||
|
|
@ -224,7 +224,6 @@ USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) {
|
||||||
uint8_t usbFunctionWrite(uint8_t *data, uint8_t len) {
|
uint8_t usbFunctionWrite(uint8_t *data, uint8_t len) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
//defined and controled by buffer.c
|
//defined and controled by buffer.c
|
||||||
extern buffer *cur_usb_load_buff;
|
extern buffer *cur_usb_load_buff;
|
||||||
extern uint8_t incoming_bytes_remain;
|
extern uint8_t incoming_bytes_remain;
|
||||||
|
|
@ -280,7 +279,5 @@ uint8_t usbFunctionWrite(uint8_t *data, uint8_t len) {
|
||||||
return NOT_DONE;
|
return NOT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -342,6 +342,45 @@ local function buffer_payload_in( wLength, buff_num )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function buffer_payload_out( num_bytes, data, buff_num )
|
||||||
|
|
||||||
|
local opcode = nil
|
||||||
|
|
||||||
|
local wLength = 0
|
||||||
|
if num_bytes == 256 then
|
||||||
|
--2B in setup packet
|
||||||
|
operand = string.unpack("B", data ,1) | (string.unpack("B", data ,2)<<8)
|
||||||
|
-- print(string.format("%04X ", operand))
|
||||||
|
--operand = string.sub(data, 1, 2)
|
||||||
|
wLength = 254
|
||||||
|
if not buff_num then
|
||||||
|
opcode = op_buffer["BUFF_OUT_PAYLOAD_2B_INSP"]
|
||||||
|
buff_num = 0
|
||||||
|
else
|
||||||
|
opcode = op_buffer["BUFF_OUT_PAYLOADN_2B_INSP"]
|
||||||
|
end
|
||||||
|
else --don't stuff data in setup packet
|
||||||
|
wLength = num_bytes
|
||||||
|
operand = 0
|
||||||
|
if not buff_num then
|
||||||
|
opcode = op_buffer["BUFF_PAYLOAD"]
|
||||||
|
buff_num = 0
|
||||||
|
else
|
||||||
|
opcode = op_buffer["BUFF_PAYLOAD0"] + buff_num
|
||||||
|
buff_num = 0 --these opcodes don't put buff num in miscdata, but should update them to do so.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local count
|
||||||
|
count, data = usb_vend_xfr(
|
||||||
|
USB_OUT, ((buff_num<<8) | dict["DICT_BUFFER"]), opcode, operand, wLength, data:sub(3,-1))
|
||||||
|
|
||||||
|
assert ( (count == wLength ), ("ERROR!!! host only sent:"..count.."bytes, expecting:"..wLength))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- external call for buffer dictionary
|
-- external call for buffer dictionary
|
||||||
local function buffer( opcode, operand, misc, data )
|
local function buffer( opcode, operand, misc, data )
|
||||||
|
|
||||||
|
|
@ -478,6 +517,7 @@ dict.io = io
|
||||||
dict.nes = nes
|
dict.nes = nes
|
||||||
dict.buffer = buffer
|
dict.buffer = buffer
|
||||||
dict.buffer_payload_in = buffer_payload_in
|
dict.buffer_payload_in = buffer_payload_in
|
||||||
|
dict.buffer_payload_out = buffer_payload_out
|
||||||
dict.operation = operation
|
dict.operation = operation
|
||||||
|
|
||||||
-- return the module's table
|
-- return the module's table
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
-- create the module's table
|
||||||
|
local erase = {}
|
||||||
|
|
||||||
|
-- import required modules
|
||||||
|
local dict = require "scripts.app.dict"
|
||||||
|
|
||||||
|
-- file constants
|
||||||
|
|
||||||
|
-- local functions
|
||||||
|
local function erase_nes()
|
||||||
|
|
||||||
|
local rv = nil
|
||||||
|
|
||||||
|
print("erasing_nrom");
|
||||||
|
|
||||||
|
dict.io("IO_RESET")
|
||||||
|
dict.io("NES_INIT")
|
||||||
|
|
||||||
|
print("erasing PRG-ROM");
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x5555, 0xAA)
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x2AAA, 0x55)
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x5555, 0x80)
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x5555, 0xAA)
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x2AAA, 0x55)
|
||||||
|
dict.nes("DISCRETE_EXP0_PRGROM_WR", 0x5555, 0x10)
|
||||||
|
rv = dict.nes("NES_CPU_RD", 0x8000)
|
||||||
|
|
||||||
|
local i = 0
|
||||||
|
|
||||||
|
while ( rv ~= 0xFF ) do
|
||||||
|
rv = dict.nes("NES_CPU_RD", 0x8000)
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
print(i, " done erasing prg.\n");
|
||||||
|
|
||||||
|
print("erasing CHR-ROM");
|
||||||
|
dict.nes("NES_PPU_WR", 0x1555, 0xAA)
|
||||||
|
dict.nes("NES_PPU_WR", 0x0AAA, 0x55)
|
||||||
|
dict.nes("NES_PPU_WR", 0x1555, 0x80)
|
||||||
|
dict.nes("NES_PPU_WR", 0x1555, 0xAA)
|
||||||
|
dict.nes("NES_PPU_WR", 0x0AAA, 0x55)
|
||||||
|
dict.nes("NES_PPU_WR", 0x1555, 0x10)
|
||||||
|
rv = dict.nes("NES_PPU_RD", 0x0000)
|
||||||
|
|
||||||
|
local i = 0
|
||||||
|
|
||||||
|
while ( rv ~= 0xFF ) do
|
||||||
|
rv = dict.nes("NES_PPU_RD", 0x0000)
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
print(i, " done erasing chr.\n");
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- global variables so other modules can use them
|
||||||
|
|
||||||
|
|
||||||
|
-- call functions desired to run when script is called/imported
|
||||||
|
|
||||||
|
|
||||||
|
-- functions other modules are able to call
|
||||||
|
erase.erase_nes = erase_nes
|
||||||
|
|
||||||
|
-- return the module's table
|
||||||
|
return erase
|
||||||
|
|
@ -0,0 +1,268 @@
|
||||||
|
|
||||||
|
-- create the module's table
|
||||||
|
local flash = {}
|
||||||
|
|
||||||
|
-- import required modules
|
||||||
|
local dict = require "scripts.app.dict"
|
||||||
|
local buffers = require "scripts.app.buffers"
|
||||||
|
|
||||||
|
-- file constants
|
||||||
|
|
||||||
|
-- local functions
|
||||||
|
local function flash_nes( file, debug )
|
||||||
|
--{
|
||||||
|
-- //make some checks to ensure rom is compatible with cart
|
||||||
|
--
|
||||||
|
-- //first do some checks like ensuring proper areas or sectors are blank
|
||||||
|
--
|
||||||
|
-- //erase sectors or chip as needed
|
||||||
|
--
|
||||||
|
-- //reset, allocate, and initialize device buffers
|
||||||
|
--
|
||||||
|
-- //initialize mapper registers as needed for memory being programmed
|
||||||
|
--
|
||||||
|
-- //set device operation to STARTFLASH
|
||||||
|
--
|
||||||
|
-- //send payload data
|
||||||
|
--
|
||||||
|
-- //run checksums to verify successful flash operation
|
||||||
|
--
|
||||||
|
local buff0 = 0
|
||||||
|
local buff1 = 1
|
||||||
|
local cur_buff_status = 0
|
||||||
|
local data = nil --lua stores data in strings
|
||||||
|
|
||||||
|
if debug then print("flashing cart") end
|
||||||
|
--
|
||||||
|
-- //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");
|
||||||
|
--
|
||||||
|
-- if ( rom->console != UNKNOWN ) {
|
||||||
|
-- check( rom->console == cart->console,
|
||||||
|
-- "request system dump doesn't match detected cartridge");
|
||||||
|
-- }
|
||||||
|
-- if ( (cart->mapper != UNKNOWN) && (rom->mapper != UNKNOWN) ) {
|
||||||
|
-- check( rom->mapper == cart->mapper,
|
||||||
|
-- "request mapper dump doesn't match detected mapper");
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- //start with reset and init
|
||||||
|
dict.io("IO_RESET")
|
||||||
|
dict.io("NES_INIT")
|
||||||
|
--
|
||||||
|
-- //start operation at reset
|
||||||
|
-- check(! set_operation( transfer, RESET ), "Unable to set buffer operation");
|
||||||
|
--
|
||||||
|
-- //setup buffers and manager
|
||||||
|
-- //reset buffers first
|
||||||
|
dict.buffer("RAW_BUFFER_RESET")
|
||||||
|
-- //need to allocate some buffers for flashing
|
||||||
|
-- //2x 256Byte buffers
|
||||||
|
local num_buffers = 2
|
||||||
|
local buff_size = 256
|
||||||
|
print("allocating buffers")
|
||||||
|
assert(buffers.allocate( num_buffers, buff_size ), "fail to allocate buffers")
|
||||||
|
--
|
||||||
|
-- //tell buffers what function to use for flashing
|
||||||
|
-- //load operation elements into buff0 and then copy buff0 to oper_info
|
||||||
|
-- load_oper_info_elements( transfer, cart );
|
||||||
|
-- get_oper_info_elements( transfer );
|
||||||
|
--
|
||||||
|
-- //setup buffers and manager
|
||||||
|
-- //reset buffers first
|
||||||
|
-- check(! reset_buffers( transfer ), "Unable to reset device buffers");
|
||||||
|
-- //need to allocate some buffers for flashing
|
||||||
|
-- //2x 256Byte buffers
|
||||||
|
-- check(! allocate_buffers( transfer, num_buffers, buff_size ), "Unable to allocate buffers");
|
||||||
|
--
|
||||||
|
-- //set mem_type and part_num to designate how to get/write data
|
||||||
|
print("setting map n part")
|
||||||
|
dict.buffer("SET_MEM_N_PART", (op_buffer["PRGROM"]<<8 | op_buffer["MASKROM"]), buff0 )
|
||||||
|
dict.buffer("SET_MEM_N_PART", (op_buffer["PRGROM"]<<8 | op_buffer["MASKROM"]), buff1 )
|
||||||
|
-- //set multiple and add_mult only when flashing
|
||||||
|
-- //TODO
|
||||||
|
-- //set mapper, map_var, and function to designate read/write algo
|
||||||
|
--
|
||||||
|
-- //just dump visible NROM memory to start
|
||||||
|
print("setting map n mapvar")
|
||||||
|
dict.buffer("SET_MAP_N_MAPVAR", (op_buffer["NROM"]<<8 | op_buffer["NOVAR"]), buff0 )
|
||||||
|
dict.buffer("SET_MAP_N_MAPVAR", (op_buffer["NROM"]<<8 | op_buffer["NOVAR"]), buff1 )
|
||||||
|
--
|
||||||
|
-- //debugging print out buffer elements
|
||||||
|
print("\nget operation:")
|
||||||
|
dict.operation("GET_OPERATION" )
|
||||||
|
print("\n\ngetting cur_buff status")
|
||||||
|
dict.buffer("GET_CUR_BUFF_STATUS" )
|
||||||
|
print("\n\ngetting elements")
|
||||||
|
print(dict.buffer("GET_PRI_ELEMENTS", nil, buff0 ))
|
||||||
|
print(dict.buffer("GET_PRI_ELEMENTS", nil, buff1 ))
|
||||||
|
print(dict.buffer("GET_SEC_ELEMENTS", nil, buff0 ))
|
||||||
|
print(dict.buffer("GET_SEC_ELEMENTS", nil, buff1 ))
|
||||||
|
print(dict.buffer("GET_PAGE_NUM", nil, buff0 ) )
|
||||||
|
print(dict.buffer("GET_PAGE_NUM", nil, buff1 ) )
|
||||||
|
|
||||||
|
print("\n\nsetting operation STARTFLASH");
|
||||||
|
-- //inform buffer manager to start dumping operation now that buffers are initialized
|
||||||
|
dict.operation("SET_OPERATION", op_buffer["STARTFLASH"] )
|
||||||
|
|
||||||
|
-- clock_t tstart, tstop;
|
||||||
|
-- tstart = clock();
|
||||||
|
--
|
||||||
|
-- //now just need to call series of payload IN transfers to retrieve data
|
||||||
|
--
|
||||||
|
-- for( i=0; i<(32*KByte/buff_size); i++) {
|
||||||
|
local i = 1
|
||||||
|
local nak = 0
|
||||||
|
for bytes in file:lines(buff_size) do
|
||||||
|
dict.buffer_payload_out( buff_size, bytes )
|
||||||
|
--for i = 1, #bytes do
|
||||||
|
-- local b = string.unpack("B", bytes, i)
|
||||||
|
-- io.write(string.format("%02X ", b))
|
||||||
|
--end
|
||||||
|
-- io.write(string.rep(" ", blocksize - #bytes))
|
||||||
|
-- bytes = string.gsub(bytes, "%c", ".")
|
||||||
|
-- io.write(" ", bytes, "\n")
|
||||||
|
-- break
|
||||||
|
-- while (cur_buff_status != EMPTY ) {
|
||||||
|
-- //debug("cur_buff->status: %x ", cur_buff_status);
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- }
|
||||||
|
cur_buff_status = dict.buffer("GET_CUR_BUFF_STATUS")
|
||||||
|
while (cur_buff_status ~= op_buffer["EMPTY"]) do
|
||||||
|
nak = nak +1
|
||||||
|
--print(nak, "cur_buff->status: ", cur_buff_status)
|
||||||
|
cur_buff_status = dict.buffer("GET_CUR_BUFF_STATUS")
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- }
|
||||||
|
end
|
||||||
|
if ( i == 32*1024/buff_size) then break end
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
print("number of naks", nak)
|
||||||
|
--
|
||||||
|
-- //The device doesn't have a good way to respond if the last buffer is flashing
|
||||||
|
-- //and the current one is full. We can only send a payload if the current buffer
|
||||||
|
-- //is empty.
|
||||||
|
-- waste some time for now..
|
||||||
|
print(dict.buffer("GET_PRI_ELEMENTS", nil, buff0 ))
|
||||||
|
print(dict.buffer("GET_PRI_ELEMENTS", nil, buff1 ))
|
||||||
|
print(dict.buffer("GET_SEC_ELEMENTS", nil, buff0 ))
|
||||||
|
print(dict.buffer("GET_SEC_ELEMENTS", nil, buff1 ))
|
||||||
|
print(dict.buffer("GET_PAGE_NUM", nil, buff0 ) )
|
||||||
|
print(dict.buffer("GET_PAGE_NUM", nil, buff1 ) )
|
||||||
|
--
|
||||||
|
-- //Read next chunk from file
|
||||||
|
-- check(! read_from_file( rom, data, buff_size ), "Error with file read");
|
||||||
|
--
|
||||||
|
-- //ensure cur_buff is EMPTY prior to sending data
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- while (cur_buff_status != EMPTY ) {
|
||||||
|
-- //debug("cur_buff->status: %x ", cur_buff_status);
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- //send data
|
||||||
|
-- check(! payload_out( transfer, data, buff_size ), "Error with payload OUT");
|
||||||
|
-- //if ( i % 256 == 0 ) debug("payload in #%d", i);
|
||||||
|
-- if ( i % 32 == 0 ) debug("payload out #%d", i);
|
||||||
|
-- }
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- //debug("\n\n\ncur_buff->status: %x\n", cur_buff_status);
|
||||||
|
--
|
||||||
|
-- //add check to ensure both buffers are done and operation is okay
|
||||||
|
-- //need to get status of buff1 and make sure it's flashed
|
||||||
|
-- while (cur_buff_status != FLASHED ) {
|
||||||
|
-- check(! get_buff_element_value( transfer, buff1, GET_PRI_ELEMENTS, BUFF_STATUS, &cur_buff_status ),
|
||||||
|
-- "Error retrieving buffer status post flashing");
|
||||||
|
-- // debug("\n\n\ncur_buff->status: %x\n", cur_buff_status);
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- debug("payload done");
|
||||||
|
--
|
||||||
|
-- //end operation at reset
|
||||||
|
-- check(! set_operation( transfer, RESET ), "Unable to set buffer operation");
|
||||||
|
--
|
||||||
|
-- tstop = clock();
|
||||||
|
-- float timediff = ( (float)(tstop-tstart) / CLOCKS_PER_SEC);
|
||||||
|
-- printf("total time: %fsec, speed: %fKBps\n", timediff, (32/timediff));
|
||||||
|
-- //TODO flush file from time to time..?
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- //tell buffer manager when to stop
|
||||||
|
-- // or not..? just reset buffers and start next memory or quit
|
||||||
|
-- //reset buffers and setup to dump CHR-ROM
|
||||||
|
--
|
||||||
|
-- //load operation elements into buff0 and then copy buff0 to oper_info
|
||||||
|
-- load_oper_info_elements_chr( transfer, cart );
|
||||||
|
-- get_oper_info_elements( transfer );
|
||||||
|
--
|
||||||
|
-- check(! reset_buffers( transfer ), "Unable to reset device buffers");
|
||||||
|
-- check(! allocate_buffers( transfer, num_buffers, buff_size ), "Unable to allocate buffers");
|
||||||
|
-- check(! set_mem_n_part( transfer, buff0, CHRROM, SST_MANF_ID ), "Unable to set mem_type and part");
|
||||||
|
-- check(! set_mem_n_part( transfer, buff1, CHRROM, SST_MANF_ID ), "Unable to set mem_type and part");
|
||||||
|
-- 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");
|
||||||
|
--
|
||||||
|
-- debug("\n\nsetting operation STARTFLASH");
|
||||||
|
-- //inform buffer manager to start dumping operation now that buffers are initialized
|
||||||
|
-- check(! set_operation( transfer, STARTFLASH ), "Unable to set buffer operation");
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- tstart = clock();
|
||||||
|
--
|
||||||
|
-- //now just need to call series of payload IN transfers to retrieve data
|
||||||
|
--
|
||||||
|
-- for( i=0; i<(8*KByte/buff_size); i++) {
|
||||||
|
--
|
||||||
|
-- //Read next chunk from file
|
||||||
|
-- check(! read_from_file( rom, data, buff_size ), "Error with file read");
|
||||||
|
--
|
||||||
|
-- //ensure cur_buff is EMPTY prior to sending data
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- while (cur_buff_status != EMPTY ) {
|
||||||
|
-- //debug("cur_buff->status: %x ", cur_buff_status);
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- //send data
|
||||||
|
-- check(! payload_out( transfer, data, buff_size ), "Error with payload OUT");
|
||||||
|
-- //if ( i % 256 == 0 ) debug("payload in #%d", i);
|
||||||
|
-- if ( i % 32 == 0 ) debug("payload out #%d", i);
|
||||||
|
-- }
|
||||||
|
-- check(! get_cur_buff_status( transfer, &cur_buff_status ), "Error retrieving cur_buff->status");
|
||||||
|
-- //debug("\n\n\ncur_buff->status: %x\n", cur_buff_status);
|
||||||
|
--
|
||||||
|
-- //check to ensure both buffers are done and operation is okay before resetting
|
||||||
|
-- //need to get status of buff1 and make sure it's flashed
|
||||||
|
-- while (cur_buff_status != FLASHED ) {
|
||||||
|
-- check(! get_buff_element_value( transfer, buff1, GET_PRI_ELEMENTS, BUFF_STATUS, &cur_buff_status ),
|
||||||
|
-- "Error retrieving buffer status post flashing");
|
||||||
|
-- // debug("\n\n\ncur_buff->status: %x\n", cur_buff_status);
|
||||||
|
-- }
|
||||||
|
--
|
||||||
|
-- debug("payload done");
|
||||||
|
-- //close file in main
|
||||||
|
--
|
||||||
|
-- //end operation at reset
|
||||||
|
-- check(! set_operation( transfer, RESET ), "Unable to set buffer operation");
|
||||||
|
--
|
||||||
|
-- //reset io at end
|
||||||
|
-- io_reset( transfer );
|
||||||
|
--
|
||||||
|
-- return SUCCESS;
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- global variables so other modules can use them
|
||||||
|
|
||||||
|
|
||||||
|
-- call functions desired to run when script is called/imported
|
||||||
|
|
||||||
|
|
||||||
|
-- functions other modules are able to call
|
||||||
|
flash.flash_nes = flash_nes
|
||||||
|
|
||||||
|
-- return the module's table
|
||||||
|
return flash
|
||||||
|
|
@ -9,6 +9,8 @@ function main ()
|
||||||
local cart = require "scripts.app.cart"
|
local cart = require "scripts.app.cart"
|
||||||
local nes = require "scripts.app.nes"
|
local nes = require "scripts.app.nes"
|
||||||
local dump = require "scripts.app.dump"
|
local dump = require "scripts.app.dump"
|
||||||
|
local erase = require "scripts.app.erase"
|
||||||
|
local flash = require "scripts.app.flash"
|
||||||
|
|
||||||
local rv
|
local rv
|
||||||
-- rv = dict.pinport( "CTL_ENABLE" )
|
-- rv = dict.pinport( "CTL_ENABLE" )
|
||||||
|
|
@ -61,6 +63,20 @@ function main ()
|
||||||
--set rom types and sizes
|
--set rom types and sizes
|
||||||
--perform desired operation
|
--perform desired operation
|
||||||
|
|
||||||
|
|
||||||
|
--FLASHING:
|
||||||
|
--erase cart
|
||||||
|
erase.erase_nes( true )
|
||||||
|
--open file
|
||||||
|
local file
|
||||||
|
file = assert(io.open("flash.bin", "rb"))
|
||||||
|
--determine if auto-doubling, deinterleaving, etc,
|
||||||
|
--needs done to make board compatible with rom
|
||||||
|
--flash cart
|
||||||
|
flash.flash_nes( file, true )
|
||||||
|
--close file
|
||||||
|
assert(file:close())
|
||||||
|
|
||||||
--DUMPING:
|
--DUMPING:
|
||||||
--create new file
|
--create new file
|
||||||
local file
|
local file
|
||||||
|
|
@ -71,15 +87,6 @@ function main ()
|
||||||
--close file
|
--close file
|
||||||
assert(file:close())
|
assert(file:close())
|
||||||
|
|
||||||
--FLASHING:
|
|
||||||
--open file
|
|
||||||
--erase cart
|
|
||||||
--determine if auto-doubling, deinterleaving, etc,
|
|
||||||
--needs done to make board compatible with rom
|
|
||||||
--flash cart
|
|
||||||
--close file
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dict.io("IO_RESET")
|
dict.io("IO_RESET")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue