Skip to content

Commit 5cb58a8

Browse files
author
Maciek
committed
Rewind progress bar
1 parent 4741c4c commit 5cb58a8

File tree

9 files changed

+120
-9
lines changed

9 files changed

+120
-9
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.6)
22
project(rin C CXX)
3+
add_executable(testProgress tools.c)
34
include(/usr/local/pspdev/psp/share/cmake/PSP.cmake)
45

56
set(CMAKE_CXX_STANDARD 11)
@@ -27,5 +28,6 @@ set(return_list ".")
2728

2829

2930

30-
add_executable(rin ${all_src} tools.c tools.h menu_rewind.c menu_rewind.h menu_credits.c menu_credits.h)
31+
add_executable(rin ${all_src} tools.c tools.h menu_rewind.c menu_rewind.h menu_credits.c menu_credits.h tools.c)
32+
3133
set_target_properties(rin PROPERTIES LINKER_LANGUAGE CXX)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MODE=REL
66
TARGET = rin_rm
77
OBJS = gbcore/cpu.o gbcore/gb.o gbcore/lcd.o gbcore/sgb.o \
88
gbcore/rom.o gbcore/mbc.o gbcore/apu.o gbcore/cheat.o \
9-
main.o pg.o renderer.o rewind.o menu.o filer.o sound.o saveload.o image.o gz.o menu_rewind.o menu_credits.o
9+
main.o pg.o renderer.o rewind.o menu.o filer.o sound.o saveload.o image.o gz.o menu_rewind.o menu_credits.o tools.o
1010

1111
INCDIR =
1212

font.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,42 @@ const unsigned char font[]={
99
0x10,0x10,0x10,0x10,0x7C,0x38,0x10,0x00, //��
1010

1111
0x00,0x20,0x60,0xFE,0x60,0x20,0x00,0x00, //��
12-
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
13-
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
14-
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
15-
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
12+
// 0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
13+
0b01111110, // 9 cursor for rewind progress bar
14+
0b01111110,
15+
0b01111110,
16+
0b01111110,
17+
0b01111110,
18+
0b01111110,
19+
0b01111110,
20+
0b11111111,
21+
//0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
22+
0b00000000, // 10 main builder for rewind progress bar
23+
0b00000000,
24+
0b00000000,
25+
0b00000000,
26+
0b00000000,
27+
0b00000000,
28+
0b00000000,
29+
0b11111111,
30+
// 0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
31+
0b00000011, // 11 left limiter for rewind progress bar
32+
0b00000011,
33+
0b00000011,
34+
0b00000011,
35+
0b00000011,
36+
0b00000011,
37+
0b00000011,
38+
0b00000011,
39+
// 0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
40+
0b11000000, // 12 right limiter for rewind progress bar
41+
0b11000000,
42+
0b11000000,
43+
0b11000000,
44+
0b11000000,
45+
0b11000000,
46+
0b11000000,
47+
0b11000000,
1648
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
1749
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,
1850
0xCC,0xCC,0x33,0x33,0xCC,0xCC,0x33,0x33,

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void mainloop(void)
262262
wavout_enable=0;
263263

264264
while(1){
265-
265+
renderer_set_msg(get_rewind_progress_bar());
266266
//begin rewinds
267267
if( read_rewind_state() > 0 ){
268268

menu_credits.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static char* credits[] = {
2424
" - Dedicated menu for rewind,",
2525
" - Support for extra memory (PSP Slim),",
2626
" - Adjustable memory and states amount in rewind,",
27+
" - Progress bar for actual rewind status,",
2728
" - Fixed crash when loading game with a different",
2829
" save size than the previous one,",
2930
" - Fixed crash when putting PSP to sleep while",

rewind.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,28 @@ struct rewind_state{
2222
struct rewind_state *prev;
2323
};
2424

25-
2625
struct rewind_state *ptr_rewind_states, *prev_state, *next_state;
2726

27+
int get_used_rewind_states_number(){
28+
int retVal = 0;
29+
if(setting.rewind_enabled && ptr_rewind_states != NULL){
30+
struct rewind_state* act = ptr_rewind_states->next;
31+
while(act != ptr_rewind_states){
32+
if(act->have_data){
33+
retVal++;
34+
}
35+
act = act->next;
36+
}
37+
}
38+
return retVal;
39+
}
40+
41+
char* get_rewind_progress_bar(){
42+
int max = num_rwnd_states;
43+
int act = get_used_rewind_states_number();
44+
45+
return get_progress_bar(max,act);
46+
}
2847

2948
static void set_number_of_rewind_states(int *number_of_states);
3049

rewind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ void test_available_memory(void);
3838
unsigned establish_max_rewind_memory(void);
3939
unsigned get_current_rewind_memory(SETTING local);
4040
void print_rewind_debug_info(SETTING local,char* info);
41+
char* get_rewind_progress_bar();
4142

4243
#endif

tools.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Created by Maciej Barczak on 19.08.2018.
3+
//
4+
#include <stdio.h>
5+
#include <memory.h>
6+
#include "tools.h"
7+
8+
char *get_progress_bar(int max, int act) {
9+
#define BAR_LENGTH 60
10+
#define MAX_PROGRESS (BAR_LENGTH+1)
11+
#define MAX_STR 200
12+
const char LIMITER_CHAR_LEFT = 11;
13+
const char LIMITER_CHAR_RIGHT = 12;
14+
const char ACT_CHAR = 9;
15+
const char BUILD_CHAR = 10;
16+
static char progress[MAX_PROGRESS];
17+
static char string[MAX_STR];
18+
if (max == 0) {
19+
string[0] = '\0';
20+
} else {
21+
memset(progress, BUILD_CHAR, MAX_PROGRESS);
22+
23+
int actPercentage = MAX(MIN((100 * act) / max, 100), 0);
24+
int actInBar = (((BAR_LENGTH - 2) * actPercentage) / 100) + 1;
25+
26+
progress[0] = LIMITER_CHAR_LEFT;
27+
progress[BAR_LENGTH - 1] = LIMITER_CHAR_RIGHT;
28+
progress[BAR_LENGTH] = '\0';
29+
if (actInBar == 0) {
30+
actInBar = 1;
31+
} else if (actInBar == BAR_LENGTH - 1) {
32+
actInBar = BAR_LENGTH - 2;
33+
}
34+
progress[actInBar] = ACT_CHAR;
35+
36+
memset(string, 0, MAX_STR);
37+
// snprintf(string, MAX_STR, " Rewind :%s", progress);
38+
snprintf(string, MAX_STR, "%s", progress);
39+
}
40+
return string;
41+
}
42+
43+
//#define TESTING
44+
45+
#ifdef TESTING
46+
47+
#include <stdio.h>
48+
49+
int main() {
50+
char *progress = get_progress_bar( 1478, 1500);
51+
printf("Progress : %s , length: %d\n", progress, strlen(progress));
52+
53+
return 0;
54+
}
55+
56+
#endif // TESTING

tools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ static inline unsigned byte2kb(unsigned bytes){
2020
return bytes/1024;
2121
}
2222

23-
void ftoa(float n, char *res, int afterpoint);
23+
char* get_progress_bar(int max, int act);
2424
#endif //RIN_TOOLS_H

0 commit comments

Comments
 (0)