cleanup code

This commit is contained in:
david 2009-06-08 11:00:27 +02:00
parent cb0ea4f8c8
commit 309e1062b9
21 changed files with 4723 additions and 4705 deletions

View File

@ -29,22 +29,15 @@ LIBS=-L$(SDK)/lib/cl
#-L$(SDK)/lib/c134
<<<<<<< HEAD:snes/fatfstest/Makefile
OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj
=======
OBJS=hook.obj StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj crc.obj
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/Makefile
APP=fatfs.smc
GFX=debugfont
all: $(APP) repair
all: $(APP)
run:
run:
$(EMU) $(APP)
debugger:
$(EMU_DEBUG) $(APP)
upload:
ucon64 -chk $(APP)
cp -rv $(APP) /Volumes/SNES
@ -55,6 +48,10 @@ disasm: $(APP)
rm -rf fatfs.asm
$(DISASM) fatfs.smc > fatfs.asm
repair: $(APP)
$(UCON) -snes -chk $(APP) 2>&1 >/dev/null
rm -rf fatfs.bak
StartupSnes.obj: StartupSnes.asm
$(AS) -V $?
@ -65,45 +62,17 @@ hook.obj: hook.asm
$(AS) -V $?
%.obj: %.c
<<<<<<< HEAD:snes/fatfstest/Makefile
$(CC) -wl -wp -sop -ML -I $(INC) $?
#$(APP): $(OBJS)
# $(LD) -HB -M21 -V -T -Pff \
# -C008000,0000 -U0000,0000 \
# -Avectors=FFE4,7FE4 \
# -Aregistration_data=FFB0,7FB0 \
# -Aressource=18000,8000 \
# -N $(OBJS) $(LIBS) -O $@
$(APP): $(OBJS) hook.obj
$(APP): $(OBJS)
echo "test"
$(LD) -B -HB -M21 -V -T -Pff \
-C3e8000,1f0000 -U000000,000000 \
-Avectors=FFE4,7FE4 \
-Aregistration_data=FFB0,7FB0 \
-Aressource=3f8000,1f8000 \
-Ahook=008000,0000 \
-N $(OBJS) hook.obj $(LIBS) -O $@
repair: $(APP)
$(UCON) -snes -chk $(APP) 2>&1 >/dev/null
rm -rf fatfs.bak
=======
$(CC) -wl -wp -sop -ML -I $(INC) $?
$(APP): $(OBJS)
$(LD) -HB -M21 -V -T -Pff \
-C3e8000,1f0000 -U000000,000000 \
-Avectors=FFE4,7FE4 \
-Aregistration_data=FFB0,7FB0 \
-Aressource=18000,8000 \
-Ahook=8000,0000 \
-N $(OBJS) $(LIBS) -O $@
ucon64 -snes -chk $(APP) 2>&1 >/dev/null
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/Makefile
-Aressource=18000,8000 \
-Ahook=008000,0000 \
-N $(OBJS) $(LIBS) -O $@
clean:
rm -vf $(APP) *.obj *.TMP
rm -vf $(APP) *.obj *.TMP

View File

@ -1,80 +1,80 @@
#include "data.h"
byte tileMapLocation[4];
word characterLocation[4];
void waitForVBlank(void) {
byte Status;
do {
Status = *(byte*)0x4210;
} while (!(Status & 0x80));
}
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber) {
tileMapLocation[bgNumber] = ((vramDst >> 8) & 0xfc) | ( screenProp & 0x03 );
*(byte*) (0x2107+bgNumber) = tileMapLocation[bgNumber];
}
void restoreTileMapLocation(byte bgNumber) {
*(byte*) (0x2107+bgNumber) = tileMapLocation[bgNumber];
}
void setCharacterLocation(word vramDst, byte bgNumber) {
characterLocation[bgNumber] = vramDst;
if(bgNumber < 2) {
*(byte*) 0x210b = (characterLocation[1] >> 8 & 0xf0 ) + (characterLocation[0] >> 12);
} else {
*(byte*) 0x210c = (characterLocation[3] >> 8 & 0xf0 ) + (characterLocation[2] >> 12);
}
}
void restoreCharacterLocation(byte bgNumber) {
setCharacterLocation(characterLocation[bgNumber], bgNumber);
}
void VRAMByteWrite(byte value, word vramDst) {
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = vramDst;
*(byte*)0x2118 = value;
}
void VRAMLoad(word src, word vramDst, word size) {
// set address in VRam for read or write ($2116) + block size transfer ($2115)
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = vramDst;
*(word*)0x4300 = 0x1801; // set DMA control register (1 word inc)
// and destination ($21xx xx -> 0x18)
*(word*)0x4302 = src; // DMA channel x source address offset
// (low $4302 and high $4303 optimisation)
*(byte*)0x4304 = 0x01; // DMA channel x source address bank
*(word*)0x4305 = size; // DMA channel x transfer size
// (low $4305 and high $4306 optimisation)
// Turn on DMA transfer for this channel
waitForVBlank();
*(byte*)0x2100 = 0x80;
*(byte*)0x420b = 0x01;
*(byte*)0x2100 = 0x00;
}
void CGRAMLoad(word src, byte cgramDst, word size) {
// set address in VRam for read or write + block size
*(byte*)0x2121 = cgramDst;
*(word*)0x4300 = 0x2200; // set DMA control register (1 byte inc)
// and destination ($21xx xx -> 022)
*(word*)0x4302 = src; // DMA channel x source address offset
// (low $4302 and high $4303 optimisation)
*(byte*)0x4304 = 0x01; // DMA channel x source address bank
*(word*)0x4305 = size; // DMA channel x transfer size
// (low $4305 and high $4306 optimisation)
// Turn on DMA transfer for this channel
waitForVBlank();
*(byte*)0x2100 = 0x80;
*(byte*)0x420b = 0x01;
*(byte*)0x2100 = 0x00;
#include "data.h"
byte tileMapLocation[4];
word characterLocation[4];
void waitForVBlank(void) {
byte Status;
do {
Status = *(byte*)0x4210;
} while (!(Status & 0x80));
}
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber) {
tileMapLocation[bgNumber] = ((vramDst >> 8) & 0xfc) | ( screenProp & 0x03 );
*(byte*) (0x2107+bgNumber) = tileMapLocation[bgNumber];
}
void restoreTileMapLocation(byte bgNumber) {
*(byte*) (0x2107+bgNumber) = tileMapLocation[bgNumber];
}
void setCharacterLocation(word vramDst, byte bgNumber) {
characterLocation[bgNumber] = vramDst;
if(bgNumber < 2) {
*(byte*) 0x210b = (characterLocation[1] >> 8 & 0xf0 ) + (characterLocation[0] >> 12);
} else {
*(byte*) 0x210c = (characterLocation[3] >> 8 & 0xf0 ) + (characterLocation[2] >> 12);
}
}
void restoreCharacterLocation(byte bgNumber) {
setCharacterLocation(characterLocation[bgNumber], bgNumber);
}
void VRAMByteWrite(byte value, word vramDst) {
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = vramDst;
*(byte*)0x2118 = value;
}
void VRAMLoad(word src, word vramDst, word size) {
// set address in VRam for read or write ($2116) + block size transfer ($2115)
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = vramDst;
*(word*)0x4300 = 0x1801; // set DMA control register (1 word inc)
// and destination ($21xx xx -> 0x18)
*(word*)0x4302 = src; // DMA channel x source address offset
// (low $4302 and high $4303 optimisation)
*(byte*)0x4304 = 0x01; // DMA channel x source address bank
*(word*)0x4305 = size; // DMA channel x transfer size
// (low $4305 and high $4306 optimisation)
// Turn on DMA transfer for this channel
waitForVBlank();
*(byte*)0x2100 = 0x80;
*(byte*)0x420b = 0x01;
*(byte*)0x2100 = 0x00;
}
void CGRAMLoad(word src, byte cgramDst, word size) {
// set address in VRam for read or write + block size
*(byte*)0x2121 = cgramDst;
*(word*)0x4300 = 0x2200; // set DMA control register (1 byte inc)
// and destination ($21xx xx -> 022)
*(word*)0x4302 = src; // DMA channel x source address offset
// (low $4302 and high $4303 optimisation)
*(byte*)0x4304 = 0x01; // DMA channel x source address bank
*(word*)0x4305 = size; // DMA channel x transfer size
// (low $4305 and high $4306 optimisation)
// Turn on DMA transfer for this channel
waitForVBlank();
*(byte*)0x2100 = 0x80;
*(byte*)0x420b = 0x01;
*(byte*)0x2100 = 0x00;
}

View File

@ -1,11 +1,11 @@
extern byte tileMapLocation[4];
extern word characterLocation[4];
void waitForVBlank(void);
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber);
void restoreTileMapLocation(byte bgNumber);
void setCharacterLocation(word vramDst, byte bgNumber);
void restoreCharacterLocation(byte bgNumber);
void VRAMByteWrite(byte value, word vramDst);
void VRAMLoad(word src, word vramDst, word size);
void CGRAMLoad(word src, byte cgramDst, word size);
extern byte tileMapLocation[4];
extern word characterLocation[4];
void waitForVBlank(void);
void setTileMapLocation(word vramDst, byte screenProp, byte bgNumber);
void restoreTileMapLocation(byte bgNumber);
void setCharacterLocation(word vramDst, byte bgNumber);
void restoreCharacterLocation(byte bgNumber);
void VRAMByteWrite(byte value, word vramDst);
void VRAMLoad(word src, word vramDst, word size);
void CGRAMLoad(word src, byte cgramDst, word size);

View File

@ -4,7 +4,9 @@
#define CMD_WRITE 0x02
#define CMD_NONE 0xff
/* Memory Map */
/*
* Memory Map
*/
#define MMIO_CMD 0x3010
#define MMIO_SECTOR01 0x3011
#define MMIO_SECTOR02 0x3012

View File

@ -1,4 +1,3 @@
word crc_update (byte *data, word size);
word crc_update_mem (unsigned long, word size);
word crc_update(byte * data, word size);
word crc_update_mem(unsigned long, word size);

View File

@ -1,8 +1,8 @@
#ifndef _DATA
typedef unsigned char byte;
typedef unsigned short word;
#define _DATA
#endif
#ifndef _DATA
typedef unsigned char byte;
typedef unsigned short word;
#define _DATA
#endif

View File

@ -1,185 +1,185 @@
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include "debug.h"
#include "data.h"
#include "pad.h"
#include "PPU.h"
#include "ressource.h"
word debugMap[0x400];
static char debug_buffer[512];
static char screen_buffer[512];
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);
VRAMLoad((word) debugMap, 0x4000, 0x0800);
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
setCharacterLocation(0x5000, (byte) 0);
*(byte*) 0x2100 = 0x0f; // enable background
// hex(24 << 10 | 24 << 5 | 24 )
// '0x6318'
*(byte*) 0x2121 = 0x00;
*(byte*) 0x2122 = 0x18;
*(byte*) 0x2122 = 0x63;
}
void clears(void) {
word i,y;
for(y=0; y<20; y++){
waitForVBlank();
for(i=0; i<32; i++){
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+i+(y*0x20);
*(byte*)0x2118 = 0;
}
}
}
void _print_char(word y,word x, char c){
waitForVBlank();
VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20)));
}
void _print_screen(word y, char *buffer){
char l;
char x = 0;
l = strlen(buffer);
waitForVBlank();
while(*buffer){
if (*buffer == '\n' ) {
while(x++<32){
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20);
*(byte*)0x2118 = 0;
}
x = 0;
y++;
buffer++;
waitForVBlank();
continue;
}
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20);
*(byte*)0x2118 = *buffer-32;
x++;
buffer++;
//waitForVBlank();
}
}
void _print_console(const char *buffer){
while(*buffer)
*(byte*) 0x3000=*buffer++;
}
void printfc(char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(debug_buffer,fmt,ap);
va_end(ap);
_print_console(debug_buffer);
//memset(debug_buffer,0,255);
}
void printfs(word y,char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(screen_buffer,fmt,ap);
va_end(ap);
_print_screen(y,screen_buffer);
memset(screen_buffer,0,255);
}
void printc_packet(unsigned long addr,unsigned int len,byte *packet){
unsigned int i,j;
unsigned int sum = 0;
unsigned int clear=0;
for (i=0;i<len;i+=16) {
sum = 0;
for (j=0;j<16;j++) {
sum +=packet[i+j];
}
if (!sum){
clear=1;
continue;
}
if (clear){
printfc("*\n");
clear = 0;
}
printfc("%lx:", addr + i);
for (j=0;j<16;j++) {
printfc(" %x", packet[i+j]);
}
printfc(" |");
for (j=0;j<16;j++) {
if (packet[i+j]>=33 && packet[i+j]<=126 )
printfc("%c", packet[i+j]);
else
printfc(".");
}
printfc("|\n");
}
}
/* 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;
}
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include "debug.h"
#include "data.h"
#include "pad.h"
#include "PPU.h"
#include "ressource.h"
word debugMap[0x400];
static char debug_buffer[512];
static char screen_buffer[512];
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);
VRAMLoad((word) debugMap, 0x4000, 0x0800);
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
setCharacterLocation(0x5000, (byte) 0);
*(byte*) 0x2100 = 0x0f; // enable background
// hex(24 << 10 | 24 << 5 | 24 )
// '0x6318'
*(byte*) 0x2121 = 0x00;
*(byte*) 0x2122 = 0x18;
*(byte*) 0x2122 = 0x63;
}
void clears(void) {
word i,y;
for(y=0; y<20; y++){
waitForVBlank();
for(i=0; i<32; i++){
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+i+(y*0x20);
*(byte*)0x2118 = 0;
}
}
}
void _print_char(word y,word x, char c){
waitForVBlank();
VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20)));
}
void _print_screen(word y, char *buffer){
char l;
char x = 0;
l = strlen(buffer);
waitForVBlank();
while(*buffer){
if (*buffer == '\n' ) {
while(x++<32){
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20);
*(byte*)0x2118 = 0;
}
x = 0;
y++;
buffer++;
waitForVBlank();
continue;
}
*(byte*)0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20);
*(byte*)0x2118 = *buffer-32;
x++;
buffer++;
//waitForVBlank();
}
}
void _print_console(const char *buffer){
while(*buffer)
*(byte*) 0x3000=*buffer++;
}
void printfc(char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(debug_buffer,fmt,ap);
va_end(ap);
_print_console(debug_buffer);
//memset(debug_buffer,0,255);
}
void printfs(word y,char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(screen_buffer,fmt,ap);
va_end(ap);
_print_screen(y,screen_buffer);
memset(screen_buffer,0,255);
}
void printc_packet(unsigned long addr,unsigned int len,byte *packet){
unsigned int i,j;
unsigned int sum = 0;
unsigned int clear=0;
for (i=0;i<len;i+=16) {
sum = 0;
for (j=0;j<16;j++) {
sum +=packet[i+j];
}
if (!sum){
clear=1;
continue;
}
if (clear){
printfc("*\n");
clear = 0;
}
printfc("%lx:", addr + i);
for (j=0;j<16;j++) {
printfc(" %x", packet[i+j]);
}
printfc(" |");
for (j=0;j<16;j++) {
if (packet[i+j]>=33 && packet[i+j]<=126 )
printfc("%c", packet[i+j]);
else
printfc(".");
}
printfc("|\n");
}
}
/* 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;
}

View File

@ -1,9 +1,8 @@
#include "data.h"
void debug_init(void);
void debug_enable(void);
void printfs(word y,char* fmt,...);
void printfc(char* fmt,...);
void clears(void);
void printc_packet(unsigned long addr,unsigned int len,byte *packet);
#include "data.h"
void debug_init(void);
void debug_enable(void);
void printfs(word y, char *fmt, ...);
void printfc(char *fmt, ...);
void clears(void);
void printc_packet(unsigned long addr, unsigned int len, byte * packet);

View File

@ -1,199 +1,199 @@
#include "integer.h"
#include "diskio.h"
#include "config.h"
#include "data.h"
#include "debug.h"
/* Interface
** Scratch Buffer
addr 3 byte
size 1 byte
** Call Interface
cmd 1 byte
sector 4 bytes
count 1 byte
return 1 byte
** Commands
* disk_init
* disk_read
* disk_write
*/
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
#include <string.h>
// TODO: Figure out gobal vars ?!?
DSTATUS Stat = 0 ; //STA_NOINIT; /* Disk status */
DSTATUS disk_initialize (BYTE drv) {
byte retval;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize called drv=%i stat=%i\n",drv,Stat);
#endif
if (drv) return STA_NOINIT; /* Supports only single drive */
Stat |= STA_NOINIT;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize stat=%i\n",Stat);
#endif
*(byte*) MMIO_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_INIT;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize poll retval\n");
#endif
while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize done Stat=%i\n",Stat);
#endif
return Stat;
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (BYTE drv){
if (drv) return STA_NOINIT; /* Supports only single drive */
return Stat;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
DWORD offset;
INT size;
byte retval;
word i;
//#ifdef MMIO_DEBUG
printfc("SNES::disk_read called sector=%li count=%i\n",sector,count);
//#endif
if (drv || !count) return RES_PARERR;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read drv ok\n");
#endif
if (Stat & STA_NOINIT) return RES_NOTRDY;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read sta ok\n");
#endif
*(byte*) MMIO_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_READ;
*(byte*) MMIO_SECTOR01 = (sector >> 24) & 0xff;
*(byte*) MMIO_SECTOR02 = (sector >> 16) & 0xff;
*(byte*) MMIO_SECTOR03 = (sector >> 8) & 0xff;
*(byte*) MMIO_SECTOR04 = (sector) & 0xff;
*(byte*) MMIO_COUNT = count;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read poll retval\n");
#endif
while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
#ifdef MMIO_DEBUG
printfc("SNES::disk_read copy buffer to %06lx\n",SHARED_ADDR);
#endif
for (i=0;i<(count*512);i++){
buff[i] = *(byte*)(SHARED_ADDR+i);
#ifdef MMIO_DEBUG
if ( i < 8)
printfc("0x%02x ",buff[i]);
#endif
}
#ifdef MMIO_DEBUG
printfc("\n");
#endif
return retval;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
DWORD offset;
INT size;
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
offset = sector * 512;
size = count * 512;
return RES_OK;
}
#endif /* _READONLY */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
#if _USE_IOCTL != 0
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
BYTE n, w, ofs, dl, dh, *ptr = (BYTE*)buff;
if (drv) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
switch (ctrl) {
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
ofs = 60; w = 2; n = 0;
break;
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
*(WORD*)buff = 512;
return RES_OK;
case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */
*(DWORD*)buff = 32;
return RES_OK;
default:
return RES_PARERR;
}
return RES_OK;
}
#endif /* _USE_IOCTL != 0 */
#include "integer.h"
#include "diskio.h"
#include "config.h"
#include "data.h"
#include "debug.h"
/* Interface
** Scratch Buffer
addr 3 byte
size 1 byte
** Call Interface
cmd 1 byte
sector 4 bytes
count 1 byte
return 1 byte
** Commands
* disk_init
* disk_read
* disk_write
*/
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
#include <string.h>
// TODO: Figure out gobal vars ?!?
DSTATUS Stat = 0 ; //STA_NOINIT; /* Disk status */
DSTATUS disk_initialize (BYTE drv) {
byte retval;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize called drv=%i stat=%i\n",drv,Stat);
#endif
if (drv) return STA_NOINIT; /* Supports only single drive */
Stat |= STA_NOINIT;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize stat=%i\n",Stat);
#endif
*(byte*) MMIO_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_INIT;
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize poll retval\n");
#endif
while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
#ifdef MMIO_DEBUG
printfc("SNES::disk_initialize done Stat=%i\n",Stat);
#endif
return Stat;
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (BYTE drv){
if (drv) return STA_NOINIT; /* Supports only single drive */
return Stat;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
DWORD offset;
INT size;
byte retval;
word i;
//#ifdef MMIO_DEBUG
printfc("SNES::disk_read called sector=%li count=%i\n",sector,count);
//#endif
if (drv || !count) return RES_PARERR;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read drv ok\n");
#endif
if (Stat & STA_NOINIT) return RES_NOTRDY;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read sta ok\n");
#endif
*(byte*) MMIO_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_READ;
*(byte*) MMIO_SECTOR01 = (sector >> 24) & 0xff;
*(byte*) MMIO_SECTOR02 = (sector >> 16) & 0xff;
*(byte*) MMIO_SECTOR03 = (sector >> 8) & 0xff;
*(byte*) MMIO_SECTOR04 = (sector) & 0xff;
*(byte*) MMIO_COUNT = count;
#ifdef MMIO_DEBUG
printfc("SNES::disk_read poll retval\n");
#endif
while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
#ifdef MMIO_DEBUG
printfc("SNES::disk_read copy buffer to %06lx\n",SHARED_ADDR);
#endif
for (i=0;i<(count*512);i++){
buff[i] = *(byte*)(SHARED_ADDR+i);
#ifdef MMIO_DEBUG
if ( i < 8)
printfc("0x%02x ",buff[i]);
#endif
}
#ifdef MMIO_DEBUG
printfc("\n");
#endif
return retval;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
DWORD offset;
INT size;
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
offset = sector * 512;
size = count * 512;
return RES_OK;
}
#endif /* _READONLY */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
#if _USE_IOCTL != 0
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
BYTE n, w, ofs, dl, dh, *ptr = (BYTE*)buff;
if (drv) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
switch (ctrl) {
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
ofs = 60; w = 2; n = 0;
break;
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
*(WORD*)buff = 512;
return RES_OK;
case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */
*(DWORD*)buff = 32;
return RES_OK;
default:
return RES_PARERR;
}
return RES_OK;
}
#endif /* _USE_IOCTL != 0 */

View File

@ -1,71 +1,83 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
/-----------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _DISKIO
#define _READONLY 0 /* 1: Read-only mode */
#define _USE_IOCTL 1
#include "integer.h"
/* Status of Disk Functions */
typedef BYTE DSTATUS;
/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
/*---------------------------------------*/
/* Prototypes for disk control functions */
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (BYTE, BYTE, void*);
void disk_timerproc (void);
/* Disk Status Bits (DSTATUS) */
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
#define STA_VOID 0xff
/* Command code for disk_ioctrl() */
/* Generic command */
#define CTRL_SYNC 0 /* Mandatory for write functions */
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
#define GET_SECTOR_SIZE 2
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
#define CTRL_POWER 4
#define CTRL_LOCK 5
#define CTRL_EJECT 6
#define _DISKIO
#endif
#ifdef __cplusplus
}
#endif
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
/-----------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _DISKIO
#define _READONLY 0 /* 1: Read-only mode */
#define _USE_IOCTL 1
#include "integer.h"
/*
* Status of Disk Functions
*/
typedef BYTE DSTATUS;
/*
* Results of Disk Functions
*/
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
/*---------------------------------------*/
/*
* Prototypes for disk control functions
*/
DSTATUS disk_initialize(BYTE);
DSTATUS disk_status(BYTE);
DRESULT disk_read(BYTE, BYTE *, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write(BYTE, const BYTE *, DWORD, BYTE);
#endif
DRESULT disk_ioctl(BYTE, BYTE, void *);
void disk_timerproc(void);
/*
* Disk Status Bits (DSTATUS)
*/
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
#define STA_VOID 0xff
/*
* Command code for disk_ioctrl()
*/
/*
* Generic command
*/
#define CTRL_SYNC 0 /* Mandatory for write functions */
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
#define GET_SECTOR_SIZE 2
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
#define CTRL_POWER 4
#define CTRL_LOCK 5
#define CTRL_EJECT 6
#define _DISKIO
#endif
#ifdef __cplusplus
}
#endif

View File

@ -1,101 +1,101 @@
#include <stdlib.h>
#include "data.h";
#include "event.h";
event *events;
void initEvents(void) {
events = NULL;
}
event *createEvent(char (*callback)(word counter)) {
event *myEvent;
myEvent = (event*) malloc(sizeof(event));
myEvent->VBlankCount = 0;
myEvent->callback = callback;
myEvent->nextEvent = NULL;
myEvent->previousEvent = NULL;
return myEvent;
}
event* addEvent(char (*callback)(word counter), int noDuplicateCallback) {
event *lastEvent;
event *myEvent;
if(events == NULL) {
events = createEvent(callback);
return events;
} else {
lastEvent = events;
// TODO optimise this with noduplicate
while(lastEvent->nextEvent != NULL) {
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL;
}
lastEvent = lastEvent->nextEvent;
}
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL;
}
myEvent = createEvent(callback);
myEvent->previousEvent = lastEvent;
lastEvent->nextEvent = myEvent;
return myEvent;
}
}
void removeEvent(event *eventElement) {
byte alone = 0;
event *next, *previous;
next = eventElement->nextEvent;
previous = eventElement->previousEvent;
if(eventElement->nextEvent != NULL && eventElement->previousEvent != NULL) {
alone++;
next->previousEvent = previous;
previous->nextEvent = next;
} else if(eventElement->nextEvent != NULL) {
alone++;
next->previousEvent = NULL;
events = next;
} else if(eventElement->previousEvent != NULL) {
alone++;
previous->nextEvent = NULL;
}
free(eventElement);
if(alone == 0) {
events = NULL;
}
}
void processEvents(void) {
event *currentEvent;
char returnValue;
currentEvent = events;
while(currentEvent != NULL) {
returnValue = currentEvent->callback(currentEvent->VBlankCount);
if(returnValue == EVENT_CONTINUE) {
currentEvent->VBlankCount++;
} else {
removeEvent(currentEvent);
}
currentEvent = currentEvent->nextEvent;
}
}
#include <stdlib.h>
#include "data.h";
#include "event.h";
event *events;
void initEvents(void) {
events = NULL;
}
event *createEvent(char (*callback)(word counter)) {
event *myEvent;
myEvent = (event*) malloc(sizeof(event));
myEvent->VBlankCount = 0;
myEvent->callback = callback;
myEvent->nextEvent = NULL;
myEvent->previousEvent = NULL;
return myEvent;
}
event* addEvent(char (*callback)(word counter), int noDuplicateCallback) {
event *lastEvent;
event *myEvent;
if(events == NULL) {
events = createEvent(callback);
return events;
} else {
lastEvent = events;
// TODO optimise this with noduplicate
while(lastEvent->nextEvent != NULL) {
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL;
}
lastEvent = lastEvent->nextEvent;
}
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL;
}
myEvent = createEvent(callback);
myEvent->previousEvent = lastEvent;
lastEvent->nextEvent = myEvent;
return myEvent;
}
}
void removeEvent(event *eventElement) {
byte alone = 0;
event *next, *previous;
next = eventElement->nextEvent;
previous = eventElement->previousEvent;
if(eventElement->nextEvent != NULL && eventElement->previousEvent != NULL) {
alone++;
next->previousEvent = previous;
previous->nextEvent = next;
} else if(eventElement->nextEvent != NULL) {
alone++;
next->previousEvent = NULL;
events = next;
} else if(eventElement->previousEvent != NULL) {
alone++;
previous->nextEvent = NULL;
}
free(eventElement);
if(alone == 0) {
events = NULL;
}
}
void processEvents(void) {
event *currentEvent;
char returnValue;
currentEvent = events;
while(currentEvent != NULL) {
returnValue = currentEvent->callback(currentEvent->VBlankCount);
if(returnValue == EVENT_CONTINUE) {
currentEvent->VBlankCount++;
} else {
removeEvent(currentEvent);
}
currentEvent = currentEvent->nextEvent;
}
}

View File

@ -1,16 +1,17 @@
typedef struct event{
word VBlankCount;
char (*callback)(word counter);
struct event *previousEvent;
struct event *nextEvent;
} event;
#define EVENT_STOP 0
#define EVENT_CONTINUE 1
extern event *events;
void initEvents(void);
extern event* addEvent(char (*callback)(word counter), int noDuplicateCallback);
extern void removeEvent(event *eventElement);
extern void processEvents(void);
typedef struct event {
word VBlankCount;
char (*callback) (word counter);
struct event *previousEvent;
struct event *nextEvent;
} event;
#define EVENT_STOP 0
#define EVENT_CONTINUE 1
extern event *events;
void initEvents(void);
extern event *addEvent(char (*callback) (word counter),
int noDuplicateCallback);
extern void removeEvent(event * eventElement);
extern void processEvents(void);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,48 @@
/*-------------------------------------------*/
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/
#ifndef _INTEGER
/* These types must be 16-bit, 32-bit or larger integer */
typedef int INT;
typedef unsigned int UINT;
/* These types must be 8-bit integer */
typedef signed char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
/* These types must be 16-bit integer */
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types must be 32-bit integer */
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
/* Boolean type */
// enum { false = 0 , true } bool;
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define _INTEGER
#endif
/*-------------------------------------------*/
/*
* Integer type definitions for FatFs module
*/
/*-------------------------------------------*/
#ifndef _INTEGER
/*
* These types must be 16-bit, 32-bit or larger integer
*/
typedef int INT;
typedef unsigned int UINT;
/*
* These types must be 8-bit integer
*/
typedef signed char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
/*
* These types must be 16-bit integer
*/
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/*
* These types must be 32-bit integer
*/
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
/*
* Boolean type
*/
// enum { false = 0 , true } bool;
typedef int BOOL;
#define FALSE 0
#define TRUE 1
#define _INTEGER
#endif

View File

@ -1,313 +1,300 @@
#include "ff.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "data.h";
#include "pad.h";
#include "event.h";
#include "myEvents.h";
#include "ressource.h";
#include "PPU.h"
#include "debug.h"
#include "crc.h"
/*
o debug STA global
o optimize internal transfer buffer
o direct write to mempage
o relocate main code
o exec loaded file
*/
//#pragma section CODE=BANK2,offset $2:0000
#define ROM_NAME "MRDO.SMC"
//#define ROM_NAME "TEST.TXT"
#define BLOCK_SIZE 512
#define BASE_ADDR 0x008000
padStatus pad1;
DWORD 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 */
DWORD p1, p2, p3;
DWORD addr;
DWORD crc_addr;
UINT crc;
BYTE res,bank;
WORD w1;
UINT s1, s2, cnt;
FATFS *fs;
DIR dir; /* Directory object */
FIL file1,file2;
void initInternalRegisters(void) {
characterLocation[0] = 0x0000;
characterLocation[1] = 0x0000;
characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000;
debug_init();
}
void preInit(void) {
// For testing purpose ...
// 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);
}
void halt(void) {
while(1);
}
void put_rc (FRESULT rc){
const char *p;
static const char str[] =
"OK\0" "NOT_READY\0" "NO_FILE\0" "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++);
}
printfc("rc=%u FR_%s\n", (WORD)rc, p);
}
FRESULT scan_files (char* path){
DIR dirs;
FRESULT res;
int i;
if ((res = f_opendir(&dirs, path)) == FR_OK) {
i = strlen(path);
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;
}
}
}
return res;
}
void wait(void){
printfc("SNES::wait: press A to continue\n");
enablePad();
//waitForVBlank();
pad1 = readPad((byte) 0);
while(!pad1.A) {
waitForVBlank();
pad1 = readPad((byte) 0);
}
printfc("SNES::wait: done\n");
//disablePad();
}
void boot(void){
#asm
jsl $008000
#endasm
}
void main(void) {
word i,j;
BYTE res;
initInternalRegisters();
*(byte*) 0x2105 = 0x01; // MODE 1 value
*(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register
*(byte*) 0x212d = 0x00; // All subPlane disable
*(byte*) 0x2100 = 0x0f; // enable background
debug_enable();
printfs(0,"FATFS OPTIXX.ORG ");
wait();
printfc("SNES::main: Try to init disk\n");
put_rc(f_mount(0, &fatfs[0]));
#if 0
printfc("SNES::main: Try to get free\n");
res = f_getfree("", &p2, &fs);
if (res)
put_rc(res);
printfc("SNES::main: printf fs results\n");
printfs(1,"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 = %lu\nDIR START LBA,CLUSTER = %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;
printfc("SNES::main: scan files\n");
res = scan_files("");
if (res)
put_rc(res);
printfs(12,"%u FILES, %lu BYTES\n%u FOLDERS\n"
"%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n",
acc_files, acc_size, acc_dirs,
(fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2));
res = f_opendir(&dir, "");
if (res)
put_rc(res);
p1 = s1 = s2 = 0;
cnt = 0;
wait();
clears();
printfc("SNES::main: read dir\n");
for(;;) {
res = f_readdir(&dir, &finfo);
if ((res != FR_OK) || !finfo.fname[0]) break;
if (finfo.fattrib & AM_DIR) {
s2++;
} else {
s1++; p1 += finfo.fsize;
}
;
printfs(cnt,"%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%s\n",
(finfo.fattrib & AM_DIR) ? 'D' : '-',
(finfo.fattrib & AM_RDO) ? 'R' : '-',
(finfo.fattrib & AM_HID) ? 'H' : '-',
(finfo.fattrib & AM_SYS) ? 'S' : '-',
(finfo.fattrib & AM_ARC) ? 'A' : '-',
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63,
finfo.fsize, &(finfo.fname[0]));
cnt+=2;
/*
printfs(cnt,"%u/%02u/%02u %02u:%02u %9lu\n%s\n",
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63,
finfo.fsize, &(finfo.fname[0]));
*/
if (cnt && cnt==20){
cnt = 0;
wait();
clears();
}
}
printfs(20,"%4u FILES\n%10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2);
if (f_getfree("", &p1, &fs) == FR_OK)
printfs(23,"%10luK BYTES FREE\n", p1 * fs->csize / 2);
wait();
clears();
#endif
printfc("SNES::main: open %s \n",ROM_NAME);
printfs(0,"OPEN %s",ROM_NAME);
put_rc(f_open(&file1, ROM_NAME, FA_READ));
p1 = 32768L * 8;
p2 = 0 ;
p3 = 0;
cnt = 0;
bank =0;
addr = BASE_ADDR;
crc_addr = BASE_ADDR;
while (p1) {
cnt = BLOCK_SIZE;
p1 -= BLOCK_SIZE;
res = f_read(&file1, (byte*)(addr) , cnt, &s2);
printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i\n",cnt,p1,p2,s2);
//printfc("SNES::main: file %x %x %x %x\n",Buff[0],Buff[1],Buff[2],Buff[3]);
if (res != FR_OK) {
printfc("SNES::main: read failed\n");
put_rc(res);
break;
}
p2 += s2;
if (cnt != s2){
printfc("SNES::main: read cnt=%i s2=%i\n",cnt,s2);
break;
}
<<<<<<< HEAD:snes/fatfstest/main.c
printfs(1,"%lu BYTES READ", p2);
=======
printfs(1 + bank,"BANK %X ADDR %LX",bank,addr);
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/main.c
/*
for (i=0; i<BLOCK_SIZE; i++){
*(byte*)(addr + i) = Buff[i];
}
*/
<<<<<<< HEAD:snes/fatfstest/main.c
printfs(2,"%i BYTES TANS %x",BLOCK_SIZE, 0x020000 + p2);
=======
printfc("SNES::main: mem %x %x %x %x %lx\n",*(byte*)(addr + 0) ,*(byte*)(addr + 1) ,*(byte*)(addr + 2) ,*(byte*)(addr + 3) ,addr);
//if (addr=0x10fe00){
printc_packet(addr,512,(byte*)(addr));
//}
addr+=s2;
if (addr%0x10000==0){
//crc = crc_update_mem(crc_addr,0x8000);
//printfc("addr=%lx crc=%x\n",crc_addr,crc);
//printfs(1 + bank,"BANK %X ADDR %LX CRC %X",bank,addr,crc);
addr+=0x8000;
//crc_addr+=0x8000;
bank++;
}
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/main.c
}
put_rc(f_close(&file1));
boot();
while(1){
wait();
}
while(1);
}
void IRQHandler(void) {
}
void NMIHandler(void) {
//processEvents();
}
#include "ff.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "data.h";
#include "pad.h";
#include "event.h";
#include "myEvents.h";
#include "ressource.h";
#include "PPU.h"
#include "debug.h"
#include "crc.h"
/*
* o debug STA global o optimize internal transfer buffer o direct write to mempage o relocate main code o exec loaded file
*/
// #pragma section CODE=BANK2,offset $2:0000
#define ROM_NAME "MRDO.SMC"
// #define ROM_NAME "TEST.TXT"
#define BLOCK_SIZE 512
#define BASE_ADDR 0x008000
padStatus pad1;
DWORD 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 */
DWORD p1,
p2,
p3;
DWORD addr;
DWORD crc_addr;
UINT crc;
BYTE res,
bank;
WORD w1;
UINT s1,
s2,
cnt;
FATFS *fs;
DIR dir; /* Directory object */
FIL file1,
file2;
void initInternalRegisters(void)
{
characterLocation[0] = 0x0000;
characterLocation[1] = 0x0000;
characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000;
debug_init();
} void
preInit(void)
{
// For testing purpose ...
// 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);
}
void halt(void)
{
while (1);
}
void put_rc(FRESULT rc)
{
const char *p;
static const char str[] =
"OK\0" "NOT_READY\0" "NO_FILE\0" "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++);
}
printfc("rc=%u FR_%s\n", (WORD) rc, p);
}
FRESULT scan_files(char *path)
{
DIR dirs;
FRESULT res;
int i;
if ((res = f_opendir(&dirs, path)) == FR_OK) {
i = strlen(path);
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;
}
}
}
return res;
}
void wait(void)
{
printfc("SNES::wait: press A to continue\n");
enablePad();
// waitForVBlank();
pad1 = readPad((byte) 0);
while (!pad1.A) {
waitForVBlank();
pad1 = readPad((byte) 0);
}
printfc("SNES::wait: done\n");
// disablePad();
}
void boot(void)
{
#asm
jsl $008000
#endasm
} void
main(void)
{
word i,
j;
BYTE res;
initInternalRegisters();
*(byte *) 0x2105 = 0x01; // MODE 1 value
*(byte *) 0x212c = 0x01; // Plane 0 (bit one) enable register
*(byte *) 0x212d = 0x00; // All subPlane disable
*(byte *) 0x2100 = 0x0f; // enable background
debug_enable();
printfs(0, "FATFS OPTIXX.ORG ");
printfc("SNES::main: Try to init disk\n");
put_rc(f_mount(0, &fatfs[0]));
#if 0
printfc("SNES::main: Try to get free\n");
res = f_getfree("", &p2, &fs);
if (res)
put_rc(res);
printfc("SNES::main: printf fs results\n");
printfs(1,
"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 = %lu\nDIR START LBA,CLUSTER = %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;
printfc("SNES::main: scan files\n");
res = scan_files("");
if (res)
put_rc(res);
printfs(12, "%u FILES, %lu BYTES\n%u FOLDERS\n"
"%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", acc_files,
acc_size, acc_dirs, (fs->max_clust - 2) * (fs->csize / 2),
p2 * (fs->csize / 2));
res = f_opendir(&dir, "");
if (res)
put_rc(res);
p1 = s1 = s2 = 0;
cnt = 0;
wait();
clears();
printfc("SNES::main: read dir\n");
for (;;) {
res = f_readdir(&dir, &finfo);
if ((res != FR_OK) || !finfo.fname[0])
break;
if (finfo.fattrib & AM_DIR) {
s2++;
} else {
s1++;
p1 += finfo.fsize;
}
;
printfs(cnt, "%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%s\n",
(finfo.fattrib & AM_DIR) ? 'D' : '-',
(finfo.fattrib & AM_RDO) ? 'R' : '-',
(finfo.fattrib & AM_HID) ? 'H' : '-',
(finfo.fattrib & AM_SYS) ? 'S' : '-',
(finfo.fattrib & AM_ARC) ? 'A' : '-',
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15,
finfo.fdate & 31, (finfo.ftime >> 11),
(finfo.ftime >> 5) & 63, finfo.fsize, &(finfo.fname[0]));
cnt += 2;
/*
* printfs(cnt,"%u/%02u/%02u %02u:%02u %9lu\n%s\n", (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
* (finfo.ftime >> 11), (finfo.ftime >> 5) & 63, finfo.fsize, &(finfo.fname[0]));
*/
if (cnt && cnt == 20) {
cnt = 0;
wait();
clears();
}
}
printfs(20, "%4u FILES\n%10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2);
if (f_getfree("", &p1, &fs) == FR_OK)
printfs(23, "%10luK BYTES FREE\n", p1 * fs->csize / 2);
wait();
clears();
#endif /* */
printfc("SNES::main: open %s \n", ROM_NAME);
printfs(0, "OPEN %s", ROM_NAME);
put_rc(f_open(&file1, ROM_NAME, FA_READ));
p1 = 32768L * 8;
p2 = 0;
p3 = 0;
cnt = 0;
bank = 0;
addr = BASE_ADDR;
crc_addr = BASE_ADDR;
while (p1) {
cnt = BLOCK_SIZE;
p1 -= BLOCK_SIZE;
res = f_read(&file1, (byte *) (addr), cnt, &s2);
printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i\n", cnt,
p1, p2, s2);
// printfc("SNES::main: file %x %x %x
// %x\n",Buff[0],Buff[1],Buff[2],Buff[3]);
if (res != FR_OK) {
printfc("SNES::main: read failed\n");
put_rc(res);
break;
}
p2 += s2;
if (cnt != s2) {
printfc("SNES::main: read cnt=%i s2=%i\n", cnt, s2);
break;
}
printfs(1 + bank, "BANK %X ADDR %LX", bank, addr);
/*
* for (i=0; i<BLOCK_SIZE; i++){ *(byte*)(addr + i) = Buff[i]; }
*/
printfc("SNES::main: mem %x %x %x %x %lx\n",
*(byte *) (addr + 0), *(byte *) (addr + 1),
*(byte *) (addr + 2), *(byte *) (addr + 3), addr);
// if (addr=0x10fe00){
printc_packet(addr, 512, (byte *) (addr));
// }
addr += s2;
if (addr % 0x10000 == 0) {
// crc = crc_update_mem(crc_addr,0x8000);
// printfc("addr=%lx crc=%x\n",crc_addr,crc);
// printfs(1 + bank,"BANK %X ADDR %LX CRC
// %X",bank,addr,crc);
addr += 0x8000;
// crc_addr+=0x8000;
bank++;
}
}
put_rc(f_close(&file1));
boot();
while (1) {
wait();
}
while (1);
}
void IRQHandler(void)
{
} void
NMIHandler(void)
{
// processEvents();
}

View File

@ -1,97 +1,97 @@
#include "data.h";
#include "pad.h";
#include "event.h";
extern padStatus pad1;
extern word scrollValue;
char fadeOut(word counter) {
static byte fadeOutValue;
if(counter == 0) {
// init fade value
fadeOutValue = 0x0f;
} else {
fadeOutValue--;
}
*(byte*) 0x2100 = fadeOutValue;
if(fadeOutValue == 0x00) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char fadeIn(word counter) {
static byte fadeInValue;
if(counter == 0) {
// init fade value
fadeInValue = 0x00;
} else {
fadeInValue++;
}
*(byte*) 0x2100 = fadeInValue;
if(fadeInValue >= 0x0f) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char mosaicOut(word counter) {
static byte mosaicOutValue;
if(counter == 0) {
// init fade value
mosaicOutValue = 0xff;
} else {
mosaicOutValue -= 0x10;
}
*(byte*) 0x2106 = mosaicOutValue;
if(mosaicOutValue == 0x0f) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char mosaicIn(word counter) {
static byte mosaicInValue;
if(counter == 0) {
// init fade value
mosaicInValue = 0x0f;
} else {
mosaicInValue += 0x10;
}
*(byte*) 0x2106 = mosaicInValue;
if(mosaicInValue == 0xff) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char NMIReadPad(word counter) {
pad1 = readPad((byte) 0);
return EVENT_CONTINUE;
}
char scrollLeft(word counter) {
scrollValue++;
*(byte*) 0x210d = (byte) scrollValue;
*(byte*) 0x210d = (byte) (scrollValue>>8);
return EVENT_CONTINUE;
#include "data.h";
#include "pad.h";
#include "event.h";
extern padStatus pad1;
extern word scrollValue;
char fadeOut(word counter) {
static byte fadeOutValue;
if(counter == 0) {
// init fade value
fadeOutValue = 0x0f;
} else {
fadeOutValue--;
}
*(byte*) 0x2100 = fadeOutValue;
if(fadeOutValue == 0x00) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char fadeIn(word counter) {
static byte fadeInValue;
if(counter == 0) {
// init fade value
fadeInValue = 0x00;
} else {
fadeInValue++;
}
*(byte*) 0x2100 = fadeInValue;
if(fadeInValue >= 0x0f) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char mosaicOut(word counter) {
static byte mosaicOutValue;
if(counter == 0) {
// init fade value
mosaicOutValue = 0xff;
} else {
mosaicOutValue -= 0x10;
}
*(byte*) 0x2106 = mosaicOutValue;
if(mosaicOutValue == 0x0f) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char mosaicIn(word counter) {
static byte mosaicInValue;
if(counter == 0) {
// init fade value
mosaicInValue = 0x0f;
} else {
mosaicInValue += 0x10;
}
*(byte*) 0x2106 = mosaicInValue;
if(mosaicInValue == 0xff) {
return EVENT_STOP;
} else {
return EVENT_CONTINUE;
}
}
char NMIReadPad(word counter) {
pad1 = readPad((byte) 0);
return EVENT_CONTINUE;
}
char scrollLeft(word counter) {
scrollValue++;
*(byte*) 0x210d = (byte) scrollValue;
*(byte*) 0x210d = (byte) (scrollValue>>8);
return EVENT_CONTINUE;
}

View File

@ -1,6 +1,6 @@
char fadeOut(word counter);
char fadeIn(word counter);
char mosaicOut(word counter);
char mosaicIn(word counter);
char NMIReadPad(word counter);
char scrollLeft(word counter);
char fadeOut(word counter);
char fadeIn(word counter);
char mosaicOut(word counter);
char mosaicIn(word counter);
char NMIReadPad(word counter);
char scrollLeft(word counter);

View File

@ -1,23 +1,23 @@
#include "data.h";
#include "pad.h";
#include "debug.h";
void enablePad(void) {
// Enable pad reading and NMI
*(byte*)0x4200 = 0x01;
}
void disablePad(void) {
// Enable pad reading and NMI
*(byte*)0x4200 = 0x00;
}
padStatus readPad(byte padNumber) {
word test;
padStatus *status;
padNumber = padNumber << 1;
test = (word) *(byte*)0x4218+padNumber << 8;
test |= (word) *(byte*)0x4219+padNumber;
status = (padStatus *) &test;
return *status;
}
#include "data.h";
#include "pad.h";
#include "debug.h";
void enablePad(void) {
// Enable pad reading and NMI
*(byte*)0x4200 = 0x01;
}
void disablePad(void) {
// Enable pad reading and NMI
*(byte*)0x4200 = 0x00;
}
padStatus readPad(byte padNumber) {
word test;
padStatus *status;
padNumber = padNumber << 1;
test = (word) *(byte*)0x4218+padNumber << 8;
test |= (word) *(byte*)0x4219+padNumber;
status = (padStatus *) &test;
return *status;
}

View File

@ -1,20 +1,20 @@
typedef struct padStatus{
byte right:1;
byte left:1;
byte down:1;
byte up:1;
byte start:1; // Enter
byte select:1; // Space
byte Y:1; // X
byte B:1; // C
//--------------------------------
byte Dummy:4;
byte R:1; // Z
byte L:1; // A
byte X:1; // S
byte A:1; // D
} padStatus;
extern void enablePad(void);
extern void disablePad(void);
extern padStatus readPad(byte padNumber);
typedef struct padStatus {
byte right:1;
byte left:1;
byte down:1;
byte up:1;
byte start:1; // Enter
byte select:1; // Space
byte Y:1; // X
byte B:1; // C
// --------------------------------
byte Dummy:4;
byte R:1; // Z
byte L:1; // A
byte X:1; // S
byte A:1; // D
} padStatus;
extern void enablePad(void);
extern void disablePad(void);
extern padStatus readPad(byte padNumber);

View File

@ -1,2 +1,2 @@
extern word debugFont_pic[];
extern word debugFont_pic[];