about summary refs log tree commit diff stats
path: root/gba/source/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'gba/source/main.c')
-rw-r--r--gba/source/main.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/gba/source/main.c b/gba/source/main.c new file mode 100644 index 0000000..9d05189 --- /dev/null +++ b/gba/source/main.c
@@ -0,0 +1,94 @@
1
2#include <gba_console.h>
3#include <gba_video.h>
4#include <gba_interrupt.h>
5#include <gba_systemcalls.h>
6#include <gba_input.h>
7#include <gba_sio.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11u32 getGameSize(void)
12{
13 if(*(vu32*)(0x08000004) != 0x51AEFF24)
14 return 0;
15 u32 i;
16 for(i = (1<<20); i < (1<<25); i<<=1)
17 {
18 vu16 *rompos = (vu16*)(0x08000000+i);
19 int j;
20 bool romend = true;
21 for(j = 0; j < 0x1000; j++)
22 {
23 if(rompos[j] != j)
24 {
25 romend = false;
26 break;
27 }
28 }
29 if(romend) break;
30 }
31 return i;
32}
33//---------------------------------------------------------------------------------
34// Program entry point
35//---------------------------------------------------------------------------------
36int main(void) {
37//---------------------------------------------------------------------------------
38
39 // the vblank interrupt must be enabled for VBlankIntrWait() to work
40 // since the default dispatcher handles the bios flags no vblank handler
41 // is required
42 irqInit();
43 irqEnable(IRQ_VBLANK);
44
45 consoleDemoInit();
46 REG_JOYTR = 0;
47 // ansi escape sequence to set print co-ordinates
48 // /x1b[line;columnH
49 u32 i;
50 iprintf("\x1b[9;10HROM Dumper\n");
51 iprintf("\x1b[10;5HPlease look at the TV\n");
52 REG_HS_CTRL |= 6;
53 while (1) {
54 if((REG_HS_CTRL&4))
55 {
56 REG_HS_CTRL |= 4;
57 u32 gamesize = getGameSize();
58 REG_JOYTR = gamesize;
59 while((REG_HS_CTRL&4) == 0) ;
60 REG_HS_CTRL |= 4;
61 if(gamesize == 0)
62 {
63 REG_JOYTR = 0;
64 continue; //nothing to read
65 }
66 //game in, send header
67 for(i = 0; i < 0xC0; i+=4)
68 {
69 REG_JOYTR = *(vu32*)(0x08000000+i);
70 while((REG_HS_CTRL&4) == 0) ;
71 REG_HS_CTRL |= 4;
72 }
73 //wait for other side to choose
74 while((REG_HS_CTRL&2) == 0) ;
75 REG_HS_CTRL |= 2;
76 if(REG_JOYRE == 0)
77 {
78 REG_JOYTR = 0;
79 continue; //nothing to read
80 }
81 //dump the game
82 for(i = 0; i < gamesize; i+=4)
83 {
84 REG_JOYTR = *(vu32*)(0x08000000+i);
85 while((REG_HS_CTRL&4) == 0) ;
86 REG_HS_CTRL |= 4;
87 }
88 REG_JOYTR = 0;
89 }
90 Halt();
91 }
92}
93
94