GBA NDS FAT

From DLDIWiki

Jump to: navigation, search

gba_nds_fat was the first attempt by Chishm at a FAT file system library for the DS and GBA. It has bugs that can cause corruption of the file system of a memory card and has been deprecated in favour of libfat. It does not have built in support for DLDI, but it can be added by an application's developer.

[edit] Adding support for DLDI

Save the following as io_dldi.h:

/*
	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_DLDI 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

Save the following as io_dldi.s:

@---------------------------------------------------------------------------------
	.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


_dldi_start:

@---------------------------------------------------------------------------------
@ 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   _dldi_start		@ data start
	.word   _dldi_end		@ 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

_dldi_end:
	.end
@---------------------------------------------------------------------------------

Put both of these files into your gba_nds_fat source directory.

In disc_io.c, under the line // Include known io-interfaces:, add the line #include "io_mpcf.h".

In the function bool disc_setGbaSlotInterface (void) add the following code before the line #ifdef SUPPORT_M3CF:

// check if we have a valid DLDI driver
active_interface = DLDI_GetInterface() ;
if (active_interface->fn_StartUp())
{
	// set the DLDI driver as the default IO
	return true ;
} ;

In the function bool disc_setDsSlotInterface (void) add the same block of code just before the line #ifdef SUPPORT_NMMC.

You should now be able to patch your application with DLDI files.

Personal tools