Merge branch 'master' of ssh://shion.micecat.ath.cx/~ikari/public_html/git/sd2snes
This commit is contained in:
71
src/crc16.c
71
src/crc16.c
@@ -2,20 +2,59 @@
|
||||
* \file stdout
|
||||
* Functions and types for CRC checks.
|
||||
*
|
||||
* Generated on Tue Jun 30 23:02:59 2009,
|
||||
* Generated on Tue Sep 15 09:32:35 2009,
|
||||
* by pycrc v0.7.1, http://www.tty1.net/pycrc/
|
||||
* using the configuration:
|
||||
* Width = 16
|
||||
* Poly = 0x8005
|
||||
* XorIn = 0x0000
|
||||
* XorIn = 0xffff
|
||||
* ReflectIn = True
|
||||
* XorOut = 0x0000
|
||||
* XorOut = 0xffff
|
||||
* ReflectOut = True
|
||||
* Algorithm = bit-by-bit-fast
|
||||
* Algorithm = table-driven
|
||||
* Direct = True
|
||||
*****************************************************************************/
|
||||
#include <stdint.h>
|
||||
#include "crc16.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Static table used for the table_driven implementation.
|
||||
*****************************************************************************/
|
||||
static const crc_t crc_table[256] = {
|
||||
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
|
||||
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
|
||||
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
|
||||
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
|
||||
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
|
||||
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
|
||||
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
|
||||
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
|
||||
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
||||
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
|
||||
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
|
||||
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
|
||||
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
|
||||
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
|
||||
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
|
||||
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
|
||||
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
|
||||
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
||||
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
|
||||
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
|
||||
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
|
||||
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
|
||||
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
|
||||
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
|
||||
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
|
||||
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
|
||||
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
||||
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
|
||||
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
|
||||
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
|
||||
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
|
||||
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the crc value with new data.
|
||||
*
|
||||
@@ -26,26 +65,14 @@
|
||||
*****************************************************************************/
|
||||
crc_t crc16_update(crc_t crc, const unsigned char *data, size_t data_len)
|
||||
{
|
||||
unsigned int i;
|
||||
uint8_t bit;
|
||||
unsigned char c;
|
||||
unsigned int tbl_idx;
|
||||
|
||||
while (data_len--) {
|
||||
c = *data++;
|
||||
for (i = 0x01; i & 0xff; i <<= 1) {
|
||||
bit = (crc & 0x8000 ? 1 : 0);
|
||||
if (c & i) {
|
||||
bit ^= 1;
|
||||
}
|
||||
crc <<= 1;
|
||||
if (bit) {
|
||||
crc ^= 0x8005;
|
||||
}
|
||||
}
|
||||
crc &= 0xffff;
|
||||
tbl_idx = (crc ^ *data) & 0xff;
|
||||
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
||||
|
||||
data++;
|
||||
}
|
||||
return crc & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
26
src/main.c
26
src/main.c
@@ -129,17 +129,9 @@ int main(void) {
|
||||
clock_prescale_set(CLOCK_PRESCALE);
|
||||
#endif
|
||||
|
||||
/* BUSY_LED_SETDDR();
|
||||
DIRTY_LED_SETDDR();
|
||||
AUX_LED_SETDDR();
|
||||
|
||||
AUX_LED_OFF();
|
||||
set_busy_led(1);
|
||||
set_dirty_led(0);
|
||||
*/
|
||||
snes_reset(1);
|
||||
uart_init();
|
||||
sei();
|
||||
// sei(); // interrupts are bad for now, resets the poor AVR when inserting SD card
|
||||
_delay_ms(100);
|
||||
disk_init();
|
||||
snes_init();
|
||||
@@ -151,19 +143,14 @@ int main(void) {
|
||||
|
||||
FATFS fatfs;
|
||||
f_mount(0,&fatfs);
|
||||
set_busy_led(0);
|
||||
set_busy_led(1);
|
||||
uart_putc('W');
|
||||
fpga_init();
|
||||
fpga_pgm("/sd2snes/main.bit");
|
||||
fpga_spi_init();
|
||||
uart_putc('!');
|
||||
_delay_ms(100);
|
||||
//set_avr_bank(0);
|
||||
set_avr_ena(0);
|
||||
// set_avr_read(1);
|
||||
// set_avr_write(1);
|
||||
// AVR_ADDR_RESET();
|
||||
// set_avr_addr_en(0);
|
||||
snes_reset(1);
|
||||
|
||||
uart_putc('(');
|
||||
@@ -184,7 +171,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
|
||||
/* HERE BE LIONS */
|
||||
/* HERE BE LIONS */
|
||||
while(1) {
|
||||
SPI_SS_HIGH();
|
||||
FPGA_SS_LOW();
|
||||
@@ -197,8 +184,13 @@ while(1) {
|
||||
spiTransferByte(0x81); // read w/ increment... hopefully
|
||||
spiTransferByte(0x00); // 1 dummy read
|
||||
uart_putcrlf();
|
||||
for(uint8_t cnt=0; cnt<16; cnt++) {
|
||||
uint8_t buff[21];
|
||||
for(uint8_t cnt=0; cnt<21; cnt++) {
|
||||
uint8_t data=spiTransferByte(0x00);
|
||||
buff[cnt]=data;
|
||||
}
|
||||
for(uint8_t cnt=0; cnt<21; cnt++) {
|
||||
uint8_t data = buff[cnt];
|
||||
_delay_ms(2);
|
||||
if(data>=0x20 && data <= 0x7a) {
|
||||
uart_putc(data);
|
||||
|
||||
15
src/memory.c
15
src/memory.c
@@ -46,9 +46,8 @@ void sram_writeblock(void* buf, uint32_t addr, uint16_t size) {
|
||||
}
|
||||
|
||||
uint32_t load_rom(char* filename) {
|
||||
// TODO Mapper, Mirroring, Bankselect
|
||||
snes_romprops_t romprops;
|
||||
// set_avr_bank(0);
|
||||
set_avr_bank(0);
|
||||
UINT bytes_read;
|
||||
DWORD filesize;
|
||||
UINT count=0;
|
||||
@@ -163,12 +162,12 @@ void save_sram(char* filename, uint32_t sram_size, uint32_t base_addr) {
|
||||
}
|
||||
|
||||
|
||||
uint32_t calc_sram_crc(uint32_t size) {
|
||||
uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size) {
|
||||
uint8_t data;
|
||||
uint32_t count;
|
||||
uint16_t crc;
|
||||
crc=0;
|
||||
set_avr_bank(3);
|
||||
set_avr_addr(base_addr);
|
||||
SPI_SS_HIGH();
|
||||
FPGA_SS_HIGH();
|
||||
FPGA_SS_LOW();
|
||||
@@ -176,16 +175,8 @@ uint32_t calc_sram_crc(uint32_t size) {
|
||||
spiTransferByte(0x00);
|
||||
for(count=0; count<size; count++) {
|
||||
data = spiTransferByte(0);
|
||||
/* uart_putc(hex[(data>>4)]);
|
||||
uart_putc(hex[data&0xf]);
|
||||
uart_putc(' ');
|
||||
_delay_ms(2);*/
|
||||
crc += crc16_update(crc, &data, 1);
|
||||
}
|
||||
FPGA_SS_HIGH();
|
||||
/* uart_putc(hex[(crc>>28)&0xf]);
|
||||
uart_putc(hex[(crc>>24)&0xf]);
|
||||
uart_putc(hex[(crc>>20)&0xf]);
|
||||
uart_putc(hex[(crc>>16)&0xf]); */
|
||||
return crc;
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
uint32_t load_rom(char* filename);
|
||||
uint32_t load_sram(char* filename);
|
||||
void save_sram(char* filename, uint32_t sram_size, uint32_t base_addr);
|
||||
uint32_t calc_sram_crc(uint32_t size);
|
||||
uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size);
|
||||
#endif
|
||||
|
||||
20
src/snes.c
20
src/snes.c
@@ -14,9 +14,9 @@
|
||||
|
||||
|
||||
uint8_t initloop=1;
|
||||
uint32_t sram_crc, sram_crc_old;
|
||||
uint32_t sram_size = 8192; // sane default
|
||||
uint32_t sram_base_addr = 0x600000; // chip 3
|
||||
uint32_t saveram_crc, saveram_crc_old;
|
||||
uint32_t saveram_size = 8192; // sane default
|
||||
uint32_t saveram_base_addr = 0x600000; // chip 3
|
||||
void snes_init() {
|
||||
DDRD |= _BV(PD5); // PD5 = RESET_DIR
|
||||
DDRD |= _BV(PD6); // PD6 = RESET
|
||||
@@ -46,18 +46,18 @@ void snes_reset(int state) {
|
||||
*/
|
||||
void snes_main_loop() {
|
||||
if(initloop) {
|
||||
sram_crc_old = calc_sram_crc(sram_size);
|
||||
save_sram("/test.srm", sram_size, sram_base_addr);
|
||||
saveram_crc_old = calc_sram_crc(saveram_base_addr, saveram_size);
|
||||
save_sram("/test.srm", saveram_size, saveram_base_addr);
|
||||
initloop=0;
|
||||
}
|
||||
sram_crc = calc_sram_crc(sram_size);
|
||||
if(sram_crc != sram_crc_old) {
|
||||
saveram_crc = calc_sram_crc(saveram_base_addr, saveram_size);
|
||||
if(saveram_crc != saveram_crc_old) {
|
||||
uart_putc('U');
|
||||
uart_puthexlong(sram_crc);
|
||||
uart_puthexshort(saveram_crc);
|
||||
uart_putcrlf();
|
||||
set_busy_led(1);
|
||||
save_sram("/test.srm", sram_size, sram_base_addr);
|
||||
save_sram("/test.srm", saveram_size, saveram_base_addr);
|
||||
set_busy_led(0);
|
||||
}
|
||||
sram_crc_old = sram_crc;
|
||||
saveram_crc_old = saveram_crc;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,12 @@ void uart_puthexlong(uint32_t num) {
|
||||
uart_puthex(num&0xff);
|
||||
}
|
||||
|
||||
void uart_puthexshort(uint16_t num) {
|
||||
uart_puthex((num>>8)&0xff);
|
||||
uart_puthex(num&0xff);
|
||||
}
|
||||
|
||||
|
||||
void uart_trace(void *ptr, uint16_t start, uint16_t len) {
|
||||
uint16_t i;
|
||||
uint8_t j;
|
||||
|
||||
@@ -36,6 +36,7 @@ unsigned char uart_getc(void);
|
||||
void uart_putc(char c);
|
||||
void uart_puthex(uint8_t num);
|
||||
void uart_puthexlong(uint32_t num);
|
||||
void uart_puthexshort(uint16_t num);
|
||||
void uart_trace(void *ptr, uint16_t start, uint16_t len);
|
||||
void uart_flush(void);
|
||||
void uart_puts_P(prog_char *text);
|
||||
|
||||
Reference in New Issue
Block a user