Ver código fonte

stuff, cant remember

J 3 anos atrás
pai
commit
9f859f275f

+ 3 - 1
brainfuck_i.h

@@ -37,9 +37,10 @@ typedef unsigned char byte;
 #include <toolbox/stream/file_stream.h>
 
 #define BF_INST_BUFFER_SIZE 2048
+#define BF_OUTPUT_SIZE 512
 #define BF_STACK_INITIAL_SIZE 128
+#define BF_INPUT_BUFFER_SIZE 64
 #define BF_STACK_STEP_SIZE 32
-#define BF_OUTPUT_SIZE 512
 
 enum brainfuckCustomEvent {
     // Reserve first 100 events for button types and indexes, starting from 0
@@ -70,6 +71,7 @@ struct BFApp {
     BFDevEnv* BF_dev_env;
     int dataSize;
     char dataBuffer[BF_INST_BUFFER_SIZE];
+    char inputBuffer[BF_INPUT_BUFFER_SIZE];
 };
 
 typedef enum {

+ 2 - 1
scenes/brainfuck_scene_config.h

@@ -2,4 +2,5 @@ ADD_SCENE(brainfuck, start, Start)
 ADD_SCENE(brainfuck, file_select, FileSelect)
 ADD_SCENE(brainfuck, file_create, FileCreate)
 ADD_SCENE(brainfuck, dev_env, DevEnv)
-ADD_SCENE(brainfuck, exec_env, ExecEnv)
+ADD_SCENE(brainfuck, exec_env, ExecEnv)
+ADD_SCENE(brainfuck, set_input, SetInput)

+ 41 - 0
scenes/brainfuck_scene_set_input.c

@@ -0,0 +1,41 @@
+#include "../brainfuck_i.h"
+
+void set_input_text_input_callback(void* context) {
+    BFApp* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, brainfuckCustomEventTextInputDone);
+}
+
+char tmpBuffer[64] = {};
+void brainfuck_scene_set_input_on_enter(void* context) {
+    BFApp* app = context;
+    TextInput* text_input = app->text_input;
+
+    text_input_set_header_text(text_input, "Edit input buffer");
+    text_input_set_result_callback(
+        text_input,
+        set_input_text_input_callback,
+        app,
+        tmpBuffer,
+        64,
+        true);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, brainfuckViewTextInput);
+}
+
+bool brainfuck_scene_set_input_on_event(void* context, SceneManagerEvent event) {
+    BFApp* app = context;
+    UNUSED(app);
+    
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == brainfuckCustomEventTextInputDone) {
+            memcpy(app->inputBuffer, tmpBuffer, 64);
+            scene_manager_next_scene(app->scene_manager, brainfuckSceneDevEnv);
+        }
+    }
+    return consumed;
+}
+
+void brainfuck_scene_set_input_on_exit(void* context) {
+    UNUSED(context);
+}

+ 10 - 0
views/bf_dev_env.c

@@ -28,6 +28,8 @@ static bool bf_dev_process_ok(BFDevEnv* devEnv, InputEvent* event);
 
 BFApp* appDev;
 
+char bfChars[9] = {'<', '>', '[', ']', '+', '-', '.', ',', 0x00};
+
 int selectedButton = 0;
 int saveNotifyCountdown = 0;
 int execCountdown = 0;
@@ -285,6 +287,7 @@ static bool bf_dev_process_ok(BFDevEnv* devEnv, InputEvent* event) {
         case 9:
         {
             //todo: input
+            //scene_manager_next_scene(appDev->scene_manager, brainfuckSceneSetInput);
             break;
         }
 
@@ -345,6 +348,13 @@ static void bf_dev_enter_callback(void* context) {
     stream_read(stream, (uint8_t*)appDev->dataBuffer, appDev->dataSize);
     buffered_file_stream_close(stream);
 
+    //replaces any invalid characters with an underscore. strips out newlines, comments, etc
+    for(int i = 0; i < appDev->dataSize; i++){
+        if(!strchr(bfChars, appDev->dataBuffer[i])){
+            appDev->dataBuffer[i] = '_';
+        }
+    }
+
     //find the end of the file to begin editing
     int tptr = 0;
     while(appDev->dataBuffer[tptr] != 0x00){ tptr++; }