o add io test
This commit is contained in:
@@ -24,7 +24,10 @@ LD=$(WINE) $(SDK)/bin/WDCLN.exe
|
||||
# Project
|
||||
|
||||
INC=$(SDK)/include
|
||||
LIBS=$(SDK)/lib/cc
|
||||
LIBS=-L$(SDK)/lib/cc
|
||||
#-L$(SDK)/lib/c134
|
||||
|
||||
|
||||
OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj
|
||||
APP=fatfs.smc
|
||||
GFX=debugfont
|
||||
@@ -62,7 +65,7 @@ $(APP): $(OBJS)
|
||||
-Avectors=FFE4,7FE4 \
|
||||
-Aregistration_data=FFB0,7FB0 \
|
||||
-Aressource=18000,8000 \
|
||||
-N $(OBJS) -L$(LIBS) -O $@
|
||||
-N $(OBJS) $(LIBS) -O $@
|
||||
ucon64 -snes -chk $(APP)
|
||||
|
||||
clean:
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "data.h"
|
||||
#include "pad.h"
|
||||
#include "PPU.h"
|
||||
#include "ressource.h"
|
||||
|
||||
word debugMap[0x400];
|
||||
|
||||
static char debug_buffer[255];
|
||||
char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
void debug_init(void) {
|
||||
word i;
|
||||
for(i=0; i<0x400; i++) {
|
||||
debugMap[i] = 0x00;
|
||||
}
|
||||
memset(debug_buffer,0,255);
|
||||
}
|
||||
|
||||
void debug_enable(void){
|
||||
VRAMLoad((word) debugFont_pic, 0x5000, 2048);
|
||||
CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16);
|
||||
VRAMLoad((word) debugMap, 0x4000, 0x0800);
|
||||
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
|
||||
setCharacterLocation(0x5000, (byte) 0);
|
||||
*(byte*) 0x2100 = 0x0f; // enable background
|
||||
}
|
||||
|
||||
char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
void int2hex(unsigned long number, char *buf,word size)
|
||||
{
|
||||
@@ -30,6 +43,8 @@ void int2hex(unsigned long number, char *buf,word size)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_screen(char *buffer,word y){
|
||||
char i;
|
||||
char l;
|
||||
@@ -43,16 +58,55 @@ void print_screen(char *buffer,word y){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_console(char *buffer){
|
||||
while(*buffer)
|
||||
*(byte*) 0x3000=*buffer++;
|
||||
}
|
||||
|
||||
void debug_enable(void){
|
||||
VRAMLoad((word) debugFont_pic, 0x5000, 2048);
|
||||
CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16);
|
||||
VRAMLoad((word) debugMap, 0x4000, 0x0800);
|
||||
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
|
||||
setCharacterLocation(0x5000, (byte) 0);
|
||||
*(byte*) 0x2100 = 0x0f; // enable background
|
||||
}
|
||||
|
||||
void printfc(char *fmt, ...){
|
||||
va_list arg;
|
||||
va_start(arg,fmt);
|
||||
vsprintf(debug_buffer,fmt,arg);
|
||||
print_console(debug_buffer);
|
||||
}
|
||||
|
||||
|
||||
/* keep the linker happy */
|
||||
int open(const char * _name, int _mode){
|
||||
print_console("open called\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int close(int fd){
|
||||
print_console("close called\n");
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
size_t read(int fd, void * buff, size_t len){
|
||||
print_console("read called\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t write(int fd, void * buffer, size_t len){
|
||||
print_console("write called\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
long lseek(int fd, long off, int count){
|
||||
print_console("lseek called\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unlink(const char * name){
|
||||
print_console("unlink called\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int isatty(){
|
||||
print_console("isatty called\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "diskio.h"
|
||||
#include "config.h"
|
||||
#include "data.h"
|
||||
#include "debug.h"
|
||||
|
||||
static
|
||||
volatile static
|
||||
DSTATUS Stat = STA_NOINIT; /* Disk status */
|
||||
|
||||
|
||||
@@ -38,6 +39,7 @@ BYTE *image_addr;
|
||||
DSTATUS disk_initialize (BYTE drv) {
|
||||
|
||||
byte retval;
|
||||
print_console("disk_initialize\n");
|
||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||
|
||||
|
||||
@@ -46,7 +48,8 @@ DSTATUS disk_initialize (BYTE drv) {
|
||||
*(byte*) MMIO_CMD = CMD_INIT;
|
||||
while(*(byte*) MMIO_RETVAL == STA_VOID);
|
||||
retval = *(byte*) MMIO_RETVAL;
|
||||
Stat &= ~retval; /* When device goes ready, clear STA_NOINIT */
|
||||
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
|
||||
print_console("disk_initialize done\n");
|
||||
return Stat;
|
||||
}
|
||||
|
||||
@@ -76,11 +79,12 @@ DRESULT disk_read (
|
||||
INT size;
|
||||
byte retval;
|
||||
word i;
|
||||
for (i=0;i<(count*512);i++)
|
||||
*(byte*)(SHARED_ADDR+i) = buff[i];
|
||||
|
||||
if (drv || !count) return RES_PARERR;
|
||||
print_console("disk_read enter\n");
|
||||
//if (drv || !count) return RES_PARERR;
|
||||
print_console("drv ok\n");
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
print_console("sta ok\n");
|
||||
|
||||
*(byte*) MMIO_RETVAL = STA_VOID;
|
||||
*(byte*) MMIO_CMD = CMD_READ;
|
||||
@@ -95,6 +99,9 @@ DRESULT disk_read (
|
||||
while(*(byte*) MMIO_RETVAL == STA_VOID);
|
||||
retval = *(byte*) MMIO_RETVAL;
|
||||
|
||||
print_console("copy buffer\n");
|
||||
for (i=0;i<(count*512);i++)
|
||||
*(byte*)(SHARED_ADDR+i) = buff[i];
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
/ performance and code efficiency. */
|
||||
|
||||
|
||||
#define _FS_READONLY 1
|
||||
#define _FS_READONLY 0
|
||||
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
|
||||
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
|
||||
/ f_truncate and useless f_getfree. */
|
||||
|
||||
@@ -5,12 +5,29 @@
|
||||
#include "ressource.h";
|
||||
#include "PPU.h"
|
||||
#include "debug.h"
|
||||
#include "ff.h"
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
padStatus pad1;
|
||||
|
||||
|
||||
WORD acc_size; /* Work register for fs command */
|
||||
WORD acc_files, acc_dirs;
|
||||
FILINFO finfo;
|
||||
|
||||
FATFS fatfs[2]; /* File system object for each logical drive */
|
||||
BYTE buff[512]; /* Working buffer */
|
||||
|
||||
FATFS *fs;
|
||||
DIR dir; /* Directory object */
|
||||
FIL file1, file2; /* File object */
|
||||
DWORD p1, p2, p3;
|
||||
|
||||
|
||||
void initInternalRegisters(void) {
|
||||
characterLocation[0] = 0x0000;
|
||||
characterLocation[1] = 0x0000;
|
||||
@@ -24,14 +41,73 @@ void preInit(void) {
|
||||
// Insert code here to be executed before register init
|
||||
}
|
||||
|
||||
DWORD get_fattime ()
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm * ptm;
|
||||
//time ( &rawtime );
|
||||
ptm = gmtime ( &rawtime );
|
||||
|
||||
return ((DWORD)(ptm->tm_year - 80) << 25)
|
||||
| ((DWORD)(ptm->tm_mon +1) << 21)
|
||||
| ((DWORD)ptm->tm_mday << 16)
|
||||
| ((DWORD)ptm->tm_hour << 11)
|
||||
| ((DWORD)ptm->tm_min << 5)
|
||||
| ((DWORD)ptm->tm_sec >> 1);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
FRESULT scan_files (char* path)
|
||||
{
|
||||
DIR dirs;
|
||||
FRESULT res;
|
||||
int i;
|
||||
|
||||
if ((res = f_opendir(&dirs, path)) == FR_OK) {
|
||||
i = strlen(path);
|
||||
//printf("Ok\n");
|
||||
while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
|
||||
if (finfo.fattrib & AM_DIR) {
|
||||
acc_dirs++;
|
||||
*(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]);
|
||||
res = scan_files(path);
|
||||
*(path+i) = '\0';
|
||||
if (res != FR_OK) break;
|
||||
} else {
|
||||
acc_files++;
|
||||
acc_size += finfo.fsize;
|
||||
}
|
||||
}
|
||||
}
|
||||
print_console("scan_files ret\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void put_rc (FRESULT rc)
|
||||
{
|
||||
char *p;
|
||||
static char str[] =
|
||||
"OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0"
|
||||
"DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
|
||||
"NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
|
||||
FRESULT i;
|
||||
|
||||
for (p = str, i = 0; i != rc && *p; i++) {
|
||||
while(*p++);
|
||||
}
|
||||
print_console(p);
|
||||
}
|
||||
|
||||
void halt(void) {
|
||||
while(1);
|
||||
|
||||
}
|
||||
void main(void) {
|
||||
word i,j;
|
||||
word crc01;
|
||||
word crc02;
|
||||
padStatus pad1;
|
||||
char line_header[32] = "OK2";
|
||||
BYTE res;
|
||||
initInternalRegisters();
|
||||
|
||||
*(byte*) 0x2105 = 0x01; // MODE 1 value
|
||||
*(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register
|
||||
*(byte*) 0x212d = 0x00; // All subPlane disable
|
||||
@@ -39,9 +115,45 @@ void main(void) {
|
||||
|
||||
debug_enable();
|
||||
print_screen("FATFS TEST",0);
|
||||
print_console("Debugging console test\n");
|
||||
print_console("test me\n");
|
||||
print_console("mount ");
|
||||
|
||||
put_rc(f_mount(0, &fatfs[0]));
|
||||
|
||||
print_console("disk_initialize \n");
|
||||
disk_initialize(0);
|
||||
print_console("disk_read \n");
|
||||
disk_read(0,buff,0xaabb,1);
|
||||
print_console("disk_done \n");
|
||||
|
||||
|
||||
halt();
|
||||
|
||||
res = f_getfree("/", &p2, &fs);
|
||||
if (res) {
|
||||
put_rc(res);
|
||||
}
|
||||
/*
|
||||
printf("FAT type = %u\nBytes/Cluster = %lu\nNumber of FATs = %u\n"
|
||||
"Root DIR entries = %u\nSectors/FAT = %lu\nNumber of clusters = %lu\n"
|
||||
"FAT start (lba) = %lu\nDIR start (lba,clustor) = %lu\nData start (lba) = %lu\n",
|
||||
(WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
|
||||
fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2,
|
||||
fs->fatbase, fs->dirbase, fs->database
|
||||
);
|
||||
*/
|
||||
acc_size = acc_files = acc_dirs = 0;
|
||||
res = scan_files("/");
|
||||
if (res) {
|
||||
put_rc(res);
|
||||
}
|
||||
/*
|
||||
printf("%u files, %lu bytes.\n%u folders.\n"
|
||||
"%lu KB total disk space.\n%lu KB available.\n",
|
||||
acc_files, acc_size, acc_dirs,
|
||||
(fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)
|
||||
);
|
||||
*/
|
||||
|
||||
while(1){
|
||||
while(!pad1.start) {
|
||||
waitForVBlank();
|
||||
|
||||
Reference in New Issue
Block a user