o add snes fatfs dummy
o add fatfs custom chip to bsnes o finishes fatfs linux backend smaple
This commit is contained in:
parent
0fd42d7b1d
commit
660767c464
69
snes/fatfstest/Makefile
Normal file
69
snes/fatfstest/Makefile
Normal file
@ -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
|
||||||
80
snes/fatfstest/PPU.c
Normal file
80
snes/fatfstest/PPU.c
Normal file
@ -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;
|
||||||
|
}
|
||||||
11
snes/fatfstest/PPU.h
Normal file
11
snes/fatfstest/PPU.h
Normal file
@ -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);
|
||||||
240
snes/fatfstest/StartupSnes.asm
Normal file
240
snes/fatfstest/StartupSnes.asm
Normal file
@ -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
|
||||||
|
|
||||||
2
snes/fatfstest/data.h
Normal file
2
snes/fatfstest/data.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
typedef unsigned char byte;
|
||||||
|
typedef unsigned short word;
|
||||||
51
snes/fatfstest/debug.c
Normal file
51
snes/fatfstest/debug.c
Normal file
@ -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
|
||||||
|
}
|
||||||
6
snes/fatfstest/debug.h
Normal file
6
snes/fatfstest/debug.h
Normal file
@ -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);
|
||||||
101
snes/fatfstest/event.c
Normal file
101
snes/fatfstest/event.c
Normal file
@ -0,0 +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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
snes/fatfstest/event.h
Normal file
16
snes/fatfstest/event.h
Normal file
@ -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);
|
||||||
61
snes/fatfstest/main.c
Normal file
61
snes/fatfstest/main.c
Normal file
@ -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 <stdlib.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
97
snes/fatfstest/myEvents.c
Normal file
97
snes/fatfstest/myEvents.c
Normal file
@ -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;
|
||||||
|
}
|
||||||
6
snes/fatfstest/myEvents.h
Normal file
6
snes/fatfstest/myEvents.h
Normal file
@ -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);
|
||||||
17
snes/fatfstest/pad.c
Normal file
17
snes/fatfstest/pad.c
Normal file
@ -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;
|
||||||
|
}
|
||||||
19
snes/fatfstest/pad.h
Normal file
19
snes/fatfstest/pad.h
Normal file
@ -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);
|
||||||
23
snes/fatfstest/ressource.asm
Normal file
23
snes/fatfstest/ressource.asm
Normal file
@ -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
|
||||||
3
snes/fatfstest/ressource.h
Normal file
3
snes/fatfstest/ressource.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
extern word debugFont_pic[];
|
||||||
|
extern word debugFont_pal[];
|
||||||
BIN
snes/fatfstest/ressource/debugFont.clr
Normal file
BIN
snes/fatfstest/ressource/debugFont.clr
Normal file
Binary file not shown.
BIN
snes/fatfstest/ressource/debugFont.pcx
Normal file
BIN
snes/fatfstest/ressource/debugFont.pcx
Normal file
Binary file not shown.
BIN
snes/fatfstest/ressource/debugFont.pic
Normal file
BIN
snes/fatfstest/ressource/debugFont.pic
Normal file
Binary file not shown.
BIN
snes/fatfstest/ressource/debugFont.xcf
Normal file
BIN
snes/fatfstest/ressource/debugFont.xcf
Normal file
Binary file not shown.
@ -126,7 +126,7 @@ link += $(if $(findstring input.rawinput,$(ruby)),$(call mklib,xinput) $(call mk
|
|||||||
objects = libco ruby libfilter string \
|
objects = libco ruby libfilter string \
|
||||||
reader cart cheat \
|
reader cart cheat \
|
||||||
memory smemory cpu scpu smp ssmp sdsp ppu bppu snes \
|
memory smemory cpu scpu smp ssmp sdsp ppu bppu snes \
|
||||||
bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010 cmmio
|
bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010 cmmio fatfs diskio
|
||||||
|
|
||||||
ifeq ($(enable_gzip),true)
|
ifeq ($(enable_gzip),true)
|
||||||
#objects += adler32 compress crc32 deflate gzio inffast inflate inftrees ioapi trees unzip zip zutil
|
#objects += adler32 compress crc32 deflate gzio inffast inflate inftrees ioapi trees unzip zip zutil
|
||||||
@ -237,6 +237,10 @@ obj/dsp4.$(obj) : chip/dsp4/dsp4.cpp chip/dsp4/*
|
|||||||
obj/obc1.$(obj) : chip/obc1/obc1.cpp chip/obc1/*
|
obj/obc1.$(obj) : chip/obc1/obc1.cpp chip/obc1/*
|
||||||
obj/st010.$(obj) : chip/st010/st010.cpp chip/st010/*
|
obj/st010.$(obj) : chip/st010/st010.cpp chip/st010/*
|
||||||
obj/cmmio.$(obj) : chip/cmmio/cmmio.cpp chip/cmmio/*
|
obj/cmmio.$(obj) : chip/cmmio/cmmio.cpp chip/cmmio/*
|
||||||
|
obj/fatfs.$(obj) : chip/fatfs/fatfs.cpp chip/fatfs/*
|
||||||
|
obj/diskio.$(obj) : chip/fatfs/diskio.cpp chip/fatfs/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
############
|
############
|
||||||
|
|||||||
@ -10,3 +10,4 @@
|
|||||||
#include "obc1/obc1.hpp"
|
#include "obc1/obc1.hpp"
|
||||||
#include "st010/st010.hpp"
|
#include "st010/st010.hpp"
|
||||||
#include "cmmio/cmmio.hpp"
|
#include "cmmio/cmmio.hpp"
|
||||||
|
#include "fatfs/fatfs.hpp"
|
||||||
|
|||||||
168
tools/bsnes/chip/fatfs/diskio.cpp
Normal file
168
tools/bsnes/chip/fatfs/diskio.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
|
||||||
|
#include "integer.h"
|
||||||
|
#include "diskio.h"
|
||||||
|
|
||||||
|
static volatile
|
||||||
|
DSTATUS Stat = STA_NOINIT; /* Disk status */
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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 */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
71
tools/bsnes/chip/fatfs/diskio.h
Normal file
71
tools/bsnes/chip/fatfs/diskio.h
Normal file
@ -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
|
||||||
116
tools/bsnes/chip/fatfs/fatfs.cpp
Normal file
116
tools/bsnes/chip/fatfs/fatfs.cpp
Normal file
@ -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<SHARED_SIZE;i++){
|
||||||
|
scratch_buffer[i] = bus.read(SHARED_ADDR + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FATFS::pushMem() {
|
||||||
|
for ( int i=0;i<SHARED_SIZE;i++){
|
||||||
|
bus.write(SHARED_ADDR + i,scratch_buffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 FATFS::mmio_read(unsigned addr) {
|
||||||
|
addr &= 0xffff;
|
||||||
|
if (addr == 0x3016){
|
||||||
|
printf("FATFS::mmio_read retal=%i\n",retval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
return cpu.regs.mdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FATFS::mmio_write(unsigned addr, uint8 data) {
|
||||||
|
addr &= 0xffff;
|
||||||
|
printf("FATFS::mmio_write 0x%04x 0x%02x (%i)\n",addr,data,data);
|
||||||
|
if (addr == 0x3010){
|
||||||
|
switch(data){
|
||||||
|
case CMD_INIT:
|
||||||
|
printf("FATFS::mmio_write CMD_INIT \n");
|
||||||
|
command = CMD_INIT;
|
||||||
|
disk_initialize(0);
|
||||||
|
break;
|
||||||
|
case CMD_READ:
|
||||||
|
printf("FATFS::mmio_write CMD_READ \n");
|
||||||
|
command = CMD_READ;
|
||||||
|
break;
|
||||||
|
case CMD_WRITE:
|
||||||
|
command = CMD_WRITE;
|
||||||
|
printf("FATFS::mmio_write CMD_WRITE \n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
command = CMD_NONE;
|
||||||
|
printf("FATFS::mmio_write CMD_NONE \n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
if (addr >= 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() {
|
||||||
|
}
|
||||||
26
tools/bsnes/chip/fatfs/fatfs.hpp
Normal file
26
tools/bsnes/chip/fatfs/fatfs.hpp
Normal file
@ -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;
|
||||||
37
tools/bsnes/chip/fatfs/integer.h
Normal file
37
tools/bsnes/chip/fatfs/integer.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*-------------------------------------------*/
|
||||||
|
/* Integer type definitions for FatFs module */
|
||||||
|
/*-------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef _INTEGER
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#include <windows.h>
|
||||||
|
#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
|
||||||
@ -24,6 +24,7 @@ DSP4 dsp4;
|
|||||||
OBC1 obc1;
|
OBC1 obc1;
|
||||||
ST010 st010;
|
ST010 st010;
|
||||||
CMMIO cmmio;
|
CMMIO cmmio;
|
||||||
|
FATFS fatfs;
|
||||||
#include "scheduler/scheduler.cpp"
|
#include "scheduler/scheduler.cpp"
|
||||||
#include "tracer/tracer.cpp"
|
#include "tracer/tracer.cpp"
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ void SNES::power() {
|
|||||||
if(cartridge.has_st010()) st010.power();
|
if(cartridge.has_st010()) st010.power();
|
||||||
|
|
||||||
cmmio.power();
|
cmmio.power();
|
||||||
|
fatfs.power();
|
||||||
|
|
||||||
for(unsigned i = 0x2100; i <= 0x213f; i++) memory::mmio.map(i, ppu);
|
for(unsigned i = 0x2100; i <= 0x213f; i++) memory::mmio.map(i, ppu);
|
||||||
for(unsigned i = 0x2140; i <= 0x217f; i++) memory::mmio.map(i, cpu);
|
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();
|
if(cartridge.has_st010()) st010.enable();
|
||||||
|
|
||||||
cmmio.enable();
|
cmmio.enable();
|
||||||
|
fatfs.enable();
|
||||||
|
|
||||||
input.port_set_device(0, snes.config.controller_port1);
|
input.port_set_device(0, snes.config.controller_port1);
|
||||||
input.port_set_device(1, snes.config.controller_port2);
|
input.port_set_device(1, snes.config.controller_port2);
|
||||||
|
|||||||
@ -5,63 +5,22 @@
|
|||||||
static volatile
|
static volatile
|
||||||
DSTATUS Stat = STA_NOINIT; /* Disk status */
|
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
|
/* Interface
|
||||||
|
|
||||||
** Scratch Buffer
|
** Scratch Buffer
|
||||||
|
|
||||||
addr 3 byte
|
addr 3 byte
|
||||||
size 1 byte
|
size 1 byte
|
||||||
|
|
||||||
** Call Interface
|
** Call Interface
|
||||||
|
|
||||||
cmd 1 byte
|
cmd 1 byte
|
||||||
sector 4 bytes
|
sector 4 bytes
|
||||||
count 1 byte
|
count 1 byte
|
||||||
return 1 byte
|
return 1 byte
|
||||||
|
|
||||||
** Commands
|
** Commands
|
||||||
|
|
||||||
* disk_init
|
* disk_init
|
||||||
* disk_read
|
* disk_read
|
||||||
* disk_write
|
* disk_write
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
@ -77,7 +36,6 @@ return 1 byte
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#define IMAGE_NAME "disk00.vfat"
|
#define IMAGE_NAME "disk00.vfat"
|
||||||
|
|
||||||
char *image_addr;
|
char *image_addr;
|
||||||
@ -86,8 +44,6 @@ DSTATUS disk_initialize (BYTE drv) {
|
|||||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||||
|
|
||||||
Stat |= STA_NOINIT;
|
Stat |= STA_NOINIT;
|
||||||
/* map image */
|
|
||||||
|
|
||||||
|
|
||||||
int fd = open(IMAGE_NAME, O_RDWR);
|
int fd = open(IMAGE_NAME, O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -95,12 +51,10 @@ DSTATUS disk_initialize (BYTE drv) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int size = lseek(fd,0,SEEK_END);
|
int size = lseek(fd,0,SEEK_END);
|
||||||
lseek(fd,0,SEEK_SET);
|
lseek(fd,0,SEEK_SET);
|
||||||
printf("Open Image (size %i)\n",size);
|
printf("Open Image (size %i)\n",size);
|
||||||
|
|
||||||
|
|
||||||
image_addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
image_addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (image_addr == MAP_FAILED) {
|
if (image_addr == MAP_FAILED) {
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -140,11 +94,8 @@ DRESULT disk_read (
|
|||||||
|
|
||||||
DWORD offset = sector * 512;
|
DWORD offset = sector * 512;
|
||||||
int size = count * 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);
|
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);
|
memcpy(buff,image_addr + offset,size);
|
||||||
//printf("%x %x %x %x\n",buff[0],buff[1],buff[2],buff[3]);
|
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,16 +111,12 @@ DRESULT disk_write (
|
|||||||
BYTE count /* Sector count (1..255) */
|
BYTE count /* Sector count (1..255) */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE s, c, iowr_l, iowr_h;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (drv || !count) return RES_PARERR;
|
if (drv || !count) return RES_PARERR;
|
||||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||||
|
|
||||||
DWORD offset = sector * 512;
|
DWORD offset = sector * 512;
|
||||||
int size = count * 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);
|
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);
|
memcpy(image_addr + offset,buff,size);
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
@ -209,38 +156,9 @@ DRESULT disk_ioctl (
|
|||||||
*(DWORD*)buff = 32;
|
*(DWORD*)buff = 32;
|
||||||
return RES_OK;
|
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:
|
default:
|
||||||
return RES_PARERR;
|
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;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
#endif /* _USE_IOCTL != 0 */
|
#endif /* _USE_IOCTL != 0 */
|
||||||
|
|||||||
@ -2,6 +2,11 @@
|
|||||||
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
|
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
|
||||||
/-----------------------------------------------------------------------*/
|
/-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _DISKIO
|
#ifndef _DISKIO
|
||||||
|
|
||||||
#define _READONLY 0 /* 1: Read-only mode */
|
#define _READONLY 0 /* 1: Read-only mode */
|
||||||
@ -56,26 +61,11 @@ void disk_timerproc (void);
|
|||||||
#define CTRL_POWER 4
|
#define CTRL_POWER 4
|
||||||
#define CTRL_LOCK 5
|
#define CTRL_LOCK 5
|
||||||
#define CTRL_EJECT 6
|
#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
|
#define _DISKIO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -81,13 +81,13 @@
|
|||||||
/* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk */
|
/* 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
|
/* 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,
|
/ 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[]. */
|
/ 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.
|
/* 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
|
/ 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.
|
/ pages. When LFN is enabled, the code page must always be set correctly.
|
||||||
|
|||||||
Binary file not shown.
@ -241,22 +241,6 @@ int main (void)
|
|||||||
{ printf("Sector size: %u\n", w1); }
|
{ printf("Sector size: %u\n", w1); }
|
||||||
if (disk_ioctl((BYTE)p1, GET_BLOCK_SIZE, &p2) == RES_OK)
|
if (disk_ioctl((BYTE)p1, GET_BLOCK_SIZE, &p2) == RES_OK)
|
||||||
{ printf("Erase block size: %lu sectors\n", p2); }
|
{ printf("Erase block size: %lu sectors\n", p2); }
|
||||||
if (disk_ioctl((BYTE)p1, MMC_GET_TYPE, &b1) == RES_OK)
|
|
||||||
{ printf("Card type: %u\n", b1); }
|
|
||||||
if (disk_ioctl((BYTE)p1, MMC_GET_CSD, Buff) == RES_OK)
|
|
||||||
{ printf("CSD:\n"); put_dump(Buff, 0, 16); }
|
|
||||||
if (disk_ioctl((BYTE)p1, MMC_GET_CID, Buff) == RES_OK)
|
|
||||||
{ printf("CID:\n"); put_dump(Buff, 0, 16); }
|
|
||||||
if (disk_ioctl((BYTE)p1, MMC_GET_OCR, Buff) == RES_OK)
|
|
||||||
{ printf("OCR:\n"); put_dump(Buff, 0, 4); }
|
|
||||||
if (disk_ioctl((BYTE)p1, MMC_GET_SDSTAT, Buff) == RES_OK) {
|
|
||||||
printf("SD Status:\n");
|
|
||||||
for (s1 = 0; s1 < 64; s1 += 16) put_dump(Buff+s1, s1, 16);
|
|
||||||
}
|
|
||||||
if (disk_ioctl((BYTE)p1, ATA_GET_MODEL, line) == RES_OK)
|
|
||||||
{ line[40] = '\0'; printf("Model: %s\n", line); }
|
|
||||||
if (disk_ioctl((BYTE)p1, ATA_GET_SN, line) == RES_OK)
|
|
||||||
{ line[20] = '\0'; printf("S/N: %s\n", line); }
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user