Skip to content
Permalink
Browse files

introduce process_result_t and move output & output_new into main.c

  • Loading branch information
samdoshi committed Apr 9, 2016
1 parent 326a95b commit b716990e98d0e26d355bddfbb9c6506188390dd2
Showing with 25 additions and 13 deletions.
  1. +4 −1 simulator/tt.c
  2. +6 −1 src/main.c
  3. +7 −9 src/teletype.c
  4. +8 −2 src/teletype.h
@@ -137,7 +137,10 @@ int main() {
if (error_detail[0]) printf(": %s", error_detail);
error_detail[0] = 0;
printf("\n");
if (status == E_OK) process(&temp);
if (status == E_OK) {
process_result_t output = process(&temp);
if (output.h == PR_VALUE) { printf(">>> %i\n", output.v); }
}
}
else {
printf("ERROR: %s", tele_error(status));
@@ -126,6 +126,7 @@ uint8_t help_length[8] = { HELP1_LENGTH, HELP2_LENGTH, HELP3_LENGTH,
HELP4_LENGTH, HELP5_LENGTH, HELP6_LENGTH,
HELP7_LENGTH, HELP8_LENGTH };

int16_t output, output_new;

#define FIRSTRUN_KEY 0x22

@@ -892,7 +893,11 @@ static void handler_HidTimer(s32 data) {
memcpy(&history.c[5], &temp,
sizeof(tele_command_t));

process(&temp);
process_result_t o = process(&temp);
if (o.h == PR_VALUE) {
output = o.v;
output_new++;
}
}

for (n = 0; n < 32; n++) input[n] = 0;
@@ -47,8 +47,6 @@ const char *tele_error(error_t e) {
static char pcmd[32];


int16_t output, output_new;

char error_detail[16];

uint8_t mutes[8];
@@ -1548,7 +1546,7 @@ error_t validate(tele_command_t *c) {
/////////////////////////////////////////////////////////////////
// PROCESS //////////////////////////////////////////////////////

void process(tele_command_t *c) {
process_result_t process(tele_command_t *c) {
top = 0;
left = 0;
int16_t i;
@@ -1612,13 +1610,13 @@ void process(tele_command_t *c) {
}
}

// PRint16_t DEBUG OUTPUT IF VAL LEFT ON STACK
if (top) {
output = pop();
output_new++;
// sprintf(dbg,"\r\n>>> %d", output);
// DBG
// to_v(output);
process_result_t o = {.h = PR_VALUE, .v = pop() };
return o;
}
else {
process_result_t o = {.h = PR_EMPTY, .v = 0 };
return o;
}
}

@@ -72,6 +72,13 @@ typedef enum {
E_NOT_LEFT
} error_t;

typedef enum { PR_EMPTY, PR_VALUE } process_result_has_value_t;

typedef struct {
process_result_has_value_t h;
int16_t v;
} process_result_t;

typedef enum { NUMBER, MOD, SEP, OP, VAR, ARRAY } tele_word_t;

typedef struct {
@@ -130,7 +137,7 @@ typedef struct {

error_t parse(char *cmd, tele_command_t *out);
error_t validate(tele_command_t *c);
void process(tele_command_t *c);
process_result_t process(tele_command_t *c);
char *print_command(const tele_command_t *c);

void tele_tick(uint8_t);
@@ -191,7 +198,6 @@ typedef void (*update_input_t)(uint8_t);
extern volatile update_input_t update_input;

extern char error_detail[16];
extern int16_t output, output_new;

extern volatile uint8_t input_states[8];

0 comments on commit b716990

Please sign in to comment.