o cleanup code

o get ls working
This commit is contained in:
david 2009-06-03 18:24:18 +02:00
parent 3ecc61adf4
commit 0a50554f4a
7 changed files with 105 additions and 40 deletions

View File

@ -2,6 +2,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <fcntl.h> #include <fcntl.h>
#include "debug.h"
#include "data.h" #include "data.h"
#include "pad.h" #include "pad.h"
#include "PPU.h" #include "PPU.h"
@ -10,7 +11,27 @@
word debugMap[0x400]; word debugMap[0x400];
static char debug_buffer[255]; static char debug_buffer[255];
static char screen_buffer[255];
word col[] = {
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
0x03ff,
};
void debug_init(void) { void debug_init(void) {
word i; word i;
@ -31,7 +52,16 @@ void debug_enable(void){
} }
void _print_char(word y,word x, unsigned char c){ void clears(void) {
word x,y;
for(y=0; y<16; y++)
for(x=0; x<32; x++)
VRAMByteWrite((byte) (' '-32), (word) (0x4000+x+(y*0x20)));
}
void _print_char(word y,word x, char c){
waitForVBlank();
VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20))); VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20)));
} }
@ -41,23 +71,42 @@ void _print_screen(word y, char *buffer){
l = strlen(buffer); l = strlen(buffer);
waitForVBlank(); waitForVBlank();
while(*buffer){ while(*buffer){
if (*buffer == '\n' ) { if (*buffer == '\n' ) {
while(x++<32) while(x++<32)
_print_char(y,x,' '); _print_char(y,x,' ');
x = 0; x = 0;
y++; y++;
} buffer++;
_print_char(y,x,*buffer); continue;
x++; }
buffer++; _print_char(y,x,*buffer);
x++;
buffer++;
} }
} }
void _print_console(const char *buffer){ void _print_console(const char *buffer){
while(*buffer) while(*buffer)
*(byte*) 0x3000=*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);
}
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);
}
/* keep the linker happy */ /* keep the linker happy */
int open(const char * _name, int _mode){ int open(const char * _name, int _mode){
_print_console("open called\n"); _print_console("open called\n");
@ -94,18 +143,4 @@ int isatty(){
_print_console("isatty called\n"); _print_console("isatty called\n");
return 1; return 1;
} }
void printfc(char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(debug_buffer,fmt,ap);
va_end(ap);
_print_console(debug_buffer);
}
void printfs(word y,char *fmt,...){
va_list ap;
va_start(ap,fmt);
vsprintf(debug_buffer,fmt,ap);
va_end(ap);
_print_screen(y,debug_buffer);
}

View File

@ -4,4 +4,5 @@ void debug_init(void);
void debug_enable(void); void debug_enable(void);
void printfs(word y,char* fmt,...); void printfs(word y,char* fmt,...);
void printfc(char* fmt,...); void printfc(char* fmt,...);
void clears(void);

View File

@ -108,22 +108,34 @@ FRESULT scan_files (char* path){
return res; return res;
} }
void wait(){
printfc("SNES::wait: press A to continue\n");
enablePad();
pad1 = readPad((byte) 0);
while(!pad1.A) {
pad1 = readPad((byte) 0);
}
printfc("SNES::wait: done\n");
disablePad();
}
void main(void) { void main(void) {
word i,j; word i,j;
BYTE res; BYTE res;
initInternalRegisters(); initInternalRegisters();
*(byte*) 0x2105 = 0x01; // MODE 1 value *(byte*) 0x2105 = 0x01; // MODE 1 value
*(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register *(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register
*(byte*) 0x212d = 0x00; // All subPlane disable *(byte*) 0x212d = 0x00; // All subPlane disable
*(byte*) 0x2100 = 0x0f; // enable background *(byte*) 0x2100 = 0x0f; // enable background
debug_enable(); debug_enable();
printfs(0,"FATFS "); printfs(0,"FATFS ");
printfs(2,"FATFS "); //wait();
printfs(3,"FATFS ");
printfs(4,"FATFS ");
halt();
printfc("SNES::main: Try to init disk\n"); printfc("SNES::main: Try to init disk\n");
put_rc(f_mount(0, &fatfs[0])); put_rc(f_mount(0, &fatfs[0]));
@ -133,7 +145,7 @@ void main(void) {
put_rc(res); put_rc(res);
printfc("SNES::main: printf fs results\n"); printfc("SNES::main: printf fs results\n");
printfc("FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\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" "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", "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, (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
@ -146,7 +158,7 @@ void main(void) {
if (res) if (res)
put_rc(res); put_rc(res);
printfc("%u FILES, %lu BYTES\n%u FOLDERS\n" printfs(12,"%u FILES, %lu BYTES\n%u FOLDERS\n"
"%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", "%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n",
acc_files, acc_size, acc_dirs, acc_files, acc_size, acc_dirs,
(fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)); (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2));
@ -156,6 +168,9 @@ void main(void) {
put_rc(res); put_rc(res);
p1 = s1 = s2 = 0; p1 = s1 = s2 = 0;
cnt = 0;
wait();
clears();
printfc("SNES::main: read dir\n"); printfc("SNES::main: read dir\n");
for(;;) { for(;;) {
res = f_readdir(&dir, &finfo); res = f_readdir(&dir, &finfo);
@ -165,7 +180,9 @@ void main(void) {
} else { } else {
s1++; p1 += finfo.fsize; s1++; p1 += finfo.fsize;
} }
printfc("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n", ;
printfs(cnt,"%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%s\n",
(finfo.fattrib & AM_DIR) ? 'D' : '-', (finfo.fattrib & AM_DIR) ? 'D' : '-',
(finfo.fattrib & AM_RDO) ? 'R' : '-', (finfo.fattrib & AM_RDO) ? 'R' : '-',
(finfo.fattrib & AM_HID) ? 'H' : '-', (finfo.fattrib & AM_HID) ? 'H' : '-',
@ -174,16 +191,21 @@ void main(void) {
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31, (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63, (finfo.ftime >> 11), (finfo.ftime >> 5) & 63,
finfo.fsize, &(finfo.fname[0])); 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]));
*/
} }
/*
printfc("%4u FILES, %10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2); printfc("%4u FILES, %10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2);
if (f_getfree("", &p1, &fs) == FR_OK) if (f_getfree("", &p1, &fs) == FR_OK)
printfc(", %10luK BYTES FREE\n", p1 * fs->csize / 2); printfc(", %10luK BYTES FREE\n", p1 * fs->csize / 2);
*/
while(1){ while(1){
while(!pad1.start) { wait();
waitForVBlank();
pad1 = readPad((byte) 0);
}
} }
while(1); while(1);
} }

View File

@ -1,11 +1,17 @@
#include "data.h"; #include "data.h";
#include "pad.h"; #include "pad.h";
#include "debug.h";
void enablePad(void) { void enablePad(void) {
// Enable pad reading and NMI // Enable pad reading and NMI
*(byte*)0x4200 = 0x81; *(byte*)0x4200 = 0x81;
} }
void disablePad(void) {
// Enable pad reading and NMI
*(byte*)0x4200 = 0x00;
}
padStatus readPad(byte padNumber) { padStatus readPad(byte padNumber) {
word test; word test;
padStatus *status; padStatus *status;

View File

@ -16,4 +16,5 @@ typedef struct padStatus{
} padStatus; } padStatus;
extern void enablePad(void); extern void enablePad(void);
extern void disablePad(void);
extern padStatus readPad(byte padNumber); extern padStatus readPad(byte padNumber);

View File

@ -44,9 +44,9 @@ image_not_parted:
image: image:
rm -fv disk00.vfat rm -fv disk00.vfat
mkfs.vfat -I -F 16 -v -C disk00.vfat 4000 mkfs.vfat -I -F 16 -v -C disk00.vfat 32000
sudo mount -o loop disk00.vfat disk sudo mount -o loop disk00.vfat disk
sudo cp -v /var/log/*.log disk/ sudo cp -v ../../../roms/*smc disk/
sudo umount disk sudo umount disk
mount: mount: