about summary refs log tree commit diff stats
path: root/gba/source/main.c
diff options
context:
space:
mode:
authorFIX94 <fix94.1@gmail.com>2016-04-10 14:44:53 +0200
committerFIX94 <fix94.1@gmail.com>2016-04-10 14:44:53 +0200
commit42379a1cc476d481f5aa7a7b6e69f271f079fda3 (patch)
tree7109daa4a6242a8852ccd3ec364dc5ad48b0418f /gba/source/main.c
parent2abebc4d066c038594dc667be210990c4c1dce30 (diff)
downloadgen3uploader-42379a1cc476d481f5aa7a7b6e69f271f079fda3.tar.gz
gen3uploader-42379a1cc476d481f5aa7a7b6e69f271f079fda3.tar.bz2
gen3uploader-42379a1cc476d481f5aa7a7b6e69f271f079fda3.zip
general cleanup
Diffstat (limited to 'gba/source/main.c')
-rw-r--r--gba/source/main.c80
1 files changed, 49 insertions, 31 deletions
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 @@
1 1/*
2#include <gba_console.h> 2 * Copyright (C) 2016 FIX94
3#include <gba_video.h> 3 *
4#include <gba_interrupt.h> 4 * This software may be modified and distributed under the terms
5#include <gba_systemcalls.h> 5 * of the MIT license. See the LICENSE file for details.
6#include <gba_input.h> 6 */
7#include <gba_sio.h> 7#include <gba.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <stdlib.h> 9#include <stdlib.h>
10#include "libSave.h" 10#include "libSave.h"
11 11
12#define REG_WAITCNT *(vu16 *)(REG_BASE + 0x204)
13#define JOY_WRITE 2
14#define JOY_READ 4
15#define JOY_RW 6
16
12u8 save_data[0x20000] __attribute__ ((section (".sbss"))); 17u8 save_data[0x20000] __attribute__ ((section (".sbss")));
13 18
14s32 getGameSize(void) 19s32 getGameSize(void)
@@ -33,8 +38,7 @@ s32 getGameSize(void)
33 } 38 }
34 return i; 39 return i;
35} 40}
36#define JOY_WRITE 2 41
37#define JOY_READ 4
38//--------------------------------------------------------------------------------- 42//---------------------------------------------------------------------------------
39// Program entry point 43// Program entry point
40//--------------------------------------------------------------------------------- 44//---------------------------------------------------------------------------------
@@ -52,31 +56,32 @@ int main(void) {
52 // ansi escape sequence to set print co-ordinates 56 // ansi escape sequence to set print co-ordinates
53 // /x1b[line;columnH 57 // /x1b[line;columnH
54 u32 i; 58 u32 i;
55 iprintf("\x1b[9;10HROM Dumper\n"); 59 iprintf("\x1b[9;2HGBA Link Cable Dumper v1.3\n");
56 iprintf("\x1b[10;5HPlease look at the TV\n"); 60 iprintf("\x1b[10;4HPlease look at the TV\n");
57 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 61 // disable this, needs power
58 u32 prevIrqMask = REG_IME; 62 SNDSTAT = 0;
63 SNDBIAS = 0;
64 // Set up waitstates for EEPROM access etc.
65 REG_WAITCNT = 0x0317;
66 //clear out previous messages
67 REG_HS_CTRL |= JOY_RW;
59 while (1) { 68 while (1) {
60 if((REG_HS_CTRL&JOY_READ)) 69 if((REG_HS_CTRL&JOY_READ))
61 { 70 {
62 irqDisable(IRQ_VBLANK); 71 REG_HS_CTRL |= JOY_RW;
63 REG_IME = 0;
64 REG_HS_CTRL |= (JOY_WRITE|JOY_READ);
65 s32 gamesize = getGameSize(); 72 s32 gamesize = getGameSize();
66 u32 savesize = SaveSize(save_data,gamesize); 73 u32 savesize = SaveSize(save_data,gamesize);
67 REG_JOYTR = gamesize; 74 REG_JOYTR = gamesize;
68 //wait for a cmd receive for safety 75 //wait for a cmd receive for safety
69 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 76 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
70 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 77 REG_HS_CTRL |= JOY_RW;
71 REG_JOYTR = savesize; 78 REG_JOYTR = savesize;
72 //wait for a cmd receive for safety 79 //wait for a cmd receive for safety
73 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 80 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
74 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 81 REG_HS_CTRL |= JOY_RW;
75 if(gamesize == -1) 82 if(gamesize == -1)
76 { 83 {
77 REG_JOYTR = 0; 84 REG_JOYTR = 0;
78 REG_IME = prevIrqMask;
79 irqEnable(IRQ_VBLANK);
80 continue; //nothing to read 85 continue; //nothing to read
81 } 86 }
82 //game in, send header 87 //game in, send header
@@ -84,32 +89,38 @@ int main(void) {
84 { 89 {
85 REG_JOYTR = *(vu32*)(0x08000000+i); 90 REG_JOYTR = *(vu32*)(0x08000000+i);
86 while((REG_HS_CTRL&JOY_READ) == 0) ; 91 while((REG_HS_CTRL&JOY_READ) == 0) ;
87 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 92 REG_HS_CTRL |= JOY_RW;
88 } 93 }
89 REG_JOYTR = 0; 94 REG_JOYTR = 0;
90 //wait for other side to choose 95 //wait for other side to choose
91 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 96 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
92 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 97 REG_HS_CTRL |= JOY_RW;
93 u32 choseval = REG_JOYRE; 98 u32 choseval = REG_JOYRE;
94 if(choseval == 0) 99 if(choseval == 0)
95 { 100 {
96 REG_JOYTR = 0; 101 REG_JOYTR = 0;
97 REG_IME = prevIrqMask;
98 irqEnable(IRQ_VBLANK);
99 continue; //nothing to read 102 continue; //nothing to read
100 } 103 }
101 else if(choseval == 1) 104 else if(choseval == 1)
102 { 105 {
106 //disable interrupts
107 u32 prevIrqMask = REG_IME;
108 REG_IME = 0;
103 //dump the game 109 //dump the game
104 for(i = 0; i < gamesize; i+=4) 110 for(i = 0; i < gamesize; i+=4)
105 { 111 {
106 REG_JOYTR = *(vu32*)(0x08000000+i); 112 REG_JOYTR = *(vu32*)(0x08000000+i);
107 while((REG_HS_CTRL&JOY_READ) == 0) ; 113 while((REG_HS_CTRL&JOY_READ) == 0) ;
108 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 114 REG_HS_CTRL |= JOY_RW;
109 } 115 }
116 //restore interrupts
117 REG_IME = prevIrqMask;
110 } 118 }
111 else if(choseval == 2) 119 else if(choseval == 2)
112 { 120 {
121 //disable interrupts
122 u32 prevIrqMask = REG_IME;
123 REG_IME = 0;
113 //backup save 124 //backup save
114 switch (savesize){ 125 switch (savesize){
115 case 0x200: 126 case 0x200:
@@ -130,16 +141,19 @@ int main(void) {
130 default: 141 default:
131 break; 142 break;
132 } 143 }
144 //restore interrupts
145 REG_IME = prevIrqMask;
146 //say gc side we read it
133 REG_JOYTR = savesize; 147 REG_JOYTR = savesize;
134 //wait for a cmd receive for safety 148 //wait for a cmd receive for safety
135 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 149 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
136 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 150 REG_HS_CTRL |= JOY_RW;
137 //send the save 151 //send the save
138 for(i = 0; i < savesize; i+=4) 152 for(i = 0; i < savesize; i+=4)
139 { 153 {
140 REG_JOYTR = *(vu32*)(save_data+i); 154 REG_JOYTR = *(vu32*)(save_data+i);
141 while((REG_HS_CTRL&JOY_READ) == 0) ; 155 while((REG_HS_CTRL&JOY_READ) == 0) ;
142 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 156 REG_HS_CTRL |= JOY_RW;
143 } 157 }
144 } 158 }
145 else if(choseval == 3) 159 else if(choseval == 3)
@@ -149,9 +163,12 @@ int main(void) {
149 for(i = 0; i < savesize; i+=4) 163 for(i = 0; i < savesize; i+=4)
150 { 164 {
151 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 165 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
152 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 166 REG_HS_CTRL |= JOY_RW;
153 *(vu32*)(save_data+i) = REG_JOYRE; 167 *(vu32*)(save_data+i) = REG_JOYRE;
154 } 168 }
169 //disable interrupts
170 u32 prevIrqMask = REG_IME;
171 REG_IME = 0;
155 //write it 172 //write it
156 switch (savesize){ 173 switch (savesize){
157 case 0x200: 174 case 0x200:
@@ -172,14 +189,15 @@ int main(void) {
172 default: 189 default:
173 break; 190 break;
174 } 191 }
192 //restore interrupts
193 REG_IME = prevIrqMask;
194 //say gc side we're done
175 REG_JOYTR = 0; 195 REG_JOYTR = 0;
176 //wait for a cmd receive for safety 196 //wait for a cmd receive for safety
177 while((REG_HS_CTRL&JOY_WRITE) == 0) ; 197 while((REG_HS_CTRL&JOY_WRITE) == 0) ;
178 REG_HS_CTRL |= (JOY_WRITE|JOY_READ); 198 REG_HS_CTRL |= JOY_RW;
179 } 199 }
180 REG_JOYTR = 0; 200 REG_JOYTR = 0;
181 REG_IME = prevIrqMask;
182 irqEnable(IRQ_VBLANK);
183 } 201 }
184 Halt(); 202 Halt();
185 } 203 }