| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include "../../driver.h" |
| 6 | #include "../common/config.h" |
| 7 | #include "../common/args.h" |
| 8 | #include "../common/platform.h" |
| 9 | #include "../common/settings.h" |
| 10 | #include "../common/revision.h" |
| 11 | #include "gp2x-video.h" |
| 12 | #ifdef NETWORK |
| 13 | #include "unix-netplay.h" |
| 14 | #endif |
| 15 | |
| 16 | #include "minimal.h" |
| 17 | #include "cpuctrl.h" |
| 18 | #include "squidgehack.h" |
| 19 | |
| 20 | extern uint8 PAL; |
| 21 | |
| 22 | char *DriverUsage= |
| 23 | "-mmuhack x Enable squidge's MMU hack if x is nonzero (GP2X).\n\ |
| 24 | -ramtimings x Enable RAM overclocking if x is nonzero (GP2X).\n\ |
| 25 | "; |
| 26 | |
| 27 | ARGPSTRUCT DriverArgs[]={ |
| 28 | {"-mmuhack",0,&Settings.mmuhack,0}, |
| 29 | {"-ramtimings",0,&Settings.ramtimings,0}, |
| 30 | {"-menu",0,&ext_menu,0x4001}, |
| 31 | {"-menustate",0,&ext_state,0x4001}, |
| 32 | {0,0,0,0} |
| 33 | }; |
| 34 | |
| 35 | void GetBaseDirectory(char *BaseDirectory) |
| 36 | { |
| 37 | strcpy(BaseDirectory, "fceultra"); |
| 38 | } |
| 39 | |
| 40 | static void SetDefaults(void) |
| 41 | { |
| 42 | memset(&Settings,0,sizeof(Settings)); |
| 43 | Settings.cpuclock = 150; |
| 44 | Settings.frameskip = -1; // auto |
| 45 | Settings.mmuhack = 1; |
| 46 | Settings.sound_rate = 22050; |
| 47 | Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire |
| 48 | Settings.gamma = 100; |
| 49 | Settings.sstate_confirm = 1; |
| 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 |
| 57 | Settings.KeyBinds[12] = 0x100; // GP2X_A |
| 58 | Settings.KeyBinds[15] = 0x200; // GP2X_Y |
| 59 | Settings.KeyBinds[ 8] = 0x008; // GP2X_START |
| 60 | Settings.KeyBinds[ 9] = 0x004; // GP2X_SELECT |
| 61 | Settings.KeyBinds[10] = 0x80000000; // GP2X_L |
| 62 | Settings.KeyBinds[11] = 0x40000000; // GP2X_R |
| 63 | Settings.KeyBinds[27] = 0xc0000000; // GP2X_PUSH |
| 64 | } |
| 65 | |
| 66 | void DoDriverArgs(void) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | |
| 71 | int mmuhack_status = 0; |
| 72 | |
| 73 | |
| 74 | void platform_init(void) |
| 75 | { |
| 76 | printf("Starting GPFCE " REV " (" __DATE__ ")\n"); |
| 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"); |
| 80 | |
| 81 | gp2x_init(); |
| 82 | cpuctrl_init(); |
| 83 | |
| 84 | SetDefaults(); |
| 85 | } |
| 86 | |
| 87 | void platform_finish(void) |
| 88 | { |
| 89 | // unscale the screen, in case it is bad. |
| 90 | gp2x_video_RGB_setscaling(320, 240); |
| 91 | |
| 92 | if (mmuhack_status > 0) |
| 93 | mmuunhack(); |
| 94 | |
| 95 | set_gamma(100); |
| 96 | cpuctrl_deinit(); |
| 97 | gp2x_deinit(); |
| 98 | |
| 99 | return(ret?0:-1); |
| 100 | } |
| 101 | |
| 102 | void platform_set_volume(int val) // 0-100 |
| 103 | { |
| 104 | platform_set_volume(val, val); |
| 105 | } |
| 106 | |
| 107 | /* optional GP2X stuff to be done after config is loaded */ |
| 108 | void platform_late_init(void) |
| 109 | { |
| 110 | if (Settings.mmuhack) { |
| 111 | int ret = mmuhack(); |
| 112 | printf("squidge hack code finished and returned %s\n", ret > 0 ? "ok" : "fail"); |
| 113 | fflush(stdout); |
| 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 | |
| 124 | void platform_apply_config(void) |
| 125 | { |
| 126 | static int prev_cpuclock = 200, prev_gamma = 100, prev_vsync = 0, prev_pal = 0; |
| 127 | if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock) |
| 128 | { |
| 129 | set_FCLK(Settings.cpuclock); |
| 130 | prev_cpuclock = Settings.cpuclock; |
| 131 | } |
| 132 | |
| 133 | if (Settings.gamma != 0 && Settings.gamma != prev_gamma) |
| 134 | { |
| 135 | set_gamma(Settings.gamma); |
| 136 | prev_gamma = Settings.gamma; |
| 137 | } |
| 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 | } |
| 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 | } |
| 160 | } |
| 161 | |
| 162 | |