From 42379a1cc476d481f5aa7a7b6e69f271f079fda3 Mon Sep 17 00:00:00 2001 From: FIX94 Date: Sun, 10 Apr 2016 14:44:53 +0200 Subject: general cleanup --- gba/source/libSave.c | 114 +++++++-------------------------------------------- gba/source/main.c | 80 ++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 131 deletions(-) (limited to 'gba/source') diff --git a/gba/source/libSave.c b/gba/source/libSave.c index d545a5f..e3bda1d 100644 --- a/gba/source/libSave.c +++ b/gba/source/libSave.c @@ -4,92 +4,18 @@ routine with a pointer to an appropriately sized array of data to be read from or written to the cartridge. Data types are from wintermute's gba_types.h libgba library. + Original file from SendSave by Chishm */ #include #include #include -//--------------------------------------------------------------------------------- -#ifndef _gba_types_h_ -#define _gba_types_h_ -//--------------------------------------------------------------------------------- - -//--------------------------------------------------------------------------------- -// Data types -//--------------------------------------------------------------------------------- -/** Unsigned 8 bit value - -*/ -typedef unsigned char u8; -/** Unsigned 16 bit value - -*/ -typedef unsigned short int u16; -/** Unsigned 32 bit value - -*/ -typedef unsigned int u32; +#include -/** signed 8 bit value - -*/ -typedef signed char s8; -/** Signed 16 bit value - -*/ -typedef signed short int s16; -/** Signed 32 bit value - -*/ -typedef signed int s32; - -/** Unsigned volatile 8 bit value - -*/ -typedef volatile u8 vu8; -/** Unsigned volatile 16 bit value - -*/ -typedef volatile u16 vu16; -/** Unsigned volatile 32 bit value - -*/ -typedef volatile u32 vu32; - -/** Unsigned volatile 8 bit value - -*/ -typedef volatile s8 vs8; -/** Signed volatile 16 bit value - -*/ -typedef volatile s16 vs16; -/** Signed volatile 32 bit value - -*/ -typedef volatile s32 vs32; - -#ifndef __cplusplus -/** C++ compatible bool for C - -*/ -typedef enum { false, true } bool; -#endif - -//--------------------------------------------------------------------------------- -#endif // data types -//--------------------------------------------------------------------------------- - - -#define EEPROM_ADDRESS (volatile u16*)0xDFFFF00 -#define SRAM_ADDRESS (volatile u16*)0x0E000000 -#define FLASH_1M_ADDRESS (volatile u16*)0x09FE0000 -#define REG_EEPROM (*(volatile u16*)0xDFFFF00) -#define REG_DM3SAD (*(volatile u32*)0x40000D4) -#define REG_DM3DAD (*(volatile u32*)0x40000D8) -#define REG_DM3CNT (*(volatile u32*)0x40000DC) -#define REG_DM3CNT_H (*(volatile u16*)0x40000DE) -#define REG_WAITCNT (*(volatile u16*)0x4000204) +#define EEPROM_ADDRESS (0xDFFFF00) +#define REG_EEPROM *(vu16 *)(EEPROM_ADDRESS) +#define REG_DMA3CNT_H *(vu16 *)(REG_BASE + 0x0de) +#define REG_WAITCNT *(vu16 *)(REG_BASE + 0x204) //----------------------------------------------------------------------- // Common EEPROM Routines @@ -98,19 +24,19 @@ typedef enum { false, true } bool; void EEPROM_SendPacket( u16* packet, int size ) { REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; - REG_DM3SAD = (u32)packet; - REG_DM3DAD = (u32)EEPROM_ADDRESS; - REG_DM3CNT = 0x80000000 + size; - while((REG_DM3CNT_H & 0x8000) != 0) ; + REG_DMA3SAD = (u32)packet; + REG_DMA3DAD = EEPROM_ADDRESS; + REG_DMA3CNT = 0x80000000 + size; + while((REG_DMA3CNT_H & 0x8000) != 0) ; } void EEPROM_ReceivePacket( u16* packet, int size ) { REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; - REG_DM3SAD = (u32)EEPROM_ADDRESS; - REG_DM3DAD = (u32)packet; - REG_DM3CNT = 0x80000000 + size; - while((REG_DM3CNT_H & 0x8000) != 0) ; + REG_DMA3SAD = EEPROM_ADDRESS; + REG_DMA3DAD = (u32)packet; + REG_DMA3CNT = 0x80000000 + size; + while((REG_DMA3CNT_H & 0x8000) != 0) ; } //----------------------------------------------------------------------- @@ -213,9 +139,6 @@ void GetSave_EEPROM_512B(u8* data) volatile u8 x; u32 sleep; - // Set up waitstates for EEPROM access etc. - *(volatile unsigned short *)0x04000204 = 0x4317; - for (x=0;x<64;++x){ EEPROM_Read_512B(x,&data[x*8]); for(sleep=0;sleep<512000;sleep++); @@ -229,9 +152,6 @@ void PutSave_EEPROM_512B(u8* data) volatile u8 x; u32 sleep; - // Set up waitstates for EEPROM access etc. - *(volatile unsigned short *)0x04000204 = 0x4317; - for (x=0;x<64;x++){ EEPROM_Write_512B(x,&data[x*8]); for(sleep=0;sleep<512000;sleep++); @@ -354,9 +274,6 @@ void GetSave_EEPROM_8KB(u8* data) volatile u16 x; u32 sleep; - // Set up waitstates for EEPROM access etc. - *(volatile unsigned short *)0x04000204 = 0x4317; - for (x=0;x<1024;x++){ EEPROM_Read_8KB(x,&data[x*8]); for(sleep=0;sleep<512000;sleep++); @@ -371,9 +288,6 @@ void PutSave_EEPROM_8KB(u8* data) volatile u16 x; u32 sleep; - // Set up waitstates for EEPROM access etc. - *(volatile unsigned short *)0x04000204 = 0x4317; - for (x=0;x<1024;x++){ EEPROM_Write_8KB(x,&data[x*8]); for(sleep=0;sleep<512000;sleep++); diff --git a/gba/source/main.c b/gba/source/main.c index 567165a..49cf2a1 100644 --- a/gba/source/main.c +++ b/gba/source/main.c @@ -1,14 +1,19 @@ - -#include -#include -#include -#include -#include -#include +/* + * Copyright (C) 2016 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ +#include #include #include #include "libSave.h" +#define REG_WAITCNT *(vu16 *)(REG_BASE + 0x204) +#define JOY_WRITE 2 +#define JOY_READ 4 +#define JOY_RW 6 + u8 save_data[0x20000] __attribute__ ((section (".sbss"))); s32 getGameSize(void) @@ -33,8 +38,7 @@ s32 getGameSize(void) } return i; } -#define JOY_WRITE 2 -#define JOY_READ 4 + //--------------------------------------------------------------------------------- // Program entry point //--------------------------------------------------------------------------------- @@ -52,31 +56,32 @@ int main(void) { // ansi escape sequence to set print co-ordinates // /x1b[line;columnH u32 i; - iprintf("\x1b[9;10HROM Dumper\n"); - iprintf("\x1b[10;5HPlease look at the TV\n"); - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); - u32 prevIrqMask = REG_IME; + iprintf("\x1b[9;2HGBA Link Cable Dumper v1.3\n"); + iprintf("\x1b[10;4HPlease look at the TV\n"); + // disable this, needs power + SNDSTAT = 0; + SNDBIAS = 0; + // Set up waitstates for EEPROM access etc. + REG_WAITCNT = 0x0317; + //clear out previous messages + REG_HS_CTRL |= JOY_RW; while (1) { if((REG_HS_CTRL&JOY_READ)) { - irqDisable(IRQ_VBLANK); - REG_IME = 0; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; s32 gamesize = getGameSize(); u32 savesize = SaveSize(save_data,gamesize); REG_JOYTR = gamesize; //wait for a cmd receive for safety while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; REG_JOYTR = savesize; //wait for a cmd receive for safety while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; if(gamesize == -1) { REG_JOYTR = 0; - REG_IME = prevIrqMask; - irqEnable(IRQ_VBLANK); continue; //nothing to read } //game in, send header @@ -84,32 +89,38 @@ int main(void) { { REG_JOYTR = *(vu32*)(0x08000000+i); while((REG_HS_CTRL&JOY_READ) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; } REG_JOYTR = 0; //wait for other side to choose while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; u32 choseval = REG_JOYRE; if(choseval == 0) { REG_JOYTR = 0; - REG_IME = prevIrqMask; - irqEnable(IRQ_VBLANK); continue; //nothing to read } else if(choseval == 1) { + //disable interrupts + u32 prevIrqMask = REG_IME; + REG_IME = 0; //dump the game for(i = 0; i < gamesize; i+=4) { REG_JOYTR = *(vu32*)(0x08000000+i); while((REG_HS_CTRL&JOY_READ) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; } + //restore interrupts + REG_IME = prevIrqMask; } else if(choseval == 2) { + //disable interrupts + u32 prevIrqMask = REG_IME; + REG_IME = 0; //backup save switch (savesize){ case 0x200: @@ -130,16 +141,19 @@ int main(void) { default: break; } + //restore interrupts + REG_IME = prevIrqMask; + //say gc side we read it REG_JOYTR = savesize; //wait for a cmd receive for safety while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; //send the save for(i = 0; i < savesize; i+=4) { REG_JOYTR = *(vu32*)(save_data+i); while((REG_HS_CTRL&JOY_READ) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; } } else if(choseval == 3) @@ -149,9 +163,12 @@ int main(void) { for(i = 0; i < savesize; i+=4) { while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; *(vu32*)(save_data+i) = REG_JOYRE; } + //disable interrupts + u32 prevIrqMask = REG_IME; + REG_IME = 0; //write it switch (savesize){ case 0x200: @@ -172,14 +189,15 @@ int main(void) { default: break; } + //restore interrupts + REG_IME = prevIrqMask; + //say gc side we're done REG_JOYTR = 0; //wait for a cmd receive for safety while((REG_HS_CTRL&JOY_WRITE) == 0) ; - REG_HS_CTRL |= (JOY_WRITE|JOY_READ); + REG_HS_CTRL |= JOY_RW; } REG_JOYTR = 0; - REG_IME = prevIrqMask; - irqEnable(IRQ_VBLANK); } Halt(); } -- cgit 1.4.1