mk2 fw wip (cleanup indent+comment)
This commit is contained in:
parent
db45a5afaf
commit
f063cb31f9
@ -55,7 +55,7 @@ TARGET = $(OBJDIR)/sd2snes
|
|||||||
|
|
||||||
|
|
||||||
# List C source files here. (C dependencies are automatically generated.)
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c crc16.c filetypes.c faulthandler.c sort.c
|
SRC = main.c ff.c ccsbcs.c clock.c uart.c power.c led.c timer.c printf.c sdcard.c spi.c fileops.c rtc.c fpga.c fpga_spi.c snes.c smc.c memory.c filetypes.c faulthandler.c sort.c
|
||||||
|
|
||||||
|
|
||||||
# List Assembler source files here.
|
# List Assembler source files here.
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
|
CONFIG_VERSION=0.0.1
|
||||||
CONFIG_MCU_FOSC=12000000
|
CONFIG_MCU_FOSC=12000000
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#ifndef _CONFIG_H
|
#ifndef _CONFIG_H
|
||||||
#define _CONFIG_H
|
#define _CONFIG_H
|
||||||
|
|
||||||
|
#define VER "0.0.1"
|
||||||
#define IN_AHBRAM __attribute__ ((section(".ahbram")))
|
#define IN_AHBRAM __attribute__ ((section(".ahbram")))
|
||||||
|
|
||||||
#define SDCARD_DETECT (1)
|
#define SDCARD_DETECT (1)
|
||||||
@ -28,7 +29,7 @@
|
|||||||
|
|
||||||
#define SNES_RESET_REG LPC_GPIO1
|
#define SNES_RESET_REG LPC_GPIO1
|
||||||
#define SNES_RESET_BIT 29
|
#define SNES_RESET_BIT 29
|
||||||
// Rev.B: 26
|
/* XXX Rev.B: 26 */
|
||||||
|
|
||||||
#define QSORT_MAXELEM 1024
|
#define QSORT_MAXELEM 1024
|
||||||
|
|
||||||
|
|||||||
70
src/crc16.c
70
src/crc16.c
@ -2,20 +2,59 @@
|
|||||||
* \file stdout
|
* \file stdout
|
||||||
* Functions and types for CRC checks.
|
* 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/
|
* by pycrc v0.7.1, http://www.tty1.net/pycrc/
|
||||||
* using the configuration:
|
* using the configuration:
|
||||||
* Width = 16
|
* Width = 16
|
||||||
* Poly = 0x8005
|
* Poly = 0x8005
|
||||||
* XorIn = 0x0000
|
* XorIn = 0xffff
|
||||||
* ReflectIn = True
|
* ReflectIn = True
|
||||||
* XorOut = 0x0000
|
* XorOut = 0xffff
|
||||||
* ReflectOut = True
|
* ReflectOut = True
|
||||||
* Algorithm = bit-by-bit-fast
|
* Algorithm = table-driven
|
||||||
* Direct = True
|
* Direct = True
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include <stdint.h>
|
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
||||||
#include "crc16.h"
|
#include "crc16.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.
|
* Update the crc value with new data.
|
||||||
*
|
*
|
||||||
@ -26,26 +65,13 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
crc_t crc16_update(crc_t crc, const unsigned char *data, size_t data_len)
|
crc_t crc16_update(crc_t crc, const unsigned char *data, size_t data_len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int tbl_idx;
|
||||||
uint8_t bit;
|
|
||||||
unsigned char c;
|
|
||||||
|
|
||||||
while (data_len--) {
|
while (data_len--) {
|
||||||
c = *data++;
|
tbl_idx = (crc ^ *data) & 0xff;
|
||||||
for (i = 0x01; i & 0xff; i <<= 1) {
|
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
||||||
bit = (crc & 0x8000 ? 1 : 0);
|
data++;
|
||||||
if (c & i) {
|
|
||||||
bit ^= 1;
|
|
||||||
}
|
|
||||||
crc <<= 1;
|
|
||||||
if (bit) {
|
|
||||||
crc ^= 0x8005;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
crc &= 0xffff;
|
|
||||||
}
|
}
|
||||||
return crc & 0xffff;
|
return crc & 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
src/ff.c
21
src/ff.c
@ -1639,6 +1639,8 @@ void get_fileinfo ( /* No return code */
|
|||||||
fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */
|
fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */
|
||||||
fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */
|
fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */
|
||||||
fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */
|
fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */
|
||||||
|
fno->clust = ((DWORD)LD_WORD(dir+DIR_FstClusHI) << 16)
|
||||||
|
| LD_WORD(dir+DIR_FstClusLO);
|
||||||
}
|
}
|
||||||
*p = 0; /* Terminate SFN str by a \0 */
|
*p = 0; /* Terminate SFN str by a \0 */
|
||||||
|
|
||||||
@ -2821,6 +2823,25 @@ FRESULT f_stat (
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FRESULT l_openfilebycluster (
|
||||||
|
FATFS *fs, /* Pointer to file system object */
|
||||||
|
FIL *fp, /* Pointer to the blank file object */
|
||||||
|
const TCHAR *path,
|
||||||
|
DWORD clust, /* Cluster number to be opened */
|
||||||
|
DWORD fsize /* File size to be assumed */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
chk_mounted(&path, &fs, 0);
|
||||||
|
fp->flag = FA_READ;
|
||||||
|
fp->org_clust = clust;
|
||||||
|
fp->fsize = fsize;
|
||||||
|
fp->fptr = 0;
|
||||||
|
fp->dsect = 0;
|
||||||
|
fp->fs = fs;
|
||||||
|
|
||||||
|
return FR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if !_FS_READONLY
|
#if !_FS_READONLY
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|||||||
5
src/ff.h
5
src/ff.h
@ -358,6 +358,7 @@ typedef struct {
|
|||||||
WORD ftime; /* Last modified time */
|
WORD ftime; /* Last modified time */
|
||||||
BYTE fattrib; /* Attribute */
|
BYTE fattrib; /* Attribute */
|
||||||
TCHAR fname[13]; /* Short file name (8.3 format) */
|
TCHAR fname[13]; /* Short file name (8.3 format) */
|
||||||
|
DWORD clust; /* start cluster */
|
||||||
#if _USE_LFN
|
#if _USE_LFN
|
||||||
TCHAR* lfname; /* Pointer to the LFN buffer */
|
TCHAR* lfname; /* Pointer to the LFN buffer */
|
||||||
UINT lfsize; /* Size of LFN buffer in TCHAR */
|
UINT lfsize; /* Size of LFN buffer in TCHAR */
|
||||||
@ -395,6 +396,10 @@ typedef enum {
|
|||||||
/*--------------------------------------------------------------*/
|
/*--------------------------------------------------------------*/
|
||||||
/* FatFs module application interface */
|
/* FatFs module application interface */
|
||||||
|
|
||||||
|
/* Low Level functions */
|
||||||
|
FRESULT l_openfilebycluster(FATFS *fs, FIL *fp, const TCHAR *path, DWORD clust, DWORD fsize); /* Open a file by its start cluster using supplied file size */
|
||||||
|
|
||||||
|
/* application level functions */
|
||||||
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
|
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
|
||||||
FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
|
FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
|
||||||
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
|
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
|
||||||
|
|||||||
@ -29,7 +29,8 @@
|
|||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
|
|
||||||
/*WCHAR ff_convert(WCHAR w, UINT dir) {
|
/*
|
||||||
|
WCHAR ff_convert(WCHAR w, UINT dir) {
|
||||||
return w;
|
return w;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@ -37,9 +38,9 @@ void file_init() {
|
|||||||
file_res=f_mount(0, &fatfs);
|
file_res=f_mount(0, &fatfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void file_open_by_filinfo(FILINFO* fno) {
|
void file_open_by_filinfo(FILINFO* fno) {
|
||||||
file_res = l_openfilebycluster(&fatfs, &file_handle, (UCHAR*)"", fno->clust, fno->fsize);
|
file_res = l_openfilebycluster(&fatfs, &file_handle, (TCHAR*)"", fno->clust, fno->fsize);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
void file_open(uint8_t* filename, BYTE flags) {
|
void file_open(uint8_t* filename, BYTE flags) {
|
||||||
file_res = f_open(&file_handle, (TCHAR*)filename, flags);
|
file_res = f_open(&file_handle, (TCHAR*)filename, flags);
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "smc.h"
|
#include "smc.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
#include "crc16.h"
|
#include "crc.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "sort.h"
|
#include "sort.h"
|
||||||
@ -89,25 +89,22 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
for(pass = 0; pass < 2; pass++) {
|
for(pass = 0; pass < 2; pass++) {
|
||||||
if(pass) {
|
if(pass) {
|
||||||
dirsize = 4*(numentries);
|
dirsize = 4*(numentries);
|
||||||
// dir_tgt_next = dir_tgt + dirsize + 4; // number of entries + end marker
|
|
||||||
next_subdir_tgt += dirsize + 4;
|
next_subdir_tgt += dirsize + 4;
|
||||||
if(parent_tgt) next_subdir_tgt += 4;
|
if(parent_tgt) next_subdir_tgt += 4;
|
||||||
if(next_subdir_tgt > dir_end) {
|
if(next_subdir_tgt > dir_end) {
|
||||||
dir_end = next_subdir_tgt;
|
dir_end = next_subdir_tgt;
|
||||||
}
|
}
|
||||||
printf("path=%s depth=%d ptr=%lx entries=%d parent=%lx next subdir @%lx\n", path, depth, db_tgt, numentries, parent_tgt, next_subdir_tgt /*dir_tgt_next*/);
|
printf("path=%s depth=%d ptr=%lx entries=%d parent=%lx next subdir @%lx\n", path, depth, db_tgt, numentries, parent_tgt, next_subdir_tgt);
|
||||||
// _delay_ms(50);
|
|
||||||
if(mkdb) {
|
if(mkdb) {
|
||||||
printf("d=%d Saving %lx to Address %lx [end]\n", depth, 0L, next_subdir_tgt - 4);
|
printf("d=%d Saving %lx to Address %lx [end]\n", depth, 0L, next_subdir_tgt - 4);
|
||||||
// _delay_ms(50);
|
|
||||||
sram_writelong(0L, next_subdir_tgt - 4);
|
sram_writelong(0L, next_subdir_tgt - 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = f_opendir(&dir, (TCHAR*)path);
|
res = f_opendir(&dir, (TCHAR*)path);
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
if(pass && parent_tgt && mkdb) {
|
if(pass && parent_tgt && mkdb) {
|
||||||
// write backlink to parent dir
|
/* write backlink to parent dir
|
||||||
// switch to next bank if record does not fit in current bank
|
switch to next bank if record does not fit in current bank */
|
||||||
if((db_tgt&0xffff) > ((0x10000-(sizeof(next_subdir_tgt)+sizeof(len)+4))&0xffff)) {
|
if((db_tgt&0xffff) > ((0x10000-(sizeof(next_subdir_tgt)+sizeof(len)+4))&0xffff)) {
|
||||||
printf("switch! old=%lx ", db_tgt);
|
printf("switch! old=%lx ", db_tgt);
|
||||||
db_tgt &= 0xffff0000;
|
db_tgt &= 0xffff0000;
|
||||||
@ -132,8 +129,6 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fn = *fno.lfname ? fno.lfname : fno.fname;
|
fn = *fno.lfname ? fno.lfname : fno.fname;
|
||||||
// printf("%s\n", fn);
|
|
||||||
// _delay_ms(100);
|
|
||||||
if (*fn == '.') continue;
|
if (*fn == '.') continue;
|
||||||
if (fno.fattrib & AM_DIR) {
|
if (fno.fattrib & AM_DIR) {
|
||||||
numentries++;
|
numentries++;
|
||||||
@ -143,15 +138,12 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
depth++;
|
depth++;
|
||||||
if(mkdb) {
|
if(mkdb) {
|
||||||
uint16_t pathlen = strlen(path);
|
uint16_t pathlen = strlen(path);
|
||||||
// write element pointer to current dir structure
|
/* write element pointer to current dir structure */
|
||||||
printf("d=%d Saving %lx to Address %lx [dir]\n", depth, db_tgt, dir_tgt);
|
printf("d=%d Saving %lx to Address %lx [dir]\n", depth, db_tgt, dir_tgt);
|
||||||
// _delay_ms(50);
|
|
||||||
sram_writelong((db_tgt-SRAM_MENU_ADDR)|((uint32_t)0x80<<24), dir_tgt);
|
sram_writelong((db_tgt-SRAM_MENU_ADDR)|((uint32_t)0x80<<24), dir_tgt);
|
||||||
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
|
/* save element:
|
||||||
|
- path name
|
||||||
// save element:
|
- pointer to sub dir structure */
|
||||||
// - path name
|
|
||||||
// - pointer to sub dir structure
|
|
||||||
if((db_tgt&0xffff) > ((0x10000-(sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2))&0xffff)) {
|
if((db_tgt&0xffff) > ((0x10000-(sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2))&0xffff)) {
|
||||||
printf("switch! old=%lx ", db_tgt);
|
printf("switch! old=%lx ", db_tgt);
|
||||||
db_tgt &= 0xffff0000;
|
db_tgt &= 0xffff0000;
|
||||||
@ -159,18 +151,15 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
printf("new=%lx\n", db_tgt);
|
printf("new=%lx\n", db_tgt);
|
||||||
}
|
}
|
||||||
printf(" Saving dir descriptor to %lx tgt=%lx, path=%s\n", db_tgt, next_subdir_tgt, path);
|
printf(" Saving dir descriptor to %lx tgt=%lx, path=%s\n", db_tgt, next_subdir_tgt, path);
|
||||||
// _delay_ms(100);
|
|
||||||
sram_writelong((next_subdir_tgt-SRAM_MENU_ADDR), db_tgt);
|
sram_writelong((next_subdir_tgt-SRAM_MENU_ADDR), db_tgt);
|
||||||
sram_writebyte(len+1, db_tgt+sizeof(next_subdir_tgt));
|
sram_writebyte(len+1, db_tgt+sizeof(next_subdir_tgt));
|
||||||
sram_writeblock(path, db_tgt+sizeof(next_subdir_tgt)+sizeof(len), pathlen);
|
sram_writeblock(path, db_tgt+sizeof(next_subdir_tgt)+sizeof(len), pathlen);
|
||||||
sram_writeblock("/\0", db_tgt + sizeof(next_subdir_tgt) + sizeof(len) + pathlen, 2);
|
sram_writeblock("/\0", db_tgt + sizeof(next_subdir_tgt) + sizeof(len) + pathlen, 2);
|
||||||
// sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
|
|
||||||
db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2;
|
db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2;
|
||||||
}
|
}
|
||||||
parent_tgt = this_dir_tgt;
|
parent_tgt = this_dir_tgt;
|
||||||
scan_dir(path, mkdb, next_subdir_tgt);
|
scan_dir(path, mkdb, next_subdir_tgt);
|
||||||
dir_tgt += 4;
|
dir_tgt += 4;
|
||||||
// if(was_empty)dir_tgt_next += 4;
|
|
||||||
was_empty = 0;
|
was_empty = 0;
|
||||||
depth--;
|
depth--;
|
||||||
path[len]=0;
|
path[len]=0;
|
||||||
@ -187,17 +176,15 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
uint16_t pathlen = strlen(path);
|
uint16_t pathlen = strlen(path);
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case TYPE_SMC:
|
case TYPE_SMC:
|
||||||
// XXX file_open_by_filinfo(&fno);
|
/* file_open_by_filinfo(&fno);
|
||||||
// XXX if(file_res){
|
if(file_res){
|
||||||
// XXX printf("ZOMG NOOOO %d\n", file_res);
|
printf("ZOMG NOOOO %d\n", file_res);
|
||||||
// XXX _delay_ms(30);
|
}
|
||||||
// XXX }
|
smc_id(&romprops);
|
||||||
// XXX smc_id(&romprops);
|
file_close();
|
||||||
// XXX file_close();
|
*/
|
||||||
// _delay_ms(30);
|
/* write element pointer to current dir structure */
|
||||||
// write element pointer to current dir structure
|
printf("d=%d Saving %lX to Address %lX [file]\n", depth, db_tgt, dir_tgt);
|
||||||
// printf("d=%d Saving %lX to Address %lX [file]\n", depth, db_tgt, dir_tgt);
|
|
||||||
// _delay_ms(50);
|
|
||||||
if((db_tgt&0xffff) > ((0x10000-(sizeof(romprops) + sizeof(len) + pathlen + 1))&0xffff)) {
|
if((db_tgt&0xffff) > ((0x10000-(sizeof(romprops) + sizeof(len) + pathlen + 1))&0xffff)) {
|
||||||
printf("switch! old=%lx ", db_tgt);
|
printf("switch! old=%lx ", db_tgt);
|
||||||
db_tgt &= 0xffff0000;
|
db_tgt &= 0xffff0000;
|
||||||
@ -205,39 +192,38 @@ uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
|||||||
printf("new=%lx\n", db_tgt);
|
printf("new=%lx\n", db_tgt);
|
||||||
}
|
}
|
||||||
sram_writelong((db_tgt-SRAM_MENU_ADDR), dir_tgt);
|
sram_writelong((db_tgt-SRAM_MENU_ADDR), dir_tgt);
|
||||||
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt, sizeof(db_tgt));
|
|
||||||
dir_tgt += 4;
|
dir_tgt += 4;
|
||||||
// save element:
|
/* save element:
|
||||||
// - SNES header information
|
- index of last slash character
|
||||||
// - file name
|
- file name */
|
||||||
sram_writeblock((uint8_t*)&romprops, db_tgt, sizeof(romprops));
|
/* sram_writeblock((uint8_t*)&romprops, db_tgt, sizeof(romprops)); */
|
||||||
sram_writebyte(len+1, db_tgt + sizeof(romprops));
|
sram_writebyte(len+1, db_tgt);
|
||||||
sram_writeblock(path, db_tgt + sizeof(romprops) + sizeof(len), pathlen + 1);
|
sram_writeblock(path, db_tgt + sizeof(len), pathlen + 1);
|
||||||
db_tgt += sizeof(romprops) + sizeof(len) + pathlen + 1;
|
db_tgt += sizeof(len) + pathlen + 1;
|
||||||
break;
|
break;
|
||||||
case TYPE_UNKNOWN:
|
case TYPE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path[len]=0;
|
path[len]=0;
|
||||||
// printf("%s ", path);
|
/* printf("%s ", path);
|
||||||
// _delay_ms(30);
|
_delay_ms(30); */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TCHAR* sfn = fno.fname;
|
TCHAR* sfn = fno.fname;
|
||||||
while(*sfn != 0) {
|
while(*sfn != 0) {
|
||||||
crc += crc16_update(crc, (unsigned char*)sfn++, 1);
|
crc += crc_xmodem_update(crc, *((unsigned char*)sfn++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("%s/%s\n", path, fn);
|
/* printf("%s/%s\n", path, fn);
|
||||||
// _delay_ms(50);
|
_delay_ms(50); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else uart_putc(0x30+res);
|
} else uart_putc(0x30+res);
|
||||||
}
|
}
|
||||||
// printf("%x\n", crc);
|
/*printf("%x\n", crc);
|
||||||
// _delay_ms(50);
|
_delay_ms(50); */
|
||||||
sram_writelong(db_tgt, SRAM_DB_ADDR+4);
|
sram_writelong(db_tgt, SRAM_DB_ADDR+4);
|
||||||
sram_writelong(dir_end, SRAM_DB_ADDR+8);
|
sram_writelong(dir_end, SRAM_DB_ADDR+8);
|
||||||
return crc;
|
return crc;
|
||||||
|
|||||||
18
src/fpga.c
18
src/fpga.c
@ -52,7 +52,8 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
/*DWORD get_fattime(void) {
|
/*
|
||||||
|
DWORD get_fattime(void) {
|
||||||
return 0L;
|
return 0L;
|
||||||
}*/
|
}*/
|
||||||
void fpga_set_prog_b(uint8_t val) {
|
void fpga_set_prog_b(uint8_t val) {
|
||||||
@ -108,7 +109,7 @@ void fpga_pgm(uint8_t* filename) {
|
|||||||
|
|
||||||
UINT bytes_read;
|
UINT bytes_read;
|
||||||
|
|
||||||
// open configware file
|
/* open configware file */
|
||||||
file_open(filename, FA_READ);
|
file_open(filename, FA_READ);
|
||||||
if(file_res) {
|
if(file_res) {
|
||||||
uart_putc('?');
|
uart_putc('?');
|
||||||
@ -118,7 +119,7 @@ void fpga_pgm(uint8_t* filename) {
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bytes_read = file_read();
|
bytes_read = file_read();
|
||||||
if (file_res || bytes_read == 0) break; // error or eof
|
if (file_res || bytes_read == 0) break; /* error or eof */
|
||||||
for(int i=0; i<bytes_read; i++) {
|
for(int i=0; i<bytes_read; i++) {
|
||||||
FPGA_SEND_BYTE_SERIAL(file_buf[i]);
|
FPGA_SEND_BYTE_SERIAL(file_buf[i]);
|
||||||
}
|
}
|
||||||
@ -127,7 +128,6 @@ void fpga_pgm(uint8_t* filename) {
|
|||||||
} while (!fpga_get_done() && retries--);
|
} while (!fpga_get_done() && retries--);
|
||||||
if(!fpga_get_done()) {
|
if(!fpga_get_done()) {
|
||||||
printf("FPGA failed to configure after %d tries.\n", MAXRETRIES);
|
printf("FPGA failed to configure after %d tries.\n", MAXRETRIES);
|
||||||
delay_ms(50);
|
|
||||||
led_panic();
|
led_panic();
|
||||||
}
|
}
|
||||||
printf("FPGA configured\n");
|
printf("FPGA configured\n");
|
||||||
@ -135,17 +135,15 @@ void fpga_pgm(uint8_t* filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_mcu_ovr(uint8_t val) {
|
void set_mcu_ovr(uint8_t val) {
|
||||||
if(!val) { // shared mode
|
if(!val) {
|
||||||
|
/* shared mode */
|
||||||
FPGA_SPI_SLOW();
|
FPGA_SPI_SLOW();
|
||||||
SET_MCU_OVR();
|
SET_MCU_OVR();
|
||||||
// Disable SPI double speed mode -> clock = f/4
|
|
||||||
// XXX SPSR = 0;
|
|
||||||
printf("SPI slow\n");
|
printf("SPI slow\n");
|
||||||
} else { // mcu only
|
} else {
|
||||||
|
/* mcu exclusive mode */
|
||||||
FPGA_SPI_FAST();
|
FPGA_SPI_FAST();
|
||||||
CLR_MCU_OVR();
|
CLR_MCU_OVR();
|
||||||
// Enable SPI double speed mode -> clock = f/2
|
|
||||||
// XXX SPSR = _BV(SPI2X);
|
|
||||||
printf("SPI fast\n");
|
printf("SPI fast\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,8 +90,8 @@ void set_mapper(uint8_t val) {
|
|||||||
|
|
||||||
uint8_t fpga_test() {
|
uint8_t fpga_test() {
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0xF0); // TEST
|
FPGA_TX_BYTE(0xF0); /* TEST */
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
uint8_t result = FPGA_RX_BYTE();
|
uint8_t result = FPGA_RX_BYTE();
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
83
src/main.c
83
src/main.c
@ -1,6 +1,7 @@
|
|||||||
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "obj/autoconf.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
@ -19,6 +20,8 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "sort.h"
|
#include "sort.h"
|
||||||
|
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
#define EMC0TOGGLE (3<<4)
|
#define EMC0TOGGLE (3<<4)
|
||||||
#define MR0R (1<<1)
|
#define MR0R (1<<1)
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ int main(void) {
|
|||||||
sd_init();
|
sd_init();
|
||||||
fpga_spi_init();
|
fpga_spi_init();
|
||||||
delay_ms(10);
|
delay_ms(10);
|
||||||
printf("\n\nsd2snes mk.2\n============\ncpu clock: %d Hz\n", CONFIG_CPU_FREQUENCY);
|
printf("\n\nsd2snes mk.2\n============\nfw ver.: " VER "\ncpu clock: %d Hz\n", CONFIG_CPU_FREQUENCY);
|
||||||
file_init();
|
file_init();
|
||||||
/* uart_putc('S');
|
/* uart_putc('S');
|
||||||
for(p1=0; p1<8192; p1++) {
|
for(p1=0; p1<8192; p1++) {
|
||||||
@ -80,7 +83,8 @@ restart:
|
|||||||
rdyled(1);
|
rdyled(1);
|
||||||
readled(0);
|
readled(0);
|
||||||
writeled(0);
|
writeled(0);
|
||||||
set_mcu_ovr(1); // exclusive mode
|
/* exclusive mode */
|
||||||
|
set_mcu_ovr(1);
|
||||||
|
|
||||||
*fs_path=0;
|
*fs_path=0;
|
||||||
uint16_t saved_dir_id;
|
uint16_t saved_dir_id;
|
||||||
@ -89,14 +93,18 @@ restart:
|
|||||||
uint16_t mem_dir_id = sram_readshort(SRAM_DIRID);
|
uint16_t mem_dir_id = sram_readshort(SRAM_DIRID);
|
||||||
uint32_t mem_magic = sram_readlong(SRAM_SCRATCHPAD);
|
uint32_t mem_magic = sram_readlong(SRAM_SCRATCHPAD);
|
||||||
|
|
||||||
|
|
||||||
if((mem_magic != 0x12345678) || (mem_dir_id != saved_dir_id)) {
|
if((mem_magic != 0x12345678) || (mem_dir_id != saved_dir_id)) {
|
||||||
uint16_t curr_dir_id = scan_dir(fs_path, 0, 0); // generate files footprint
|
/* generate fs footprint (interesting files only) */
|
||||||
|
uint16_t curr_dir_id = scan_dir(fs_path, 0, 0);
|
||||||
printf("curr dir id = %x\n", curr_dir_id);
|
printf("curr dir id = %x\n", curr_dir_id);
|
||||||
if((get_db_id(&saved_dir_id) != FR_OK) // no database?
|
/* files changed or no database found? */
|
||||||
|| saved_dir_id != curr_dir_id) { // files changed? // XXX
|
if((get_db_id(&saved_dir_id) != FR_OK)
|
||||||
|
|| saved_dir_id != curr_dir_id) {
|
||||||
|
/* rebuild database */
|
||||||
printf("saved dir id = %x\n", saved_dir_id);
|
printf("saved dir id = %x\n", saved_dir_id);
|
||||||
printf("rebuilding database...");
|
printf("rebuilding database...");
|
||||||
curr_dir_id = scan_dir(fs_path, 1, 0); // then rebuild database
|
curr_dir_id = scan_dir(fs_path, 1, 0);
|
||||||
sram_writeblock(&curr_dir_id, SRAM_DB_ADDR, 2);
|
sram_writeblock(&curr_dir_id, SRAM_DB_ADDR, 2);
|
||||||
uint32_t endaddr, direndaddr;
|
uint32_t endaddr, direndaddr;
|
||||||
sram_readblock(&endaddr, SRAM_DB_ADDR+4, 4);
|
sram_readblock(&endaddr, SRAM_DB_ADDR+4, 4);
|
||||||
@ -108,18 +116,12 @@ restart:
|
|||||||
save_sram((uint8_t*)"/sd2snes/sd2snes.db", endaddr-SRAM_DB_ADDR, SRAM_DB_ADDR);
|
save_sram((uint8_t*)"/sd2snes/sd2snes.db", endaddr-SRAM_DB_ADDR, SRAM_DB_ADDR);
|
||||||
save_sram((uint8_t*)"/sd2snes/sd2snes.dir", direndaddr-(SRAM_DIR_ADDR), SRAM_DIR_ADDR);
|
save_sram((uint8_t*)"/sd2snes/sd2snes.dir", direndaddr-(SRAM_DIR_ADDR), SRAM_DIR_ADDR);
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
// sram_hexdump(SRAM_DB_ADDR, 0x400);
|
|
||||||
} else {
|
} else {
|
||||||
printf("saved dir id = %x\n", saved_dir_id);
|
printf("saved dir id = %x\n", saved_dir_id);
|
||||||
printf("different card, consistent db, loading db...\n");
|
printf("different card, consistent db, loading db...\n");
|
||||||
load_sram((uint8_t*)"/sd2snes/sd2snes.db", SRAM_DB_ADDR);
|
load_sram((uint8_t*)"/sd2snes/sd2snes.db", SRAM_DB_ADDR);
|
||||||
load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR);
|
load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR);
|
||||||
}
|
}
|
||||||
// save_sram((uint8_t*)"/debug.smc", 0x400000, 0);
|
|
||||||
// uart_putc('[');
|
|
||||||
// load_sram((uint8_t*)"/test.srm", SRAM_SAVE_ADDR);
|
|
||||||
// uart_putc(']');
|
|
||||||
|
|
||||||
sram_writeshort(curr_dir_id, SRAM_DIRID);
|
sram_writeshort(curr_dir_id, SRAM_DIRID);
|
||||||
sram_writelong(0x12345678, SRAM_SCRATCHPAD);
|
sram_writelong(0x12345678, SRAM_SCRATCHPAD);
|
||||||
} else {
|
} else {
|
||||||
@ -128,18 +130,18 @@ restart:
|
|||||||
load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR);
|
load_sram((uint8_t*)"/sd2snes/sd2snes.dir", SRAM_DIR_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* load menu */
|
||||||
uart_putc('(');
|
uart_putc('(');
|
||||||
load_rom((uint8_t*)"/sd2snes/menu.bin", SRAM_MENU_ADDR);
|
load_rom((uint8_t*)"/sd2snes/menu.bin", SRAM_MENU_ADDR);
|
||||||
set_rom_mask(0x3fffff); // force mirroring off
|
/* force memory size + mapper */
|
||||||
set_mapper(0x7); // menu mapper XXX
|
set_rom_mask(0x3fffff);
|
||||||
|
set_mapper(0x7);
|
||||||
uart_putc(')');
|
uart_putc(')');
|
||||||
uart_putcrlf();
|
uart_putcrlf();
|
||||||
// sram_hexdump(0x7ffff0, 0x10);
|
|
||||||
// sram_hexdump(0, 0x400);
|
|
||||||
// save_sram((uint8_t*)"/sd2snes/dump", 65536, 0);
|
|
||||||
|
|
||||||
sram_writebyte(0, SRAM_CMD_ADDR);
|
sram_writebyte(0, SRAM_CMD_ADDR);
|
||||||
|
|
||||||
|
/* shared mode */
|
||||||
set_mcu_ovr(0);
|
set_mcu_ovr(0);
|
||||||
|
|
||||||
printf("SNES GO!\n");
|
printf("SNES GO!\n");
|
||||||
@ -150,25 +152,15 @@ restart:
|
|||||||
while(!sram_reliable()) uart_puts("DERP");
|
while(!sram_reliable()) uart_puts("DERP");
|
||||||
printf("ok\n");
|
printf("ok\n");
|
||||||
|
|
||||||
/* uint8_t *teststring=(uint8_t*)"Wer das liest ist doof! 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
sram_hexdump(SRAM_DB_ADDR, 0x200);
|
||||||
uint8_t testbuf[80];
|
|
||||||
while(1) {
|
|
||||||
sram_writeblock(teststring, 0xd00000, 61);
|
|
||||||
sram_readblock(testbuf, 0xd00000, 61);
|
|
||||||
testbuf[60]=0;
|
|
||||||
printf("%p %s\n",testbuf, (char*)testbuf);
|
|
||||||
} */
|
|
||||||
|
|
||||||
while(!cmd) {
|
while(!cmd) {
|
||||||
cmd=menu_main_loop();
|
cmd=menu_main_loop();
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
case SNES_CMD_LOADROM:
|
case SNES_CMD_LOADROM:
|
||||||
get_selected_name(file_lfn);
|
get_selected_name(file_lfn);
|
||||||
// snes_reset(1);
|
|
||||||
set_mcu_ovr(1);
|
set_mcu_ovr(1);
|
||||||
printf("Selected name: %s\n", file_lfn);
|
printf("Selected name: %s\n", file_lfn);
|
||||||
load_rom(file_lfn, SRAM_ROM_ADDR);
|
load_rom(file_lfn, SRAM_ROM_ADDR);
|
||||||
// save_sram((uint8_t*)"/sd2snes/test.smc", romprops.romsize_bytes, 0);
|
|
||||||
if(romprops.ramsize_bytes) {
|
if(romprops.ramsize_bytes) {
|
||||||
strcpy(strrchr((char*)file_lfn, (int)'.'), ".srm");
|
strcpy(strrchr((char*)file_lfn, (int)'.'), ".srm");
|
||||||
printf("SRM file: %s\n", file_lfn);
|
printf("SRM file: %s\n", file_lfn);
|
||||||
@ -185,7 +177,7 @@ while(1) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("unknown cmd: %d\n", cmd);
|
printf("unknown cmd: %d\n", cmd);
|
||||||
cmd=0; // unknown cmd: stay in loop
|
cmd=0; /* unknown cmd: stay in loop */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +192,6 @@ while(1) {
|
|||||||
if(!snes_reset_prev) {
|
if(!snes_reset_prev) {
|
||||||
printf("RESET BUTTON DOWN\n");
|
printf("RESET BUTTON DOWN\n");
|
||||||
snes_reset_state=1;
|
snes_reset_state=1;
|
||||||
// reset reset counter
|
|
||||||
reset_count=0;
|
reset_count=0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -231,37 +222,7 @@ while(1) {
|
|||||||
}
|
}
|
||||||
snes_reset_prev = snes_reset_now;
|
snes_reset_prev = snes_reset_now;
|
||||||
}
|
}
|
||||||
// FPGA TEST FAIL. PANIC.
|
/* fpga test fail: panic */
|
||||||
led_panic();
|
led_panic();
|
||||||
|
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void teststuff(void) {
|
|
||||||
uint8_t i=0, data;
|
|
||||||
uint32_t p1;
|
|
||||||
sram_writebyte(0x5e, 0);
|
|
||||||
sram_writebyte(0x6f, 1);
|
|
||||||
sram_writelong(0x3451451e, 4);
|
|
||||||
sram_hexdump(0x0, 0x10);
|
|
||||||
sram_hexdump(0x620000, 0x200);
|
|
||||||
|
|
||||||
while(i<10) {
|
|
||||||
FPGA_SELECT();
|
|
||||||
FPGA_TX_BYTE(0xff);
|
|
||||||
FPGA_TX_BYTE(0xff);
|
|
||||||
data=FPGA_TXRX_BYTE(i);
|
|
||||||
FPGA_DESELECT();
|
|
||||||
printf("%x %x\n", i, data);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while(1) {
|
|
||||||
// if((data=fpga_test())!=0xa5) printf("Unexpected FPGA test token 0x%x\n", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
p1 = LPC_GPIO1->FIOPIN;
|
|
||||||
BITBAND(LPC_GPIO2->FIOPIN, 1) = (p1 & BV(29))>>29;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
75
src/memory.c
75
src/memory.c
@ -28,7 +28,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "fpga.h"
|
#include "fpga.h"
|
||||||
#include "crc16.h"
|
#include "crc.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
@ -53,17 +53,17 @@ void sram_hexdump(uint32_t addr, uint32_t len) {
|
|||||||
void sram_writebyte(uint8_t val, uint32_t addr) {
|
void sram_writebyte(uint8_t val, uint32_t addr) {
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x91); // WRITE
|
FPGA_TX_BYTE(0x91); /* WRITE */
|
||||||
FPGA_TX_BYTE(val);
|
FPGA_TX_BYTE(val);
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t sram_readbyte(uint32_t addr) {
|
uint8_t sram_readbyte(uint32_t addr) {
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x81); // READ
|
FPGA_TX_BYTE(0x81); /* READ */
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
uint8_t val = FPGA_TXRX_BYTE(0x00);
|
uint8_t val = FPGA_TXRX_BYTE(0x00);
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
return val;
|
return val;
|
||||||
@ -72,22 +72,22 @@ uint8_t sram_readbyte(uint32_t addr) {
|
|||||||
void sram_writeshort(uint16_t val, uint32_t addr) {
|
void sram_writeshort(uint16_t val, uint32_t addr) {
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x91); // WRITE
|
FPGA_TX_BYTE(0x91); /* WRITE */
|
||||||
FPGA_TX_BYTE(val&0xff); // 7-0
|
FPGA_TX_BYTE(val&0xff);
|
||||||
FPGA_TX_BYTE((val>>8)&0xff); // 15-8
|
FPGA_TX_BYTE((val>>8)&0xff);
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sram_writelong(uint32_t val, uint32_t addr) {
|
void sram_writelong(uint32_t val, uint32_t addr) {
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x91); // WRITE
|
FPGA_TX_BYTE(0x91); /* WRITE */
|
||||||
FPGA_TX_BYTE(val&0xff); // 7-0
|
FPGA_TX_BYTE(val&0xff);
|
||||||
FPGA_TX_BYTE((val>>8)&0xff); // 15-8
|
FPGA_TX_BYTE((val>>8)&0xff);
|
||||||
FPGA_TX_BYTE((val>>16)&0xff); // 23-15
|
FPGA_TX_BYTE((val>>16)&0xff);
|
||||||
FPGA_TX_BYTE((val>>24)&0xff); // 31-24
|
FPGA_TX_BYTE((val>>24)&0xff);
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00);
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,6 @@ uint16_t sram_readshort(uint32_t addr) {
|
|||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x81);
|
FPGA_TX_BYTE(0x81);
|
||||||
FPGA_TX_BYTE(0x00);
|
FPGA_TX_BYTE(0x00);
|
||||||
|
|
||||||
uint32_t val = FPGA_TXRX_BYTE(0x00);
|
uint32_t val = FPGA_TXRX_BYTE(0x00);
|
||||||
val |= ((uint32_t)FPGA_TXRX_BYTE(0x00)<<8);
|
val |= ((uint32_t)FPGA_TXRX_BYTE(0x00)<<8);
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
@ -137,8 +136,8 @@ void sram_readblock(void* buf, uint32_t addr, uint16_t size) {
|
|||||||
uint8_t* tgt = buf;
|
uint8_t* tgt = buf;
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x81); // READ
|
FPGA_TX_BYTE(0x81); /* READ */
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
while(count--) {
|
while(count--) {
|
||||||
*(tgt++) = FPGA_TXRX_BYTE(0x00);
|
*(tgt++) = FPGA_TXRX_BYTE(0x00);
|
||||||
}
|
}
|
||||||
@ -150,16 +149,15 @@ void sram_writeblock(void* buf, uint32_t addr, uint16_t size) {
|
|||||||
uint8_t* src = buf;
|
uint8_t* src = buf;
|
||||||
set_mcu_addr(addr);
|
set_mcu_addr(addr);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x91); // WRITE
|
FPGA_TX_BYTE(0x91); /* WRITE */
|
||||||
while(count--) {
|
while(count--) {
|
||||||
FPGA_TX_BYTE(*src++);
|
FPGA_TX_BYTE(*src++);
|
||||||
}
|
}
|
||||||
FPGA_TX_BYTE(0x00); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t load_rom(uint8_t* filename, uint32_t base_addr) {
|
uint32_t load_rom(uint8_t* filename, uint32_t base_addr) {
|
||||||
// uint8_t dummy;
|
|
||||||
UINT bytes_read;
|
UINT bytes_read;
|
||||||
DWORD filesize;
|
DWORD filesize;
|
||||||
UINT count=0;
|
UINT count=0;
|
||||||
@ -176,28 +174,20 @@ uint32_t load_rom(uint8_t* filename, uint32_t base_addr) {
|
|||||||
f_lseek(&file_handle, romprops.offset);
|
f_lseek(&file_handle, romprops.offset);
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
for(;;) {
|
for(;;) {
|
||||||
// SPI_OFFLOAD=1;
|
/* SPI_OFFLOAD=1; */
|
||||||
bytes_read = file_read();
|
bytes_read = file_read();
|
||||||
if (file_res || !bytes_read) break;
|
if (file_res || !bytes_read) break;
|
||||||
if(!(count++ % 32)) {
|
if(!(count++ % 32)) {
|
||||||
toggle_read_led();
|
toggle_read_led();
|
||||||
// bounce_busy_led();
|
/* bounce_busy_led(); */
|
||||||
uart_putc('.');
|
uart_putc('.');
|
||||||
}
|
}
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x91); // write w/ increment
|
FPGA_TX_BYTE(0x91); /* write w/ increment */
|
||||||
if(!(count++ % 8)) {
|
|
||||||
// toggle_busy_led();
|
|
||||||
// bounce_busy_led();
|
|
||||||
uart_putc('.');
|
|
||||||
}
|
|
||||||
for(int j=0; j<bytes_read; j++) {
|
for(int j=0; j<bytes_read; j++) {
|
||||||
FPGA_TX_BYTE(file_buf[j]);
|
FPGA_TX_BYTE(file_buf[j]);
|
||||||
/* SPDR = file_buf[j];
|
|
||||||
loop_until_bit_is_set(SPSR, SPIF);
|
|
||||||
dummy = SPDR;*/
|
|
||||||
}
|
}
|
||||||
FPGA_TX_BYTE(0x00); // dummy tx for increment+write pulse */
|
FPGA_TX_BYTE(0x00); /* dummy tx for increment+write pulse */
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
file_close();
|
file_close();
|
||||||
@ -239,7 +229,7 @@ uint32_t load_sram(uint8_t* filename, uint32_t base_addr) {
|
|||||||
for(int j=0; j<bytes_read; j++) {
|
for(int j=0; j<bytes_read; j++) {
|
||||||
FPGA_TX_BYTE(file_buf[j]);
|
FPGA_TX_BYTE(file_buf[j]);
|
||||||
}
|
}
|
||||||
FPGA_TX_BYTE(0x00); // dummy tx
|
FPGA_TX_BYTE(0x00); /* dummy tx */
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
}
|
}
|
||||||
file_close();
|
file_close();
|
||||||
@ -259,8 +249,8 @@ void save_sram(uint8_t* filename, uint32_t sram_size, uint32_t base_addr) {
|
|||||||
while(count<sram_size) {
|
while(count<sram_size) {
|
||||||
set_mcu_addr(base_addr+count);
|
set_mcu_addr(base_addr+count);
|
||||||
FPGA_SELECT();
|
FPGA_SELECT();
|
||||||
FPGA_TX_BYTE(0x81); // read
|
FPGA_TX_BYTE(0x81); /* read */
|
||||||
FPGA_TX_BYTE(0); // dummy
|
FPGA_TX_BYTE(0x00); /* dummy */
|
||||||
for(int j=0; j<sizeof(file_buf); j++) {
|
for(int j=0; j<sizeof(file_buf); j++) {
|
||||||
file_buf[j] = FPGA_TXRX_BYTE(0x00);
|
file_buf[j] = FPGA_TXRX_BYTE(0x00);
|
||||||
count++;
|
count++;
|
||||||
@ -291,7 +281,7 @@ uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size) {
|
|||||||
crc_valid = 0;
|
crc_valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
crc += crc16_update(crc, &data, 1);
|
crc += crc_xmodem_update(crc, data);
|
||||||
}
|
}
|
||||||
FPGA_DESELECT();
|
FPGA_DESELECT();
|
||||||
return crc;
|
return crc;
|
||||||
@ -300,27 +290,26 @@ uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size) {
|
|||||||
uint8_t sram_reliable() {
|
uint8_t sram_reliable() {
|
||||||
uint16_t score=0;
|
uint16_t score=0;
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
// uint32_t val = sram_readlong(SRAM_SCRATCHPAD);
|
|
||||||
uint8_t result = 0;
|
uint8_t result = 0;
|
||||||
/* while(score<SRAM_RELIABILITY_SCORE) {
|
/*while(score<SRAM_RELIABILITY_SCORE) {
|
||||||
if(sram_readlong(SRAM_SCRATCHPAD)==val) {
|
if(sram_readlong(SRAM_SCRATCHPAD)==val) {
|
||||||
score++;
|
score++;
|
||||||
} else {
|
} else {
|
||||||
set_pwr_led(0);
|
set_pwr_led(0);
|
||||||
score=0;
|
score=0;
|
||||||
}
|
}
|
||||||
}*/
|
} */
|
||||||
for(uint16_t i = 0; i < SRAM_RELIABILITY_SCORE; i++) {
|
for(uint16_t i = 0; i < SRAM_RELIABILITY_SCORE; i++) {
|
||||||
val=sram_readlong(SRAM_SCRATCHPAD);
|
val=sram_readlong(SRAM_SCRATCHPAD);
|
||||||
if(val==0x12345678) {
|
if(val==0x12345678) {
|
||||||
score++;
|
score++;
|
||||||
// } else {
|
/* } else {
|
||||||
// dprintf("i=%d val=%08lX\n", i, val);
|
dprintf("i=%d val=%08lX\n", i, val); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(score<SRAM_RELIABILITY_SCORE) {
|
if(score<SRAM_RELIABILITY_SCORE) {
|
||||||
result = 0;
|
result = 0;
|
||||||
// dprintf("score=%d\n", score);
|
/* dprintf("score=%d\n", score); */
|
||||||
} else {
|
} else {
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/memory.h
34
src/memory.h
@ -28,6 +28,7 @@
|
|||||||
#define MEMORY_H
|
#define MEMORY_H
|
||||||
|
|
||||||
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
#include <arm/NXP/LPC17xx/LPC17xx.h>
|
||||||
|
#include "smc.h"
|
||||||
|
|
||||||
#define SRAM_ROM_ADDR (0x000000L)
|
#define SRAM_ROM_ADDR (0x000000L)
|
||||||
#define SRAM_SAVE_ADDR (0xE00000L)
|
#define SRAM_SAVE_ADDR (0xE00000L)
|
||||||
@ -42,22 +43,21 @@
|
|||||||
#define SRAM_DIRID (0xFFFFF0L)
|
#define SRAM_DIRID (0xFFFFF0L)
|
||||||
#define SRAM_RELIABILITY_SCORE (0x100)
|
#define SRAM_RELIABILITY_SCORE (0x100)
|
||||||
|
|
||||||
uint32_t load_rom(uint8_t* filename, uint32_t base_addr);
|
uint32_t load_rom(uint8_t* filename, uint32_t base_addr);
|
||||||
uint32_t load_sram(uint8_t* filename, uint32_t base_addr);
|
uint32_t load_sram(uint8_t* filename, uint32_t base_addr);
|
||||||
void sram_hexdump(uint32_t addr, uint32_t len);
|
void sram_hexdump(uint32_t addr, uint32_t len);
|
||||||
uint8_t sram_readbyte(uint32_t addr);
|
uint8_t sram_readbyte(uint32_t addr);
|
||||||
uint16_t sram_readshort(uint32_t addr);
|
uint16_t sram_readshort(uint32_t addr);
|
||||||
uint32_t sram_readlong(uint32_t addr);
|
uint32_t sram_readlong(uint32_t addr);
|
||||||
void sram_writebyte(uint8_t val, uint32_t addr);
|
void sram_writebyte(uint8_t val, uint32_t addr);
|
||||||
void sram_writeshort(uint16_t val, uint32_t addr);
|
void sram_writeshort(uint16_t val, uint32_t addr);
|
||||||
void sram_writelong(uint32_t val, uint32_t addr);
|
void sram_writelong(uint32_t val, uint32_t addr);
|
||||||
void sram_readblock(void* buf, uint32_t addr, uint16_t size);
|
void sram_readblock(void* buf, uint32_t addr, uint16_t size);
|
||||||
void sram_readlongblock(uint32_t* buf, uint32_t addr, uint16_t count);
|
void sram_readlongblock(uint32_t* buf, uint32_t addr, uint16_t count);
|
||||||
void sram_writeblock(void* buf, uint32_t addr, uint16_t size);
|
void sram_writeblock(void* buf, uint32_t addr, uint16_t size);
|
||||||
void save_sram(uint8_t* filename, uint32_t sram_size, uint32_t base_addr);
|
void save_sram(uint8_t* filename, uint32_t sram_size, uint32_t base_addr);
|
||||||
uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size);
|
uint32_t calc_sram_crc(uint32_t base_addr, uint32_t size);
|
||||||
uint8_t sram_reliable(void);
|
uint8_t sram_reliable(void);
|
||||||
|
|
||||||
#include "smc.h"
|
snes_romprops_t romprops;
|
||||||
snes_romprops_t romprops;
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
18
src/smc.c
18
src/smc.c
@ -74,15 +74,13 @@ uint8_t checkChksum(uint16_t cchk, uint16_t chk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void smc_id(snes_romprops_t* props) {
|
void smc_id(snes_romprops_t* props) {
|
||||||
uint8_t score, maxscore=1, score_idx=2; // assume LoROM
|
uint8_t score, maxscore=1, score_idx=2; /* assume LoROM */
|
||||||
|
|
||||||
snes_header_t* header = &(props->header);
|
snes_header_t* header = &(props->header);
|
||||||
|
|
||||||
for(uint8_t num = 0; num < 6; num++) {
|
for(uint8_t num = 0; num < 6; num++) {
|
||||||
if(!file_readblock(header, hdr_addr[num], sizeof(snes_header_t))
|
if(!file_readblock(header, hdr_addr[num], sizeof(snes_header_t))
|
||||||
|| file_res) {
|
|| file_res) {
|
||||||
// dprintf("uh oh... %d\n", file_res);
|
|
||||||
// _delay_ms(30);
|
|
||||||
score = 0;
|
score = 0;
|
||||||
} else {
|
} else {
|
||||||
score = smc_headerscore(header)/(1+(num&1));
|
score = smc_headerscore(header)/(1+(num&1));
|
||||||
@ -100,8 +98,7 @@ void smc_id(snes_romprops_t* props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dprintf("%d: offset = %lX; score = %d\n", num, hdr_addr[num], score);
|
/* dprintf("%d: offset = %lX; score = %d\n", num, hdr_addr[num], score); */
|
||||||
// _delay_ms(100);
|
|
||||||
if(score>=maxscore) {
|
if(score>=maxscore) {
|
||||||
score_idx=num;
|
score_idx=num;
|
||||||
maxscore=score;
|
maxscore=score;
|
||||||
@ -114,9 +111,8 @@ void smc_id(snes_romprops_t* props) {
|
|||||||
props->offset = 0;
|
props->offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore the chosen one
|
/* restore the chosen one */
|
||||||
// dprintf("winner is %d\n", score_idx);
|
/*dprintf("winner is %d\n", score_idx); */
|
||||||
// _delay_ms(30);
|
|
||||||
file_readblock(header, hdr_addr[score_idx], sizeof(snes_header_t));
|
file_readblock(header, hdr_addr[score_idx], sizeof(snes_header_t));
|
||||||
switch(header->map & 0xef) {
|
switch(header->map & 0xef) {
|
||||||
case 0x20:
|
case 0x20:
|
||||||
@ -128,7 +124,7 @@ void smc_id(snes_romprops_t* props) {
|
|||||||
case 0x25:
|
case 0x25:
|
||||||
props->mapper_id = 2;
|
props->mapper_id = 2;
|
||||||
break;
|
break;
|
||||||
default: // invalid/unsupported mapper, use header location
|
default: /* invalid/unsupported mapper, use header location */
|
||||||
switch(score_idx) {
|
switch(score_idx) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@ -152,11 +148,11 @@ void smc_id(snes_romprops_t* props) {
|
|||||||
props->ramsize_bytes = (uint32_t)1024 << header->ramsize;
|
props->ramsize_bytes = (uint32_t)1024 << header->ramsize;
|
||||||
props->romsize_bytes = (uint32_t)1024 << header->romsize;
|
props->romsize_bytes = (uint32_t)1024 << header->romsize;
|
||||||
props->expramsize_bytes = (uint32_t)1024 << header->expramsize;
|
props->expramsize_bytes = (uint32_t)1024 << header->expramsize;
|
||||||
// dprintf("ramsize_bytes: %ld\n", props->ramsize_bytes);
|
/*dprintf("ramsize_bytes: %ld\n", props->ramsize_bytes); */
|
||||||
if(props->ramsize_bytes > 32768 || props->ramsize_bytes < 2048) {
|
if(props->ramsize_bytes > 32768 || props->ramsize_bytes < 2048) {
|
||||||
props->ramsize_bytes = 0;
|
props->ramsize_bytes = 0;
|
||||||
}
|
}
|
||||||
// dprintf("ramsize_bytes: %ld\n", props->ramsize_bytes);
|
/*dprintf("ramsize_bytes: %ld\n", props->ramsize_bytes); */
|
||||||
f_lseek(&file_handle, 0);
|
f_lseek(&file_handle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
46
src/smc.h
46
src/smc.h
@ -28,32 +28,32 @@
|
|||||||
#define SMC_H
|
#define SMC_H
|
||||||
|
|
||||||
typedef struct _snes_header {
|
typedef struct _snes_header {
|
||||||
uint8_t maker[2]; // 0xB0
|
uint8_t maker[2]; /* 0xB0 */
|
||||||
uint8_t gamecode[4]; // 0xB2
|
uint8_t gamecode[4]; /* 0xB2 */
|
||||||
uint8_t fixed_00[7]; // 0xB6
|
uint8_t fixed_00[7]; /* 0xB6 */
|
||||||
uint8_t expramsize; // 0xBD
|
uint8_t expramsize; /* 0xBD */
|
||||||
uint8_t specver; // 0xBE
|
uint8_t specver; /* 0xBE */
|
||||||
uint8_t carttype2; // 0xBF
|
uint8_t carttype2; /* 0xBF */
|
||||||
uint8_t name[21]; // 0xC0
|
uint8_t name[21]; /* 0xC0 */
|
||||||
uint8_t map; // 0xD5
|
uint8_t map; /* 0xD5 */
|
||||||
uint8_t carttype; // 0xD6
|
uint8_t carttype; /* 0xD6 */
|
||||||
uint8_t romsize; // 0xD7
|
uint8_t romsize; /* 0xD7 */
|
||||||
uint8_t ramsize; // 0xD8
|
uint8_t ramsize; /* 0xD8 */
|
||||||
uint8_t destcode; // 0xD9
|
uint8_t destcode; /* 0xD9 */
|
||||||
uint8_t fixed_33; // 0xDA
|
uint8_t fixed_33; /* 0xDA */
|
||||||
uint8_t ver; // 0xDB
|
uint8_t ver; /* 0xDB */
|
||||||
uint16_t cchk; // 0xDC
|
uint16_t cchk; /* 0xDC */
|
||||||
uint16_t chk; // 0xDE
|
uint16_t chk; /* 0xDE */
|
||||||
} snes_header_t;
|
} snes_header_t;
|
||||||
|
|
||||||
typedef struct _snes_romprops {
|
typedef struct _snes_romprops {
|
||||||
uint16_t offset; // start of actual ROM image
|
uint16_t offset; /* start of actual ROM image */
|
||||||
uint8_t mapper_id; // FPGA mapper
|
uint8_t mapper_id; /* FPGA mapper */
|
||||||
uint8_t pad1; // for alignment
|
uint8_t pad1; /* for alignment */
|
||||||
uint32_t expramsize_bytes; // ExpRAM size in bytes
|
uint32_t expramsize_bytes; /* ExpRAM size in bytes */
|
||||||
uint32_t ramsize_bytes; // CartRAM size in bytes
|
uint32_t ramsize_bytes; /* CartRAM size in bytes */
|
||||||
uint32_t romsize_bytes; // ROM size in bytes (rounded up)
|
uint32_t romsize_bytes; /* ROM size in bytes (rounded up) */
|
||||||
snes_header_t header; // original header from ROM image
|
snes_header_t header; /* original header from ROM image */
|
||||||
} snes_romprops_t;
|
} snes_romprops_t;
|
||||||
|
|
||||||
void smc_id(snes_romprops_t*);
|
void smc_id(snes_romprops_t*);
|
||||||
|
|||||||
@ -131,5 +131,5 @@ uint8_t menu_main_loop() {
|
|||||||
void get_selected_name(uint8_t* fn) {
|
void get_selected_name(uint8_t* fn) {
|
||||||
uint32_t addr = sram_readlong(SRAM_PARAM_ADDR);
|
uint32_t addr = sram_readlong(SRAM_PARAM_ADDR);
|
||||||
printf("fd addr=%lx\n", addr);
|
printf("fd addr=%lx\n", addr);
|
||||||
sram_readblock(fn, addr+0x41+SRAM_MENU_ADDR, 256);
|
sram_readblock(fn, addr+1+SRAM_MENU_ADDR, 256);
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/sort.c
15
src/sort.c
@ -41,9 +41,7 @@ int sort_cmp_elem(const void* elem1, const void* elem2) {
|
|||||||
uint32_t el2 = *(uint32_t*)elem2;
|
uint32_t el2 = *(uint32_t*)elem2;
|
||||||
sort_getstring_for_dirent(sort_str1, el1);
|
sort_getstring_for_dirent(sort_str1, el1);
|
||||||
sort_getstring_for_dirent(sort_str2, el2);
|
sort_getstring_for_dirent(sort_str2, el2);
|
||||||
//sort_getlong_for_dirent(sort_long1, elem1);
|
/*printf("i1=%d i2=%d elem1=%lx elem2=%lx ; compare %s --- %s\n", index1, index2, elem1, elem2, sort_str1, sort_str2); */
|
||||||
//sort_getlong_for_dirent(sort_long2, elem2);
|
|
||||||
// printf("i1=%d i2=%d elem1=%lx elem2=%lx ; compare %s --- %s\n", index1, index2, elem1, elem2, sort_str1, sort_str2);
|
|
||||||
|
|
||||||
if ((el1 & 0x80000000) && !(el2 & 0x80000000)) {
|
if ((el1 & 0x80000000) && !(el2 & 0x80000000)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -58,7 +56,7 @@ int sort_cmp_elem(const void* elem1, const void* elem2) {
|
|||||||
if(cmp_i==8) {
|
if(cmp_i==8) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return sort_long1[cmp_i]-sort_long2[cmp_i];*/
|
return sort_long1[cmp_i]-sort_long2[cmp_i]; */
|
||||||
return strcasecmp(sort_str1, sort_str2);
|
return strcasecmp(sort_str1, sort_str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,25 +68,22 @@ stat_getstring++;
|
|||||||
sram_readblock(ptr, addr+0x6+SRAM_MENU_ADDR, 20);
|
sram_readblock(ptr, addr+0x6+SRAM_MENU_ADDR, 20);
|
||||||
} else {
|
} else {
|
||||||
/* is file link, name offset 65 */
|
/* is file link, name offset 65 */
|
||||||
sram_readblock(ptr, addr+0x41+SRAM_MENU_ADDR, 20);
|
sram_readblock(ptr, addr+1+SRAM_MENU_ADDR, 20);
|
||||||
}
|
}
|
||||||
ptr[20]=0;
|
ptr[20]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort_heapify(uint32_t addr, unsigned int i, unsigned int heapsize)
|
void sort_heapify(uint32_t addr, unsigned int i, unsigned int heapsize)
|
||||||
{
|
{
|
||||||
while(1)
|
while(1) {
|
||||||
{
|
|
||||||
unsigned int l = 2*i+1;
|
unsigned int l = 2*i+1;
|
||||||
unsigned int r = 2*i+2;
|
unsigned int r = 2*i+2;
|
||||||
|
|
||||||
unsigned int largest = (l < heapsize && sort_cmp_idx(addr, i, l) < 0) ? l : i;
|
unsigned int largest = (l < heapsize && sort_cmp_idx(addr, i, l) < 0) ? l : i;
|
||||||
|
|
||||||
if(r < heapsize && sort_cmp_idx(addr, largest, r) < 0)
|
if(r < heapsize && sort_cmp_idx(addr, largest, r) < 0)
|
||||||
largest = r;
|
largest = r;
|
||||||
|
|
||||||
if(largest != i)
|
if(largest != i) {
|
||||||
{
|
|
||||||
uint32_t tmp = sort_get_elem(addr, i);
|
uint32_t tmp = sort_get_elem(addr, i);
|
||||||
sort_put_elem(addr, i, sort_get_elem(addr, largest));
|
sort_put_elem(addr, i, sort_get_elem(addr, largest));
|
||||||
sort_put_elem(addr, largest, tmp);
|
sort_put_elem(addr, largest, tmp);
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
volatile tick_t ticks;
|
volatile tick_t ticks;
|
||||||
|
|
||||||
void __attribute__((weak,noinline)) SysTick_Hook(void) {
|
void __attribute__((weak,noinline)) SysTick_Hook(void) {
|
||||||
// Empty function for hooking the systick handler
|
/* Empty function for hooking the systick handler */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Systick interrupt handler */
|
/* Systick interrupt handler */
|
||||||
@ -30,7 +30,7 @@ void timer_init(void) {
|
|||||||
BITBAND(LPC_SC->PCONP, PCRIT) = 1;
|
BITBAND(LPC_SC->PCONP, PCRIT) = 1;
|
||||||
|
|
||||||
/* clear RIT mask */
|
/* clear RIT mask */
|
||||||
LPC_RIT->RIMASK = 0; //xffffffff;
|
LPC_RIT->RIMASK = 0; /*xffffffff;*/
|
||||||
|
|
||||||
/* PCLK = CCLK */
|
/* PCLK = CCLK */
|
||||||
BITBAND(LPC_SC->PCLKSEL1, 26) = 1;
|
BITBAND(LPC_SC->PCLKSEL1, 26) = 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user