| 1 | // MIT License | 
|---|
| 2 |  | 
|---|
| 3 | // Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com | 
|---|
| 4 |  | 
|---|
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy | 
|---|
| 6 | // of this software and associated documentation files (the "Software"), to deal | 
|---|
| 7 | // in the Software without restriction, including without limitation the rights | 
|---|
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
|---|
| 9 | // copies of the Software, and to permit persons to whom the Software is | 
|---|
| 10 | // furnished to do so, subject to the following conditions: | 
|---|
| 11 |  | 
|---|
| 12 | // The above copyright notice and this permission notice shall be included in all | 
|---|
| 13 | // copies or substantial portions of the Software. | 
|---|
| 14 |  | 
|---|
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
|---|
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|---|
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
|---|
| 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
|---|
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
|---|
| 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
|---|
| 21 | // SOFTWARE. | 
|---|
| 22 |  | 
|---|
| 23 | #pragma once | 
|---|
| 24 |  | 
|---|
| 25 | #include "studio/studio.h" | 
|---|
| 26 | #include "studio/fs.h" | 
|---|
| 27 |  | 
|---|
| 28 | typedef enum | 
|---|
| 29 | { | 
|---|
| 30 | CART_SAVE_OK, | 
|---|
| 31 | CART_SAVE_ERROR, | 
|---|
| 32 | CART_SAVE_MISSING_NAME, | 
|---|
| 33 | } CartSaveResult; | 
|---|
| 34 |  | 
|---|
| 35 | typedef struct Console Console; | 
|---|
| 36 | typedef struct CommandDesc CommandDesc; | 
|---|
| 37 |  | 
|---|
| 38 | struct Console | 
|---|
| 39 | { | 
|---|
| 40 | struct Config* config; | 
|---|
| 41 |  | 
|---|
| 42 | struct | 
|---|
| 43 | { | 
|---|
| 44 | tic_point pos; | 
|---|
| 45 | s32 delay; | 
|---|
| 46 | } cursor; | 
|---|
| 47 |  | 
|---|
| 48 | struct | 
|---|
| 49 | { | 
|---|
| 50 | s32 pos; | 
|---|
| 51 | s32 start; | 
|---|
| 52 |  | 
|---|
| 53 | bool active; | 
|---|
| 54 | } scroll; | 
|---|
| 55 |  | 
|---|
| 56 | struct | 
|---|
| 57 | { | 
|---|
| 58 | const char* start; | 
|---|
| 59 | const char* end; | 
|---|
| 60 | bool active; | 
|---|
| 61 | } select; | 
|---|
| 62 |  | 
|---|
| 63 | char* text; | 
|---|
| 64 | u8* color; | 
|---|
| 65 |  | 
|---|
| 66 | struct | 
|---|
| 67 | { | 
|---|
| 68 | char* text; | 
|---|
| 69 | size_t pos; | 
|---|
| 70 | } input; | 
|---|
| 71 |  | 
|---|
| 72 | Studio* studio; | 
|---|
| 73 | tic_mem* tic; | 
|---|
| 74 |  | 
|---|
| 75 | struct tic_fs* fs; | 
|---|
| 76 | struct tic_net* net; | 
|---|
| 77 |  | 
|---|
| 78 | struct | 
|---|
| 79 | { | 
|---|
| 80 | char name[TICNAME_MAX]; | 
|---|
| 81 | char path[TICNAME_MAX]; | 
|---|
| 82 | } rom; | 
|---|
| 83 |  | 
|---|
| 84 | struct | 
|---|
| 85 | { | 
|---|
| 86 | s32 index; | 
|---|
| 87 | s32 size; | 
|---|
| 88 | char** items; | 
|---|
| 89 | } history; | 
|---|
| 90 |  | 
|---|
| 91 | u32 tickCounter; | 
|---|
| 92 |  | 
|---|
| 93 | bool active; | 
|---|
| 94 | StartArgs args; | 
|---|
| 95 |  | 
|---|
| 96 | struct | 
|---|
| 97 | { | 
|---|
| 98 | s32 count; | 
|---|
| 99 | s32 current; | 
|---|
| 100 | char** items; | 
|---|
| 101 | } commands; | 
|---|
| 102 |  | 
|---|
| 103 | CommandDesc* desc; | 
|---|
| 104 |  | 
|---|
| 105 | void(*load)(Console*, const char* path); | 
|---|
| 106 | bool(*loadCart)(Console*, const char* path); | 
|---|
| 107 | void(*loadByHash)(Console*, const char* name, const char* hash, const char* section, fs_done_callback callback, void* data); | 
|---|
| 108 | void(*updateProject)(Console*); | 
|---|
| 109 | void(*error)(Console*, const char*); | 
|---|
| 110 | void(*trace)(Console*, const char*, u8 color); | 
|---|
| 111 | void(*tick)(Console*); | 
|---|
| 112 | void(*done)(Console*); | 
|---|
| 113 |  | 
|---|
| 114 | CartSaveResult(*save)(Console*); | 
|---|
| 115 | }; | 
|---|
| 116 |  | 
|---|
| 117 | void initConsole(Console*, Studio* studio, struct tic_fs* fs, struct tic_net* net, struct Config* config, StartArgs args); | 
|---|
| 118 | void freeConsole(Console* console); | 
|---|
| 119 |  | 
|---|