Skip to content

Commit

Permalink
New state structure, fix font
Browse files Browse the repository at this point in the history
  • Loading branch information
egordorichev committed Oct 9, 2017
1 parent 697b2a7 commit abe8214
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 232 deletions.
27 changes: 10 additions & 17 deletions include/carts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,29 @@
#define neko_carts_hpp

#include <LuaJIT/lua.hpp>
#include <neko.hpp>

typedef struct neko_cart {
char *code;
lua_State *lua;
lua_State *thread;
} neko_cart;

typedef struct neko_carts {
neko_cart *loaded;
} neko_carts;
typedef struct neko_carts : neko_state {
neko_carts(neko *machine);

struct neko;

namespace carts {
// Inits carts
neko_carts *init(neko *machine);
// Renders current
void escape(neko *machine);
void event(neko *machine, SDL_Event *);
void render(neko *machine);
// Attemps to call a callback in cart

bool checkForLuaFunction(neko *machine, const char *name);
void triggerCallback(neko *machine, const char *callback); // TODO: add args
// Creates new cart
neko_cart *createNew(neko *machine);
// Runs current loaded cart
void run(neko *machine);
// Loads a cart
void load(neko *machine, char *name);
// Saves a cart
void save(neko *machine, char *name);
// Free all
void clean(neko_carts *carts);
}

neko_cart *loaded;
} neko_carts;

#endif
17 changes: 9 additions & 8 deletions include/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
#define neko_console_hpp

#include <string>
#include <neko.hpp>
#include <SDL_events.h>

struct neko;
typedef struct neko_console : neko_state {
neko_console(neko *machine);

void escape(neko *machine);
void event(neko *machine, SDL_Event *);
void render(neko *machine);
void drawPrompt(neko *machine);

typedef struct neko_console {
std::string input;
bool forceDraw;
} neko_console;

namespace console {
neko_console *init(neko *machine);
void render(neko *machine);
void clean(neko_console *console);
};

#endif
26 changes: 17 additions & 9 deletions include/neko.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@

#include <config.hpp>
#include <ram.hpp>
#include <console.hpp>
#include <graphics.hpp>
#include <fs.hpp>
#include <carts.hpp>

typedef enum neko_state {
struct neko_carts;
struct neko_console;

typedef enum neko_state_id {
STATE_CONSOLE = 0,
STATE_RUNNING_CART = 1,
STATE_CODE_EDITOR = 2

STATE_SIZE = 2
} neko_state_id;

typedef struct neko_state {
neko_state_id id;

virtual void escape(neko *machine) {};
virtual void event(neko *machine, SDL_Event *) {};
virtual void render(neko *machine) {};
} neko_state;

typedef struct neko {
neko_ram *ram;
neko_graphics *graphics;
neko_carts *carts;
neko_state state;
neko_state prevState;
neko_state_id state;
neko_state **states;
neko_state_id prevState;
neko_config *config;
neko_fs *fs;

neko_console *console;
} neko;

namespace machine {
Expand Down
14 changes: 6 additions & 8 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))

static const char *font[] = {
//0b1110000, 0b1010000, 0b1110000, 0b0000000, 0b1110000, 0b1100000, 0b1000000, 0b0000000, 0b1110000, 0b1000000, 0b1000000, 0b0000000, 0b1110000, 0b1000000, 0b1100000, 0b0000000, 0b1110000, 0b1100000, 0b1000000, 0b0000000, 0b1110000, 0b1100000, 0b1000000, 0b0000000, 0b1110000, 0b1000000, 0b1010000, 0b0000000, 0b1110000, 0b1000000, 0b1110000, 0b0000000, 0b1000000, 0b1110000, 0b1000000, 0b0000000, 0b1000000, 0b1110000, 0b1000000, 0b0000000, 0b1110000, 0b1000000, 0b1010000, 0b0000000, 0b1110000, 0b0000000, 0b0000000, 0b0000000, 0b1110000, 0b1100000, 0b1110000, 0b0000000, 0b1110000, 0b1000000, 0b1100000, 0b0000000, 0b1100000, 0b1000000, 0b1110000, 0b0000000, 0b1110000, 0b1010000, 0b1110000, 0b0000000, 0b1100000, 0b1010000, 0b1000000, 0b0000000, 0b1110000, 0b1010000, 0b1100000, 0b0000000, 0b1000000, 0b1000000, 0b1010000, 0b0000000, 0b1000000, 0b1110000, 0b1000000, 0b0000000, 0b1110000, 0b0000000, 0b1110000, 0b0000000, 0b1110000, 0b1000000, 0b1110000, 0b0000000, 0b1110000, 0b1000000, 0b1110000, 0b0000000, 0b1010000, 0b1000000, 0b1010000, 0b0000000, 0b1100000, 0b1000000, 0b1110000, 0b0000000, 0b1010000, 0b1000000, 0b1100000, 0b0000000, 0b1111000, 0b1010000, 0b1111000, 0b0000000, 0b1111000, 0b1010000, 0b1111000, 0b0000000, 0b1110000, 0b1000000, 0b1000000, 0b0000000, 0b1111000, 0b1000000, 0b1110000, 0b0000000, 0b1111000, 0b1010000, 0b1000000, 0b0000000, 0b1111000, 0b1010000, 0b1000000, 0b0000000, 0b1110000, 0b1000000, 0b1001000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b1000000, 0b1111000, 0b1000000, 0b0000000, 0b1000000, 0b1111000, 0b1000000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b1111000, 0b0000000, 0b0000000, 0b0000000, 0b1111000, 0b1100000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1110000, 0b0000000, 0b1110000, 0b1000000, 0b1111000, 0b0000000, 0b1111000, 0b1010000, 0b1110000, 0b0000000, 0b1110000, 0b1001000, 0b1100000, 0b0000000, 0b1111000, 0b1010000, 0b1111000, 0b0000000, 0b1100000, 0b1010000, 0b1111000, 0b0000000, 0b1000000, 0b1111000, 0b1000000, 0b0000000, 0b1111000, 0b0000000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b1110000, 0b1000000, 0b1111000, 0b0000000, 0b1001000, 0b1010000, 0b1100000, 0b0000000, 0b1000000, 0b1111000, 0b0000000, 0b0000000, 0b1111000, 0b1010000, 0b1110000, 0b0000000, 0b1000000, 0b1010000, 0b1111000, 0b0000000, 0b1110000, 0b1000000, 0b1111000, 0b0000000, 0b1110000, 0b1010000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1100000, 0b0000000, 0b1000000, 0b1000000, 0b1111000, 0b0000000, 0b1111000, 0b1010000, 0b1111000, 0b0000000, 0b1110000, 0b1010000, 0b1111000, 0b0000000, 0b1111000, 0b1000000, 0b1111000, 0b0000000, 0b0000000, 0b1110000, 0b0000000, 0b0000000, 0b1000000, 0b1010000, 0b1110000, 0b0000000, 0b1111000, 0b1000000, 0b0000000, 0b0000000, 0b0000000, 0b1000000, 0b1111000, 0b0000000, 0b1110000, 0b1000000, 0b0000000, 0b0000000, 0b1000000, 0b1111000, 0b1000000, 0b0000000, 0b1000000, 0b1111000, 0b1000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b1000000, 0b0000000, 0b0000000, 0b0000000, 0b1010000, 0b0000000, 0b0000000, 0b0000000, 0b1010000, 0b0000000, 0b0000000, 0b1000000, 0b1010000, 0b1000000, 0b0000000, 0b1000000, 0b1010000, 0b1000000, 0b0000000, 0b1000000, 0b1110000, 0b1000000, 0b0000000, 0b1010000, 0b1010000, 0b1010000, 0b0000000, 0b1001000, 0b1000000, 0b1100000, 0b0000000, 0b1111000, 0b1010000, 0b1111000, 0b0000000, 0b1000000, 0b1000000, 0b1000000, 0b0000000, 0b1010000, 0b1110000, 0b1010000, 0b0000000, 0b1100000, 0b1000000, 0b1100000, 0b0000000, 0b0000000, 0b1110000, 0b1000000, 0b0000000, 0b1000000, 0b1110000, 0b0000000, 0b0000000, 0b0000000, 0b1111000, 0b0000000, 0b0000000, 0b1111000, 0b1111000, 0b1111000, 0b0000000, 0b1110000, 0b1000000, 0b1100000, 0b0000000, 0b1111000, 0b1110000, 0b1100000, 0b0000000, 0b0000000, 0b1000000, 0b1000000, 0b0000000, 0b1100000, 0b0000000, 0b1100000, 0b0000000, 0b1000000, 0b1000000, 0b0000000, 0b0000000, 0b1000000, 0b1000000, 0b1000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000

"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011101110011011001110111001101010111011101010100011101100011011100100111001101110101010101010101010101110110011101110101011101000111011101110111001001110110001100100011011000000000000000000001010000000000010101010010010100000001010000100111001001100010010100100000000000000",
"1110110011101100111011101110101011101110101010001110110001101110010011100110111010101010101010101010111010101010100010101000100010001010010001001010100011101010101010101010101010000100101010101010101010100010010000100010101010001000001010101010101001000010100000101000010001000000000001000100010001000100111000101110101001000010010001000100110010101100001010101000000000000000",
"1010110010001010110011001000101001000100110010001110101010101010101010101000010010101010101001001110001011101100100010101100110010001110010001001100100010101010101011101010110011100100101010101010010011100100010011100110111011101110001011101110101001000110100000101000110001100000000000000000100000101110000001001010000011101110010001000100011010101110000000000000111000000000",
"1110101010001010100010001010111001000100101010001010101010101110110011000010010010101110111010100010100010101010100010101000100010101010010001001010100010101010101010001100101000100100101011101110101000101000010010000010001000101010001010100010101000000000100000101000010001000000010001000100010001000100111010001110000001001000010001000100111010001010000000000000000000000000",
"1010111011101100111010001110101011101100101011101010101011001000011010101100010001100100111010101110111010101110011011101110100011101010111011001010111010101010110010000110101011000100011001001110101011101110111011101110001011101110001011100010111001000100110001100100011011000100100010000000001010000000000010101010000010100000100000100100010001101110000000000000000011100000"
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001110111001101100111011100110101011101110101010001110110001101110010011100110111010101010101010101010111011001110111010101110100011101110111011100100111011000110010001101100000000000000000000101000000000001010101001001010000000101000010011100100110001001010010000000000",
"111011001110110011101110111010101110111010101000111011000110111001001110011011101010101010101010101011101010101010001010100010001000101001000100101010001110101010101010101010101000010010101010101010101010001001000010001010101000100000101010101010100100001010000010100001000100000000000100010001000100010011100010111010100100001001000100010011001010110000101010100000000000",
"101011001000101011001100100010100100010011001000111010101010101010101010100001001010101010100100111000101110110010001010110011001000111001000100110010001010101010101110101011001110010010101010101001001110010001001110011011101110111000101110111010100100011010000010100011000110000000000000000010000010111000000100101000001110111001000100010001101010111000000000000011100000",
"111010101000101010001000101011100100010010101000101010101010111011001100001001001010111011101010001010001010101010001010100010001010101001000100101010001010101010101000110010100010010010101110111010100010100001001000001000100010101000101010001010100000000010000010100001000100000001000100010001000100010011101000111000000100100001000100010011101000101000000000000000000000",
"101011101110110011101000111010101110110010101110101010101100100001101010110001000110010011101010111011101010111001101110111010001110101011101100101011101010101011001000011010101100010001100100111010101110111011101110111000101110111000101110001011100100010011000110010001101100010010001000000000101000000000001010101000001010000010000010010001000110111000000000000000001110"
};

static const char *letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?[]({}.,;:<>+=%#^*~/\\\\|$@&`\\\"'-_ ";
static const char *letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?[]({}.,;:<>+=%#^*~/\\|$@&`\"'-_";

namespace api {
static int applyCamX(neko *machine, int x) {
Expand Down
Loading

0 comments on commit abe8214

Please sign in to comment.