├── .gitignore ├── Makefile ├── data └── amiga.fnt ├── include ├── BoyScout.h ├── disc.h ├── disc_io.h ├── dldi.h ├── erapi.h ├── fade.h ├── gba.h ├── gba_affine.h ├── gba_base.h ├── gba_compression.h ├── gba_console.h ├── gba_dma.h ├── gba_input.h ├── gba_interrupt.h ├── gba_multiboot.h ├── gba_sio.h ├── gba_sound.h ├── gba_sprites.h ├── gba_systemcalls.h ├── gba_timers.h ├── gba_types.h ├── gba_video.h ├── mappy.h ├── mbv2.h ├── xcomms.h └── xcomms_cmd.h ├── libgba.dox ├── libgba_license.txt └── src ├── AffineSet.c ├── ArcTan.s ├── BoyScout ├── BoyScout.c └── GBASoundRegs.h ├── Compression.c ├── CpuSet.c ├── Div.s ├── DivArm.s ├── InterruptDispatcher.s ├── IntrWait.c ├── MultiBoot.s ├── Reset.s ├── Sound.s ├── Sqrt.s ├── console.c ├── disc_io ├── disc.c ├── dldi.c ├── dldi_stub.s ├── io_cf_common.c ├── io_cf_common.h ├── io_m3_common.c ├── io_m3_common.h ├── io_m3cf.c ├── io_m3cf.h ├── io_m3sd.c ├── io_m3sd.h ├── io_mpcf.c ├── io_mpcf.h ├── io_sc_common.c ├── io_sc_common.h ├── io_sccf.c ├── io_sccf.h ├── io_scsd.c ├── io_scsd.h ├── io_scsd_s.s ├── io_sd_common.c └── io_sd_common.h ├── fade.c ├── input.c ├── interrupt.c ├── mappy_print.c ├── mbv2.c ├── mbv2.txt ├── mbv2print.c ├── xcomms.c └── xcomms_print.c /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | lib 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | ifeq ($(strip $(DEVKITARM)),) 5 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM) 6 | endif 7 | ifeq ($(strip $(DEVKITPRO)),) 8 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPro) 9 | endif 10 | include $(DEVKITARM)/gba_rules 11 | 12 | BUILD := build 13 | SOURCES := src src/BoyScout src/disc_io 14 | INCLUDES := include build 15 | DATA := data 16 | 17 | 18 | export LIBGBA_MAJOR := 0 19 | export LIBGBA_MINOR := 5 20 | export LIBGBA_PATCH := 4 21 | 22 | VERSION := $(LIBGBA_MAJOR).$(LIBGBA_MINOR).$(LIBGBA_PATCH) 23 | 24 | ARCH := -march=armv4t -mtune=arm7tdmi -mthumb 25 | 26 | #--------------------------------------------------------------------------------- 27 | # options for code generation 28 | #--------------------------------------------------------------------------------- 29 | CFLAGS := -g -O3 -Wall -Wno-switch -Wno-multichar $(ARCH) $(INCLUDE) 30 | ASFLAGS := -g -Wa,--warn $(ARCH) 31 | 32 | #--------------------------------------------------------------------------------- 33 | ifneq ($(BUILD),$(notdir $(CURDIR))) 34 | 35 | export TARGET := $(CURDIR)/lib/libgba.a 36 | 37 | export VPATH := $(foreach dir,$(DATA),$(CURDIR)/$(dir)) $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) 38 | 39 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 40 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 41 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 42 | 43 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 44 | 45 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 46 | 47 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 48 | 49 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 50 | 51 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) 52 | export DEPSDIR := $(CURDIR)/build 53 | 54 | .PHONY: $(BUILD) clean docs 55 | 56 | $(BUILD): 57 | @[ -d lib ] || mkdir -p lib 58 | @[ -d $@ ] || mkdir -p $@ 59 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 60 | 61 | docs: 62 | doxygen libgba.dox 63 | 64 | clean: 65 | @echo clean ... 66 | @rm -fr $(BUILD) *.tar.bz2 67 | 68 | install: $(BUILD) 69 | mkdir -p $(DESTDIR)$(DEVKITPRO)/libgba 70 | cp -rv include lib libgba_license.txt $(DESTDIR)$(DEVKITPRO)/libgba 71 | 72 | #--------------------------------------------------------------------------------- 73 | else 74 | 75 | DEPENDS := $(OFILES:.o=.d) 76 | 77 | #--------------------------------------------------------------------------------- 78 | $(TARGET): $(OFILES) 79 | 80 | $(OFILES_SRC) : $(HFILES) 81 | 82 | #--------------------------------------------------------------------------------- 83 | %_fnt.h %.fnt.o : %.fnt 84 | $(SILENTMSG) $(notdir $<) 85 | $(SILENTCMD) $(bin2o) 86 | 87 | -include $(DEPENDS) 88 | 89 | endif 90 | #--------------------------------------------------------------------------------- 91 | -------------------------------------------------------------------------------- /data/amiga.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devkitPro/libgba/f0e44ce9ed57e1d21f148443223408fddeacfb9d/data/amiga.fnt -------------------------------------------------------------------------------- /include/BoyScout.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // File: BoyScout.h // 3 | // // 4 | // Description: Header file for BoyScout music playback on the GameBoy. // 5 | // // 6 | // Author: Christer Andersson (c) 2001 // 7 | // Addon: Willem Kokke // 8 | // // 9 | ////////////////////////////////////////////////////////////////////////// 10 | 11 | ////////////////////////////////////////////////////////////// 12 | // New section of functions were written by Willem Kokke. // 13 | // He also fixed a silly miss in the wave RAM copy of the // 14 | // v.0.93 playback libraries. Thanks alot mate :O) // 15 | // // 16 | // / Christer // 17 | ////////////////////////////////////////////////////////////// 18 | 19 | // Make sure header is only included once 20 | #ifndef HEADER_BOYSCOUT_H 21 | #define HEADER_BOYSCOUT_H 22 | 23 | // DEFINES //////// 24 | 25 | #define PATTERN_PARAMETER_EMPTY 10000 26 | 27 | #define SOUND_CHANNEL_COUNT 4 28 | 29 | #define SOUND1_PARAMETER_COUNT 7 30 | #define SOUND2_PARAMETER_COUNT 5 31 | #define SOUND3_PARAMETER_COUNT 4 32 | #define SOUND4_PARAMETER_COUNT 7 33 | 34 | // Play states 35 | #define PLAYSTATE_STOP 1 36 | #define PLAYSTATE_PLAY 2 37 | #define PLAYSTATE_LOOP 4 38 | 39 | 40 | // STRUCTS //////// 41 | 42 | // Iterator for traversing compressed data 43 | typedef struct SRLEIterator 44 | { 45 | unsigned char *pData; 46 | unsigned char iValue; 47 | unsigned char mask; 48 | unsigned char cValue; 49 | short nValue; 50 | unsigned char iValuePos; 51 | } SRLEIterator; 52 | 53 | // Sound 1 pattern 54 | typedef struct 55 | { 56 | unsigned short nLength; 57 | unsigned char *apParams[SOUND1_PARAMETER_COUNT]; 58 | } SSound1Pattern; 59 | 60 | // Sound 2 pattern 61 | typedef struct 62 | { 63 | unsigned short nLength; 64 | unsigned char *apParams[SOUND2_PARAMETER_COUNT]; 65 | } SSound2Pattern; 66 | 67 | // Sound 3 pattern 68 | typedef struct 69 | { 70 | unsigned short nLength; 71 | unsigned char *apParams[SOUND3_PARAMETER_COUNT]; 72 | } SSound3Pattern; 73 | 74 | // Sound 4 pattern 75 | typedef struct 76 | { 77 | unsigned short nLength; 78 | unsigned char *apParams[SOUND4_PARAMETER_COUNT]; 79 | } SSound4Pattern; 80 | 81 | // PROTOTYPES ///// 82 | 83 | void RLEISet(unsigned char *pData, SRLEIterator *pRLEIterator); 84 | void RLEINext(SRLEIterator *pRLEIterator); 85 | 86 | void BoyScoutInitialize(); 87 | void BoyScoutOpenSong(const unsigned char *pSongData); 88 | void BoyScoutPlaySong(int nLoop); 89 | void BoyScoutStopSong(); 90 | unsigned short BoyScoutGetNeededSongMemory(const unsigned char *pSongData); 91 | void BoyScoutSetMemoryArea(unsigned int nMemoryAddress); 92 | unsigned int BoyScoutGetMemoryArea(); 93 | int BoyScoutUpdateSong(); 94 | 95 | void DMA3Copy32(unsigned int Src, unsigned int Dst, unsigned short Count); 96 | 97 | // WK Set to 1 to use dma, or to 0 to use software copy 98 | // Software copy is the preffered option, it's faster and more stable 99 | #define USE_DMA 0 100 | 101 | // WK some functions to manipulate the speed of the original song 102 | // You directly manipulate the time a beat takes 103 | // a beat takes x/60, where x is the value you give 104 | // increasing this value slows the song down, decreasing speeds it up 105 | 106 | // TODO? move the timing to a timer to get a better control through increades granularity 107 | 108 | unsigned char BoyScoutGetNormalSpeed(); 109 | unsigned char BoyScoutGetSpeed(); 110 | 111 | void BoyScoutIncSpeed(unsigned char speed); 112 | void BoyScoutDecSpeed(unsigned char speed); 113 | void BoyScoutSetSpeed(unsigned char speed); 114 | 115 | 116 | // WK some functions to mute individual channels 117 | void BoyScoutMuteChannel1(int mute); 118 | void BoyScoutMuteChannel2(int mute); 119 | void BoyScoutMuteChannel3(int mute); 120 | void BoyScoutMuteChannel4(int mute); 121 | 122 | #endif 123 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /include/disc.h: -------------------------------------------------------------------------------- 1 | /* 2 | disc.h 3 | 4 | Copyright (c) 2008 Michael "Chishm" Chisholm 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 3. The name of the author may not be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | #ifndef GBA_DISC_INCLUDE 30 | #define GBA_DISC_INCLUDE 31 | 32 | #include "disc_io.h" 33 | 34 | extern const DISC_INTERFACE* discGetInterface (void); 35 | 36 | #endif // GBA_DISC_INCLUDE 37 | -------------------------------------------------------------------------------- /include/disc_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | disc_io.h 3 | Interface template for low level disc functions. 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | Based on code originally written by MightyMax 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef GBA_DISC_IO_INCLUDE 31 | #define GBA_DISC_IO_INCLUDE 32 | 33 | #include "gba_types.h" 34 | #include 35 | #include 36 | 37 | #define FEATURE_MEDIUM_CANREAD 0x00000001 38 | #define FEATURE_MEDIUM_CANWRITE 0x00000002 39 | #define FEATURE_SLOT_GBA 0x00000010 40 | #define FEATURE_SLOT_NDS 0x00000020 41 | 42 | typedef uint32_t sec_t; 43 | 44 | typedef bool (* FN_MEDIUM_STARTUP)(void) ; 45 | typedef bool (* FN_MEDIUM_ISINSERTED)(void) ; 46 | typedef bool (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ; 47 | typedef bool (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ; 48 | typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; 49 | typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ; 50 | 51 | struct DISC_INTERFACE_STRUCT { 52 | unsigned long ioType ; 53 | unsigned long features ; 54 | FN_MEDIUM_STARTUP startup ; 55 | FN_MEDIUM_ISINSERTED isInserted ; 56 | FN_MEDIUM_READSECTORS readSectors ; 57 | FN_MEDIUM_WRITESECTORS writeSectors ; 58 | FN_MEDIUM_CLEARSTATUS clearStatus ; 59 | FN_MEDIUM_SHUTDOWN shutdown ; 60 | } ; 61 | 62 | typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ; 63 | 64 | #endif // define GBA_DISC_IO_INCLUDE 65 | -------------------------------------------------------------------------------- /include/dldi.h: -------------------------------------------------------------------------------- 1 | /* 2 | dldi.h 3 | 4 | Copyright (c) 2006 Michael "Chishm" Chisholm 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 3. The name of the author may not be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | #ifndef GBA_DLDI_INCLUDE 30 | #define GBA_DLDI_INCLUDE 31 | 32 | #include "disc_io.h" 33 | 34 | #define FIX_ALL 0x01 35 | #define FIX_GLUE 0x02 36 | #define FIX_GOT 0x04 37 | #define FIX_BSS 0x08 38 | 39 | #define DLDI_MAGIC_STRING_LEN 8 40 | #define DLDI_FRIENDLY_NAME_LEN 48 41 | 42 | extern const u32 DLDI_MAGIC_NUMBER; 43 | 44 | // I/O interface with DLDI extensions 45 | typedef struct { 46 | u32 magicNumber; 47 | char magicString [DLDI_MAGIC_STRING_LEN]; 48 | u8 versionNumber; 49 | u8 driverSize; // log-2 of driver size in bytes 50 | u8 fixSectionsFlags; 51 | u8 allocatedSize; // log-2 of the allocated space in bytes 52 | 53 | char friendlyName [DLDI_FRIENDLY_NAME_LEN]; 54 | 55 | // Pointers to sections that need address fixing 56 | void* dldiStart; 57 | void* dldiEnd; 58 | void* interworkStart; 59 | void* interworkEnd; 60 | void* gotStart; 61 | void* gotEnd; 62 | void* bssStart; 63 | void* bssEnd; 64 | 65 | // Original I/O interface data 66 | DISC_INTERFACE ioInterface; 67 | } DLDI_INTERFACE; 68 | 69 | 70 | /* 71 | Pointer to the internal DLDI, not directly usable by libfat. 72 | You'll need to set the bus permissions appropriately before using. 73 | */ 74 | extern const DLDI_INTERFACE* io_dldi_data; 75 | 76 | /* 77 | Return a pointer to the internal IO interface, 78 | setting up bus permissions in the process. 79 | */ 80 | extern const DISC_INTERFACE* dldiGetInternal (void); 81 | 82 | /* 83 | Determines if an IO driver is a valid DLDI driver 84 | */ 85 | extern bool dldiIsValid (const DLDI_INTERFACE* io); 86 | 87 | /* 88 | Adjust the pointer addresses within a DLDI driver 89 | */ 90 | extern void dldiFixDriverAddresses (DLDI_INTERFACE* io); 91 | 92 | /* 93 | Load a DLDI from disc and set up the bus permissions. 94 | This returns a type not directly usable in libfat, 95 | but it does give extra information, such as a friendly name. 96 | To use in libfat: 97 | const DLDI_INTERFACE* loadedDldi = dldi_loadFromFile ("file"); 98 | loadedDldi->ioInterface.startup(); 99 | fatMount(&loadedDldi->ioInterface, "devname", 0); 100 | */ 101 | extern DLDI_INTERFACE* dldiLoadFromFile (const char* path); 102 | 103 | /* 104 | Free resources used by a loaded DLDI. 105 | Remember to unmount and shutdown first: 106 | fatUnmount("devname"); 107 | loadedDldi->ioInterface.shutdown(); 108 | dldiFree(loadedDldi); 109 | */ 110 | extern void dldiFree (DLDI_INTERFACE* dldi); 111 | 112 | #endif // GBA_DLDI_INCLUDE 113 | -------------------------------------------------------------------------------- /include/fade.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba palette fade routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | /*! \file fade.h 29 | \brief gba palette fading. 30 | 31 | */ 32 | 33 | //--------------------------------------------------------------------------------- 34 | #ifndef _fade_h_ 35 | #define _fade_h_ 36 | //--------------------------------------------------------------------------------- 37 | 38 | //--------------------------------------------------------------------------------- 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | //--------------------------------------------------------------------------------- 43 | 44 | /*! \fn void FadeToPalette(const u16 *NewPalette, int FrameCount) 45 | \brief fade from the current palette to a preset palette. 46 | \param NewPalette 47 | \param FrameCount 48 | 49 | */ 50 | void FadeToPalette(const u16 *NewPalette, int FrameCount); 51 | 52 | /*! \fn void FadeToGrayScale(int gray, int FrameCount) 53 | \brief fade from the current palette to a preset palette. 54 | \param gray 55 | \param FrameCount 56 | 57 | */ 58 | void FadeToGrayScale(int gray, int FrameCount); 59 | /*! \fn void SetPalette(u16 *Palette) 60 | \brief Set the current Palette directly 61 | \param Palette 62 | 63 | */ 64 | void SetPalette(u16 *Palette); 65 | 66 | static inline void FadeToBlack(int frames) { FadeToGrayScale(0,frames); } 67 | 68 | //--------------------------------------------------------------------------------- 69 | #ifdef __cplusplus 70 | } // extern "C" 71 | #endif 72 | //--------------------------------------------------------------------------------- 73 | 74 | //--------------------------------------------------------------------------------- 75 | #endif // _fade_h_ 76 | //--------------------------------------------------------------------------------- 77 | -------------------------------------------------------------------------------- /include/gba.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba bios affine functions 4 | 5 | Copyright 2003-2005 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | //--------------------------------------------------------------------------------- 27 | #ifndef _gba_h_ 28 | #define _gba_h_ 29 | //--------------------------------------------------------------------------------- 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | //--------------------------------------------------------------------------------- 46 | #endif //_gba_h 47 | //--------------------------------------------------------------------------------- 48 | -------------------------------------------------------------------------------- /include/gba_affine.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba bios affine functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | //--------------------------------------------------------------------------------- 29 | #ifndef _gba_affine_h_ 30 | #define _gba_affine_h_ 31 | //--------------------------------------------------------------------------------- 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include "gba_base.h" 37 | 38 | //--------------------------------------------------------------------------------- 39 | typedef struct t_BGAffineSource { 40 | s32 x; /*!< Original data's center X coordinate (8bit fractional portion) */ 41 | s32 y; /*!< Original data's center Y coordinate (8bit fractional portion) */ 42 | s16 tX; /*!< Display's center X coordinate */ 43 | s16 tY; /*!< Display's center Y coordinate */ 44 | s16 sX; /*!< Scaling ratio in X direction (8bit fractional portion) */ 45 | s16 sY; /*!< Scaling ratio in Y direction (8bit fractional portion) */ 46 | u16 theta; /*!< Angle of rotation (8bit fractional portion) Effective Range 0-FFFF */ 47 | } BGAffineSource; 48 | 49 | typedef struct t_BGAffineDest { 50 | s16 pa; /*!< Difference in X coordinate along same line */ 51 | s16 pb; /*!< Difference in X coordinate along next line */ 52 | s16 pc; /*!< Difference in Y coordinate along same line */ 53 | s16 pd; /*!< Difference in Y coordinate along next line */ 54 | s32 x; /*!< Start X coordinate */ 55 | s32 y; /*!< Start Y coordinate */ 56 | } BGAffineDest; 57 | 58 | 59 | typedef struct t_ObjAffineSource { 60 | s16 sX; /*!< Scaling ratio in X direction (8bit fractional portion) */ 61 | s16 sY; /*!< Scaling ratio in Y direction (8bit fractional portion) */ 62 | u16 theta; /*!< Angle of rotation (8bit fractional portion) Effective Range 0-FFFF */ 63 | } ObjAffineSource; 64 | 65 | 66 | typedef struct t_ObjAffineDest { 67 | s16 pa; /*!< Difference in X coordinate along same line */ 68 | s16 pb; /*!< Difference in X coordinate along next line */ 69 | s16 pc; /*!< Difference in Y coordinate along same line */ 70 | s16 pd; /*!< Difference in Y coordinate along next line */ 71 | } ObjAffineDest; 72 | 73 | 74 | void ObjAffineSet(ObjAffineSource *source, void *dest, s32 num, s32 offset); 75 | void BgAffineSet(BGAffineSource *source, BGAffineDest *dest, s32 num); 76 | 77 | //--------------------------------------------------------------------------------- 78 | #ifdef __cplusplus 79 | } // extern "C" 80 | #endif 81 | //--------------------------------------------------------------------------------- 82 | #endif //_gba_affine_h 83 | //--------------------------------------------------------------------------------- 84 | -------------------------------------------------------------------------------- /include/gba_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba base macros, included by all libgba files 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | /*! \file gba_base.h 28 | \brief gba base definitions. 29 | 30 | */ 31 | 32 | 33 | //--------------------------------------------------------------------------------- 34 | #ifndef _gba_base_h_ 35 | #define _gba_base_h_ 36 | //--------------------------------------------------------------------------------- 37 | 38 | #include "gba_types.h" 39 | 40 | /*! \def VRAM 41 | 42 | \brief Base address of gba video ram. 43 | 44 | */ 45 | #define VRAM 0x06000000 46 | /*! \def IWRAM 47 | 48 | \brief Base address of gba internal work ram. 49 | 50 | */ 51 | #define IWRAM 0x03000000 52 | /*! \def EWRAM 53 | 54 | \brief Base address of gba external work ram. 55 | 56 | */ 57 | #define EWRAM 0x02000000 58 | #define EWRAM_END 0x02040000 59 | /*! \def SRAM 60 | 61 | \brief Base address of gba cart save ram. 62 | 63 | */ 64 | #define SRAM 0x0E000000 65 | /*! \def REG_BASE 66 | 67 | \brief Base address of gba hardware registers. 68 | 69 | */ 70 | #define REG_BASE 0x04000000 71 | 72 | #ifndef NULL 73 | #define NULL 0 74 | #endif 75 | 76 | //--------------------------------------------------------------------------------- 77 | /*! \def SystemCall(Number) 78 | 79 | \brief helper macro to insert a bios call. 80 | \param Number swi number to call 81 | 82 | Inserts a swi of the correct format for arm or thumb code. 83 | 84 | */ 85 | #if defined ( __thumb__ ) 86 | #define SystemCall(Number) __asm ("SWI "#Number"\n" ::: "r0", "r1", "r2", "r3") 87 | #else 88 | #define SystemCall(Number) __asm ("SWI "#Number" << 16\n" :::"r0", "r1", "r2", "r3") 89 | #endif 90 | 91 | /*! \def BIT(number) 92 | 93 | \brief Macro for bit settings. 94 | 95 | \param number bit number to set 96 | */ 97 | #define BIT(number) (1<<(number)) 98 | 99 | #define IWRAM_CODE __attribute__((section(".iwram"), long_call)) 100 | #define EWRAM_CODE __attribute__((section(".ewram"), long_call)) 101 | 102 | #define IWRAM_DATA __attribute__((section(".iwram_data"))) 103 | #define EWRAM_DATA __attribute__((section(".ewram_data"))) 104 | 105 | #define ARM_CODE __attribute__((target("arm"))) 106 | #define THUMB_CODE __attribute__((target("thumb"))) 107 | 108 | #define EWRAM_BSS __attribute__((section(".sbss"))) 109 | #define ALIGN(m) __attribute__((aligned (m))) 110 | 111 | //--------------------------------------------------------------------------------- 112 | // modes for DMA and CPU(Fast)Set 113 | //--------------------------------------------------------------------------------- 114 | enum DMA_MODES { 115 | FILL = (1<<24), 116 | COPY16 = (0<<26), 117 | COPY32 = (1<<26) 118 | }; 119 | 120 | //--------------------------------------------------------------------------------- 121 | #endif //_gba_base_h 122 | //--------------------------------------------------------------------------------- 123 | -------------------------------------------------------------------------------- /include/gba_compression.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba bios compression functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | 27 | //--------------------------------------------------------------------------------- 28 | #ifndef _gba_compression_h_ 29 | #define _gba_compression_h_ 30 | //--------------------------------------------------------------------------------- 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include "gba_base.h" 37 | 38 | typedef struct { 39 | u16 SrcNum; // Source Data Byte Size 40 | u8 SrcBitNum; // 1 Source Data Bit Number 41 | u8 DestBitNum; // 1 Destination Data Bit Number 42 | u32 DestOffset:31; // Number added to Source Data 43 | u32 DestOffset0_On:1; // Flag to add/not add Offset to 0 Data 44 | } BUP; 45 | 46 | 47 | //--------------------------------------------------------------------------------- 48 | // Decompression functions 49 | //--------------------------------------------------------------------------------- 50 | void BitUnPack(const void *source, void *dest, BUP* bup); 51 | void LZ77UnCompWram(const void *source, void *dest); 52 | void LZ77UnCompVram(const void *source, void *dest); 53 | void HuffUnComp(const void *source, void *dest); 54 | void RLUnCompWram(const void *source, void *dest); 55 | void RLUnCompVram(const void *source, void *dest); 56 | void Diff8bitUnFilterWram(const void *source, void *dest); 57 | void Diff8bitUnFilterVram(const void *source, void *dest); 58 | void Diff16bitUnFilter(const void *source, void *dest); 59 | 60 | //--------------------------------------------------------------------------------- 61 | #ifdef __cplusplus 62 | } // extern "C" 63 | #endif 64 | 65 | //--------------------------------------------------------------------------------- 66 | #endif //_gba_compression_h_ 67 | -------------------------------------------------------------------------------- /include/gba_console.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2003-2004 by Dave Murphy. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; either 7 | version 2 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 17 | USA. 18 | 19 | Please report all bugs and problems through the bug tracker at 20 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 21 | 22 | */ 23 | 24 | //--------------------------------------------------------------------------------- 25 | #ifndef _gba_console_h_ 26 | #define _gba_console_h_ 27 | //--------------------------------------------------------------------------------- 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | //--------------------------------------------------------------------------------- 32 | #include "gba_base.h" 33 | 34 | // Make console interaction a little less eye-crossing 35 | #define CONSOLE_ESC(x) "\x1b[" #x 36 | #define CONSOLE_RESET CONSOLE_ESC(0m) 37 | #define CONSOLE_BLACK CONSOLE_ESC(30m) 38 | #define CONSOLE_RED CONSOLE_ESC(31;1m) 39 | #define CONSOLE_GREEN CONSOLE_ESC(32;1m) 40 | #define CONSOLE_YELLOW CONSOLE_ESC(33;1m) 41 | #define CONSOLE_BLUE CONSOLE_ESC(34;1m) 42 | #define CONSOLE_MAGENTA CONSOLE_ESC(35;1m) 43 | #define CONSOLE_CYAN CONSOLE_ESC(36;1m) 44 | #define CONSOLE_WHITE CONSOLE_ESC(37;1m) 45 | 46 | #define CON_CLS() "\033[2J" 47 | #define CON_POS(_x, _y) "\033[" #_y ";" #_x "H" 48 | #define CON_UP(_dy) "\033[" #_dy "A" 49 | #define CON_DOWN(_dy) "\033[" #_dy "B" 50 | #define CON_RIGHT(_dx) "\033[" #_dx "C" 51 | #define CON_LEFT(_dx) "\033[" #_dx "D" 52 | #define CON_ERASE() "\033[K" 53 | #define CON_CLL(_y) CON_POS(1,_y) CON_ERASE() 54 | 55 | void consoleInit( int charBase, int mapBase, int background, 56 | const u8* font, int fontsize, int palette); 57 | 58 | void consoleDemoInit(void); 59 | 60 | //--------------------------------------------------------------------------------- 61 | #ifdef __cplusplus 62 | } // extern "C" 63 | #endif 64 | //--------------------------------------------------------------------------------- 65 | #endif // _gba_console_h_ 66 | //--------------------------------------------------------------------------------- 67 | -------------------------------------------------------------------------------- /include/gba_dma.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba DMA definitions 4 | 5 | Copyright 2003-2007 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | 27 | //--------------------------------------------------------------------------------- 28 | #ifndef _gba_dma_h_ 29 | #define _gba_dma_h_ 30 | //--------------------------------------------------------------------------------- 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | //--------------------------------------------------------------------------------- 35 | 36 | #include "gba_base.h" 37 | 38 | 39 | #define REG_DMA0SAD *(vu32*)(REG_BASE + 0x0b0) 40 | #define REG_DMA0DAD *(vu32*)(REG_BASE + 0x0b4) 41 | #define REG_DMA0CNT *(vu32*)(REG_BASE + 0x0b8) 42 | 43 | #define REG_DMA1SAD *(vu32*)(REG_BASE + 0x0bc) 44 | #define REG_DMA1DAD *(vu32*)(REG_BASE + 0x0c0) 45 | #define REG_DMA1CNT *(vu32*)(REG_BASE + 0x0c4) 46 | 47 | #define REG_DMA2SAD *(vu32*)(REG_BASE + 0x0c8) 48 | #define REG_DMA2DAD *(vu32*)(REG_BASE + 0x0cc) 49 | #define REG_DMA2CNT *(vu32*)(REG_BASE + 0x0d0) 50 | 51 | #define REG_DMA3SAD *(vu32*)(REG_BASE + 0x0d4) 52 | #define REG_DMA3DAD *(vu32*)(REG_BASE + 0x0d8) 53 | #define REG_DMA3CNT *(vu32*)(REG_BASE + 0x0dc) 54 | 55 | 56 | #define DMA_DST_INC (0<<21) 57 | #define DMA_DST_DEC (1<<21) 58 | #define DMA_DST_FIXED (2<<21) 59 | #define DMA_DST_RELOAD (3<<21) 60 | 61 | #define DMA_SRC_INC (0<<23) 62 | #define DMA_SRC_DEC (1<<23) 63 | #define DMA_SRC_FIXED (2<<23) 64 | 65 | #define DMA_REPEAT (1<<25) 66 | 67 | #define DMA16 (0<<26) 68 | #define DMA32 (1<<26) 69 | 70 | #define GAMEPAK_DRQ (1<<27) 71 | 72 | #define DMA_IMMEDIATE (0<<28) 73 | #define DMA_VBLANK (1<<28) 74 | #define DMA_HBLANK (2<<28) 75 | #define DMA_SPECIAL (3<<28) 76 | 77 | #define DMA_IRQ (1<<30) 78 | #define DMA_ENABLE (1<<31) 79 | 80 | #define DMA_Copy(channel, source, dest, mode) {\ 81 | REG_DMA##channel##SAD = (u32)(source);\ 82 | REG_DMA##channel##DAD = (u32)(dest);\ 83 | REG_DMA##channel##CNT = DMA_ENABLE | (mode); \ 84 | } 85 | 86 | static inline void dmaCopy(const void * source, void * dest, u32 size) { 87 | DMA_Copy(3, source, dest, DMA16 | size>>1); 88 | } 89 | 90 | #define DMA0COPY( source, dest, mode) DMA_Copy(0,(source),(dest),(mode)) 91 | #define DMA1COPY( source, dest, mode) DMA_Copy(1,(source),(dest),(mode)) 92 | #define DMA2COPY( source, dest, mode) DMA_Copy(2,(source),(dest),(mode)) 93 | #define DMA3COPY( source, dest, mode) DMA_Copy(3,(source),(dest),(mode)) 94 | 95 | //--------------------------------------------------------------------------------- 96 | #ifdef __cplusplus 97 | } // extern "C" 98 | #endif 99 | //--------------------------------------------------------------------------------- 100 | #endif // _gba_dma_h_ 101 | -------------------------------------------------------------------------------- /include/gba_input.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba input functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | /*! \file gba_input.h 29 | \brief gba inout support functions. 30 | 31 | */ 32 | 33 | //--------------------------------------------------------------------------------- 34 | #ifndef _gba_input_h_ 35 | #define _gba_input_h_ 36 | //--------------------------------------------------------------------------------- 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | //--------------------------------------------------------------------------------- 41 | #include "gba_base.h" 42 | 43 | /*! \def REG_KEYINPUT 44 | 45 | \brief Keypad status register. 46 | 47 | */ 48 | #define REG_KEYINPUT *(vu16*)(REG_BASE + 0x130) // Key Input 49 | /*! \def REG_KEYCNT 50 | 51 | \brief Keypad interrupt control register. 52 | 53 | */ 54 | #define REG_KEYCNT *(vu16*)(REG_BASE + 0x132) // Key Control 55 | /*! \enum KEYPAD_BITS 56 | 57 | \brief bit values for keypad buttons 58 | */ 59 | typedef enum KEYPAD_BITS { 60 | KEY_A = (1<<0), /*!< keypad A button */ 61 | KEY_B = (1<<1), /*!< keypad B button */ 62 | KEY_SELECT = (1<<2), /*!< keypad SELECT button */ 63 | KEY_START = (1<<3), /*!< keypad START button */ 64 | KEY_RIGHT = (1<<4), /*!< dpad RIGHT */ 65 | KEY_LEFT = (1<<5), /*!< dpad LEFT */ 66 | KEY_UP = (1<<6), /*!< dpad UP */ 67 | KEY_DOWN = (1<<7), /*!< dpad DOWN */ 68 | KEY_R = (1<<8), /*!< Right shoulder button */ 69 | KEY_L = (1<<9), /*!< Left shoulder button */ 70 | 71 | KEYIRQ_ENABLE = (1<<14), /*!< Enable keypad interrupt */ 72 | KEYIRQ_OR = (0<<15), /*!< interrupt logical OR mode */ 73 | KEYIRQ_AND = (1<<15), /*!< interrupt logical AND mode */ 74 | DPAD = (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT) /*!< mask all dpad buttons */ 75 | } KEYPAD_BITS; 76 | 77 | 78 | /*! \fn scanKeys() 79 | \brief obtain the current keypad states. 80 | 81 | Call this function once per main loop in order to use the keypad functions. 82 | */ 83 | void scanKeys(void); 84 | /*! \fn u16 keysDown() 85 | \brief obtain the current keypad pressed state. 86 | 87 | Returns the keys which have been pressed since the last call to KeysDown(), the keys are reset on this call. 88 | Keys which are pressed will not be reported again until they are released. 89 | */ 90 | u16 keysDown(void); 91 | /*! \fn u16 keysDownRepeat() 92 | \brief obtain the current keypad pressed state with repeat. 93 | 94 | */ 95 | u16 keysDownRepeat(void); 96 | /*! \fn u16 keysUp() 97 | \brief obtain the current keypad released. 98 | 99 | Returns the keys which have been pressed since the last call to KeysDown(), the keys are reset on this call. 100 | Keys which are pressed will not be reported again until they have been held for the times specified using SetRepeat(). 101 | */ 102 | u16 keysUp(void); 103 | /*! \fn u16 keysHeld() 104 | \brief obtain the current keypad held state. 105 | 106 | Returns the keys which have been pressed since the last call to KeysUp(), the keys are reset on this call. 107 | Keys which are released will not be reported again until they are pressed. 108 | */ 109 | u16 keysHeld(void); 110 | 111 | 112 | /*! \fn setRepeat(int SetDelay, int SetRepeat) 113 | \brief Set the repeat parameters for KeyDownRepeat. 114 | \param SetDelay The count before the key starts to repeat 115 | \param SetRepeat The count at which the key will repeat 116 | 117 | The counts are updated on each call to ScanKeys(), the rates are dependent on how often that function is called. 118 | */ 119 | void setRepeat( int SetDelay, int SetRepeat); 120 | 121 | //--------------------------------------------------------------------------------- 122 | #ifdef __cplusplus 123 | } // extern "C" 124 | #endif 125 | //--------------------------------------------------------------------------------- 126 | #endif // _gba_input_h_ 127 | //--------------------------------------------------------------------------------- 128 | -------------------------------------------------------------------------------- /include/gba_interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba interrupt handling 4 | 5 | Copyright 2003-2006 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | /*! \file gba_interrupt.h 29 | \brief gba interrupt support. 30 | 31 | */ 32 | 33 | #ifndef _gba_interrupt_h_ 34 | #define _gba_interrupt_h_ 35 | //--------------------------------------------------------------------------------- 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | //--------------------------------------------------------------------------------- 40 | 41 | #include "gba_base.h" 42 | 43 | /*! \var typedef void ( * IntFn)(void) 44 | \brief A type definition for an interrupt function pointer 45 | */ 46 | typedef void ( * IntFn)(void); 47 | 48 | struct IntTable{IntFn handler; u32 mask;}; 49 | 50 | #define MAX_INTS 15 51 | 52 | #define INT_VECTOR *(IntFn *)(0x03007ffc) // BIOS Interrupt vector 53 | /*! \def REG_IME 54 | 55 | \brief Interrupt Master Enable Register. 56 | 57 | When bit 0 is clear, all interrupts are masked. When it is 1, 58 | interrupts will occur if not masked out in REG_IE. 59 | 60 | */ 61 | #define REG_IME *(vu16 *)(REG_BASE + 0x208) // Interrupt Master Enable 62 | /*! \def REG_IE 63 | 64 | \brief Interrupt Enable Register. 65 | 66 | This is the activation mask for the internal interrupts. Unless 67 | the corresponding bit is set, the IRQ will be masked out. 68 | */ 69 | #define REG_IE *(vu16 *)(REG_BASE + 0x200) // Interrupt Enable 70 | /*! \def REG_IF 71 | 72 | \brief Interrupt Flag Register. 73 | 74 | Since there is only one hardware interrupt vector, the IF register 75 | contains flags to indicate when a particular of interrupt has occured. 76 | To acknowledge processing interrupts, set IF to the value of the 77 | interrupt handled. 78 | 79 | */ 80 | #define REG_IF *(vu16 *)(REG_BASE + 0x202) // Interrupt Request 81 | 82 | //! interrupt masks. 83 | /*! 84 | These masks are used in conjuction with REG_IE to enable specific interrupts 85 | and with REG_IF to acknowledge interrupts have been serviced. 86 | */ 87 | typedef enum irqMASKS { 88 | IRQ_VBLANK = (1<<0), /*!< vertical blank interrupt mask */ 89 | IRQ_HBLANK = (1<<1), /*!< horizontal blank interrupt mask */ 90 | IRQ_VCOUNT = (1<<2), /*!< vcount match interrupt mask */ 91 | IRQ_TIMER0 = (1<<3), /*!< timer 0 interrupt mask */ 92 | IRQ_TIMER1 = (1<<4), /*!< timer 1 interrupt mask */ 93 | IRQ_TIMER2 = (1<<5), /*!< timer 2 interrupt mask */ 94 | IRQ_TIMER3 = (1<<6), /*!< timer 3 interrupt mask */ 95 | IRQ_SERIAL = (1<<7), /*!< serial interrupt mask */ 96 | IRQ_DMA0 = (1<<8), /*!< DMA 0 interrupt mask */ 97 | IRQ_DMA1 = (1<<9), /*!< DMA 1 interrupt mask */ 98 | IRQ_DMA2 = (1<<10), /*!< DMA 2 interrupt mask */ 99 | IRQ_DMA3 = (1<<11), /*!< DMA 3 interrupt mask */ 100 | IRQ_KEYPAD = (1<<12), /*!< Keypad interrupt mask */ 101 | IRQ_GAMEPAK = (1<<13) /*!< horizontal blank interrupt mask */ 102 | } irqMASK; 103 | 104 | extern struct IntTable IntrTable[]; 105 | 106 | /*! \fn void irqInit(void) 107 | \brief initialises the gba interrupt code. 108 | 109 | */ 110 | void InitInterrupt(void) __attribute__ ((deprecated)); 111 | void irqInit(void); 112 | 113 | /*! \fn IntFn *irqSet(irqMASK mask, IntFn function) 114 | \brief sets the interrupt handler for a particular interrupt. 115 | 116 | \param mask 117 | \param function 118 | */ 119 | IntFn *SetInterrupt(irqMASK mask, IntFn function) __attribute__ ((deprecated)); 120 | IntFn *irqSet(irqMASK mask, IntFn function); 121 | /*! \fn void irqEnable(int mask) 122 | \brief allows an interrupt to occur. 123 | 124 | \param mask 125 | */ 126 | void EnableInterrupt(irqMASK mask) __attribute__ ((deprecated)); 127 | void irqEnable(int mask); 128 | 129 | /*! \fn void irqDisable(int mask) 130 | \brief prevents an interrupt occuring. 131 | 132 | \param mask 133 | */ 134 | void DisableInterrupt(irqMASK mask) __attribute__ ((deprecated)); 135 | void irqDisable(int mask); 136 | 137 | void IntrMain(void); 138 | 139 | 140 | 141 | //--------------------------------------------------------------------------------- 142 | #ifdef __cplusplus 143 | } // extern "C" 144 | #endif 145 | //--------------------------------------------------------------------------------- 146 | #endif // _gba_interrupt_h_ 147 | -------------------------------------------------------------------------------- /include/gba_multiboot.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba multiboot definitions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | 27 | */ 28 | 29 | //--------------------------------------------------------------------------------- 30 | #ifndef _gba_multiboot_h_ 31 | #define _gba_multiboot_h_ 32 | //--------------------------------------------------------------------------------- 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | //--------------------------------------------------------------------------------- 37 | 38 | #include "gba_base.h" 39 | 40 | typedef struct { 41 | u32 reserved1[5]; 42 | u8 handshake_data; 43 | u8 padding; 44 | u16 handshake_timeout; 45 | u8 probe_count; 46 | u8 client_data[3]; 47 | u8 palette_data; 48 | u8 response_bit; 49 | u8 client_bit; 50 | u8 reserved2; 51 | u8 *boot_srcp; 52 | u8 *boot_endp; 53 | u8 *masterp; 54 | u8 *reserved3[3]; 55 | u32 system_work2[4]; 56 | u8 sendflag; 57 | u8 probe_target_bit; 58 | u8 check_wait; 59 | u8 server_type; 60 | } MultiBootParam; 61 | 62 | enum MULTIBOOT_MODES { MODE32_NORMAL, MODE16_MULTI, MODE32_2MHZ}; 63 | 64 | u32 MultiBoot(MultiBootParam *mp, u32 mode); 65 | 66 | 67 | //--------------------------------------------------------------------------------- 68 | #ifdef __cplusplus 69 | } // extern "C" 70 | #endif 71 | //--------------------------------------------------------------------------------- 72 | #endif //_gba_multiboot_h_ 73 | -------------------------------------------------------------------------------- /include/gba_sio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba serial communication functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | 27 | */ 28 | 29 | //--------------------------------------------------------------------------------- 30 | #ifndef _gba_sio_h_ 31 | #define _gba_sio_h_ 32 | //--------------------------------------------------------------------------------- 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | //--------------------------------------------------------------------------------- 37 | #include "gba_base.h" 38 | 39 | //--------------------------------------------------------------------------------- 40 | // SIO mode control bits used with REG_SIOCNT 41 | //--------------------------------------------------------------------------------- 42 | #define SIO_8BIT 0x0000 // Normal 8-bit communication mode 43 | #define SIO_32BIT 0x1000 // Normal 32-bit communication mode 44 | #define SIO_MULTI 0x2000 // Multi-play communication mode 45 | #define SIO_UART 0x3000 // UART communication mode 46 | #define SIO_IRQ 0x4000 // Enable serial irq 47 | 48 | 49 | //--------------------------------------------------------------------------------- 50 | // baud rate settings 51 | //--------------------------------------------------------------------------------- 52 | #define SIO_9600 0x0000 53 | #define SIO_38400 0x0001 54 | #define SIO_57600 0x0002 55 | #define SIO_115200 0x0003 56 | 57 | #define SIO_CLK_INT (1<<0) // Select internal clock 58 | #define SIO_2MHZ_CLK (1<<1) // Select 2MHz clock 59 | #define SIO_RDY (1<<2) // Opponent SO state 60 | #define SIO_SO_HIGH (1<<3) // Our SO state 61 | #define SIO_START (1<<7) 62 | 63 | 64 | //--------------------------------------------------------------------------------- 65 | // SIO modes set with REG_RCNT 66 | //--------------------------------------------------------------------------------- 67 | #define R_NORMAL 0x0000 68 | #define R_MULTI 0x0000 69 | #define R_UART 0x0000 70 | #define R_GPIO 0x8000 71 | #define R_JOYBUS 0xC000 72 | 73 | //--------------------------------------------------------------------------------- 74 | // General purpose mode control bits used with REG_RCNT 75 | //--------------------------------------------------------------------------------- 76 | #define GPIO_SC 0x0001 // Data 77 | #define GPIO_SD 0x0002 78 | #define GPIO_SI 0x0004 79 | #define GPIO_SO 0x0008 80 | #define GPIO_SC_IO 0x0010 // Select I/O 81 | #define GPIO_SD_IO 0x0020 82 | #define GPIO_SI_IO 0x0040 83 | #define GPIO_SO_IO 0x0080 84 | #define GPIO_SC_INPUT 0x0000 // Input setting 85 | #define GPIO_SD_INPUT 0x0000 86 | #define GPIO_SI_INPUT 0x0000 87 | #define GPIO_SO_INPUT 0x0000 88 | #define GPIO_SC_OUTPUT 0x0010 // Output setting 89 | #define GPIO_SD_OUTPUT 0x0020 90 | #define GPIO_SI_OUTPUT 0x0040 91 | #define GPIO_SO_OUTPUT 0x0080 92 | 93 | 94 | #define REG_SIOCNT *(vu16*)(REG_BASE + 0x128) // Serial Communication Control 95 | #define REG_SIODATA8 *(vu16*)(REG_BASE + 0x12a) // 8bit Serial Communication Data 96 | #define REG_SIODATA32 *(vu32*)(REG_BASE + 0x120) // 32bit Serial Communication Data 97 | #define REG_SIOMLT_SEND *(vu16*)(REG_BASE + 0x12a) // Multi-play SIO Send Data 98 | #define REG_SIOMLT_RECV *(vu16*)(REG_BASE + 0x120) // Multi-play SIO Receive Data 99 | #define REG_SIOMULTI0 *(vu16*)(REG_BASE + 0x120) // Master data 100 | #define REG_SIOMULTI1 *(vu16*)(REG_BASE + 0x122) // Slave 1 data 101 | #define REG_SIOMULTI2 *(vu16*)(REG_BASE + 0x124) // Slave 2 data 102 | #define REG_SIOMULTI3 *(vu16*)(REG_BASE + 0x126) // Slave 3 data 103 | 104 | #define REG_RCNT *(vu16*)(REG_BASE + 0x134) // SIO Mode Select/General Purpose Data 105 | 106 | #define REG_HS_CTRL *(vu16*)(REG_BASE + 0x140) // SIO JOY Bus Control 107 | 108 | #define REG_JOYRE *(vu32*)(REG_BASE + 0x150) // SIO JOY Bus Receive Data 109 | #define REG_JOYRE_L *(vu16*)(REG_BASE + 0x150) 110 | #define REG_JOYRE_H *(vu16*)(REG_BASE + 0x152) 111 | 112 | #define REG_JOYTR *(vu32*)(REG_BASE + 0x154) // SIO JOY Bus Transmit Data 113 | #define REG_JOYTR_L *(vu16*)(REG_BASE + 0x154) 114 | #define REG_JOYTR_H *(vu16*)(REG_BASE + 0x156) 115 | 116 | #define REG_JSTAT *(vu16*)(REG_BASE + 0x158) // SIO JOY Bus Receive Status 117 | 118 | 119 | //--------------------------------------------------------------------------------- 120 | #ifdef __cplusplus 121 | } // extern "C" 122 | #endif 123 | //--------------------------------------------------------------------------------- 124 | #endif // _gba_sio_h 125 | -------------------------------------------------------------------------------- /include/gba_sprites.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba sprite definitions 4 | 5 | Copyright 2003-2006 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | 27 | //--------------------------------------------------------------------------------- 28 | #ifndef _gba_sprites_h_ 29 | #define _gba_sprites_h_ 30 | //--------------------------------------------------------------------------------- 31 | 32 | #include "gba_base.h" 33 | 34 | typedef struct { 35 | u16 attr0; 36 | u16 attr1; 37 | u16 attr2; 38 | u16 dummy; 39 | } ALIGN(4) OBJATTR; 40 | 41 | typedef struct { 42 | u16 attribute[3]; 43 | u16 dummy; 44 | } ALIGN(4) SpriteEntry; 45 | 46 | typedef struct { 47 | u16 dummy0[3]; 48 | s16 pa; 49 | u16 dummy1[3]; 50 | s16 pb; 51 | u16 dummy2[3]; 52 | s16 pc; 53 | u16 dummy3[3]; 54 | s16 pd; 55 | } ALIGN(4) OBJAFFINE; 56 | 57 | typedef struct { 58 | /* Attribute 0 */ 59 | u16 Y:8; 60 | u16 RotationScaling:1; 61 | u16 Disable:1; 62 | u16 Mode:2; 63 | u16 Mosaic:1; 64 | u16 ColorMode:1; 65 | u16 Shape:2; 66 | /* Attribute 1 */ 67 | u16 X:9; 68 | u16 NotUsed:3; 69 | u16 HFlip:1; 70 | u16 VFlip:1; 71 | u16 Size:2; 72 | /* Attribute 2 */ 73 | u16 Character:10; 74 | u16 Priority:2; 75 | u16 Palette:4; 76 | /* Attribute 3 */ 77 | u16 dummy; 78 | } ALIGN(4) Sprite; 79 | 80 | typedef struct { 81 | /* Attribute 0 */ 82 | u16 Y:8; 83 | u16 RotationScaling:1; 84 | u16 DoubleSize:1; 85 | u16 Mode:2; 86 | u16 Mosaic:1; 87 | u16 ColorMode:1; 88 | u16 Shape:2; 89 | /* Attribute 1 */ 90 | u16 X:9; 91 | u16 Affine:5; 92 | u16 Size:2; 93 | /* Attribute 2 */ 94 | u16 Character:10; 95 | u16 Priority:2; 96 | u16 Palette:4; 97 | /* Attribute 3 */ 98 | u16 dummy; 99 | } ALIGN(4) AffineSprite; 100 | 101 | 102 | #define OAM ((OBJATTR *)0x07000000) 103 | #define OBJ_BASE_ADR ((void *)(VRAM + 0x10000)) 104 | #define SPRITE_GFX ((u16 *)(VRAM + 0x10000)) 105 | #define BITMAP_OBJ_BASE_ADR ((void *)(VRAM + 0x14000)) 106 | 107 | enum SPRITE_SHAPES { 108 | SQUARE, 109 | WIDE, 110 | TALL 111 | }; 112 | #define OBJ_SHAPE(m) ((m)<<14) 113 | 114 | 115 | // Sprite Attribute 0 116 | #define OBJ_Y(m) ((m)&0x00ff) 117 | #define OBJ_ROT_SCALE_ON (1<<8) 118 | #define OBJ_DISABLE (1<<9) 119 | #define OBJ_DOUBLE (1<<9) 120 | #define OBJ_MODE(m) ((m)<<10) 121 | #define OBJ_MOSAIC (1<<12) 122 | #define OBJ_256_COLOR (1<<13) 123 | #define OBJ_16_COLOR (0<<13) 124 | 125 | #define ATTR0_MOSAIC (1<<12) 126 | #define ATTR0_COLOR_256 (1<<13) 127 | #define ATTR0_COLOR_16 (0<<13) 128 | #define ATTR0_TYPE_NORMAL (0<<10) 129 | #define ATTR0_TYPE_BLENDED (1<<10) 130 | #define ATTR0_TYPE_WINDOWED (2<<10) 131 | #define ATTR0_NORMAL (0<<8) 132 | #define ATTR0_ROTSCALE (1<<8) 133 | #define ATTR0_DISABLED (2<<8) 134 | #define ATTR0_ROTSCALE_DOUBLE (3<<8) 135 | 136 | #define ATTR0_SQUARE OBJ_SHAPE(SQUARE) 137 | #define ATTR0_WIDE OBJ_SHAPE(WIDE) 138 | #define ATTR0_TALL OBJ_SHAPE(TALL) 139 | 140 | 141 | 142 | // Sprite Attribute 1 143 | #define OBJ_X(m) ((m)&0x01ff) 144 | #define OBJ_ROT_SCALE(m) ((m)<<9) 145 | #define OBJ_HFLIP (1<<12) 146 | #define OBJ_VFLIP (1<<13) 147 | 148 | 149 | #define ATTR1_ROTDATA(n) ((n)<<9) // note: overlaps with flip flags 150 | #define ATTR1_FLIP_X (1<<12) 151 | #define ATTR1_FLIP_Y (1<<13) 152 | #define ATTR1_SIZE_8 (0<<14) 153 | #define ATTR1_SIZE_16 (1<<14) 154 | #define ATTR1_SIZE_32 (2<<14) 155 | #define ATTR1_SIZE_64 (3<<14) 156 | 157 | 158 | 159 | #define OBJ_SIZE(m) ((m)<<14) 160 | 161 | // Sprite Attribute 2 162 | #define OBJ_CHAR(m) ((m)&0x03ff) 163 | #define OBJ_PRIORITY(m) ((m)<<10) 164 | #define OBJ_PALETTE(m) ((m)<<12) 165 | 166 | #define ATTR2_PRIORITY(n) ((n)<<10) 167 | #define ATTR2_PALETTE(n) ((n)<<12) 168 | 169 | #define OBJ_TRANSLUCENT OBJ_MODE(1) 170 | #define OBJ_OBJWINDOW OBJ_MODE(2) 171 | #define OBJ_SQUARE OBJ_SHAPE(0) 172 | #define OBJ_WIDE OBJ_SHAPE(1) 173 | #define OBJ_TALL OBJ_SHAPE(2) 174 | 175 | //--------------------------------------------------------------------------------- 176 | enum SPRITE_SIZECODE { 177 | Sprite_8x8, // OBJ_SHAPE(0) OBJ_SIZE(0) 178 | Sprite_16x16, // OBJ_SHAPE(0) OBJ_SIZE(1) 179 | Sprite_32x32, // OBJ_SHAPE(0) OBJ_SIZE(2) 180 | Sprite_64x64, // OBJ_SHAPE(0) OBJ_SIZE(3) 181 | Sprite_16x8, // OBJ_SHAPE(1) OBJ_SIZE(0) 182 | Sprite_32x8, // OBJ_SHAPE(1) OBJ_SIZE(1) 183 | Sprite_32x16, // OBJ_SHAPE(1) OBJ_SIZE(2) 184 | Sprite_64x32, // OBJ_SHAPE(1) OBJ_SIZE(3) 185 | Sprite_8x16, // OBJ_SHAPE(2) OBJ_SIZE(0) 186 | Sprite_8x32, // OBJ_SHAPE(2) OBJ_SIZE(1) 187 | Sprite_16x32, // OBJ_SHAPE(2) OBJ_SIZE(2) 188 | Sprite_32x64 // OBJ_SHAPE(2) OBJ_SIZE(3) 189 | }; 190 | 191 | 192 | 193 | //--------------------------------------------------------------------------------- 194 | #endif // _gba_sprites_h_ 195 | //--------------------------------------------------------------------------------- 196 | -------------------------------------------------------------------------------- /include/gba_systemcalls.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | Header file for libgba bios calls 4 | 5 | Copyright 2003-2005 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | 27 | ---------------------------------------------------------------------------------*/ 28 | 29 | /*! \file gba_systemcalls.h 30 | \brief gba bios support. 31 | 32 | */ 33 | 34 | //--------------------------------------------------------------------------------- 35 | #ifndef _gba_systemcalls_h_ 36 | #define _gba_systemcalls_h_ 37 | //--------------------------------------------------------------------------------- 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include "gba_base.h" 44 | 45 | 46 | 47 | //--------------------------------------------------------------------------------- 48 | // Reset Functions 49 | //--------------------------------------------------------------------------------- 50 | /*! \enum RESTART_FLAG 51 | 52 | \brief flags for the SoftReset function 53 | */ 54 | typedef enum RESTART_FLAG { 55 | ROM_RESTART, /*!< Restart from RAM entry point. */ 56 | RAM_RESTART /*!< restart from ROM entry point */ 57 | } RESTART_FLAG; 58 | 59 | 60 | /*! \fn void SoftReset(RESTART_FLAG RestartFlag) 61 | \brief reset the GBA. 62 | \param RestartFlag flag 63 | */ 64 | void SoftReset(RESTART_FLAG RestartFlag); 65 | 66 | /*! \enum RESET_FLAG 67 | 68 | \brief flags controlling which parts of the system get reset 69 | */ 70 | enum RESET_FLAG { 71 | RESET_EWRAM = (1<<0), /*!< Clear 256K on-board WRAM */ 72 | RESET_IWRAM = (1<<1), /*!< Clear 32K in-chip WRAM */ 73 | RESET_PALETTE = (1<<2), /*!< Clear Palette */ 74 | RESET_VRAM = (1<<3), /*!< Clear VRAM */ 75 | RESET_OAM = (1<<4), /*!< Clear OAM */ 76 | RESET_SIO = (1<<5), /*!< Switches to general purpose mode */ 77 | RESET_SOUND = (1<<6), /*!< Reset Sound registers */ 78 | RESET_OTHER = (1<<7) /*!< all other registers */ 79 | }; 80 | 81 | typedef enum RESET_FLAG RESET_FLAGS; 82 | 83 | /*! \fn void RegisterRamReset(int ResetFlags) 84 | \brief reset the GBA registers and RAM. 85 | \param ResetFlags flags 86 | */ 87 | void RegisterRamReset(int ResetFlags); 88 | 89 | //--------------------------------------------------------------------------------- 90 | // Interrupt functions 91 | //--------------------------------------------------------------------------------- 92 | 93 | /*! \def static inline void Halt() 94 | */ 95 | 96 | static inline void Halt(void) { SystemCall(2); } 97 | static inline void Stop(void) { SystemCall(3); } 98 | 99 | //--------------------------------------------------------------------------------- 100 | static inline u32 BiosCheckSum(void) { 101 | //--------------------------------------------------------------------------------- 102 | register u32 result __asm("r0"); 103 | #if defined ( __thumb__ ) 104 | __asm ("SWI 0x0d" : "=r"(result) :: "r1", "r2", "r3"); 105 | #else 106 | __asm ("SWI 0x0d<<16" : "=r"(result) :: "r1", "r2", "r3"); 107 | #endif 108 | return result; 109 | } 110 | 111 | //--------------------------------------------------------------------------------- 112 | // Math functions 113 | //--------------------------------------------------------------------------------- 114 | /*! \fn s32 Div(s32 Number, s32 Divisor) 115 | \param Number 116 | \param Divisor 117 | */ 118 | s32 Div(s32 Number, s32 Divisor); 119 | /*! \fn s32 DivMod(s32 Number, s32 Divisor) 120 | \param Number 121 | \param Divisor 122 | 123 | */ 124 | s32 DivMod(s32 Number, s32 Divisor); 125 | /*! \fn u32 DivAbs(s32 Number, s32 Divisor) 126 | \param Number 127 | \param Divisor 128 | */ 129 | u32 DivAbs(s32 Number, s32 Divisor); 130 | /*! \fn s32 DivArm(s32 Number, s32 Divisor) 131 | \param Number 132 | \param Divisor 133 | */ 134 | s32 DivArm(s32 Divisor, s32 Number); 135 | /*! \fn s32 DivArmMod(s32 Number, s32 Divisor) 136 | \param Number 137 | \param Divisor 138 | */ 139 | s32 DivArmMod(s32 Divisor, s32 Number); 140 | /*! \fn u32 DivArmAbs(s32 Number, s32 Divisor) 141 | \param Number 142 | \param Divisor 143 | */ 144 | u32 DivArmAbs(s32 Divisor, s32 Number); 145 | /*! \fn u16 Sqrt(u32 X) 146 | \param X 147 | */ 148 | u16 Sqrt(u32 X); 149 | 150 | /*! \fn s16 ArcTan(s16 Tan) 151 | \param Tan 152 | */ 153 | s16 ArcTan(s16 Tan); 154 | /*! \fn s16 ArcTan2(s16 X, s16 Y) 155 | \param X 156 | \param Y 157 | */ 158 | u16 ArcTan2(s16 X, s16 Y); 159 | 160 | /*! \fn CpuSet( const void *source, void *dest, u32 mode) 161 | \param source 162 | \param dest 163 | \param mode 164 | */ 165 | void CpuSet( const void *source, void *dest, u32 mode); 166 | /*! \fn CpuFastSet( const void *source, void *dest, u32 mode) 167 | \param source 168 | \param dest 169 | \param mode 170 | */ 171 | void CpuFastSet( const void *source, void *dest, u32 mode); 172 | 173 | /*! \fn void IntrWait(u32 ReturnFlag, u32 IntFlag) 174 | \brief waits for an interrupt to occur. 175 | \param ReturnFlag 176 | \param IntFlag 177 | */ 178 | void IntrWait(u32 ReturnFlag, u32 IntFlag); 179 | 180 | /*! \fn void VBlankIntrWait() 181 | \brief waits for a vertical blank interrupt to occur. 182 | 183 | */ 184 | static inline 185 | void VBlankIntrWait(void) { SystemCall(5); } 186 | 187 | //--------------------------------------------------------------------------------- 188 | #ifdef __cplusplus 189 | } // extern "C" 190 | #endif 191 | 192 | 193 | //--------------------------------------------------------------------------------- 194 | #endif //_gba_systemcalls_h_ 195 | -------------------------------------------------------------------------------- /include/gba_timers.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | Header file for libgba timer definitions 4 | 5 | Copyright 2003-2005 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | ---------------------------------------------------------------------------------*/ 26 | 27 | #ifndef _gba_timers_h_ 28 | #define _gba_timers_h_ 29 | //--------------------------------------------------------------------------------- 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | //--------------------------------------------------------------------------------- 34 | 35 | #include "gba_base.h" 36 | 37 | #define REG_TM0CNT *(vu32*)(REG_BASE + 0x100) 38 | #define REG_TM0CNT_L *(vu16*)(REG_BASE + 0x100) 39 | #define REG_TM0CNT_H *(vu16*)(REG_BASE + 0x102) 40 | 41 | #define REG_TM1CNT *(vu32*)(REG_BASE + 0x104) 42 | #define REG_TM1CNT_L *(vu16*)(REG_BASE + 0x104) 43 | #define REG_TM1CNT_H *(vu16*)(REG_BASE + 0x106) 44 | 45 | #define REG_TM2CNT *(vu32*)(REG_BASE + 0x108) 46 | #define REG_TM2CNT_L *(vu16*)(REG_BASE + 0x108) 47 | #define REG_TM2CNT_H *(vu16*)(REG_BASE + 0x10a) 48 | 49 | #define REG_TM3CNT *(vu32*)(REG_BASE + 0x10c) 50 | #define REG_TM3CNT_L *(vu16*)(REG_BASE + 0x10c) 51 | #define REG_TM3CNT_H *(vu16*)(REG_BASE + 0x10e) 52 | 53 | #define TIMER_COUNT BIT(2) 54 | #define TIMER_IRQ BIT(6) 55 | #define TIMER_START BIT(7) 56 | 57 | 58 | //--------------------------------------------------------------------------------- 59 | #ifdef __cplusplus 60 | } // extern "C" 61 | #endif 62 | //--------------------------------------------------------------------------------- 63 | #endif // _gba_timers_h_ 64 | -------------------------------------------------------------------------------- /include/gba_types.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | Header file for libgba type definitions 4 | 5 | Copyright 2003-2005 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | ---------------------------------------------------------------------------------*/ 27 | 28 | /*! \file gba_types.h 29 | \brief gba type definitions. 30 | 31 | */ 32 | 33 | //--------------------------------------------------------------------------------- 34 | #ifndef _gba_types_h_ 35 | #define _gba_types_h_ 36 | //--------------------------------------------------------------------------------- 37 | 38 | #include 39 | #include 40 | //--------------------------------------------------------------------------------- 41 | // Data types 42 | //--------------------------------------------------------------------------------- 43 | typedef uint8_t u8; /**< Unsigned 8 bit value */ 44 | typedef uint16_t u16; /**< Unsigned 16 bit value */ 45 | typedef uint32_t u32; /**< Unsigned 32 bit value */ 46 | typedef int8_t s8; /**< Signed 8 bit value */ 47 | typedef int16_t s16; /**< Signed 16 bit value */ 48 | typedef int32_t s32; /**< Signed 32 bit value */ 49 | typedef volatile u8 vu8; /**< volatile Unsigned 8 bit value */ 50 | typedef volatile u16 vu16; /**< volatile Unigned 16 bit value */ 51 | typedef volatile u32 vu32; /**< volatile Unsigned 32 bit value */ 52 | typedef volatile s8 vs8; /**< volatile Signed 8 bit value */ 53 | typedef volatile s16 vs16; /**< volatile Signed 8 bit value */ 54 | typedef volatile s32 vs32; /**< volatile Signed 8 bit value */ 55 | 56 | 57 | //--------------------------------------------------------------------------------- 58 | #endif // _gba_types_h_ 59 | //--------------------------------------------------------------------------------- 60 | 61 | -------------------------------------------------------------------------------- /include/mappy.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba mappy debug functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | //--------------------------------------------------------------------------------- 29 | #ifndef _mappy_h_ 30 | #define _mappy_h_ 31 | //--------------------------------------------------------------------------------- 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | //--------------------------------------------------------------------------------- 36 | 37 | #include "gba_types.h" 38 | 39 | //--------------------------------------------------------------------------------- 40 | // Don't Use these function names 41 | //--------------------------------------------------------------------------------- 42 | void mappy_dprintf (char *str, ...); 43 | void mappy_dputchar (int c); 44 | 45 | //--------------------------------------------------------------------------------- 46 | // Use these function names instead 47 | // these will be repeated for Xcomms & MBV2 48 | //--------------------------------------------------------------------------------- 49 | #define dprintf mappy_dprintf 50 | #define dputchar mappy_dputchar 51 | 52 | //--------------------------------------------------------------------------------- 53 | // Sorry no file stuff 54 | //--------------------------------------------------------------------------------- 55 | #define dfprintf 56 | #define dfopen 57 | #define dfseek 58 | #define dfread 59 | #define dfwrite 60 | #define dftell 61 | #define dfclose 62 | #define dfgetc 63 | #define dfputc 64 | #define drewind 65 | 66 | 67 | //--------------------------------------------------------------------------------- 68 | #ifdef __cplusplus 69 | } // extern "C" 70 | #endif 71 | //--------------------------------------------------------------------------------- 72 | #endif // _mappy_h 73 | -------------------------------------------------------------------------------- /include/mbv2.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba mbv2 functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | //--------------------------------------------------------------------------------- 29 | #ifndef _mbv2_h_ 30 | #define _mbv2_h_ 31 | //--------------------------------------------------------------------------------- 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | //--------------------------------------------------------------------------------- 36 | 37 | //--------------------------------------------------------------------------------- 38 | // Don't Use these function names 39 | //--------------------------------------------------------------------------------- 40 | void mbv2_dprintf (char *str, ...); 41 | void mbv2_dfprintf (int fp, char *str, ...); 42 | int mbv2_dputchar (int c); 43 | int mbv2_dgetch (void); 44 | int mbv2_dkbhit (void); 45 | 46 | int mbv2_dfopen (const char *file, const char *type); 47 | int mbv2_dfclose (int fp); 48 | int mbv2_dfgetc (int fp); 49 | int mbv2_dfputc (int ch, int fp); 50 | void mbv2_drewind (int fp); 51 | 52 | //--------------------------------------------------------------------------------- 53 | // Use these function names instead 54 | // these will be repeated for VBA & Xcomms 55 | //--------------------------------------------------------------------------------- 56 | #define dprintf mbv2_dprintf 57 | #define dfprintf mbv2_dfprintf 58 | #define dputchar mbv2_dputchar 59 | #define dgetch mbv2_dgetch 60 | #define dkbhit mbv2_dkbhit 61 | 62 | #define dfopen mbv2_dfopen 63 | #define dfclose mbv2_dfclose 64 | #define dfgetc mbv2_dfgetc 65 | #define dfputc mbv2_dfputc 66 | #define drewind mbv2_drewind 67 | 68 | #define __DOUTBUFSIZE 256 69 | #define __FINBUFSIZE 256 //Must be a multiple of 2! (ex: 32,64,128,256,512..) 70 | #define __KINBUFSIZE 64 //Must be a multiple of 2! (ex: 32,64,128,256,512..) 71 | #define __ESCCHR 27 72 | 73 | #define __ESC_NADA 0 74 | #define __ESC_ESCCHR 1 75 | #define __ESC_FOPEN 2 76 | #define __ESC_FCLOSE 3 77 | #define __ESC_FGETC 4 78 | #define __ESC_FPUTC 5 79 | #define __ESC_REWIND 6 80 | #define __ESC_FPUTC_PROCESSED 7 // PC side add CR before LF if DOS machine 81 | #define __ESC_KBDCHR 8 82 | 83 | int __dputchar (int c); 84 | 85 | //--------------------------------------------------------------------------------- 86 | #ifdef __cplusplus 87 | } // extern "C" 88 | #endif 89 | //--------------------------------------------------------------------------------- 90 | #endif // _mbv2_h 91 | -------------------------------------------------------------------------------- /include/xcomms.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba xboo cable functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | //--------------------------------------------------------------------------------- 29 | #ifndef _xcomms_h_ 30 | #define _xcomms_h_ 31 | //--------------------------------------------------------------------------------- 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | //--------------------------------------------------------------------------------- 36 | 37 | #include "gba_types.h" 38 | 39 | //--------------------------------------------------------------------------------- 40 | // Don't Use these function names 41 | //--------------------------------------------------------------------------------- 42 | void xcomms_dprintf (char *str, ...); 43 | void xcomms_dfprintf (int handle, char *str, ...); 44 | void xcomms_dputchar (int c); 45 | 46 | int xcomms_dfopen (const char *file, const char *type); 47 | void xcomms_dfclose (int handle); 48 | u8 xcomms_dfgetc (int handle); 49 | void xcomms_dfputc (int ch, int handle); 50 | 51 | void xcomms_fread ( void *buffer, u32 size, u32 count, int handle ); 52 | void xcomms_fwrite ( void *buffer, u32 size, u32 count, int handle ); 53 | void xcomms_drewind (int handle); 54 | 55 | void xcomms_fseek ( int handle, u32 offset, int origin ); 56 | u32 xcomms_ftell ( int handle ); 57 | 58 | 59 | void xcomms_send(u32 data); 60 | void xcomms_sendblock(const void *block, int len); 61 | 62 | int xcomms_getch (void); 63 | int xcomms_kbhit (void); 64 | 65 | void xcomms_init(); 66 | 67 | //--------------------------------------------------------------------------------- 68 | // Use these function names instead 69 | // these will be repeated for VBA & MBV2 70 | //--------------------------------------------------------------------------------- 71 | #define dprintf xcomms_dprintf 72 | #define dfprintf xcomms_dfprintf 73 | #define dputchar xcomms_dputchar 74 | 75 | #define dfopen xcomms_dfopen 76 | #define dfseek xcomms_fseek 77 | #define dfread xcomms_fread 78 | #define dfwrite xcomms_fwrite 79 | #define dftell xcomms_ftell 80 | #define dfclose xcomms_dfclose 81 | #define dfgetc xcomms_dfgetc 82 | #define dfputc xcomms_dfputc 83 | #define drewind xcomms_drewind 84 | 85 | #define dgetch xcomms_getch 86 | #define dkbhit xcomms_kbhit 87 | 88 | //--------------------------------------------------------------------------------- 89 | #ifdef __cplusplus 90 | } // extern "C" 91 | #endif 92 | //--------------------------------------------------------------------------------- 93 | #endif // _xcomms_h 94 | -------------------------------------------------------------------------------- /include/xcomms_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Header file for libgba Xboo Communicator commands 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | 27 | //--------------------------------------------------------------------------------- 28 | #ifndef _xcomms_cmd_h_ 29 | #define _xcomms_cmd_h_ 30 | //--------------------------------------------------------------------------------- 31 | 32 | #define PRINT_CMD ('PRT'<<8) 33 | #define DPUTC_CMD ('DPT'<<8) 34 | 35 | #define FOPEN_CMD ('OPN'<<8) 36 | #define FCLOSE_CMD ('CLS'<<8) 37 | 38 | #define FREAD_CMD ('FRD'<<8) 39 | #define FWRITE_CMD ('FWR'<<8) 40 | 41 | #define FSEEK_CMD ('FSK'<<8) 42 | #define REWIND_CMD ('RWD'<<8) 43 | #define FTELL_CMD ('FTL'<<8) 44 | 45 | #define FGETC_CMD ('FGT'<<8) 46 | #define FPUTC_CMD ('FPT'<<8) 47 | 48 | #define GETCH_CMD ('GTC'<<8) 49 | #define KBHIT_CMD ('KBH'<<8) 50 | 51 | //--------------------------------------------------------------------------------- 52 | #endif //_xcomms_cmd_h_ 53 | //--------------------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /src/AffineSet.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios affine functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | //--------------------------------------------------------------------------------- 28 | #include "gba_affine.h" 29 | 30 | //--------------------------------------------------------------------------------- 31 | void ObjAffineSet(ObjAffineSource *source, void *dest, s32 num, s32 offset) 32 | //--------------------------------------------------------------------------------- 33 | { 34 | SystemCall (15); 35 | } 36 | 37 | //--------------------------------------------------------------------------------- 38 | void BgAffineSet(BGAffineSource *source, BGAffineDest *dest, s32 num) 39 | //--------------------------------------------------------------------------------- 40 | { 41 | SystemCall (14); 42 | } 43 | -------------------------------------------------------------------------------- /src/ArcTan.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios arctan routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | .text 28 | .code 16 29 | 30 | .global ArcTan 31 | .thumb_func 32 | ArcTan: 33 | swi 9 34 | bx lr 35 | 36 | .global ArcTan2 37 | .thumb_func 38 | ArcTan2: 39 | swi 10 40 | bx lr 41 | 42 | -------------------------------------------------------------------------------- /src/BoyScout/GBASoundRegs.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////// 2 | // File: GBASoundRegs.h // 3 | // // 4 | // Description: The GameBoy sound registers. Included with // 5 | // the BoyScout music playback code. // 6 | // // 7 | // Author: Christer Andersson (c) 2001 // 8 | // // 9 | ///////////////////////////////////////////////////////////// 10 | 11 | // Make sure this header is only included once 12 | #ifndef HEADER_GBASOUNDREGS_H 13 | #define HEADER_GBASOUNDREG_H 14 | 15 | /////////////////////// 16 | // CONTROL REGISTERS // 17 | /////////////////////// 18 | 19 | #define SGCNT0L *(unsigned short*)0x04000080 // Final sound control register addresses 20 | #define SGCNT0H *(unsigned short*)0x04000082 21 | #define SGCNT1 *(unsigned short*)0x04000084 22 | 23 | #define SGCNT0LROUT(n) n // Right speaker output level (0-7) 24 | #define SGCNT0LLOUT(n) (n<<4) // Left speaker output level (0-7) 25 | 26 | #define SGCNT0LSND1RENABLED (1<<8) // Enable left & right speakers for each sound channel 27 | #define SGCNT0LSND1LENABLED (1<<12) 28 | #define SGCNT0LSND2RENABLED (1<<9) 29 | #define SGCNT0LSND2LENABLED (1<<13) 30 | #define SGCNT0LSND3RENABLED (1<<10) 31 | #define SGCNT0LSND3LENABLED (1<<14) 32 | #define SGCNT0LSND4RENABLED (1<<11) 33 | #define SGCNT0LSND4LENABLED (1<<15) 34 | 35 | #define SGCNT0HSNDOUTPUT14 0 // Output ratios (1/4, 1/2 or 1/1) 36 | #define SGCNT0HSNDOUTPUT12 1 // for sound synthesis (sound 1-4) 37 | #define SGCNT0HSNDOUTPUT1 2 38 | 39 | #define SGCNT0HDSAOUTPUT12 (0<<2) // Output ratio for direct sound channel A 40 | #define SGCNT0HDSAOUTPUT1 (1<<2) // (1/2 or 1/1) 41 | #define SGCNT0HDSBOUTPUT12 (0<<3) // Output ratio for direct sound channel B 42 | #define SGCNT0HDSBOUTPUT1 (1<<3) // (1/2 or 1/1) 43 | 44 | #define SGCNT0HDSARENABLED (1<<8) // Enable left & right speakers for 45 | #define SGCNT0HDSALENABLED (1<<9) // direct sound channel A 46 | #define SGCNT0HDSBRENABLED (1<<12) // Enable left & right speakers for 47 | #define SGCNT0HDSBLENABLED (1<<13) // direct sound channel A 48 | 49 | #define SGCNT0HDSATIMER0 (0<<10) // Timer selection 0 or 1 for each 50 | #define SGCNT0HDSATIMER1 (1<<10) // direct sound channel A & B 51 | #define SGCNT0HDSBTIMER0 (0<<14) 52 | #define SGCNT0HDSBTIMER1 (1<<14) 53 | 54 | #define SGCNT0HDSFIFOARESET (1<<11) // Reset FIFO and sequencer for each direct sound A & B 55 | #define SGCNT0HDSFIFOBRESET (1<<15) 56 | 57 | #define SGCNT1SND1OPERATE 1 // Turn sound operation ON 58 | #define SGCNT1SND2OPERATE (1<<1) 59 | #define SGCNT1SND3OPERATE (1<<2) 60 | #define SGCNT1SND4OPERATE (1<<3) 61 | #define SGCNT1ALLSNDOPERATE (1<<7) 62 | 63 | ///////////// 64 | // SOUND 1 // 65 | ///////////// 66 | 67 | #define SG10L *(unsigned short*)0x04000060 // Addresses of sound 1 registers 68 | #define SG10H *(unsigned short*)0x04000062 69 | #define SG11 *(unsigned short*)0x04000064 70 | 71 | #define SG10LSWEEPSHIFTS(n) n // Number of sweep shifts (0-7) 72 | #define SG10LSWEEPSHIFTINC (0<<3) // Number of sweep shifts (0-7) 73 | #define SG10LSWEEPSHIFTDEC (1<<3) // Number of sweep shifts (0-7) 74 | #define SG10LSWEEPTIME(n) (n<<4) // Time of sweep (0-7) 75 | 76 | #define SG10HSNDLENGTH(n) n // Length of sound (0-63) 77 | #define SG10HWAVEDUTYCYCLE(n) (n<<6) // Waveform proportions (0-3) 78 | #define SG10HENVELOPESTEPS(n) (n<<8) // Envelope steps (0-7) 79 | #define SG10HENVELOPEINC (1<<11) // If to increase or decrease envelope 80 | #define SG10HENVELOPEDEC (0<<11) 81 | #define SG10HENVELOPEINIT(n) (n<<12) // Initial envelope (0-15) 82 | 83 | #define SG11FREQUENCY(n) n // Frequency 11-bits 84 | #define SG11PLAYONCE (1<<14) // Play sound once 85 | #define SG11PLAYLOOP (0<<14) // Loop sound 86 | #define SG11INIT (1<<15) // Makes the sound restart 87 | 88 | ///////////// 89 | // SOUND 2 // 90 | ///////////// 91 | 92 | #define SG20 *(unsigned short*)0x04000068 93 | #define SG21 *(unsigned short*)0x0400006C 94 | 95 | #define SG20SNDLENGTH(n) n // Length of sound (0-63) 96 | #define SG20WAVEDUTYCYCLE(n) (n<<6) // Waveform proportions (0-3) 97 | #define SG20ENVELOPESTEPS(n) (n<<8) // Envelope steps (0-7) 98 | #define SG20ENVELOPEINC (1<<11) // If to increase or decrease envelope 99 | #define SG20ENVELOPEDEC (0<<11) 100 | #define SG20ENVELOPEINIT(n) (n<<12) // Initial envelope (0-15) 101 | 102 | #define SG21FREQUENCY(n) n // Frequency 11-bits 103 | #define SG21PLAYONCE (1<<14) // Play sound once 104 | #define SG21PLAYLOOP (0<<14) // Loop sound 105 | #define SG21INIT (1<<15) // Makes the sound restart 106 | 107 | ///////////// 108 | // SOUND 3 // 109 | ///////////// 110 | 111 | #define SG30L *(volatile unsigned short* volatile)0x04000070 // Addresses to sound 3 registers 112 | #define SG30H *(volatile unsigned short* volatile)0x04000072 113 | #define SG31 *(volatile unsigned short* volatile)0x04000074 114 | 115 | #define SGWRAM *(unsigned short*)0x04000090 // Address of sound 3 wave RAM (16 bytes 4bit/step) 116 | 117 | #define SG30LSTEP32 (0<<5) // Use two banks of 32 steps each 118 | #define SG30LSTEP64 (1<<5) // Use one bank of 64 steps 119 | #define SG30LSETBANK0 (0<<6) // Bank to play 0 or 1 (non set bank is written to) 120 | #define SG30LSETBANK1 (1<<6) 121 | #define SG30LPLAY (1<<7) // Output sound 122 | #define SG30LSTOP (0<<7) // Stop sound output 123 | 124 | #define SG30HSNDLENGTH(n) n // Length of sound playback (0-255) 125 | #define SG30HOUTPUTMUTE (0<<13) // Mute output 126 | #define SG30HOUTPUT1 (1<<13) // Output unmodified 127 | #define SG30HOUTPUT12 (2<<13) // Output 1/2 (right shift of 1) 128 | #define SG30HOUTPUT14 (3<<13) // Output 1/4 (right shift of 2) 129 | #define SG30HOUTPUT34 (1<<15) // Output 3/4 130 | 131 | #define SG31FREQUENCY(n) n // 11-bit frequency data 132 | #define SG31PLAYONCE (1<<14) // Play sound once 133 | #define SG31PLAYLOOP (0<<14) // Play sound looped 134 | #define SG31INIT (1<<15) // Makes the sound restart 135 | 136 | ///////////// 137 | // SOUND 4 // 138 | ///////////// 139 | 140 | #define SG40 *(unsigned short*)0x04000078 // Addresses to sound 4 registers 141 | #define SG41 *(unsigned short*)0x0400007C 142 | 143 | #define SG40SNDLENGTH(n) n // Sound length (0-63) 144 | #define SG40ENVELOPESTEPS(n) (n<<8) // Envelope steps (0-7) 145 | #define SG40ENVELOPEINC (1<<11) // Increase or decrease envelope 146 | #define SG40ENVELOPEDEC (0<<11) 147 | #define SG40ENVELOPEINIT(n) (n<<12) // Initial envelope value 148 | 149 | #define SG41DIVRATIOFREQSEL(n) n // (0-7) 150 | #define SG41STEPS7 (1<<3) 151 | #define SG41STEPS15 (0<<3) 152 | #define SG41SHIFTFREQ(n) (n<<4) // (0-15) 153 | #define SG41PLAYONCE (1<<14) 154 | #define SG41PLAYLOOP (0<<14) 155 | #define SG41INIT (1<<15) 156 | 157 | //////////////////// 158 | // DMA3 Registers // 159 | //////////////////// 160 | 161 | #define DMA3SRC *(volatile unsigned int*)0x040000D4 // Source address of transfer (27-bit) 162 | #define DMA3DST *(volatile unsigned int*)0x040000D8 // Destination address of transfer (27-bit) 163 | #define DMA3COUNT *(volatile unsigned short*)0x040000DC // Count of characters that should be transferred (14-bit) 164 | #define DMA3CNT *(volatile unsigned short*)0x040000DE // DMA3 transfer control register 165 | 166 | // Control of destination address for transfer 167 | #define DMACNTDSTINC (0<<5) // Increment 168 | #define DMACNTDSTDEC (1<<5) // Decrement 169 | #define DMACNTDSTFIX (2<<5) // Stay fixed 170 | #define DMACNTDSTINCRELOAD (3<<5) // Address is incremented but reset after transfer 171 | 172 | // Control of source address for transfer 173 | #define DMACNTSRCINC (0<<7) // Increment 174 | #define DMACNTSRCDEC (1<<7) // Decrement 175 | #define DMACNTSRCFIX (2<<7) // Stay fixed 176 | 177 | // If time of transfer is the next VB or HB, DMA transfer 178 | // happens every VB/HB 179 | #define DMACNTREPEAT (1<<9) 180 | 181 | // Tranfer mode 182 | #define DMACNTTRANSFER16 (0<<10) // Transfer in 16-bit units 183 | #define DMACNTTRANSFER32 (1<<10) // Transfer in 32-bit units 184 | 185 | // Time of transfer 186 | #define DMACNTSTARTIM (0<<12) // Immediately 187 | #define DMACNTSTARTVB (1<<12) // Next vertical blank 188 | #define DMACNTSTARTHB (2<<12) // Next horizontal blank 189 | 190 | // Enable interrupt request when transfer is done 191 | #define DMACNTINTENABLE (1<<14) 192 | 193 | // Enable DMA transfer 194 | #define DMACNTENABLE (1<<15) 195 | 196 | 197 | #endif 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /src/Compression.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios decompression functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | #include "gba_compression.h" 29 | 30 | //--------------------------------------------------------------------------------- 31 | void BitUnPack(const void *source, void *dest, BUP* bup) 32 | //--------------------------------------------------------------------------------- 33 | { 34 | SystemCall(16); 35 | } 36 | 37 | //--------------------------------------------------------------------------------- 38 | void LZ77UnCompWram(const void *source, void *dest) 39 | //--------------------------------------------------------------------------------- 40 | { 41 | SystemCall(17); 42 | } 43 | //--------------------------------------------------------------------------------- 44 | void LZ77UnCompVram(const void *source, void *dest) 45 | //--------------------------------------------------------------------------------- 46 | { 47 | SystemCall(18); 48 | } 49 | //--------------------------------------------------------------------------------- 50 | void HuffUnComp(const void *source, void *dest) 51 | //--------------------------------------------------------------------------------- 52 | { 53 | SystemCall(19); 54 | } 55 | //--------------------------------------------------------------------------------- 56 | void RLUnCompWram(const void *source, void *dest) 57 | //-------------------------------------------------------------------------------- 58 | { 59 | SystemCall(20); 60 | } 61 | //--------------------------------------------------------------------------------- 62 | void RLUnCompVram(const void *source, void *dest) 63 | //--------------------------------------------------------------------------------- 64 | { 65 | SystemCall(21); 66 | } 67 | //--------------------------------------------------------------------------------- 68 | void Diff8bitUnFilterWram(const void *source, void *dest) 69 | //--------------------------------------------------------------------------------- 70 | { 71 | SystemCall(22); 72 | } 73 | //--------------------------------------------------------------------------------- 74 | void Diff8bitUnFilterVram(const void *source, void *dest) 75 | //--------------------------------------------------------------------------------- 76 | { 77 | SystemCall(23); 78 | } 79 | //--------------------------------------------------------------------------------- 80 | void Diff16bitUnFilter(const void *source, void *dest) 81 | //--------------------------------------------------------------------------------- 82 | { 83 | SystemCall(24); 84 | } 85 | -------------------------------------------------------------------------------- /src/CpuSet.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios CpuSet functions 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | #include "gba_systemcalls.h" 28 | 29 | //--------------------------------------------------------------------------------- 30 | void CpuSet( const void *source, void *dest, u32 mode) 31 | //--------------------------------------------------------------------------------- 32 | { 33 | SystemCall(11); 34 | } 35 | 36 | //--------------------------------------------------------------------------------- 37 | void CpuFastSet( const void *source, void *dest, u32 mode) 38 | //--------------------------------------------------------------------------------- 39 | { 40 | SystemCall(12); 41 | } 42 | -------------------------------------------------------------------------------- /src/Div.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios division routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | .text 28 | .code 16 29 | 30 | @--------------------------------------------------------------------------------- 31 | .global Div 32 | .thumb_func 33 | @--------------------------------------------------------------------------------- 34 | Div: 35 | @--------------------------------------------------------------------------------- 36 | swi 6 37 | bx lr 38 | 39 | @--------------------------------------------------------------------------------- 40 | .global DivMod 41 | .thumb_func 42 | @--------------------------------------------------------------------------------- 43 | DivMod: 44 | @--------------------------------------------------------------------------------- 45 | swi 6 46 | mov r0, r1 47 | bx lr 48 | 49 | @--------------------------------------------------------------------------------- 50 | .global DivAbs 51 | .thumb_func 52 | @--------------------------------------------------------------------------------- 53 | DivAbs: 54 | @--------------------------------------------------------------------------------- 55 | swi 6 56 | mov r0, r3 57 | bx lr 58 | 59 | -------------------------------------------------------------------------------- /src/DivArm.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios division routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | .text 29 | .code 16 30 | 31 | 32 | .global DivArm 33 | .thumb_func 34 | DivArm: 35 | swi 7 36 | bx lr 37 | 38 | .global DivArmMod 39 | .thumb_func 40 | DivArmMod: 41 | swi 7 42 | mov r0, r1 43 | bx lr 44 | 45 | .global DivArmAbs 46 | .thumb_func 47 | DivArmAbs: 48 | swi 7 49 | mov r0, r3 50 | bx lr 51 | -------------------------------------------------------------------------------- /src/InterruptDispatcher.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba interrupt dispatcher routines 4 | 5 | Copyright 2003-2007 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | @--------------------------------------------------------------------------------- 29 | .section .iwram,"ax",%progbits 30 | .extern IntrTable 31 | .code 32 32 | 33 | .global IntrMain 34 | @--------------------------------------------------------------------------------- 35 | IntrMain: 36 | @--------------------------------------------------------------------------------- 37 | mov r3, #0x4000000 @ REG_BASE 38 | ldr r2, [r3,#0x200] @ Read REG_IE 39 | 40 | ldr r1, [r3, #0x208] @ r1 = IME 41 | str r3, [r3, #0x208] @ disable IME 42 | mrs r0, spsr 43 | stmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq} 44 | 45 | and r1, r2, r2, lsr #16 @ r1 = IE & IF 46 | 47 | ldrh r2, [r3, #-8] @\mix up with BIOS irq flags at 3007FF8h, 48 | orr r2, r2, r1 @ aka mirrored at 3FFFFF8h, this is required 49 | strh r2, [r3, #-8] @/when using the (VBlank)IntrWait functions 50 | 51 | ldr r2,=IntrTable 52 | add r3,r3,#0x200 53 | 54 | @--------------------------------------------------------------------------------- 55 | findIRQ: 56 | @--------------------------------------------------------------------------------- 57 | ldr r0, [r2, #4] @ Interrupt mask 58 | cmp r0,#0 59 | beq no_handler 60 | ands r0, r0, r1 61 | bne jump_intr 62 | add r2, r2, #8 63 | b findIRQ 64 | 65 | @--------------------------------------------------------------------------------- 66 | no_handler: 67 | @--------------------------------------------------------------------------------- 68 | strh r1, [r3, #0x02] @ IF Clear 69 | ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq} 70 | str r1, [r3, #0x208] @ restore REG_IME 71 | mov pc,lr 72 | 73 | @--------------------------------------------------------------------------------- 74 | jump_intr: 75 | @--------------------------------------------------------------------------------- 76 | ldr r2, [r2] @ user IRQ handler address 77 | cmp r2, #0 78 | beq no_handler 79 | 80 | @--------------------------------------------------------------------------------- 81 | got_handler: 82 | @--------------------------------------------------------------------------------- 83 | 84 | mrs r1, cpsr 85 | bic r1, r1, #0xdf @ \__ 86 | orr r1, r1, #0x1f @ / --> Enable IRQ & FIQ. Set CPU mode to System. 87 | msr cpsr,r1 88 | 89 | strh r0, [r3, #0x02] @ IF Clear 90 | 91 | push {lr} 92 | adr lr, IntrRet 93 | bx r2 94 | 95 | @--------------------------------------------------------------------------------- 96 | IntrRet: 97 | @--------------------------------------------------------------------------------- 98 | pop {lr} 99 | mov r3, #0x4000000 @ REG_BASE 100 | str r3, [r3, #0x208] @ disable IME 101 | 102 | mrs r3, cpsr 103 | bic r3, r3, #0xdf @ \__ 104 | orr r3, r3, #0x92 @ / --> Disable IRQ. Enable FIQ. Set CPU mode to IRQ. 105 | msr cpsr, r3 106 | 107 | ldmfd sp!, {r0-r1,r3,lr} @ {spsr, IME, REG_BASE, lr_irq} 108 | str r1, [r3, #0x208] @ restore REG_IME 109 | msr spsr, r0 @ restore spsr 110 | mov pc,lr 111 | 112 | .pool 113 | .end 114 | -------------------------------------------------------------------------------- /src/IntrWait.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios interrupt wait routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | #include "gba_interrupt.h" 28 | 29 | //--------------------------------------------------------------------------------- 30 | void IntrWait(u32 ReturnFlag, u32 IntFlag) 31 | //--------------------------------------------------------------------------------- 32 | { 33 | SystemCall(4); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/MultiBoot.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios multiboot routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ .text 27 | .code 16 28 | 29 | .global MultiBoot 30 | .thumb_func 31 | MultiBoot: 32 | swi 37 33 | bx lr 34 | -------------------------------------------------------------------------------- /src/Reset.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios reset routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | .text 28 | .code 16 29 | 30 | .global RegisterRamReset 31 | .thumb_func 32 | RegisterRamReset: 33 | swi 1 34 | bx lr 35 | 36 | .global SoftReset 37 | .thumb_func 38 | SoftReset: 39 | ldr r3, =0x03007FFA @ restart flag 40 | strb r0,[r3, #0] 41 | ldr r3, =0x04000208 @ REG_IME 42 | mov r2, #0 43 | strb r2, [r3, #0] 44 | ldr r1, =0x03007f00 45 | mov sp, r1 46 | swi 1 47 | swi 0 48 | 49 | .pool 50 | -------------------------------------------------------------------------------- /src/Sound.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios sound routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | .text 28 | .code 16 29 | 30 | 31 | .global SoundDriverMode 32 | .thumb_func 33 | SoundDriverMode: 34 | swi 27 35 | bx lr 36 | 37 | .global SoundDriverInit 38 | .thumb_func 39 | SoundDriverInit: 40 | swi 26 41 | bx lr 42 | 43 | 44 | .global MidiKey2Freq 45 | .thumb_func 46 | MidiKey2Freq: 47 | swi 31 48 | bx lr 49 | -------------------------------------------------------------------------------- /src/Sqrt.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba bios sqrt routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | .text 28 | .code 16 29 | 30 | .global Sqrt 31 | .thumb_func 32 | Sqrt: 33 | swi 8 34 | bx lr 35 | -------------------------------------------------------------------------------- /src/disc_io/disc.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | disc.c 4 | 5 | uniformed io-interface to work with Chishm's FAT library 6 | 7 | Written by MightyMax, modified by Chishm 8 | 9 | 10 | Copyright (c) 2006 Michael "Chishm" Chisholm 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation and/or 19 | other materials provided with the distribution. 20 | 3. The name of the author may not be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 25 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | 36 | // Include known io-interfaces: 37 | #include "io_mpcf.h" 38 | #include "io_m3cf.h" 39 | #include "io_sccf.h" 40 | #include "io_scsd.h" 41 | #include "io_m3sd.h" 42 | 43 | static const DISC_INTERFACE* discInterfaces[] = { 44 | &_io_mpcf, &_io_m3cf, &_io_sccf, &_io_scsd, &_io_m3sd 45 | }; 46 | 47 | const DISC_INTERFACE* discGetInterface (void) 48 | { 49 | int i; 50 | 51 | for (i = 0; i < (sizeof(discInterfaces) / sizeof(DISC_INTERFACE*)); i++) { 52 | if (discInterfaces[i]->startup()) { 53 | return discInterfaces[i]; 54 | } 55 | } 56 | return NULL; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/disc_io/dldi.c: -------------------------------------------------------------------------------- 1 | /* 2 | disc.c 3 | Interface to the low level disc functions. Used by the higher level 4 | file system code. 5 | Based on code originally written by MightyMax 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | const u32 DLDI_MAGIC_NUMBER = 38 | 0xBF8DA5ED; 39 | 40 | // Stored backwards to prevent it being picked up by DLDI patchers 41 | const char DLDI_MAGIC_STRING_BACKWARDS [DLDI_MAGIC_STRING_LEN] = 42 | {'\0', 'm', 'h', 's', 'i', 'h', 'C', ' '} ; 43 | 44 | // The only built in driver 45 | extern DLDI_INTERFACE _io_dldi_stub; 46 | 47 | const DLDI_INTERFACE* io_dldi_data = &_io_dldi_stub; 48 | 49 | const DISC_INTERFACE* dldiGetInternal (void) { 50 | return &_io_dldi_stub.ioInterface; 51 | } 52 | 53 | 54 | bool dldiIsValid (const DLDI_INTERFACE* io) { 55 | int i; 56 | 57 | if (io->magicNumber != DLDI_MAGIC_NUMBER) { 58 | return false; 59 | } 60 | 61 | for (i = 0; i < DLDI_MAGIC_STRING_LEN; i++) { 62 | if (io->magicString[i] != DLDI_MAGIC_STRING_BACKWARDS [DLDI_MAGIC_STRING_LEN - 1 - i]) { 63 | return false; 64 | } 65 | } 66 | 67 | return true; 68 | } 69 | 70 | void dldiFixDriverAddresses (DLDI_INTERFACE* io) { 71 | u32 offset; 72 | u8** address; 73 | u8* oldStart; 74 | u8* oldEnd; 75 | 76 | offset = (char*)io - (char*)(io->dldiStart); 77 | 78 | oldStart = io->dldiStart; 79 | oldEnd = io->dldiEnd; 80 | 81 | // Correct all pointers to the offsets from the location of this interface 82 | io->dldiStart = (char*)io->dldiStart + offset; 83 | io->dldiEnd = (char*)io->dldiEnd + offset; 84 | io->interworkStart = (char*)io->interworkStart + offset; 85 | io->interworkEnd = (char*)io->interworkEnd + offset; 86 | io->gotStart = (char*)io->gotStart + offset; 87 | io->gotEnd = (char*)io->gotEnd + offset; 88 | io->bssStart = (char*)io->bssStart + offset; 89 | io->bssEnd = (char*)io->bssEnd + offset; 90 | 91 | io->ioInterface.startup = (FN_MEDIUM_STARTUP) ((char*)io->ioInterface.startup + offset); 92 | io->ioInterface.isInserted = (FN_MEDIUM_ISINSERTED) ((char*)io->ioInterface.isInserted + offset); 93 | io->ioInterface.readSectors = (FN_MEDIUM_READSECTORS) ((char*)io->ioInterface.readSectors + offset); 94 | io->ioInterface.writeSectors = (FN_MEDIUM_WRITESECTORS) ((char*)io->ioInterface.writeSectors + offset); 95 | io->ioInterface.clearStatus = (FN_MEDIUM_CLEARSTATUS) ((char*)io->ioInterface.clearStatus + offset); 96 | io->ioInterface.shutdown = (FN_MEDIUM_SHUTDOWN) ((char*)io->ioInterface.shutdown + offset); 97 | 98 | // Fix all addresses with in the DLDI 99 | if (io->fixSectionsFlags & FIX_ALL) { 100 | for (address = (u8**)io->dldiStart; address < (u8**)io->dldiEnd; address++) { 101 | if (oldStart <= *address && *address < oldEnd) { 102 | *address += offset; 103 | } 104 | } 105 | } 106 | 107 | // Fix the interworking glue section 108 | if (io->fixSectionsFlags & FIX_GLUE) { 109 | for (address = (u8**)io->interworkStart; address < (u8**)io->interworkEnd; address++) { 110 | if (oldStart <= *address && *address < oldEnd) { 111 | *address += offset; 112 | } 113 | } 114 | } 115 | 116 | // Fix the global offset table section 117 | if (io->fixSectionsFlags & FIX_GOT) { 118 | for (address = (u8**)io->gotStart; address < (u8**)io->gotEnd; address++) { 119 | if (oldStart <= *address && *address < oldEnd) { 120 | *address += offset; 121 | } 122 | } 123 | } 124 | 125 | // Initialise the BSS to 0 126 | if (io->fixSectionsFlags & FIX_BSS) { 127 | memset (io->bssStart, 0, (u8*)io->bssEnd - (u8*)io->bssStart); 128 | } 129 | } 130 | 131 | DLDI_INTERFACE* dldiLoadFromFile (const char* path) { 132 | DLDI_INTERFACE* device; 133 | int fd; 134 | size_t dldiSize; 135 | 136 | // Read in the DLDI header 137 | if ((fd = open (path, O_RDONLY, 0)) < 0) { 138 | return NULL; 139 | } 140 | 141 | if ((device = malloc (sizeof(DLDI_INTERFACE))) == NULL) { 142 | close (fd); 143 | return NULL; 144 | } 145 | 146 | if (read (fd, device, sizeof(DLDI_INTERFACE)) < sizeof(DLDI_INTERFACE)) { 147 | free (device); 148 | close (fd); 149 | return NULL; 150 | } 151 | 152 | // Check that it is a valid DLDI 153 | if (!dldiIsValid (device)) { 154 | free (device); 155 | close (fd); 156 | return NULL; 157 | } 158 | 159 | // Calculate actual size of DLDI 160 | // Although the file may only go to the dldiEnd, the BSS section can extend past that 161 | if (device->dldiEnd > device->bssEnd) { 162 | dldiSize = (char*)device->dldiEnd - (char*)device->dldiStart; 163 | } else { 164 | dldiSize = (char*)device->bssEnd - (char*)device->dldiStart; 165 | } 166 | dldiSize = (dldiSize + 0x03) & ~0x03; // Round up to nearest integer multiple 167 | 168 | // Load entire DLDI 169 | free (device); 170 | if ((device = malloc (dldiSize)) == NULL) { 171 | close (fd); 172 | return NULL; 173 | } 174 | 175 | memset (device, 0, dldiSize); 176 | lseek (fd, 0, SEEK_SET); 177 | read (fd, device, dldiSize); 178 | close (fd); 179 | 180 | dldiFixDriverAddresses (device); 181 | 182 | return device; 183 | } 184 | 185 | void dldiFree (DLDI_INTERFACE* dldi) { 186 | if (!dldi) return; 187 | free(dldi); 188 | } 189 | 190 | -------------------------------------------------------------------------------- /src/disc_io/dldi_stub.s: -------------------------------------------------------------------------------- 1 | @--------------------------------------------------------------------------------- 2 | .align 4 3 | .arm 4 | .global _io_dldi_stub 5 | @--------------------------------------------------------------------------------- 6 | .equ FEATURE_MEDIUM_CANREAD, 0x00000001 7 | .equ FEATURE_MEDIUM_CANWRITE, 0x00000002 8 | .equ FEATURE_SLOT_GBA, 0x00000010 9 | .equ FEATURE_SLOT_NDS, 0x00000020 10 | 11 | .equ DLDI_ALLOCATED_SPACE, 32768 12 | 13 | _io_dldi_stub: 14 | 15 | dldi_start: 16 | 17 | @--------------------------------------------------------------------------------- 18 | @ Driver patch file standard header -- 16 bytes 19 | .word 0xBF8DA5ED @ Magic number to identify this region 20 | .asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator) 21 | .byte 0x01 @ Version number 22 | .byte 0x0F @32KiB @ Log [base-2] of the size of this driver in bytes. 23 | .byte 0x00 @ Sections to fix 24 | .byte 0x0F @32KiB @ Log [base-2] of the allocated space in bytes. 25 | 26 | @--------------------------------------------------------------------------------- 27 | @ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes 28 | .align 4 29 | .asciz "Default (No interface)" 30 | 31 | @--------------------------------------------------------------------------------- 32 | @ Offsets to important sections within the data -- 32 bytes 33 | .align 6 34 | .word dldi_start @ data start 35 | .word dldi_end @ data end 36 | .word 0x00000000 @ Interworking glue start -- Needs address fixing 37 | .word 0x00000000 @ Interworking glue end 38 | .word 0x00000000 @ GOT start -- Needs address fixing 39 | .word 0x00000000 @ GOT end 40 | .word 0x00000000 @ bss start -- Needs setting to zero 41 | .word 0x00000000 @ bss end 42 | 43 | @--------------------------------------------------------------------------------- 44 | @ DISC_INTERFACE data -- 32 bytes 45 | .ascii "DLDI" @ ioType 46 | .word 0x00000000 @ Features 47 | .word _DLDI_startup @ 48 | .word _DLDI_isInserted @ 49 | .word _DLDI_readSectors @ Function pointers to standard device driver functions 50 | .word _DLDI_writeSectors @ 51 | .word _DLDI_clearStatus @ 52 | .word _DLDI_shutdown @ 53 | 54 | @--------------------------------------------------------------------------------- 55 | 56 | _DLDI_startup: 57 | _DLDI_isInserted: 58 | _DLDI_readSectors: 59 | _DLDI_writeSectors: 60 | _DLDI_clearStatus: 61 | _DLDI_shutdown: 62 | mov r0, #0x00 @ Return false for every function 63 | bx lr 64 | 65 | 66 | 67 | @--------------------------------------------------------------------------------- 68 | .align 69 | .pool 70 | 71 | dldi_data_end: 72 | 73 | @ Pad to end of allocated space 74 | .space DLDI_ALLOCATED_SPACE - (dldi_data_end - dldi_start) 75 | 76 | dldi_end: 77 | .end 78 | @--------------------------------------------------------------------------------- 79 | -------------------------------------------------------------------------------- /src/disc_io/io_cf_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_cf_common.c based on 3 | 4 | compact_flash.c 5 | By chishm (Michael Chisholm) 6 | 7 | Common hardware routines for using a compact flash card. This is not reentrant 8 | and does not do range checking on the supplied addresses. This is designed to 9 | be as fast as possible. 10 | 11 | CF routines modified with help from Darkfader 12 | 13 | Copyright (c) 2006 Michael "Chishm" Chisholm 14 | 15 | Redistribution and use in source and binary forms, with or without modification, 16 | are permitted provided that the following conditions are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright notice, 19 | this list of conditions and the following disclaimer. 20 | 2. Redistributions in binary form must reproduce the above copyright notice, 21 | this list of conditions and the following disclaimer in the documentation and/or 22 | other materials provided with the distribution. 23 | 3. The name of the author may not be used to endorse or promote products derived 24 | from this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 27 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 28 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 34 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | 38 | #include "io_cf_common.h" 39 | 40 | //--------------------------------------------------------------- 41 | // CF Addresses & Commands 42 | 43 | CF_REGISTERS cfRegisters = {0}; 44 | 45 | 46 | /*----------------------------------------------------------------- 47 | _CF_isInserted 48 | Is a compact flash card inserted? 49 | bool return OUT: true if a CF card is inserted 50 | -----------------------------------------------------------------*/ 51 | bool _CF_isInserted (void) { 52 | // Change register, then check if value did change 53 | *(cfRegisters.status) = CF_STS_INSERTED; 54 | return ((*(cfRegisters.status) & 0xff) == CF_STS_INSERTED); 55 | } 56 | 57 | 58 | /*----------------------------------------------------------------- 59 | _CF_clearStatus 60 | Tries to make the CF card go back to idle mode 61 | bool return OUT: true if a CF card is idle 62 | -----------------------------------------------------------------*/ 63 | bool _CF_clearStatus (void) { 64 | int i; 65 | 66 | // Wait until CF card is finished previous commands 67 | i=0; 68 | while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT)) { 69 | i++; 70 | } 71 | 72 | // Wait until card is ready for commands 73 | i = 0; 74 | while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT)) { 75 | i++; 76 | } 77 | if (i >= CF_CARD_TIMEOUT) 78 | return false; 79 | 80 | return true; 81 | } 82 | 83 | 84 | /*----------------------------------------------------------------- 85 | _CF_readSectors 86 | Read 512 byte sector numbered "sector" into "buffer" 87 | u32 sector IN: address of first 512 byte sector on CF card to read 88 | u32 numSectors IN: number of 512 byte sectors to read, 89 | 1 to 256 sectors can be read 90 | void* buffer OUT: pointer to 512 byte buffer to store data in 91 | bool return OUT: true if successful 92 | -----------------------------------------------------------------*/ 93 | bool _CF_readSectors (u32 sector, u32 numSectors, void* buffer) { 94 | int i; 95 | 96 | u16 *buff = (u16*)buffer; 97 | u8 *buff_u8 = (u8*)buffer; 98 | int temp; 99 | 100 | // Wait until CF card is finished previous commands 101 | i=0; 102 | while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT)) { 103 | i++; 104 | } 105 | 106 | // Wait until card is ready for commands 107 | i = 0; 108 | while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT)) { 109 | i++; 110 | } 111 | if (i >= CF_CARD_TIMEOUT) 112 | return false; 113 | 114 | // Set number of sectors to read 115 | *(cfRegisters.sectorCount) = (numSectors < 256 ? numSectors : 0); // Read a maximum of 256 sectors, 0 means 256 116 | 117 | // Set read sector 118 | *(cfRegisters.lba1) = sector & 0xFF; // 1st byte of sector number 119 | *(cfRegisters.lba2) = (sector >> 8) & 0xFF; // 2nd byte of sector number 120 | *(cfRegisters.lba3) = (sector >> 16) & 0xFF; // 3rd byte of sector number 121 | *(cfRegisters.lba4) = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number 122 | 123 | // Set command to read 124 | *(cfRegisters.command) = CF_CMD_READ; 125 | 126 | 127 | while (numSectors--) 128 | { 129 | // Wait until card is ready for reading 130 | i = 0; 131 | while (((*(cfRegisters.status) & 0xff)!= CF_STS_READY) && (i < CF_CARD_TIMEOUT)) 132 | { 133 | i++; 134 | } 135 | if (i >= CF_CARD_TIMEOUT) 136 | return false; 137 | 138 | // Read data 139 | i=256; 140 | if ((u32)buff_u8 & 0x01) { 141 | while(i--) 142 | { 143 | temp = *(cfRegisters.data); 144 | *buff_u8++ = temp & 0xFF; 145 | *buff_u8++ = temp >> 8; 146 | } 147 | } else { 148 | while(i--) 149 | *buff++ = *(cfRegisters.data); 150 | } 151 | } 152 | 153 | return true; 154 | } 155 | 156 | 157 | 158 | /*----------------------------------------------------------------- 159 | _CF_writeSectors 160 | Write 512 byte sector numbered "sector" from "buffer" 161 | u32 sector IN: address of 512 byte sector on CF card to read 162 | u32 numSectors IN: number of 512 byte sectors to read, 163 | 1 to 256 sectors can be read 164 | void* buffer IN: pointer to 512 byte buffer to read data from 165 | bool return OUT: true if successful 166 | -----------------------------------------------------------------*/ 167 | bool _CF_writeSectors (u32 sector, u32 numSectors, void* buffer) { 168 | int i; 169 | 170 | u16 *buff = (u16*)buffer; 171 | u8 *buff_u8 = (u8*)buffer; 172 | int temp; 173 | 174 | // Wait until CF card is finished previous commands 175 | i=0; 176 | while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT)) 177 | { 178 | i++; 179 | } 180 | 181 | // Wait until card is ready for commands 182 | i = 0; 183 | while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT)) 184 | { 185 | i++; 186 | } 187 | if (i >= CF_CARD_TIMEOUT) 188 | return false; 189 | 190 | // Set number of sectors to write 191 | *(cfRegisters.sectorCount) = (numSectors < 256 ? numSectors : 0); // Write a maximum of 256 sectors, 0 means 256 192 | 193 | // Set write sector 194 | *(cfRegisters.lba1) = sector & 0xFF; // 1st byte of sector number 195 | *(cfRegisters.lba2) = (sector >> 8) & 0xFF; // 2nd byte of sector number 196 | *(cfRegisters.lba3) = (sector >> 16) & 0xFF; // 3rd byte of sector number 197 | *(cfRegisters.lba4) = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number 198 | 199 | // Set command to write 200 | *(cfRegisters.command) = CF_CMD_WRITE; 201 | 202 | while (numSectors--) 203 | { 204 | // Wait until card is ready for writing 205 | i = 0; 206 | while (((*(cfRegisters.status) & 0xff) != CF_STS_READY) && (i < CF_CARD_TIMEOUT)) 207 | { 208 | i++; 209 | } 210 | if (i >= CF_CARD_TIMEOUT) 211 | return false; 212 | 213 | // Write data 214 | i=256; 215 | if ((u32)buff_u8 & 0x01) { 216 | while(i--) 217 | { 218 | temp = *buff_u8++; 219 | temp |= *buff_u8++ << 8; 220 | *(cfRegisters.data) = temp; 221 | } 222 | } else { 223 | while(i--) 224 | *(cfRegisters.data) = *buff++; 225 | } 226 | } 227 | 228 | return true; 229 | } 230 | 231 | /*----------------------------------------------------------------- 232 | _CF_shutdown 233 | shutdown the CF interface 234 | -----------------------------------------------------------------*/ 235 | bool _CF_shutdown(void) { 236 | return _CF_clearStatus() ; 237 | } 238 | 239 | /*----------------------------------------------------------------- 240 | _CF_startUp 241 | Initializes the CF interface using the supplied registers 242 | returns true if successful, otherwise returns false 243 | -----------------------------------------------------------------*/ 244 | bool _CF_startup(const CF_REGISTERS *usableCfRegs) { 245 | cfRegisters = *usableCfRegs; 246 | // See if there is a read/write register 247 | u16 temp = *(cfRegisters.lba1); 248 | *(cfRegisters.lba1) = (~temp & 0xFF); 249 | temp = (~temp & 0xFF); 250 | if (!(*(cfRegisters.lba1) == temp)) { 251 | return false; 252 | } 253 | // Make sure it is 8 bit 254 | *(cfRegisters.lba1) = 0xAA55; 255 | if (*(cfRegisters.lba1) == 0xAA55) { 256 | return false; 257 | } 258 | return true; 259 | } 260 | 261 | -------------------------------------------------------------------------------- /src/disc_io/io_cf_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_cf_common.h 3 | 4 | By chishm (Michael Chisholm) 5 | 6 | Common Compact Flash card values 7 | 8 | Copyright (c) 2006 Michael "Chishm" Chisholm 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | 2. Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation and/or 17 | other materials provided with the distribution. 18 | 3. The name of the author may not be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 23 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef IO_CF_COMMON_H 33 | #define IO_CF_COMMON_H 34 | 35 | #include 36 | 37 | typedef struct { 38 | vu16* data; 39 | vu16* status; 40 | vu16* command; 41 | vu16* error; 42 | vu16* sectorCount; 43 | vu16* lba1; 44 | vu16* lba2; 45 | vu16* lba3; 46 | vu16* lba4; 47 | } CF_REGISTERS; 48 | 49 | 50 | // CF Card status 51 | #define CF_STS_INSERTED 0x50 52 | #define CF_STS_REMOVED 0x00 53 | #define CF_STS_READY 0x58 54 | 55 | #define CF_STS_DRQ 0x08 56 | #define CF_STS_BUSY 0x80 57 | 58 | // CF Card commands 59 | #define CF_CMD_LBA 0xE0 60 | #define CF_CMD_READ 0x20 61 | #define CF_CMD_WRITE 0x30 62 | 63 | #define CF_CARD_TIMEOUT 10000000 64 | 65 | bool _CF_isInserted (void); 66 | bool _CF_clearStatus (void); 67 | bool _CF_readSectors (u32 sector, u32 numSectors, void* buffer); 68 | bool _CF_writeSectors (u32 sector, u32 numSectors, void* buffer); 69 | bool _CF_shutdown(void); 70 | bool _CF_startup(const CF_REGISTERS *usableCfRegs); 71 | 72 | #endif // define IO_CF_COMMON_H 73 | -------------------------------------------------------------------------------- /src/disc_io/io_m3_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3_common.c 3 | 4 | Routines common to all version of the M3 5 | 6 | Some code based on M3 SD drivers supplied by M3Adapter. 7 | Some code written by SaTa may have been unknowingly used. 8 | 9 | Copyright (c) 2006 Michael "Chishm" Chisholm 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, 15 | this list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation and/or 18 | other materials provided with the distribution. 19 | 3. The name of the author may not be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 24 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | 35 | static u16 _M3_readHalfword (u32 addr) { 36 | return *((vu16*)addr); 37 | } 38 | 39 | void _M3_changeMode (u32 mode) { 40 | _M3_readHalfword (0x08e00002); 41 | _M3_readHalfword (0x0800000e); 42 | _M3_readHalfword (0x08801ffc); 43 | _M3_readHalfword (0x0800104a); 44 | _M3_readHalfword (0x08800612); 45 | _M3_readHalfword (0x08000000); 46 | _M3_readHalfword (0x08801b66); 47 | _M3_readHalfword (0x08000000 + (mode << 1)); 48 | _M3_readHalfword (0x0800080e); 49 | _M3_readHalfword (0x08000000); 50 | 51 | if ((mode & 0x0f) != 4) { 52 | _M3_readHalfword (0x09000000); 53 | } else { 54 | _M3_readHalfword (0x080001e4); 55 | _M3_readHalfword (0x080001e4); 56 | _M3_readHalfword (0x08000188); 57 | _M3_readHalfword (0x08000188); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/disc_io/io_m3_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3_common.h 3 | 4 | Routines common to all version of the M3 5 | 6 | Some code based on M3 SD drivers supplied by M3Adapter. 7 | Some code written by SaTa may have been unknowingly used. 8 | 9 | Copyright (c) 2006 Michael "Chishm" Chisholm 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, 15 | this list of conditions and the following disclaimer. 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation and/or 18 | other materials provided with the distribution. 19 | 3. The name of the author may not be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 24 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 2006-07-11 - Chishm 33 | * Original release 34 | */ 35 | 36 | #ifndef IO_M3_COMMON_H 37 | #define IO_M3_COMMON_H 38 | 39 | #include 40 | 41 | // Values for changing mode 42 | #define M3_MODE_ROM 0x00400004 43 | #define M3_MODE_MEDIA 0x00400003 44 | 45 | extern void _M3_changeMode (u32 mode); 46 | 47 | #endif // IO_M3_COMMON_H 48 | 49 | -------------------------------------------------------------------------------- /src/disc_io/io_m3cf.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3cf.c based on 3 | 4 | compact_flash.c 5 | By chishm (Michael Chisholm) 6 | 7 | Hardware Routines for reading a compact flash card 8 | using the M3 Perfect CF Adapter 9 | 10 | CF routines modified with help from Darkfader 11 | 12 | Copyright (c) 2006 Michael "Chishm" Chisholm 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, 18 | this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation and/or 21 | other materials provided with the distribution. 22 | 3. The name of the author may not be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | 37 | #include "io_m3cf.h" 38 | #include "io_m3_common.h" 39 | #include "io_cf_common.h" 40 | 41 | //--------------------------------------------------------------- 42 | // M3 CF Addresses 43 | #define REG_M3CF_STS ((vu16*)0x080C0000) // Status of the CF Card / Device control 44 | #define REG_M3CF_CMD ((vu16*)0x088E0000) // Commands sent to control chip and status return 45 | #define REG_M3CF_ERR ((vu16*)0x08820000) // Errors / Features 46 | 47 | #define REG_M3CF_SEC ((vu16*)0x08840000) // Number of sector to transfer 48 | #define REG_M3CF_LBA1 ((vu16*)0x08860000) // 1st byte of sector address 49 | #define REG_M3CF_LBA2 ((vu16*)0x08880000) // 2nd byte of sector address 50 | #define REG_M3CF_LBA3 ((vu16*)0x088A0000) // 3rd byte of sector address 51 | #define REG_M3CF_LBA4 ((vu16*)0x088C0000) // last nibble of sector address | 0xE0 52 | 53 | #define REG_M3CF_DATA ((vu16*)0x08800000) // Pointer to buffer of CF data transered from card 54 | 55 | static const CF_REGISTERS _M3CF_Registers = { 56 | REG_M3CF_DATA, 57 | REG_M3CF_STS, 58 | REG_M3CF_CMD, 59 | REG_M3CF_ERR, 60 | REG_M3CF_SEC, 61 | REG_M3CF_LBA1, 62 | REG_M3CF_LBA2, 63 | REG_M3CF_LBA3, 64 | REG_M3CF_LBA4 65 | }; 66 | 67 | 68 | bool _M3CF_startup(void) { 69 | _M3_changeMode (M3_MODE_MEDIA); 70 | return _CF_startup (&_M3CF_Registers); 71 | } 72 | 73 | 74 | const DISC_INTERFACE _io_m3cf = { 75 | DEVICE_TYPE_M3CF, 76 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA, 77 | (FN_MEDIUM_STARTUP)&_M3CF_startup, 78 | (FN_MEDIUM_ISINSERTED)&_CF_isInserted, 79 | (FN_MEDIUM_READSECTORS)&_CF_readSectors, 80 | (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors, 81 | (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus, 82 | (FN_MEDIUM_SHUTDOWN)&_CF_shutdown 83 | } ; 84 | -------------------------------------------------------------------------------- /src/disc_io/io_m3cf.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3cf.h 3 | 4 | Hardware Routines for reading a compact flash card 5 | using the M3 CF 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 2006-07-11 - Chishm 31 | * Original release 32 | */ 33 | 34 | #ifndef IO_M3CF_H 35 | #define IO_M3CF_H 36 | 37 | // 'M3CF' 38 | #define DEVICE_TYPE_M3CF 0x4643334D 39 | 40 | #include 41 | 42 | // export interface 43 | extern const DISC_INTERFACE _io_m3cf ; 44 | 45 | #endif // define IO_M3CF_H 46 | -------------------------------------------------------------------------------- /src/disc_io/io_m3sd.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3sd.h 3 | 4 | Hardware Routines for reading a Secure Digital card 5 | using the M3 SD 6 | 7 | Some code based on M3 SD drivers supplied by M3Adapter. 8 | Some code written by SaTa may have been unknowingly used. 9 | 10 | Copyright (c) 2006 Michael "Chishm" Chisholm 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation and/or 19 | other materials provided with the distribution. 20 | 3. The name of the author may not be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 25 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef IO_M3SD_H 35 | #define IO_M3SD_H 36 | 37 | // 'M3SD' 38 | #define DEVICE_TYPE_M3SD 0x4453334D 39 | 40 | #include 41 | 42 | // export interface 43 | extern const DISC_INTERFACE _io_m3sd ; 44 | 45 | #endif // define IO_M3SD_H 46 | -------------------------------------------------------------------------------- /src/disc_io/io_mpcf.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_mpcf.c based on 3 | 4 | compact_flash.c 5 | By chishm (Michael Chisholm) 6 | 7 | Hardware Routines for reading a compact flash card 8 | using the GBA Movie Player 9 | 10 | CF routines modified with help from Darkfader 11 | 12 | Copyright (c) 2006 Michael "Chishm" Chisholm 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, 18 | this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation and/or 21 | other materials provided with the distribution. 22 | 3. The name of the author may not be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | 37 | #include "io_mpcf.h" 38 | #include "io_cf_common.h" 39 | 40 | //--------------------------------------------------------------- 41 | // GBAMP CF Addresses 42 | #define REG_MPCF_STS ((vu16*)0x098C0000) // Status of the CF Card / Device control 43 | #define REG_MPCF_CMD ((vu16*)0x090E0000) // Commands sent to control chip and status return 44 | #define REG_MPCF_ERR ((vu16*)0x09020000) // Errors / Features 45 | 46 | #define REG_MPCF_SEC ((vu16*)0x09040000) // Number of sector to transfer 47 | #define REG_MPCF_LBA1 ((vu16*)0x09060000) // 1st byte of sector address 48 | #define REG_MPCF_LBA2 ((vu16*)0x09080000) // 2nd byte of sector address 49 | #define REG_MPCF_LBA3 ((vu16*)0x090A0000) // 3rd byte of sector address 50 | #define REG_MPCF_LBA4 ((vu16*)0x090C0000) // last nibble of sector address | 0xE0 51 | 52 | #define REG_MPCF_DATA ((vu16*)0x09000000) // Pointer to buffer of CF data transered from card 53 | 54 | static const CF_REGISTERS _MPCF_Registers = { 55 | REG_MPCF_DATA, 56 | REG_MPCF_STS, 57 | REG_MPCF_CMD, 58 | REG_MPCF_ERR, 59 | REG_MPCF_SEC, 60 | REG_MPCF_LBA1, 61 | REG_MPCF_LBA2, 62 | REG_MPCF_LBA3, 63 | REG_MPCF_LBA4 64 | }; 65 | 66 | /*----------------------------------------------------------------- 67 | _MPCF_startup 68 | initializes the CF interface, returns true if successful, 69 | otherwise returns false 70 | -----------------------------------------------------------------*/ 71 | bool _MPCF_startup(void) { 72 | return _CF_startup(&_MPCF_Registers); 73 | } 74 | 75 | /*----------------------------------------------------------------- 76 | the actual interface structure 77 | -----------------------------------------------------------------*/ 78 | const DISC_INTERFACE _io_mpcf = { 79 | DEVICE_TYPE_MPCF, 80 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA, 81 | (FN_MEDIUM_STARTUP)&_MPCF_startup, 82 | (FN_MEDIUM_ISINSERTED)&_CF_isInserted, 83 | (FN_MEDIUM_READSECTORS)&_CF_readSectors, 84 | (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors, 85 | (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus, 86 | (FN_MEDIUM_SHUTDOWN)&_CF_shutdown 87 | } ; 88 | -------------------------------------------------------------------------------- /src/disc_io/io_mpcf.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_mpcf.h 3 | 4 | Hardware Routines for reading a compact flash card 5 | using the GBA Movie Player 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef IO_MPCF_H 32 | #define IO_MPCF_H 33 | 34 | // 'MPCF' 35 | #define DEVICE_TYPE_MPCF 0x4643504D 36 | 37 | #include 38 | 39 | // export interface 40 | extern const DISC_INTERFACE _io_mpcf ; 41 | 42 | #endif // define IO_MPCF_H 43 | -------------------------------------------------------------------------------- /src/disc_io/io_sc_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_m3_common.h 3 | 4 | Routines common to all version of the Super Card 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "io_sc_common.h" 31 | 32 | /*----------------------------------------------------------------- 33 | _SC_changeMode (was SC_Unlock) 34 | Added by MightyMax 35 | Modified by Chishm 36 | Modified again by loopy 37 | 1=ram(readonly), 5=ram, 3=SD interface? 38 | -----------------------------------------------------------------*/ 39 | void _SC_changeMode(u8 mode) { 40 | vu16 *unlockAddress = (vu16*)0x09FFFFFE; 41 | *unlockAddress = 0xA55A ; 42 | *unlockAddress = 0xA55A ; 43 | *unlockAddress = mode ; 44 | *unlockAddress = mode ; 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/disc_io/io_sc_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_sc_common.h 3 | 4 | Routines common to all version of the Super Card 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef IO_SC_COMMON_H 31 | #define IO_SC_COMMON_H 32 | 33 | #include 34 | 35 | // Values for changing mode 36 | #define SC_MODE_FLASH 0x1510 37 | #define SC_MODE_RAM 0x5 38 | #define SC_MODE_MEDIA 0x3 39 | #define SC_MODE_RAM_RO 0x1 40 | 41 | extern void _SC_changeMode (u8 mode); 42 | 43 | #endif // IO_SC_COMMON_H 44 | -------------------------------------------------------------------------------- /src/disc_io/io_sccf.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_sccf.c based on 3 | 4 | compact_flash.c 5 | By chishm (Michael Chisholm) 6 | 7 | Hardware Routines for reading a compact flash card 8 | using the Super Card CF 9 | 10 | CF routines modified with help from Darkfader 11 | 12 | Copyright (c) 2006 Michael "Chishm" Chisholm 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, 18 | this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation and/or 21 | other materials provided with the distribution. 22 | 3. The name of the author may not be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | 37 | #include "io_sccf.h" 38 | #include "io_sc_common.h" 39 | #include "io_cf_common.h" 40 | 41 | //--------------------------------------------------------------- 42 | // SC CF Addresses 43 | #define REG_SCCF_STS ((vu16*)0x098C0000) // Status of the CF Card / Device control 44 | #define REG_SCCF_CMD ((vu16*)0x090E0000) // Commands sent to control chip and status return 45 | #define REG_SCCF_ERR ((vu16*)0x09020000) // Errors / Features 46 | 47 | #define REG_SCCF_SEC ((vu16*)0x09040000) // Number of sector to transfer 48 | #define REG_SCCF_LBA1 ((vu16*)0x09060000) // 1st byte of sector address 49 | #define REG_SCCF_LBA2 ((vu16*)0x09080000) // 2nd byte of sector address 50 | #define REG_SCCF_LBA3 ((vu16*)0x090A0000) // 3rd byte of sector address 51 | #define REG_SCCF_LBA4 ((vu16*)0x090C0000) // last nibble of sector address | 0xE0 52 | 53 | #define REG_SCCF_DATA ((vu16*)0x09000000) // Pointer to buffer of CF data transered from card 54 | 55 | static const CF_REGISTERS _SCCF_Registers = { 56 | REG_SCCF_DATA, 57 | REG_SCCF_STS, 58 | REG_SCCF_CMD, 59 | REG_SCCF_ERR, 60 | REG_SCCF_SEC, 61 | REG_SCCF_LBA1, 62 | REG_SCCF_LBA2, 63 | REG_SCCF_LBA3, 64 | REG_SCCF_LBA4 65 | }; 66 | 67 | 68 | bool _SCCF_startup(void) { 69 | _SC_changeMode (SC_MODE_MEDIA); 70 | return _CF_startup(&_SCCF_Registers); 71 | } 72 | 73 | 74 | const DISC_INTERFACE _io_sccf = { 75 | DEVICE_TYPE_SCCF, 76 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA, 77 | (FN_MEDIUM_STARTUP)&_SCCF_startup, 78 | (FN_MEDIUM_ISINSERTED)&_CF_isInserted, 79 | (FN_MEDIUM_READSECTORS)&_CF_readSectors, 80 | (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors, 81 | (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus, 82 | (FN_MEDIUM_SHUTDOWN)&_CF_shutdown 83 | } ; 84 | -------------------------------------------------------------------------------- /src/disc_io/io_sccf.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_sccf.h 3 | 4 | Hardware Routines for reading a compact flash card 5 | using the Supercard CF 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 2006-07-11 - Chishm 31 | * Original release 32 | */ 33 | 34 | #ifndef IO_SCCF_H 35 | #define IO_SCCF_H 36 | 37 | // 'SCCF' 38 | #define DEVICE_TYPE_SCCF 0x46434353 39 | 40 | #include 41 | 42 | // export interface 43 | extern const DISC_INTERFACE _io_sccf; 44 | 45 | #endif // define IO_SCCF_H 46 | -------------------------------------------------------------------------------- /src/disc_io/io_scsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_scsd.h 3 | 4 | Hardware Routines for reading a Secure Digital card 5 | using the Supercard SD 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 2006-07-11 - Chishm 31 | * Original release 32 | 33 | 2006-07-22 - Chishm 34 | * First release of stable code 35 | */ 36 | 37 | #ifndef IO_SCSD_H 38 | #define IO_SCSD_H 39 | 40 | // 'SCSD' 41 | #define DEVICE_TYPE_SCSD 0x44534353 42 | 43 | #include 44 | 45 | // export interface 46 | extern const DISC_INTERFACE _io_scsd ; 47 | 48 | #endif // define IO_SCSD_H 49 | -------------------------------------------------------------------------------- /src/disc_io/io_scsd_s.s: -------------------------------------------------------------------------------- 1 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 2 | @ io_scsd_s.s 3 | @ 4 | @ Hardware Routines for reading a Secure Digital card 5 | @ using the SC SD 6 | @ 7 | @ Based on code supplied by Romman 8 | @ 9 | @ Copyright (c) 2006 Michael "Chishm" Chisholm 10 | @ 11 | @ Redistribution and use in source and binary forms, with or without modification, 12 | @ are permitted provided that the following conditions are met: 13 | @ 14 | @ 1. Redistributions of source code must retain the above copyright notice, 15 | @ this list of conditions and the following disclaimer. 16 | @ 2. Redistributions in binary form must reproduce the above copyright notice, 17 | @ this list of conditions and the following disclaimer in the documentation and/or 18 | @ other materials provided with the distribution. 19 | @ 3. The name of the author may not be used to endorse or promote products derived 20 | @ from this software without specific prior written permission. 21 | @ 22 | @ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | @ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 24 | @ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 25 | @ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | @ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | @ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | @ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | @ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | @ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | @ 32 | @ 2006-07-22 - Chishm 33 | @ * First release of stable code 34 | @ 35 | @ 2006-08-19 - Chishm 36 | @ * Added SuperCard Lite support 37 | @ 38 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39 | 40 | .align 4 41 | .arm 42 | 43 | .equ REG_SCSD_DATAWRITE, 0x09000000 44 | .equ BYTES_PER_READ, 0x200 45 | .equ SCSD_STS_BUSY, 0x100 46 | .equ BUSY_WAIT_TIMEOUT, 0x10000 47 | .equ FALSE, 0 48 | .equ TRUE, 1 49 | 50 | @ bool _SCSD_writeData_s (u8 *data, u16* crc) 51 | 52 | .global _SCSD_writeData_s 53 | 54 | _SCSD_writeData_s: 55 | stmfd r13!, {r4-r5} 56 | mov r5, #BYTES_PER_READ 57 | mov r2, #REG_SCSD_DATAWRITE 58 | 59 | @ Wait for a free data buffer on the SD card 60 | mov r4, #BUSY_WAIT_TIMEOUT 61 | _SCSD_writeData_busy_wait: 62 | @ Test for timeout 63 | subs r4, r4, #1 64 | moveq r0, #FALSE @ return false on failure 65 | beq _SCSD_writeData_return 66 | @ Check the busy bit of the status register 67 | ldrh r3, [r2] 68 | tst r3, #SCSD_STS_BUSY 69 | beq _SCSD_writeData_busy_wait 70 | 71 | ldrh r3, [r2] @ extra clock 72 | 73 | mov r3, #0 @ start bit 74 | strh r3,[r2] 75 | 76 | @ Check if the data buffer is aligned on a halfword boundary 77 | tst r0, #1 78 | beq _SCSD_writeData_data_loop 79 | 80 | @ Used when the source data is unaligned 81 | _SCSD_writeData_data_loop_unaligned: 82 | ldrb r3, [r0], #1 83 | ldrb r4, [r0], #1 84 | orr r3, r3, r4, lsl #8 85 | stmia r2, {r3-r4} 86 | subs r5, r5, #2 87 | bne _SCSD_writeData_data_loop_unaligned 88 | b _SCSD_writeData_crc 89 | 90 | @ Write the data to the card 91 | @ 4 halfwords are transmitted to the Supercard at once, for timing purposes 92 | @ Only the first halfword needs to contain data for standard SuperCards 93 | @ For the SuperCard Lite, the data is split into 4 nibbles, one per halfword 94 | _SCSD_writeData_data_loop: 95 | ldrh r3, [r0], #2 96 | 97 | @ This bit added for SCLite. Notice that the shift is not the same as in 98 | @ the original (buggy) code supplied by Romman 99 | add r3, r3, r3, lsl #20 100 | mov r4, r3, lsr #8 101 | 102 | stmia r2, {r3-r4} 103 | 104 | subs r5, r5, #2 105 | bne _SCSD_writeData_data_loop 106 | 107 | @ Send the data CRC 108 | _SCSD_writeData_crc: 109 | cmp r1, #0 110 | movne r0, r1 111 | movne r1, #0 112 | movne r5, #8 113 | bne _SCSD_writeData_data_loop 114 | 115 | mov r3, #0xff @ end bit 116 | strh r3, [r2] 117 | 118 | @ Wait for the SD card to signal that it is finished recieving 119 | mov r4, #BUSY_WAIT_TIMEOUT 120 | _SCSD_writeData_finished_wait: 121 | @ Test for timeout 122 | subs r4, r4, #1 123 | moveq r0, #FALSE @ return false on failure 124 | beq _SCSD_writeData_return 125 | @ Check the busy bit of the status register 126 | ldrh r3, [r2] 127 | tst r3, #0x100 128 | bne _SCSD_writeData_finished_wait 129 | 130 | @ Send 8 more clocks, as required by the SD card 131 | ldmia r2, {r3-r4} 132 | 133 | @ return true for success 134 | mov r0, #TRUE 135 | 136 | _SCSD_writeData_return: 137 | ldmfd r13!,{r4-r5} 138 | bx r14 139 | 140 | -------------------------------------------------------------------------------- /src/disc_io/io_sd_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | io_sd_common.c 3 | 4 | By chishm (Michael Chisholm) 5 | 6 | Common SD card routines 7 | 8 | SD routines partially based on sd.s by Romman 9 | 10 | Copyright (c) 2006 Michael "Chishm" Chisholm 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation and/or 19 | other materials provided with the distribution. 20 | 3. The name of the author may not be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 25 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "io_sd_common.h" 35 | 36 | #define MAX_STARTUP_TRIES 1000 // Arbitrary value, check if the card is ready 20 times before giving up 37 | #define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up 38 | 39 | /* 40 | Improved CRC7 function provided by cory1492 41 | Calculates the CRC of an SD command, and includes the end bit in the byte 42 | */ 43 | u8 _SD_CRC7(u8* data, int cnt) { 44 | int i, a; 45 | u8 crc, temp; 46 | 47 | crc = 0; 48 | for (a = 0; a < cnt; a++) 49 | { 50 | temp = data[a]; 51 | for (i = 0; i < 8; i++) 52 | { 53 | crc <<= 1; 54 | if ((temp & 0x80) ^ (crc & 0x80)) crc ^= 0x09; 55 | temp <<= 1; 56 | } 57 | } 58 | crc = (crc << 1) | 1; 59 | return(crc); 60 | } 61 | 62 | /* 63 | Calculates the CRC16 for a sector of data. Calculates it 64 | as 4 separate lots, merged into one buffer. This is used 65 | for 4 SD data lines, not for 1 data line alone. 66 | */ 67 | void _SD_CRC16 (u8* buff, int buffLength, u8* crc16buff) { 68 | u32 a, b, c, d; 69 | int count; 70 | u32 bitPattern = 0x80808080; // r7 71 | u32 crcConst = 0x1021; // r8 72 | u32 dataByte = 0; // r2 73 | 74 | a = 0; // r3 75 | b = 0; // r4 76 | c = 0; // r5 77 | d = 0; // r6 78 | 79 | buffLength = buffLength * 8; 80 | 81 | 82 | do { 83 | if (bitPattern & 0x80) dataByte = *buff++; 84 | 85 | a = a << 1; 86 | if ( a & 0x10000) a ^= crcConst; 87 | if (dataByte & (bitPattern >> 24)) a ^= crcConst; 88 | 89 | b = b << 1; 90 | if (b & 0x10000) b ^= crcConst; 91 | if (dataByte & (bitPattern >> 25)) b ^= crcConst; 92 | 93 | c = c << 1; 94 | if (c & 0x10000) c ^= crcConst; 95 | if (dataByte & (bitPattern >> 26)) c ^= crcConst; 96 | 97 | d = d << 1; 98 | if (d & 0x10000) d ^= crcConst; 99 | if (dataByte & (bitPattern >> 27)) d ^= crcConst; 100 | 101 | bitPattern = (bitPattern >> 4) | (bitPattern << 28); 102 | } while (buffLength-=4); 103 | 104 | count = 16; // r8 105 | 106 | do { 107 | bitPattern = bitPattern << 4; 108 | if (a & 0x8000) bitPattern |= 8; 109 | if (b & 0x8000) bitPattern |= 4; 110 | if (c & 0x8000) bitPattern |= 2; 111 | if (d & 0x8000) bitPattern |= 1; 112 | 113 | a = a << 1; 114 | b = b << 1; 115 | c = c << 1; 116 | d = d << 1; 117 | 118 | count--; 119 | 120 | if (!(count & 0x01)) { 121 | *crc16buff++ = (u8)(bitPattern & 0xff); 122 | } 123 | } while (count != 0); 124 | 125 | return; 126 | } 127 | 128 | /* 129 | Initialise the SD card, after it has been sent into an Idle state 130 | cmd_6byte_response: a pointer to a function that sends the SD card a command and gets a 6 byte response 131 | cmd_17byte_response: a pointer to a function that sends the SD card a command and gets a 17 byte response 132 | use4bitBus: initialise card to use a 4 bit data bus when communicating with the card 133 | RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits. 134 | */ 135 | bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, 136 | _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response, 137 | bool use4bitBus, 138 | u32 *RCA) 139 | { 140 | u8 responseBuffer[17] = {0}; 141 | int i; 142 | 143 | for (i = 0; i < MAX_STARTUP_TRIES ; i++) { 144 | cmd_6byte_response (responseBuffer, APP_CMD, 0); 145 | // Check that the card gave the correct response 146 | if (responseBuffer[0] != APP_CMD) { 147 | return false; 148 | } 149 | if ( 150 | cmd_6byte_response (responseBuffer, SD_APP_OP_COND, SD_OCR_VALUE) && 151 | ((responseBuffer[1] & 0x80) != 0)) 152 | { 153 | // Card is ready to receive commands now 154 | break; 155 | } 156 | } 157 | if (i >= MAX_STARTUP_TRIES) { 158 | return false; 159 | } 160 | 161 | // The card's name, as assigned by the manufacturer 162 | cmd_17byte_response (responseBuffer, ALL_SEND_CID, 0); 163 | 164 | // Get a new address 165 | for (i = 0; i < MAX_STARTUP_TRIES ; i++) { 166 | cmd_6byte_response (responseBuffer, SEND_RELATIVE_ADDR, 0); 167 | *RCA = (responseBuffer[1] << 24) | (responseBuffer[2] << 16); 168 | if ((responseBuffer[3] & 0x1e) != (SD_STATE_STBY << 1)) { 169 | break; 170 | } 171 | } 172 | if (i >= MAX_STARTUP_TRIES) { 173 | return false; 174 | } 175 | 176 | // Some cards won't go to higher speeds unless they think you checked their capabilities 177 | cmd_17byte_response (responseBuffer, SEND_CSD, *RCA); 178 | 179 | // Only this card should respond to all future commands 180 | cmd_6byte_response (responseBuffer, SELECT_CARD, *RCA); 181 | 182 | if (use4bitBus) { 183 | // Set a 4 bit data bus 184 | cmd_6byte_response (responseBuffer, APP_CMD, *RCA); 185 | cmd_6byte_response (responseBuffer, SET_BUS_WIDTH, 2); // 4-bit mode. 186 | } 187 | 188 | // Use 512 byte blocks 189 | cmd_6byte_response (responseBuffer, SET_BLOCKLEN, 512); // 512 byte blocks 190 | 191 | // Wait until card is ready for data 192 | i = 0; 193 | do { 194 | if (i >= RESPONSE_TIMEOUT) { 195 | return false; 196 | } 197 | i++; 198 | } while (!cmd_6byte_response (responseBuffer, SEND_STATUS, *RCA) && ((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA))); 199 | 200 | return true; 201 | } 202 | 203 | 204 | -------------------------------------------------------------------------------- /src/disc_io/io_sd_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | io_sd_common.h 3 | 4 | By chishm (Michael Chisholm) 5 | 6 | Common SD card routines 7 | 8 | SD routines partially based on sd.s by Romman 9 | 10 | Copyright (c) 2006 Michael "Chishm" Chisholm 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation and/or 19 | other materials provided with the distribution. 20 | 3. The name of the author may not be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 25 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 26 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef IO_SD_COMMON_H 35 | #define IO_SD_COMMON_H 36 | 37 | #include 38 | 39 | /* SD commands */ 40 | #define GO_IDLE_STATE 0 41 | #define ALL_SEND_CID 2 42 | #define SEND_RELATIVE_ADDR 3 43 | #define SELECT_CARD 7 44 | #define SEND_CSD 9 45 | #define STOP_TRANSMISSION 12 46 | #define SEND_STATUS 13 47 | #define GO_INACTIVE_STATE 15 48 | #define SET_BLOCKLEN 16 49 | #define READ_SINGLE_BLOCK 17 50 | #define READ_MULTIPLE_BLOCK 18 51 | #define WRITE_BLOCK 24 52 | #define WRITE_MULTIPLE_BLOCK 25 53 | #define APP_CMD 55 54 | 55 | /* SD App commands */ 56 | #define SET_BUS_WIDTH 6 57 | #define SD_APP_OP_COND 41 58 | 59 | /* OCR (Operating Conditions Register) send value */ 60 | #define SD_OCR_VALUE 0x00030000 /* 2.8V to 3.0V */ 61 | //#define SD_OCR_VALUE 0x003F8000 /* 2.7V to 3.4V */ 62 | //#define SD_OCR_VALUE 0x00FC0000 63 | 64 | /* SD Data repsonses */ 65 | #define SD_CARD_BUSY 0xff 66 | 67 | /* SD states */ 68 | #define SD_STATE_IDLE 0 // Idle state, after power on or GO_IDLE_STATE command 69 | #define SD_STATE_READY 1 // Ready state, after card replies non-busy to SD_APP_OP_COND 70 | #define SD_STATE_IDENT 2 // Identification state, after ALL_SEND_CID 71 | #define SD_STATE_STBY 3 // Standby state, when card is deselected 72 | #define SD_STATE_TRAN 4 // Transfer state, after card is selected and ready for data transfer 73 | #define SD_STATE_DATA 5 // 74 | #define SD_STATE_RCV 6 // Receive data state 75 | #define SD_STATE_PRG 7 // Programming state 76 | #define SD_STATE_DIS 8 // Disconnect state 77 | #define SD_STATE_INA 9 // Inactive state, after GO_INACTIVE_STATE 78 | 79 | #define READY_FOR_DATA 1 // bit 8 in card status 80 | 81 | /* 82 | Calculate the CRC7 of a command and return it preshifted with 83 | an end bit added 84 | */ 85 | extern u8 _SD_CRC7(u8* data, int size); 86 | 87 | /* 88 | Calculate the CRC16 of a block of data, ready for transmission on 89 | four data lines at once 90 | */ 91 | extern void _SD_CRC16 (u8* buff, int buffLength, u8* crc16buff); 92 | 93 | typedef bool (*_SD_FN_CMD_6BYTE_RESPONSE) (u8* responseBuffer, u8 command, u32 data); 94 | typedef bool (*_SD_FN_CMD_17BYTE_RESPONSE) (u8* responseBuffer, u8 command, u32 data); 95 | 96 | /* 97 | Initialise the SD card, after it has been sent into an Idle state 98 | cmd_6byte_response: a pointer to a function that sends the SD card a command and gets a 6 byte response 99 | cmd_17byte_response: a pointer to a function that sends the SD card a command and gets a 17 byte response 100 | use4bitBus: initialise card to use a 4 bit data bus when communicating with the card 101 | RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits. 102 | */ 103 | extern bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response, 104 | _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response, 105 | bool use4bitBus, 106 | u32 *RCA); 107 | 108 | #endif // define IO_SD_COMMON_H 109 | -------------------------------------------------------------------------------- /src/fade.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba 256 color fade routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | /*--------------------------------------------------------------------------------- 29 | Fade to black implemented as a special case 30 | Calling FadeToPalette with a buffer of all zeros will do the same thing 31 | 32 | FadeToPalette will also perform a cross fade effect 33 | 34 | ---------------------------------------------------------------------------------*/ 35 | #include 36 | #include 37 | #include 38 | 39 | //--------------------------------------------------------------------------------- 40 | // Global variables 41 | //--------------------------------------------------------------------------------- 42 | u16 CurrentPalette[512] EWRAM_BSS; 43 | 44 | //--------------------------------------------------------------------------------- 45 | // fade table consists of color components & offsets in 8:8 form 46 | // Red offset, Red component ... 47 | //--------------------------------------------------------------------------------- 48 | s16 FadeTable[512*3*2] EWRAM_BSS; 49 | 50 | //--------------------------------------------------------------------------------- 51 | static void GetCurrentPalette(void) { 52 | //--------------------------------------------------------------------------------- 53 | int i; 54 | vu16 * Src = BG_COLORS; 55 | vu16 * Dest = CurrentPalette; 56 | for (i = 0; i<512; i++) { 57 | *(Dest++) = *(Src++); 58 | } 59 | } 60 | 61 | //--------------------------------------------------------------------------------- 62 | void SetPalette(u16 *Palette) { 63 | //--------------------------------------------------------------------------------- 64 | u16 *From, *To; 65 | From = (u16 *)Palette; 66 | To = (u16 *)BG_COLORS; 67 | int i; 68 | 69 | for (i = 0; i<512; i++) { 70 | *(To++) = *(From++); 71 | } 72 | } 73 | 74 | //--------------------------------------------------------------------------------- 75 | static void DoFade(u32 FadeCount) { 76 | //--------------------------------------------------------------------------------- 77 | int r,g,b,index,count,color; 78 | 79 | 80 | for (count=0; count>8) | ((g>>8)<<5) | ((b>>8)<<10); 98 | *(Dest++) = color; 99 | } 100 | 101 | VBlankIntrWait(); 102 | SetPalette(CurrentPalette); 103 | } 104 | } 105 | 106 | //--------------------------------------------------------------------------------- 107 | /// Fade to a shade of grey 108 | //--------------------------------------------------------------------------------- 109 | /** Special case function for fade to Grey 110 | gray = 0 - 31 - final value of all components 111 | */ 112 | //--------------------------------------------------------------------------------- 113 | void FadeToGrayScale(int gray, int FrameCount) { 114 | //--------------------------------------------------------------------------------- 115 | int index,r,g,b,color; 116 | u16 *Src; 117 | s16 *Table; 118 | 119 | GetCurrentPalette(); 120 | Src = CurrentPalette; 121 | Table = FadeTable; 122 | 123 | for (index=0;index<512; index++) { 124 | 125 | color = *(Src++); 126 | r = (color & 0x1f) << 8; 127 | g = (color>>5 & 0x1f) << 8; 128 | b = (color>>10 & 0x1f) << 8; 129 | 130 | *Table++ = ((gray<<8)-r) / FrameCount; 131 | *Table++ = r; 132 | 133 | *Table++ = ((gray<<8)-g) / FrameCount; 134 | *Table++ = g; 135 | 136 | *Table++ = ((gray<<8)-b) / FrameCount; 137 | *Table++ = b; 138 | } 139 | 140 | DoFade( FrameCount); 141 | } 142 | 143 | //--------------------------------------------------------------------------------- 144 | /// Fade to a specific palette 145 | //--------------------------------------------------------------------------------- 146 | void FadeToPalette(const u16 *NewPalette, int FrameCount) { 147 | //--------------------------------------------------------------------------------- 148 | int index; 149 | GetCurrentPalette(); 150 | 151 | u16 *Src; 152 | u16 *Dest; 153 | s16 *Table; 154 | 155 | u16 color; 156 | s16 r1,r2,g1,g2,b1,b2; 157 | 158 | Src = CurrentPalette; 159 | Dest = (u16 *)NewPalette; 160 | Table = FadeTable; 161 | 162 | for (index=0;index<512; index++) { 163 | 164 | color = *(Src++); 165 | r1 = (color & 0x1f) << 8; // get component & convert to 8:8 166 | g1 = (color>>5 & 0x1f) << 8; 167 | b1 = (color>>10 & 0x1f) << 8; 168 | 169 | color = *(Dest++); 170 | r2 = (color & 0x1f) << 8; 171 | g2 = (color>>5 & 0x1f) << 8; 172 | b2 = (color>>10 & 0x1f) << 8; 173 | 174 | *(Table++) = (r2 - r1) / FrameCount; // Set component Delta 175 | *(Table++) = r1; // Set component start value 176 | *(Table++) = (g2 - g1) / FrameCount; 177 | *(Table++) = g1; 178 | *(Table++) = (b2 - b1) / FrameCount; 179 | *(Table++) = b1; 180 | } 181 | 182 | DoFade(FrameCount); 183 | 184 | } 185 | 186 | -------------------------------------------------------------------------------- /src/input.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba keypad input routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | //--------------------------------------------------------------------------------- 29 | #include "gba_input.h" 30 | //--------------------------------------------------------------------------------- 31 | typedef struct{ 32 | u16 Up, 33 | Down, 34 | Held, 35 | Last, 36 | DownRepeat; 37 | }__attribute__ ((packed)) KeyInput; 38 | 39 | //--------------------------------------------------------------------------------- 40 | // Global variables 41 | //--------------------------------------------------------------------------------- 42 | static KeyInput Keys = { 0,0,0,0,0 }; 43 | 44 | static u8 delay = 60, repeat = 30, count = 60; 45 | 46 | //--------------------------------------------------------------------------------- 47 | void setRepeat( int SetDelay, int SetRepeat) 48 | //--------------------------------------------------------------------------------- 49 | { 50 | delay = SetDelay; 51 | repeat = SetRepeat; 52 | } 53 | 54 | //--------------------------------------------------------------------------------- 55 | void scanKeys(void) 56 | //--------------------------------------------------------------------------------- 57 | { 58 | Keys.Last = Keys.Held; 59 | Keys.Held = (REG_KEYINPUT & 0x03ff) ^ 0x03ff; // upper 6 bits clear on hw not emulated 60 | 61 | 62 | u16 pressed = Keys.Held & ( Keys.Last ^ 0x03ff); 63 | 64 | Keys.DownRepeat |= pressed; 65 | Keys.Down |= pressed; 66 | 67 | 68 | u16 released = ((Keys.Held ^ 0x03ff) & Keys.Last); 69 | 70 | Keys.Up |= released; 71 | 72 | Keys.Down &= ~released; 73 | Keys.DownRepeat &= ~released; 74 | 75 | Keys.Up &= ~pressed; 76 | 77 | if ( Keys.Last != Keys.Held) count = delay; 78 | 79 | 80 | if ( delay != 0) 81 | { 82 | count--; 83 | if (count == 0) 84 | { 85 | count = repeat; 86 | Keys.DownRepeat |= Keys.Held; 87 | } 88 | } 89 | } 90 | 91 | //--------------------------------------------------------------------------------- 92 | u16 keysDownRepeat(void) 93 | //--------------------------------------------------------------------------------- 94 | { 95 | u16 tmp = Keys.DownRepeat; 96 | Keys.DownRepeat = 0; 97 | 98 | return tmp; 99 | } 100 | 101 | //--------------------------------------------------------------------------------- 102 | u16 keysDown(void) 103 | //--------------------------------------------------------------------------------- 104 | { 105 | u16 tmp = Keys.Down; 106 | Keys.Down = 0; 107 | 108 | return tmp; 109 | } 110 | 111 | //--------------------------------------------------------------------------------- 112 | u16 keysUp(void) 113 | //--------------------------------------------------------------------------------- 114 | { 115 | u16 tmp = Keys.Up; 116 | Keys.Up = 0; 117 | 118 | return tmp; 119 | } 120 | 121 | //--------------------------------------------------------------------------------- 122 | u16 keysHeld(void) 123 | //--------------------------------------------------------------------------------- 124 | { 125 | return Keys.Held; 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/interrupt.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba interrupt support routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | 27 | #include "gba_interrupt.h" 28 | #include "gba_video.h" 29 | 30 | //--------------------------------------------------------------------------------- 31 | struct IntTable IntrTable[MAX_INTS]; 32 | void dummy(void) {}; 33 | 34 | 35 | //--------------------------------------------------------------------------------- 36 | void InitInterrupt(void) { 37 | //--------------------------------------------------------------------------------- 38 | irqInit(); 39 | } 40 | 41 | //--------------------------------------------------------------------------------- 42 | void irqInit() { 43 | //--------------------------------------------------------------------------------- 44 | int i; 45 | 46 | // Set all interrupts to dummy functions. 47 | for(i = 0; i < MAX_INTS; i ++) 48 | { 49 | IntrTable[i].handler = dummy; 50 | IntrTable[i].mask = 0; 51 | } 52 | 53 | INT_VECTOR = IntrMain; 54 | } 55 | 56 | //--------------------------------------------------------------------------------- 57 | IntFn* SetInterrupt(irqMASK mask, IntFn function) { 58 | //--------------------------------------------------------------------------------- 59 | return irqSet(mask,function); 60 | } 61 | 62 | //--------------------------------------------------------------------------------- 63 | IntFn* irqSet(irqMASK mask, IntFn function) { 64 | //--------------------------------------------------------------------------------- 65 | int i; 66 | 67 | for (i=0;;i++) { 68 | if (!IntrTable[i].mask || IntrTable[i].mask == mask) break; 69 | } 70 | 71 | if ( i >= MAX_INTS) return NULL; 72 | 73 | IntrTable[i].handler = function; 74 | IntrTable[i].mask = mask; 75 | 76 | return &IntrTable[i].handler; 77 | 78 | } 79 | 80 | //--------------------------------------------------------------------------------- 81 | void EnableInterrupt(irqMASK mask) { 82 | //--------------------------------------------------------------------------------- 83 | irqEnable(mask); 84 | } 85 | 86 | //--------------------------------------------------------------------------------- 87 | void irqEnable ( int mask ) { 88 | //--------------------------------------------------------------------------------- 89 | REG_IME = 0; 90 | 91 | if (mask & IRQ_VBLANK) REG_DISPSTAT |= LCDC_VBL; 92 | if (mask & IRQ_HBLANK) REG_DISPSTAT |= LCDC_HBL; 93 | if (mask & IRQ_VCOUNT) REG_DISPSTAT |= LCDC_VCNT; 94 | REG_IE |= mask; 95 | REG_IME = 1; 96 | } 97 | 98 | //--------------------------------------------------------------------------------- 99 | void DisableInterrupt(irqMASK mask) { 100 | //--------------------------------------------------------------------------------- 101 | irqDisable(mask); 102 | } 103 | 104 | //--------------------------------------------------------------------------------- 105 | void irqDisable(int mask) { 106 | //--------------------------------------------------------------------------------- 107 | REG_IME = 0; 108 | 109 | if (mask & IRQ_VBLANK) REG_DISPSTAT &= ~LCDC_VBL; 110 | if (mask & IRQ_HBLANK) REG_DISPSTAT &= ~LCDC_HBL; 111 | if (mask & IRQ_VCOUNT) REG_DISPSTAT &= ~LCDC_VCNT; 112 | REG_IE &= ~mask; 113 | 114 | REG_IME = 1; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/mappy_print.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba mappy debug print routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | */ 26 | #include 27 | #include 28 | #include 29 | 30 | #define __DOUTBUFSIZE 256 31 | 32 | char __outstr[__DOUTBUFSIZE]; 33 | 34 | //--------------------------------------------------------------------------------- 35 | // VBoy and Mappy debug console output 36 | //--------------------------------------------------------------------------------- 37 | static void dprint(const char *sz) 38 | //--------------------------------------------------------------------------------- 39 | { 40 | asm volatile( 41 | "mov r2, %0\n" 42 | "ldr r0, =0xc0ded00d\n" 43 | "mov r1, #0\n" 44 | "and r0, r0, r0\n" 45 | : 46 | : 47 | "r" (sz) : 48 | "r0", "r1", "r2"); 49 | } 50 | 51 | 52 | //--------------------------------------------------------------------------------- 53 | void mappy_dprintf(char *str, ...) 54 | //--------------------------------------------------------------------------------- 55 | { 56 | va_list args; 57 | 58 | va_start(args, str); 59 | vsnprintf(__outstr,__DOUTBUFSIZE,str,args); 60 | va_end(args); 61 | 62 | dprint(__outstr); 63 | } 64 | 65 | //--------------------------------------------------------------------------------- 66 | void mappy_dputchar (int c) 67 | //--------------------------------------------------------------------------------- 68 | { 69 | snprintf(__outstr,__DOUTBUFSIZE,"%c",c); 70 | dprint(__outstr); 71 | } 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/mbv2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba mbv2 support functions 4 | 5 | Copyright 2003-2004 by Jeff Frohwein and Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "gba_sio.h" 31 | #include "mbv2.h" 32 | 33 | 34 | unsigned char __finstr[__FINBUFSIZE]; 35 | unsigned char __kinstr[__KINBUFSIZE]; 36 | int finptr = 0; 37 | int foutptr = 0; 38 | int kinptr = 0; 39 | int koutptr = 0; 40 | 41 | //--------------------------------------------------------------------------------- 42 | int __dputchar (int c) 43 | //--------------------------------------------------------------------------------- 44 | { 45 | int rcv; 46 | static int LastChar = 0; 47 | static int KbdCharNext = 0; 48 | 49 | // Set non-general purpose comms mode 50 | REG_RCNT = 0; 51 | 52 | // Init normal comms, 8 bit transfer, receive clocking 53 | //REG_SIOCNT = 0x00; 54 | REG_SIODATA8 = c; 55 | REG_SIOCNT = SIO_START; 56 | 57 | // Wait until transfer is complete 58 | while (REG_SIOCNT & SIO_START) {} 59 | // Wait until SC is low 60 | while (REG_RCNT & 1) {} 61 | 62 | // Force SD high 63 | REG_RCNT = 0x8022; 64 | 65 | // Wait until SC is high 66 | while ((REG_RCNT & 1)==0) {} 67 | 68 | rcv = REG_SIODATA8; 69 | 70 | if (KbdCharNext) 71 | { 72 | // Put into keyboard buffer 73 | __kinstr[kinptr++] = rcv; 74 | kinptr &= (__KINBUFSIZE-1); 75 | 76 | KbdCharNext = 0; 77 | 78 | // Make received char look like a NADA character 79 | // so that it won't be buffered elsewhere. 80 | LastChar = __ESCCHR; 81 | rcv = __ESC_NADA; 82 | } 83 | 84 | if (LastChar == __ESCCHR) 85 | { 86 | // Process escape character 87 | switch (rcv) 88 | { 89 | case __ESC_ESCCHR: 90 | __finstr[finptr++] = __ESCCHR; 91 | finptr &= (__FINBUFSIZE-1); 92 | break; 93 | case __ESC_KBDCHR: 94 | KbdCharNext = 1; 95 | break; 96 | } 97 | LastChar = 0; 98 | } 99 | else 100 | { 101 | if (rcv == __ESCCHR) 102 | LastChar = __ESCCHR; 103 | else 104 | { 105 | // If char received from PC then save in receive FIFO 106 | __finstr[finptr++] = rcv; 107 | finptr &= (__FINBUFSIZE-1); 108 | } 109 | } 110 | return(1); 111 | } 112 | 113 | //--------------------------------------------------------------------------------- 114 | int mbv2_dputchar (int c) 115 | //--------------------------------------------------------------------------------- 116 | { 117 | (void) __dputchar(c); 118 | if (c == __ESCCHR) 119 | (void) __dputchar(__ESC_ESCCHR); 120 | 121 | return (1); 122 | } 123 | 124 | 125 | //--------------------------------------------------------------------------------- 126 | int mbv2_dgetch (void) 127 | //--------------------------------------------------------------------------------- 128 | { 129 | int c; 130 | 131 | // If no character is in FIFO then wait for one. 132 | while (kinptr == koutptr) 133 | { 134 | __dputchar(__ESCCHR); 135 | __dputchar(__ESC_NADA); 136 | } 137 | 138 | c = __kinstr[koutptr++]; 139 | koutptr &= (__KINBUFSIZE-1); 140 | 141 | return (c); 142 | } 143 | 144 | //--------------------------------------------------------------------------------- 145 | int mbv2_dfgetch (void) 146 | //--------------------------------------------------------------------------------- 147 | { 148 | int c; 149 | 150 | // If no character is in FIFO then wait for one. 151 | while (finptr == foutptr) 152 | { 153 | __dputchar(__ESCCHR); 154 | __dputchar(__ESC_NADA); 155 | } 156 | 157 | c = __finstr[foutptr++]; 158 | foutptr &= (__FINBUFSIZE-1); 159 | 160 | return (c); 161 | } 162 | 163 | //--------------------------------------------------------------------------------- 164 | int mbv2_dkbhit (void) 165 | //--------------------------------------------------------------------------------- 166 | { 167 | return(kinptr != koutptr); 168 | } 169 | 170 | //--------------------------------------------------------------------------------- 171 | int mbv2_dfopen (const char *file, const char *type) 172 | //--------------------------------------------------------------------------------- 173 | { 174 | __dputchar(__ESCCHR); 175 | __dputchar(__ESC_FOPEN); 176 | 177 | while (*file) 178 | mbv2_dputchar(*file++); 179 | 180 | mbv2_dputchar(0); 181 | 182 | while (*type) 183 | mbv2_dputchar(*type++); 184 | 185 | mbv2_dputchar(0); 186 | 187 | return(1); 188 | } 189 | 190 | //--------------------------------------------------------------------------------- 191 | int mbv2_dfclose (int fp) 192 | //--------------------------------------------------------------------------------- 193 | { 194 | __dputchar(__ESCCHR); 195 | __dputchar(__ESC_FCLOSE); 196 | 197 | return(1); 198 | } 199 | 200 | //--------------------------------------------------------------------------------- 201 | int mbv2_dfgetc (int fp) 202 | //--------------------------------------------------------------------------------- 203 | { 204 | __dputchar(__ESCCHR); 205 | __dputchar(__ESC_FGETC); 206 | 207 | return(mbv2_dfgetch()); 208 | } 209 | 210 | //--------------------------------------------------------------------------------- 211 | int mbv2_dfputc (int ch, int fp) 212 | //--------------------------------------------------------------------------------- 213 | { 214 | __dputchar(__ESCCHR); 215 | __dputchar(__ESC_FPUTC); 216 | 217 | mbv2_dputchar(ch); 218 | 219 | return(1); 220 | } 221 | 222 | //--------------------------------------------------------------------------------- 223 | void mbv2_drewind (int fp) 224 | //--------------------------------------------------------------------------------- 225 | { 226 | __dputchar(__ESCCHR); 227 | __dputchar(__ESC_REWIND); 228 | } 229 | 230 | 231 | -------------------------------------------------------------------------------- /src/mbv2.txt: -------------------------------------------------------------------------------- 1 | // 2 | // v1.40 - Initial release. 3 | // v1.41 - Put received keyboard & file data in separate buffers 4 | // to prevent mixing of data during simultaneous use. 5 | // Added dfprintf library function. 6 | // 7 | // MB v1.41 or later pc software is required to use this library 8 | // software. 9 | // 10 | // NOTE: THIS LIBRARY USES GLOBAL INITIALIZED DATA SO YOU MUST USE 11 | // A CRT0.S AND A LINKER SCRIPT THAT SUPPORTS THIS AS WELL. GET 12 | // CRTLS V1.1 OR LATER FROM HTTP://www.devrs.com/gba FOR PROPER SUPPORT. 13 | // 14 | // The following library functions are supported: 15 | // 16 | // Library name Standard Name Function 17 | // dprintf printf Print a string on PC console. 18 | // dputchar putchar Print a char on PC console. 19 | // dgetch getch Get a char from PC keyboard. 20 | // dkbhit kbhit Return 1 if PC keyboard char is ready. 21 | // 22 | // dfopen fopen Open PC file. 23 | // dfclose fclose Close PC file. 24 | // dfprintf fprintf Print a string to PC file. 25 | // dfgetc fgetc Get char from PC file. 26 | // dfputc fputc Write a char to PC file. 27 | // drewind rewind Set file pointer to start of file. 28 | // 29 | // If you wish to use the standard naming conventions 30 | // rather than the library names then change "__ANSI_NAMES 0" 31 | // to "__ANSI_NAMES 1" instead. 32 | // 33 | // Notes: 34 | // 35 | // Currently only ONE file may be open at a time. 36 | // 37 | // If you are sending raw binary data to a PC file, use 38 | // dfputc instead of dfprintf. Dfprintf will insert 39 | // carriage return characters before linefeed characters 40 | // on the PC side if the PC console software is running on 41 | // dos/windows for proper text formatting. 42 | // 43 | // If you are missing some .h files during compile than get 44 | // 'arminc.zip' from http://www.devrs.com/gba in the 45 | // Apps / C Compilers section. 46 | // 47 | // Example command line: 48 | // mb -s file.mb -c -w 50 -x 255 -m 49 | // 50 | // In this example, after transferring "file.mb" to the GBA, 51 | // the PC goes into console/file server mode (-c) and also 52 | // shows all of the file open/file close/fgetc/fputc commands 53 | // (-m) on screen. The -w value should be a large enough value 54 | // where the -s is reliable and the -x value should be a large 55 | // enough value where the -c is reliable with the GBA. 56 | // 57 | // [Sending a file & console mode each have 58 | // their own delay settings because they 59 | // each use a different method for transferring 60 | // data. Each method is about ideal for it's 61 | // application.] 62 | // 63 | // Example GBA Code: 64 | // 65 | // #include "mbv2lib.c" 66 | // 67 | // int main (void) 68 | // { 69 | // 70 | // int i,j,k; 71 | // FILE fp; 72 | // 73 | // dprintf ("Hello world!"); 74 | // 75 | // // Get character from PC keyboard 76 | // i = dgetch (); 77 | // 78 | // // Copy SRAM or Flash backup to PC 79 | // fp = dfopen("sram.bin","wb"); 80 | // for (i = 0; i != 0x8000; i++) 81 | // dfputc(*(unsigned char *)(i + 0xE000000), fp); 82 | // dfclose(fp); 83 | // 84 | // // Copy PC to SRAM 85 | // fp = dfopen("sram.bin","rb"); 86 | // for (i = 0; i != 0x8000; i++) 87 | // *(unsigned char *)(i + 0xE000000) = dfgetc (fp); 88 | // dfclose(fp); 89 | 90 | // // Read data from file 91 | // fp = dfopen ("foo.bin", "rb"); 92 | // i = dfgetc (fp); 93 | // j = dfgetc (fp); 94 | // k = dfgetc (fp); 95 | // dfclose (fp); 96 | // 97 | // } 98 | 99 | // Data transfer format 100 | // -------------------- 101 | // 102 | // PC -> GBA Comms: 103 | // Raw data is PC File read data. 104 | // ESCCHR 0x00 = nada (used for input polling) 105 | // ESCCHR 0x01 = Escape character from PC file read 106 | // ESCCHR 0x08 0x?? = Keyboard read data 107 | // 108 | // 109 | // GBA -> PC comms 110 | // Raw data is console print data. 111 | // ESCCHR = escape sequence 112 | // ESCCHR 0x00 = nada (used for input polling) 113 | // ESCCHR 0x01 = Escape character for console print 114 | // ESCCHR 0x02 = file open (gba -> PC) 115 | // ESCCHR 0x03 = file close (gba -> PC) 116 | // ESCCHR 0x04 = fgetc (gba -> PC) 117 | // ESCCHR 0x05 0x?? = fputc (gba -> PC) 118 | // ESCCHR 0x06 = rewind (gba -> PC) 119 | // ESCCHR 0x07 = fputc processed (gba -> pC) (Add CR before LF char if win/DOS machine) 120 | -------------------------------------------------------------------------------- /src/mbv2print.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba mbv2 support routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "mbv2.h" 31 | 32 | char __outstr[__DOUTBUFSIZE]; 33 | 34 | //--------------------------------------------------------------------------------- 35 | void mbv2_dprintf(char *str, ...) 36 | //--------------------------------------------------------------------------------- 37 | { 38 | va_list args; 39 | char *string = __outstr; 40 | 41 | va_start(args, str); 42 | vsprintf(__outstr,str,args); 43 | va_end(args); 44 | 45 | while (*string) 46 | mbv2_dputchar(*string++); 47 | } 48 | 49 | //--------------------------------------------------------------------------------- 50 | void mbv2_dfprintf(int fp, char *str, ...) 51 | //--------------------------------------------------------------------------------- 52 | { 53 | va_list args; 54 | char *string = __outstr; 55 | 56 | va_start(args, str); 57 | vsprintf(__outstr,str,args); 58 | va_end(args); 59 | 60 | 61 | while (*string) 62 | { 63 | __dputchar(__ESCCHR); 64 | __dputchar(__ESC_FPUTC_PROCESSED); 65 | 66 | mbv2_dputchar(*string++); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/xcomms.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | libgba Xboo Communicator support routines 4 | 5 | Copyright 2003-2004 by Dave Murphy. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 | USA. 21 | 22 | Please report all bugs and problems through the bug tracker at 23 | "http://sourceforge.net/tracker/?group_id=114505&atid=668551". 24 | 25 | 26 | */ 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | //--------------------------------------------------------------------------------- 33 | u32 xcomms_recv(void) 34 | //--------------------------------------------------------------------------------- 35 | { 36 | REG_SIOCNT = SIO_32BIT; 37 | REG_SIOCNT = SIO_32BIT | SIO_SO_HIGH | SIO_START; 38 | 39 | while (REG_SIOCNT & SIO_START); 40 | 41 | return REG_SIODATA32; 42 | 43 | } 44 | //--------------------------------------------------------------------------------- 45 | void xcomms_send(u32 data) 46 | //--------------------------------------------------------------------------------- 47 | { 48 | REG_SIODATA32 = data; 49 | REG_SIOCNT = SIO_32BIT; 50 | REG_SIOCNT = SIO_32BIT | SIO_SO_HIGH | SIO_START; 51 | while (REG_SIOCNT & SIO_START); 52 | 53 | } 54 | 55 | //--------------------------------------------------------------------------------- 56 | void xcomms_init() 57 | //--------------------------------------------------------------------------------- 58 | { 59 | REG_RCNT = 0; 60 | REG_SIOCNT = SIO_32BIT | SIO_SO_HIGH; 61 | } 62 | 63 | //--------------------------------------------------------------------------------- 64 | u32 xcomms_exchange(u32 data) 65 | //--------------------------------------------------------------------------------- 66 | { 67 | REG_SIODATA32 = data; 68 | REG_SIOCNT = SIO_32BIT; 69 | REG_SIOCNT = SIO_32BIT | SIO_SO_HIGH | SIO_START; 70 | while (REG_SIOCNT & SIO_START); 71 | 72 | return REG_SIODATA32; 73 | 74 | } 75 | 76 | //--------------------------------------------------------------------------------- 77 | void xcomms_dputchar(int c) 78 | //--------------------------------------------------------------------------------- 79 | { 80 | xcomms_send( DPUTC_CMD | (c & 0xff)); 81 | } 82 | 83 | //--------------------------------------------------------------------------------- 84 | void xcomms_sendblock(const void *block, u32 len) 85 | //--------------------------------------------------------------------------------- 86 | { 87 | u32 data, i; 88 | u8 *ptr = (u8 *)block; 89 | for (i=0; i 28 | #include 29 | 30 | #include "xcomms_cmd.h" 31 | #include "xcomms.h" 32 | 33 | #define __DOUTBUFSIZE 256 34 | 35 | char __outstr[__DOUTBUFSIZE]; 36 | 37 | 38 | //--------------------------------------------------------------------------------- 39 | void xcomms_dprintf(char *str, ...) 40 | //--------------------------------------------------------------------------------- 41 | { 42 | va_list args; 43 | int len; 44 | 45 | va_start(args, str); 46 | len=vsnprintf(__outstr,__DOUTBUFSIZE,str,args); 47 | va_end(args); 48 | 49 | u32 data = PRINT_CMD | len; 50 | xcomms_send(data); 51 | 52 | xcomms_sendblock(__outstr,len); 53 | } 54 | 55 | --------------------------------------------------------------------------------