Adding libcartreset, fixing CD audio bug, adding DLDI support (defined out all other fat drivers)

svn-id: r25124
This commit is contained in:
Neil Millstone 2007-01-19 21:47:10 +00:00
parent 31abbc14ae
commit fe9682ac55
13 changed files with 401 additions and 46 deletions

View File

@ -118,7 +118,8 @@ LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt
INCLUDES= -I./ -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/common -I$(portdir)/source -I$(portdir)/source/compressor -I$(portdir)/source/fat \
-I$(srcdir)/backends/fs -I$(srcdir)/backends/fs/ds -I$(portdir)/data -I$(libndsdir)/include -I$(portdir)/../commoninclude\
-I$(srcdir)/scumm -I$(libndsdir)/include -I$(libndsdir)/include/nds -I$(srcdir)/engines -I$(portdir)/source/mad
-I$(srcdir)/scumm -I$(libndsdir)/include -I$(libndsdir)/include/nds -I$(srcdir)/engines -I$(portdir)/source/mad\
-I$(portdir)/source/libcartreset
LIBS = -lm -L$(libndsdir)/lib -L$(portdir)/lib -lnds9
@ -172,16 +173,19 @@ FAT_OBJS := $(portdir)/source/fat/disc_io.o $(portdir)/source/fat/gba_nds_fat.o
$(portdir)/source/fat/io_mmcf.o \
$(portdir)/source/fat/io_sd_common.o \
$(portdir)/source/fat/io_m3_common.o \
$(portdir)/source/fat/io_dldi.o \
$(portdir)/source/fat/m3sd.o
# $(portdir)/source/fat/io_cf_common.o $(portdir)/source/fat/io_m3_common.o\
# $(portdir)/source/fat/io_sd_common.o $(portdir)/source/fat/io_scsd_s.o \
# $(portdir)/source/fat/io_sc_common.o $(portdir)/source/fat/io_sd_common.o
LIBCARTRESET_OBJS := $(portdir)/source/libcartreset/cartreset.o
OBJS := $(DATA_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS)
OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS)

View File

@ -114,7 +114,7 @@ void allocBuffers() {
}
void setActive(bool active) {
active = active;
DS::CD::active = active;
}
bool getActive() {
@ -232,7 +232,7 @@ void playTrack(int track, int numLoops, int startFrame, int duration) {
//decompressBlock();
playNextBlock();
numLoops = numLoops;
DS::CD::numLoops = numLoops;
}
void update() {

View File

@ -43,6 +43,7 @@
// - Software scaler?
// - 100% scale
#define USE_LIBCARTRESET
#include <nds.h>
@ -71,6 +72,7 @@
#include "ramsave.h"
#include "disc_io.h"
#include "blitters.h"
#include "cartreset_nolibfat.h"
namespace DS {
@ -2035,6 +2037,58 @@ void debug_print_stub(char *string) {
}
#endif
#ifdef USE_LIBCARTRESET
void reboot() {
int deviceType = -1;
switch (disc_getDeviceId()) {
case DEVICE_M3SD: {
deviceType = DEVICE_TYPE_M3SD;
break;
}
case DEVICE_MMCF: {
deviceType = -1;
break;
}
case DEVICE_M3CF: {
deviceType = DEVICE_TYPE_M3CF;
break;
}
case DEVICE_MPCF: {
deviceType = DEVICE_TYPE_MPCF;
break;
}
case DEVICE_SCCF: {
deviceType = DEVICE_TYPE_SCCF;
break;
}
case DEVICE_NJSD: {
deviceType = -1;
break;
}
case DEVICE_SCSD: {
deviceType = DEVICE_TYPE_SCSD;
break;
}
case DEVICE_NMMC: {
deviceType = DEVICE_TYPE_NMMC;
break;
}
}
consolePrintf("Device: %x\n", deviceType);
if (deviceType == -1) {
IPC->reset = true; // Send message to ARM7 to turn power off
} else {
cartSetMenuMode(deviceType);
passmeloopEnter();
}
while (true); // Stop the program continuing beyond this point
}
#endif
void powerOff() {
while (keysHeld() != 0) { // Wait for all keys to be released.
swiWaitForVBlank(); // Allow you to read error before the power
@ -2047,8 +2101,13 @@ void powerOff() {
if (ConfMan.hasKey("disablepoweroff", "ds") && ConfMan.getBool("disablepoweroff", "ds")) {
while (true);
} else {
#ifdef USE_LIBCARTRESET
reboot();
#else
IPC->reset = true; // Send message to ARM7 to turn power off
while (true); // Stop the program continuing beyond this point
#endif
}
}
@ -2059,11 +2118,12 @@ void powerOff() {
int main(void)
{
soundCallback = NULL;
initHardware();
#ifdef USE_DEBUGGER
for (int r = 0; r < 150; r++) {
swiWaitForVBlank();

View File

@ -77,6 +77,8 @@
#include "io_mmcf.h"
#endif
#include "io_dldi.h"
// Keep a pointer to the active interface
LPIO_INTERFACE active_interface = 0;
@ -104,6 +106,8 @@ static struct {
u32 count;
} cache[ DISC_CACHE_COUNT ];
FATDevice currentDevice;
static u32 disc_CacheFind(u32 sector) {
u32 i;
@ -245,6 +249,7 @@ bool disc_setGbaSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set M3 SD as default IO
currentDevice = DEVICE_M3SD;
return true ;
} ;
}
@ -259,6 +264,7 @@ bool disc_setGbaSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set MMCF as default IO
currentDevice = DEVICE_MMCF;
return true ;
} ;
#endif
@ -271,6 +277,7 @@ bool disc_setGbaSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set M3 CF as default IO
currentDevice = DEVICE_M3CF;
return true ;
} ;
#endif
@ -282,6 +289,7 @@ bool disc_setGbaSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set GBAMP as default IO
currentDevice = DEVICE_MPCF;
return true ;
} ;
#endif
@ -293,6 +301,7 @@ bool disc_setGbaSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set SC CF as default IO
currentDevice = DEVICE_SCCF;
return true ;
} ;
#endif
@ -325,6 +334,11 @@ bool disc_setGbaSlotInterface (void)
return false;
}
FATDevice disc_getDeviceId() {
return currentDevice;
}
#ifdef NDS
// Check the DS card slot for a valid memory card interface
// If an interface is found, it is set as the default interace
@ -339,6 +353,16 @@ bool disc_setDsSlotInterface (void)
WAIT_CR |= (1<<11);
#endif
active_interface = DLDI_GetInterface();
if (active_interface->fn_StartUp()) {
consolePrintf("DLDI Driver Initialised OK!\n");
currentDevice = DEVICE_DLDI;
return true;
} else {
consolePrintf("DLDI Initialise failed.\n");
}
#ifdef SUPPORT_SCSD
// check if we have a SuperCard SD plugged in
if (discDetect == 2) {
@ -347,6 +371,7 @@ bool disc_setDsSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set SC SD as default IO
currentDevice = DEVICE_SCSD;
return true ;
} ;
}
@ -358,6 +383,7 @@ bool disc_setDsSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set NJSD as default IO
currentDevice = DEVICE_NJSD;
return true ;
} ;
#endif
@ -368,6 +394,7 @@ bool disc_setDsSlotInterface (void)
if (active_interface->fn_StartUp())
{
// set Neoflash MK2 / MK3 as default IO
currentDevice = DEVICE_NMMC;
return true ;
} ;
#endif

View File

@ -15,16 +15,18 @@
// Device support options, added by www.neoflash.com
#define SUPPORT_NMMC // comment out this line to remove Neoflash MK2 MMC Card support
#define SUPPORT_MPCF // comment out this line to remove GBA Movie Player support
#define SUPPORT_M3CF // comment out this line to remove M3 Perfect CF support
#define SUPPORT_M3SD // comment out this line to remove M3 Perfect SD support
#define SUPPORT_SCCF // comment out this line to remove Supercard CF support
#define SUPPORT_SCSD // comment out this line to remove Supercard SD support
//#define SUPPORT_MPCF // comment out this line to remove GBA Movie Player support
//#define SUPPORT_M3CF // comment out this line to remove M3 Perfect CF support
//#define SUPPORT_M3SD // comment out this line to remove M3 Perfect SD support
//#define SUPPORT_SCCF // comment out this line to remove Supercard CF support
//#define SUPPORT_SCSD // comment out this line to remove Supercard SD support
//#define SUPPORT_NJSD
//#define SUPPORT_MMCF
//#define SUPPORT_EFA2 // comment out this line to remove EFA2 linker support
#define SUPPORT_FCSR // comment out this line to remove GBA Flash Cart support
#define SUPPORT_NJSD
#define SUPPORT_MMCF
//#define SUPPORT_FCSR // comment out this line to remove GBA Flash Cart support
//#define SUPPORT_NMMC // comment out this line to remove Neoflash MK2 MMC Card support
// Disk caching options, added by www.neoflash.com
// Each additional sector cache uses 512 bytes of memory
@ -72,6 +74,20 @@
extern "C" {
#endif
typedef enum {
DEVICE_NONE = 0,
DEVICE_M3SD,
DEVICE_MMCF,
DEVICE_M3CF,
DEVICE_MPCF,
DEVICE_SCCF,
DEVICE_NJSD,
DEVICE_SCSD,
DEVICE_NMMC,
DEVICE_DLDI
} FATDevice;
/*-----------------------------------------------------------------
disc_Init
Detects the inserted hardware and initialises it if necessary
@ -88,6 +104,8 @@ extern bool disc_IsInserted(void) ;
extern void disc_setEnable(int en);
extern FATDevice disc_getDeviceId();
/*-----------------------------------------------------------------
disc_ReadSectors
Read 512 byte sector numbered "sector" into "buffer"
@ -161,6 +179,7 @@ static inline bool disc_CacheFlush(void)
#define FEATURE_SLOT_GBA 0x00000010
#define FEATURE_SLOT_NDS 0x00000020
typedef bool (* FN_MEDIUM_STARTUP)(void) ;
typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
typedef bool (* FN_MEDIUM_READSECTORS)(u32 sector, u8 numSecs, void* buffer) ;

View File

@ -0,0 +1,34 @@
/*
io_dldi.h
Reserved space for new drivers
This software is completely free. No warranty is provided.
If you use it, please give me credit and email me about your
project at chishm@hotmail.com
See gba_nds_fat.txt for help and license details.
*/
#ifndef IO_DLDI_H
#define IO_DLDI_H
// 'DLDI'
#define DEVICE_TYPE_DLDD 0x49444C44
#include "disc_io.h"
#ifdef NDS
#include <nds/memory.h>
#endif
extern IO_INTERFACE _io_dldi;
// export interface
static inline LPIO_INTERFACE DLDI_GetInterface(void) {
#ifdef NDS
WAIT_CR &= ~(ARM9_OWNS_ROM | ARM9_OWNS_CARD);
#endif // defined NDS
return &_io_dldi;
}
#endif // define IO_DLDI_H

View File

@ -0,0 +1,70 @@
@---------------------------------------------------------------------------------
.align 4
.arm
.global _io_dldi
@---------------------------------------------------------------------------------
.equ FEATURE_MEDIUM_CANREAD, 0x00000001
.equ FEATURE_MEDIUM_CANWRITE, 0x00000002
.equ FEATURE_SLOT_GBA, 0x00000010
.equ FEATURE_SLOT_NDS, 0x00000020
@---------------------------------------------------------------------------------
@ Driver patch file standard header -- 16 bytes
.word 0xBF8DA5ED @ Magic number to identify this region
.asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator)
.byte 0x01 @ Version number
.byte 0x0F @32KiB @ Log [base-2] of the size of this driver in bytes.
.byte 0x00 @ Sections to fix
.byte 0x0F @32KiB @ Log [base-2] of the allocated space in bytes.
@---------------------------------------------------------------------------------
@ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes
.align 4
.asciz "Default (No interface)"
@---------------------------------------------------------------------------------
@ Offsets to important sections within the data -- 32 bytes
.align 6
.word 0x00000000 @ data start
.word 0x00000000 @ data end
.word 0x00000000 @ Interworking glue start -- Needs address fixing
.word 0x00000000 @ Interworking glue end
.word 0x00000000 @ GOT start -- Needs address fixing
.word 0x00000000 @ GOT end
.word 0x00000000 @ bss start -- Needs setting to zero
.word 0x00000000 @ bss end
@---------------------------------------------------------------------------------
@ IO_INTERFACE data -- 32 bytes
_io_dldi:
.ascii "DLDI" @ ioType
.word 0x00000000 @ Features
.word _DLDI_startup @
.word _DLDI_isInserted @
.word _DLDI_readSectors @ Function pointers to standard device driver functions
.word _DLDI_writeSectors @
.word _DLDI_clearStatus @
.word _DLDI_shutdown @
@---------------------------------------------------------------------------------
_DLDI_startup:
_DLDI_isInserted:
_DLDI_readSectors:
_DLDI_writeSectors:
_DLDI_clearStatus:
_DLDI_shutdown:
mov r0, #0x00 @ Return false for every function
bx lr
@---------------------------------------------------------------------------------
.align
.pool
.space 32632 @ Fill to 32KiB
.end
@---------------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
#define io_M3SD_c
#include "io_m3sd.h"
#ifdef SUPPORT_M3SD
//M3-SD interface SD card.
#define DMA3SAD *(volatile u32*)0x040000D4
@ -379,3 +379,5 @@ LPIO_INTERFACE M3SD_GetInterface(void)
{
return &io_m3sd ;
}
#endif

View File

@ -35,6 +35,7 @@
#include "io_njsd.h"
#ifdef SUPPORT_NJSD
#ifdef NDS
#include <nds.h>
@ -677,3 +678,4 @@ LPIO_INTERFACE NJSD_GetInterface(void) {
} ;
#endif // defined NDS
#endif

View File

@ -26,6 +26,8 @@
#include "io_scsd.h"
#ifdef SUPPORT_SCSD
/*-----------------------------------------------------------------
Since all CF addresses and commands are the same for the GBAMP,
simply use it's functions instead.
@ -101,3 +103,4 @@ LPIO_INTERFACE SCSD_GetInterface(void) {
return &io_scsd ;
} ;
#endif

View File

@ -26,33 +26,4 @@
// export interface
extern LPIO_INTERFACE SCSD_GetInterface(void) ;
#endif // define IO_SCSD_H
/*
io_scsd.h by SaTa.
based on io_sccf.h
*/
/*
io_sccf.h
Hardware Routines for reading a compact flash card
using the GBA Movie Player
This software is completely free. No warranty is provided.
If you use it, please give me credit and email me about your
project at chishm@hotmail.com
See gba_nds_fat.txt for help and license details.
*/
#ifndef IO_SCSD_H
#define IO_SCSD_H
#include "disc_io.h"
// export interface
extern LPIO_INTERFACE SCSD_GetInterface(void) ;
#endif // define IO_SCSD_H
#endif // define IO_SCSD_H

View File

@ -0,0 +1,107 @@
/**********************************
Copyright (C) Rick Wong (Lick)
http://licklick.wordpress.com/
***********************************/
#include <cartreset_nolibfat.h>
#ifdef ARM9
bool cartSetMenuMode(u32 _deviceType)
{
*(vu16*)(0x04000204) &= ~0x0880; //sysSetBusOwners(true, true);
u32 deviceType = _deviceType;
*((vu32*)0x027FFFF8) = 0x080000C0; // ARM7 reset address
if(deviceType == DEVICE_TYPE_EFA2)
{
*(u16 *)0x9FE0000 = 0xD200;
*(u16 *)0x8000000 = 0x1500;
*(u16 *)0x8020000 = 0xD200;
*(u16 *)0x8040000 = 0x1500;
*(u16 *)0x9880000 = 1 << 15;
*(u16 *)0x9FC0000 = 0x1500;
return true;
}
else if(deviceType == DEVICE_TYPE_MPCF)
{
return true;
}
else if(deviceType == DEVICE_TYPE_EZSD)
{
return true;
}
else if(deviceType == DEVICE_TYPE_M3CF || deviceType == DEVICE_TYPE_M3SD)
{
u32 mode = 0x00400004;
vu16 tmp;
tmp = *(vu16*)(0x08E00002);
tmp = *(vu16*)(0x0800000E);
tmp = *(vu16*)(0x08801FFC);
tmp = *(vu16*)(0x0800104A);
tmp = *(vu16*)(0x08800612);
tmp = *(vu16*)(0x08000000);
tmp = *(vu16*)(0x08801B66);
tmp = *(vu16*)(0x08000000 + (mode << 1));
tmp = *(vu16*)(0x0800080E);
tmp = *(vu16*)(0x08000000);
tmp = *(vu16*)(0x080001E4);
tmp = *(vu16*)(0x080001E4);
tmp = *(vu16*)(0x08000188);
tmp = *(vu16*)(0x08000188);
return true;
}
else if(deviceType == DEVICE_TYPE_SCCF || deviceType == DEVICE_TYPE_SCSD)
{
*(vu16*)0x09FFFFFE = 0xA55A;
*(vu16*)0x09FFFFFE = 0xA55A;
*(vu16*)0x09FFFFFE = 0;
*(vu16*)0x09FFFFFE = 0;
*((vu32*)0x027FFFF8) = 0x08000000; // Special ARM7 reset address
return true;
}
return false;
}
void passmeloopEnter()
{
*(vu16*)(0x04000208) = 0; //REG_IME = IME_DISABLE;
*(vu16*)(0x04000204) |= 0x0880; //sysSetBusOwners(false, false);
*((vu32*)0x027FFFFC) = 0;
*((vu32*)0x027FFE04) = (u32)0xE59FF018;
*((vu32*)0x027FFE24) = (u32)0x027FFE04;
asm("swi 0x00"); //swiSoftReset();
asm("bx lr");
}
#endif
#ifdef ARM7
bool passmeloopQuery()
{
if(*((vu32*)0x027FFE24) == (u32)0x027FFE04)
return true;
return false;
}
void cartExecute()
{
*(vu16*)(0x04000208) = 0; //REG_IME = IME_DISABLE;
*((vu32*)0x027FFE34) = *((vu32*)0x027FFFF8);
asm("swi 0x00"); //swiSoftReset();
asm("bx lr");
}
#endif

View File

@ -0,0 +1,56 @@
/**********************************
Copyright (C) Rick Wong (Lick)
http://licklick.wordpress.com/
***********************************/
#ifndef CARTRESET_H
#define CARTRESET_H
#include <fat.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ARM9
// Auto detect:
#define DEVICE_TYPE_AUTO 0x00000000 // doesn't work in libcartreset "nolibfat" version
// Not supported:
#define DEVICE_TYPE_FCSR 0x52534346
#define DEVICE_TYPE_MMCF 0x46434D4D
#define DEVICE_TYPE_NJSD 0x44534A4E
#define DEVICE_TYPE_NMMC 0x434D4D4E
// Supported:
#define DEVICE_TYPE_EFA2 0x32414645
#define DEVICE_TYPE_MPCF 0x4643504D
#define DEVICE_TYPE_M3CF 0x4643334D
#define DEVICE_TYPE_M3SD 0x4453334D
#define DEVICE_TYPE_SCCF 0x46434353
#define DEVICE_TYPE_SCSD 0x44534353
// Supported, but libfat doesn't detect the device:
#define DEVICE_TYPE_EZSD 0x44535A45
bool cartSetMenuMode(u32 _deviceType);
void passmeloopEnter();
#endif
#ifdef ARM7
bool passmeloopQuery();
void cartExecute();
#endif
#ifdef __cplusplus
}
#endif
#endif