diff options
Diffstat (limited to 'gba/source/libSave.c')
-rw-r--r-- | gba/source/libSave.c | 114 |
1 files changed, 14 insertions, 100 deletions
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 @@ | |||
4 | routine with a pointer to an appropriately sized array of data to | 4 | routine with a pointer to an appropriately sized array of data to |
5 | be read from or written to the cartridge. | 5 | be read from or written to the cartridge. |
6 | Data types are from wintermute's gba_types.h libgba library. | 6 | Data types are from wintermute's gba_types.h libgba library. |
7 | Original file from SendSave by Chishm | ||
7 | */ | 8 | */ |
8 | 9 | ||
9 | #include <stdio.h> | 10 | #include <stdio.h> |
10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
11 | #include <string.h> | 12 | #include <string.h> |
12 | //--------------------------------------------------------------------------------- | 13 | #include <gba_dma.h> |
13 | #ifndef _gba_types_h_ | ||
14 | #define _gba_types_h_ | ||
15 | //--------------------------------------------------------------------------------- | ||
16 | |||
17 | //--------------------------------------------------------------------------------- | ||
18 | // Data types | ||
19 | //--------------------------------------------------------------------------------- | ||
20 | /** Unsigned 8 bit value | ||
21 | |||
22 | */ | ||
23 | typedef unsigned char u8; | ||
24 | /** Unsigned 16 bit value | ||
25 | |||
26 | */ | ||
27 | typedef unsigned short int u16; | ||
28 | /** Unsigned 32 bit value | ||
29 | |||
30 | */ | ||
31 | typedef unsigned int u32; | ||
32 | 14 | ||
33 | /** signed 8 bit value | 15 | #define EEPROM_ADDRESS (0xDFFFF00) |
34 | 16 | #define REG_EEPROM *(vu16 *)(EEPROM_ADDRESS) | |
35 | */ | 17 | #define REG_DMA3CNT_H *(vu16 *)(REG_BASE + 0x0de) |
36 | typedef signed char s8; | 18 | #define REG_WAITCNT *(vu16 *)(REG_BASE + 0x204) |
37 | /** Signed 16 bit value | ||
38 | |||
39 | */ | ||
40 | typedef signed short int s16; | ||
41 | /** Signed 32 bit value | ||
42 | |||
43 | */ | ||
44 | typedef signed int s32; | ||
45 | |||
46 | /** Unsigned volatile 8 bit value | ||
47 | |||
48 | */ | ||
49 | typedef volatile u8 vu8; | ||
50 | /** Unsigned volatile 16 bit value | ||
51 | |||
52 | */ | ||
53 | typedef volatile u16 vu16; | ||
54 | /** Unsigned volatile 32 bit value | ||
55 | |||
56 | */ | ||
57 | typedef volatile u32 vu32; | ||
58 | |||
59 | /** Unsigned volatile 8 bit value | ||
60 | |||
61 | */ | ||
62 | typedef volatile s8 vs8; | ||
63 | /** Signed volatile 16 bit value | ||
64 | |||
65 | */ | ||
66 | typedef volatile s16 vs16; | ||
67 | /** Signed volatile 32 bit value | ||
68 | |||
69 | */ | ||
70 | typedef volatile s32 vs32; | ||
71 | |||
72 | #ifndef __cplusplus | ||
73 | /** C++ compatible bool for C | ||
74 | |||
75 | */ | ||
76 | typedef enum { false, true } bool; | ||
77 | #endif | ||
78 | |||
79 | //--------------------------------------------------------------------------------- | ||
80 | #endif // data types | ||
81 | //--------------------------------------------------------------------------------- | ||
82 | |||
83 | |||
84 | #define EEPROM_ADDRESS (volatile u16*)0xDFFFF00 | ||
85 | #define SRAM_ADDRESS (volatile u16*)0x0E000000 | ||
86 | #define FLASH_1M_ADDRESS (volatile u16*)0x09FE0000 | ||
87 | #define REG_EEPROM (*(volatile u16*)0xDFFFF00) | ||
88 | #define REG_DM3SAD (*(volatile u32*)0x40000D4) | ||
89 | #define REG_DM3DAD (*(volatile u32*)0x40000D8) | ||
90 | #define REG_DM3CNT (*(volatile u32*)0x40000DC) | ||
91 | #define REG_DM3CNT_H (*(volatile u16*)0x40000DE) | ||
92 | #define REG_WAITCNT (*(volatile u16*)0x4000204) | ||
93 | 19 | ||
94 | //----------------------------------------------------------------------- | 20 | //----------------------------------------------------------------------- |
95 | // Common EEPROM Routines | 21 | // Common EEPROM Routines |
@@ -98,19 +24,19 @@ typedef enum { false, true } bool; | |||
98 | void EEPROM_SendPacket( u16* packet, int size ) | 24 | void EEPROM_SendPacket( u16* packet, int size ) |
99 | { | 25 | { |
100 | REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; | 26 | REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; |
101 | REG_DM3SAD = (u32)packet; | 27 | REG_DMA3SAD = (u32)packet; |
102 | REG_DM3DAD = (u32)EEPROM_ADDRESS; | 28 | REG_DMA3DAD = EEPROM_ADDRESS; |
103 | REG_DM3CNT = 0x80000000 + size; | 29 | REG_DMA3CNT = 0x80000000 + size; |
104 | while((REG_DM3CNT_H & 0x8000) != 0) ; | 30 | while((REG_DMA3CNT_H & 0x8000) != 0) ; |
105 | } | 31 | } |
106 | 32 | ||
107 | void EEPROM_ReceivePacket( u16* packet, int size ) | 33 | void EEPROM_ReceivePacket( u16* packet, int size ) |
108 | { | 34 | { |
109 | REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; | 35 | REG_WAITCNT = (REG_WAITCNT & 0xF8FF) | 0x0300; |
110 | REG_DM3SAD = (u32)EEPROM_ADDRESS; | 36 | REG_DMA3SAD = EEPROM_ADDRESS; |
111 | REG_DM3DAD = (u32)packet; | 37 | REG_DMA3DAD = (u32)packet; |
112 | REG_DM3CNT = 0x80000000 + size; | 38 | REG_DMA3CNT = 0x80000000 + size; |
113 | while((REG_DM3CNT_H & 0x8000) != 0) ; | 39 | while((REG_DMA3CNT_H & 0x8000) != 0) ; |
114 | } | 40 | } |
115 | 41 | ||
116 | //----------------------------------------------------------------------- | 42 | //----------------------------------------------------------------------- |
@@ -213,9 +139,6 @@ void GetSave_EEPROM_512B(u8* data) | |||
213 | volatile u8 x; | 139 | volatile u8 x; |
214 | u32 sleep; | 140 | u32 sleep; |
215 | 141 | ||
216 | // Set up waitstates for EEPROM access etc. | ||
217 | *(volatile unsigned short *)0x04000204 = 0x4317; | ||
218 | |||
219 | for (x=0;x<64;++x){ | 142 | for (x=0;x<64;++x){ |
220 | EEPROM_Read_512B(x,&data[x*8]); | 143 | EEPROM_Read_512B(x,&data[x*8]); |
221 | for(sleep=0;sleep<512000;sleep++); | 144 | for(sleep=0;sleep<512000;sleep++); |
@@ -229,9 +152,6 @@ void PutSave_EEPROM_512B(u8* data) | |||
229 | volatile u8 x; | 152 | volatile u8 x; |
230 | u32 sleep; | 153 | u32 sleep; |
231 | 154 | ||
232 | // Set up waitstates for EEPROM access etc. | ||
233 | *(volatile unsigned short *)0x04000204 = 0x4317; | ||
234 | |||
235 | for (x=0;x<64;x++){ | 155 | for (x=0;x<64;x++){ |
236 | EEPROM_Write_512B(x,&data[x*8]); | 156 | EEPROM_Write_512B(x,&data[x*8]); |
237 | for(sleep=0;sleep<512000;sleep++); | 157 | for(sleep=0;sleep<512000;sleep++); |
@@ -354,9 +274,6 @@ void GetSave_EEPROM_8KB(u8* data) | |||
354 | volatile u16 x; | 274 | volatile u16 x; |
355 | u32 sleep; | 275 | u32 sleep; |
356 | 276 | ||
357 | // Set up waitstates for EEPROM access etc. | ||
358 | *(volatile unsigned short *)0x04000204 = 0x4317; | ||
359 | |||
360 | for (x=0;x<1024;x++){ | 277 | for (x=0;x<1024;x++){ |
361 | EEPROM_Read_8KB(x,&data[x*8]); | 278 | EEPROM_Read_8KB(x,&data[x*8]); |
362 | for(sleep=0;sleep<512000;sleep++); | 279 | for(sleep=0;sleep<512000;sleep++); |
@@ -371,9 +288,6 @@ void PutSave_EEPROM_8KB(u8* data) | |||
371 | volatile u16 x; | 288 | volatile u16 x; |
372 | u32 sleep; | 289 | u32 sleep; |
373 | 290 | ||
374 | // Set up waitstates for EEPROM access etc. | ||
375 | *(volatile unsigned short *)0x04000204 = 0x4317; | ||
376 | |||
377 | for (x=0;x<1024;x++){ | 291 | for (x=0;x<1024;x++){ |
378 | EEPROM_Write_8KB(x,&data[x*8]); | 292 | EEPROM_Write_8KB(x,&data[x*8]); |
379 | for(sleep=0;sleep<512000;sleep++); | 293 | for(sleep=0;sleep<512000;sleep++); |