-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu_rewind.c
317 lines (289 loc) · 11.2 KB
/
menu_rewind.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//
// Created by Papiex on 18.07.2018.
//
#include "menu_rewind.h"
#include "tools.h"
#include "rewind.h"
#define MAX_MENU_ENTRY_LENGTH 200
static int rin_menu_rewind_get_config_decrease_row(const int MAX_ROW, int sel);
static int rin_menu_rewind_get_config_increase_row(const int MAX_ROW, int sel);
static void rin_menu_rewind_get_config_save_value(SETTING* localSettings);
static void rin_menu_rewind_get_config_increase_value(SETTING *local, short longStep);
static void rin_menu_rewind_get_config_decrease_value(SETTING *local, short longStep);
static void rin_menu_rewind_get_config_show_current(long sel,int* crs_count,SETTING* local);
static void rin_menu_rewind_get_config_toogle_max(SETTING *local);
static void change_value(u32 *baseValue, int lowerBound, int upperBound, int step, int direction);
static void rin_frame_rewind_use_max();
static void rin_frame_rewind_no_max();
static void rin_frame_rewind_change_mode();
static void rin_frame_rewind_disabled();
static void change_selected_value(SETTING *local, int direction, short longStep);
static void print_rewind_memory_limit_line(unsigned long *x, unsigned long *y, const SETTING *local, const long sel);
static void print_rewind_states_limit_line(unsigned long *x, unsigned long *y, const SETTING *local, const long sel);
static void print_rewind_states_help(unsigned long *x, unsigned long *y, const SETTING *local, const long sel);
static void rin_frame_rewind(SETTING *local, long sel);
/*
*
* 0 : Limit mode : memory amount
* 1 : Preferred memory amount designed for rewind purposes (current max: 23mb): 9mb | Always use MAX
* rin_frame("□:Don't Use max ×:Cancel ○:Save ");
* rin_frame("□:Use max <-:Sub ->:Add ×:Cancel ○:Save ");
*
* 0 : Limit mode : number of states
* 1 : Preferred number of rewind states : 10 states | Always use MAX
* rin_frame("□:Don't Use max ×:Cancel ○:Save ");
* rin_frame("□:Use max <-:Sub ->:Add ×:Cancel ○:Save ");
*/
static void rin_menu_rewind_get_config_toogle_max(SETTING *local) {
if(local->rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT){
local->rewind_always_use_max_memory = (u8)!local->rewind_always_use_max_memory;
}else{
local->rewind_always_use_max_states = (u8)!local->rewind_always_use_max_states;
}
}
#define REWIND_MEMORY_STEP ((int)(1 * 1024 *1024))
#define REWIND_STATES_STEP 10
#define REWIND_MEMORY_STEP_SLOW ((int)(0.1 * 1024 *1024))
#define REWIND_STATES_STEP_SLOW 1
static void rin_menu_rewind_get_config_decrease_value(SETTING *local, short longStep) {
change_selected_value(local, -1, longStep);
}
static void rin_menu_rewind_get_config_increase_value(SETTING *local, short longStep) {
change_selected_value(local, 1, longStep);
}
static void change_selected_value(SETTING *local, int direction, short longStep) {
if(local->rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT){
if(!local->rewind_always_use_max_memory){
change_value(&local->rewind_user_max_memory_ammount,REWIND_MIN_USER_MEMORY,
REWIND_MAX_USER_MEMORY,longStep?REWIND_MEMORY_STEP:REWIND_MEMORY_STEP_SLOW,direction);
}
}else{
if(!local->rewind_always_use_max_states){
change_value(&local->rewind_user_max_states_ammount,REWIND_MIN_USER_STATES,
REWIND_MAX_USER_STATES,longStep?REWIND_STATES_STEP:REWIND_STATES_STEP_SLOW,direction);
}
}
}
static void change_value(u32 *baseValue, int lowerBound, int upperBound, int step, int direction){
int bv = (*baseValue);
bv += (step*direction);
if(bv > upperBound){
bv = lowerBound;
} else if(bv < lowerBound){
bv = upperBound;
}
(*baseValue) = (u32)bv;
}
static void rin_menu_rewind_get_config_save_value(SETTING* localSettings) {
memcpy(&setting,localSettings, sizeof(SETTING));
}
static int rin_menu_rewind_get_config_increase_row(const int MAX_ROW, int sel) {
sel--;
if(sel<0) sel=MAX_ROW;
return sel;
}
static int rin_menu_rewind_get_config_decrease_row(const int MAX_ROW, int sel) {
sel++;
if(sel>MAX_ROW) sel=0;
return sel;
}
static unsigned long rewind_get_text_color(const long sel,const int element) {
// return setting.color[sel==element?2:3];
return setting.color[3];
}
void rin_menu_rewind_get_config_show_current(long sel,int* crs_count,SETTING* local) {
unsigned long x=4,y=5;
rin_frame_rewind(local, sel);
if(local->rewind_enabled) {
pgPrintf(x, y++, rewind_get_text_color(sel, 0), "Limit mode : %s",
local->rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT ? "by memory amount"
: "by number of states");
y++;
if (local->rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT) {
print_rewind_memory_limit_line(&x, &y, local, sel);
} else {
print_rewind_states_limit_line(&x, &y, local, sel);
}
print_rewind_states_help(&x, &y,local,sel);
}else{
pgPrintf(x, y++, rewind_get_text_color(sel, 0), "Rewind disabled (press triangle to enable).");
}
if ((*crs_count)++>=30) (*crs_count)=0;
if ((*crs_count) < 15 && local->rewind_enabled) {
x = 3;
if (sel == 0) {
y = 5;
} else if (sel == 1) {
y = 7;
}
pgPutChar(x * 8, y * 8, setting.color[3], 0, 127, 1, 0, 1);
}
pgScreenFlipV();
}
void rin_frame_rewind(SETTING *local, long sel) {
if(local->rewind_enabled){
if(sel == 0){
rin_frame_rewind_change_mode();
}else{
if(local->rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT){
if(local->rewind_always_use_max_memory){
rin_frame_rewind_use_max();
}else{
rin_frame_rewind_no_max();
}
}else{
if(local->rewind_always_use_max_states){
rin_frame_rewind_use_max();
}else{
rin_frame_rewind_no_max();
}
}
}
}else{
rin_frame_rewind_disabled();
}
}
static void print_rewind_states_limit_line(unsigned long *x, unsigned long *y, const SETTING *local, const long sel) {
char tmpString[MAX_MENU_ENTRY_LENGTH] = {0};
if(local->rewind_always_use_max_states){
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"Always use max");
}else{
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"%d states",local->rewind_user_max_states_ammount);
}
pgPrintf(*x,*y,rewind_get_text_color(sel,1),
"Preferred number of rewind states: %s",tmpString);
}
static void print_rewind_states_help(unsigned long *x, unsigned long *y, const SETTING *local, const long sel) {
#define HELP_COLOR RGB(26, 163, 255)
unsigned help_y = 13;
unsigned help_x = 4;
char tmpString[MAX_MENU_ENTRY_LENGTH] = {0};
if(local->rewind_always_use_max_states){
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"Always use max");
}else{
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"%d states",local->rewind_user_max_states_ammount);
}
pgPrintf(help_x,help_y,HELP_COLOR, "---------------------------------------------------");
help_y += 2;
pgPrintf(help_x,help_y,HELP_COLOR, "On newer PSP models (PSP Slim and higher), more");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "memory for rewind can be enabled by using CFW with");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "extra memory for homebrew support.");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "Enter recovery menu and enable:");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "\"Advanced/Force High Memory Layout\".");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "The same applies to PS Vita with Adrenaline.");
help_y += 2;
pgPrintf(help_x,help_y,HELP_COLOR, "----------------------------------------------------");
help_y += 1;
pgPrintf(help_x,help_y,HELP_COLOR, "");
}
static void print_rewind_memory_limit_line(unsigned long *x, unsigned long *y, const SETTING *local, const long sel) {
char tmpString[MAX_MENU_ENTRY_LENGTH] = {0};
if(local->rewind_always_use_max_memory){
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"Always use max");
}else{
snprintf(tmpString,MAX_MENU_ENTRY_LENGTH,"%.1f MB",byte2mb_asFloat(local->rewind_user_max_memory_ammount));
}
pgPrintf(*x,*y,rewind_get_text_color(sel,1),
"Preferred memory amount designated for rewind");
(*y)++;
pgPrintf(*x,*y,rewind_get_text_color(sel,1),
"(current max: %.1f MB): %s",byte2mb_asFloat(max_rewind_memory),tmpString);
}
static char* rin_frame_get_title(){
return "Tweak Rewind Settings";
}
static void rin_frame_rewind_use_max() {
rin_frame(rin_frame_get_title(),"□:Don't use max ×:Cancel ○:Save ");
}
static void rin_frame_rewind_no_max(){
rin_frame(rin_frame_get_title(),"□:Use max ←:Sub →:Add △:(press) Fine tune ×:Cancel ○:Save ");
}
static void rin_frame_rewind_disabled(){
rin_frame(rin_frame_get_title(),"△: Enable Rewind ×:Cancel ○:Save ");
}
static void rin_frame_rewind_change_mode(){
rin_frame(rin_frame_get_title(),"←→:Change limit mode △: Disable Rewind ×:Cancel ○:Save ");
}
char *rin_menu_rewind_get_main_menu_string() {
static char buf[MAX_MENU_ENTRY_LENGTH] = {0};
#if 0
if(setting.rewind_limit_mode == REWIND_MODE_LIMIT_MEMORY_AMOUNT) {
if(setting.rewind_always_use_max_memory){
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"Memory in use %s MB (%d states for current rom)",
get_current_rewind_memory_string(setting),num_rwnd_states);
} else{
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"Memory: user limit, using %s MB",get_current_rewind_memory_string(setting));
}
}else{
if(setting.rewind_always_use_max_states){
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"States: no limit, using %u states",num_rwnd_states);
}else{
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"States: user limit, using %u states",num_rwnd_states);
}
}
#endif
if(setting.rewind_enabled){
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"RAM used: %.1fMB (holds %d states)",
byte2mb_asFloat(get_current_rewind_memory(setting)),num_rwnd_states);
}else{
snprintf(buf,MAX_MENU_ENTRY_LENGTH,"Disabled");
}
return buf;
}
void rin_menu_rewind_get_config(void) {
const int MAX_ROW = 1;
SETTING localSettings;
memcpy(&localSettings,&setting, sizeof(SETTING));
long sel=0;
int crs_count=0;
short longStep = 1;
for(;;){
readpad();
if(now_pad & (CTRL_UP|CTRL_DOWN|CTRL_LEFT|CTRL_RIGHT))
crs_count=0;
if(now_pad & CTRL_TRIANGLE) {
longStep = 0;
}else{
longStep = 1;
}
if(new_pad & CTRL_TRIANGLE){
if(sel == 0){
localSettings.rewind_enabled = (u8)!localSettings.rewind_enabled;
}
}
if(new_pad & CTRL_CIRCLE){
rin_menu_rewind_get_config_save_value(&localSettings);
free_rewind_states();
allocate_rewind_states();
break;
}else if(new_pad & CTRL_CROSS){
break;
}else if(new_pad & CTRL_SQUARE && localSettings.rewind_enabled){
if(sel == 1 ) {
rin_menu_rewind_get_config_toogle_max(&localSettings);
}
}else if(new_pad & CTRL_DOWN && localSettings.rewind_enabled){
sel = rin_menu_rewind_get_config_decrease_row(MAX_ROW, sel);
}else if(new_pad & CTRL_UP && localSettings.rewind_enabled){
sel = rin_menu_rewind_get_config_increase_row(MAX_ROW, sel);
}else if(new_pad & CTRL_RIGHT && localSettings.rewind_enabled){
if(sel == 0){
localSettings.rewind_limit_mode = (u8)!localSettings.rewind_limit_mode;
}else if (sel == 1){
rin_menu_rewind_get_config_increase_value(&localSettings, longStep);
}
}else if(new_pad & CTRL_LEFT && localSettings.rewind_enabled){
if(sel == 0){
localSettings.rewind_limit_mode = (u8)!localSettings.rewind_limit_mode;
}else if (sel == 1){
rin_menu_rewind_get_config_decrease_value(&localSettings, longStep);
}
}
rin_menu_rewind_get_config_show_current(sel,&crs_count,&localSettings);
}
}