Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chip8 File Select Fix #48

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions applications/chip8/chip8.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ static int32_t chip8_worker(void* context) {

FURI_LOG_I(WORKER_TAG, "Start storage file alloc");
File* rom_file = storage_file_alloc(furi_storage_record);
FURI_LOG_I(WORKER_TAG, "Start storage file open, path = %s", chip8->file_path);
FURI_LOG_I(WORKER_TAG, "Start storage file open, path = %s", string_get_cstr(chip8->file_path));

uint8_t* rom_data = malloc(2048);
FURI_LOG_I(WORKER_TAG, "2048 array gotten");
uint8_t* rom_data = malloc(4096);
FURI_LOG_I(WORKER_TAG, "4096 array gotten");


while(1) {
Expand Down Expand Up @@ -115,7 +115,7 @@ static int32_t chip8_worker(void* context) {

Chip8Emulator* chip8_make_emulator(string_t file_path) {
furi_assert(file_path);
FURI_LOG_I("CHIP8", "make emulator, file_path=", file_path);
FURI_LOG_I("CHIP8", "make emulator, file_path=", string_get_cstr(file_path));

Chip8Emulator* chip8 = malloc(sizeof(Chip8Emulator));
string_init(chip8->file_path);
Expand All @@ -138,7 +138,7 @@ Chip8Emulator* chip8_make_emulator(string_t file_path) {

chip8->thread = furi_thread_alloc();
furi_thread_set_name(chip8->thread, "Chip8Worker");
furi_thread_set_stack_size(chip8->thread, 2048);
furi_thread_set_stack_size(chip8->thread, 4096);
furi_thread_set_context(chip8->thread, chip8);
furi_thread_set_callback(chip8->thread, chip8_worker);

Expand Down
3 changes: 1 addition & 2 deletions applications/chip8/chip8_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

#define CHIP8_APP_PATH_FOLDER "/any/chip8"
#define CHIP8_APP_EXTENSION ".ch8"
#define CHIP8_FILE_NAME_LEN 40

struct Chip8App{
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
DialogsApp* dialogs;

char file_name[CHIP8_FILE_NAME_LEN+ 1];
string_t file_name;
uint8_t** backup_screen;
Chip8View* chip8_view;
Chip8Emulator* chip8;
Expand Down
17 changes: 11 additions & 6 deletions applications/chip8/scenes/chip8_scene_file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@

static bool chip8_file_select(Chip8App* chip8) {
furi_assert(chip8);
string_t file_path;
string_init(file_path);
string_set_str(file_path, CHIP8_APP_PATH_FOLDER);
string_init(chip8->file_name);
string_set_str(chip8->file_name, CHIP8_APP_PATH_FOLDER);
// string_set_str(file_path, chip8->file_name);

bool res = dialog_file_browser_show(
chip8->dialogs,
file_path,
file_path,
chip8->file_name,
chip8->file_name,
CHIP8_APP_EXTENSION,
true,
&I_unknown_10px,
false);

FURI_LOG_I("Chip8_file_browser_show", "chip8->file_name: %s", string_get_cstr(chip8->file_name));
FURI_LOG_I("Chip8_file_browser_show", "res: %d", res);
return res;
}

void chip8_scene_file_select_on_enter(void* context) {
Chip8App* chip8 = context;

if(chip8_file_select(chip8)) {
FURI_LOG_I("Chip8", "chip8_file_select, file_name = %s", chip8->file_name);
FURI_LOG_I("Chip8", "chip8_file_select, file_name = %s", string_get_cstr(chip8->file_name));
scene_manager_next_scene(chip8->scene_manager, Chip8WorkView);
} else {
view_dispatcher_stop(chip8->view_dispatcher);
}
}

bool chip8_scene_file_select_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
return false;
}

void chip8_scene_file_select_on_exit(void* context) {
UNUSED(context);
}
15 changes: 8 additions & 7 deletions applications/chip8/scenes/chip8_scene_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ bool chip8_scene_work_on_event(void* context, SceneManagerEvent event) {
void chip8_scene_work_on_enter(void* context) {
Chip8App* app = context;

string_t file_name;
string_init(file_name);

chip8_set_file_name(app->chip8_view, app->file_name);

string_printf(
file_name, "%s/%s%s", CHIP8_APP_PATH_FOLDER, app->file_name, CHIP8_APP_EXTENSION);
string_t file_tmp;
string_init(file_tmp);

string_printf(file_tmp, "%s", string_get_cstr(app->file_name));

FURI_LOG_I("chip8_scene_work_on_enter","file_name: %s", string_get_cstr(file_tmp));

FURI_LOG_I("chip8_scene_work_on_enter", "START SET BACKUP SCREEN");
chip8_set_backup_screen(app->chip8_view, app->backup_screen);
FURI_LOG_I("chip8_scene_work_on_enter", "END SET BACKUP SCREEN");

app->chip8 = chip8_make_emulator(file_name);
app->chip8 = chip8_make_emulator(file_tmp);

string_clear(file_name);
string_clear(file_tmp);

chip8_set_state(app->chip8_view, chip8_get_state(app->chip8));

Expand Down
6 changes: 3 additions & 3 deletions applications/chip8/views/chip8_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Chip8View {
};

typedef struct {
char* file_name;
string_t file_name;
Chip8State state;
uint8_t** backup_screen;
} Chip8Model;
Expand Down Expand Up @@ -171,11 +171,11 @@ void chip8_set_down_callback(Chip8View* chip8, Chip8ViewKeyDownCallback callback
});
}

void chip8_set_file_name(Chip8View* chip8, char* name) {
void chip8_set_file_name(Chip8View* chip8, string_t name) {
furi_assert(name);
with_view_model(
chip8->view, (Chip8Model* model) {
model->file_name = name;
*model->file_name = *name;
return false;
});
}
Expand Down
2 changes: 1 addition & 1 deletion applications/chip8/views/chip8_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ void chip8_set_release_callback(Chip8View* chip8, Chip8ViewReleaseCallback callb

void chip8_set_backup_screen(Chip8View* chip8, uint8_t** screen);

void chip8_set_file_name(Chip8View* chip8, char* name);
void chip8_set_file_name(Chip8View* chip8, string_t name);

void chip8_set_state(Chip8View* chip8, Chip8State* st);