addd bugs, clean code

This commit is contained in:
david 2009-06-10 16:30:46 +02:00
parent 4ea1912318
commit 1100333487
12 changed files with 3042 additions and 2513 deletions

View File

@ -0,0 +1,22 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: relocate code
desc: |-
move main code to upper page like 0xe4 and use 0x4f as shared mem window
or even combine this
code seems to reloacte and start, but ram doesn't seem accessable. broked
sprintfs
type: :bugfix
component: fatfs
release:
reporter: David <david@optixx.org>
status: :unstarted
disposition:
creation_time: 2009-06-10 14:22:10.400739 Z
references: []
id: 032fab33a68ffbeb19f1e9fa4856101996759255
log_events:
- - 2009-06-10 14:22:11.288638 Z
- David <david@optixx.org>
- created
- ""

View File

@ -0,0 +1,21 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: "debug ram mapping "
desc: |-
global vars seem to be borked or miss used. seems all kind of buffers are overlapping
just reordering global var order renders the code unusable.
also the strange sprintf buffer conflicts seem to related to this issue
type: :bugfix
component: fatfs
release:
reporter: David <david@optixx.org>
status: :unstarted
disposition:
creation_time: 2009-06-10 14:23:44.121219 Z
references: []
id: 6498cae9de5e51829e5dbb6b8fcaa20c7a647aa6
log_events:
- - 2009-06-10 14:23:45.632999 Z
- David <david@optixx.org>
- created
- ""

View File

@ -0,0 +1,20 @@
--- !ditz.rubyforge.org,2008-03-06/issue
title: debug sta return val
desc: |-
debug the sta value in diskio.c
never seems to take the correct value, looks like global,local scope problem
type: :bugfix
component: fatfs
release:
reporter: David <david@optixx.org>
status: :unstarted
disposition:
creation_time: 2009-06-10 14:20:20.608109 Z
references: []
id: 99ae09d1da472e76501325424bc586f78980199e
log_events:
- - 2009-06-10 14:20:24.343929 Z
- David <david@optixx.org>
- created
- ""

View File

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

View File

@ -1,14 +1,14 @@
#include "data.h" #include "data.h"
word crc_update (char far *data, word size) word crc_update(char far * data, word size)
{ {
word i; word i;
word j; word j;
word crc=0; word crc = 0;
for (j=0; j<size; j++){ for (j = 0; j < size; j++) {
crc = crc ^ ((word)data[j]<< 8); crc = crc ^ ((word) data[j] << 8);
for (i=0; i<8; i++){ for (i = 0; i < 8; i++) {
if (crc & 0x8000) if (crc & 0x8000)
crc = (crc << 1) ^ 0x1021; crc = (crc << 1) ^ 0x1021;
else else
@ -19,14 +19,14 @@ word crc_update (char far *data, word size)
} }
word crc_update_mem (unsigned long addr, word size) word crc_update_mem(unsigned long addr, word size)
{ {
word i; word i;
word j; word j;
word crc=0; word crc = 0;
for (j=0; j<size; j++){ for (j = 0; j < size; j++) {
crc = crc ^ ((word) *(byte*)(addr+j)<< 8); crc = crc ^ ((word) * (byte *) (addr + j) << 8);
for (i=0; i<8; i++){ for (i = 0; i < 8; i++) {
if (crc & 0x8000) if (crc & 0x8000)
crc = (crc << 1) ^ 0x1021; crc = (crc << 1) ^ 0x1021;
else else

View File

@ -17,69 +17,74 @@ static char debug_buffer[512];
static char screen_buffer[512]; static char screen_buffer[512];
void debug_init(void) { void debug_init(void)
{
word i; word i;
for(i=0; i<0x400; i++) { for (i = 0; i < 0x400; i++) {
debugMap[i] = 0x00; debugMap[i] = 0x00;
} }
memset(debug_buffer,0,255); memset(debug_buffer, 0, 255);
} }
void debug_enable(void){ void debug_enable(void)
{
VRAMLoad((word) debugFont_pic, 0x5000, 2048); VRAMLoad((word) debugFont_pic, 0x5000, 2048);
VRAMLoad((word) debugMap, 0x4000, 0x0800); VRAMLoad((word) debugMap, 0x4000, 0x0800);
setTileMapLocation(0x4000, (byte) 0x00, (byte) 0); setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
setCharacterLocation(0x5000, (byte) 0); setCharacterLocation(0x5000, (byte) 0);
*(byte*) 0x2100 = 0x0f; // enable background *(byte *) 0x2100 = 0x0f; // enable background
// Font Color // Font Color
// hex(24 << 10 | 24 << 5 | 24 ) = '0x6318' // hex(24 << 10 | 24 << 5 | 24 ) = '0x6318'
*(byte*) 0x2121 = 0x02; *(byte *) 0x2121 = 0x02;
*(byte*) 0x2122 = 0xff; *(byte *) 0x2122 = 0xff;
*(byte*) 0x2122 = 0x7f; *(byte *) 0x2122 = 0x7f;
// Font Border Color // Font Border Color
*(byte*) 0x2121 = 0x00; *(byte *) 0x2121 = 0x00;
*(byte*) 0x2122 = 0x00; *(byte *) 0x2122 = 0x00;
*(byte*) 0x2122 = 0x00; *(byte *) 0x2122 = 0x00;
// Background Color // Background Color
*(byte*) 0x2121 = 0x01; *(byte *) 0x2121 = 0x01;
*(byte*) 0x2122 = 0x05; *(byte *) 0x2122 = 0x05;
*(byte*) 0x2122 = 0x29; *(byte *) 0x2122 = 0x29;
} }
void clears(void) { void clears(void)
word i,y; {
for(y=0; y<20; y++){ word i, y;
for (y = 0; y < 20; y++) {
waitForVBlank(); waitForVBlank();
for(i=0; i<32; i++){ for (i = 0; i < 32; i++) {
*(byte*)0x2115 = 0x80; *(byte *) 0x2115 = 0x80;
*(word*)0x2116 = 0x4000+i+(y*0x20); *(word *) 0x2116 = 0x4000 + i + (y * 0x20);
*(byte*)0x2118 = 0; *(byte *) 0x2118 = 0;
} }
} }
} }
void _print_char(word y,word x, char c){ void _print_char(word y, word x, char c)
{
waitForVBlank(); waitForVBlank();
VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20))); VRAMByteWrite((byte) (c - 32), (word) (0x4000 + x + (y * 0x20)));
} }
void _print_screen(word y, char *buffer){ void _print_screen(word y, char *buffer)
{
char l; char l;
char x = 0; char x = 0;
l = strlen(buffer); l = strlen(buffer);
waitForVBlank(); waitForVBlank();
while(*buffer){ while (*buffer) {
if (*buffer == '\n' ) { if (*buffer == '\n') {
while(x++<32){ while (x++ < 32) {
*(byte*)0x2115 = 0x80; *(byte *) 0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20); *(word *) 0x2116 = 0x4000 + x + (y * 0x20);
*(byte*)0x2118 = 0; *(byte *) 0x2118 = 0;
} }
x = 0; x = 0;
y++; y++;
@ -87,9 +92,9 @@ void _print_screen(word y, char *buffer){
waitForVBlank(); waitForVBlank();
continue; continue;
} }
*(byte*)0x2115 = 0x80; *(byte *) 0x2115 = 0x80;
*(word*)0x2116 = 0x4000+x+(y*0x20); *(word *) 0x2116 = 0x4000 + x + (y * 0x20);
*(byte*)0x2118 = *buffer-32; *(byte *) 0x2118 = *buffer - 32;
x++; x++;
buffer++; buffer++;
#if 0 #if 0
@ -97,60 +102,64 @@ void _print_screen(word y, char *buffer){
#endif #endif
} }
} }
void _print_console(const char *buffer){ void _print_console(const char *buffer)
while(*buffer) {
*(byte*) 0x3000=*buffer++; while (*buffer)
*(byte *) 0x3000 = *buffer++;
} }
void printfc(const char *fmt,...){ void printfc(const char *fmt, ...)
{
va_list ap; va_list ap;
va_start(ap,fmt); va_start(ap, fmt);
vsprintf(debug_buffer,fmt,ap); vsprintf(debug_buffer, fmt, ap);
va_end(ap); va_end(ap);
_print_console(debug_buffer); _print_console(debug_buffer);
//memset(debug_buffer,0,255); // memset(debug_buffer,0,255);
} }
void printfs(word y,const char *fmt,...){ void printfs(word y, const char *fmt, ...)
{
va_list ap; va_list ap;
va_start(ap,fmt); va_start(ap, fmt);
vsprintf(screen_buffer,fmt,ap); vsprintf(screen_buffer, fmt, ap);
va_end(ap); va_end(ap);
_print_screen(y,screen_buffer); _print_screen(y, screen_buffer);
memset(screen_buffer,0,255); memset(screen_buffer, 0, 255);
} }
void printc_packet(unsigned long addr,unsigned int len,byte *packet){ void printc_packet(unsigned long addr, unsigned int len, byte * packet)
unsigned int i,j; {
unsigned int i, j;
unsigned int sum = 0; unsigned int sum = 0;
unsigned int clear=0; unsigned int clear = 0;
for (i=0;i<len;i+=16) { for (i = 0; i < len; i += 16) {
sum = 0; sum = 0;
for (j=0;j<16;j++) { for (j = 0; j < 16; j++) {
sum +=packet[i+j]; sum += packet[i + j];
} }
if (!sum){ if (!sum) {
clear=1; clear = 1;
continue; continue;
} }
if (clear){ if (clear) {
printfc("*\n"); printfc("*\n");
clear = 0; clear = 0;
} }
printfc("%lx:", addr + i); printfc("%lx:", addr + i);
for (j=0;j<16;j++) { for (j = 0; j < 16; j++) {
printfc(" %x", packet[i+j]); printfc(" %x", packet[i + j]);
} }
printfc(" |"); printfc(" |");
for (j=0;j<16;j++) { for (j = 0; j < 16; j++) {
if (packet[i+j]>=33 && packet[i+j]<=126 ) if (packet[i + j] >= 33 && packet[i + j] <= 126)
printfc("%c", packet[i+j]); printfc("%c", packet[i + j]);
else else
printfc("."); printfc(".");
} }
@ -158,40 +167,48 @@ void printc_packet(unsigned long addr,unsigned int len,byte *packet){
} }
} }
/* keep the linker happy */ /*
int open(const char * _name, int _mode){ * keep the linker happy
*/
int open(const char *_name, int _mode)
{
_print_console("open called\n"); _print_console("open called\n");
return -1; return -1;
} }
int close(int fd){ int close(int fd)
{
_print_console("close called\n"); _print_console("close called\n");
return -1; return -1;
} }
size_t read(int fd, void * buff, size_t len){ size_t read(int fd, void *buff, size_t len)
{
_print_console("read called\n"); _print_console("read called\n");
return 0; return 0;
} }
size_t write(int fd, void * buffer, size_t len){ size_t write(int fd, void *buffer, size_t len)
{
_print_console("write called\n"); _print_console("write called\n");
return 0; return 0;
} }
long lseek(int fd, long off, int count){ long lseek(int fd, long off, int count)
{
_print_console("lseek called\n"); _print_console("lseek called\n");
return 0; return 0;
} }
int unlink(const char * name){ int unlink(const char *name)
{
_print_console("unlink called\n"); _print_console("unlink called\n");
return -1; return -1;
} }
int isatty(){ int isatty()
{
_print_console("isatty called\n"); _print_console("isatty called\n");
return 1; return 1;
} }

View File

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

View File

@ -5,14 +5,16 @@
event *events; event *events;
void initEvents(void) { void initEvents(void)
{
events = NULL; events = NULL;
} }
event *createEvent(char (*callback)(word counter)) { event *createEvent(char (*callback) (word counter))
{
event *myEvent; event *myEvent;
myEvent = (event*) malloc(sizeof(event)); myEvent = (event *) malloc(sizeof(event));
myEvent->VBlankCount = 0; myEvent->VBlankCount = 0;
myEvent->callback = callback; myEvent->callback = callback;
@ -23,24 +25,25 @@ event *createEvent(char (*callback)(word counter)) {
return myEvent; return myEvent;
} }
event* addEvent(char (*callback)(word counter), int noDuplicateCallback) { event *addEvent(char (*callback) (word counter), int noDuplicateCallback)
{
event *lastEvent; event *lastEvent;
event *myEvent; event *myEvent;
if(events == NULL) { if (events == NULL) {
events = createEvent(callback); events = createEvent(callback);
return events; return events;
} else { } else {
lastEvent = events; lastEvent = events;
// TODO optimise this with noduplicate // TODO optimise this with noduplicate
while(lastEvent->nextEvent != NULL) { while (lastEvent->nextEvent != NULL) {
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) { if (noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL; return NULL;
} }
lastEvent = lastEvent->nextEvent; lastEvent = lastEvent->nextEvent;
} }
if(noDuplicateCallback == 1 && lastEvent->callback == *callback) { if (noDuplicateCallback == 1 && lastEvent->callback == *callback) {
return NULL; return NULL;
} }
myEvent = createEvent(callback); myEvent = createEvent(callback);
@ -52,7 +55,8 @@ event* addEvent(char (*callback)(word counter), int noDuplicateCallback) {
} }
void removeEvent(event *eventElement) { void removeEvent(event * eventElement)
{
byte alone = 0; byte alone = 0;
event *next, *previous; event *next, *previous;
@ -60,37 +64,38 @@ void removeEvent(event *eventElement) {
next = eventElement->nextEvent; next = eventElement->nextEvent;
previous = eventElement->previousEvent; previous = eventElement->previousEvent;
if(eventElement->nextEvent != NULL && eventElement->previousEvent != NULL) { if (eventElement->nextEvent != NULL && eventElement->previousEvent != NULL) {
alone++; alone++;
next->previousEvent = previous; next->previousEvent = previous;
previous->nextEvent = next; previous->nextEvent = next;
} else if(eventElement->nextEvent != NULL) { } else if (eventElement->nextEvent != NULL) {
alone++; alone++;
next->previousEvent = NULL; next->previousEvent = NULL;
events = next; events = next;
} else if(eventElement->previousEvent != NULL) { } else if (eventElement->previousEvent != NULL) {
alone++; alone++;
previous->nextEvent = NULL; previous->nextEvent = NULL;
} }
free(eventElement); free(eventElement);
if(alone == 0) { if (alone == 0) {
events = NULL; events = NULL;
} }
} }
void processEvents(void) { void processEvents(void)
{
event *currentEvent; event *currentEvent;
char returnValue; char returnValue;
currentEvent = events; currentEvent = events;
while(currentEvent != NULL) { while (currentEvent != NULL) {
returnValue = currentEvent->callback(currentEvent->VBlankCount); returnValue = currentEvent->callback(currentEvent->VBlankCount);
if(returnValue == EVENT_CONTINUE) { if (returnValue == EVENT_CONTINUE) {
currentEvent->VBlankCount++; currentEvent->VBlankCount++;
} else { } else {
removeEvent(currentEvent); removeEvent(currentEvent);

File diff suppressed because it is too large Load Diff

View File

@ -13,18 +13,6 @@
#include "debug.h" #include "debug.h"
#include "crc.h" #include "crc.h"
/*
o relocate main code
o exec loaded file
o debug STA global
o optimize internal transfer buffer
o direct writeto mempage
*/
#define ROM_NAME "TURRICAN.SMC" #define ROM_NAME "TURRICAN.SMC"
#define BLOCK_SIZE 512 #define BLOCK_SIZE 512
@ -32,14 +20,14 @@ o direct writeto mempage
#define BANK_COUNT 16 #define BANK_COUNT 16
#define BASE_ADDR 0x008000 #define BASE_ADDR 0x008000
typedef void (*FUNC)(void); typedef void (*FUNC) (void);
padStatus pad1; padStatus pad1;
DWORD acc_size; /* Work register for fs command */ DWORD acc_size; /* Work register for fs command */
WORD acc_files, acc_dirs; WORD acc_files, acc_dirs;
FILINFO finfo; FILINFO finfo;
FATFS fatfs[2]; /* File system object for each logical * drive */ FATFS fatfs[2]; /* File system object for each logical * drive */
//BYTE Buff[512]; /* Working buffer */ // BYTE Buff[512]; /* Working buffer */
DWORD p1, p2, p3; DWORD p1, p2, p3;
DWORD addr; DWORD addr;
DWORD crc_addr; DWORD crc_addr;
@ -57,7 +45,9 @@ void initInternalRegisters(void)
characterLocation[2] = 0x0000; characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000; characterLocation[3] = 0x0000;
debug_init(); debug_init();
} void preInit(void) }
void preInit(void)
{ {
// For testing purpose ... // For testing purpose ...
@ -137,7 +127,7 @@ void wait(void)
void boot(DWORD addr) void boot(DWORD addr)
{ {
FUNC fn; FUNC fn;
printfc("SNES::boot addr=%lx\n",addr); printfc("SNES::boot addr=%lx\n", addr);
fn = (FUNC) addr; fn = (FUNC) addr;
fn(); fn();
@ -153,7 +143,7 @@ void boot(DWORD addr)
debug_enable(); debug_enable();
printfc("SNES::main: Try to init disk\n"); printfc("SNES::main: Try to init disk\n");
put_rc(f_mount((BYTE)0, &fatfs[0])); put_rc(f_mount((BYTE) 0, &fatfs[0]));
printfs(0, "FATFS OPTIXX.ORG "); printfs(0, "FATFS OPTIXX.ORG ");
printfc("SNES::main: Try to get free\n"); printfc("SNES::main: Try to get free\n");
@ -228,7 +218,7 @@ void boot(DWORD addr)
printfc("SNES::main: open %s \n", ROM_NAME); printfc("SNES::main: open %s \n", ROM_NAME);
printfs(0, "OPEN %s", ROM_NAME); printfs(0, "OPEN %s", ROM_NAME);
put_rc(f_open(&file1, ROM_NAME, (BYTE)FA_READ)); put_rc(f_open(&file1, ROM_NAME, (BYTE) FA_READ));
p1 = BANK_SIZE * BANK_COUNT; p1 = BANK_SIZE * BANK_COUNT;
p2 = 0; p2 = 0;
p3 = 0; p3 = 0;
@ -252,7 +242,6 @@ void boot(DWORD addr)
printfc("SNES::main: read cnt=%i s2=%i\n", cnt, s2); printfc("SNES::main: read cnt=%i s2=%i\n", cnt, s2);
break; break;
} }
#if 0 #if 0
printc_packet(addr, 512, (byte *) (addr)); printc_packet(addr, 512, (byte *) (addr));
wait(); wait();
@ -264,9 +253,9 @@ void boot(DWORD addr)
printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i \n", cnt, printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i \n", cnt,
p1, p2, s2); p1, p2, s2);
#if 0 #if 0
crc = crc_update_mem(crc_addr,0x8000); crc = crc_update_mem(crc_addr, 0x8000);
printfc("SNES::main: crc_addr=%lx crc=%x\n",crc_addr,crc); printfc("SNES::main: crc_addr=%lx crc=%x\n", crc_addr, crc);
crc_addr+=0x8000; crc_addr += 0x8000;
#endif #endif
printfs((1 + bank), "BANK %i ADDR 0X%lx ", bank, addr); printfs((1 + bank), "BANK %i ADDR 0X%lx ", bank, addr);
@ -275,9 +264,9 @@ void boot(DWORD addr)
} }
} }
put_rc(f_close(&file1)); put_rc(f_close(&file1));
addr = *(byte *)0xFFFD; addr = *(byte *) 0xFFFD;
addr = addr << 8; addr = addr << 8;
addr |= (*(byte *)0xFFFC); addr |= (*(byte *) 0xFFFC);
boot(addr); boot(addr);
while (1) { while (1) {
wait(); wait();
@ -287,7 +276,9 @@ void boot(DWORD addr)
void IRQHandler(void) void IRQHandler(void)
{ {
} void NMIHandler(void) }
void NMIHandler(void)
{ {
// processEvents(); // processEvents();

View File

@ -5,93 +5,99 @@
extern padStatus pad1; extern padStatus pad1;
extern word scrollValue; extern word scrollValue;
char fadeOut(word counter) { char fadeOut(word counter)
{
static byte fadeOutValue; static byte fadeOutValue;
if(counter == 0) { if (counter == 0) {
// init fade value // init fade value
fadeOutValue = 0x0f; fadeOutValue = 0x0f;
} else { } else {
fadeOutValue--; fadeOutValue--;
} }
*(byte*) 0x2100 = fadeOutValue; *(byte *) 0x2100 = fadeOutValue;
if(fadeOutValue == 0x00) { if (fadeOutValue == 0x00) {
return EVENT_STOP; return EVENT_STOP;
} else { } else {
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }
} }
char fadeIn(word counter) { char fadeIn(word counter)
{
static byte fadeInValue; static byte fadeInValue;
if(counter == 0) { if (counter == 0) {
// init fade value // init fade value
fadeInValue = 0x00; fadeInValue = 0x00;
} else { } else {
fadeInValue++; fadeInValue++;
} }
*(byte*) 0x2100 = fadeInValue; *(byte *) 0x2100 = fadeInValue;
if(fadeInValue >= 0x0f) { if (fadeInValue >= 0x0f) {
return EVENT_STOP; return EVENT_STOP;
} else { } else {
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }
} }
char mosaicOut(word counter) { char mosaicOut(word counter)
{
static byte mosaicOutValue; static byte mosaicOutValue;
if(counter == 0) { if (counter == 0) {
// init fade value // init fade value
mosaicOutValue = 0xff; mosaicOutValue = 0xff;
} else { } else {
mosaicOutValue -= 0x10; mosaicOutValue -= 0x10;
} }
*(byte*) 0x2106 = mosaicOutValue; *(byte *) 0x2106 = mosaicOutValue;
if(mosaicOutValue == 0x0f) { if (mosaicOutValue == 0x0f) {
return EVENT_STOP; return EVENT_STOP;
} else { } else {
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }
} }
char mosaicIn(word counter) { char mosaicIn(word counter)
{
static byte mosaicInValue; static byte mosaicInValue;
if(counter == 0) { if (counter == 0) {
// init fade value // init fade value
mosaicInValue = 0x0f; mosaicInValue = 0x0f;
} else { } else {
mosaicInValue += 0x10; mosaicInValue += 0x10;
} }
*(byte*) 0x2106 = mosaicInValue; *(byte *) 0x2106 = mosaicInValue;
if(mosaicInValue == 0xff) { if (mosaicInValue == 0xff) {
return EVENT_STOP; return EVENT_STOP;
} else { } else {
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }
} }
char NMIReadPad(word counter) { char NMIReadPad(word counter)
{
pad1 = readPad((byte) 0); pad1 = readPad((byte) 0);
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }
char scrollLeft(word counter) { char scrollLeft(word counter)
{
scrollValue++; scrollValue++;
*(byte*) 0x210d = (byte) scrollValue; *(byte *) 0x210d = (byte) scrollValue;
*(byte*) 0x210d = (byte) (scrollValue>>8); *(byte *) 0x210d = (byte) (scrollValue >> 8);
return EVENT_CONTINUE; return EVENT_CONTINUE;
} }

View File

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