diff --git a/applications/plugins/bpmtapper/bpm.c b/applications/plugins/bpmtapper/bpm.c index e2d3e13ef..cd74a1c67 100644 --- a/applications/plugins/bpmtapper/bpm.c +++ b/applications/plugins/bpmtapper/bpm.c @@ -16,70 +16,69 @@ typedef struct { InputEvent input; } PluginEvent; - //QUEUE struct node { int interval; - struct node *next; + struct node* next; }; typedef struct node node; typedef struct { int size; int max_size; - node *front; - node *rear; + node* front; + node* rear; } queue; -static void init_queue(queue *q) { - q->size = 0; - q->max_size = 8; - q->front = NULL; - q->rear = NULL; +static void init_queue(queue* q) { + q->size = 0; + q->max_size = 8; + q->front = NULL; + q->rear = NULL; } -static void queue_remove(queue *q) { - node *tmp; +static void queue_remove(queue* q) { + node* tmp; tmp = q->front; q->front = q->front->next; q->size--; free(tmp); } -static void queue_add(queue *q, int value) { - node *tmp = malloc(sizeof(node)); +static void queue_add(queue* q, int value) { + node* tmp = malloc(sizeof(node)); tmp->interval = value; tmp->next = NULL; - if (q->size == q->max_size) { - queue_remove(q); - } + if(q->size == q->max_size) { + queue_remove(q); + } // check if empty - if (q->rear == NULL) { - q->front = tmp; - q->rear = tmp; + if(q->rear == NULL) { + q->front = tmp; + q->rear = tmp; } else { - q->rear->next = tmp; - q->rear = tmp; + q->rear->next = tmp; + q->rear = tmp; } q->size++; } -static float queue_avg(queue *q) { +static float queue_avg(queue* q) { float avg = 0.0; - if (q->size == 0){ - return avg; + if(q->size == 0) { + return avg; } else { - node *tmp; - float sum = 0.0; - tmp = q->front; - while (tmp != NULL) { - sum = sum + tmp->interval; - tmp = tmp->next; - } - avg = sum / q->size; - FURI_LOG_D("BPM-Tapper", "Sum: %.2f Avg: %.2f", (double)sum, (double)avg); - return avg; + node* tmp; + float sum = 0.0; + tmp = q->front; + while(tmp != NULL) { + sum = sum + tmp->interval; + tmp = tmp->next; + } + avg = sum / q->size; + FURI_LOG_D("BPM-Tapper", "Sum: %.2f Avg: %.2f", (double)sum, (double)avg); + return avg; } } @@ -95,33 +94,32 @@ typedef struct { double bpm; uint32_t last_stamp; uint32_t interval; - queue *tap_queue; + queue* tap_queue; } BPMTapper; static void show_hello() { + // BEGIN HELLO DIALOG + DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); + DialogMessage* message = dialog_message_alloc(); - // BEGIN HELLO DIALOG - DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); - DialogMessage* message = dialog_message_alloc(); + const char* header_text = "BPM Tapper"; + const char* message_text = "Tap center to start"; - const char* header_text = "BPM Tapper"; - const char* message_text = "Tap center to start"; + dialog_message_set_header(message, header_text, 63, 3, AlignCenter, AlignTop); + dialog_message_set_text(message, message_text, 0, 17, AlignLeft, AlignTop); + dialog_message_set_buttons(message, NULL, "Tap", NULL); - dialog_message_set_header(message, header_text, 63, 3, AlignCenter, AlignTop); - dialog_message_set_text(message, message_text, 0, 17, AlignLeft, AlignTop); - dialog_message_set_buttons(message, NULL, "Tap", NULL); + dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17); - dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17); + dialog_message_show(dialogs, message); - dialog_message_show(dialogs, message); - - dialog_message_free(message); - furi_record_close(RECORD_DIALOGS); - // END HELLO DIALOG + dialog_message_free(message); + furi_record_close(RECORD_DIALOGS); + // END HELLO DIALOG } static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { - furi_assert(event_queue); + furi_assert(event_queue); PluginEvent event = {.type = EventTypeKey, .input = *input_event}; furi_message_queue_put(event_queue, &event, FuriWaitForever); @@ -131,8 +129,8 @@ static void render_callback(Canvas* const canvas, void* ctx) { string_t tempStr; const BPMTapper* bpm_state = acquire_mutex((ValueMutex*)ctx, 25); - if (bpm_state == NULL) { - return; + if(bpm_state == NULL) { + return; } // border //canvas_draw_frame(canvas, 0, 0, 128, 64); @@ -152,7 +150,7 @@ static void render_callback(Canvas* const canvas, void* ctx) { canvas_draw_str_aligned(canvas, 5, 20, AlignLeft, AlignBottom, string_get_cstr(tempStr)); string_reset(tempStr); - string_printf(tempStr, "x2 %.2f /2 %.2f", bpm_state->bpm*2, bpm_state->bpm/2); + string_printf(tempStr, "x2 %.2f /2 %.2f", bpm_state->bpm * 2, bpm_state->bpm / 2); canvas_draw_str_aligned(canvas, 64, 60, AlignCenter, AlignCenter, string_get_cstr(tempStr)); string_reset(tempStr); @@ -166,97 +164,95 @@ static void render_callback(Canvas* const canvas, void* ctx) { release_mutex((ValueMutex*)ctx, bpm_state); } - static void bpm_state_init(BPMTapper* const plugin_state) { - plugin_state->taps = 0; - plugin_state->bpm = 120.0; - plugin_state->last_stamp = 0;// furi_get_tick(); - plugin_state->interval = 0; - queue *q; - q = malloc(sizeof(queue)); - init_queue(q); - plugin_state->tap_queue = q; + plugin_state->taps = 0; + plugin_state->bpm = 120.0; + plugin_state->last_stamp = 0; // furi_get_tick(); + plugin_state->interval = 0; + queue* q; + q = malloc(sizeof(queue)); + init_queue(q); + plugin_state->tap_queue = q; } int32_t bpm_tapper_app(void* p) { - UNUSED(p); + UNUSED(p); - FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); - - BPMTapper* bpm_state = malloc(sizeof(BPMTapper)); - // setup - bpm_state_init(bpm_state); - - ValueMutex state_mutex; - if (!init_mutex(&state_mutex, bpm_state, sizeof(bpm_state))) { - FURI_LOG_E("BPM-Tapper", "cannot create mutex\r\n"); - free(bpm_state); - return 255; - } - show_hello(); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); - // BEGIN IMPLEMENTATION + BPMTapper* bpm_state = malloc(sizeof(BPMTapper)); + // setup + bpm_state_init(bpm_state); - // Set system callbacks - ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, render_callback, &state_mutex); - view_port_input_callback_set(view_port, input_callback, event_queue); - - // Open GUI and register view_port - Gui* gui = furi_record_open("gui"); - gui_add_view_port(gui, view_port, GuiLayerFullscreen); - - PluginEvent event; - for (bool processing = true; processing;) { - FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); - BPMTapper* bpm_state = (BPMTapper*)acquire_mutex_block(&state_mutex); - if(event_status == FuriStatusOk) { - // press events - if(event.type == EventTypeKey) { - if(event.input.type == InputTypePress) { - switch(event.input.key) { - case InputKeyUp: - case InputKeyDown: - case InputKeyRight: - case InputKeyLeft: - case InputKeyOk: - bpm_state->taps++; - uint32_t new_stamp = furi_get_tick(); - if (bpm_state->last_stamp == 0) { - bpm_state->last_stamp = new_stamp; - break; - } - bpm_state->interval = new_stamp - bpm_state->last_stamp; - bpm_state->last_stamp = new_stamp; - queue_add(bpm_state->tap_queue, bpm_state->interval); - float avg = queue_avg(bpm_state->tap_queue); - float bps = 1.0 / (avg / 1000.0); - bpm_state->bpm = bps * 60.0; - break; - case InputKeyBack: - // Exit the plugin - processing = false; - break; - } - } - } - } else { - FURI_LOG_D("BPM-Tapper", "FuriMessageQueue: event timeout"); - // event timeout + ValueMutex state_mutex; + if(!init_mutex(&state_mutex, bpm_state, sizeof(bpm_state))) { + FURI_LOG_E("BPM-Tapper", "cannot create mutex\r\n"); + free(bpm_state); + return 255; } - view_port_update(view_port); - release_mutex(&state_mutex, bpm_state); - } - view_port_enabled_set(view_port, false); - gui_remove_view_port(gui, view_port); - furi_record_close("gui"); - view_port_free(view_port); - furi_message_queue_free(event_queue); - delete_mutex(&state_mutex); - queue *q = bpm_state->tap_queue; - free(q); - free(bpm_state); + show_hello(); - return 0; + // BEGIN IMPLEMENTATION + + // Set system callbacks + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); + + // Open GUI and register view_port + Gui* gui = furi_record_open("gui"); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + + PluginEvent event; + for(bool processing = true; processing;) { + FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); + BPMTapper* bpm_state = (BPMTapper*)acquire_mutex_block(&state_mutex); + if(event_status == FuriStatusOk) { + // press events + if(event.type == EventTypeKey) { + if(event.input.type == InputTypePress) { + switch(event.input.key) { + case InputKeyUp: + case InputKeyDown: + case InputKeyRight: + case InputKeyLeft: + case InputKeyOk: + bpm_state->taps++; + uint32_t new_stamp = furi_get_tick(); + if(bpm_state->last_stamp == 0) { + bpm_state->last_stamp = new_stamp; + break; + } + bpm_state->interval = new_stamp - bpm_state->last_stamp; + bpm_state->last_stamp = new_stamp; + queue_add(bpm_state->tap_queue, bpm_state->interval); + float avg = queue_avg(bpm_state->tap_queue); + float bps = 1.0 / (avg / 1000.0); + bpm_state->bpm = bps * 60.0; + break; + case InputKeyBack: + // Exit the plugin + processing = false; + break; + } + } + } + } else { + FURI_LOG_D("BPM-Tapper", "FuriMessageQueue: event timeout"); + // event timeout + } + view_port_update(view_port); + release_mutex(&state_mutex, bpm_state); + } + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); + furi_record_close("gui"); + view_port_free(view_port); + furi_message_queue_free(event_queue); + delete_mutex(&state_mutex); + queue* q = bpm_state->tap_queue; + free(q); + free(bpm_state); + + return 0; } - diff --git a/applications/plugins/calculator/calculator.c b/applications/plugins/calculator/calculator.c index 0cd3eefe8..b121641b0 100644 --- a/applications/plugins/calculator/calculator.c +++ b/applications/plugins/calculator/calculator.c @@ -425,11 +425,11 @@ int32_t calculator_app(void* p) { view_port_update(view_port); } - + if(event.type == InputTypeLong) { switch(event.key) { case InputKeyOk: - if (calculator_state->position.x == 0 && calculator_state->position.y == 4) { + if(calculator_state->position.x == 0 && calculator_state->position.y == 4) { if(calculator_state->textLength < MAX_TEXT_LENGTH) { calculator_state->text[calculator_state->textLength++] = ')'; calculator_state->text[calculator_state->textLength] = '\0'; diff --git a/applications/plugins/calculator/tinyexpr.h b/applications/plugins/calculator/tinyexpr.h index c2cbe1a30..3833965a1 100644 --- a/applications/plugins/calculator/tinyexpr.h +++ b/applications/plugins/calculator/tinyexpr.h @@ -26,59 +26,69 @@ #ifndef TINYEXPR_H #define TINYEXPR_H - #ifdef __cplusplus extern "C" { #endif - - typedef struct te_expr { int type; - union {double value; const double *bound; const void *function;}; - void *parameters[1]; + union { + double value; + const double* bound; + const void* function; + }; + void* parameters[1]; } te_expr; - enum { TE_VARIABLE = 0, - TE_FUNCTION0 = 8, TE_FUNCTION1, TE_FUNCTION2, TE_FUNCTION3, - TE_FUNCTION4, TE_FUNCTION5, TE_FUNCTION6, TE_FUNCTION7, + TE_FUNCTION0 = 8, + TE_FUNCTION1, + TE_FUNCTION2, + TE_FUNCTION3, + TE_FUNCTION4, + TE_FUNCTION5, + TE_FUNCTION6, + TE_FUNCTION7, - TE_CLOSURE0 = 16, TE_CLOSURE1, TE_CLOSURE2, TE_CLOSURE3, - TE_CLOSURE4, TE_CLOSURE5, TE_CLOSURE6, TE_CLOSURE7, + TE_CLOSURE0 = 16, + TE_CLOSURE1, + TE_CLOSURE2, + TE_CLOSURE3, + TE_CLOSURE4, + TE_CLOSURE5, + TE_CLOSURE6, + TE_CLOSURE7, TE_FLAG_PURE = 32 }; typedef struct te_variable { - const char *name; - const void *address; + const char* name; + const void* address; int type; - void *context; + void* context; } te_variable; - - /* Parses the input expression, evaluates it, and frees it. */ /* Returns NaN on error. */ -double te_interp(const char *expression, int *error); +double te_interp(const char* expression, int* error); /* Parses the input expression and binds variables. */ /* Returns NULL on error. */ -te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error); +te_expr* + te_compile(const char* expression, const te_variable* variables, int var_count, int* error); /* Evaluates the expression. */ -double te_eval(const te_expr *n); +double te_eval(const te_expr* n); /* Prints debugging information on the syntax tree. */ -void te_print(const te_expr *n); +void te_print(const te_expr* n); /* Frees the expression. */ /* This is safe to call on NULL pointers. */ -void te_free(te_expr *n); - +void te_free(te_expr* n); #ifdef __cplusplus } diff --git a/applications/plugins/dolphinbackup/scenes/storage_DolphinBackup_scene_confirm.c b/applications/plugins/dolphinbackup/scenes/storage_DolphinBackup_scene_confirm.c index 7afcfa648..6e5c16d66 100644 --- a/applications/plugins/dolphinbackup/scenes/storage_DolphinBackup_scene_confirm.c +++ b/applications/plugins/dolphinbackup/scenes/storage_DolphinBackup_scene_confirm.c @@ -11,7 +11,8 @@ static void storage_DolphinBackup_scene_confirm_widget_callback( furi_assert(app); if(type == InputTypeShort) { if(result == GuiButtonTypeRight) { - view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventConfirm); + view_dispatcher_send_custom_event( + app->view_dispatcher, DolphinBackupCustomEventConfirm); } else if(result == GuiButtonTypeLeft) { view_dispatcher_send_custom_event(app->view_dispatcher, DolphinBackupCustomEventExit); } diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin.c b/applications/plugins/dtmf_dolphin/dtmf_dolphin.c index 9643566d6..2ff8ce0ba 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin.c +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin.c @@ -83,10 +83,10 @@ static void app_free(DTMFDolphinApp* app) { free(app); } -int32_t dtmf_dolphin_app(void *p) { +int32_t dtmf_dolphin_app(void* p) { UNUSED(p); DTMFDolphinApp* app = app_alloc(); - + view_dispatcher_run(app->view_dispatcher); app_free(app); diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.c b/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.c index 6d6341bf1..e7778b328 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.c +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.c @@ -1,11 +1,11 @@ #include "dtmf_dolphin_audio.h" -DTMFDolphinAudio *current_player; +DTMFDolphinAudio* current_player; static void dtmf_dolphin_audio_dma_isr(void* ctx) { - FuriMessageQueue *event_queue = ctx; + FuriMessageQueue* event_queue = ctx; - if (LL_DMA_IsActiveFlag_HT1(DMA1)) { + if(LL_DMA_IsActiveFlag_HT1(DMA1)) { LL_DMA_ClearFlag_HT1(DMA1); DTMFDolphinCustomEvent event = {.type = DTMFDolphinEventDMAHalfTransfer}; @@ -21,13 +21,13 @@ static void dtmf_dolphin_audio_dma_isr(void* ctx) { } void dtmf_dolphin_audio_clear_samples(DTMFDolphinAudio* player) { - for (size_t i = 0; i < player->buffer_length; i++) { + for(size_t i = 0; i < player->buffer_length; i++) { player->sample_buffer[i] = 0; } } DTMFDolphinOsc* dtmf_dolphin_osc_alloc() { - DTMFDolphinOsc *osc = malloc(sizeof(DTMFDolphinOsc)); + DTMFDolphinOsc* osc = malloc(sizeof(DTMFDolphinOsc)); osc->cached_freq = 0; osc->offset = 0; osc->period = 0; @@ -36,7 +36,7 @@ DTMFDolphinOsc* dtmf_dolphin_osc_alloc() { } DTMFDolphinAudio* dtmf_dolphin_audio_alloc() { - DTMFDolphinAudio *player = malloc(sizeof(DTMFDolphinAudio)); + DTMFDolphinAudio* player = malloc(sizeof(DTMFDolphinAudio)); player->buffer_length = SAMPLE_BUFFER_LENGTH; player->half_buffer_length = SAMPLE_BUFFER_LENGTH / 2; player->sample_buffer = malloc(sizeof(uint16_t) * player->buffer_length); @@ -50,34 +50,32 @@ DTMFDolphinAudio* dtmf_dolphin_audio_alloc() { } size_t calc_waveform_period(float freq) { - if (!freq) { + if(!freq) { return 0; } // DMA Rate calculation, thanks to Dr_Zlo - float dma_rate = CPU_CLOCK_FREQ \ - / 2 \ - / DTMF_DOLPHIN_HAL_DMA_PRESCALER \ - / (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1); + float dma_rate = CPU_CLOCK_FREQ / 2 / DTMF_DOLPHIN_HAL_DMA_PRESCALER / + (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1); // Using a constant scaling modifier, which likely represents // the combined system overhead and isr latency. - return (uint16_t) dma_rate * 2 / freq * 0.801923; + return (uint16_t)dma_rate * 2 / freq * 0.801923; } void osc_generate_lookup_table(DTMFDolphinOsc* osc, float freq) { - if (osc->lookup_table != NULL) { + if(osc->lookup_table != NULL) { free(osc->lookup_table); } osc->offset = 0; osc->cached_freq = freq; osc->period = calc_waveform_period(freq); - if (!osc->period) { + if(!osc->period) { osc->lookup_table = NULL; return; } osc->lookup_table = malloc(sizeof(float) * osc->period); - for (size_t i = 0; i < osc->period; i++) { + for(size_t i = 0; i < osc->period; i++) { osc->lookup_table[i] = sin(i * PERIOD_2_PI / osc->period) + 1; } } @@ -85,7 +83,7 @@ void osc_generate_lookup_table(DTMFDolphinOsc* osc, float freq) { float sample_frame(DTMFDolphinOsc* osc) { float frame = 0.0; - if (osc->period) { + if(osc->period) { frame = osc->lookup_table[osc->offset]; osc->offset = (osc->offset + 1) % osc->period; } @@ -103,7 +101,7 @@ void dtmf_dolphin_audio_free(DTMFDolphinAudio* player) { } void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc) { - if (osc->lookup_table != NULL) { + if(osc->lookup_table != NULL) { free(osc->lookup_table); } free(osc); @@ -112,18 +110,16 @@ void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc) { bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) { uint16_t* sample_buffer_start = &player->sample_buffer[buffer_index]; - for (size_t i = 0; i < player->half_buffer_length; i++) { + for(size_t i = 0; i < player->half_buffer_length; i++) { float data = 0; - if (player->osc2->period) { - data = \ - (sample_frame(player->osc1) / 2) + \ - (sample_frame(player->osc2) / 2); + if(player->osc2->period) { + data = (sample_frame(player->osc1) / 2) + (sample_frame(player->osc2) / 2); } else { data = (sample_frame(player->osc1)); } data *= player->volume; - data *= UINT8_MAX / 2; // scale -128..127 - data += UINT8_MAX / 2; // to unsigned + data *= UINT8_MAX / 2; // scale -128..127 + data += UINT8_MAX / 2; // to unsigned if(data < 0) { data = 0; @@ -151,7 +147,8 @@ bool dtmf_dolphin_audio_play_tones(float freq1, float freq2) { dtmf_dolphin_speaker_init(); dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length); - furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue); + furi_hal_interrupt_set_isr( + FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue); dtmf_dolphin_dma_start(); dtmf_dolphin_speaker_start(); @@ -165,20 +162,20 @@ bool dtmf_dolphin_audio_stop_tones() { furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL); dtmf_dolphin_audio_free(current_player); - + return true; } bool dtmf_dolphin_audio_handle_tick() { bool handled = false; - if (current_player) { + if(current_player) { DTMFDolphinCustomEvent event; if(furi_message_queue_get(current_player->queue, &event, 250) == FuriStatusOk) { if(event.type == DTMFDolphinEventDMAHalfTransfer) { generate_waveform(current_player, 0); handled = true; - } else if (event.type == DTMFDolphinEventDMAFullTransfer) { + } else if(event.type == DTMFDolphinEventDMAFullTransfer) { generate_waveform(current_player, current_player->half_buffer_length); handled = true; } diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.h b/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.h index 071323a6c..3c6cc4904 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.h +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin_audio.h @@ -17,12 +17,12 @@ typedef struct { typedef struct { size_t buffer_length; size_t half_buffer_length; - uint8_t *buffer_buffer; - uint16_t *sample_buffer; + uint8_t* buffer_buffer; + uint16_t* sample_buffer; float volume; - FuriMessageQueue *queue; - DTMFDolphinOsc *osc1; - DTMFDolphinOsc *osc2; + FuriMessageQueue* queue; + DTMFDolphinOsc* osc1; + DTMFDolphinOsc* osc2; } DTMFDolphinAudio; DTMFDolphinOsc* dtmf_dolphin_osc_alloc(); diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.c b/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.c index d0a85800c..a99c13baa 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.c +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.c @@ -7,13 +7,13 @@ typedef struct { } DTMFDolphinTonePos; typedef struct { - const char *name; + const char* name; const float frequency_1; const float frequency_2; const DTMFDolphinTonePos pos; - const uint16_t pulses; // for Redbox - const uint16_t pulse_ms; // for Redbox - const uint16_t gap_duration; // for Redbox + const uint16_t pulses; // for Redbox + const uint16_t pulse_ms; // for Redbox + const uint16_t gap_duration; // for Redbox } DTMFDolphinTones; typedef struct { @@ -44,41 +44,38 @@ DTMFDolphinSceneData DTMFDolphinSceneDataDialer = { {"0", 941.0, 1336.0, {3, 1, 1}, 0, 0, 0}, {"#", 941.0, 1477.0, {3, 2, 1}, 0, 0, 0}, {"D", 941.0, 1633.0, {3, 3, 1}, 0, 0, 0}, - } -}; + }}; DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = { .name = "Bluebox", .block = DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX, .tone_count = 13, .tones = { - {"1", 700.0, 900.0, {0, 0, 1}, 0, 0, 0}, - {"2", 700.0, 1100.0, {0, 1, 1}, 0, 0, 0}, - {"3", 900.0, 1100.0, {0, 2, 1}, 0, 0, 0}, - {"4", 700.0, 1300.0, {1, 0, 1}, 0, 0, 0}, - {"5", 900.0, 1300.0, {1, 1, 1}, 0, 0, 0}, - {"6", 1100.0, 1300.0, {1, 2, 1}, 0, 0, 0}, - {"7", 700.0, 1500.0, {2, 0, 1}, 0, 0, 0}, - {"8", 900.0, 1500.0, {2, 1, 1}, 0, 0, 0}, - {"9", 1100.0, 1500.0, {2, 2, 1}, 0, 0, 0}, - {"0", 1300.0, 1500.0, {3, 1, 1}, 0, 0, 0}, - {"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0}, - {"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0}, - {"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0}, - } -}; + {"1", 700.0, 900.0, {0, 0, 1}, 0, 0, 0}, + {"2", 700.0, 1100.0, {0, 1, 1}, 0, 0, 0}, + {"3", 900.0, 1100.0, {0, 2, 1}, 0, 0, 0}, + {"4", 700.0, 1300.0, {1, 0, 1}, 0, 0, 0}, + {"5", 900.0, 1300.0, {1, 1, 1}, 0, 0, 0}, + {"6", 1100.0, 1300.0, {1, 2, 1}, 0, 0, 0}, + {"7", 700.0, 1500.0, {2, 0, 1}, 0, 0, 0}, + {"8", 900.0, 1500.0, {2, 1, 1}, 0, 0, 0}, + {"9", 1100.0, 1500.0, {2, 2, 1}, 0, 0, 0}, + {"0", 1300.0, 1500.0, {3, 1, 1}, 0, 0, 0}, + {"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0}, + {"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0}, + {"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0}, + }}; DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = { .name = "Redbox (US)", .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US, .tone_count = 4, .tones = { - {"Nickel", 1700.0, 2200.0, {0, 0, 5}, 1, 66, 0}, - {"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66}, + {"Nickel", 1700.0, 2200.0, {0, 0, 5}, 1, 66, 0}, + {"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66}, {"Quarter", 1700.0, 2200.0, {2, 0, 5}, 5, 33, 33}, - {"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0}, - } -}; + {"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0}, + }}; DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = { .name = "Redbox (UK)", @@ -87,28 +84,25 @@ DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = { .tones = { {"10p", 1000.0, 0.0, {0, 0, 3}, 1, 200, 0}, {"50p", 1000.0, 0.0, {1, 0, 3}, 1, 350, 0}, - } -}; + }}; DTMFDolphinSceneData DTMFDolphinSceneDataMisc = { .name = "Misc", .block = DTMF_DOLPHIN_TONE_BLOCK_MISC, .tone_count = 3, .tones = { - {"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0}, - {"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0}, + {"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0}, + {"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0}, {"CCITT KP2", 1300.0, 1700.0, {2, 0, 5}, 0, 0, 0}, - } -}; + }}; DTMFDolphinToneSection current_section; -DTMFDolphinSceneData *current_scene_data; +DTMFDolphinSceneData* current_scene_data; void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) { current_section = section; - switch (current_section) - { + switch(current_section) { case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX: current_scene_data = &DTMFDolphinSceneDataBluebox; break; @@ -131,14 +125,14 @@ DTMFDolphinToneSection dtmf_dolphin_data_get_current_section() { return current_section; } -DTMFDolphinSceneData *dtmf_dolphin_data_get_current_scene_data() { +DTMFDolphinSceneData* dtmf_dolphin_data_get_current_scene_data() { return current_scene_data; } -bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t row, uint8_t col) { - for (size_t i = 0; i < current_scene_data->tone_count; i++) { +bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col) { + for(size_t i = 0; i < current_scene_data->tone_count; i++) { DTMFDolphinTones tones = current_scene_data->tones[i]; - if (tones.pos.row == row && tones.pos.col == col) { + if(tones.pos.row == row && tones.pos.col == col) { freq1[0] = tones.frequency_1; freq2[0] = tones.frequency_2; return true; @@ -148,9 +142,9 @@ bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t } const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) { - for (size_t i = 0; i < current_scene_data->tone_count; i++) { + for(size_t i = 0; i < current_scene_data->tone_count; i++) { DTMFDolphinTones tones = current_scene_data->tones[i]; - if (tones.pos.row == row && tones.pos.col == col) { + if(tones.pos.row == row && tones.pos.col == col) { return tones.name; } } @@ -158,7 +152,7 @@ const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) { } const char* dtmf_dolphin_data_get_current_section_name() { - if (current_scene_data) { + if(current_scene_data) { return current_scene_data->name; } return NULL; @@ -168,27 +162,26 @@ void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t max_rows[0] = 0; max_cols[0] = 0; max_span[0] = 0; - uint8_t tmp_rowspan[5] = { 0, 0, 0, 0, 0 }; - for (size_t i = 0; i < current_scene_data->tone_count; i++) { + uint8_t tmp_rowspan[5] = {0, 0, 0, 0, 0}; + for(size_t i = 0; i < current_scene_data->tone_count; i++) { DTMFDolphinTones tones = current_scene_data->tones[i]; - if (tones.pos.row > max_rows[0]) { + if(tones.pos.row > max_rows[0]) { max_rows[0] = tones.pos.row; } - if (tones.pos.col > max_cols[0]) { + if(tones.pos.col > max_cols[0]) { max_cols[0] = tones.pos.col; } tmp_rowspan[tones.pos.row] += tones.pos.span; - if (tmp_rowspan[tones.pos.row] > max_span[0]) - max_span[0] = tmp_rowspan[tones.pos.row]; + if(tmp_rowspan[tones.pos.row] > max_span[0]) max_span[0] = tmp_rowspan[tones.pos.row]; } max_rows[0]++; max_cols[0]++; } uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col) { - for (size_t i = 0; i < current_scene_data->tone_count; i++) { + for(size_t i = 0; i < current_scene_data->tone_count; i++) { DTMFDolphinTones tones = current_scene_data->tones[i]; - if (tones.pos.row == row && tones.pos.col == col) { + if(tones.pos.row == row && tones.pos.col == col) { return tones.pos.span; } } diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.h b/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.h index 65fb9c75e..056fb223e 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.h +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin_data.h @@ -17,7 +17,7 @@ void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section); DTMFDolphinToneSection dtmf_dolphin_data_get_current_section(); -bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t row, uint8_t col); +bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col); const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col); diff --git a/applications/plugins/dtmf_dolphin/dtmf_dolphin_i.h b/applications/plugins/dtmf_dolphin/dtmf_dolphin_i.h index 2a0de1b41..abdabd2b3 100644 --- a/applications/plugins/dtmf_dolphin/dtmf_dolphin_i.h +++ b/applications/plugins/dtmf_dolphin/dtmf_dolphin_i.h @@ -17,7 +17,6 @@ #define TAG "DTMFDolphin" - enum DTMFDolphinSceneState { DTMFDolphinSceneStateDialer, DTMFDolphinSceneStateBluebox, @@ -39,7 +38,4 @@ typedef struct { NotificationApp* notification; } DTMFDolphinApp; -typedef enum { - DTMFDolphinViewMainMenu, - DTMFDolphinViewDialer -} DTMFDolphinView; +typedef enum { DTMFDolphinViewMainMenu, DTMFDolphinViewDialer } DTMFDolphinView; diff --git a/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c b/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c index 2c24918ba..9820f5c9a 100644 --- a/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c +++ b/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_dialer.c @@ -2,17 +2,15 @@ // #include "../dtmf_dolphin_data.h" // #include "../dtmf_dolphin_audio.h" - -void dtmf_dolphin_scene_dialer_on_enter(void *context) { +void dtmf_dolphin_scene_dialer_on_enter(void* context) { DTMFDolphinApp* app = context; DTMFDolphinScene scene_id = DTMFDolphinSceneDialer; enum DTMFDolphinSceneState state = scene_manager_get_scene_state(app->scene_manager, scene_id); - switch (state) - { + switch(state) { case DTMFDolphinSceneStateBluebox: dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX); - break; + break; case DTMFDolphinSceneStateRedboxUS: dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US); break; diff --git a/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c b/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c index d789c36ce..1afd117fd 100644 --- a/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c +++ b/applications/plugins/dtmf_dolphin/scenes/dtmf_dolphin_scene_start.c @@ -2,16 +2,10 @@ static void dtmf_dolphin_scene_start_main_menu_enter_callback(void* context, uint32_t index) { DTMFDolphinApp* app = context; - if (index == DTMFDolphinSceneStateDialer) { - view_dispatcher_send_custom_event( - app->view_dispatcher, - DTMFDolphinEventStartDialer - ); - } else if (index == DTMFDolphinSceneStateBluebox) { - view_dispatcher_send_custom_event( - app->view_dispatcher, - DTMFDolphinEventStartBluebox - ); + if(index == DTMFDolphinSceneStateDialer) { + view_dispatcher_send_custom_event(app->view_dispatcher, DTMFDolphinEventStartDialer); + } else if(index == DTMFDolphinSceneStateBluebox) { + view_dispatcher_send_custom_event(app->view_dispatcher, DTMFDolphinEventStartBluebox); } } @@ -21,21 +15,16 @@ void dtmf_dolphin_scene_start_on_enter(void* context) { // VariableItem* item; variable_item_list_set_enter_callback( - var_item_list, - dtmf_dolphin_scene_start_main_menu_enter_callback, - app); + var_item_list, dtmf_dolphin_scene_start_main_menu_enter_callback, app); variable_item_list_add(var_item_list, "Dialer", 0, NULL, NULL); variable_item_list_add(var_item_list, "Bluebox", 0, NULL, NULL); variable_item_list_add(var_item_list, "Misc", 0, NULL, NULL); variable_item_list_set_selected_item( - var_item_list, - scene_manager_get_scene_state(app->scene_manager, DTMFDolphinSceneStart)); + var_item_list, scene_manager_get_scene_state(app->scene_manager, DTMFDolphinSceneStart)); - view_dispatcher_switch_to_view( - app->view_dispatcher, - DTMFDolphinViewMainMenu); + view_dispatcher_switch_to_view(app->view_dispatcher, DTMFDolphinViewMainMenu); } bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) { @@ -44,14 +33,17 @@ bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) { bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if (event.event == DTMFDolphinEventStartDialer) { - scene_manager_set_scene_state(app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateDialer); + if(event.event == DTMFDolphinEventStartDialer) { + scene_manager_set_scene_state( + app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateDialer); scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneDialer); - } else if (event.event == DTMFDolphinEventStartBluebox) { - scene_manager_set_scene_state(app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateBluebox); + } else if(event.event == DTMFDolphinEventStartBluebox) { + scene_manager_set_scene_state( + app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateBluebox); scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneDialer); - } else if (event.event == DTMFDolphinEventStartMisc) { - scene_manager_set_scene_state(app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateMisc); + } else if(event.event == DTMFDolphinEventStartMisc) { + scene_manager_set_scene_state( + app->scene_manager, DTMFDolphinSceneDialer, DTMFDolphinSceneStateMisc); scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneDialer); } consumed = true; diff --git a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_common.h b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_common.h index 855978d2c..f2f4838d6 100644 --- a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_common.h +++ b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_common.h @@ -7,4 +7,4 @@ #define DTMF_DOLPHIN_NUMPAD_Y 14 #define DTMF_DOLPHIN_BUTTON_WIDTH 13 #define DTMF_DOLPHIN_BUTTON_HEIGHT 13 -#define DTMF_DOLPHIN_BUTTON_PADDING 1 // all sides +#define DTMF_DOLPHIN_BUTTON_PADDING 1 // all sides diff --git a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.c b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.c index f33cd642a..514e4f144 100644 --- a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.c +++ b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.c @@ -21,53 +21,55 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer); static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer); static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer); -static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event); +static bool + dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event); void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) { - - uint8_t left = DTMF_DOLPHIN_NUMPAD_X + \ - // ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) + - (col * DTMF_DOLPHIN_BUTTON_WIDTH); - // (col * DTMF_DOLPHIN_BUTTON_PADDING); - uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + \ - // ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) + - (row * DTMF_DOLPHIN_BUTTON_HEIGHT); - // (row * DTMF_DOLPHIN_BUTTON_PADDING); + uint8_t left = DTMF_DOLPHIN_NUMPAD_X + // ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) + + (col * DTMF_DOLPHIN_BUTTON_WIDTH); + // (col * DTMF_DOLPHIN_BUTTON_PADDING); + uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + // ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) + + (row * DTMF_DOLPHIN_BUTTON_HEIGHT); + // (row * DTMF_DOLPHIN_BUTTON_PADDING); uint8_t span = dtmf_dolphin_get_tone_span(row, col); - if (span == 0) { + if(span == 0) { return; } canvas_set_color(canvas, ColorBlack); - - if (invert) - canvas_draw_rbox(canvas, left, top, + + if(invert) + canvas_draw_rbox( + canvas, + left, + top, (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2), DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2), 2); else - canvas_draw_rframe(canvas, left, top, + canvas_draw_rframe( + canvas, + left, + top, (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2), - DTMF_DOLPHIN_BUTTON_HEIGHT- (DTMF_DOLPHIN_BUTTON_PADDING * 2), + DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2), 2); - if (invert) - canvas_invert_color(canvas); - + if(invert) canvas_invert_color(canvas); canvas_set_font(canvas, FontSecondary); // canvas_set_color(canvas, invert ? ColorWhite : ColorBlack); - canvas_draw_str_aligned(canvas, - left - 1 + (int) ((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2), - top + (int) (DTMF_DOLPHIN_BUTTON_HEIGHT / 2), + canvas_draw_str_aligned( + canvas, + left - 1 + (int)((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2), + top + (int)(DTMF_DOLPHIN_BUTTON_HEIGHT / 2), AlignCenter, AlignCenter, dtmf_dolphin_data_get_tone_name(row, col)); - if (invert) - canvas_invert_color(canvas); + if(invert) canvas_invert_color(canvas); } void draw_dialer(Canvas* canvas, void* _model) { @@ -79,9 +81,9 @@ void draw_dialer(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontSecondary); - for (int r = 0; r < max_rows; r++) { - for (int c = 0; c < max_cols; c++) { - if (model->row == r && model->col == c) + for(int r = 0; r < max_rows; r++) { + for(int c = 0; c < max_cols; c++) { + if(model->row == r && model->col == c) draw_button(canvas, r, c, true); else draw_button(canvas, r, c, false); @@ -89,20 +91,20 @@ void draw_dialer(Canvas* canvas, void* _model) { } } -void update_frequencies(DTMFDolphinDialerModel *model) { +void update_frequencies(DTMFDolphinDialerModel* model) { dtmf_dolphin_data_get_tone_frequencies(&model->freq1, &model->freq2, model->row, model->col); } static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) { DTMFDolphinDialerModel* model = _model; - if (model->playing) { + if(model->playing) { // Leverage the prioritized draw callback to handle // the DMA so that it doesn't skip. dtmf_dolphin_audio_handle_tick(); // Don't do any drawing if audio is playing. canvas_set_font(canvas, FontPrimary); elements_multiline_text_aligned( - canvas, + canvas, canvas_width(canvas) / 2, canvas_height(canvas) / 2, AlignCenter, @@ -118,11 +120,15 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontPrimary); elements_multiline_text(canvas, 2, 10, dtmf_dolphin_data_get_current_section_name()); - canvas_draw_line(canvas, - (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, 0, - (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, canvas_height(canvas)); + canvas_draw_line( + canvas, + (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, + 0, + (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, + canvas_height(canvas)); elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 10, "Detail"); - canvas_draw_line(canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3); + canvas_draw_line( + canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3); // elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Dialer Mode"); draw_dialer(canvas, model); @@ -130,22 +136,20 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) { string_t output; string_init(output); - if (model->freq1 && model->freq2) { + if(model->freq1 && model->freq2) { string_cat_printf( output, "Dual Tone\nF1: %u Hz\nF2: %u Hz\n", - (unsigned int) model->freq1, - (unsigned int) model->freq2); - } else if (model->freq1) { - string_cat_printf( - output, - "Single Tone\nF: %u Hz\n", - (unsigned int) model->freq1); + (unsigned int)model->freq1, + (unsigned int)model->freq2); + } else if(model->freq1) { + string_cat_printf(output, "Single Tone\nF: %u Hz\n", (unsigned int)model->freq1); } canvas_set_font(canvas, FontSecondary); canvas_set_color(canvas, ColorBlack); - elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, string_get_cstr(output)); + elements_multiline_text( + canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, string_get_cstr(output)); string_clear(output); } @@ -178,11 +182,11 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) { uint8_t span = 0; uint8_t cursor = model->row; - while (span == 0 && cursor > 0) { + while(span == 0 && cursor > 0) { cursor--; span = dtmf_dolphin_get_tone_span(cursor, model->col); } - if (span != 0) { + if(span != 0) { model->row = cursor; } return true; @@ -204,7 +208,7 @@ static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dia cursor++; span = dtmf_dolphin_get_tone_span(cursor, model->col); } - if (span != 0) { + if(span != 0) { model->row = cursor; } return true; @@ -217,11 +221,11 @@ static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dia dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) { uint8_t span = 0; uint8_t cursor = model->col; - while (span == 0 && cursor > 0) { + while(span == 0 && cursor > 0) { cursor--; span = dtmf_dolphin_get_tone_span(model->row, cursor); } - if (span != 0) { + if(span != 0) { model->col = cursor; } return true; @@ -243,7 +247,7 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di cursor++; span = dtmf_dolphin_get_tone_span(model->row, cursor); } - if (span != 0) { + if(span != 0) { model->col = cursor; } return true; @@ -251,14 +255,15 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di return true; } -static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) { +static bool + dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) { bool consumed = false; with_view_model( dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) { - if (event->type == InputTypePress) { + if(event->type == InputTypePress) { model->playing = dtmf_dolphin_audio_play_tones(model->freq1, model->freq2); - } else if (event->type == InputTypeRelease) { + } else if(event->type == InputTypeRelease) { model->playing = !dtmf_dolphin_audio_stop_tones(); } @@ -281,15 +286,15 @@ static void dtmf_dolphin_dialer_enter_callback(void* context) { model->freq2 = 0.0; model->playing = false; return true; - } - ); + }); } DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() { DTMFDolphinDialer* dtmf_dolphin_dialer = malloc(sizeof(DTMFDolphinDialer)); dtmf_dolphin_dialer->view = view_alloc(); - view_allocate_model(dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel)); + view_allocate_model( + dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel)); with_view_model( dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) { @@ -300,8 +305,7 @@ DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() { model->freq2 = 0.0; model->playing = false; return true; - } - ); + }); view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer); view_set_draw_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_draw_callback); @@ -320,4 +324,3 @@ View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer) { furi_assert(dtmf_dolphin_dialer); return dtmf_dolphin_dialer->view; } - diff --git a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.h b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.h index c52343ff0..1929afbc5 100644 --- a/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.h +++ b/applications/plugins/dtmf_dolphin/views/dtmf_dolphin_dialer.h @@ -12,4 +12,7 @@ void dtmf_dolphin_dialer_free(DTMFDolphinDialer* dtmf_dolphin_dialer); View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer); -void dtmf_dolphin_dialer_set_ok_callback(DTMFDolphinDialer* dtmf_dolphin_dialer, DTMFDolphinDialerOkCallback callback, void* context); +void dtmf_dolphin_dialer_set_ok_callback( + DTMFDolphinDialer* dtmf_dolphin_dialer, + DTMFDolphinDialerOkCallback callback, + void* context); diff --git a/applications/plugins/metronome/gui_extensions.c b/applications/plugins/metronome/gui_extensions.c index 7b2aa62fd..ccad67930 100644 --- a/applications/plugins/metronome/gui_extensions.c +++ b/applications/plugins/metronome/gui_extensions.c @@ -14,7 +14,7 @@ void elements_button_top_left(Canvas* canvas, const char* str) { const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset; const uint8_t x = 0; - const uint8_t y = 0 + button_height; + const uint8_t y = 0 + button_height; canvas_draw_box(canvas, x, y - button_height, button_width, button_height); canvas_draw_line(canvas, x + button_width + 0, y - button_height, x + button_width + 0, y - 1); @@ -44,8 +44,8 @@ void elements_button_top_right(Canvas* canvas, const char* str) { canvas_draw_box(canvas, x - button_width, y - button_height, button_width, button_height); canvas_draw_line(canvas, x - button_width - 1, y - button_height, x - button_width - 1, y - 1); - canvas_draw_line(canvas, x - button_width - 2, y - button_height, x - button_width - 2, y - 2); - canvas_draw_line(canvas, x - button_width - 3, y - button_height, x - button_width - 3, y - 3); + canvas_draw_line(canvas, x - button_width - 2, y - button_height, x - button_width - 2, y - 2); + canvas_draw_line(canvas, x - button_width - 3, y - button_height, x - button_width - 3, y - 3); canvas_invert_color(canvas); canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str); diff --git a/applications/plugins/metronome/metronome.c b/applications/plugins/metronome/metronome.c index 9b14d4b2c..e0770f2f8 100644 --- a/applications/plugins/metronome/metronome.c +++ b/applications/plugins/metronome/metronome.c @@ -21,351 +21,363 @@ #define wave_bitmap_left_width 4 #define wave_bitmap_left_height 14 -static uint8_t wave_bitmap_left_bits[] = { - 0x08, 0x0C, 0x06, 0x06, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0x06, - 0x0C, 0x08 -}; +static uint8_t wave_bitmap_left_bits[] = + {0x08, 0x0C, 0x06, 0x06, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0x06, 0x0C, 0x08}; #define wave_bitmap_right_width 4 #define wave_bitmap_right_height 14 -static uint8_t wave_bitmap_right_bits[] = { - 0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x06, 0x06, - 0x03, 0x01 -}; +static uint8_t wave_bitmap_right_bits[] = + {0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x06, 0x06, 0x03, 0x01}; typedef enum { - EventTypeTick, - EventTypeKey, + EventTypeTick, + EventTypeKey, } EventType; typedef struct { - EventType type; - InputEvent input; + EventType type; + InputEvent input; } PluginEvent; -enum OutputMode { - Loud, - Vibro, - Silent -}; +enum OutputMode { Loud, Vibro, Silent }; typedef struct { - double bpm; - bool playing; - int beats_per_bar; - int note_length; - int current_beat; - enum OutputMode output_mode; - FuriTimer* timer; - NotificationApp* notifications; + double bpm; + bool playing; + int beats_per_bar; + int note_length; + int current_beat; + enum OutputMode output_mode; + FuriTimer* timer; + NotificationApp* notifications; } MetronomeState; static void render_callback(Canvas* const canvas, void* ctx) { - const MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); - if(metronome_state == NULL) { - return; - } + const MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); + if(metronome_state == NULL) { + return; + } - string_t tempStr; - string_init(tempStr); + string_t tempStr; + string_init(tempStr); - canvas_draw_frame(canvas, 0, 0, 128, 64); + canvas_draw_frame(canvas, 0, 0, 128, 64); - canvas_set_font(canvas, FontPrimary); - - // draw bars/beat - string_printf(tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length); - canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, string_get_cstr(tempStr)); - string_reset(tempStr); + canvas_set_font(canvas, FontPrimary); - // draw BPM value - string_printf(tempStr, "%.2f", metronome_state->bpm); - canvas_set_font(canvas, FontBigNumbers); - canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignCenter, string_get_cstr(tempStr)); - string_reset(tempStr); + // draw bars/beat + string_printf(tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length); + canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, string_get_cstr(tempStr)); + string_reset(tempStr); - // draw volume indicator - // always draw first waves - canvas_draw_xbm(canvas, 20, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); - canvas_draw_xbm(canvas, canvas_width(canvas)-20-wave_bitmap_right_width, 17, wave_bitmap_right_width, wave_bitmap_right_height, wave_bitmap_right_bits); - if (metronome_state->output_mode < Silent) { - canvas_draw_xbm(canvas, 16, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); - canvas_draw_xbm(canvas, canvas_width(canvas)-16-wave_bitmap_right_width, 17, wave_bitmap_right_width, wave_bitmap_right_height, wave_bitmap_right_bits); - } - if (metronome_state->output_mode < Vibro) { - canvas_draw_xbm(canvas, 12, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); - canvas_draw_xbm(canvas, canvas_width(canvas)-12-wave_bitmap_right_width, 17, wave_bitmap_right_width, wave_bitmap_right_height, wave_bitmap_right_bits); - } - // draw button prompts - canvas_set_font(canvas, FontSecondary); - elements_button_left(canvas, "Slow"); - elements_button_right(canvas, "Fast"); - if (metronome_state->playing) { - elements_button_center(canvas, "Stop "); - } else { - elements_button_center(canvas, "Start"); - } - elements_button_top_left(canvas, "Push"); - elements_button_top_right(canvas, "Hold"); + // draw BPM value + string_printf(tempStr, "%.2f", metronome_state->bpm); + canvas_set_font(canvas, FontBigNumbers); + canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignCenter, string_get_cstr(tempStr)); + string_reset(tempStr); - // draw progress bar - elements_progress_bar(canvas, 8, 36, 112, (float)metronome_state->current_beat/metronome_state->beats_per_bar); + // draw volume indicator + // always draw first waves + canvas_draw_xbm( + canvas, 20, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); + canvas_draw_xbm( + canvas, + canvas_width(canvas) - 20 - wave_bitmap_right_width, + 17, + wave_bitmap_right_width, + wave_bitmap_right_height, + wave_bitmap_right_bits); + if(metronome_state->output_mode < Silent) { + canvas_draw_xbm( + canvas, 16, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); + canvas_draw_xbm( + canvas, + canvas_width(canvas) - 16 - wave_bitmap_right_width, + 17, + wave_bitmap_right_width, + wave_bitmap_right_height, + wave_bitmap_right_bits); + } + if(metronome_state->output_mode < Vibro) { + canvas_draw_xbm( + canvas, 12, 17, wave_bitmap_left_width, wave_bitmap_left_height, wave_bitmap_left_bits); + canvas_draw_xbm( + canvas, + canvas_width(canvas) - 12 - wave_bitmap_right_width, + 17, + wave_bitmap_right_width, + wave_bitmap_right_height, + wave_bitmap_right_bits); + } + // draw button prompts + canvas_set_font(canvas, FontSecondary); + elements_button_left(canvas, "Slow"); + elements_button_right(canvas, "Fast"); + if(metronome_state->playing) { + elements_button_center(canvas, "Stop "); + } else { + elements_button_center(canvas, "Start"); + } + elements_button_top_left(canvas, "Push"); + elements_button_top_right(canvas, "Hold"); - // cleanup - string_clear(tempStr); - release_mutex((ValueMutex*)ctx, metronome_state); + // draw progress bar + elements_progress_bar( + canvas, 8, 36, 112, (float)metronome_state->current_beat / metronome_state->beats_per_bar); + + // cleanup + string_clear(tempStr); + release_mutex((ValueMutex*)ctx, metronome_state); } static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { - furi_assert(event_queue); + furi_assert(event_queue); - PluginEvent event = {.type = EventTypeKey, .input = *input_event}; - furi_message_queue_put(event_queue, &event, FuriWaitForever); + PluginEvent event = {.type = EventTypeKey, .input = *input_event}; + furi_message_queue_put(event_queue, &event, FuriWaitForever); } static void timer_callback(void* ctx) { - // this is where we go BEEP! - MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); - metronome_state->current_beat++; - if (metronome_state->current_beat > metronome_state->beats_per_bar) { - metronome_state->current_beat = 1; - } - if (metronome_state->current_beat == 1) { - // pronounced beat - notification_message(metronome_state->notifications, &sequence_set_only_red_255); - switch(metronome_state->output_mode) { - case Loud: - furi_hal_speaker_start(440.0f, 1.0f); - break; - case Vibro: - notification_message(metronome_state->notifications, &sequence_set_vibro_on); - break; - case Silent: - break; + // this is where we go BEEP! + MetronomeState* metronome_state = acquire_mutex((ValueMutex*)ctx, 25); + metronome_state->current_beat++; + if(metronome_state->current_beat > metronome_state->beats_per_bar) { + metronome_state->current_beat = 1; } - } else { - // unpronounced beat - notification_message(metronome_state->notifications, &sequence_set_only_green_255); - switch(metronome_state->output_mode) { - case Loud: - furi_hal_speaker_start(220.0f, 1.0f); - break; - case Vibro: - notification_message(metronome_state->notifications, &sequence_set_vibro_on); - break; - case Silent: - break; - } - }; + if(metronome_state->current_beat == 1) { + // pronounced beat + notification_message(metronome_state->notifications, &sequence_set_only_red_255); + switch(metronome_state->output_mode) { + case Loud: + furi_hal_speaker_start(440.0f, 1.0f); + break; + case Vibro: + notification_message(metronome_state->notifications, &sequence_set_vibro_on); + break; + case Silent: + break; + } + } else { + // unpronounced beat + notification_message(metronome_state->notifications, &sequence_set_only_green_255); + switch(metronome_state->output_mode) { + case Loud: + furi_hal_speaker_start(220.0f, 1.0f); + break; + case Vibro: + notification_message(metronome_state->notifications, &sequence_set_vibro_on); + break; + case Silent: + break; + } + }; - // this is a bit of a kludge... if we are on vibro and unpronounced, stop vibro after half the usual duration - switch(metronome_state->output_mode) { + // this is a bit of a kludge... if we are on vibro and unpronounced, stop vibro after half the usual duration + switch(metronome_state->output_mode) { case Loud: - furi_delay_ms(BEEP_DELAY_MS); - furi_hal_speaker_stop(); - break; - case Vibro: - if (metronome_state->current_beat == 1) { furi_delay_ms(BEEP_DELAY_MS); - notification_message(metronome_state->notifications, &sequence_reset_vibro); - } else { - furi_delay_ms((int)BEEP_DELAY_MS/2); - notification_message(metronome_state->notifications, &sequence_reset_vibro); - furi_delay_ms((int)BEEP_DELAY_MS/2); - } - break; + furi_hal_speaker_stop(); + break; + case Vibro: + if(metronome_state->current_beat == 1) { + furi_delay_ms(BEEP_DELAY_MS); + notification_message(metronome_state->notifications, &sequence_reset_vibro); + } else { + furi_delay_ms((int)BEEP_DELAY_MS / 2); + notification_message(metronome_state->notifications, &sequence_reset_vibro); + furi_delay_ms((int)BEEP_DELAY_MS / 2); + } + break; case Silent: - break; - } - notification_message(metronome_state->notifications, &sequence_reset_rgb); + break; + } + notification_message(metronome_state->notifications, &sequence_reset_rgb); - release_mutex((ValueMutex*)ctx, metronome_state); + release_mutex((ValueMutex*)ctx, metronome_state); } static uint32_t state_to_sleep_ticks(MetronomeState* metronome_state) { - // calculate time between beeps - uint32_t tps = furi_kernel_get_tick_frequency(); - double multiplier = 4.0d/metronome_state->note_length; - double bps = (double)metronome_state->bpm / 60; - return (uint32_t)(round(tps / bps) - ((BEEP_DELAY_MS/1000)*tps)) * multiplier; + // calculate time between beeps + uint32_t tps = furi_kernel_get_tick_frequency(); + double multiplier = 4.0d / metronome_state->note_length; + double bps = (double)metronome_state->bpm / 60; + return (uint32_t)(round(tps / bps) - ((BEEP_DELAY_MS / 1000) * tps)) * multiplier; } static void update_timer(MetronomeState* metronome_state) { - if (furi_timer_is_running(metronome_state->timer)) { - furi_timer_stop(metronome_state->timer); - furi_timer_start( - metronome_state->timer, - state_to_sleep_ticks(metronome_state) - ); - } + if(furi_timer_is_running(metronome_state->timer)) { + furi_timer_stop(metronome_state->timer); + furi_timer_start(metronome_state->timer, state_to_sleep_ticks(metronome_state)); + } } static void increase_bpm(MetronomeState* metronome_state, double amount) { - metronome_state->bpm += amount; - if(metronome_state->bpm > (double)BPM_BOUNDARY_HIGH) { - metronome_state->bpm = BPM_BOUNDARY_HIGH; - } - update_timer(metronome_state); + metronome_state->bpm += amount; + if(metronome_state->bpm > (double)BPM_BOUNDARY_HIGH) { + metronome_state->bpm = BPM_BOUNDARY_HIGH; + } + update_timer(metronome_state); } static void decrease_bpm(MetronomeState* metronome_state, double amount) { - metronome_state->bpm -= amount; - if(metronome_state->bpm < (double)BPM_BOUNDARY_LOW) { - metronome_state->bpm = BPM_BOUNDARY_LOW; - } - update_timer(metronome_state); + metronome_state->bpm -= amount; + if(metronome_state->bpm < (double)BPM_BOUNDARY_LOW) { + metronome_state->bpm = BPM_BOUNDARY_LOW; + } + update_timer(metronome_state); } static void cycle_beats_per_bar(MetronomeState* metronome_state) { - metronome_state->beats_per_bar++; - if (metronome_state->beats_per_bar > metronome_state->note_length) { - metronome_state->beats_per_bar = 1; - } + metronome_state->beats_per_bar++; + if(metronome_state->beats_per_bar > metronome_state->note_length) { + metronome_state->beats_per_bar = 1; + } } static void cycle_note_length(MetronomeState* metronome_state) { - metronome_state->note_length *= 2; - if (metronome_state->note_length > 16) { - metronome_state->note_length = 2; - metronome_state->beats_per_bar = 1; - } - update_timer(metronome_state); + metronome_state->note_length *= 2; + if(metronome_state->note_length > 16) { + metronome_state->note_length = 2; + metronome_state->beats_per_bar = 1; + } + update_timer(metronome_state); } static void cycle_output_mode(MetronomeState* metronome_state) { metronome_state->output_mode++; - if (metronome_state->output_mode > Silent) { - metronome_state->output_mode = Loud; + if(metronome_state->output_mode > Silent) { + metronome_state->output_mode = Loud; } } static void metronome_state_init(MetronomeState* const metronome_state) { - metronome_state->bpm = 120.0; - metronome_state->playing = false; - metronome_state->beats_per_bar = 4; - metronome_state->note_length = 4; - metronome_state->current_beat = 0; - metronome_state->output_mode = Loud; - metronome_state->notifications = furi_record_open(RECORD_NOTIFICATION); + metronome_state->bpm = 120.0; + metronome_state->playing = false; + metronome_state->beats_per_bar = 4; + metronome_state->note_length = 4; + metronome_state->current_beat = 0; + metronome_state->output_mode = Loud; + metronome_state->notifications = furi_record_open(RECORD_NOTIFICATION); } int32_t metronome_app() { - FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); - MetronomeState* metronome_state = malloc(sizeof(MetronomeState)); - metronome_state_init(metronome_state); + MetronomeState* metronome_state = malloc(sizeof(MetronomeState)); + metronome_state_init(metronome_state); - ValueMutex state_mutex; - if(!init_mutex(&state_mutex, metronome_state, sizeof(MetronomeState))) { - FURI_LOG_E("Metronome", "cannot create mutex\r\n"); - free(metronome_state); - return 255; - } - - // Set system callbacks - ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, render_callback, &state_mutex); - view_port_input_callback_set(view_port, input_callback, event_queue); - metronome_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, &state_mutex); - - // Open GUI and register view_port - Gui* gui = furi_record_open("gui"); - gui_add_view_port(gui, view_port, GuiLayerFullscreen); - - PluginEvent event; - for(bool processing = true; processing;) { - FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); - - MetronomeState* metronome_state = (MetronomeState*)acquire_mutex_block(&state_mutex); - - if(event_status == FuriStatusOk) { - if(event.type == EventTypeKey) { - if(event.input.type == InputTypeShort) { - // push events - switch(event.input.key) { - case InputKeyUp: - cycle_beats_per_bar(metronome_state); - break; - case InputKeyDown: - cycle_output_mode(metronome_state); - break; - case InputKeyRight: - increase_bpm(metronome_state, BPM_STEP_SIZE_FINE); - break; - case InputKeyLeft: - decrease_bpm(metronome_state, BPM_STEP_SIZE_FINE); - break; - case InputKeyOk: - metronome_state->playing = !metronome_state->playing; - if (metronome_state->playing) { - furi_timer_start(metronome_state->timer, state_to_sleep_ticks(metronome_state)); - } else { - furi_timer_stop(metronome_state->timer); - } - break; - case InputKeyBack: - processing = false; - break; - } - } else if (event.input.type == InputTypeLong) { - // hold events - switch(event.input.key) { - case InputKeyUp: - cycle_note_length(metronome_state); - break; - case InputKeyDown: - break; - case InputKeyRight: - increase_bpm(metronome_state, BPM_STEP_SIZE_COARSE); - break; - case InputKeyLeft: - decrease_bpm(metronome_state, BPM_STEP_SIZE_COARSE); - break; - case InputKeyOk: - break; - case InputKeyBack: - processing = false; - break; - } - } else if (event.input.type == InputTypeRepeat) { - // repeat events - switch(event.input.key) { - case InputKeyUp: - break; - case InputKeyDown: - break; - case InputKeyRight: - increase_bpm(metronome_state, BPM_STEP_SIZE_COARSE); - break; - case InputKeyLeft: - decrease_bpm(metronome_state, BPM_STEP_SIZE_COARSE); - break; - case InputKeyOk: - break; - case InputKeyBack: - processing = false; - break; - } - } - } - } else { - FURI_LOG_D("Metronome", "FuriMessageQueue: event timeout"); - // event timeout + ValueMutex state_mutex; + if(!init_mutex(&state_mutex, metronome_state, sizeof(MetronomeState))) { + FURI_LOG_E("Metronome", "cannot create mutex\r\n"); + free(metronome_state); + return 255; } - view_port_update(view_port); - release_mutex(&state_mutex, metronome_state); - } + // Set system callbacks + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); + metronome_state->timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, &state_mutex); - view_port_enabled_set(view_port, false); - gui_remove_view_port(gui, view_port); - furi_record_close("gui"); - view_port_free(view_port); - furi_message_queue_free(event_queue); - delete_mutex(&state_mutex); - furi_timer_free(metronome_state->timer); - furi_record_close(RECORD_NOTIFICATION); - free(metronome_state); + // Open GUI and register view_port + Gui* gui = furi_record_open("gui"); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); - return 0; + PluginEvent event; + for(bool processing = true; processing;) { + FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); + + MetronomeState* metronome_state = (MetronomeState*)acquire_mutex_block(&state_mutex); + + if(event_status == FuriStatusOk) { + if(event.type == EventTypeKey) { + if(event.input.type == InputTypeShort) { + // push events + switch(event.input.key) { + case InputKeyUp: + cycle_beats_per_bar(metronome_state); + break; + case InputKeyDown: + cycle_output_mode(metronome_state); + break; + case InputKeyRight: + increase_bpm(metronome_state, BPM_STEP_SIZE_FINE); + break; + case InputKeyLeft: + decrease_bpm(metronome_state, BPM_STEP_SIZE_FINE); + break; + case InputKeyOk: + metronome_state->playing = !metronome_state->playing; + if(metronome_state->playing) { + furi_timer_start( + metronome_state->timer, state_to_sleep_ticks(metronome_state)); + } else { + furi_timer_stop(metronome_state->timer); + } + break; + case InputKeyBack: + processing = false; + break; + } + } else if(event.input.type == InputTypeLong) { + // hold events + switch(event.input.key) { + case InputKeyUp: + cycle_note_length(metronome_state); + break; + case InputKeyDown: + break; + case InputKeyRight: + increase_bpm(metronome_state, BPM_STEP_SIZE_COARSE); + break; + case InputKeyLeft: + decrease_bpm(metronome_state, BPM_STEP_SIZE_COARSE); + break; + case InputKeyOk: + break; + case InputKeyBack: + processing = false; + break; + } + } else if(event.input.type == InputTypeRepeat) { + // repeat events + switch(event.input.key) { + case InputKeyUp: + break; + case InputKeyDown: + break; + case InputKeyRight: + increase_bpm(metronome_state, BPM_STEP_SIZE_COARSE); + break; + case InputKeyLeft: + decrease_bpm(metronome_state, BPM_STEP_SIZE_COARSE); + break; + case InputKeyOk: + break; + case InputKeyBack: + processing = false; + break; + } + } + } + } else { + FURI_LOG_D("Metronome", "FuriMessageQueue: event timeout"); + // event timeout + } + + view_port_update(view_port); + release_mutex(&state_mutex, metronome_state); + } + + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); + furi_record_close("gui"); + view_port_free(view_port); + furi_message_queue_free(event_queue); + delete_mutex(&state_mutex); + furi_timer_free(metronome_state->timer); + furi_record_close(RECORD_NOTIFICATION); + free(metronome_state); + + return 0; } diff --git a/applications/plugins/tama_p1/tamalib/cpu.c b/applications/plugins/tama_p1/tamalib/cpu.c index 511365744..3f422c2d6 100644 --- a/applications/plugins/tama_p1/tamalib/cpu.c +++ b/applications/plugins/tama_p1/tamalib/cpu.c @@ -21,105 +21,113 @@ #include "hw.h" #include "hal.h" -#define TICK_FREQUENCY 32768 // Hz +#define TICK_FREQUENCY 32768 // Hz -#define TIMER_1HZ_PERIOD 32768 // in ticks -#define TIMER_256HZ_PERIOD 128 // in ticks +#define TIMER_1HZ_PERIOD 32768 // in ticks +#define TIMER_256HZ_PERIOD 128 // in ticks -#define MASK_4B 0xF00 -#define MASK_6B 0xFC0 -#define MASK_7B 0xFE0 -#define MASK_8B 0xFF0 -#define MASK_10B 0xFFC -#define MASK_12B 0xFFF +#define MASK_4B 0xF00 +#define MASK_6B 0xFC0 +#define MASK_7B 0xFE0 +#define MASK_8B 0xFF0 +#define MASK_10B 0xFFC +#define MASK_12B 0xFFF -#define PCS (pc & 0xFF) -#define PCSL (pc & 0xF) -#define PCSH ((pc >> 4) & 0xF) -#define PCP ((pc >> 8) & 0xF) -#define PCB ((pc >> 12) & 0x1) -#define TO_PC(bank, page, step) ((step & 0xFF) | ((page & 0xF) << 8) | (bank & 0x1) << 12) -#define NBP ((np >> 4) & 0x1) -#define NPP (np & 0xF) -#define TO_NP(bank, page) ((page & 0xF) | (bank & 0x1) << 4) -#define XHL (x & 0xFF) -#define XL (x & 0xF) -#define XH ((x >> 4) & 0xF) -#define XP ((x >> 8) & 0xF) -#define YHL (y & 0xFF) -#define YL (y & 0xF) -#define YH ((y >> 4) & 0xF) -#define YP ((y >> 8) & 0xF) -#define M(n) get_memory(n) -#define SET_M(n, v) set_memory(n, v) -#define RQ(i) get_rq(i) -#define SET_RQ(i, v) set_rq(i, v) -#define SPL (sp & 0xF) -#define SPH ((sp >> 4) & 0xF) +#define PCS (pc & 0xFF) +#define PCSL (pc & 0xF) +#define PCSH ((pc >> 4) & 0xF) +#define PCP ((pc >> 8) & 0xF) +#define PCB ((pc >> 12) & 0x1) +#define TO_PC(bank, page, step) ((step & 0xFF) | ((page & 0xF) << 8) | (bank & 0x1) << 12) +#define NBP ((np >> 4) & 0x1) +#define NPP (np & 0xF) +#define TO_NP(bank, page) ((page & 0xF) | (bank & 0x1) << 4) +#define XHL (x & 0xFF) +#define XL (x & 0xF) +#define XH ((x >> 4) & 0xF) +#define XP ((x >> 8) & 0xF) +#define YHL (y & 0xFF) +#define YL (y & 0xF) +#define YH ((y >> 4) & 0xF) +#define YP ((y >> 8) & 0xF) +#define M(n) get_memory(n) +#define SET_M(n, v) set_memory(n, v) +#define RQ(i) get_rq(i) +#define SET_RQ(i, v) set_rq(i, v) +#define SPL (sp & 0xF) +#define SPH ((sp >> 4) & 0xF) -#define FLAG_C (0x1 << 0) -#define FLAG_Z (0x1 << 1) -#define FLAG_D (0x1 << 2) -#define FLAG_I (0x1 << 3) +#define FLAG_C (0x1 << 0) +#define FLAG_Z (0x1 << 1) +#define FLAG_D (0x1 << 2) +#define FLAG_I (0x1 << 3) -#define C !!(flags & FLAG_C) -#define Z !!(flags & FLAG_Z) -#define D !!(flags & FLAG_D) -#define I !!(flags & FLAG_I) +#define C !!(flags & FLAG_C) +#define Z !!(flags & FLAG_Z) +#define D !!(flags & FLAG_D) +#define I !!(flags & FLAG_I) -#define SET_C() {flags |= FLAG_C;} -#define CLEAR_C() {flags &= ~FLAG_C;} -#define SET_Z() {flags |= FLAG_Z;} -#define CLEAR_Z() {flags &= ~FLAG_Z;} -#define SET_D() {flags |= FLAG_D;} -#define CLEAR_D() {flags &= ~FLAG_D;} -#define SET_I() {flags |= FLAG_I;} -#define CLEAR_I() {flags &= ~FLAG_I;} +#define SET_C() \ + { flags |= FLAG_C; } +#define CLEAR_C() \ + { flags &= ~FLAG_C; } +#define SET_Z() \ + { flags |= FLAG_Z; } +#define CLEAR_Z() \ + { flags &= ~FLAG_Z; } +#define SET_D() \ + { flags |= FLAG_D; } +#define CLEAR_D() \ + { flags &= ~FLAG_D; } +#define SET_I() \ + { flags |= FLAG_I; } +#define CLEAR_I() \ + { flags &= ~FLAG_I; } -#define REG_CLK_INT_FACTOR_FLAGS 0xF00 -#define REG_SW_INT_FACTOR_FLAGS 0xF01 -#define REG_PROG_INT_FACTOR_FLAGS 0xF02 -#define REG_SERIAL_INT_FACTOR_FLAGS 0xF03 -#define REG_K00_K03_INT_FACTOR_FLAGS 0xF04 -#define REG_K10_K13_INT_FACTOR_FLAGS 0xF05 -#define REG_CLOCK_INT_MASKS 0xF10 -#define REG_SW_INT_MASKS 0xF11 -#define REG_PROG_INT_MASKS 0xF12 -#define REG_SERIAL_INT_MASKS 0xF13 -#define REG_K00_K03_INT_MASKS 0xF14 -#define REG_K10_K13_INT_MASKS 0xF15 -#define REG_PROG_TIMER_DATA_L 0xF24 -#define REG_PROG_TIMER_DATA_H 0xF25 -#define REG_PROG_TIMER_RELOAD_DATA_L 0xF26 -#define REG_PROG_TIMER_RELOAD_DATA_H 0xF27 -#define REG_K00_K03_INPUT_PORT 0xF40 -#define REG_K10_K13_INPUT_PORT 0xF42 -#define REG_K40_K43_BZ_OUTPUT_PORT 0xF54 -#define REG_CPU_OSC3_CTRL 0xF70 -#define REG_LCD_CTRL 0xF71 -#define REG_LCD_CONTRAST 0xF72 -#define REG_SVD_CTRL 0xF73 -#define REG_BUZZER_CTRL1 0xF74 -#define REG_BUZZER_CTRL2 0xF75 -#define REG_CLK_WD_TIMER_CTRL 0xF76 -#define REG_SW_TIMER_CTRL 0xF77 -#define REG_PROG_TIMER_CTRL 0xF78 -#define REG_PROG_TIMER_CLK_SEL 0xF79 +#define REG_CLK_INT_FACTOR_FLAGS 0xF00 +#define REG_SW_INT_FACTOR_FLAGS 0xF01 +#define REG_PROG_INT_FACTOR_FLAGS 0xF02 +#define REG_SERIAL_INT_FACTOR_FLAGS 0xF03 +#define REG_K00_K03_INT_FACTOR_FLAGS 0xF04 +#define REG_K10_K13_INT_FACTOR_FLAGS 0xF05 +#define REG_CLOCK_INT_MASKS 0xF10 +#define REG_SW_INT_MASKS 0xF11 +#define REG_PROG_INT_MASKS 0xF12 +#define REG_SERIAL_INT_MASKS 0xF13 +#define REG_K00_K03_INT_MASKS 0xF14 +#define REG_K10_K13_INT_MASKS 0xF15 +#define REG_PROG_TIMER_DATA_L 0xF24 +#define REG_PROG_TIMER_DATA_H 0xF25 +#define REG_PROG_TIMER_RELOAD_DATA_L 0xF26 +#define REG_PROG_TIMER_RELOAD_DATA_H 0xF27 +#define REG_K00_K03_INPUT_PORT 0xF40 +#define REG_K10_K13_INPUT_PORT 0xF42 +#define REG_K40_K43_BZ_OUTPUT_PORT 0xF54 +#define REG_CPU_OSC3_CTRL 0xF70 +#define REG_LCD_CTRL 0xF71 +#define REG_LCD_CONTRAST 0xF72 +#define REG_SVD_CTRL 0xF73 +#define REG_BUZZER_CTRL1 0xF74 +#define REG_BUZZER_CTRL2 0xF75 +#define REG_CLK_WD_TIMER_CTRL 0xF76 +#define REG_SW_TIMER_CTRL 0xF77 +#define REG_PROG_TIMER_CTRL 0xF78 +#define REG_PROG_TIMER_CLK_SEL 0xF79 -#define INPUT_PORT_NUM 2 +#define INPUT_PORT_NUM 2 typedef struct { - char *log; - u12_t code; - u12_t mask; - u12_t shift_arg0; - u12_t mask_arg0; // != 0 only if there are two arguments - u8_t cycles; - void (*cb)(u8_t arg0, u8_t arg1); + char* log; + u12_t code; + u12_t mask; + u12_t shift_arg0; + u12_t mask_arg0; // != 0 only if there are two arguments + u8_t cycles; + void (*cb)(u8_t arg0, u8_t arg1); } op_t; typedef struct { - u4_t states; + u4_t states; } input_port_t; /* Registers */ @@ -132,22 +140,22 @@ static u8_t sp; /* Flags */ static u4_t flags; -static const u12_t *g_program = NULL; +static const u12_t* g_program = NULL; static MEM_BUFFER_TYPE memory[MEM_BUFFER_SIZE]; static input_port_t inputs[INPUT_PORT_NUM] = {{0}}; /* Interrupts (in priority order) */ static interrupt_t interrupts[INT_SLOT_NUM] = { - {0x0, 0x0, 0, 0x0C}, // Prog timer - {0x0, 0x0, 0, 0x0A}, // Serial interface - {0x0, 0x0, 0, 0x08}, // Input (K10-K13) - {0x0, 0x0, 0, 0x06}, // Input (K00-K03) - {0x0, 0x0, 0, 0x04}, // Stopwatch timer - {0x0, 0x0, 0, 0x02}, // Clock timer + {0x0, 0x0, 0, 0x0C}, // Prog timer + {0x0, 0x0, 0, 0x0A}, // Serial interface + {0x0, 0x0, 0, 0x08}, // Input (K10-K13) + {0x0, 0x0, 0, 0x06}, // Input (K00-K03) + {0x0, 0x0, 0, 0x04}, // Stopwatch timer + {0x0, 0x0, 0, 0x02}, // Clock timer }; -static breakpoint_t *g_breakpoints = NULL; +static breakpoint_t* g_breakpoints = NULL; static u32_t call_depth = 0; @@ -163,1747 +171,1863 @@ static u8_t speed_ratio = 1; static timestamp_t ref_ts; static state_t cpu_state = { - .pc = &pc, - .x = &x, - .y = &y, - .a = &a, - .b = &b, - .np = &np, - .sp = &sp, - .flags = &flags, + .pc = &pc, + .x = &x, + .y = &y, + .a = &a, + .b = &b, + .np = &np, + .sp = &sp, + .flags = &flags, - .tick_counter = &tick_counter, - .clk_timer_timestamp = &clk_timer_timestamp, - .prog_timer_timestamp = &prog_timer_timestamp, - .prog_timer_enabled = &prog_timer_enabled, - .prog_timer_data = &prog_timer_data, - .prog_timer_rld = &prog_timer_rld, + .tick_counter = &tick_counter, + .clk_timer_timestamp = &clk_timer_timestamp, + .prog_timer_timestamp = &prog_timer_timestamp, + .prog_timer_enabled = &prog_timer_enabled, + .prog_timer_data = &prog_timer_data, + .prog_timer_rld = &prog_timer_rld, - .call_depth = &call_depth, + .call_depth = &call_depth, - .interrupts = interrupts, + .interrupts = interrupts, - .memory = memory, + .memory = memory, }; +void cpu_add_bp(breakpoint_t** list, u13_t addr) { + breakpoint_t* bp; -void cpu_add_bp(breakpoint_t **list, u13_t addr) -{ - breakpoint_t *bp; + bp = (breakpoint_t*)g_hal->malloc(sizeof(breakpoint_t)); + if(!bp) { + g_hal->log(LOG_ERROR, "Cannot allocate memory for breakpoint 0x%04X!\n", addr); + return; + } - bp = (breakpoint_t *) g_hal->malloc(sizeof(breakpoint_t)); - if (!bp) { - g_hal->log(LOG_ERROR, "Cannot allocate memory for breakpoint 0x%04X!\n", addr); - return; - } + bp->addr = addr; - bp->addr = addr; + if(*list != NULL) { + bp->next = *list; + } else { + /* List is empty */ + bp->next = NULL; + } - if (*list != NULL) { - bp->next = *list; - } else { - /* List is empty */ - bp->next = NULL; - } - - *list = bp; + *list = bp; } -void cpu_free_bp(breakpoint_t **list) -{ - breakpoint_t *bp = *list, *tmp; +void cpu_free_bp(breakpoint_t** list) { + breakpoint_t *bp = *list, *tmp; - while (bp != NULL) { - tmp = bp->next; - g_hal->free(bp); - bp = tmp; - } + while(bp != NULL) { + tmp = bp->next; + g_hal->free(bp); + bp = tmp; + } - *list = NULL; + *list = NULL; } -void cpu_set_speed(u8_t speed) -{ - speed_ratio = speed; +void cpu_set_speed(u8_t speed) { + speed_ratio = speed; } -state_t * cpu_get_state(void) -{ - return &cpu_state; +state_t* cpu_get_state(void) { + return &cpu_state; } -u32_t cpu_get_depth(void) -{ - return call_depth; +u32_t cpu_get_depth(void) { + return call_depth; } -static void generate_interrupt(int_slot_t slot, u8_t bit) -{ - /* Set the factor flag no matter what */ - interrupts[slot].factor_flag_reg = interrupts[slot].factor_flag_reg | (0x1 << bit); +static void generate_interrupt(int_slot_t slot, u8_t bit) { + /* Set the factor flag no matter what */ + interrupts[slot].factor_flag_reg = interrupts[slot].factor_flag_reg | (0x1 << bit); - /* Trigger the INT only if not masked */ - if (interrupts[slot].mask_reg & (0x1 << bit)) { - interrupts[slot].triggered = 1; - } + /* Trigger the INT only if not masked */ + if(interrupts[slot].mask_reg & (0x1 << bit)) { + interrupts[slot].triggered = 1; + } } -void cpu_set_input_pin(pin_t pin, pin_state_t state) -{ - /* Set the I/O */ - inputs[pin & 0x4].states = (inputs[pin & 0x4].states & ~(0x1 << (pin & 0x3))) | (state << (pin & 0x3)); +void cpu_set_input_pin(pin_t pin, pin_state_t state) { + /* Set the I/O */ + inputs[pin & 0x4].states = (inputs[pin & 0x4].states & ~(0x1 << (pin & 0x3))) | + (state << (pin & 0x3)); - /* Trigger the interrupt (TODO: handle relation register) */ - if (state == PIN_STATE_LOW) { - switch ((pin & 0x4) >> 2) { - case 0: - generate_interrupt(INT_K00_K03_SLOT, pin & 0x3); - break; + /* Trigger the interrupt (TODO: handle relation register) */ + if(state == PIN_STATE_LOW) { + switch((pin & 0x4) >> 2) { + case 0: + generate_interrupt(INT_K00_K03_SLOT, pin & 0x3); + break; - case 1: - generate_interrupt(INT_K10_K13_SLOT, pin & 0x3); - break; - } - } + case 1: + generate_interrupt(INT_K10_K13_SLOT, pin & 0x3); + break; + } + } } -void cpu_sync_ref_timestamp(void) -{ - ref_ts = g_hal->get_timestamp(); +void cpu_sync_ref_timestamp(void) { + ref_ts = g_hal->get_timestamp(); } -static u4_t get_io(u12_t n) -{ - u4_t tmp; +static u4_t get_io(u12_t n) { + u4_t tmp; - switch (n) { - case REG_CLK_INT_FACTOR_FLAGS: - /* Interrupt factor flags (clock timer) */ - tmp = interrupts[INT_CLOCK_TIMER_SLOT].factor_flag_reg; - interrupts[INT_CLOCK_TIMER_SLOT].factor_flag_reg = 0; - return tmp; + switch(n) { + case REG_CLK_INT_FACTOR_FLAGS: + /* Interrupt factor flags (clock timer) */ + tmp = interrupts[INT_CLOCK_TIMER_SLOT].factor_flag_reg; + interrupts[INT_CLOCK_TIMER_SLOT].factor_flag_reg = 0; + return tmp; - case REG_SW_INT_FACTOR_FLAGS: - /* Interrupt factor flags (stopwatch) */ - tmp = interrupts[INT_STOPWATCH_SLOT].factor_flag_reg; - interrupts[INT_STOPWATCH_SLOT].factor_flag_reg = 0; - return tmp; + case REG_SW_INT_FACTOR_FLAGS: + /* Interrupt factor flags (stopwatch) */ + tmp = interrupts[INT_STOPWATCH_SLOT].factor_flag_reg; + interrupts[INT_STOPWATCH_SLOT].factor_flag_reg = 0; + return tmp; - case REG_PROG_INT_FACTOR_FLAGS: - /* Interrupt factor flags (prog timer) */ - tmp = interrupts[INT_PROG_TIMER_SLOT].factor_flag_reg; - interrupts[INT_PROG_TIMER_SLOT].factor_flag_reg = 0; - return tmp; + case REG_PROG_INT_FACTOR_FLAGS: + /* Interrupt factor flags (prog timer) */ + tmp = interrupts[INT_PROG_TIMER_SLOT].factor_flag_reg; + interrupts[INT_PROG_TIMER_SLOT].factor_flag_reg = 0; + return tmp; - case REG_SERIAL_INT_FACTOR_FLAGS: - /* Interrupt factor flags (serial) */ - tmp = interrupts[INT_SERIAL_SLOT].factor_flag_reg; - interrupts[INT_SERIAL_SLOT].factor_flag_reg = 0; - return tmp; + case REG_SERIAL_INT_FACTOR_FLAGS: + /* Interrupt factor flags (serial) */ + tmp = interrupts[INT_SERIAL_SLOT].factor_flag_reg; + interrupts[INT_SERIAL_SLOT].factor_flag_reg = 0; + return tmp; - case REG_K00_K03_INT_FACTOR_FLAGS: - /* Interrupt factor flags (K00-K03) */ - tmp = interrupts[INT_K00_K03_SLOT].factor_flag_reg; - interrupts[INT_K00_K03_SLOT].factor_flag_reg = 0; - return tmp; + case REG_K00_K03_INT_FACTOR_FLAGS: + /* Interrupt factor flags (K00-K03) */ + tmp = interrupts[INT_K00_K03_SLOT].factor_flag_reg; + interrupts[INT_K00_K03_SLOT].factor_flag_reg = 0; + return tmp; - case REG_K10_K13_INT_FACTOR_FLAGS: - /* Interrupt factor flags (K10-K13) */ - tmp = interrupts[INT_K10_K13_SLOT].factor_flag_reg; - interrupts[INT_K10_K13_SLOT].factor_flag_reg = 0; - return tmp; + case REG_K10_K13_INT_FACTOR_FLAGS: + /* Interrupt factor flags (K10-K13) */ + tmp = interrupts[INT_K10_K13_SLOT].factor_flag_reg; + interrupts[INT_K10_K13_SLOT].factor_flag_reg = 0; + return tmp; - case REG_CLOCK_INT_MASKS: - /* Clock timer interrupt masks */ - return interrupts[INT_CLOCK_TIMER_SLOT].mask_reg; + case REG_CLOCK_INT_MASKS: + /* Clock timer interrupt masks */ + return interrupts[INT_CLOCK_TIMER_SLOT].mask_reg; - case REG_SW_INT_MASKS: - /* Stopwatch interrupt masks */ - return interrupts[INT_STOPWATCH_SLOT].mask_reg & 0x3; + case REG_SW_INT_MASKS: + /* Stopwatch interrupt masks */ + return interrupts[INT_STOPWATCH_SLOT].mask_reg & 0x3; - case REG_PROG_INT_MASKS: - /* Prog timer interrupt masks */ - return interrupts[INT_PROG_TIMER_SLOT].mask_reg & 0x1; + case REG_PROG_INT_MASKS: + /* Prog timer interrupt masks */ + return interrupts[INT_PROG_TIMER_SLOT].mask_reg & 0x1; - case REG_SERIAL_INT_MASKS: - /* Serial interface interrupt masks */ - return interrupts[INT_SERIAL_SLOT].mask_reg & 0x1; + case REG_SERIAL_INT_MASKS: + /* Serial interface interrupt masks */ + return interrupts[INT_SERIAL_SLOT].mask_reg & 0x1; - case REG_K00_K03_INT_MASKS: - /* Input (K00-K03) interrupt masks */ - return interrupts[INT_K00_K03_SLOT].mask_reg; + case REG_K00_K03_INT_MASKS: + /* Input (K00-K03) interrupt masks */ + return interrupts[INT_K00_K03_SLOT].mask_reg; - case REG_K10_K13_INT_MASKS: - /* Input (K10-K13) interrupt masks */ - return interrupts[INT_K10_K13_SLOT].mask_reg; + case REG_K10_K13_INT_MASKS: + /* Input (K10-K13) interrupt masks */ + return interrupts[INT_K10_K13_SLOT].mask_reg; - case REG_PROG_TIMER_DATA_L: - /* Prog timer data (low) */ - return prog_timer_data & 0xF; + case REG_PROG_TIMER_DATA_L: + /* Prog timer data (low) */ + return prog_timer_data & 0xF; - case REG_PROG_TIMER_DATA_H: - /* Prog timer data (high) */ - return (prog_timer_data >> 4) & 0xF; + case REG_PROG_TIMER_DATA_H: + /* Prog timer data (high) */ + return (prog_timer_data >> 4) & 0xF; - case REG_PROG_TIMER_RELOAD_DATA_L: - /* Prog timer reload data (low) */ - return prog_timer_rld & 0xF; + case REG_PROG_TIMER_RELOAD_DATA_L: + /* Prog timer reload data (low) */ + return prog_timer_rld & 0xF; - case REG_PROG_TIMER_RELOAD_DATA_H: - /* Prog timer reload data (high) */ - return (prog_timer_rld >> 4) & 0xF; + case REG_PROG_TIMER_RELOAD_DATA_H: + /* Prog timer reload data (high) */ + return (prog_timer_rld >> 4) & 0xF; - case REG_K00_K03_INPUT_PORT: - /* Input port (K00-K03) */ - return inputs[0].states; + case REG_K00_K03_INPUT_PORT: + /* Input port (K00-K03) */ + return inputs[0].states; - case REG_K10_K13_INPUT_PORT: - /* Input port (K10-K13) */ - return inputs[1].states; + case REG_K10_K13_INPUT_PORT: + /* Input port (K10-K13) */ + return inputs[1].states; - case REG_K40_K43_BZ_OUTPUT_PORT: - /* Output port (R40-R43) */ - return GET_IO_MEMORY(memory, n); + case REG_K40_K43_BZ_OUTPUT_PORT: + /* Output port (R40-R43) */ + return GET_IO_MEMORY(memory, n); - case REG_CPU_OSC3_CTRL: - /* CPU/OSC3 clocks switch, CPU voltage switch */ - return GET_IO_MEMORY(memory, n); + case REG_CPU_OSC3_CTRL: + /* CPU/OSC3 clocks switch, CPU voltage switch */ + return GET_IO_MEMORY(memory, n); - case REG_LCD_CTRL: - /* LCD control */ - return GET_IO_MEMORY(memory, n); + case REG_LCD_CTRL: + /* LCD control */ + return GET_IO_MEMORY(memory, n); - case REG_LCD_CONTRAST: - /* LCD contrast */ - break; + case REG_LCD_CONTRAST: + /* LCD contrast */ + break; - case REG_SVD_CTRL: - /* SVD */ - return GET_IO_MEMORY(memory, n) & 0x7; // Voltage always OK + case REG_SVD_CTRL: + /* SVD */ + return GET_IO_MEMORY(memory, n) & 0x7; // Voltage always OK - case REG_BUZZER_CTRL1: - /* Buzzer config 1 */ - return GET_IO_MEMORY(memory, n); + case REG_BUZZER_CTRL1: + /* Buzzer config 1 */ + return GET_IO_MEMORY(memory, n); - case REG_BUZZER_CTRL2: - /* Buzzer config 2 */ - return GET_IO_MEMORY(memory, n) & 0x3; // Buzzer ready + case REG_BUZZER_CTRL2: + /* Buzzer config 2 */ + return GET_IO_MEMORY(memory, n) & 0x3; // Buzzer ready - case REG_CLK_WD_TIMER_CTRL: - /* Clock/Watchdog timer reset */ - break; + case REG_CLK_WD_TIMER_CTRL: + /* Clock/Watchdog timer reset */ + break; - case REG_SW_TIMER_CTRL: - /* Stopwatch stop/run/reset */ - break; + case REG_SW_TIMER_CTRL: + /* Stopwatch stop/run/reset */ + break; - case REG_PROG_TIMER_CTRL: - /* Prog timer stop/run/reset */ - return !!prog_timer_enabled; + case REG_PROG_TIMER_CTRL: + /* Prog timer stop/run/reset */ + return !!prog_timer_enabled; - case REG_PROG_TIMER_CLK_SEL: - /* Prog timer clock selection */ - break; + case REG_PROG_TIMER_CLK_SEL: + /* Prog timer clock selection */ + break; - default: - g_hal->log(LOG_ERROR, "Read from unimplemented I/O 0x%03X - PC = 0x%04X\n", n, pc); - } + default: + g_hal->log(LOG_ERROR, "Read from unimplemented I/O 0x%03X - PC = 0x%04X\n", n, pc); + } - return 0; + return 0; } -static void set_io(u12_t n, u4_t v) -{ - switch (n) { - case REG_CLOCK_INT_MASKS: - /* Clock timer interrupt masks */ - /* Assume 1Hz timer INT enabled (0x8) */ - interrupts[INT_CLOCK_TIMER_SLOT].mask_reg = v; - break; +static void set_io(u12_t n, u4_t v) { + switch(n) { + case REG_CLOCK_INT_MASKS: + /* Clock timer interrupt masks */ + /* Assume 1Hz timer INT enabled (0x8) */ + interrupts[INT_CLOCK_TIMER_SLOT].mask_reg = v; + break; - case REG_SW_INT_MASKS: - /* Stopwatch interrupt masks */ - /* Assume all INT disabled */ - interrupts[INT_STOPWATCH_SLOT].mask_reg = v; - break; + case REG_SW_INT_MASKS: + /* Stopwatch interrupt masks */ + /* Assume all INT disabled */ + interrupts[INT_STOPWATCH_SLOT].mask_reg = v; + break; - case REG_PROG_INT_MASKS: - /* Prog timer interrupt masks */ - /* Assume Prog timer INT enabled (0x1) */ - interrupts[INT_PROG_TIMER_SLOT].mask_reg = v; - break; + case REG_PROG_INT_MASKS: + /* Prog timer interrupt masks */ + /* Assume Prog timer INT enabled (0x1) */ + interrupts[INT_PROG_TIMER_SLOT].mask_reg = v; + break; - case REG_SERIAL_INT_MASKS: - /* Serial interface interrupt masks */ - /* Assume all INT disabled */ - interrupts[INT_K10_K13_SLOT].mask_reg = v; - break; + case REG_SERIAL_INT_MASKS: + /* Serial interface interrupt masks */ + /* Assume all INT disabled */ + interrupts[INT_K10_K13_SLOT].mask_reg = v; + break; - case REG_K00_K03_INT_MASKS: - /* Input (K00-K03) interrupt masks */ - /* Assume all INT disabled */ - interrupts[INT_SERIAL_SLOT].mask_reg = v; - break; + case REG_K00_K03_INT_MASKS: + /* Input (K00-K03) interrupt masks */ + /* Assume all INT disabled */ + interrupts[INT_SERIAL_SLOT].mask_reg = v; + break; - case REG_K10_K13_INT_MASKS: - /* Input (K10-K13) interrupt masks */ - /* Assume all INT disabled */ - interrupts[INT_K10_K13_SLOT].mask_reg = v; - break; + case REG_K10_K13_INT_MASKS: + /* Input (K10-K13) interrupt masks */ + /* Assume all INT disabled */ + interrupts[INT_K10_K13_SLOT].mask_reg = v; + break; - case REG_PROG_TIMER_RELOAD_DATA_L: - /* Prog timer reload data (low) */ - prog_timer_rld = v | (prog_timer_rld & 0xF0); - break; + case REG_PROG_TIMER_RELOAD_DATA_L: + /* Prog timer reload data (low) */ + prog_timer_rld = v | (prog_timer_rld & 0xF0); + break; - case REG_PROG_TIMER_RELOAD_DATA_H: - /* Prog timer reload data (high) */ - prog_timer_rld = (prog_timer_rld & 0xF) | (v << 4); - break; + case REG_PROG_TIMER_RELOAD_DATA_H: + /* Prog timer reload data (high) */ + prog_timer_rld = (prog_timer_rld & 0xF) | (v << 4); + break; - case REG_K00_K03_INPUT_PORT: - /* Input port (K00-K03) */ - /* Write not allowed */ - break; + case REG_K00_K03_INPUT_PORT: + /* Input port (K00-K03) */ + /* Write not allowed */ + break; - case REG_K40_K43_BZ_OUTPUT_PORT: - /* Output port (R40-R43) */ - //g_hal->log(LOG_INFO, "Output/Buzzer: 0x%X\n", v); - hw_enable_buzzer(!(v & 0x8)); - break; + case REG_K40_K43_BZ_OUTPUT_PORT: + /* Output port (R40-R43) */ + //g_hal->log(LOG_INFO, "Output/Buzzer: 0x%X\n", v); + hw_enable_buzzer(!(v & 0x8)); + break; - case REG_CPU_OSC3_CTRL: - /* CPU/OSC3 clocks switch, CPU voltage switch */ - /* Assume 32,768 OSC1 selected, OSC3 off, battery >= 3,1V (0x1) */ - break; + case REG_CPU_OSC3_CTRL: + /* CPU/OSC3 clocks switch, CPU voltage switch */ + /* Assume 32,768 OSC1 selected, OSC3 off, battery >= 3,1V (0x1) */ + break; - case REG_LCD_CTRL: - /* LCD control */ - break; + case REG_LCD_CTRL: + /* LCD control */ + break; - case REG_LCD_CONTRAST: - /* LCD contrast */ - /* Assume medium contrast (0x8) */ - break; + case REG_LCD_CONTRAST: + /* LCD contrast */ + /* Assume medium contrast (0x8) */ + break; - case REG_SVD_CTRL: - /* SVD */ - /* Assume battery voltage always OK (0x6) */ - break; + case REG_SVD_CTRL: + /* SVD */ + /* Assume battery voltage always OK (0x6) */ + break; - case REG_BUZZER_CTRL1: - /* Buzzer config 1 */ - hw_set_buzzer_freq(v & 0x7); - break; + case REG_BUZZER_CTRL1: + /* Buzzer config 1 */ + hw_set_buzzer_freq(v & 0x7); + break; - case REG_BUZZER_CTRL2: - /* Buzzer config 2 */ - break; + case REG_BUZZER_CTRL2: + /* Buzzer config 2 */ + break; - case REG_CLK_WD_TIMER_CTRL: - /* Clock/Watchdog timer reset */ - /* Ignore watchdog */ - break; + case REG_CLK_WD_TIMER_CTRL: + /* Clock/Watchdog timer reset */ + /* Ignore watchdog */ + break; - case REG_SW_TIMER_CTRL: - /* Stopwatch stop/run/reset */ - break; + case REG_SW_TIMER_CTRL: + /* Stopwatch stop/run/reset */ + break; - case REG_PROG_TIMER_CTRL: - /* Prog timer stop/run/reset */ - if (v & 0x2) { - prog_timer_data = prog_timer_rld; - } + case REG_PROG_TIMER_CTRL: + /* Prog timer stop/run/reset */ + if(v & 0x2) { + prog_timer_data = prog_timer_rld; + } - if ((v & 0x1) && !prog_timer_enabled) { - prog_timer_timestamp = tick_counter; - } + if((v & 0x1) && !prog_timer_enabled) { + prog_timer_timestamp = tick_counter; + } - prog_timer_enabled = v & 0x1; - break; + prog_timer_enabled = v & 0x1; + break; - case REG_PROG_TIMER_CLK_SEL: - /* Prog timer clock selection */ - /* Assume 256Hz, output disabled */ - break; + case REG_PROG_TIMER_CLK_SEL: + /* Prog timer clock selection */ + /* Assume 256Hz, output disabled */ + break; - default: - g_hal->log(LOG_ERROR, "Write 0x%X to unimplemented I/O 0x%03X - PC = 0x%04X\n", v, n, pc); - } + default: + g_hal->log(LOG_ERROR, "Write 0x%X to unimplemented I/O 0x%03X - PC = 0x%04X\n", v, n, pc); + } } -static void set_lcd(u12_t n, u4_t v) -{ - u8_t i; - u8_t seg, com0; +static void set_lcd(u12_t n, u4_t v) { + u8_t i; + u8_t seg, com0; - seg = ((n & 0x7F) >> 1); - com0 = (((n & 0x80) >> 7) * 8 + (n & 0x1) * 4); + seg = ((n & 0x7F) >> 1); + com0 = (((n & 0x80) >> 7) * 8 + (n & 0x1) * 4); - for (i = 0; i < 4; i++) { - hw_set_lcd_pin(seg, com0 + i, (v >> i) & 0x1); - } + for(i = 0; i < 4; i++) { + hw_set_lcd_pin(seg, com0 + i, (v >> i) & 0x1); + } } -static u4_t get_memory(u12_t n) -{ - u4_t res = 0; +static u4_t get_memory(u12_t n) { + u4_t res = 0; - if (n < MEM_RAM_SIZE) { - /* RAM */ - g_hal->log(LOG_MEMORY, "RAM - "); - res = GET_RAM_MEMORY(memory, n); - } else if (n >= MEM_DISPLAY1_ADDR && n < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { - /* Display Memory 1 */ - g_hal->log(LOG_MEMORY, "Display Memory 1 - "); - res = GET_DISP1_MEMORY(memory, n); - } else if (n >= MEM_DISPLAY2_ADDR && n < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { - /* Display Memory 2 */ - g_hal->log(LOG_MEMORY, "Display Memory 2 - "); - res = GET_DISP2_MEMORY(memory, n); - } else if (n >= MEM_IO_ADDR && n < (MEM_IO_ADDR + MEM_IO_SIZE)) { - /* I/O Memory */ - g_hal->log(LOG_MEMORY, "I/O - "); - res = get_io(n); - } else { - g_hal->log(LOG_ERROR, "Read from invalid memory address 0x%03X - PC = 0x%04X\n", n, pc); - return 0; - } + if(n < MEM_RAM_SIZE) { + /* RAM */ + g_hal->log(LOG_MEMORY, "RAM - "); + res = GET_RAM_MEMORY(memory, n); + } else if(n >= MEM_DISPLAY1_ADDR && n < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { + /* Display Memory 1 */ + g_hal->log(LOG_MEMORY, "Display Memory 1 - "); + res = GET_DISP1_MEMORY(memory, n); + } else if(n >= MEM_DISPLAY2_ADDR && n < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { + /* Display Memory 2 */ + g_hal->log(LOG_MEMORY, "Display Memory 2 - "); + res = GET_DISP2_MEMORY(memory, n); + } else if(n >= MEM_IO_ADDR && n < (MEM_IO_ADDR + MEM_IO_SIZE)) { + /* I/O Memory */ + g_hal->log(LOG_MEMORY, "I/O - "); + res = get_io(n); + } else { + g_hal->log(LOG_ERROR, "Read from invalid memory address 0x%03X - PC = 0x%04X\n", n, pc); + return 0; + } - g_hal->log(LOG_MEMORY, "Read 0x%X - Address 0x%03X - PC = 0x%04X\n", res, n, pc); + g_hal->log(LOG_MEMORY, "Read 0x%X - Address 0x%03X - PC = 0x%04X\n", res, n, pc); - return res; + return res; } -static void set_memory(u12_t n, u4_t v) -{ - /* Cache any data written to a valid address, and process it */ - if (n < MEM_RAM_SIZE) { - /* RAM */ - SET_RAM_MEMORY(memory, n, v); - g_hal->log(LOG_MEMORY, "RAM - "); - } else if (n >= MEM_DISPLAY1_ADDR && n < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { - /* Display Memory 1 */ - SET_DISP1_MEMORY(memory, n, v); - set_lcd(n, v); - g_hal->log(LOG_MEMORY, "Display Memory 1 - "); - } else if (n >= MEM_DISPLAY2_ADDR && n < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { - /* Display Memory 2 */ - SET_DISP2_MEMORY(memory, n, v); - set_lcd(n, v); - g_hal->log(LOG_MEMORY, "Display Memory 2 - "); - } else if (n >= MEM_IO_ADDR && n < (MEM_IO_ADDR + MEM_IO_SIZE)) { - /* I/O Memory */ - SET_IO_MEMORY(memory, n, v); - set_io(n, v); - g_hal->log(LOG_MEMORY, "I/O - "); - } else { - g_hal->log(LOG_ERROR, "Write 0x%X to invalid memory address 0x%03X - PC = 0x%04X\n", v, n, pc); - return; - } +static void set_memory(u12_t n, u4_t v) { + /* Cache any data written to a valid address, and process it */ + if(n < MEM_RAM_SIZE) { + /* RAM */ + SET_RAM_MEMORY(memory, n, v); + g_hal->log(LOG_MEMORY, "RAM - "); + } else if(n >= MEM_DISPLAY1_ADDR && n < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { + /* Display Memory 1 */ + SET_DISP1_MEMORY(memory, n, v); + set_lcd(n, v); + g_hal->log(LOG_MEMORY, "Display Memory 1 - "); + } else if(n >= MEM_DISPLAY2_ADDR && n < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { + /* Display Memory 2 */ + SET_DISP2_MEMORY(memory, n, v); + set_lcd(n, v); + g_hal->log(LOG_MEMORY, "Display Memory 2 - "); + } else if(n >= MEM_IO_ADDR && n < (MEM_IO_ADDR + MEM_IO_SIZE)) { + /* I/O Memory */ + SET_IO_MEMORY(memory, n, v); + set_io(n, v); + g_hal->log(LOG_MEMORY, "I/O - "); + } else { + g_hal->log( + LOG_ERROR, "Write 0x%X to invalid memory address 0x%03X - PC = 0x%04X\n", v, n, pc); + return; + } - g_hal->log(LOG_MEMORY, "Write 0x%X - Address 0x%03X - PC = 0x%04X\n", v, n, pc); + g_hal->log(LOG_MEMORY, "Write 0x%X - Address 0x%03X - PC = 0x%04X\n", v, n, pc); } -void cpu_refresh_hw(void) -{ - static const struct range { - u12_t addr; - u12_t size; - } refresh_locs[] = { - { MEM_DISPLAY1_ADDR, MEM_DISPLAY1_SIZE }, /* Display Memory 1 */ - { MEM_DISPLAY2_ADDR, MEM_DISPLAY2_SIZE }, /* Display Memory 2 */ - { REG_BUZZER_CTRL1, 1 }, /* Buzzer frequency */ - { REG_K40_K43_BZ_OUTPUT_PORT, 1 }, /* Buzzer enabled */ +void cpu_refresh_hw(void) { + static const struct range { + u12_t addr; + u12_t size; + } refresh_locs[] = { + {MEM_DISPLAY1_ADDR, MEM_DISPLAY1_SIZE}, /* Display Memory 1 */ + {MEM_DISPLAY2_ADDR, MEM_DISPLAY2_SIZE}, /* Display Memory 2 */ + {REG_BUZZER_CTRL1, 1}, /* Buzzer frequency */ + {REG_K40_K43_BZ_OUTPUT_PORT, 1}, /* Buzzer enabled */ - { 0, 0 }, // end of list - }; + {0, 0}, // end of list + }; - for (int i = 0; refresh_locs[i].size != 0; i++) { - for (u12_t n = refresh_locs[i].addr; n < (refresh_locs[i].addr + refresh_locs[i].size); n++) { - set_memory(n, GET_MEMORY(memory, n)); - } - } + for(int i = 0; refresh_locs[i].size != 0; i++) { + for(u12_t n = refresh_locs[i].addr; n < (refresh_locs[i].addr + refresh_locs[i].size); + n++) { + set_memory(n, GET_MEMORY(memory, n)); + } + } } -static u4_t get_rq(u12_t rq) -{ - switch (rq & 0x3) { - case 0x0: - return a; +static u4_t get_rq(u12_t rq) { + switch(rq & 0x3) { + case 0x0: + return a; - case 0x1: - return b; + case 0x1: + return b; - case 0x2: - return M(x); + case 0x2: + return M(x); - case 0x3: - return M(y); - } + case 0x3: + return M(y); + } - return 0; + return 0; } -static void set_rq(u12_t rq, u4_t v) -{ - switch (rq & 0x3) { - case 0x0: - a = v; - break; +static void set_rq(u12_t rq, u4_t v) { + switch(rq & 0x3) { + case 0x0: + a = v; + break; - case 0x1: - b = v; - break; + case 0x1: + b = v; + break; - case 0x2: - SET_M(x, v); - break; + case 0x2: + SET_M(x, v); + break; - case 0x3: - SET_M(y, v); - break; - } + case 0x3: + SET_M(y, v); + break; + } } /* Instructions */ -static void op_pset_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - np = arg0; -} - -static void op_jp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - next_pc = arg0 | (np << 8); -} - -static void op_jp_c_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (flags & FLAG_C) { - next_pc = arg0 | (np << 8); - } -} - -static void op_jp_nc_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (!(flags & FLAG_C)) { - next_pc = arg0 | (np << 8); - } -} - -static void op_jp_z_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (flags & FLAG_Z) { - next_pc = arg0 | (np << 8); - } -} - -static void op_jp_nz_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (!(flags & FLAG_Z)) { - next_pc = arg0 | (np << 8); - } +static void op_pset_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + np = arg0; } -static void op_jpba_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - next_pc = a | (b << 4) | (np << 8); +static void op_jp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + next_pc = arg0 | (np << 8); } -static void op_call_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - pc = (pc + 1) & 0x1FFF; // This does not actually change the PC register - SET_M(sp - 1, PCP); - SET_M(sp - 2, PCSH); - SET_M(sp - 3, PCSL); - sp = (sp - 3) & 0xFF; - next_pc = TO_PC(PCB, NPP, arg0); - call_depth++; +static void op_jp_c_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(flags & FLAG_C) { + next_pc = arg0 | (np << 8); + } } -static void op_calz_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - pc = (pc + 1) & 0x1FFF; // This does not actually change the PC register - SET_M(sp - 1, PCP); - SET_M(sp - 2, PCSH); - SET_M(sp - 3, PCSL); - sp = (sp - 3) & 0xFF; - next_pc = TO_PC(PCB, 0, arg0); - call_depth++; +static void op_jp_nc_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(!(flags & FLAG_C)) { + next_pc = arg0 | (np << 8); + } } -static void op_ret_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); - sp = (sp + 3) & 0xFF; - call_depth--; +static void op_jp_z_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(flags & FLAG_Z) { + next_pc = arg0 | (np << 8); + } } -static void op_rets_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); - sp = (sp + 3) & 0xFF; - next_pc = (pc + 1) & 0x1FFF; - call_depth--; +static void op_jp_nz_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(!(flags & FLAG_Z)) { + next_pc = arg0 | (np << 8); + } } -static void op_retd_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); - sp = (sp + 3) & 0xFF; - SET_M(x, arg0 & 0xF); - SET_M(x + 1, (arg0 >> 4) & 0xF); - x = ((x + 2) & 0xFF) | (XP << 8); - call_depth--; +static void op_jpba_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + next_pc = a | (b << 4) | (np << 8); } -static void op_nop5_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); +static void op_call_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + pc = (pc + 1) & 0x1FFF; // This does not actually change the PC register + SET_M(sp - 1, PCP); + SET_M(sp - 2, PCSH); + SET_M(sp - 3, PCSL); + sp = (sp - 3) & 0xFF; + next_pc = TO_PC(PCB, NPP, arg0); + call_depth++; } -static void op_nop7_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); +static void op_calz_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + pc = (pc + 1) & 0x1FFF; // This does not actually change the PC register + SET_M(sp - 1, PCP); + SET_M(sp - 2, PCSH); + SET_M(sp - 3, PCSL); + sp = (sp - 3) & 0xFF; + next_pc = TO_PC(PCB, 0, arg0); + call_depth++; } -static void op_halt_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - g_hal->halt(); +static void op_ret_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); + sp = (sp + 3) & 0xFF; + call_depth--; } -static void op_inc_x_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - x = ((x + 1) & 0xFF) | (XP << 8); +static void op_rets_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); + sp = (sp + 3) & 0xFF; + next_pc = (pc + 1) & 0x1FFF; + call_depth--; } -static void op_inc_y_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - y = ((y + 1) & 0xFF) | (YP << 8); +static void op_retd_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + next_pc = M(sp) | (M(sp + 1) << 4) | (M(sp + 2) << 8) | (PCB << 12); + sp = (sp + 3) & 0xFF; + SET_M(x, arg0 & 0xF); + SET_M(x + 1, (arg0 >> 4) & 0xF); + x = ((x + 2) & 0xFF) | (XP << 8); + call_depth--; } -static void op_ld_x_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - x = arg0 | (XP << 8); +static void op_nop5_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); } -static void op_ld_y_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - y = arg0 | (YP << 8); +static void op_nop7_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); } -static void op_ld_xp_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - x = XHL | (RQ(arg0) << 8); +static void op_halt_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + g_hal->halt(); } -static void op_ld_xh_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - x = XL | (RQ(arg0) << 4) | (XP << 8); +static void op_inc_x_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + x = ((x + 1) & 0xFF) | (XP << 8); } -static void op_ld_xl_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - x = RQ(arg0) | (XH << 4) | (XP << 8); +static void op_inc_y_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + y = ((y + 1) & 0xFF) | (YP << 8); } -static void op_ld_yp_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - y = YHL | (RQ(arg0) << 8); +static void op_ld_x_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + x = arg0 | (XP << 8); } -static void op_ld_yh_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - y = YL | (RQ(arg0) << 4) | (YP << 8); +static void op_ld_y_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + y = arg0 | (YP << 8); } -static void op_ld_yl_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - y = RQ(arg0) | (YH << 4) | (YP << 8); +static void op_ld_xp_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + x = XHL | (RQ(arg0) << 8); } -static void op_ld_r_xp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, XP); +static void op_ld_xh_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + x = XL | (RQ(arg0) << 4) | (XP << 8); } -static void op_ld_r_xh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, XH); +static void op_ld_xl_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + x = RQ(arg0) | (XH << 4) | (XP << 8); } -static void op_ld_r_xl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, XL); +static void op_ld_yp_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + y = YHL | (RQ(arg0) << 8); } -static void op_ld_r_yp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, YP); +static void op_ld_yh_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + y = YL | (RQ(arg0) << 4) | (YP << 8); } -static void op_ld_r_yh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, YH); +static void op_ld_yl_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + y = RQ(arg0) | (YH << 4) | (YP << 8); } -static void op_ld_r_yl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, YL); +static void op_ld_r_xp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, XP); } -static void op_adc_xh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; +static void op_ld_r_xh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, XH); +} + +static void op_ld_r_xl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, XL); +} + +static void op_ld_r_yp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, YP); +} + +static void op_ld_r_yh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, YH); +} + +static void op_ld_r_yl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, YL); +} + +static void op_adc_xh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; - tmp = XH + arg0 + C; - x = XL | ((tmp & 0xF) << 4)| (XP << 8); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!(tmp & 0xF)) { SET_Z(); } else { CLEAR_Z(); } + tmp = XH + arg0 + C; + x = XL | ((tmp & 0xF) << 4) | (XP << 8); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!(tmp & 0xF)) { + SET_Z(); + } else { + CLEAR_Z(); + } } -static void op_adc_xl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; +static void op_adc_xl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; - tmp = XL + arg0 + C; - x = (tmp & 0xF) | (XH << 4) | (XP << 8); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!(tmp & 0xF)) { SET_Z(); } else { CLEAR_Z(); } + tmp = XL + arg0 + C; + x = (tmp & 0xF) | (XH << 4) | (XP << 8); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!(tmp & 0xF)) { + SET_Z(); + } else { + CLEAR_Z(); + } } -static void op_adc_yh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; +static void op_adc_yh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; - tmp = YH + arg0 + C; - y = YL | ((tmp & 0xF) << 4)| (YP << 8); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!(tmp & 0xF)) { SET_Z(); } else { CLEAR_Z(); } + tmp = YH + arg0 + C; + y = YL | ((tmp & 0xF) << 4) | (YP << 8); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!(tmp & 0xF)) { + SET_Z(); + } else { + CLEAR_Z(); + } } -static void op_adc_yl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; +static void op_adc_yl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; - tmp = YL + arg0 + C; - y = (tmp & 0xF) | (YH << 4) | (YP << 8); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!(tmp & 0xF)) { SET_Z(); } else { CLEAR_Z(); } + tmp = YL + arg0 + C; + y = (tmp & 0xF) | (YH << 4) | (YP << 8); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!(tmp & 0xF)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_cp_xh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(XH < arg0) { + SET_C(); + } else { + CLEAR_C(); + } + if(XH == arg0) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_cp_xl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(XL < arg0) { + SET_C(); + } else { + CLEAR_C(); + } + if(XL == arg0) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_cp_yh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(YH < arg0) { + SET_C(); + } else { + CLEAR_C(); + } + if(YH == arg0) { + SET_Z(); + } else { + CLEAR_Z(); + } } -static void op_cp_xh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (XH < arg0) { SET_C(); } else { CLEAR_C(); } - if (XH == arg0) { SET_Z(); } else { CLEAR_Z(); } +static void op_cp_yl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + if(YL < arg0) { + SET_C(); + } else { + CLEAR_C(); + } + if(YL == arg0) { + SET_Z(); + } else { + CLEAR_Z(); + } } -static void op_cp_xl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (XL < arg0) { SET_C(); } else { CLEAR_C(); } - if (XL == arg0) { SET_Z(); } else { CLEAR_Z(); } +static void op_ld_r_i_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, arg1); } -static void op_cp_yh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (YH < arg0) { SET_C(); } else { CLEAR_C(); } - if (YH == arg0) { SET_Z(); } else { CLEAR_Z(); } +static void op_ld_r_q_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg1)); } -static void op_cp_yl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - if (YL < arg0) { SET_C(); } else { CLEAR_C(); } - if (YL == arg0) { SET_Z(); } else { CLEAR_Z(); } +static void op_ld_a_mn_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + a = M(arg0); } -static void op_ld_r_i_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, arg1); +static void op_ld_b_mn_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + b = M(arg0); } -static void op_ld_r_q_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg1)); +static void op_ld_mn_a_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_M(arg0, a); } -static void op_ld_a_mn_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - a = M(arg0); +static void op_ld_mn_b_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_M(arg0, b); } -static void op_ld_b_mn_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - b = M(arg0); +static void op_ldpx_mx_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_M(x, arg0); + x = ((x + 1) & 0xFF) | (XP << 8); } -static void op_ld_mn_a_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_M(arg0, a); +static void op_ldpx_r_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg1)); + x = ((x + 1) & 0xFF) | (XP << 8); } -static void op_ld_mn_b_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_M(arg0, b); +static void op_ldpy_my_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_M(y, arg0); + y = ((y + 1) & 0xFF) | (YP << 8); } -static void op_ldpx_mx_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_M(x, arg0); - x = ((x + 1) & 0xFF) | (XP << 8); +static void op_ldpy_r_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg1)); + y = ((y + 1) & 0xFF) | (YP << 8); } -static void op_ldpx_r_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg1)); - x = ((x + 1) & 0xFF) | (XP << 8); +static void op_lbpx_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_M(x, arg0 & 0xF); + SET_M(x + 1, (arg0 >> 4) & 0xF); + x = ((x + 2) & 0xFF) | (XP << 8); } -static void op_ldpy_my_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_M(y, arg0); - y = ((y + 1) & 0xFF) | (YP << 8); +static void op_set_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + flags |= arg0; } -static void op_ldpy_r_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg1)); - y = ((y + 1) & 0xFF) | (YP << 8); +static void op_rst_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + flags &= arg0; } -static void op_lbpx_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_M(x, arg0 & 0xF); - SET_M(x + 1, (arg0 >> 4) & 0xF); - x = ((x + 2) & 0xFF) | (XP << 8); +static void op_scf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + SET_C(); } -static void op_set_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - flags |= arg0; +static void op_rcf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + CLEAR_C(); } -static void op_rst_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - flags &= arg0; +static void op_szf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + SET_Z(); } -static void op_scf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - SET_C(); +static void op_rzf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + CLEAR_Z(); } -static void op_rcf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - CLEAR_C(); +static void op_sdf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + SET_D(); } -static void op_szf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - SET_Z(); +static void op_rdf_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + CLEAR_D(); } -static void op_rzf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - CLEAR_Z(); +static void op_ei_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + SET_I(); } -static void op_sdf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - SET_D(); +static void op_di_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + CLEAR_I(); } -static void op_rdf_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - CLEAR_D(); +static void op_inc_sp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp + 1) & 0xFF; } -static void op_ei_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - SET_I(); +static void op_dec_sp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; } -static void op_di_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - CLEAR_I(); +static void op_push_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, RQ(arg0)); } -static void op_inc_sp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp + 1) & 0xFF; +static void op_push_xp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, XP); } -static void op_dec_sp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; +static void op_push_xh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, XH); } -static void op_push_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, RQ(arg0)); +static void op_push_xl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, XL); } -static void op_push_xp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, XP); +static void op_push_yp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, YP); } -static void op_push_xh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, XH); +static void op_push_yh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, YH); } -static void op_push_xl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, XL); +static void op_push_yl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, YL); } -static void op_push_yp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, YP); +static void op_push_f_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + sp = (sp - 1) & 0xFF; + SET_M(sp, flags); } -static void op_push_yh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, YH); +static void op_pop_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, M(sp)); + sp = (sp + 1) & 0xFF; } -static void op_push_yl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, YL); +static void op_pop_xp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + x = XL | (XH << 4) | (M(sp) << 8); + sp = (sp + 1) & 0xFF; } -static void op_push_f_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - sp = (sp - 1) & 0xFF; - SET_M(sp, flags); +static void op_pop_xh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + x = XL | (M(sp) << 4) | (XP << 8); + sp = (sp + 1) & 0xFF; } -static void op_pop_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, M(sp)); - sp = (sp + 1) & 0xFF; +static void op_pop_xl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + x = M(sp) | (XH << 4) | (XP << 8); + sp = (sp + 1) & 0xFF; } -static void op_pop_xp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - x = XL | (XH << 4)| (M(sp) << 8); - sp = (sp + 1) & 0xFF; +static void op_pop_yp_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + y = YL | (YH << 4) | (M(sp) << 8); + sp = (sp + 1) & 0xFF; } -static void op_pop_xh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - x = XL | (M(sp) << 4)| (XP << 8); - sp = (sp + 1) & 0xFF; -} - -static void op_pop_xl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - x = M(sp) | (XH << 4)| (XP << 8); - sp = (sp + 1) & 0xFF; -} - -static void op_pop_yp_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - y = YL | (YH << 4)| (M(sp) << 8); - sp = (sp + 1) & 0xFF; -} - -static void op_pop_yh_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - y = YL | (M(sp) << 4)| (YP << 8); - sp = (sp + 1) & 0xFF; -} - -static void op_pop_yl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - y = M(sp) | (YH << 4)| (YP << 8); - sp = (sp + 1) & 0xFF; -} - -static void op_pop_f_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg0); - UNUSED(arg1); - flags = M(sp); - sp = (sp + 1) & 0xFF; -} - -static void op_ld_sph_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - sp = SPL | (RQ(arg0) << 4); -} - -static void op_ld_spl_r_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - sp = RQ(arg0) | (SPH << 4); -} - -static void op_ld_r_sph_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, SPH); -} - -static void op_ld_r_spl_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, SPL); -} - -static void op_add_r_i_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) + arg1; - if (D) { - if (tmp >= 10) { - SET_RQ(arg0, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_RQ(arg0, tmp); - CLEAR_C(); - } - } else { - SET_RQ(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_add_r_q_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) + RQ(arg1); - if (D) { - if (tmp >= 10) { - SET_RQ(arg0, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_RQ(arg0, tmp); - CLEAR_C(); - } - } else { - SET_RQ(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_adc_r_i_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) + arg1 + C; - if (D) { - if (tmp >= 10) { - SET_RQ(arg0, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_RQ(arg0, tmp); - CLEAR_C(); - } - } else { - SET_RQ(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_adc_r_q_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) + RQ(arg1) + C; - if (D) { - if (tmp >= 10) { - SET_RQ(arg0, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_RQ(arg0, tmp); - CLEAR_C(); - } - } else { - SET_RQ(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_sub_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) - RQ(arg1); - if (D) { - if (tmp >> 4) { - SET_RQ(arg0, (tmp - 6) & 0xF); - } else { - SET_RQ(arg0, tmp); - } - } else { - SET_RQ(arg0, tmp & 0xF); - } - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_sbc_r_i_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) - arg1 - C; - if (D) { - if (tmp >> 4) { - SET_RQ(arg0, (tmp - 6) & 0xF); - } else { - SET_RQ(arg0, tmp); - } - } else { - SET_RQ(arg0, tmp & 0xF); - } - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_sbc_r_q_cb(u8_t arg0, u8_t arg1) -{ - u8_t tmp; - - tmp = RQ(arg0) - RQ(arg1) - C; - if (D) { - if (tmp >> 4) { - SET_RQ(arg0, (tmp - 6) & 0xF); - } else { - SET_RQ(arg0, tmp); - } - } else { - SET_RQ(arg0, tmp & 0xF); - } - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_and_r_i_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) & arg1); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_and_r_q_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) & RQ(arg1)); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_or_r_i_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) | arg1); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_or_r_q_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) | RQ(arg1)); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_xor_r_i_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) ^ arg1); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_xor_r_q_cb(u8_t arg0, u8_t arg1) -{ - SET_RQ(arg0, RQ(arg0) ^ RQ(arg1)); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_cp_r_i_cb(u8_t arg0, u8_t arg1) -{ - if (RQ(arg0) < arg1) { SET_C(); } else { CLEAR_C(); } - if (RQ(arg0) == arg1) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_cp_r_q_cb(u8_t arg0, u8_t arg1) -{ - if (RQ(arg0) < RQ(arg1)) { SET_C(); } else { CLEAR_C(); } - if (RQ(arg0) == RQ(arg1)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_fan_r_i_cb(u8_t arg0, u8_t arg1) -{ - if (!(RQ(arg0) & arg1)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_fan_r_q_cb(u8_t arg0, u8_t arg1) -{ - if (!(RQ(arg0) & RQ(arg1))) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_rlc_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = (RQ(arg0) << 1) | C; - if (RQ(arg0) & 0x8) { SET_C(); } else { CLEAR_C(); } - SET_RQ(arg0, tmp & 0xF); - /* No need to set Z (issue in DS) */ -} - -static void op_rrc_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = (RQ(arg0) >> 1) | (C << 3); - if (RQ(arg0) & 0x1) { SET_C(); } else { CLEAR_C(); } - SET_RQ(arg0, tmp & 0xF); - /* No need to set Z (issue in DS) */ -} - -static void op_inc_mn_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(arg0) + 1; - SET_M(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!M(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_dec_mn_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(arg0) - 1; - SET_M(arg0, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!M(arg0)) { SET_Z(); } else { CLEAR_Z(); } -} - -static void op_acpx_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(x) + RQ(arg0) + C; - if (D) { - if (tmp >= 10) { - SET_M(x, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_M(x, tmp); - CLEAR_C(); - } - } else { - SET_M(x, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!M(x)) { SET_Z(); } else { CLEAR_Z(); } - x = ((x + 1) & 0xFF) | (XP << 8); -} - -static void op_acpy_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(y) + RQ(arg0) + C; - if (D) { - if (tmp >= 10) { - SET_M(y, (tmp - 10) & 0xF); - SET_C(); - } else { - SET_M(y, tmp); - CLEAR_C(); - } - } else { - SET_M(y, tmp & 0xF); - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - } - if (!M(y)) { SET_Z(); } else { CLEAR_Z(); } - y = ((y + 1) & 0xFF) | (YP << 8); -} - -static void op_scpx_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(x) - RQ(arg0) - C; - if (D) { - if (tmp >> 4) { - SET_M(x, (tmp - 6) & 0xF); - } else { - SET_M(x, tmp); - } - } else { - SET_M(x, tmp & 0xF); - } - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!M(x)) { SET_Z(); } else { CLEAR_Z(); } - x = ((x + 1) & 0xFF) | (XP << 8); -} - -static void op_scpy_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - u8_t tmp; - - tmp = M(y) - RQ(arg0) - C; - if (D) { - if (tmp >> 4) { - SET_M(y, (tmp - 6) & 0xF); - } else { - SET_M(y, tmp); - } - } else { - SET_M(y, tmp & 0xF); - } - if (tmp >> 4) { SET_C(); } else { CLEAR_C(); } - if (!M(y)) { SET_Z(); } else { CLEAR_Z(); } - y = ((y + 1) & 0xFF) | (YP << 8); -} - -static void op_not_cb(u8_t arg0, u8_t arg1) -{ - UNUSED(arg1); - SET_RQ(arg0, ~RQ(arg0) & 0xF); - if (!RQ(arg0)) { SET_Z(); } else { CLEAR_Z(); } +static void op_pop_yh_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + y = YL | (M(sp) << 4) | (YP << 8); + sp = (sp + 1) & 0xFF; +} + +static void op_pop_yl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + y = M(sp) | (YH << 4) | (YP << 8); + sp = (sp + 1) & 0xFF; +} + +static void op_pop_f_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg0); + UNUSED(arg1); + flags = M(sp); + sp = (sp + 1) & 0xFF; +} + +static void op_ld_sph_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + sp = SPL | (RQ(arg0) << 4); +} + +static void op_ld_spl_r_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + sp = RQ(arg0) | (SPH << 4); +} + +static void op_ld_r_sph_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, SPH); +} + +static void op_ld_r_spl_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, SPL); +} + +static void op_add_r_i_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) + arg1; + if(D) { + if(tmp >= 10) { + SET_RQ(arg0, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_RQ(arg0, tmp); + CLEAR_C(); + } + } else { + SET_RQ(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_add_r_q_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) + RQ(arg1); + if(D) { + if(tmp >= 10) { + SET_RQ(arg0, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_RQ(arg0, tmp); + CLEAR_C(); + } + } else { + SET_RQ(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_adc_r_i_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) + arg1 + C; + if(D) { + if(tmp >= 10) { + SET_RQ(arg0, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_RQ(arg0, tmp); + CLEAR_C(); + } + } else { + SET_RQ(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_adc_r_q_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) + RQ(arg1) + C; + if(D) { + if(tmp >= 10) { + SET_RQ(arg0, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_RQ(arg0, tmp); + CLEAR_C(); + } + } else { + SET_RQ(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_sub_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) - RQ(arg1); + if(D) { + if(tmp >> 4) { + SET_RQ(arg0, (tmp - 6) & 0xF); + } else { + SET_RQ(arg0, tmp); + } + } else { + SET_RQ(arg0, tmp & 0xF); + } + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_sbc_r_i_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) - arg1 - C; + if(D) { + if(tmp >> 4) { + SET_RQ(arg0, (tmp - 6) & 0xF); + } else { + SET_RQ(arg0, tmp); + } + } else { + SET_RQ(arg0, tmp & 0xF); + } + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_sbc_r_q_cb(u8_t arg0, u8_t arg1) { + u8_t tmp; + + tmp = RQ(arg0) - RQ(arg1) - C; + if(D) { + if(tmp >> 4) { + SET_RQ(arg0, (tmp - 6) & 0xF); + } else { + SET_RQ(arg0, tmp); + } + } else { + SET_RQ(arg0, tmp & 0xF); + } + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_and_r_i_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) & arg1); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_and_r_q_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) & RQ(arg1)); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_or_r_i_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) | arg1); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_or_r_q_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) | RQ(arg1)); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_xor_r_i_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) ^ arg1); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_xor_r_q_cb(u8_t arg0, u8_t arg1) { + SET_RQ(arg0, RQ(arg0) ^ RQ(arg1)); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_cp_r_i_cb(u8_t arg0, u8_t arg1) { + if(RQ(arg0) < arg1) { + SET_C(); + } else { + CLEAR_C(); + } + if(RQ(arg0) == arg1) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_cp_r_q_cb(u8_t arg0, u8_t arg1) { + if(RQ(arg0) < RQ(arg1)) { + SET_C(); + } else { + CLEAR_C(); + } + if(RQ(arg0) == RQ(arg1)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_fan_r_i_cb(u8_t arg0, u8_t arg1) { + if(!(RQ(arg0) & arg1)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_fan_r_q_cb(u8_t arg0, u8_t arg1) { + if(!(RQ(arg0) & RQ(arg1))) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_rlc_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = (RQ(arg0) << 1) | C; + if(RQ(arg0) & 0x8) { + SET_C(); + } else { + CLEAR_C(); + } + SET_RQ(arg0, tmp & 0xF); + /* No need to set Z (issue in DS) */ +} + +static void op_rrc_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = (RQ(arg0) >> 1) | (C << 3); + if(RQ(arg0) & 0x1) { + SET_C(); + } else { + CLEAR_C(); + } + SET_RQ(arg0, tmp & 0xF); + /* No need to set Z (issue in DS) */ +} + +static void op_inc_mn_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(arg0) + 1; + SET_M(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!M(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_dec_mn_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(arg0) - 1; + SET_M(arg0, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!M(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } +} + +static void op_acpx_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(x) + RQ(arg0) + C; + if(D) { + if(tmp >= 10) { + SET_M(x, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_M(x, tmp); + CLEAR_C(); + } + } else { + SET_M(x, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!M(x)) { + SET_Z(); + } else { + CLEAR_Z(); + } + x = ((x + 1) & 0xFF) | (XP << 8); +} + +static void op_acpy_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(y) + RQ(arg0) + C; + if(D) { + if(tmp >= 10) { + SET_M(y, (tmp - 10) & 0xF); + SET_C(); + } else { + SET_M(y, tmp); + CLEAR_C(); + } + } else { + SET_M(y, tmp & 0xF); + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + } + if(!M(y)) { + SET_Z(); + } else { + CLEAR_Z(); + } + y = ((y + 1) & 0xFF) | (YP << 8); +} + +static void op_scpx_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(x) - RQ(arg0) - C; + if(D) { + if(tmp >> 4) { + SET_M(x, (tmp - 6) & 0xF); + } else { + SET_M(x, tmp); + } + } else { + SET_M(x, tmp & 0xF); + } + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!M(x)) { + SET_Z(); + } else { + CLEAR_Z(); + } + x = ((x + 1) & 0xFF) | (XP << 8); +} + +static void op_scpy_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + u8_t tmp; + + tmp = M(y) - RQ(arg0) - C; + if(D) { + if(tmp >> 4) { + SET_M(y, (tmp - 6) & 0xF); + } else { + SET_M(y, tmp); + } + } else { + SET_M(y, tmp & 0xF); + } + if(tmp >> 4) { + SET_C(); + } else { + CLEAR_C(); + } + if(!M(y)) { + SET_Z(); + } else { + CLEAR_Z(); + } + y = ((y + 1) & 0xFF) | (YP << 8); +} + +static void op_not_cb(u8_t arg0, u8_t arg1) { + UNUSED(arg1); + SET_RQ(arg0, ~RQ(arg0) & 0xF); + if(!RQ(arg0)) { + SET_Z(); + } else { + CLEAR_Z(); + } } /* The E0C6S46 supported instructions */ static const op_t ops[] = { - {"PSET #0x%02X " , 0xE40, MASK_7B , 0, 0 , 5 , &op_pset_cb}, // PSET - {"JP #0x%02X " , 0x000, MASK_4B , 0, 0 , 5 , &op_jp_cb}, // JP - {"JP C #0x%02X " , 0x200, MASK_4B , 0, 0 , 5 , &op_jp_c_cb}, // JP_C - {"JP NC #0x%02X " , 0x300, MASK_4B , 0, 0 , 5 , &op_jp_nc_cb}, // JP_NC - {"JP Z #0x%02X " , 0x600, MASK_4B , 0, 0 , 5 , &op_jp_z_cb}, // JP_Z - {"JP NZ #0x%02X " , 0x700, MASK_4B , 0, 0 , 5 , &op_jp_nz_cb}, // JP_NZ - {"JPBA " , 0xFE8, MASK_12B, 0, 0 , 5 , &op_jpba_cb}, // JPBA - {"CALL #0x%02X " , 0x400, MASK_4B , 0, 0 , 7 , &op_call_cb}, // CALL - {"CALZ #0x%02X " , 0x500, MASK_4B , 0, 0 , 7 , &op_calz_cb}, // CALZ - {"RET " , 0xFDF, MASK_12B, 0, 0 , 7 , &op_ret_cb}, // RET - {"RETS " , 0xFDE, MASK_12B, 0, 0 , 12, &op_rets_cb}, // RETS - {"RETD #0x%02X " , 0x100, MASK_4B , 0, 0 , 12, &op_retd_cb}, // RETD - {"NOP5 " , 0xFFB, MASK_12B, 0, 0 , 5 , &op_nop5_cb}, // NOP5 - {"NOP7 " , 0xFFF, MASK_12B, 0, 0 , 7 , &op_nop7_cb}, // NOP7 - {"HALT " , 0xFF8, MASK_12B, 0, 0 , 5 , &op_halt_cb}, // HALT - {"INC X #0x%02X " , 0xEE0, MASK_12B, 0, 0 , 5 , &op_inc_x_cb}, // INC_X - {"INC Y #0x%02X " , 0xEF0, MASK_12B, 0, 0 , 5 , &op_inc_y_cb}, // INC_Y - {"LD X #0x%02X " , 0xB00, MASK_4B , 0, 0 , 5 , &op_ld_x_cb}, // LD_X - {"LD Y #0x%02X " , 0x800, MASK_4B , 0, 0 , 5 , &op_ld_y_cb}, // LD_Y - {"LD XP R(#0x%02X) " , 0xE80, MASK_10B, 0, 0 , 5 , &op_ld_xp_r_cb}, // LD_XP_R - {"LD XH R(#0x%02X) " , 0xE84, MASK_10B, 0, 0 , 5 , &op_ld_xh_r_cb}, // LD_XH_R - {"LD XL R(#0x%02X) " , 0xE88, MASK_10B, 0, 0 , 5 , &op_ld_xl_r_cb}, // LD_XL_R - {"LD YP R(#0x%02X) " , 0xE90, MASK_10B, 0, 0 , 5 , &op_ld_yp_r_cb}, // LD_YP_R - {"LD YH R(#0x%02X) " , 0xE94, MASK_10B, 0, 0 , 5 , &op_ld_yh_r_cb}, // LD_YH_R - {"LD YL R(#0x%02X) " , 0xE98, MASK_10B, 0, 0 , 5 , &op_ld_yl_r_cb}, // LD_YL_R - {"LD R(#0x%02X) XP " , 0xEA0, MASK_10B, 0, 0 , 5 , &op_ld_r_xp_cb}, // LD_R_XP - {"LD R(#0x%02X) XH " , 0xEA4, MASK_10B, 0, 0 , 5 , &op_ld_r_xh_cb}, // LD_R_XH - {"LD R(#0x%02X) XL " , 0xEA8, MASK_10B, 0, 0 , 5 , &op_ld_r_xl_cb}, // LD_R_XL - {"LD R(#0x%02X) YP " , 0xEB0, MASK_10B, 0, 0 , 5 , &op_ld_r_yp_cb}, // LD_R_YP - {"LD R(#0x%02X) YH " , 0xEB4, MASK_10B, 0, 0 , 5 , &op_ld_r_yh_cb}, // LD_R_YH - {"LD R(#0x%02X) YL " , 0xEB8, MASK_10B, 0, 0 , 5 , &op_ld_r_yl_cb}, // LD_R_YL - {"ADC XH #0x%02X " , 0xA00, MASK_8B , 0, 0 , 7 , &op_adc_xh_cb}, // ADC_XH - {"ADC XL #0x%02X " , 0xA10, MASK_8B , 0, 0 , 7 , &op_adc_xl_cb}, // ADC_XL - {"ADC YH #0x%02X " , 0xA20, MASK_8B , 0, 0 , 7 , &op_adc_yh_cb}, // ADC_YH - {"ADC YL #0x%02X " , 0xA30, MASK_8B , 0, 0 , 7 , &op_adc_yl_cb}, // ADC_YL - {"CP XH #0x%02X " , 0xA40, MASK_8B , 0, 0 , 7 , &op_cp_xh_cb}, // CP_XH - {"CP XL #0x%02X " , 0xA50, MASK_8B , 0, 0 , 7 , &op_cp_xl_cb}, // CP_XL - {"CP YH #0x%02X " , 0xA60, MASK_8B , 0, 0 , 7 , &op_cp_yh_cb}, // CP_YH - {"CP YL #0x%02X " , 0xA70, MASK_8B , 0, 0 , 7 , &op_cp_yl_cb}, // CP_YL - {"LD R(#0x%02X) #0x%02X ", 0xE00, MASK_6B , 4, 0x030, 5 , &op_ld_r_i_cb}, // LD_R_I - {"LD R(#0x%02X) Q(#0x%02X)", 0xEC0, MASK_8B , 2, 0x00C, 5 , &op_ld_r_q_cb}, // LD_R_Q - {"LD A M(#0x%02X) " , 0xFA0, MASK_8B , 0, 0 , 5 , &op_ld_a_mn_cb}, // LD_A_MN - {"LD B M(#0x%02X) " , 0xFB0, MASK_8B , 0, 0 , 5 , &op_ld_b_mn_cb}, // LD_B_MN - {"LD M(#0x%02X) A " , 0xF80, MASK_8B , 0, 0 , 5 , &op_ld_mn_a_cb}, // LD_MN_A - {"LD M(#0x%02X) B " , 0xF90, MASK_8B , 0, 0 , 5 , &op_ld_mn_b_cb}, // LD_MN_B - {"LDPX MX #0x%02X " , 0xE60, MASK_8B , 0, 0 , 5 , &op_ldpx_mx_cb}, // LDPX_MX - {"LDPX R(#0x%02X) Q(#0x%02X)", 0xEE0, MASK_8B , 2, 0x00C, 5 , &op_ldpx_r_cb}, // LDPX_R - {"LDPY MY #0x%02X " , 0xE70, MASK_8B , 0, 0 , 5 , &op_ldpy_my_cb}, // LDPY_MY - {"LDPY R(#0x%02X) Q(#0x%02X)", 0xEF0, MASK_8B , 2, 0x00C, 5 , &op_ldpy_r_cb}, // LDPY_R - {"LBPX #0x%02X " , 0x900, MASK_4B , 0, 0 , 5 , &op_lbpx_cb}, // LBPX - {"SET #0x%02X " , 0xF40, MASK_8B , 0, 0 , 7 , &op_set_cb}, // SET - {"RST #0x%02X " , 0xF50, MASK_8B , 0, 0 , 7 , &op_rst_cb}, // RST - {"SCF " , 0xF41, MASK_12B, 0, 0 , 7 , &op_scf_cb}, // SCF - {"RCF " , 0xF5E, MASK_12B, 0, 0 , 7 , &op_rcf_cb}, // RCF - {"SZF " , 0xF42, MASK_12B, 0, 0 , 7 , &op_szf_cb}, // SZF - {"RZF " , 0xF5D, MASK_12B, 0, 0 , 7 , &op_rzf_cb}, // RZF - {"SDF " , 0xF44, MASK_12B, 0, 0 , 7 , &op_sdf_cb}, // SDF - {"RDF " , 0xF5B, MASK_12B, 0, 0 , 7 , &op_rdf_cb}, // RDF - {"EI " , 0xF48, MASK_12B, 0, 0 , 7 , &op_ei_cb}, // EI - {"DI " , 0xF57, MASK_12B, 0, 0 , 7 , &op_di_cb}, // DI - {"INC SP " , 0xFDB, MASK_12B, 0, 0 , 5 , &op_inc_sp_cb}, // INC_SP - {"DEC SP " , 0xFCB, MASK_12B, 0, 0 , 5 , &op_dec_sp_cb}, // DEC_SP - {"PUSH R(#0x%02X) " , 0xFC0, MASK_10B, 0, 0 , 5 , &op_push_r_cb}, // PUSH_R - {"PUSH XP " , 0xFC4, MASK_12B, 0, 0 , 5 , &op_push_xp_cb}, // PUSH_XP - {"PUSH XH " , 0xFC5, MASK_12B, 0, 0 , 5 , &op_push_xh_cb}, // PUSH_XH - {"PUSH XL " , 0xFC6, MASK_12B, 0, 0 , 5 , &op_push_xl_cb}, // PUSH_XL - {"PUSH YP " , 0xFC7, MASK_12B, 0, 0 , 5 , &op_push_yp_cb}, // PUSH_YP - {"PUSH YH " , 0xFC8, MASK_12B, 0, 0 , 5 , &op_push_yh_cb}, // PUSH_YH - {"PUSH YL " , 0xFC9, MASK_12B, 0, 0 , 5 , &op_push_yl_cb}, // PUSH_YL - {"PUSH F " , 0xFCA, MASK_12B, 0, 0 , 5 , &op_push_f_cb}, // PUSH_F - {"POP R(#0x%02X) " , 0xFD0, MASK_10B, 0, 0 , 5 , &op_pop_r_cb}, // POP_R - {"POP XP " , 0xFD4, MASK_12B, 0, 0 , 5 , &op_pop_xp_cb}, // POP_XP - {"POP XH " , 0xFD5, MASK_12B, 0, 0 , 5 , &op_pop_xh_cb}, // POP_XH - {"POP XL " , 0xFD6, MASK_12B, 0, 0 , 5 , &op_pop_xl_cb}, // POP_XL - {"POP YP " , 0xFD7, MASK_12B, 0, 0 , 5 , &op_pop_yp_cb}, // POP_YP - {"POP YH " , 0xFD8, MASK_12B, 0, 0 , 5 , &op_pop_yh_cb}, // POP_YH - {"POP YL " , 0xFD9, MASK_12B, 0, 0 , 5 , &op_pop_yl_cb}, // POP_YL - {"POP F " , 0xFDA, MASK_12B, 0, 0 , 5 , &op_pop_f_cb}, // POP_F - {"LD SPH R(#0x%02X) " , 0xFE0, MASK_10B, 0, 0 , 5 , &op_ld_sph_r_cb}, // LD_SPH_R - {"LD SPL R(#0x%02X) " , 0xFF0, MASK_10B, 0, 0 , 5 , &op_ld_spl_r_cb}, // LD_SPL_R - {"LD R(#0x%02X) SPH " , 0xFE4, MASK_10B, 0, 0 , 5 , &op_ld_r_sph_cb}, // LD_R_SPH - {"LD R(#0x%02X) SPL " , 0xFF4, MASK_10B, 0, 0 , 5 , &op_ld_r_spl_cb}, // LD_R_SPL - {"ADD R(#0x%02X) #0x%02X ", 0xC00, MASK_6B , 4, 0x030, 7 , &op_add_r_i_cb}, // ADD_R_I - {"ADD R(#0x%02X) Q(#0x%02X)", 0xA80, MASK_8B , 2, 0x00C, 7 , &op_add_r_q_cb}, // ADD_R_Q - {"ADC R(#0x%02X) #0x%02X ", 0xC40, MASK_6B , 4, 0x030, 7 , &op_adc_r_i_cb}, // ADC_R_I - {"ADC R(#0x%02X) Q(#0x%02X)", 0xA90, MASK_8B , 2, 0x00C, 7 , &op_adc_r_q_cb}, // ADC_R_Q - {"SUB R(#0x%02X) Q(#0x%02X)", 0xAA0, MASK_8B , 2, 0x00C, 7 , &op_sub_cb}, // SUB - {"SBC R(#0x%02X) #0x%02X ", 0xB40, MASK_6B , 4, 0x030, 7 , &op_sbc_r_i_cb}, // SBC_R_I - {"SBC R(#0x%02X) Q(#0x%02X)", 0xAB0, MASK_8B , 2, 0x00C, 7 , &op_sbc_r_q_cb}, // SBC_R_Q - {"AND R(#0x%02X) #0x%02X ", 0xC80, MASK_6B , 4, 0x030, 7 , &op_and_r_i_cb}, // AND_R_I - {"AND R(#0x%02X) Q(#0x%02X)", 0xAC0, MASK_8B , 2, 0x00C, 7 , &op_and_r_q_cb}, // AND_R_Q - {"OR R(#0x%02X) #0x%02X ", 0xCC0, MASK_6B , 4, 0x030, 7 , &op_or_r_i_cb}, // OR_R_I - {"OR R(#0x%02X) Q(#0x%02X)", 0xAD0, MASK_8B , 2, 0x00C, 7 , &op_or_r_q_cb}, // OR_R_Q - {"XOR R(#0x%02X) #0x%02X ", 0xD00, MASK_6B , 4, 0x030, 7 , &op_xor_r_i_cb}, // XOR_R_I - {"XOR R(#0x%02X) Q(#0x%02X)", 0xAE0, MASK_8B , 2, 0x00C, 7 , &op_xor_r_q_cb}, // XOR_R_Q - {"CP R(#0x%02X) #0x%02X ", 0xDC0, MASK_6B , 4, 0x030, 7 , &op_cp_r_i_cb}, // CP_R_I - {"CP R(#0x%02X) Q(#0x%02X)", 0xF00, MASK_8B , 2, 0x00C, 7 , &op_cp_r_q_cb}, // CP_R_Q - {"FAN R(#0x%02X) #0x%02X ", 0xD80, MASK_6B , 4, 0x030, 7 , &op_fan_r_i_cb}, // FAN_R_I - {"FAN R(#0x%02X) Q(#0x%02X)", 0xF10, MASK_8B , 2, 0x00C, 7 , &op_fan_r_q_cb}, // FAN_R_Q - {"RLC R(#0x%02X) " , 0xAF0, MASK_8B , 0, 0 , 7 , &op_rlc_cb}, // RLC - {"RRC R(#0x%02X) " , 0xE8C, MASK_10B, 0, 0 , 5 , &op_rrc_cb}, // RRC - {"INC M(#0x%02X) " , 0xF60, MASK_8B , 0, 0 , 7 , &op_inc_mn_cb}, // INC_MN - {"DEC M(#0x%02X) " , 0xF70, MASK_8B , 0, 0 , 7 , &op_dec_mn_cb}, // DEC_MN - {"ACPX R(#0x%02X) " , 0xF28, MASK_10B, 0, 0 , 7 , &op_acpx_cb}, // ACPX - {"ACPY R(#0x%02X) " , 0xF2C, MASK_10B, 0, 0 , 7 , &op_acpy_cb}, // ACPY - {"SCPX R(#0x%02X) " , 0xF38, MASK_10B, 0, 0 , 7 , &op_scpx_cb}, // SCPX - {"SCPY R(#0x%02X) " , 0xF3C, MASK_10B, 0, 0 , 7 , &op_scpy_cb}, // SCPY - {"NOT R(#0x%02X) " , 0xD0F, 0xFCF , 4, 0 , 7 , &op_not_cb}, // NOT + {"PSET #0x%02X ", 0xE40, MASK_7B, 0, 0, 5, &op_pset_cb}, // PSET + {"JP #0x%02X ", 0x000, MASK_4B, 0, 0, 5, &op_jp_cb}, // JP + {"JP C #0x%02X ", 0x200, MASK_4B, 0, 0, 5, &op_jp_c_cb}, // JP_C + {"JP NC #0x%02X ", 0x300, MASK_4B, 0, 0, 5, &op_jp_nc_cb}, // JP_NC + {"JP Z #0x%02X ", 0x600, MASK_4B, 0, 0, 5, &op_jp_z_cb}, // JP_Z + {"JP NZ #0x%02X ", 0x700, MASK_4B, 0, 0, 5, &op_jp_nz_cb}, // JP_NZ + {"JPBA ", 0xFE8, MASK_12B, 0, 0, 5, &op_jpba_cb}, // JPBA + {"CALL #0x%02X ", 0x400, MASK_4B, 0, 0, 7, &op_call_cb}, // CALL + {"CALZ #0x%02X ", 0x500, MASK_4B, 0, 0, 7, &op_calz_cb}, // CALZ + {"RET ", 0xFDF, MASK_12B, 0, 0, 7, &op_ret_cb}, // RET + {"RETS ", 0xFDE, MASK_12B, 0, 0, 12, &op_rets_cb}, // RETS + {"RETD #0x%02X ", 0x100, MASK_4B, 0, 0, 12, &op_retd_cb}, // RETD + {"NOP5 ", 0xFFB, MASK_12B, 0, 0, 5, &op_nop5_cb}, // NOP5 + {"NOP7 ", 0xFFF, MASK_12B, 0, 0, 7, &op_nop7_cb}, // NOP7 + {"HALT ", 0xFF8, MASK_12B, 0, 0, 5, &op_halt_cb}, // HALT + {"INC X #0x%02X ", 0xEE0, MASK_12B, 0, 0, 5, &op_inc_x_cb}, // INC_X + {"INC Y #0x%02X ", 0xEF0, MASK_12B, 0, 0, 5, &op_inc_y_cb}, // INC_Y + {"LD X #0x%02X ", 0xB00, MASK_4B, 0, 0, 5, &op_ld_x_cb}, // LD_X + {"LD Y #0x%02X ", 0x800, MASK_4B, 0, 0, 5, &op_ld_y_cb}, // LD_Y + {"LD XP R(#0x%02X) ", 0xE80, MASK_10B, 0, 0, 5, &op_ld_xp_r_cb}, // LD_XP_R + {"LD XH R(#0x%02X) ", 0xE84, MASK_10B, 0, 0, 5, &op_ld_xh_r_cb}, // LD_XH_R + {"LD XL R(#0x%02X) ", 0xE88, MASK_10B, 0, 0, 5, &op_ld_xl_r_cb}, // LD_XL_R + {"LD YP R(#0x%02X) ", 0xE90, MASK_10B, 0, 0, 5, &op_ld_yp_r_cb}, // LD_YP_R + {"LD YH R(#0x%02X) ", 0xE94, MASK_10B, 0, 0, 5, &op_ld_yh_r_cb}, // LD_YH_R + {"LD YL R(#0x%02X) ", 0xE98, MASK_10B, 0, 0, 5, &op_ld_yl_r_cb}, // LD_YL_R + {"LD R(#0x%02X) XP ", 0xEA0, MASK_10B, 0, 0, 5, &op_ld_r_xp_cb}, // LD_R_XP + {"LD R(#0x%02X) XH ", 0xEA4, MASK_10B, 0, 0, 5, &op_ld_r_xh_cb}, // LD_R_XH + {"LD R(#0x%02X) XL ", 0xEA8, MASK_10B, 0, 0, 5, &op_ld_r_xl_cb}, // LD_R_XL + {"LD R(#0x%02X) YP ", 0xEB0, MASK_10B, 0, 0, 5, &op_ld_r_yp_cb}, // LD_R_YP + {"LD R(#0x%02X) YH ", 0xEB4, MASK_10B, 0, 0, 5, &op_ld_r_yh_cb}, // LD_R_YH + {"LD R(#0x%02X) YL ", 0xEB8, MASK_10B, 0, 0, 5, &op_ld_r_yl_cb}, // LD_R_YL + {"ADC XH #0x%02X ", 0xA00, MASK_8B, 0, 0, 7, &op_adc_xh_cb}, // ADC_XH + {"ADC XL #0x%02X ", 0xA10, MASK_8B, 0, 0, 7, &op_adc_xl_cb}, // ADC_XL + {"ADC YH #0x%02X ", 0xA20, MASK_8B, 0, 0, 7, &op_adc_yh_cb}, // ADC_YH + {"ADC YL #0x%02X ", 0xA30, MASK_8B, 0, 0, 7, &op_adc_yl_cb}, // ADC_YL + {"CP XH #0x%02X ", 0xA40, MASK_8B, 0, 0, 7, &op_cp_xh_cb}, // CP_XH + {"CP XL #0x%02X ", 0xA50, MASK_8B, 0, 0, 7, &op_cp_xl_cb}, // CP_XL + {"CP YH #0x%02X ", 0xA60, MASK_8B, 0, 0, 7, &op_cp_yh_cb}, // CP_YH + {"CP YL #0x%02X ", 0xA70, MASK_8B, 0, 0, 7, &op_cp_yl_cb}, // CP_YL + {"LD R(#0x%02X) #0x%02X ", 0xE00, MASK_6B, 4, 0x030, 5, &op_ld_r_i_cb}, // LD_R_I + {"LD R(#0x%02X) Q(#0x%02X)", 0xEC0, MASK_8B, 2, 0x00C, 5, &op_ld_r_q_cb}, // LD_R_Q + {"LD A M(#0x%02X) ", 0xFA0, MASK_8B, 0, 0, 5, &op_ld_a_mn_cb}, // LD_A_MN + {"LD B M(#0x%02X) ", 0xFB0, MASK_8B, 0, 0, 5, &op_ld_b_mn_cb}, // LD_B_MN + {"LD M(#0x%02X) A ", 0xF80, MASK_8B, 0, 0, 5, &op_ld_mn_a_cb}, // LD_MN_A + {"LD M(#0x%02X) B ", 0xF90, MASK_8B, 0, 0, 5, &op_ld_mn_b_cb}, // LD_MN_B + {"LDPX MX #0x%02X ", 0xE60, MASK_8B, 0, 0, 5, &op_ldpx_mx_cb}, // LDPX_MX + {"LDPX R(#0x%02X) Q(#0x%02X)", 0xEE0, MASK_8B, 2, 0x00C, 5, &op_ldpx_r_cb}, // LDPX_R + {"LDPY MY #0x%02X ", 0xE70, MASK_8B, 0, 0, 5, &op_ldpy_my_cb}, // LDPY_MY + {"LDPY R(#0x%02X) Q(#0x%02X)", 0xEF0, MASK_8B, 2, 0x00C, 5, &op_ldpy_r_cb}, // LDPY_R + {"LBPX #0x%02X ", 0x900, MASK_4B, 0, 0, 5, &op_lbpx_cb}, // LBPX + {"SET #0x%02X ", 0xF40, MASK_8B, 0, 0, 7, &op_set_cb}, // SET + {"RST #0x%02X ", 0xF50, MASK_8B, 0, 0, 7, &op_rst_cb}, // RST + {"SCF ", 0xF41, MASK_12B, 0, 0, 7, &op_scf_cb}, // SCF + {"RCF ", 0xF5E, MASK_12B, 0, 0, 7, &op_rcf_cb}, // RCF + {"SZF ", 0xF42, MASK_12B, 0, 0, 7, &op_szf_cb}, // SZF + {"RZF ", 0xF5D, MASK_12B, 0, 0, 7, &op_rzf_cb}, // RZF + {"SDF ", 0xF44, MASK_12B, 0, 0, 7, &op_sdf_cb}, // SDF + {"RDF ", 0xF5B, MASK_12B, 0, 0, 7, &op_rdf_cb}, // RDF + {"EI ", 0xF48, MASK_12B, 0, 0, 7, &op_ei_cb}, // EI + {"DI ", 0xF57, MASK_12B, 0, 0, 7, &op_di_cb}, // DI + {"INC SP ", 0xFDB, MASK_12B, 0, 0, 5, &op_inc_sp_cb}, // INC_SP + {"DEC SP ", 0xFCB, MASK_12B, 0, 0, 5, &op_dec_sp_cb}, // DEC_SP + {"PUSH R(#0x%02X) ", 0xFC0, MASK_10B, 0, 0, 5, &op_push_r_cb}, // PUSH_R + {"PUSH XP ", 0xFC4, MASK_12B, 0, 0, 5, &op_push_xp_cb}, // PUSH_XP + {"PUSH XH ", 0xFC5, MASK_12B, 0, 0, 5, &op_push_xh_cb}, // PUSH_XH + {"PUSH XL ", 0xFC6, MASK_12B, 0, 0, 5, &op_push_xl_cb}, // PUSH_XL + {"PUSH YP ", 0xFC7, MASK_12B, 0, 0, 5, &op_push_yp_cb}, // PUSH_YP + {"PUSH YH ", 0xFC8, MASK_12B, 0, 0, 5, &op_push_yh_cb}, // PUSH_YH + {"PUSH YL ", 0xFC9, MASK_12B, 0, 0, 5, &op_push_yl_cb}, // PUSH_YL + {"PUSH F ", 0xFCA, MASK_12B, 0, 0, 5, &op_push_f_cb}, // PUSH_F + {"POP R(#0x%02X) ", 0xFD0, MASK_10B, 0, 0, 5, &op_pop_r_cb}, // POP_R + {"POP XP ", 0xFD4, MASK_12B, 0, 0, 5, &op_pop_xp_cb}, // POP_XP + {"POP XH ", 0xFD5, MASK_12B, 0, 0, 5, &op_pop_xh_cb}, // POP_XH + {"POP XL ", 0xFD6, MASK_12B, 0, 0, 5, &op_pop_xl_cb}, // POP_XL + {"POP YP ", 0xFD7, MASK_12B, 0, 0, 5, &op_pop_yp_cb}, // POP_YP + {"POP YH ", 0xFD8, MASK_12B, 0, 0, 5, &op_pop_yh_cb}, // POP_YH + {"POP YL ", 0xFD9, MASK_12B, 0, 0, 5, &op_pop_yl_cb}, // POP_YL + {"POP F ", 0xFDA, MASK_12B, 0, 0, 5, &op_pop_f_cb}, // POP_F + {"LD SPH R(#0x%02X) ", 0xFE0, MASK_10B, 0, 0, 5, &op_ld_sph_r_cb}, // LD_SPH_R + {"LD SPL R(#0x%02X) ", 0xFF0, MASK_10B, 0, 0, 5, &op_ld_spl_r_cb}, // LD_SPL_R + {"LD R(#0x%02X) SPH ", 0xFE4, MASK_10B, 0, 0, 5, &op_ld_r_sph_cb}, // LD_R_SPH + {"LD R(#0x%02X) SPL ", 0xFF4, MASK_10B, 0, 0, 5, &op_ld_r_spl_cb}, // LD_R_SPL + {"ADD R(#0x%02X) #0x%02X ", 0xC00, MASK_6B, 4, 0x030, 7, &op_add_r_i_cb}, // ADD_R_I + {"ADD R(#0x%02X) Q(#0x%02X)", 0xA80, MASK_8B, 2, 0x00C, 7, &op_add_r_q_cb}, // ADD_R_Q + {"ADC R(#0x%02X) #0x%02X ", 0xC40, MASK_6B, 4, 0x030, 7, &op_adc_r_i_cb}, // ADC_R_I + {"ADC R(#0x%02X) Q(#0x%02X)", 0xA90, MASK_8B, 2, 0x00C, 7, &op_adc_r_q_cb}, // ADC_R_Q + {"SUB R(#0x%02X) Q(#0x%02X)", 0xAA0, MASK_8B, 2, 0x00C, 7, &op_sub_cb}, // SUB + {"SBC R(#0x%02X) #0x%02X ", 0xB40, MASK_6B, 4, 0x030, 7, &op_sbc_r_i_cb}, // SBC_R_I + {"SBC R(#0x%02X) Q(#0x%02X)", 0xAB0, MASK_8B, 2, 0x00C, 7, &op_sbc_r_q_cb}, // SBC_R_Q + {"AND R(#0x%02X) #0x%02X ", 0xC80, MASK_6B, 4, 0x030, 7, &op_and_r_i_cb}, // AND_R_I + {"AND R(#0x%02X) Q(#0x%02X)", 0xAC0, MASK_8B, 2, 0x00C, 7, &op_and_r_q_cb}, // AND_R_Q + {"OR R(#0x%02X) #0x%02X ", 0xCC0, MASK_6B, 4, 0x030, 7, &op_or_r_i_cb}, // OR_R_I + {"OR R(#0x%02X) Q(#0x%02X)", 0xAD0, MASK_8B, 2, 0x00C, 7, &op_or_r_q_cb}, // OR_R_Q + {"XOR R(#0x%02X) #0x%02X ", 0xD00, MASK_6B, 4, 0x030, 7, &op_xor_r_i_cb}, // XOR_R_I + {"XOR R(#0x%02X) Q(#0x%02X)", 0xAE0, MASK_8B, 2, 0x00C, 7, &op_xor_r_q_cb}, // XOR_R_Q + {"CP R(#0x%02X) #0x%02X ", 0xDC0, MASK_6B, 4, 0x030, 7, &op_cp_r_i_cb}, // CP_R_I + {"CP R(#0x%02X) Q(#0x%02X)", 0xF00, MASK_8B, 2, 0x00C, 7, &op_cp_r_q_cb}, // CP_R_Q + {"FAN R(#0x%02X) #0x%02X ", 0xD80, MASK_6B, 4, 0x030, 7, &op_fan_r_i_cb}, // FAN_R_I + {"FAN R(#0x%02X) Q(#0x%02X)", 0xF10, MASK_8B, 2, 0x00C, 7, &op_fan_r_q_cb}, // FAN_R_Q + {"RLC R(#0x%02X) ", 0xAF0, MASK_8B, 0, 0, 7, &op_rlc_cb}, // RLC + {"RRC R(#0x%02X) ", 0xE8C, MASK_10B, 0, 0, 5, &op_rrc_cb}, // RRC + {"INC M(#0x%02X) ", 0xF60, MASK_8B, 0, 0, 7, &op_inc_mn_cb}, // INC_MN + {"DEC M(#0x%02X) ", 0xF70, MASK_8B, 0, 0, 7, &op_dec_mn_cb}, // DEC_MN + {"ACPX R(#0x%02X) ", 0xF28, MASK_10B, 0, 0, 7, &op_acpx_cb}, // ACPX + {"ACPY R(#0x%02X) ", 0xF2C, MASK_10B, 0, 0, 7, &op_acpy_cb}, // ACPY + {"SCPX R(#0x%02X) ", 0xF38, MASK_10B, 0, 0, 7, &op_scpx_cb}, // SCPX + {"SCPY R(#0x%02X) ", 0xF3C, MASK_10B, 0, 0, 7, &op_scpy_cb}, // SCPY + {"NOT R(#0x%02X) ", 0xD0F, 0xFCF, 4, 0, 7, &op_not_cb}, // NOT - {NULL, 0, 0, 0, 0, 0, NULL}, + {NULL, 0, 0, 0, 0, 0, NULL}, }; static timestamp_t wait_for_cycles(timestamp_t since, u8_t cycles) { - timestamp_t deadline; + timestamp_t deadline; - tick_counter += cycles; + tick_counter += cycles; - if (speed_ratio == 0) { - /* Emulation will be as fast as possible */ - return g_hal->get_timestamp(); - } + if(speed_ratio == 0) { + /* Emulation will be as fast as possible */ + return g_hal->get_timestamp(); + } - deadline = since + (cycles * ts_freq)/(TICK_FREQUENCY * speed_ratio); - g_hal->sleep_until(deadline); + deadline = since + (cycles * ts_freq) / (TICK_FREQUENCY * speed_ratio); + g_hal->sleep_until(deadline); - return deadline; + return deadline; } -static void process_interrupts(void) -{ - u8_t i; +static void process_interrupts(void) { + u8_t i; - /* Process interrupts in priority order */ - for (i = 0; i < INT_SLOT_NUM; i++) { - if (interrupts[i].triggered) { - //printf("IT %u !\n", i); - SET_M(sp - 1, PCP); - SET_M(sp - 2, PCSH); - SET_M(sp - 3, PCSL); - sp = (sp - 3) & 0xFF; - CLEAR_I(); - np = TO_NP(NBP, 1); - pc = TO_PC(PCB, 1, interrupts[i].vector); - call_depth++; + /* Process interrupts in priority order */ + for(i = 0; i < INT_SLOT_NUM; i++) { + if(interrupts[i].triggered) { + //printf("IT %u !\n", i); + SET_M(sp - 1, PCP); + SET_M(sp - 2, PCSH); + SET_M(sp - 3, PCSL); + sp = (sp - 3) & 0xFF; + CLEAR_I(); + np = TO_NP(NBP, 1); + pc = TO_PC(PCB, 1, interrupts[i].vector); + call_depth++; - ref_ts = wait_for_cycles(ref_ts, 12); - interrupts[i].triggered = 0; - } - } + ref_ts = wait_for_cycles(ref_ts, 12); + interrupts[i].triggered = 0; + } + } } -static void print_state(u8_t op_num, u12_t op, u13_t addr) -{ - u8_t i; +static void print_state(u8_t op_num, u12_t op, u13_t addr) { + u8_t i; - if (!g_hal->is_log_enabled(LOG_CPU)) { - return; - } + if(!g_hal->is_log_enabled(LOG_CPU)) { + return; + } - g_hal->log(LOG_CPU, "0x%04X: ", addr); + g_hal->log(LOG_CPU, "0x%04X: ", addr); - for (i = 0; i < call_depth; i++) { - g_hal->log(LOG_CPU, " "); - } + for(i = 0; i < call_depth; i++) { + g_hal->log(LOG_CPU, " "); + } - if (ops[op_num].mask_arg0 != 0) { - /* Two arguments */ - g_hal->log(LOG_CPU, ops[op_num].log, (op & ops[op_num].mask_arg0) >> ops[op_num].shift_arg0, op & ~(ops[op_num].mask | ops[op_num].mask_arg0)); - } else { - /* One argument */ - g_hal->log(LOG_CPU, ops[op_num].log, (op & ~ops[op_num].mask) >> ops[op_num].shift_arg0); - } + if(ops[op_num].mask_arg0 != 0) { + /* Two arguments */ + g_hal->log( + LOG_CPU, + ops[op_num].log, + (op & ops[op_num].mask_arg0) >> ops[op_num].shift_arg0, + op & ~(ops[op_num].mask | ops[op_num].mask_arg0)); + } else { + /* One argument */ + g_hal->log(LOG_CPU, ops[op_num].log, (op & ~ops[op_num].mask) >> ops[op_num].shift_arg0); + } - if (call_depth < 10) { - for (i = 0; i < (10 - call_depth); i++) { - g_hal->log(LOG_CPU, " "); - } - } + if(call_depth < 10) { + for(i = 0; i < (10 - call_depth); i++) { + g_hal->log(LOG_CPU, " "); + } + } - g_hal->log(LOG_CPU, " ; 0x%03X - ", op); - for (i = 0; i < 12; i++) { - g_hal->log(LOG_CPU, "%s", ((op >> (11 - i)) & 0x1) ? "1" : "0"); - } - g_hal->log(LOG_CPU, " - PC = 0x%04X, SP = 0x%02X, NP = 0x%02X, X = 0x%03X, Y = 0x%03X, A = 0x%X, B = 0x%X, F = 0x%X\n", pc, sp, np, x, y, a, b, flags); + g_hal->log(LOG_CPU, " ; 0x%03X - ", op); + for(i = 0; i < 12; i++) { + g_hal->log(LOG_CPU, "%s", ((op >> (11 - i)) & 0x1) ? "1" : "0"); + } + g_hal->log( + LOG_CPU, + " - PC = 0x%04X, SP = 0x%02X, NP = 0x%02X, X = 0x%03X, Y = 0x%03X, A = 0x%X, B = 0x%X, F = 0x%X\n", + pc, + sp, + np, + x, + y, + a, + b, + flags); } -void cpu_reset(void) -{ - u13_t i; +void cpu_reset(void) { + u13_t i; - /* Registers and variables init */ - pc = TO_PC(0, 1, 0x00); // PC starts at bank 0, page 1, step 0 - np = TO_NP(0, 1); // NP starts at page 1 - a = 0; // undef - b = 0; // undef - x = 0; // undef - y = 0; // undef - sp = 0; // undef - flags = 0; + /* Registers and variables init */ + pc = TO_PC(0, 1, 0x00); // PC starts at bank 0, page 1, step 0 + np = TO_NP(0, 1); // NP starts at page 1 + a = 0; // undef + b = 0; // undef + x = 0; // undef + y = 0; // undef + sp = 0; // undef + flags = 0; - /* Init RAM to zeros */ - for (i = 0; i < MEM_BUFFER_SIZE; i++) { - memory[i] = 0; - } + /* Init RAM to zeros */ + for(i = 0; i < MEM_BUFFER_SIZE; i++) { + memory[i] = 0; + } - SET_IO_MEMORY(memory, REG_K40_K43_BZ_OUTPUT_PORT, 0xF); // Output port (R40-R43) - SET_IO_MEMORY(memory, REG_LCD_CTRL, 0x8); // LCD control - /* TODO: Input relation register */ + SET_IO_MEMORY(memory, REG_K40_K43_BZ_OUTPUT_PORT, 0xF); // Output port (R40-R43) + SET_IO_MEMORY(memory, REG_LCD_CTRL, 0x8); // LCD control + /* TODO: Input relation register */ - cpu_sync_ref_timestamp(); + cpu_sync_ref_timestamp(); } -bool_t cpu_init(const u12_t *program, breakpoint_t *breakpoints, u32_t freq) -{ - g_program = program; - g_breakpoints = breakpoints; - ts_freq = freq; +bool_t cpu_init(const u12_t* program, breakpoint_t* breakpoints, u32_t freq) { + g_program = program; + g_breakpoints = breakpoints; + ts_freq = freq; - cpu_reset(); + cpu_reset(); - return 0; + return 0; } -void cpu_release(void) -{ +void cpu_release(void) { } -int cpu_step(void) -{ - u12_t op; - u8_t i; - breakpoint_t *bp = g_breakpoints; - static u8_t previous_cycles = 0; +int cpu_step(void) { + u12_t op; + u8_t i; + breakpoint_t* bp = g_breakpoints; + static u8_t previous_cycles = 0; - op = g_program[pc]; + op = g_program[pc]; - /* Lookup the OP code */ - for (i = 0; ops[i].log != NULL; i++) { - if ((op & ops[i].mask) == ops[i].code) { - break; - } - } + /* Lookup the OP code */ + for(i = 0; ops[i].log != NULL; i++) { + if((op & ops[i].mask) == ops[i].code) { + break; + } + } - if (ops[i].log == NULL) { - g_hal->log(LOG_ERROR, "Unknown op-code 0x%X (pc = 0x%04X)\n", op, pc); - return 1; - } + if(ops[i].log == NULL) { + g_hal->log(LOG_ERROR, "Unknown op-code 0x%X (pc = 0x%04X)\n", op, pc); + return 1; + } - next_pc = (pc + 1) & 0x1FFF; + next_pc = (pc + 1) & 0x1FFF; - /* Display the operation along with the current state of the processor */ - print_state(i, op, pc); + /* Display the operation along with the current state of the processor */ + print_state(i, op, pc); - /* Match the speed of the real processor + /* Match the speed of the real processor * NOTE: For better accuracy, the final wait should happen here, however * the downside is that all interrupts will likely be delayed by one OP */ - ref_ts = wait_for_cycles(ref_ts, previous_cycles); + ref_ts = wait_for_cycles(ref_ts, previous_cycles); - /* Process the OP code */ - if (ops[i].cb != NULL) { - if (ops[i].mask_arg0 != 0) { - /* Two arguments */ - ops[i].cb((op & ops[i].mask_arg0) >> ops[i].shift_arg0, op & ~(ops[i].mask | ops[i].mask_arg0)); - } else { - /* One arguments */ - ops[i].cb((op & ~ops[i].mask) >> ops[i].shift_arg0, 0); - } - } + /* Process the OP code */ + if(ops[i].cb != NULL) { + if(ops[i].mask_arg0 != 0) { + /* Two arguments */ + ops[i].cb( + (op & ops[i].mask_arg0) >> ops[i].shift_arg0, + op & ~(ops[i].mask | ops[i].mask_arg0)); + } else { + /* One arguments */ + ops[i].cb((op & ~ops[i].mask) >> ops[i].shift_arg0, 0); + } + } - /* Prepare for the next instruction */ - pc = next_pc; - previous_cycles = ops[i].cycles; + /* Prepare for the next instruction */ + pc = next_pc; + previous_cycles = ops[i].cycles; - if (i > 0) { - /* OP code is not PSET, reset NP */ - np = (pc >> 8) & 0x1F; - } + if(i > 0) { + /* OP code is not PSET, reset NP */ + np = (pc >> 8) & 0x1F; + } - /* Handle timers using the internal tick counter */ - if (tick_counter - clk_timer_timestamp >= TIMER_1HZ_PERIOD) { - do { - clk_timer_timestamp += TIMER_1HZ_PERIOD; - } while (tick_counter - clk_timer_timestamp >= TIMER_1HZ_PERIOD); + /* Handle timers using the internal tick counter */ + if(tick_counter - clk_timer_timestamp >= TIMER_1HZ_PERIOD) { + do { + clk_timer_timestamp += TIMER_1HZ_PERIOD; + } while(tick_counter - clk_timer_timestamp >= TIMER_1HZ_PERIOD); - generate_interrupt(INT_CLOCK_TIMER_SLOT, 3); - } + generate_interrupt(INT_CLOCK_TIMER_SLOT, 3); + } - if (prog_timer_enabled && tick_counter - prog_timer_timestamp >= TIMER_256HZ_PERIOD) { - do { - prog_timer_timestamp += TIMER_256HZ_PERIOD; - prog_timer_data--; + if(prog_timer_enabled && tick_counter - prog_timer_timestamp >= TIMER_256HZ_PERIOD) { + do { + prog_timer_timestamp += TIMER_256HZ_PERIOD; + prog_timer_data--; - if (prog_timer_data == 0) { - prog_timer_data = prog_timer_rld; - generate_interrupt(INT_PROG_TIMER_SLOT, 0); - } - } while (tick_counter - prog_timer_timestamp >= TIMER_256HZ_PERIOD); - } + if(prog_timer_data == 0) { + prog_timer_data = prog_timer_rld; + generate_interrupt(INT_PROG_TIMER_SLOT, 0); + } + } while(tick_counter - prog_timer_timestamp >= TIMER_256HZ_PERIOD); + } - /* Check if there is any pending interrupt */ - if (I && i > 0) { // Do not process interrupts after a PSET operation - process_interrupts(); - } + /* Check if there is any pending interrupt */ + if(I && i > 0) { // Do not process interrupts after a PSET operation + process_interrupts(); + } - /* Check if we could pause the execution */ - while (bp != NULL) { - if (bp->addr == pc) { - return 1; - } + /* Check if we could pause the execution */ + while(bp != NULL) { + if(bp->addr == pc) { + return 1; + } - bp = bp->next; - } + bp = bp->next; + } - return 0; + return 0; } diff --git a/applications/plugins/tama_p1/tamalib/cpu.h b/applications/plugins/tama_p1/tamalib/cpu.h index e8e406b7f..4405103b2 100644 --- a/applications/plugins/tama_p1/tamalib/cpu.h +++ b/applications/plugins/tama_p1/tamalib/cpu.h @@ -22,16 +22,16 @@ #include "hal.h" -#define MEMORY_SIZE 4096 // 4096 x 4 bits (640 x 4 bits of RAM) +#define MEMORY_SIZE 4096 // 4096 x 4 bits (640 x 4 bits of RAM) -#define MEM_RAM_ADDR 0x000 -#define MEM_RAM_SIZE 0x280 -#define MEM_DISPLAY1_ADDR 0xE00 -#define MEM_DISPLAY1_SIZE 0x050 -#define MEM_DISPLAY2_ADDR 0xE80 -#define MEM_DISPLAY2_SIZE 0x050 -#define MEM_IO_ADDR 0xF00 -#define MEM_IO_SIZE 0x080 +#define MEM_RAM_ADDR 0x000 +#define MEM_RAM_SIZE 0x280 +#define MEM_DISPLAY1_ADDR 0xE00 +#define MEM_DISPLAY1_SIZE 0x050 +#define MEM_DISPLAY2_ADDR 0xE80 +#define MEM_DISPLAY2_SIZE 0x050 +#define MEM_IO_ADDR 0xF00 +#define MEM_IO_SIZE 0x080 /* Define this if you want to reduce the footprint of the memory buffer from 4096 u4_t (most likely bytes) * to 464 u8_t (bytes for sure), while increasing slightly the number of operations needed to read/write from/to it. @@ -40,139 +40,162 @@ #ifdef LOW_FOOTPRINT /* Invalid memory areas are not buffered to reduce the footprint of the library in memory */ -#define MEM_BUFFER_SIZE (MEM_RAM_SIZE + MEM_DISPLAY1_SIZE + MEM_DISPLAY2_SIZE + MEM_IO_SIZE)/2 +#define MEM_BUFFER_SIZE (MEM_RAM_SIZE + MEM_DISPLAY1_SIZE + MEM_DISPLAY2_SIZE + MEM_IO_SIZE) / 2 /* Maps the CPU memory to the memory buffer */ -#define RAM_TO_MEMORY(n) ((n - MEM_RAM_ADDR)/2) -#define DISP1_TO_MEMORY(n) ((n - MEM_DISPLAY1_ADDR + MEM_RAM_SIZE)/2) -#define DISP2_TO_MEMORY(n) ((n - MEM_DISPLAY2_ADDR + MEM_RAM_SIZE + MEM_DISPLAY1_SIZE)/2) -#define IO_TO_MEMORY(n) ((n - MEM_IO_ADDR + MEM_RAM_SIZE + MEM_DISPLAY1_SIZE + MEM_DISPLAY2_SIZE)/2) +#define RAM_TO_MEMORY(n) ((n - MEM_RAM_ADDR) / 2) +#define DISP1_TO_MEMORY(n) ((n - MEM_DISPLAY1_ADDR + MEM_RAM_SIZE) / 2) +#define DISP2_TO_MEMORY(n) ((n - MEM_DISPLAY2_ADDR + MEM_RAM_SIZE + MEM_DISPLAY1_SIZE) / 2) +#define IO_TO_MEMORY(n) \ + ((n - MEM_IO_ADDR + MEM_RAM_SIZE + MEM_DISPLAY1_SIZE + MEM_DISPLAY2_SIZE) / 2) -#define SET_RAM_MEMORY(buffer, n, v) {buffer[RAM_TO_MEMORY(n)] = (buffer[RAM_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | ((v) & 0xF) << (((n) % 2) << 2);} -#define SET_DISP1_MEMORY(buffer, n, v) {buffer[DISP1_TO_MEMORY(n)] = (buffer[DISP1_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | ((v) & 0xF) << (((n) % 2) << 2);} -#define SET_DISP2_MEMORY(buffer, n, v) {buffer[DISP2_TO_MEMORY(n)] = (buffer[DISP2_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | ((v) & 0xF) << (((n) % 2) << 2);} -#define SET_IO_MEMORY(buffer, n, v) {buffer[IO_TO_MEMORY(n)] = (buffer[IO_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | ((v) & 0xF) << (((n) % 2) << 2);} -#define SET_MEMORY(buffer, n, v) {if ((n) < (MEM_RAM_ADDR + MEM_RAM_SIZE)) { \ - SET_RAM_MEMORY(buffer, n, v); \ - } else if ((n) < MEM_DISPLAY1_ADDR) { \ - /* INVALID_MEMORY */ \ - } else if ((n) < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { \ - SET_DISP1_MEMORY(buffer, n, v); \ - } else if ((n) < MEM_DISPLAY2_ADDR) { \ - /* INVALID_MEMORY */ \ - } else if ((n) < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { \ - SET_DISP2_MEMORY(buffer, n, v); \ - } else if ((n) < MEM_IO_ADDR) { \ - /* INVALID_MEMORY */ \ - } else if ((n) < (MEM_IO_ADDR + MEM_IO_SIZE)) { \ - SET_IO_MEMORY(buffer, n, v); \ - } else { \ - /* INVALID_MEMORY */ \ - }} +#define SET_RAM_MEMORY(buffer, n, v) \ + { \ + buffer[RAM_TO_MEMORY(n)] = (buffer[RAM_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | \ + ((v)&0xF) << (((n) % 2) << 2); \ + } +#define SET_DISP1_MEMORY(buffer, n, v) \ + { \ + buffer[DISP1_TO_MEMORY(n)] = (buffer[DISP1_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | \ + ((v)&0xF) << (((n) % 2) << 2); \ + } +#define SET_DISP2_MEMORY(buffer, n, v) \ + { \ + buffer[DISP2_TO_MEMORY(n)] = (buffer[DISP2_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | \ + ((v)&0xF) << (((n) % 2) << 2); \ + } +#define SET_IO_MEMORY(buffer, n, v) \ + { \ + buffer[IO_TO_MEMORY(n)] = (buffer[IO_TO_MEMORY(n)] & ~(0xF << (((n) % 2) << 2))) | \ + ((v)&0xF) << (((n) % 2) << 2); \ + } +#define SET_MEMORY(buffer, n, v) \ + { \ + if((n) < (MEM_RAM_ADDR + MEM_RAM_SIZE)) { \ + SET_RAM_MEMORY(buffer, n, v); \ + } else if((n) < MEM_DISPLAY1_ADDR) { \ + /* INVALID_MEMORY */ \ + } else if((n) < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) { \ + SET_DISP1_MEMORY(buffer, n, v); \ + } else if((n) < MEM_DISPLAY2_ADDR) { \ + /* INVALID_MEMORY */ \ + } else if((n) < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) { \ + SET_DISP2_MEMORY(buffer, n, v); \ + } else if((n) < MEM_IO_ADDR) { \ + /* INVALID_MEMORY */ \ + } else if((n) < (MEM_IO_ADDR + MEM_IO_SIZE)) { \ + SET_IO_MEMORY(buffer, n, v); \ + } else { \ + /* INVALID_MEMORY */ \ + } \ + } -#define GET_RAM_MEMORY(buffer, n) ((buffer[RAM_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) -#define GET_DISP1_MEMORY(buffer, n) ((buffer[DISP1_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) -#define GET_DISP2_MEMORY(buffer, n) ((buffer[DISP2_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) -#define GET_IO_MEMORY(buffer, n) ((buffer[IO_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) -#define GET_MEMORY(buffer, n) ((buffer[ \ - ((n) < (MEM_RAM_ADDR + MEM_RAM_SIZE)) ? RAM_TO_MEMORY(n) : \ - ((n) < MEM_DISPLAY1_ADDR) ? 0 : \ - ((n) < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) ? DISP1_TO_MEMORY(n) : \ - ((n) < MEM_DISPLAY2_ADDR) ? 0 : \ - ((n) < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) ? DISP2_TO_MEMORY(n) : \ - ((n) < MEM_IO_ADDR) ? 0 : \ - ((n) < (MEM_IO_ADDR + MEM_IO_SIZE)) ? IO_TO_MEMORY(n) : 0 \ - ] >> (((n) % 2) << 2)) & 0xF) +#define GET_RAM_MEMORY(buffer, n) ((buffer[RAM_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) +#define GET_DISP1_MEMORY(buffer, n) ((buffer[DISP1_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) +#define GET_DISP2_MEMORY(buffer, n) ((buffer[DISP2_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) +#define GET_IO_MEMORY(buffer, n) ((buffer[IO_TO_MEMORY(n)] >> (((n) % 2) << 2)) & 0xF) +#define GET_MEMORY(buffer, n) \ + ((buffer \ + [((n) < (MEM_RAM_ADDR + MEM_RAM_SIZE)) ? RAM_TO_MEMORY(n) : \ + ((n) < MEM_DISPLAY1_ADDR) ? 0 : \ + ((n) < (MEM_DISPLAY1_ADDR + MEM_DISPLAY1_SIZE)) ? DISP1_TO_MEMORY(n) : \ + ((n) < MEM_DISPLAY2_ADDR) ? 0 : \ + ((n) < (MEM_DISPLAY2_ADDR + MEM_DISPLAY2_SIZE)) ? DISP2_TO_MEMORY(n) : \ + ((n) < MEM_IO_ADDR) ? 0 : \ + ((n) < (MEM_IO_ADDR + MEM_IO_SIZE)) ? IO_TO_MEMORY(n) : \ + 0] >> \ + (((n) % 2) << 2)) & \ + 0xF) -#define MEM_BUFFER_TYPE u8_t +#define MEM_BUFFER_TYPE u8_t #else -#define MEM_BUFFER_SIZE MEMORY_SIZE +#define MEM_BUFFER_SIZE MEMORY_SIZE -#define SET_MEMORY(buffer, n, v) {buffer[n] = v;} -#define SET_RAM_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) -#define SET_DISP1_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) -#define SET_DISP2_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) -#define SET_IO_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) +#define SET_MEMORY(buffer, n, v) \ + { buffer[n] = v; } +#define SET_RAM_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) +#define SET_DISP1_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) +#define SET_DISP2_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) +#define SET_IO_MEMORY(buffer, n, v) SET_MEMORY(buffer, n, v) -#define GET_MEMORY(buffer, n) (buffer[n]) -#define GET_RAM_MEMORY(buffer, n) GET_MEMORY(buffer, n) -#define GET_DISP1_MEMORY(buffer, n) GET_MEMORY(buffer, n) -#define GET_DISP2_MEMORY(buffer, n) GET_MEMORY(buffer, n) -#define GET_IO_MEMORY(buffer, n) GET_MEMORY(buffer, n) +#define GET_MEMORY(buffer, n) (buffer[n]) +#define GET_RAM_MEMORY(buffer, n) GET_MEMORY(buffer, n) +#define GET_DISP1_MEMORY(buffer, n) GET_MEMORY(buffer, n) +#define GET_DISP2_MEMORY(buffer, n) GET_MEMORY(buffer, n) +#define GET_IO_MEMORY(buffer, n) GET_MEMORY(buffer, n) -#define MEM_BUFFER_TYPE u4_t +#define MEM_BUFFER_TYPE u4_t #endif typedef struct breakpoint { - u13_t addr; - struct breakpoint *next; + u13_t addr; + struct breakpoint* next; } breakpoint_t; /* Pins (TODO: add other pins) */ typedef enum { - PIN_K00 = 0x0, - PIN_K01 = 0x1, - PIN_K02 = 0x2, - PIN_K03 = 0x3, - PIN_K10 = 0X4, - PIN_K11 = 0X5, - PIN_K12 = 0X6, - PIN_K13 = 0X7, + PIN_K00 = 0x0, + PIN_K01 = 0x1, + PIN_K02 = 0x2, + PIN_K03 = 0x3, + PIN_K10 = 0X4, + PIN_K11 = 0X5, + PIN_K12 = 0X6, + PIN_K13 = 0X7, } pin_t; typedef enum { - PIN_STATE_LOW = 0, - PIN_STATE_HIGH = 1, + PIN_STATE_LOW = 0, + PIN_STATE_HIGH = 1, } pin_state_t; typedef enum { - INT_PROG_TIMER_SLOT = 0, - INT_SERIAL_SLOT = 1, - INT_K10_K13_SLOT = 2, - INT_K00_K03_SLOT = 3, - INT_STOPWATCH_SLOT = 4, - INT_CLOCK_TIMER_SLOT = 5, - INT_SLOT_NUM, + INT_PROG_TIMER_SLOT = 0, + INT_SERIAL_SLOT = 1, + INT_K10_K13_SLOT = 2, + INT_K00_K03_SLOT = 3, + INT_STOPWATCH_SLOT = 4, + INT_CLOCK_TIMER_SLOT = 5, + INT_SLOT_NUM, } int_slot_t; typedef struct { - u4_t factor_flag_reg; - u4_t mask_reg; - bool_t triggered; /* 1 if triggered, 0 otherwise */ - u8_t vector; + u4_t factor_flag_reg; + u4_t mask_reg; + bool_t triggered; /* 1 if triggered, 0 otherwise */ + u8_t vector; } interrupt_t; typedef struct { - u13_t *pc; - u12_t *x; - u12_t *y; - u4_t *a; - u4_t *b; - u5_t *np; - u8_t *sp; - u4_t *flags; + u13_t* pc; + u12_t* x; + u12_t* y; + u4_t* a; + u4_t* b; + u5_t* np; + u8_t* sp; + u4_t* flags; - u32_t *tick_counter; - u32_t *clk_timer_timestamp; - u32_t *prog_timer_timestamp; - bool_t *prog_timer_enabled; - u8_t *prog_timer_data; - u8_t *prog_timer_rld; + u32_t* tick_counter; + u32_t* clk_timer_timestamp; + u32_t* prog_timer_timestamp; + bool_t* prog_timer_enabled; + u8_t* prog_timer_data; + u8_t* prog_timer_rld; - u32_t *call_depth; + u32_t* call_depth; - interrupt_t *interrupts; + interrupt_t* interrupts; - MEM_BUFFER_TYPE *memory; + MEM_BUFFER_TYPE* memory; } state_t; - -void cpu_add_bp(breakpoint_t **list, u13_t addr); -void cpu_free_bp(breakpoint_t **list); +void cpu_add_bp(breakpoint_t** list, u13_t addr); +void cpu_free_bp(breakpoint_t** list); void cpu_set_speed(u8_t speed); -state_t * cpu_get_state(void); +state_t* cpu_get_state(void); u32_t cpu_get_depth(void); @@ -184,7 +207,7 @@ void cpu_refresh_hw(void); void cpu_reset(void); -bool_t cpu_init(const u12_t *program, breakpoint_t *breakpoints, u32_t freq); +bool_t cpu_init(const u12_t* program, breakpoint_t* breakpoints, u32_t freq); void cpu_release(void); int cpu_step(void); diff --git a/applications/plugins/tama_p1/tamalib/hal.h b/applications/plugins/tama_p1/tamalib/hal.h index 4427689af..84140befb 100644 --- a/applications/plugins/tama_p1/tamalib/hal.h +++ b/applications/plugins/tama_p1/tamalib/hal.h @@ -23,14 +23,14 @@ #include "../hal_types.h" #ifndef NULL - #define NULL 0 +#define NULL 0 #endif typedef enum { - LOG_ERROR = 0x1, - LOG_INFO = (0x1 << 1), - LOG_MEMORY = (0x1 << 2), - LOG_CPU = (0x1 << 3), + LOG_ERROR = 0x1, + LOG_INFO = (0x1 << 1), + LOG_MEMORY = (0x1 << 2), + LOG_CPU = (0x1 << 3), } log_level_t; /* The Hardware Abstraction Layer @@ -38,52 +38,52 @@ typedef enum { * All pointers MUST be implemented, but some implementations can be left empty. */ typedef struct { - /* Memory allocation functions + /* Memory allocation functions * NOTE: Needed only if breakpoints support is required. */ - void * (*malloc)(u32_t size); - void (*free)(void *ptr); + void* (*malloc)(u32_t size); + void (*free)(void* ptr); - /* What to do if the CPU has halted + /* What to do if the CPU has halted */ - void (*halt)(void); + void (*halt)(void); - /* Log related function + /* Log related function * NOTE: Needed only if log messages are required. */ - bool_t (*is_log_enabled)(log_level_t level); - void (*log)(log_level_t level, char *buff, ...); + bool_t (*is_log_enabled)(log_level_t level); + void (*log)(log_level_t level, char* buff, ...); - /* Clock related functions + /* Clock related functions * NOTE: Timestamps granularity is configured with tamalib_init(), an accuracy * of ~30 us (1/32768) is required for a cycle accurate emulation. */ - void (*sleep_until)(timestamp_t ts); - timestamp_t (*get_timestamp)(void); + void (*sleep_until)(timestamp_t ts); + timestamp_t (*get_timestamp)(void); - /* Screen related functions + /* Screen related functions * NOTE: In case of direct hardware access to pixels, the set_XXXX() functions * (called for each pixel/icon update) can directly drive them, otherwise they * should just store the data in a buffer and let update_screen() do the actual * rendering (at 30 fps). */ - void (*update_screen)(void); - void (*set_lcd_matrix)(u8_t x, u8_t y, bool_t val); - void (*set_lcd_icon)(u8_t icon, bool_t val); + void (*update_screen)(void); + void (*set_lcd_matrix)(u8_t x, u8_t y, bool_t val); + void (*set_lcd_icon)(u8_t icon, bool_t val); - /* Sound related functions + /* Sound related functions * NOTE: set_frequency() changes the output frequency of the sound, while * play_frequency() decides whether the sound should be heard or not. */ - void (*set_frequency)(u32_t freq); - void (*play_frequency)(bool_t en); + void (*set_frequency)(u32_t freq); + void (*play_frequency)(bool_t en); - /* Event handler from the main app (if any) + /* Event handler from the main app (if any) * NOTE: This function usually handles button related events, states loading/saving ... */ - int (*handler)(void); + int (*handler)(void); } hal_t; -extern hal_t *g_hal; +extern hal_t* g_hal; #endif /* _HAL_H_ */ diff --git a/applications/plugins/tama_p1/tamalib/hw.c b/applications/plugins/tama_p1/tamalib/hw.c index cfce8d925..0a91f2a78 100644 --- a/applications/plugins/tama_p1/tamalib/hw.c +++ b/applications/plugins/tama_p1/tamalib/hw.c @@ -22,29 +22,27 @@ #include "hal.h" /* SEG -> LCD mapping */ -static u8_t seg_pos[40] = {0, 1, 2, 3, 4, 5, 6, 7, 32, 8, 9, 10, 11, 12 ,13 ,14, 15, 33, 34, 35, 31, 30, 29, 28, 27, 26, 25, 24, 36, 23, 22, 21, 20, 19, 18, 17, 16, 37, 38, 39}; +static u8_t seg_pos[40] = {0, 1, 2, 3, 4, 5, 6, 7, 32, 8, 9, 10, 11, 12, + 13, 14, 15, 33, 34, 35, 31, 30, 29, 28, 27, 26, 25, 24, + 36, 23, 22, 21, 20, 19, 18, 17, 16, 37, 38, 39}; +bool_t hw_init(void) { + /* Buttons are active LOW */ + cpu_set_input_pin(PIN_K00, PIN_STATE_HIGH); + cpu_set_input_pin(PIN_K01, PIN_STATE_HIGH); + cpu_set_input_pin(PIN_K02, PIN_STATE_HIGH); -bool_t hw_init(void) -{ - /* Buttons are active LOW */ - cpu_set_input_pin(PIN_K00, PIN_STATE_HIGH); - cpu_set_input_pin(PIN_K01, PIN_STATE_HIGH); - cpu_set_input_pin(PIN_K02, PIN_STATE_HIGH); - - return 0; + return 0; } -void hw_release(void) -{ +void hw_release(void) { } -void hw_set_lcd_pin(u8_t seg, u8_t com, u8_t val) -{ - if (seg_pos[seg] < LCD_WIDTH) { - g_hal->set_lcd_matrix(seg_pos[seg], com, val); - } else { - /* +void hw_set_lcd_pin(u8_t seg, u8_t com, u8_t val) { + if(seg_pos[seg] < LCD_WIDTH) { + g_hal->set_lcd_matrix(seg_pos[seg], com, val); + } else { + /* * IC n -> seg-com|... * IC 0 -> 8-0 |18-3 |19-2 * IC 1 -> 8-1 |17-0 |19-3 @@ -55,85 +53,82 @@ void hw_set_lcd_pin(u8_t seg, u8_t com, u8_t val) * IC 6 -> 28-14|37-15|39-12 * IC 7 -> 28-15|38-12|39-13 */ - if (seg == 8 && com < 4) { - g_hal->set_lcd_icon(com, val); - } else if (seg == 28 && com >= 12) { - g_hal->set_lcd_icon(com - 8, val); - } - } + if(seg == 8 && com < 4) { + g_hal->set_lcd_icon(com, val); + } else if(seg == 28 && com >= 12) { + g_hal->set_lcd_icon(com - 8, val); + } + } } -void hw_set_button(button_t btn, btn_state_t state) -{ - pin_state_t pin_state = (state == BTN_STATE_PRESSED) ? PIN_STATE_LOW : PIN_STATE_HIGH; +void hw_set_button(button_t btn, btn_state_t state) { + pin_state_t pin_state = (state == BTN_STATE_PRESSED) ? PIN_STATE_LOW : PIN_STATE_HIGH; - switch (btn) { - case BTN_LEFT: - cpu_set_input_pin(PIN_K02, pin_state); - break; + switch(btn) { + case BTN_LEFT: + cpu_set_input_pin(PIN_K02, pin_state); + break; - case BTN_MIDDLE: - cpu_set_input_pin(PIN_K01, pin_state); - break; + case BTN_MIDDLE: + cpu_set_input_pin(PIN_K01, pin_state); + break; - case BTN_RIGHT: - cpu_set_input_pin(PIN_K00, pin_state); - break; - } + case BTN_RIGHT: + cpu_set_input_pin(PIN_K00, pin_state); + break; + } } -void hw_set_buzzer_freq(u4_t freq) -{ - u32_t snd_freq = 0; +void hw_set_buzzer_freq(u4_t freq) { + u32_t snd_freq = 0; - switch (freq) { - case 0: - /* 4096.0 Hz */ - snd_freq = 40960; - break; + switch(freq) { + case 0: + /* 4096.0 Hz */ + snd_freq = 40960; + break; - case 1: - /* 3276.8 Hz */ - snd_freq = 32768; - break; + case 1: + /* 3276.8 Hz */ + snd_freq = 32768; + break; - case 2: - /* 2730.7 Hz */ - snd_freq = 27307; - break; + case 2: + /* 2730.7 Hz */ + snd_freq = 27307; + break; - case 3: - /* 2340.6 Hz */ - snd_freq = 23406; - break; + case 3: + /* 2340.6 Hz */ + snd_freq = 23406; + break; - case 4: - /* 2048.0 Hz */ - snd_freq = 20480; - break; + case 4: + /* 2048.0 Hz */ + snd_freq = 20480; + break; - case 5: - /* 1638.4 Hz */ - snd_freq = 16384; - break; + case 5: + /* 1638.4 Hz */ + snd_freq = 16384; + break; - case 6: - /* 1365.3 Hz */ - snd_freq = 13653; - break; + case 6: + /* 1365.3 Hz */ + snd_freq = 13653; + break; - case 7: - /* 1170.3 Hz */ - snd_freq = 11703; - break; - } + case 7: + /* 1170.3 Hz */ + snd_freq = 11703; + break; + } - if (snd_freq != 0) { - g_hal->set_frequency(snd_freq); - } + if(snd_freq != 0) { + g_hal->set_frequency(snd_freq); + } } -void hw_enable_buzzer(bool_t en) -{ - g_hal->play_frequency(en); +void hw_enable_buzzer(bool_t en) { + g_hal->play_frequency(en); } diff --git a/applications/plugins/tama_p1/tamalib/hw.h b/applications/plugins/tama_p1/tamalib/hw.h index 39a22957a..853515b39 100644 --- a/applications/plugins/tama_p1/tamalib/hw.h +++ b/applications/plugins/tama_p1/tamalib/hw.h @@ -22,23 +22,22 @@ #include "hal.h" -#define LCD_WIDTH 32 -#define LCD_HEIGHT 16 +#define LCD_WIDTH 32 +#define LCD_HEIGHT 16 -#define ICON_NUM 8 +#define ICON_NUM 8 typedef enum { - BTN_STATE_RELEASED = 0, - BTN_STATE_PRESSED, + BTN_STATE_RELEASED = 0, + BTN_STATE_PRESSED, } btn_state_t; typedef enum { - BTN_LEFT = 0, - BTN_MIDDLE, - BTN_RIGHT, + BTN_LEFT = 0, + BTN_MIDDLE, + BTN_RIGHT, } button_t; - bool_t hw_init(void); void hw_release(void); diff --git a/applications/plugins/tama_p1/tamalib/tamalib.c b/applications/plugins/tama_p1/tamalib/tamalib.c index 4bd8879c0..92a19678c 100644 --- a/applications/plugins/tama_p1/tamalib/tamalib.c +++ b/applications/plugins/tama_p1/tamalib/tamalib.c @@ -22,7 +22,7 @@ #include "cpu.h" #include "hal.h" -#define DEFAULT_FRAMERATE 30 // fps +#define DEFAULT_FRAMERATE 30 // fps static exec_mode_t exec_mode = EXEC_MODE_RUN; @@ -34,104 +34,95 @@ static u32_t ts_freq; static u8_t g_framerate = DEFAULT_FRAMERATE; -hal_t *g_hal; +hal_t* g_hal; +bool_t tamalib_init(const u12_t* program, breakpoint_t* breakpoints, u32_t freq) { + bool_t res = 0; -bool_t tamalib_init(const u12_t *program, breakpoint_t *breakpoints, u32_t freq) -{ - bool_t res = 0; + res |= cpu_init(program, breakpoints, freq); + res |= hw_init(); - res |= cpu_init(program, breakpoints, freq); - res |= hw_init(); + ts_freq = freq; - ts_freq = freq; - - return res; + return res; } -void tamalib_release(void) -{ - hw_release(); - cpu_release(); +void tamalib_release(void) { + hw_release(); + cpu_release(); } -void tamalib_set_framerate(u8_t framerate) -{ - g_framerate = framerate; +void tamalib_set_framerate(u8_t framerate) { + g_framerate = framerate; } -u8_t tamalib_get_framerate(void) -{ - return g_framerate; +u8_t tamalib_get_framerate(void) { + return g_framerate; } -void tamalib_register_hal(hal_t *hal) -{ - g_hal = hal; +void tamalib_register_hal(hal_t* hal) { + g_hal = hal; } -void tamalib_set_exec_mode(exec_mode_t mode) -{ - exec_mode = mode; - step_depth = cpu_get_depth(); - cpu_sync_ref_timestamp(); +void tamalib_set_exec_mode(exec_mode_t mode) { + exec_mode = mode; + step_depth = cpu_get_depth(); + cpu_sync_ref_timestamp(); } -void tamalib_step(void) -{ - if (exec_mode == EXEC_MODE_PAUSE) { - return; - } +void tamalib_step(void) { + if(exec_mode == EXEC_MODE_PAUSE) { + return; + } - if (cpu_step()) { - exec_mode = EXEC_MODE_PAUSE; - step_depth = cpu_get_depth(); - } else { - switch (exec_mode) { - case EXEC_MODE_PAUSE: - case EXEC_MODE_RUN: - break; + if(cpu_step()) { + exec_mode = EXEC_MODE_PAUSE; + step_depth = cpu_get_depth(); + } else { + switch(exec_mode) { + case EXEC_MODE_PAUSE: + case EXEC_MODE_RUN: + break; - case EXEC_MODE_STEP: - exec_mode = EXEC_MODE_PAUSE; - break; + case EXEC_MODE_STEP: + exec_mode = EXEC_MODE_PAUSE; + break; - case EXEC_MODE_NEXT: - if (cpu_get_depth() <= step_depth) { - exec_mode = EXEC_MODE_PAUSE; - step_depth = cpu_get_depth(); - } - break; + case EXEC_MODE_NEXT: + if(cpu_get_depth() <= step_depth) { + exec_mode = EXEC_MODE_PAUSE; + step_depth = cpu_get_depth(); + } + break; - case EXEC_MODE_TO_CALL: - if (cpu_get_depth() > step_depth) { - exec_mode = EXEC_MODE_PAUSE; - step_depth = cpu_get_depth(); - } - break; + case EXEC_MODE_TO_CALL: + if(cpu_get_depth() > step_depth) { + exec_mode = EXEC_MODE_PAUSE; + step_depth = cpu_get_depth(); + } + break; - case EXEC_MODE_TO_RET: - if (cpu_get_depth() < step_depth) { - exec_mode = EXEC_MODE_PAUSE; - step_depth = cpu_get_depth(); - } - break; - } - } + case EXEC_MODE_TO_RET: + if(cpu_get_depth() < step_depth) { + exec_mode = EXEC_MODE_PAUSE; + step_depth = cpu_get_depth(); + } + break; + } + } } -void tamalib_mainloop(void) -{ - timestamp_t ts; +void tamalib_mainloop(void) { + timestamp_t ts; - while (!g_hal->handler()) { - tamalib_step(); + while(!g_hal->handler()) { + tamalib_step(); - /* Update the screen @ g_framerate fps */ - ts = g_hal->get_timestamp(); - if (ts - screen_ts >= ts_freq/g_framerate) { - screen_ts = ts; - g_hal->update_screen(); - } - } + /* Update the screen @ g_framerate fps */ + ts = g_hal->get_timestamp(); + if(ts - screen_ts >= ts_freq / g_framerate) { + screen_ts = ts; + g_hal->update_screen(); + } + } } diff --git a/applications/plugins/tama_p1/tamalib/tamalib.h b/applications/plugins/tama_p1/tamalib/tamalib.h index d18101bf6..570f845eb 100644 --- a/applications/plugins/tama_p1/tamalib/tamalib.h +++ b/applications/plugins/tama_p1/tamalib/tamalib.h @@ -24,35 +24,34 @@ #include "hw.h" #include "hal.h" -#define tamalib_set_button(btn, state) hw_set_button(btn, state) +#define tamalib_set_button(btn, state) hw_set_button(btn, state) -#define tamalib_set_speed(speed) cpu_set_speed(speed) +#define tamalib_set_speed(speed) cpu_set_speed(speed) -#define tamalib_get_state() cpu_get_state() -#define tamalib_refresh_hw() cpu_refresh_hw() +#define tamalib_get_state() cpu_get_state() +#define tamalib_refresh_hw() cpu_refresh_hw() -#define tamalib_reset() cpu_reset() +#define tamalib_reset() cpu_reset() -#define tamalib_add_bp(list, addr) cpu_add_bp(list, addr) -#define tamalib_free_bp(list) cpu_free_bp(list) +#define tamalib_add_bp(list, addr) cpu_add_bp(list, addr) +#define tamalib_free_bp(list) cpu_free_bp(list) typedef enum { - EXEC_MODE_PAUSE, - EXEC_MODE_RUN, - EXEC_MODE_STEP, - EXEC_MODE_NEXT, - EXEC_MODE_TO_CALL, - EXEC_MODE_TO_RET, + EXEC_MODE_PAUSE, + EXEC_MODE_RUN, + EXEC_MODE_STEP, + EXEC_MODE_NEXT, + EXEC_MODE_TO_CALL, + EXEC_MODE_TO_RET, } exec_mode_t; - void tamalib_release(void); -bool_t tamalib_init(const u12_t *program, breakpoint_t *breakpoints, u32_t freq); +bool_t tamalib_init(const u12_t* program, breakpoint_t* breakpoints, u32_t freq); void tamalib_set_framerate(u8_t framerate); u8_t tamalib_get_framerate(void); -void tamalib_register_hal(hal_t *hal); +void tamalib_register_hal(hal_t* hal); void tamalib_set_exec_mode(exec_mode_t mode); diff --git a/applications/plugins/tanksgame/tanks_game.c b/applications/plugins/tanksgame/tanks_game.c index d02e06eb1..6dd47a54b 100644 --- a/applications/plugins/tanksgame/tanks_game.c +++ b/applications/plugins/tanksgame/tanks_game.c @@ -1181,7 +1181,7 @@ static void tanks_game_init_game(TanksState* const tanks_state, GameState type) static bool tanks_game_collision(Point const next_step, bool shoot, TanksState const* const tanks_state) { - if((int8_t) next_step.x < 0 || (int8_t) next_step.y < 0) { + if((int8_t)next_step.x < 0 || (int8_t)next_step.y < 0) { return true; } @@ -1533,7 +1533,7 @@ static void tanks_game_process_game_step(TanksState* const tanks_state) { } int32_t tanks_game_app(void* p) { - UNUSED(p); + UNUSED(p); srand(DWT->CYCCNT); FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(TanksEvent)); diff --git a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_console_output.c b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_console_output.c index b66e79a1f..45a64bf58 100644 --- a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_console_output.c +++ b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_console_output.c @@ -1,12 +1,12 @@ #include "../wifi_deauther_app_i.h" -void wifi_deauther_console_output_handle_rx_data_cb(uint8_t *buf, size_t len, void* context) { +void wifi_deauther_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) { furi_assert(context); WifideautherApp* app = context; // If text box store gets too big, then truncate it app->text_box_store_strlen += len; - if (app->text_box_store_strlen >= WIFI_deauther_TEXT_BOX_STORE_SIZE - 1) { + if(app->text_box_store_strlen >= WIFI_deauther_TEXT_BOX_STORE_SIZE - 1) { string_right(app->text_box_store, app->text_box_store_strlen / 2); app->text_box_store_strlen = string_size(app->text_box_store); } @@ -24,21 +24,22 @@ void wifi_deauther_scene_console_output_on_enter(void* context) { TextBox* text_box = app->text_box; text_box_reset(app->text_box); text_box_set_font(text_box, TextBoxFontText); - if (app->focus_console_start) { + if(app->focus_console_start) { text_box_set_focus(text_box, TextBoxFocusStart); } else { text_box_set_focus(text_box, TextBoxFocusEnd); } - if (app->is_command) { + if(app->is_command) { string_reset(app->text_box_store); app->text_box_store_strlen = 0; - if (0 == strncmp("help", app->selected_tx_string, strlen("help"))) { - const char* help_msg = "For app support/feedback,\nreach out to me:\n@cococode#6011 (discord)\n0xchocolate (github)\n"; + if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) { + const char* help_msg = + "For app support/feedback,\nreach out to me:\n@cococode#6011 (discord)\n0xchocolate (github)\n"; string_cat_str(app->text_box_store, help_msg); app->text_box_store_strlen += strlen(help_msg); } - if (app->show_stopscan_tip) { + if(app->show_stopscan_tip) { const char* help_msg = "Press BACK to send stopscan\n"; string_cat_str(app->text_box_store, help_msg); app->text_box_store_strlen += strlen(help_msg); @@ -51,11 +52,13 @@ void wifi_deauther_scene_console_output_on_enter(void* context) { view_dispatcher_switch_to_view(app->view_dispatcher, WifideautherAppViewConsoleOutput); // Register callback to receive data - wifi_deauther_uart_set_handle_rx_data_cb(app->uart, wifi_deauther_console_output_handle_rx_data_cb); // setup callback for rx thread + wifi_deauther_uart_set_handle_rx_data_cb( + app->uart, wifi_deauther_console_output_handle_rx_data_cb); // setup callback for rx thread // Send command with newline '\n' - if (app->is_command && app->selected_tx_string) { - wifi_deauther_uart_tx((uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string)); + if(app->is_command && app->selected_tx_string) { + wifi_deauther_uart_tx( + (uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string)); wifi_deauther_uart_tx((uint8_t*)("\n"), 1); } } @@ -82,7 +85,7 @@ void wifi_deauther_scene_console_output_on_exit(void* context) { wifi_deauther_uart_set_handle_rx_data_cb(app->uart, NULL); // Automatically stop the scan when exiting view - if (app->is_command) { + if(app->is_command) { wifi_deauther_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n")); } } \ No newline at end of file diff --git a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_start.c b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_start.c index 6bcb913b0..92b80b2cf 100644 --- a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_start.c +++ b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_start.c @@ -3,17 +3,9 @@ // For each command, define whether additional arguments are needed // (enabling text input to fill them out), and whether the console // text box should focus at the start of the output or the end -typedef enum { - NO_ARGS = 0, - INPUT_ARGS, - TOGGLE_ARGS -} InputArgs; +typedef enum { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs; -typedef enum { - FOCUS_CONSOLE_END = 0, - FOCUS_CONSOLE_START, - FOCUS_CONSOLE_TOGGLE -} FocusConsole; +typedef enum { FOCUS_CONSOLE_END = 0, FOCUS_CONSOLE_START, FOCUS_CONSOLE_TOGGLE } FocusConsole; #define SHOW_STOPSCAN_TIP (true) #define NO_TIP (false) @@ -31,34 +23,78 @@ typedef struct { // NUM_MENU_ITEMS defined in wifi_deauther_app_i.h - if you add an entry here, increment it! const WifideautherItem MenuItems[NUM_MENU_ITEMS] = { - { "View Log from", {"start", "end"}, 2, {}, NO_ARGS, FOCUS_CONSOLE_TOGGLE, NO_TIP }, - { "Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Stop", {""}, 1, {"stop all"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Scan", {"All", "SSIDs", "Stations"}, 3, {"scan", "scan aps", "scan stations"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Select", {"All", "SSIDs", "Stations"}, 3, {"select all", "select aps", "select stations"}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Deselect", {"All", "SSIDs", "Stations"}, 3, {"deselect all", "deselect aps", "deselect stations"}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Show", {"SSIDs", "Stations", "All", "Selected"}, 4, {"show ap", "show station", "show all", "show selected"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Attack", {"deauth", "deauthall", "beacon", "probe"}, 4, {"attack deauth", "attack deauthall", "attack beacon", "attack probe"}, NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP }, - { "Settings", {"Get", "Remove AP", "Set SSID", "Set Pass", "Save"}, 5, {"get settings", "set webinterface false", "set ssid: pwned", "set password: deauther", "save settings"}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Sysinfo", {""}, 1, {"sysinfo"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, - { "Reboot", {""}, 1, {"reboot"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP }, + {"View Log from", {"start", "end"}, 2, {}, NO_ARGS, FOCUS_CONSOLE_TOGGLE, NO_TIP}, + {"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"Stop", {""}, 1, {"stop all"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"Scan", + {"All", "SSIDs", "Stations"}, + 3, + {"scan", "scan aps", "scan stations"}, + NO_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, + {"Select", + {"All", "SSIDs", "Stations"}, + 3, + {"select all", "select aps", "select stations"}, + INPUT_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, + {"Deselect", + {"All", "SSIDs", "Stations"}, + 3, + {"deselect all", "deselect aps", "deselect stations"}, + INPUT_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, + {"Show", + {"SSIDs", "Stations", "All", "Selected"}, + 4, + {"show ap", "show station", "show all", "show selected"}, + NO_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, + {"Attack", + {"deauth", "deauthall", "beacon", "probe"}, + 4, + {"attack deauth", "attack deauthall", "attack beacon", "attack probe"}, + NO_ARGS, + FOCUS_CONSOLE_END, + SHOW_STOPSCAN_TIP}, + {"Settings", + {"Get", "Remove AP", "Set SSID", "Set Pass", "Save"}, + 5, + {"get settings", + "set webinterface false", + "set ssid: pwned", + "set password: deauther", + "save settings"}, + INPUT_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, + {"Sysinfo", {""}, 1, {"sysinfo"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"Reboot", {""}, 1, {"reboot"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, }; - static void wifi_deauther_scene_start_var_list_enter_callback(void* context, uint32_t index) { furi_assert(context); WifideautherApp* app = context; - if (app->selected_option_index[index] < MenuItems[index].num_options_menu) { - app->selected_tx_string = MenuItems[index].actual_commands[app->selected_option_index[index]]; + if(app->selected_option_index[index] < MenuItems[index].num_options_menu) { + app->selected_tx_string = + MenuItems[index].actual_commands[app->selected_option_index[index]]; } app->is_command = (1 <= index); app->is_custom_tx_string = false; app->selected_menu_index = index; - app->focus_console_start = (MenuItems[index].focus_console == FOCUS_CONSOLE_TOGGLE) ? (app->selected_option_index[index] == 0) : MenuItems[index].focus_console; + app->focus_console_start = (MenuItems[index].focus_console == FOCUS_CONSOLE_TOGGLE) ? + (app->selected_option_index[index] == 0) : + MenuItems[index].focus_console; app->show_stopscan_tip = MenuItems[index].show_stopscan_tip; - bool needs_keyboard = (MenuItems[index].needs_keyboard == TOGGLE_ARGS) ? (app->selected_option_index[index] != 0) : MenuItems[index].needs_keyboard; - if (needs_keyboard) { + bool needs_keyboard = (MenuItems[index].needs_keyboard == TOGGLE_ARGS) ? + (app->selected_option_index[index] != 0) : + MenuItems[index].needs_keyboard; + if(needs_keyboard) { view_dispatcher_send_custom_event(app->view_dispatcher, WifideautherEventStartKeyboard); } else { view_dispatcher_send_custom_event(app->view_dispatcher, WifideautherEventStartConsole); @@ -86,11 +122,17 @@ void wifi_deauther_scene_start_on_enter(void* context) { var_item_list, wifi_deauther_scene_start_var_list_enter_callback, app); VariableItem* item; - for (int i = 0; i < NUM_MENU_ITEMS; ++i) { - item = variable_item_list_add(var_item_list, MenuItems[i].item_string, MenuItems[i].num_options_menu, wifi_deauther_scene_start_var_list_change_callback, app); - if (MenuItems[i].num_options_menu) { + for(int i = 0; i < NUM_MENU_ITEMS; ++i) { + item = variable_item_list_add( + var_item_list, + MenuItems[i].item_string, + MenuItems[i].num_options_menu, + wifi_deauther_scene_start_var_list_change_callback, + app); + if(MenuItems[i].num_options_menu) { variable_item_set_current_value_index(item, app->selected_option_index[i]); - variable_item_set_current_value_text(item, MenuItems[i].options_menu[app->selected_option_index[i]]); + variable_item_set_current_value_text( + item, MenuItems[i].options_menu[app->selected_option_index[i]]); } } @@ -106,15 +148,17 @@ bool wifi_deauther_scene_start_on_event(void* context, SceneManagerEvent event) bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if (event.event == WifideautherEventStartKeyboard) { - scene_manager_set_scene_state(app->scene_manager, WifideautherSceneStart, app->selected_menu_index); + if(event.event == WifideautherEventStartKeyboard) { + scene_manager_set_scene_state( + app->scene_manager, WifideautherSceneStart, app->selected_menu_index); scene_manager_next_scene(app->scene_manager, WifideautherAppViewTextInput); - } else if (event.event == WifideautherEventStartConsole) { - scene_manager_set_scene_state(app->scene_manager, WifideautherSceneStart, app->selected_menu_index); + } else if(event.event == WifideautherEventStartConsole) { + scene_manager_set_scene_state( + app->scene_manager, WifideautherSceneStart, app->selected_menu_index); scene_manager_next_scene(app->scene_manager, WifideautherAppViewConsoleOutput); } consumed = true; - } else if (event.type == SceneManagerEventTypeTick) { + } else if(event.type == SceneManagerEventTypeTick) { app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list); consumed = true; } diff --git a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_text_input.c b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_text_input.c index a05feaf25..339b2f2a3 100644 --- a/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_text_input.c +++ b/applications/plugins/wifi_deauther/scenes/wifi_deauther_scene_text_input.c @@ -1,6 +1,5 @@ #include "../wifi_deauther_app_i.h" - void wifi_deauther_scene_text_input_callback(void* context) { WifideautherApp* app = context; @@ -10,7 +9,7 @@ void wifi_deauther_scene_text_input_callback(void* context) { void wifi_deauther_scene_text_input_on_enter(void* context) { WifideautherApp* app = context; - if (false == app->is_custom_tx_string) { + if(false == app->is_custom_tx_string) { // Fill text input with selected string so that user can add to it size_t length = strlen(app->selected_tx_string); furi_assert(length < WIFI_deauther_TEXT_INPUT_STORE_SIZE); @@ -19,27 +18,33 @@ void wifi_deauther_scene_text_input_on_enter(void* context) { // Add space - because flipper keyboard currently doesn't have a space app->text_input_store[length] = ' '; - app->text_input_store[length+1] = '\0'; + app->text_input_store[length + 1] = '\0'; app->is_custom_tx_string = true; } // Setup view TextInput* text_input = app->text_input; // Add help message to header - if (0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) { + if(0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) { text_input_set_header_text(text_input, "Enter # SSIDs to generate"); - } else if (0 == strncmp("ssid -a -n", app->selected_tx_string, strlen("ssid -a -n"))) { + } else if(0 == strncmp("ssid -a -n", app->selected_tx_string, strlen("ssid -a -n"))) { text_input_set_header_text(text_input, "Enter SSID name to add"); - } else if (0 == strncmp("ssid -r", app->selected_tx_string, strlen("ssid -r"))) { + } else if(0 == strncmp("ssid -r", app->selected_tx_string, strlen("ssid -r"))) { text_input_set_header_text(text_input, "Remove target from SSID list"); - } else if (0 == strncmp("select -a", app->selected_tx_string, strlen("select -a"))) { + } else if(0 == strncmp("select -a", app->selected_tx_string, strlen("select -a"))) { text_input_set_header_text(text_input, "Add target from AP list"); - } else if (0 == strncmp("select -s", app->selected_tx_string, strlen("select -s"))) { + } else if(0 == strncmp("select -s", app->selected_tx_string, strlen("select -s"))) { text_input_set_header_text(text_input, "Add target from SSID list"); } else { text_input_set_header_text(text_input, "Add command arguments"); } - text_input_set_result_callback(text_input, wifi_deauther_scene_text_input_callback, app, app->text_input_store, WIFI_deauther_TEXT_INPUT_STORE_SIZE, false); + text_input_set_result_callback( + text_input, + wifi_deauther_scene_text_input_callback, + app, + app->text_input_store, + WIFI_deauther_TEXT_INPUT_STORE_SIZE, + false); view_dispatcher_switch_to_view(app->view_dispatcher, WifideautherAppViewTextInput); } @@ -48,8 +53,8 @@ bool wifi_deauther_scene_text_input_on_event(void* context, SceneManagerEvent ev WifideautherApp* app = context; bool consumed = false; - if (event.type == SceneManagerEventTypeCustom) { - if (event.event == WifideautherEventStartConsole) { + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == WifideautherEventStartConsole) { // Point to custom string to send app->selected_tx_string = app->text_input_store; scene_manager_next_scene(app->scene_manager, WifideautherAppViewConsoleOutput); diff --git a/applications/plugins/wifi_deauther/wifi_deauther_app.c b/applications/plugins/wifi_deauther/wifi_deauther_app.c index 7d17a2369..11d389c00 100644 --- a/applications/plugins/wifi_deauther/wifi_deauther_app.c +++ b/applications/plugins/wifi_deauther/wifi_deauther_app.c @@ -47,17 +47,19 @@ WifideautherApp* wifi_deauther_app_alloc() { WifideautherAppViewVarItemList, variable_item_list_get_view(app->var_item_list)); - for (int i = 0; i < NUM_MENU_ITEMS; ++i) { + for(int i = 0; i < NUM_MENU_ITEMS; ++i) { app->selected_option_index[i] = 0; } app->text_box = text_box_alloc(); - view_dispatcher_add_view(app->view_dispatcher, WifideautherAppViewConsoleOutput, text_box_get_view(app->text_box)); + view_dispatcher_add_view( + app->view_dispatcher, WifideautherAppViewConsoleOutput, text_box_get_view(app->text_box)); string_init(app->text_box_store); string_reserve(app->text_box_store, WIFI_deauther_TEXT_BOX_STORE_SIZE); app->text_input = text_input_alloc(); - view_dispatcher_add_view(app->view_dispatcher, WifideautherAppViewTextInput, text_input_get_view(app->text_input)); + view_dispatcher_add_view( + app->view_dispatcher, WifideautherAppViewTextInput, text_input_get_view(app->text_input)); scene_manager_next_scene(app->scene_manager, WifideautherSceneStart); diff --git a/applications/plugins/wifi_deauther/wifi_deauther_uart.c b/applications/plugins/wifi_deauther/wifi_deauther_uart.c index ba756d8e5..10e73c323 100644 --- a/applications/plugins/wifi_deauther/wifi_deauther_uart.c +++ b/applications/plugins/wifi_deauther/wifi_deauther_uart.c @@ -10,8 +10,8 @@ struct WifideautherUart { WifideautherApp* app; FuriThread* rx_thread; StreamBufferHandle_t rx_stream; - uint8_t rx_buf[RX_BUF_SIZE+1]; - void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void* context); + uint8_t rx_buf[RX_BUF_SIZE + 1]; + void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context); }; typedef enum { @@ -19,7 +19,9 @@ typedef enum { WorkerEvtRxDone = (1 << 1), } WorkerEvtFlags; -void wifi_deauther_uart_set_handle_rx_data_cb(WifideautherUart* uart, void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void* context)) { +void wifi_deauther_uart_set_handle_rx_data_cb( + WifideautherUart* uart, + void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context)) { furi_assert(uart); uart->handle_rx_data_cb = handle_rx_data_cb; } @@ -48,10 +50,9 @@ static int32_t uart_worker(void* context) { furi_check((events & FuriFlagError) == 0); if(events & WorkerEvtStop) break; if(events & WorkerEvtRxDone) { - size_t len = - xStreamBufferReceive(uart->rx_stream, uart->rx_buf, RX_BUF_SIZE, 0); + size_t len = xStreamBufferReceive(uart->rx_stream, uart->rx_buf, RX_BUF_SIZE, 0); if(len > 0) { - if (uart->handle_rx_data_cb) uart->handle_rx_data_cb(uart->rx_buf, len, uart->app); + if(uart->handle_rx_data_cb) uart->handle_rx_data_cb(uart->rx_buf, len, uart->app); } } } @@ -61,12 +62,12 @@ static int32_t uart_worker(void* context) { return 0; } -void wifi_deauther_uart_tx(uint8_t *data, size_t len) { +void wifi_deauther_uart_tx(uint8_t* data, size_t len) { furi_hal_uart_tx(UART_CH, data, len); } WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app) { - WifideautherUart *uart = malloc(sizeof(WifideautherUart)); + WifideautherUart* uart = malloc(sizeof(WifideautherUart)); furi_hal_console_disable(); furi_hal_uart_set_br(UART_CH, BAUDRATE); diff --git a/applications/plugins/wifi_deauther/wifi_deauther_uart.h b/applications/plugins/wifi_deauther/wifi_deauther_uart.h index 0017519bb..534c2fdf7 100644 --- a/applications/plugins/wifi_deauther/wifi_deauther_uart.h +++ b/applications/plugins/wifi_deauther/wifi_deauther_uart.h @@ -6,7 +6,9 @@ typedef struct WifideautherUart WifideautherUart; -void wifi_deauther_uart_set_handle_rx_data_cb(WifideautherUart* uart, void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void* context)); -void wifi_deauther_uart_tx(uint8_t *data, size_t len); +void wifi_deauther_uart_set_handle_rx_data_cb( + WifideautherUart* uart, + void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context)); +void wifi_deauther_uart_tx(uint8_t* data, size_t len); WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app); void wifi_deauther_uart_free(WifideautherUart* uart); diff --git a/applications/services/desktop/scenes/desktop_scene_main.c b/applications/services/desktop/scenes/desktop_scene_main.c index b8a03f650..b38c96d2a 100644 --- a/applications/services/desktop/scenes/desktop_scene_main.c +++ b/applications/services/desktop/scenes/desktop_scene_main.c @@ -112,7 +112,8 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { break; } case DesktopMainEventOpenClock: { - LoaderStatus status = loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Main/Clock.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Main/Clock.fap")); consumed = true; break; } @@ -169,38 +170,38 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { break; } case DesktopMainEventOpenSnake: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/Snake.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/Snake.fap")); consumed = true; break; } case DesktopMainEventOpen2048: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/2048.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/2048.fap")); consumed = true; break; } case DesktopMainEventOpenZombiez: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/Zombiez.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/Zombiez.fap")); consumed = true; break; } case DesktopMainEventOpenTetris: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/Tetris.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/Tetris.fap")); consumed = true; break; } case DesktopMainEventOpenDOOM: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/DOOM.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/DOOM.fap")); consumed = true; break; } case DesktopMainEventOpenDice: { - LoaderStatus status = loader_start( - desktop->loader, "Applications", EXT_PATH("/apps/Games/Dice.fap")); + LoaderStatus status = + loader_start(desktop->loader, "Applications", EXT_PATH("/apps/Games/Dice.fap")); consumed = true; break; } diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 373ca6b63..7e8b3c7d9 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -85,7 +85,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { } else { str = "Set PIN + Off"; } - // } else if(i == DesktopLockMenuIndexGameMode) { + // } else if(i == DesktopLockMenuIndexGameMode) { // str = "Games Mode"; } else if(i == DesktopLockMenuIndexDummy) { if(m->dummy_mode) { @@ -151,7 +151,7 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { lock_menu->callback(DesktopLockMenuEventPinLock, lock_menu->context); } else if((idx == DesktopLockMenuIndexPinLockShutdown) && (event->type == InputTypeShort)) { lock_menu->callback(DesktopLockMenuEventPinLockShutdown, lock_menu->context); - // } else if((idx == DesktopLockMenuIndexGameMode) && (event->type == InputTypeShort)) { + // } else if((idx == DesktopLockMenuIndexGameMode) && (event->type == InputTypeShort)) { // desktop_view_lock_menu_dumbmode_changed(1); // DOLPHIN_DEED(getRandomDeed()); // lock_menu->callback(DesktopLockMenuEventExit, lock_menu->context); diff --git a/applications/services/desktop/views/desktop_view_main.c b/applications/services/desktop/views/desktop_view_main.c index 39881b824..3903160a1 100644 --- a/applications/services/desktop/views/desktop_view_main.c +++ b/applications/services/desktop/views/desktop_view_main.c @@ -84,7 +84,8 @@ bool desktop_main_input_callback(InputEvent* event, void* context) { } else if(event->key == InputKeyDown) { main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context); } else if(event->key == InputKeyLeft) { - main_view->callback(DesktopMainEventOpenSubRemote, main_view->context); // OPENS SUBGHZ REMOTE + main_view->callback( + DesktopMainEventOpenSubRemote, main_view->context); // OPENS SUBGHZ REMOTE } } } else if(main_view->is_gamemode == true) { @@ -105,9 +106,11 @@ bool desktop_main_input_callback(InputEvent* event, void* context) { } else if(event->key == InputKeyUp) { main_view->callback(DesktopMainEventOpenDOOM, main_view->context); // OPENS DOOM } else if(event->key == InputKeyDown) { - main_view->callback(DesktopMainEventOpenZombiez, main_view->context); // OPENS Zombiez + main_view->callback( + DesktopMainEventOpenZombiez, main_view->context); // OPENS Zombiez } else if(event->key == InputKeyLeft) { - main_view->callback(DesktopMainEventOpenTetris, main_view->context); // OPENS TETRIS + main_view->callback( + DesktopMainEventOpenTetris, main_view->context); // OPENS TETRIS } } } else { @@ -127,10 +130,12 @@ bool desktop_main_input_callback(InputEvent* event, void* context) { } else if(event->key == InputKeyUp) { main_view->callback(DesktopMainEventOpenSnake, main_view->context); // OPENS SNAKE } else if(event->key == InputKeyDown) { - main_view->callback(DesktopMainEventOpenZombiez, main_view->context); // OPENS Zombiez + main_view->callback( + DesktopMainEventOpenZombiez, main_view->context); // OPENS Zombiez } else if(event->key == InputKeyLeft) { - main_view->callback(DesktopMainEventOpenTetris, main_view->context); // OPENS TETRIS - } + main_view->callback( + DesktopMainEventOpenTetris, main_view->context); // OPENS TETRIS + } } } diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c index 78ab5cbac..6a1f7118c 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c @@ -151,10 +151,10 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent sme) consumed = true; break; // case SCENE_EVENT_SELECT_FAVORITE_GAME: - // scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 2); - // scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite); - // consumed = true; - // break; + // scene_manager_set_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite, 2); + // scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite); + // consumed = true; + // break; case SCENE_EVENT_SELECT_PIN_SETUP: scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinMenu); consumed = true; diff --git a/applications/settings/dolphin_passport/passport.c b/applications/settings/dolphin_passport/passport.c index ede818bd5..3eb2ce5ad 100644 --- a/applications/settings/dolphin_passport/passport.c +++ b/applications/settings/dolphin_passport/passport.c @@ -19,16 +19,15 @@ static const Icon* const portrait_happy[7] = { &I_G0ku, &I_g0ku_1, &I_g0ku_2, - &I_g0ku_3 - }; + &I_g0ku_3}; // static const Icon* const portrait_ok[MOODS_TOTAL] = { - // &I_passport_okay1_46x49, - // &I_passport_okay2_46x49, - // &I_passport_okay3_46x49}; +// &I_passport_okay1_46x49, +// &I_passport_okay2_46x49, +// &I_passport_okay3_46x49}; // static const Icon* const portrait_bad[MOODS_TOTAL] = { - // &I_passport_bad1_46x49, - // &I_passport_bad2_46x49, - // &I_passport_bad3_46x49}; +// &I_passport_bad1_46x49, +// &I_passport_bad2_46x49, +// &I_passport_bad3_46x49}; // static const Icon* const* portraits[MOODS_TOTAL] = {portrait_happy, portrait_ok, portrait_bad}; static const Icon* const* portraits[MOODS_TOTAL] = {portrait_happy}; @@ -49,8 +48,7 @@ static const char* const moods[16] = { "Annoyed", "Upset", "Angry", - "Furious" -}; + "Furious"}; static void input_callback(InputEvent* input, void* ctx) { FuriSemaphore* semaphore = ctx; @@ -87,7 +85,7 @@ static void render_callback(Canvas* canvas, void* ctx) { // multipass canvas_draw_icon(canvas, 0, 0, &I_passport_DB); - + // portrait furi_assert((stats->level > 0) && (stats->level <= 30)); uint16_t tmpLvl = 0; @@ -98,7 +96,7 @@ static void render_callback(Canvas* canvas, void* ctx) { if(stats->level > 24) tmpLvl = 5; if(stats->level > 27) tmpLvl = 6; canvas_draw_icon(canvas, 11, 2, portraits[mood][tmpLvl]); - + const char* my_name = furi_hal_version_get_name_ptr(); snprintf(level_str, 12, "Level: %hu", stats->level); snprintf(xp_str, 12, "%lu/%lu", xp_above_last_levelup, xp_for_current_level); @@ -114,7 +112,7 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_set_color(canvas, ColorWhite); canvas_draw_box(canvas, 123 - xp_progress, 45, xp_progress + 1, 5); canvas_set_color(canvas, ColorBlack); - } +} int32_t passport_app(void* p) { UNUSED(p); diff --git a/lib/subghz/protocols/kia.c b/lib/subghz/protocols/kia.c index 923fc0cbb..6fc106170 100644 --- a/lib/subghz/protocols/kia.c +++ b/lib/subghz/protocols/kia.c @@ -142,8 +142,7 @@ void subghz_protocol_decoder_kia_feed(void* context, bool level, uint32_t durati case KIADecoderStepSaveDuration: if(level) { if(duration >= - (uint32_t)( - subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) { + (uint32_t)(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) { //Found stop bit instance->decoder.parser_step = KIADecoderStepReset; if(instance->decoder.decode_count_bit ==