35868d35 |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
35868d35 |
4 | |
b2b95d2e |
5 | #include "../../driver.h" |
6 | #include "../common/config.h" |
7 | #include "../common/args.h" |
4a2a617a |
8 | #include "../common/platform.h" |
9 | #include "../common/settings.h" |
10 | #include "../common/revision.h" |
22f08d95 |
11 | #include "gp2x-video.h" |
35868d35 |
12 | #ifdef NETWORK |
13 | #include "unix-netplay.h" |
14 | #endif |
b2b95d2e |
15 | |
35868d35 |
16 | #include "minimal.h" |
b2b95d2e |
17 | #include "cpuctrl.h" |
18 | #include "squidgehack.h" |
22f08d95 |
19 | |
7b356ee3 |
20 | extern uint8 PAL; |
21 | |
35868d35 |
22 | char *DriverUsage= |
4a2a617a |
23 | "-mmuhack x Enable squidge's MMU hack if x is nonzero (GP2X).\n\ |
b2b95d2e |
24 | -ramtimings x Enable RAM overclocking if x is nonzero (GP2X).\n\ |
4a2a617a |
25 | "; |
35868d35 |
26 | |
35868d35 |
27 | ARGPSTRUCT DriverArgs[]={ |
b2b95d2e |
28 | {"-mmuhack",0,&Settings.mmuhack,0}, |
29 | {"-ramtimings",0,&Settings.ramtimings,0}, |
30 | {"-menu",0,&ext_menu,0x4001}, |
31 | {"-menustate",0,&ext_state,0x4001}, |
35868d35 |
32 | {0,0,0,0} |
33 | }; |
34 | |
35868d35 |
35 | void GetBaseDirectory(char *BaseDirectory) |
36 | { |
b2b95d2e |
37 | strcpy(BaseDirectory, "fceultra"); |
35868d35 |
38 | } |
39 | |
40 | static void SetDefaults(void) |
41 | { |
b2b95d2e |
42 | memset(&Settings,0,sizeof(Settings)); |
43 | Settings.cpuclock = 150; |
44 | Settings.frameskip = -1; // auto |
45 | Settings.mmuhack = 1; |
e6ee7529 |
46 | Settings.sound_rate = 22050; |
989672f4 |
47 | Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire |
48 | Settings.gamma = 100; |
6f6bc6fa |
49 | Settings.sstate_confirm = 1; |
b547bda7 |
50 | // default controls, RLDU SEBA |
51 | Settings.KeyBinds[ 0] = 0x010; // GP2X_UP |
52 | Settings.KeyBinds[ 4] = 0x020; // GP2X_DOWN |
53 | Settings.KeyBinds[ 2] = 0x040; // GP2X_LEFT |
54 | Settings.KeyBinds[ 6] = 0x080; // GP2X_RIGHT |
55 | Settings.KeyBinds[13] = 0x001; // GP2X_B |
56 | Settings.KeyBinds[14] = 0x002; // GP2X_X |
989672f4 |
57 | Settings.KeyBinds[12] = 0x100; // GP2X_A |
58 | Settings.KeyBinds[15] = 0x200; // GP2X_Y |
b547bda7 |
59 | Settings.KeyBinds[ 8] = 0x008; // GP2X_START |
60 | Settings.KeyBinds[ 9] = 0x004; // GP2X_SELECT |
6f6bc6fa |
61 | Settings.KeyBinds[10] = 0x80000000; // GP2X_L |
62 | Settings.KeyBinds[11] = 0x40000000; // GP2X_R |
63 | Settings.KeyBinds[27] = 0xc0000000; // GP2X_PUSH |
35868d35 |
64 | } |
65 | |
66 | void DoDriverArgs(void) |
67 | { |
35868d35 |
68 | } |
b2b95d2e |
69 | |
b547bda7 |
70 | |
b547bda7 |
71 | int mmuhack_status = 0; |
35868d35 |
72 | |
b2b95d2e |
73 | |
4a2a617a |
74 | void platform_init(void) |
35868d35 |
75 | { |
4a2a617a |
76 | printf("Starting GPFCE " REV " (" __DATE__ ")\n"); |
e6ee7529 |
77 | puts("Based on FCE Ultra "VERSION_STRING" and 0.98.1x versions"); |
78 | puts("Original port by Zheng Zhu"); |
79 | puts("Menu/optimization/misc work by notaz\n"); |
35868d35 |
80 | |
b2b95d2e |
81 | gp2x_init(); |
82 | cpuctrl_init(); |
35868d35 |
83 | |
84 | SetDefaults(); |
4a2a617a |
85 | } |
b2b95d2e |
86 | |
4a2a617a |
87 | void platform_finish(void) |
88 | { |
7b356ee3 |
89 | // unscale the screen, in case it is bad. |
90 | gp2x_video_RGB_setscaling(320, 240); |
35868d35 |
91 | |
b547bda7 |
92 | if (mmuhack_status > 0) |
93 | mmuunhack(); |
94 | |
989672f4 |
95 | set_gamma(100); |
b2b95d2e |
96 | cpuctrl_deinit(); |
35868d35 |
97 | gp2x_deinit(); |
b2b95d2e |
98 | |
35868d35 |
99 | return(ret?0:-1); |
100 | } |
101 | |
4a2a617a |
102 | void platform_set_volume(int val) // 0-100 |
103 | { |
104 | platform_set_volume(val, val); |
105 | } |
b2b95d2e |
106 | |
b2b95d2e |
107 | /* optional GP2X stuff to be done after config is loaded */ |
4a2a617a |
108 | void platform_late_init(void) |
b2b95d2e |
109 | { |
110 | if (Settings.mmuhack) { |
111 | int ret = mmuhack(); |
b547bda7 |
112 | printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail"); |
113 | fflush(stdout); |
b2b95d2e |
114 | mmuhack_status = ret; |
115 | } |
116 | if (Settings.ramtimings) { |
117 | printf("setting RAM timings.. "); fflush(stdout); |
118 | // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 |
119 | set_RAM_Timings(6, 4, 1, 1, 1, 2, 2); |
120 | printf("done.\n"); fflush(stdout); |
121 | } |
122 | } |
123 | |
4a2a617a |
124 | void platform_apply_config(void) |
b547bda7 |
125 | { |
7b356ee3 |
126 | static int prev_cpuclock = 200, prev_gamma = 100, prev_vsync = 0, prev_pal = 0; |
b547bda7 |
127 | if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock) |
128 | { |
129 | set_FCLK(Settings.cpuclock); |
130 | prev_cpuclock = Settings.cpuclock; |
131 | } |
989672f4 |
132 | |
133 | if (Settings.gamma != 0 && Settings.gamma != prev_gamma) |
134 | { |
135 | set_gamma(Settings.gamma); |
136 | prev_gamma = Settings.gamma; |
137 | } |
7b356ee3 |
138 | |
139 | if (Settings.perfect_vsync != prev_vsync || (Settings.perfect_vsync && prev_pal != PAL)) |
140 | { |
141 | if (Settings.perfect_vsync) |
142 | { |
143 | set_LCD_custom_rate(PAL ? LCDR_100_02 : LCDR_120_20); |
144 | prev_pal = PAL; |
145 | } |
146 | else |
147 | { |
148 | unset_LCD_custom_rate(); |
149 | } |
150 | prev_vsync = Settings.perfect_vsync; |
151 | } |
4a2a617a |
152 | |
153 | gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8); |
154 | switch (Settings.scaling & 3) { |
155 | case 0: gp2x_video_set_offs(0); gp2x_video_RGB_setscaling(320, 240); break; |
156 | case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(256, 240); break; |
157 | case 2: gp2x_video_set_offs(32+srendline*320); gp2x_video_RGB_setscaling(256, erendline-srendline); break; |
158 | case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(320, 240); break; |
159 | } |
b547bda7 |
160 | } |
161 | |
162 | |