From 660767c464c3d78d36436123eb2e717c3c85f6bc Mon Sep 17 00:00:00 2001 From: david Date: Tue, 26 May 2009 17:07:39 +0200 Subject: [PATCH] o add snes fatfs dummy o add fatfs custom chip to bsnes o finishes fatfs linux backend smaple --- snes/fatfstest/Makefile | 69 +++++++ snes/fatfstest/PPU.c | 80 +++++++++ snes/fatfstest/PPU.h | 11 ++ snes/fatfstest/StartupSnes.asm | 240 +++++++++++++++++++++++++ snes/fatfstest/data.h | 2 + snes/fatfstest/debug.c | 51 ++++++ snes/fatfstest/debug.h | 6 + snes/fatfstest/event.c | 101 +++++++++++ snes/fatfstest/event.h | 16 ++ snes/fatfstest/main.c | 61 +++++++ snes/fatfstest/myEvents.c | 97 ++++++++++ snes/fatfstest/myEvents.h | 6 + snes/fatfstest/pad.c | 17 ++ snes/fatfstest/pad.h | 19 ++ snes/fatfstest/ressource.asm | 23 +++ snes/fatfstest/ressource.h | 3 + snes/fatfstest/ressource/debugFont.clr | Bin 0 -> 2 bytes snes/fatfstest/ressource/debugFont.pcx | Bin 0 -> 3154 bytes snes/fatfstest/ressource/debugFont.pic | Bin 0 -> 2048 bytes snes/fatfstest/ressource/debugFont.xcf | Bin 0 -> 6237 bytes tools/bsnes/Makefile | 6 +- tools/bsnes/chip/chip.hpp | 1 + tools/bsnes/chip/fatfs/diskio.cpp | 168 +++++++++++++++++ tools/bsnes/chip/fatfs/diskio.h | 71 ++++++++ tools/bsnes/chip/fatfs/fatfs.cpp | 116 ++++++++++++ tools/bsnes/chip/fatfs/fatfs.hpp | 26 +++ tools/bsnes/chip/fatfs/integer.h | 37 ++++ tools/bsnes/snes/snes.cpp | 3 + tools/ffsample/linux/diskio.c | 82 --------- tools/ffsample/linux/diskio.h | 30 ++-- tools/ffsample/linux/ff.h | 4 +- tools/ffsample/linux/fftest | Bin 40235 -> 40212 bytes tools/ffsample/linux/main.c | 16 -- 33 files changed, 1241 insertions(+), 121 deletions(-) create mode 100644 snes/fatfstest/Makefile create mode 100644 snes/fatfstest/PPU.c create mode 100644 snes/fatfstest/PPU.h create mode 100644 snes/fatfstest/StartupSnes.asm create mode 100644 snes/fatfstest/data.h create mode 100644 snes/fatfstest/debug.c create mode 100644 snes/fatfstest/debug.h create mode 100644 snes/fatfstest/event.c create mode 100644 snes/fatfstest/event.h create mode 100644 snes/fatfstest/main.c create mode 100644 snes/fatfstest/myEvents.c create mode 100644 snes/fatfstest/myEvents.h create mode 100644 snes/fatfstest/pad.c create mode 100644 snes/fatfstest/pad.h create mode 100644 snes/fatfstest/ressource.asm create mode 100644 snes/fatfstest/ressource.h create mode 100644 snes/fatfstest/ressource/debugFont.clr create mode 100644 snes/fatfstest/ressource/debugFont.pcx create mode 100644 snes/fatfstest/ressource/debugFont.pic create mode 100644 snes/fatfstest/ressource/debugFont.xcf create mode 100644 tools/bsnes/chip/fatfs/diskio.cpp create mode 100644 tools/bsnes/chip/fatfs/diskio.h create mode 100644 tools/bsnes/chip/fatfs/fatfs.cpp create mode 100644 tools/bsnes/chip/fatfs/fatfs.hpp create mode 100644 tools/bsnes/chip/fatfs/integer.h diff --git a/snes/fatfstest/Makefile b/snes/fatfstest/Makefile new file mode 100644 index 0000000..58b12c3 --- /dev/null +++ b/snes/fatfstest/Makefile @@ -0,0 +1,69 @@ +# SDK Config + + +PLATFORM=$(shell uname) + +ifeq ($(PLATFORM),Linux) + # Linux Wine + SDK=/home/david/.wine/drive_c/65xx_FreeSDK + WINE=wine + EMU=zsnes + EMU_DEBUG=/home/david/Devel/arch/snes/tools/zsnes_linux_debug151/src/zsnesd -d +else + # Mac Wine + SDK=/Users/david/.wine/drive_c/65xx_FreeSDK + WINE=wine + EMU=zsnes +endif + +CC=$(WINE) $(SDK)/bin/WDC816CC.exe +AS=$(WINE) $(SDK)/bin/WDC816AS.exe +LD=$(WINE) $(SDK)/bin/WDCLN.exe + + +# Project + +INC=$(SDK)/include +LIBS=$(SDK)/lib/cc +OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj +APP=fatfs.smc +GFX=debugfont + +all: $(APP) + +run: + $(EMU) $(APP) + +debugger: + $(EMU_DEBUG) $(APP) + +upload: + ucon64 -chk $(APP) + cp -rv $(APP) /Volumes/SNES + sync + diskutil unmount /Volumes/SNES + +crc: + python ../../scripts/crc_xmodem.py $(APP) + + +StartupSnes.obj: StartupSnes.asm + $(AS) -V $? + +ressource.obj: ressource.asm + $(AS) -V $? + +%.obj: %.c + $(CC) -wl -wp -sop -MC -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) -L$(LIBS) -O $@ + ucon64 -snes -chk $(APP) + +clean: + rm -vf $(APP) *.obj diff --git a/snes/fatfstest/PPU.c b/snes/fatfstest/PPU.c new file mode 100644 index 0000000..e61b481 --- /dev/null +++ b/snes/fatfstest/PPU.c @@ -0,0 +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; +} \ No newline at end of file diff --git a/snes/fatfstest/PPU.h b/snes/fatfstest/PPU.h new file mode 100644 index 0000000..36ecef9 --- /dev/null +++ b/snes/fatfstest/PPU.h @@ -0,0 +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); \ No newline at end of file diff --git a/snes/fatfstest/StartupSnes.asm b/snes/fatfstest/StartupSnes.asm new file mode 100644 index 0000000..994eda2 --- /dev/null +++ b/snes/fatfstest/StartupSnes.asm @@ -0,0 +1,240 @@ +; SNES ROM startup code + +;****************************************************************************** +;*** Define a special section in case most of the code is not in bank 0. *** +;****************************************************************************** + +;STACK EQU $01ff ;CHANGE THIS FOR YOUR SYSTEM + +;STARTUP SECTION OFFSET $008000 + +CODE + + XDEF START +START: + XREF _~main + + sei ; Disabled interrupts + clc ; clear carry to switch to native mode + xce ; Xchange carry & emulation bit. native mode + rep #$18 ; Binary mode (decimal mode off), X/Y 16 bit + LONGI ON + ldx #$1FFF ; set stack to $1FFF + txs + + rep #$30 + longa on + longi on + + ; Init data used for heap + ; see heap definition below + XREF _~_heap_top + XREF _~_mem_start + stz _~_heap_top + stz _~_mem_start + + XREF _~preInit + jsr >_~preInit + + sep #$30 ; X,Y,A are 8 bit numbers + LONGA OFF + LONGI OFF + lda #$8F ; screen off, full brightness + sta $2100 ; brightness + screen enable register + stz $2101 ; Sprite register (size + address in VRAM) + stz $2102 ; Sprite registers (address of sprite memory [OAM]) + stz $2103 ; "" "" + stz $2105 ; Mode 0, = Graphic mode register + stz $2106 ; noplanes, no mosaic, = Mosaic register + stz $2107 ; Plane 0 map VRAM location + stz $2108 ; Plane 1 map VRAM location + stz $2109 ; Plane 2 map VRAM location + stz $210A ; Plane 3 map VRAM location + stz $210B ; Plane 0+1 Tile data location + stz $210C ; Plane 2+3 Tile data location + stz $210D ; Plane 0 scroll x (first 8 bits) + stz $210D ; Plane 0 scroll x (last 3 bits) #$0 - #$07ff + stz $210E ; Plane 0 scroll y (first 8 bits) + stz $210E ; Plane 0 scroll y (last 3 bits) #$0 - #$07ff + stz $210F ; Plane 1 scroll x (first 8 bits) + stz $210F ; Plane 1 scroll x (last 3 bits) #$0 - #$07ff + stz $2110 ; Plane 1 scroll y (first 8 bits) + stz $2110 ; Plane 1 scroll y (last 3 bits) #$0 - #$07ff + stz $2111 ; Plane 2 scroll x (first 8 bits) + stz $2111 ; Plane 2 scroll x (last 3 bits) #$0 - #$07ff + stz $2112 ; Plane 2 scroll y (first 8 bits) + stz $2112 ; Plane 2 scroll y (last 3 bits) #$0 - #$07ff + stz $2113 ; Plane 3 scroll x (first 8 bits) + stz $2113 ; Plane 3 scroll x (last 3 bits) #$0 - #$07ff + stz $2114 ; Plane 3 scroll y (first 8 bits) + stz $2114 ; Plane 3 scroll y (last 3 bits) #$0 - #$07ff + lda #$80 ; increase VRAM address after writing to $2119 + sta $2115 ; VRAM address increment register + stz $2116 ; VRAM address low + stz $2117 ; VRAM address high + stz $211A ; Initial Mode 7 setting register + stz $211B ; Mode 7 matrix parameter A register (low) + lda #$01 + sta $211B ; Mode 7 matrix parameter A register (high) + stz $211C ; Mode 7 matrix parameter B register (low) + stz $211C ; Mode 7 matrix parameter B register (high) + stz $211D ; Mode 7 matrix parameter C register (low) + stz $211D ; Mode 7 matrix parameter C register (high) + stz $211E ; Mode 7 matrix parameter D register (low) + sta $211E ; Mode 7 matrix parameter D register (high) + stz $211F ; Mode 7 center position X register (low) + stz $211F ; Mode 7 center position X register (high) + stz $2120 ; Mode 7 center position Y register (low) + stz $2120 ; Mode 7 center position Y register (high) + stz $2121 ; Color number register ($0-ff) + stz $2123 ; BG1 & BG2 Window mask setting register + stz $2124 ; BG3 & BG4 Window mask setting register + stz $2125 ; OBJ & Color Window mask setting register + stz $2126 ; Window 1 left position register + stz $2127 ; Window 2 left position register + stz $2128 ; Window 3 left position register + stz $2129 ; Window 4 left position register + stz $212A ; BG1, BG2, BG3, BG4 Window Logic register + stz $212B ; OBJ, Color Window Logic Register (or,and,xor,xnor) + sta $212C ; Main Screen designation (planes, sprites enable) + stz $212D ; Sub Screen designation + stz $212E ; Window mask for Main Screen + stz $212F ; Window mask for Sub Screen + lda #$30 + sta $2130 ; Color addition & screen addition init setting + stz $2131 ; Add/Sub sub designation for screen, sprite, color + lda #$E0 + sta $2132 ; color data for addition/subtraction + stz $2133 ; Screen setting (interlace x,y/enable SFX data) + stz $4200 ; Enable V-blank, interrupt, Joypad register + lda #$FF + sta $4201 ; Programmable I/O port + stz $4202 ; Multiplicand A + stz $4203 ; Multiplier B + stz $4204 ; Multiplier C + stz $4205 ; Multiplicand C + stz $4206 ; Divisor B + stz $4207 ; Horizontal Count Timer + stz $4208 ; Horizontal Count Timer MSB (most significant bit) + stz $4209 ; Vertical Count Timer + stz $420A ; Vertical Count Timer MSB + stz $420B ; General DMA enable (bits 0-7) + stz $420C ; Horizontal DMA (HDMA) enable (bits 0-7) + stz $420D ; Access cycle designation (slow/fast rom) + cli ; Enable interrupts + + rep #$30 + longa on + longi on + + jsr >_~main + brk + + XDEF IRQ +IRQ: + XREF _~IRQHandler + LONGA ON + LONGI ON + rep #$30 + pha + phx + phy + jsr _~IRQHandler + ply + plx + pla + rti + + XDEF NMI +NMI: + XREF _~NMIHandler + LONGA ON + LONGI ON + rep #$30 + pha + phx + phy + phd + phb + lda #$0000 + sep #$30 ; X,Y,A are 8 bit numbers + LONGA OFF + LONGI OFF + lda $4210 ; Read NMI + LONGA ON + LONGI ON + rep #$30 + jsr _~NMIHandler + plb + pld + ply + plx + pla + rti + +DIRQ: + rti + +ENDS + +;****************************************************************************** +;*** Heap definition *** +;****************************************************************************** + +DATA + + XDEF _~heap_start + XDEF _~heap_end + +_~heap_start: + WORD $1000 +_~heap_end: + WORD $1200 + +;****************************************************************************** +;*** SNES ROM Registartion Data *** +;****************************************************************************** + +REGISTRATION_DATA SECTION + +MAKER_CODE FCC /FF/ +GAME_CODE FCC /SMWJ/ +FIXED_VALUE0 BYTE $00, $00, $00, $00, $00, $00, $00 +EXPANSION_RAM_SIZE BYTE $00 +SPECIAL_VERSION BYTE $00 +CARTRIDGE_TYPE_SUB BYTE $00 +GAME_TITLE FCC /GAME TITLE !/ + ;012345678901234567890; +MAP_MODE BYTE $20 +CARTRIDGE_SIZE BYTE $00 +ROM_SIZE BYTE $09 +RAM_SIZE BYTE $00 +DESTINATION_CODE BYTE $00 +FIXED_VALUE1 BYTE $33 +MASK_ROM_VERSION BYTE $00 +COMPLEMENT_CHECK BYTE $00, $00 +CHEKSUM BYTE $00, $00 + +;****************************************************************************** +;*** SNES Interrupts and Reset vector *** +;****************************************************************************** + +VECTORS SECTION +; Native vector +N_COP DW DIRQ +N_BRK DW DIRQ +N_ABORT DW DIRQ +N_NMI DW NMI +N_RSRVD DW DIRQ +N_IRQ DW IRQ + DS 4 +; Emulation vector +E_COP DW DIRQ +E_RSRVD DW DIRQ +E_ABORT DW DIRQ +E_NMI DW DIRQ +E_RESET DW START +E_IRQ DW DIRQ + +END + diff --git a/snes/fatfstest/data.h b/snes/fatfstest/data.h new file mode 100644 index 0000000..5152032 --- /dev/null +++ b/snes/fatfstest/data.h @@ -0,0 +1,2 @@ +typedef unsigned char byte; +typedef unsigned short word; diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c new file mode 100644 index 0000000..5956fc9 --- /dev/null +++ b/snes/fatfstest/debug.c @@ -0,0 +1,51 @@ +#include "data.h" +#include "pad.h" +#include "PPU.h" +#include "ressource.h" + +word debugMap[0x400]; +void initDebugMap(void) { + word i; + for(i=0; i<0x400; i++) { + debugMap[i] = 0x00; + } +} + +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) +{ + unsigned long n; + unsigned char i; + //unsigned char x; + for (i = 0; i < size; i++) { + n = number >> 4; + //x = (number - (n << 4)); + buf[size-i-1] = hex_chars[(number - (n << 4))]; + number = n; + } + +} + +void printDebugScreen(char *buffer,word y){ + char i; + waitForVBlank(); + for(i=0; i<32; i++) { + waitForVBlank(); + VRAMByteWrite((byte) (buffer[i]-32), (word) (0x4000+i+(y*0x20))); + } +} + +void printf(char *buffer){ + while(*buffer) + *(byte*) 0x3000=*buffer++; +} + +void enableDebugScreen(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 +} \ No newline at end of file diff --git a/snes/fatfstest/debug.h b/snes/fatfstest/debug.h new file mode 100644 index 0000000..fe4f667 --- /dev/null +++ b/snes/fatfstest/debug.h @@ -0,0 +1,6 @@ +void initDebugMap(void); +void debug(void); +void int2hex(unsigned long i, char *buf,word size); +void printDebugScreen(char* line,word y); +void enableDebugScreen(void); +void printf(char* line); diff --git a/snes/fatfstest/event.c b/snes/fatfstest/event.c new file mode 100644 index 0000000..1c62c4a --- /dev/null +++ b/snes/fatfstest/event.c @@ -0,0 +1,101 @@ +#include + +#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; + } + +} diff --git a/snes/fatfstest/event.h b/snes/fatfstest/event.h new file mode 100644 index 0000000..76b07dc --- /dev/null +++ b/snes/fatfstest/event.h @@ -0,0 +1,16 @@ +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); diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c new file mode 100644 index 0000000..c9d22e9 --- /dev/null +++ b/snes/fatfstest/main.c @@ -0,0 +1,61 @@ +#include "data.h"; +#include "pad.h"; +#include "event.h"; +#include "myEvents.h"; +#include "ressource.h"; +#include "PPU.h" +#include "debug.h" + + +#include + +padStatus pad1; + +void initInternalRegisters(void) { + characterLocation[0] = 0x0000; + characterLocation[1] = 0x0000; + characterLocation[2] = 0x0000; + characterLocation[3] = 0x0000; + initDebugMap(); +} + +void preInit(void) { + // For testing purpose ... + // Insert code here to be executed before register init +} + +void main(void) { + word i,j; + word crc01; + word crc02; + padStatus pad1; + char line_header[32] = "OK2"; + char packet[4] = "TEST"; + 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 + + enableDebugScreen(); + printDebugScreen(line_header,0); + printf("Debugging console test\n"); + printf("test me\n"); + printDebugScreen(line_header,1); + + while(1){ + while(!pad1.start) { + waitForVBlank(); + pad1 = readPad((byte) 0); + } + } + while(1); +} + +void IRQHandler(void) { +} + +void NMIHandler(void) { + //processEvents(); +} diff --git a/snes/fatfstest/myEvents.c b/snes/fatfstest/myEvents.c new file mode 100644 index 0000000..92c78ac --- /dev/null +++ b/snes/fatfstest/myEvents.c @@ -0,0 +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; +} \ No newline at end of file diff --git a/snes/fatfstest/myEvents.h b/snes/fatfstest/myEvents.h new file mode 100644 index 0000000..719abe7 --- /dev/null +++ b/snes/fatfstest/myEvents.h @@ -0,0 +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); \ No newline at end of file diff --git a/snes/fatfstest/pad.c b/snes/fatfstest/pad.c new file mode 100644 index 0000000..2b86eac --- /dev/null +++ b/snes/fatfstest/pad.c @@ -0,0 +1,17 @@ +#include "data.h"; +#include "pad.h"; + +void enablePad(void) { + // Enable pad reading and NMI + *(byte*)0x4200 = 0x81; +} + +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; +} diff --git a/snes/fatfstest/pad.h b/snes/fatfstest/pad.h new file mode 100644 index 0000000..e5a907f --- /dev/null +++ b/snes/fatfstest/pad.h @@ -0,0 +1,19 @@ +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 padStatus readPad(byte padNumber); diff --git a/snes/fatfstest/ressource.asm b/snes/fatfstest/ressource.asm new file mode 100644 index 0000000..6802a07 --- /dev/null +++ b/snes/fatfstest/ressource.asm @@ -0,0 +1,23 @@ +ressource .section + +; XDEF __title_map +;__title_map: +; INSERT ressource/kungfu.map +; +; XDEF __title_pic +;__title_pic: +; INSERT ressource/kungfu.pic +; +; XDEF __title_pal +;__title_pal: +;make INSERT ressource/kungfu.clr + + XDEF _~debugFont_pic +_~debugFont_pic + INSERT ressource/debugFont.pic + + XDEF _~debugFont_pal +_~debugFont_pal + INSERT ressource/debugFont.clr + +.ends diff --git a/snes/fatfstest/ressource.h b/snes/fatfstest/ressource.h new file mode 100644 index 0000000..8298c7e --- /dev/null +++ b/snes/fatfstest/ressource.h @@ -0,0 +1,3 @@ + +extern word debugFont_pic[]; +extern word debugFont_pal[]; diff --git a/snes/fatfstest/ressource/debugFont.clr b/snes/fatfstest/ressource/debugFont.clr new file mode 100644 index 0000000000000000000000000000000000000000..09f370e38f498a462e1ca0faa724559b6630c04f GIT binary patch literal 2 JcmZQz0000200961 literal 0 HcmV?d00001 diff --git a/snes/fatfstest/ressource/debugFont.pcx b/snes/fatfstest/ressource/debugFont.pcx new file mode 100644 index 0000000000000000000000000000000000000000..9a481e084bc507111f54174d01131fa9268d0117 GIT binary patch literal 3154 zcmeH}Yi`^y41{F^MT??G$^8!?KawWfGqg9^&Nn1wyImB>?`C%`$$Sil6m9L-Pt%vC z&wcvbo~EaX^}9Y(o8RwrM7U4a@5}TyEp45)w)ooH^xU-CB;9p&U7JLU=3i4s%W}a= zzs0{;*NDE{U$x#7yyLJ7@tDHJAXijEKK@0-5%+rA6{?FRA))Z9?AomKG|bj$RuXNS zHFPbR7tJ==Syo_0KkTcH<(ic#V@j)6hK4LrX9ph3p*hIri!X4Sq&~JMN)37t`Lc@fl1J z^$RWTJ*uie(W&fS_lCs1z~x`OYNNBXf8SbRYc{Kk8>G8vMKCu9U0rWMSt-E+;`t$A z-+Kphh1rD!Uc(diAvhk7lXs>rs51l{j##lT#Y1F;WU^kVq^knZ$2YySA|D^DH;K+i zJ4Zb-a@=+Bo=#&LERNz_MaR*TOMBME8PCk02r&7@>79o?do6)A1Ndwg)@kOOVOFXE e$`Su8mYUo)-}K++-tPJwe{w!n9~Jm-D)1XJOx*kc literal 0 HcmV?d00001 diff --git a/snes/fatfstest/ressource/debugFont.pic b/snes/fatfstest/ressource/debugFont.pic new file mode 100644 index 0000000000000000000000000000000000000000..ea179dc0fc59ef93fe15239af9bb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|H z$=@4&oHML8@y0Uwp49m_@IY{L{Aqi03~u+1Y>h-cPg|n(eT*ky`B++3GjiQ&lCJ5l^30{zEh07Ty(wyk+Qw|#f&dQ_;}E}fKRRX0Oco<0ocuZ z$$z;L=u*o!CN%heiW43H3vG%B?rf5Bppvn3|B2+=mQn}w=Nfem_nk(b$DJS8aN&&9 z-<0_sZ|jrIjWcm|BU-FBp5KVs#cyf+zIL;};qkM!xpwgTA1*gl2s +#include +#include +#include +#include +#include +#include +#include + +#define IMAGE_NAME "disk00.vfat" + +BYTE *image_addr; + +DSTATUS disk_initialize (BYTE drv) { + if (drv) return STA_NOINIT; /* Supports only single drive */ + + Stat |= STA_NOINIT; + + int fd = open(IMAGE_NAME, O_RDWR); + if (fd == -1) { + perror("Error opening file for writing"); + exit(EXIT_FAILURE); + } + + int size = lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + printf("Open Image (size %i)\n",size); + + image_addr = (BYTE*)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (image_addr == MAP_FAILED) { + close(fd); + perror("Error mmapping the file"); + exit(EXIT_FAILURE); + } + + Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */ + 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) */ +) +{ + BYTE c, iord_l, iord_h; + if (drv || !count) return RES_PARERR; + if (Stat & STA_NOINIT) return RES_NOTRDY; + + DWORD offset = sector * 512; + int size = count * 512; + printf("disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); + memcpy(buff,image_addr + offset,size); + return RES_OK; +} + +/*-----------------------------------------------------------------------*/ +/* 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) */ +) +{ + + if (drv || !count) return RES_PARERR; + if (Stat & STA_NOINIT) return RES_NOTRDY; + + DWORD offset = sector * 512; + int size = count * 512; + printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); + memcpy(image_addr + offset,buff,size); + 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) */ + printf("disk_ioctl: GET_SECTOR_COUNT\n"); + ofs = 60; w = 2; n = 0; + break; + + case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */ + printf("disk_ioctl: GET_SECTOR_SIZE\n"); + *(WORD*)buff = 512; + return RES_OK; + + case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */ + printf("disk_ioctl: GET_BLOCK_SIZE\n"); + *(DWORD*)buff = 32; + return RES_OK; + + default: + return RES_PARERR; + } + return RES_OK; +} +#endif /* _USE_IOCTL != 0 */ + + + + diff --git a/tools/bsnes/chip/fatfs/diskio.h b/tools/bsnes/chip/fatfs/diskio.h new file mode 100644 index 0000000..e9f28bf --- /dev/null +++ b/tools/bsnes/chip/fatfs/diskio.h @@ -0,0 +1,71 @@ +/*----------------------------------------------------------------------- +/ 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 */ + + + +/* 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 \ No newline at end of file diff --git a/tools/bsnes/chip/fatfs/fatfs.cpp b/tools/bsnes/chip/fatfs/fatfs.cpp new file mode 100644 index 0000000..e59941a --- /dev/null +++ b/tools/bsnes/chip/fatfs/fatfs.cpp @@ -0,0 +1,116 @@ +#include <../base.hpp> +#include <../cart/cart.hpp> +#include "fatfs.hpp" + + +#include "diskio.h" + +#define CMD_INIT 0x00 +#define CMD_READ 0x01 +#define CMD_WRITE 0x02 +#define CMD_NONE 0xff + +#define SHARED_SIZE 512 +#define SHARED_ADDR 0x3f0000 + +void FATFS::init() { + command = CMD_NONE; + sector = 0; + count = 0; + retval = -1; + scratch_buffer = (char*)malloc(SHARED_SIZE); +} + +void FATFS::enable() { + // command + memory::mmio.map(0x3010, *this); + // sector + memory::mmio.map(0x3011, *this); + memory::mmio.map(0x3012, *this); + memory::mmio.map(0x3013, *this); + memory::mmio.map(0x3014, *this); + // offset + memory::mmio.map(0x3015, *this); + // return value + memory::mmio.map(0x3016, *this); +} + +void FATFS::power() { + reset(); +} + +void FATFS::reset() { +} + + +void FATFS::fetchMem() { + for ( int i=0;i= 0x3011 && addr <= 0x3014){ + sector = data << ( (3 - ( addr - 0x3011)) << 3); + printf("FATFS::mmio_write set sector: byte=%i val=%i sector=%i \n",(3 - ( addr - 0x3011)),data,sector); + } + if (addr == 0x3015){ + count = data; + printf("FATFS::mmio_write set offset: countr=%i \n",count); + if (command == CMD_READ) { + retval = disk_read (0, (BYTE*)scratch_buffer, sector, count); + if (!retval) + pushMem(); + } else if (command == CMD_WRITE) { + fetchMem(); + retval = disk_write (0, (BYTE*)scratch_buffer, sector, count); + } else{ + printf("FATFS::mmio_write set offset: no command to trigger \n"); + } + } + if (addr == 0x3016){ + printf("FATFS::mmio_write reg 0x3016 retav is RW\n"); + } +} + +FATFS::FATFS() { +} diff --git a/tools/bsnes/chip/fatfs/fatfs.hpp b/tools/bsnes/chip/fatfs/fatfs.hpp new file mode 100644 index 0000000..36221cf --- /dev/null +++ b/tools/bsnes/chip/fatfs/fatfs.hpp @@ -0,0 +1,26 @@ +class FATFS : public MMIO { +public: + + void init(); + void enable(); + void power(); + void reset(); + + + void fetchMem(); + void pushMem(); + + + uint8 mmio_read (unsigned addr); + void mmio_write(unsigned addr, uint8 data); + + FATFS(); +private: + char command; + int sector; + char count; + char retval; + char *scratch_buffer; +}; + +extern FATFS fatfs; diff --git a/tools/bsnes/chip/fatfs/integer.h b/tools/bsnes/chip/fatfs/integer.h new file mode 100644 index 0000000..1d6bac3 --- /dev/null +++ b/tools/bsnes/chip/fatfs/integer.h @@ -0,0 +1,37 @@ +/*-------------------------------------------*/ +/* Integer type definitions for FatFs module */ +/*-------------------------------------------*/ + +#ifndef _INTEGER + +#if 0 +#include +#else + +/* 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 */ +typedef enum { FALSE = 0, TRUE } BOOL; + +#endif + +#define _INTEGER +#endif diff --git a/tools/bsnes/snes/snes.cpp b/tools/bsnes/snes/snes.cpp index 0db7ba2..9f11763 100755 --- a/tools/bsnes/snes/snes.cpp +++ b/tools/bsnes/snes/snes.cpp @@ -24,6 +24,7 @@ DSP4 dsp4; OBC1 obc1; ST010 st010; CMMIO cmmio; +FATFS fatfs; #include "scheduler/scheduler.cpp" #include "tracer/tracer.cpp" @@ -101,6 +102,7 @@ void SNES::power() { if(cartridge.has_st010()) st010.power(); cmmio.power(); + fatfs.power(); for(unsigned i = 0x2100; i <= 0x213f; i++) memory::mmio.map(i, ppu); for(unsigned i = 0x2140; i <= 0x217f; i++) memory::mmio.map(i, cpu); @@ -125,6 +127,7 @@ void SNES::power() { if(cartridge.has_st010()) st010.enable(); cmmio.enable(); + fatfs.enable(); input.port_set_device(0, snes.config.controller_port1); input.port_set_device(1, snes.config.controller_port2); diff --git a/tools/ffsample/linux/diskio.c b/tools/ffsample/linux/diskio.c index 40a43a4..f86b3e9 100644 --- a/tools/ffsample/linux/diskio.c +++ b/tools/ffsample/linux/diskio.c @@ -5,63 +5,22 @@ static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */ -/* - -sudo losetup /dev/loop0 disk00.vfat -sudo mkfs.vfat -f 2 -F 16 -v /dev/loop0 -mkfs.vfat 2.11 (12 Mar 2005) -Loop device does not match a floppy size, using default hd params -/dev/loop0 has 64 heads and 32 sectors per track, -logical sector size is 512, -using 0xf8 media descriptor, with 524288 sectors; -file system has 2 16-bit FATs and 8 sectors per cluster. -FAT size is 256 sectors, and provides 65467 clusters. -Root directory contains 512 slots. -Volume ID is 4a1aab3d, no volume label. - - -FAT type = 2 -Bytes/Cluster = 4096 -Number of FATs = 2 -Root DIR entries = 512 -Sectors/FAT = 256 -Number of clusters = 65467 -FAT start (lba) = 1 -DIR start (lba,clustor) = 513 -Data start (lba) = 545 -Ok -disk_read: sector=513 count=1 addr=0xa8009800 size=512 -scan_files ret -0 files, 0 bytes. -0 folders. -261868 KB total disk space. -147456 KB available. - - - -*/ /* 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 - - */ /*-----------------------------------------------------------------------*/ @@ -77,7 +36,6 @@ return 1 byte #include #include - #define IMAGE_NAME "disk00.vfat" char *image_addr; @@ -86,8 +44,6 @@ DSTATUS disk_initialize (BYTE drv) { if (drv) return STA_NOINIT; /* Supports only single drive */ Stat |= STA_NOINIT; - /* map image */ - int fd = open(IMAGE_NAME, O_RDWR); if (fd == -1) { @@ -95,11 +51,9 @@ DSTATUS disk_initialize (BYTE drv) { exit(EXIT_FAILURE); } - int size = lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); printf("Open Image (size %i)\n",size); - image_addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (image_addr == MAP_FAILED) { @@ -140,11 +94,8 @@ DRESULT disk_read ( DWORD offset = sector * 512; int size = count * 512; - printf("disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); memcpy(buff,image_addr + offset,size); - //printf("%x %x %x %x\n",buff[0],buff[1],buff[2],buff[3]); - return RES_OK; } @@ -160,16 +111,12 @@ DRESULT disk_write ( BYTE count /* Sector count (1..255) */ ) { - BYTE s, c, iowr_l, iowr_h; - - if (drv || !count) return RES_PARERR; if (Stat & STA_NOINIT) return RES_NOTRDY; DWORD offset = sector * 512; int size = count * 512; - printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); memcpy(image_addr + offset,buff,size); return RES_OK; @@ -209,38 +156,9 @@ DRESULT disk_ioctl ( *(DWORD*)buff = 32; return RES_OK; - case CTRL_SYNC : /* Nothing to do */ - printf("disk_ioctl: CTRL_SIZE\n"); - return RES_OK; - - case ATA_GET_REV : /* Get firmware revision (8 chars) */ - printf("disk_ioctl: ATAL_GET_REV\n"); - ofs = 23; w = 4; n = 4; - break; - - case ATA_GET_MODEL : /* Get model name (40 chars) */ - printf("disk_ioctl: ATAL_GET_MODEL\n"); - ofs = 27; w = 20; n = 20; - break; - - case ATA_GET_SN : /* Get serial number (20 chars) */ - printf("disk_ioctl: ATAL_GET_SN\n"); - ofs = 10; w = 10; n = 10; - break; - default: return RES_PARERR; } - - /* - write_ata(REG_COMMAND, CMD_IDENTIFY); - if (!wait_data()) return RES_ERROR; - read_part(ptr, ofs, w); - while (n--) { - dl = *ptr; dh = *(ptr+1); - *ptr++ = dh; *ptr++ = dl; - } - */ return RES_OK; } #endif /* _USE_IOCTL != 0 */ diff --git a/tools/ffsample/linux/diskio.h b/tools/ffsample/linux/diskio.h index 2c846d1..e9f28bf 100644 --- a/tools/ffsample/linux/diskio.h +++ b/tools/ffsample/linux/diskio.h @@ -2,6 +2,11 @@ / 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 */ @@ -56,26 +61,11 @@ void disk_timerproc (void); #define CTRL_POWER 4 #define CTRL_LOCK 5 #define CTRL_EJECT 6 -/* MMC/SDC command */ -#define MMC_GET_TYPE 10 -#define MMC_GET_CSD 11 -#define MMC_GET_CID 12 -#define MMC_GET_OCR 13 -#define MMC_GET_SDSTAT 14 -/* ATA/CF command */ -#define ATA_GET_REV 20 -#define ATA_GET_MODEL 21 -#define ATA_GET_SN 22 - - - -/* Card type flags (CardType) */ -#define CT_MMC 0x01 -#define CT_SD1 0x02 -#define CT_SD2 0x04 -#define CT_SDC (CT_SD1|CT_SD2) -#define CT_BLOCK 0x08 - #define _DISKIO #endif + + + #ifdef __cplusplus + } + #endif \ No newline at end of file diff --git a/tools/ffsample/linux/ff.h b/tools/ffsample/linux/ff.h index 8ba05cf..57786c9 100644 --- a/tools/ffsample/linux/ff.h +++ b/tools/ffsample/linux/ff.h @@ -81,13 +81,13 @@ /* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk */ -#define _MULTI_PARTITION 1 +#define _MULTI_PARTITION 0 /* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical / drive number and can mount only first primaly partition. When it is set to 1, / each volume is tied to the partitions listed in Drives[]. */ -#define _CODE_PAGE 850 +#define _CODE_PAGE 437 /* The _CODE_PAGE specifies the OEM code page to be used on the target system. / When it is non LFN configuration, there is no difference between SBCS code / pages. When LFN is enabled, the code page must always be set correctly. diff --git a/tools/ffsample/linux/fftest b/tools/ffsample/linux/fftest index 8bd0121b0e6d343ec4b5a96ceab756eb86ff3009..d1cf9ac77245e50b6f83d0b28c5843f6fd51123f 100755 GIT binary patch delta 5227 zcma)Ad0Z4%67KhCpdG`S;%fW_F~X?hEG}4{ zt1*(8WD{MliLSvI@rbA~-kTW32np&8Acqn~#mrXq^sGnz+5Qbv@2lgh>UytVzhOry zUt7wH3Y^mC3PSqay{p_ExL9M_>JZ6!NY;f9|IJYl%H>l6UY4J5 zj7}%&gW7V$dIng0ND4ingcul?+K;FxG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