A0-A14|-<vaild address>-
D0-D7 |----<iii>---
*/
-void cpu_write_flash(uint16_t address, uint16_t length, const uint8_t *data)
+static inline void cpu_write_flash_waveform(uint16_t address, uint8_t data)
{
- direction_write();
- while(length != 0){
- uint8_t control = bit_get_negative(CPU_PHI2);
- address_set(address);
- if(0){ //R/W = /WE controlled write operation
- if((address & 0x8000) != 0){
- control &= bit_get_negative(CPU_ROMCS);
- BUS_CONTROL_OUT = control;
- }
- control &= bit_get_negative(CPU_RW);
- BUS_CONTROL_OUT = control;
- DATABUS_OUT = *data;
- data++;
- control |= 1 << CPU_RW; //R/W close
- BUS_CONTROL_OUT = control;
- }else{ ///ROMCS = /CS controlled write operation
- control &= bit_get_negative(CPU_RW);
+ uint8_t control = bit_get_negative(CPU_PHI2);
+ address_set(address);
+ if(0){ //R/W = /WE controlled write operation
+ if((address & 0x8000) != 0){
+ control &= bit_get_negative(CPU_ROMCS);
BUS_CONTROL_OUT = control;
- if((address & 0x8000) != 0){
- control &= bit_get_negative(CPU_ROMCS);
- BUS_CONTROL_OUT = control;
- }
- DATABUS_OUT = *data;
- data++;
- control |= 1 << CPU_ROMCS;
+ }
+ control &= bit_get_negative(CPU_RW);
+ BUS_CONTROL_OUT = control;
+ DATABUS_OUT = data;
+ control |= 1 << CPU_RW; //R/W close
+ BUS_CONTROL_OUT = control;
+ }else{ ///ROMCS = /CS controlled write operation
+ control &= bit_get_negative(CPU_RW);
+ BUS_CONTROL_OUT = control;
+ if((address & 0x8000) != 0){
+ control &= bit_get_negative(CPU_ROMCS);
BUS_CONTROL_OUT = control;
}
- BUS_CONTROL_OUT = BUS_CLOSE;
+ DATABUS_OUT = data;
+ control |= 1 << CPU_ROMCS;
+ BUS_CONTROL_OUT = control;
+ }
+ BUS_CONTROL_OUT = BUS_CLOSE;
+}
+void cpu_write_flash(uint16_t address, uint16_t length, const uint8_t *data)
+{
+ direction_write();
+ while(length != 0){
+ cpu_write_flash_waveform(address, *data);
+ data++;
address += 1;
length--;
}
}
+void cpu_write_flash_order(const struct flash_order *t)
+{
+ int length = FLASH_PROGRAM_ORDER;
+ direction_write();
+ while(length != 0){
+ cpu_write_flash_waveform(t->address, t->data);
+ t++;
+ length--;
+ }
+}
/*
NTSC hardware timing
Master clock fsc: 21.4772272 MHz
}
}
+static inline void ppu_write_waveform(uint16_t address, uint8_t data)
+{
+ address_set(address);//PPU memory /CS open
+ BUS_CONTROL_OUT = bit_get_negative(PPU_WR);
+ DATABUS_OUT = data;
+ BUS_CONTROL_OUT = BUS_CLOSE;
+ address_set(1 << 13); //PPU memory /CS close
+}
void ppu_write(uint16_t address, uint16_t length, const uint8_t *data)
{
while(length != 0){
- address_set(address);//PPU memory /CS open
- BUS_CONTROL_OUT = bit_get_negative(PPU_WR);
- DATABUS_OUT = *data;
+ ppu_write_waveform(address, *data);
data++;
- BUS_CONTROL_OUT = BUS_CLOSE;
- address_set(1 << 13); //PPU memory /CS close
address += 1;
length--;
}
}
+
+void ppu_write_order(const struct flash_order *t)
+{
+ int length = FLASH_PROGRAM_ORDER;
+ while(length != 0){
+ ppu_write_waveform(t->address, t->data);
+ t++;
+ length--;
+ }
+}
//---- global variable ----
struct flash_seqence{
void (*const writer)(uint16_t address, uint16_t length, const uint8_t *data);
+ void (*const programmer)(const struct flash_order *t);
void (*const reader)(uint16_t address, uint16_t length, uint8_t *data);
enum compare_status (*const compare)(uint16_t address, uint16_t length, const uint8_t *data);
- enum{
+ enum status{
IDLE = 0,
ERASE, ERASE_WAIT,
PROGRAM, TOGGLE_FIRST, TOGGLE_CHECK
uint16_t address, length, program_unit;
const uint8_t *data;
uint8_t toggle, retry_count;
+ struct flash_order program_command[FLASH_PROGRAM_ORDER];
};
static struct flash_seqence seqence_cpu = {
- .status = IDLE, .reader = cpu_read, .writer = cpu_write_flash,
+ .status = IDLE, .reader = cpu_read,
+ .writer = cpu_write_flash, .programmer = cpu_write_flash_order,
.compare = cpu_compare
};
static struct flash_seqence seqence_ppu = {
- .status = IDLE, .reader = ppu_read, .writer = ppu_write,
+ .status = IDLE, .reader = ppu_read,
+ .writer = ppu_write, .programmer = ppu_write_order,
.compare = ppu_compare
};
t->command_2aaa = c2aaa;
t->command_5555 = c5555;
t->program_unit = unit;
+ t->program_command[0].address = c5555;
+ t->program_command[0].data = 0xaa;
+ t->program_command[1].address = c2aaa;
+ t->program_command[1].data = 0x55;
+ t->program_command[2].address = c5555;
+ t->program_command[2].data = 0xa0;
};
void flash_cpu_config(uint16_t c000x, uint16_t c2aaa, uint16_t c5555, uint16_t unit)
{
config_set(c000x, c2aaa, c5555, unit, &seqence_ppu);
}
-static void program_assign(uint16_t address, uint16_t length, const uint8_t *data, struct flash_seqence *t)
+static void program_assign(enum status status, uint16_t address, uint16_t length, const uint8_t *data, struct flash_seqence *t)
{
+ t->status = status;
+ t->request = status;
t->address = address;
t->length = length;
t->data = data;
}
void flash_cpu_program(uint16_t address, uint16_t length, const uint8_t *data)
{
- seqence_cpu.status = PROGRAM;
- seqence_cpu.request = PROGRAM;
- program_assign(address, length, data, &seqence_cpu);
+ program_assign(PROGRAM, address, length, data, &seqence_cpu);
}
void flash_ppu_program(uint16_t address, uint16_t length, const uint8_t *data)
{
- seqence_ppu.status = PROGRAM;
- seqence_ppu.request = PROGRAM;
- program_assign(address, length, data, &seqence_ppu);
+ program_assign(PROGRAM, address, length, data, &seqence_ppu);
}
#define NULL (0)
void flash_cpu_erase(uint16_t address)
{
- seqence_cpu.status = ERASE;
- seqence_cpu.request = ERASE;
//length ¤Ë unit ¤òÅϤ·¤Æ toggle check ¸å IDLE ¤Ë¤Ê¤ë¤è¤¦¤Ë¤¹¤ë
- program_assign(address, seqence_cpu.program_unit, NULL, &seqence_cpu);
+ program_assign(ERASE, address, seqence_cpu.program_unit, NULL, &seqence_cpu);
}
void flash_ppu_erase(uint16_t address)
{
- seqence_ppu.status = ERASE;
- seqence_ppu.request = ERASE;
- program_assign(address, seqence_ppu.program_unit, NULL, &seqence_ppu);
+ program_assign(ERASE, address, seqence_ppu.program_unit, NULL, &seqence_ppu);
}
//---- command write ----
}
static void program(const struct flash_seqence *t)
{
- static const struct flash_command c[] = {
+/* static const struct flash_command c[] = {
{C5555, 0xaa}, {C2AAA, 0x55}, {C5555, 0xa0}, {END, 0}
};
- command_execute(c, t);
+ command_execute(c, t);*/
+ t->programmer(t->program_command);
t->writer(t->address, t->program_unit, t->data);
}