Compare commits

...

3 Commits

3 changed files with 24 additions and 50 deletions

View File

@ -39,11 +39,11 @@ ifeq ($(TARGETCASIO),"FXCG50")
$(info ********* Add Numworks modules ********* )
SRC_C += \
ports/sh/numworks/modkandinsky.c \
ports/sh/numworks/ion.c \
ports/sh/numworks/modion.c \
SRC_QSTR += \
ports/sh/numworks/modkandinsky.c \
ports/sh/numworks/ion.c \
ports/sh/numworks/modion.c \
endif

View File

@ -3,13 +3,8 @@
//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. //
//.-'` `---` ' License: MIT (except some files; see LICENSE) //
//---------------------------------------------------------------------------//
// pe.ion: `gint` module
//
// This module aims to wrap commonly-used gint functions (not all APIs are
// considered relevant for high-level Python development).
//---
// pe.io: Compatibility module for NumWorks Ion library
#include "console.h"
#include "py/objtuple.h"
#include "py/runtime.h"
#include <gint/keyboard.h>
@ -90,20 +85,6 @@ int KeyTranslationMap[ 53 ] = { 0x85, 0x86, 0x75, 0x76, 0x91, // gint LEFT, UP,
/* END OF KEY TRANSLATION */
#define FUN_0(NAME) MP_DEFINE_CONST_FUN_OBJ_0(ion_##NAME##_obj, ion_##NAME)
#define FUN_1(NAME) MP_DEFINE_CONST_FUN_OBJ_1(ion_##NAME##_obj, ion_##NAME)
#define FUN_2(NAME) MP_DEFINE_CONST_FUN_OBJ_2(ion_##NAME##_obj, ion_##NAME)
#define FUN_3(NAME) MP_DEFINE_CONST_FUN_OBJ_3(ion_##NAME##_obj, ion_##NAME)
#define FUN_VAR(NAME, MIN) \
MP_DEFINE_CONST_FUN_OBJ_VAR(ion_##NAME##_obj, MIN, ion_##NAME)
#define FUN_BETWEEN(NAME, MIN, MAX) \
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ion_##NAME##_obj, MIN, MAX, ion_##NAME)
STATIC mp_obj_t ion___init__(void) { return mp_const_none; }
/* <gint/keyboard.h> */
STATIC mp_obj_t ion_keydown(mp_obj_t arg1) {
mp_int_t key = mp_obj_get_int(arg1);
@ -121,22 +102,16 @@ STATIC mp_obj_t ion_keydown(mp_obj_t arg1) {
return mp_obj_new_bool(down);
}
FUN_1(keydown);
FUN_0(__init__);
MP_DEFINE_CONST_FUN_OBJ_1(ion_keydown_obj, ion_keydown);
/* Module definition */
// Helper: define object "ion_F_obj" as object "F" in the module
#define OBJ(F) \
{ MP_ROM_QSTR(MP_QSTR_##F), MP_ROM_PTR(&ion_##F##_obj) }
// Helper: define small integer constant "I" as "I" in the module
#define INT(I) \
{ MP_ROM_QSTR(MP_QSTR_##I), MP_OBJ_NEW_SMALL_INT(I) }
STATIC const mp_rom_map_elem_t ion_module_globals_table[] = {
{MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ion)},
OBJ(__init__),
/*Numworks keycodes */
/* BE CAREFUL THERE ARE MISSING SLOTS */
@ -192,7 +167,7 @@ STATIC const mp_rom_map_elem_t ion_module_globals_table[] = {
INT(KEY_ANS),
INT(KEY_EXE), // value 52
OBJ(keydown),
{ MP_ROM_QSTR(MP_QSTR_keydown), MP_ROM_PTR(&ion_keydown_obj) }
};
STATIC MP_DEFINE_CONST_DICT(ion_module_globals, ion_module_globals_table);

View File

@ -126,34 +126,34 @@ static mp_obj_t Kandinsky_color(size_t n, mp_obj_t const *args) {
}
// TODO: Use qstrs here
int Internal_Get_Color_From_String(const char *str) {
int Internal_Get_Color_From_String(int qstr) {
if (strcmp(str, "red") == 0 || strcmp(str, "r") == 0)
if (qstr == MP_QSTR_red || qstr == MP_QSTR_r)
return NW_RED;
else if (strcmp(str, "green") == 0 || strcmp(str, "g") == 0)
else if (qstr == MP_QSTR_green || qstr == MP_QSTR_g)
return NW_GREEN;
else if (strcmp(str, "blue") == 0 || strcmp(str, "b") == 0)
else if (qstr == MP_QSTR_blue || qstr == MP_QSTR_b)
return NW_BLUE;
else if (strcmp(str, "black") == 0 || strcmp(str, "k") == 0)
else if (qstr == MP_QSTR_black || qstr == MP_QSTR_k)
return NW_BLACK;
else if (strcmp(str, "white") == 0 || strcmp(str, "w") == 0)
else if (qstr == MP_QSTR_white || qstr == MP_QSTR_w)
return NW_WHITE;
else if (strcmp(str, "yellow") == 0 || strcmp(str, "y") == 0)
else if (qstr == MP_QSTR_yellow || qstr == MP_QSTR_y)
return NW_YELLOW;
else if (strcmp(str, "pink") == 0)
else if (qstr == MP_QSTR_pink)
return NW_PINK;
else if (strcmp(str, "magenta") == 0)
else if (qstr == MP_QSTR_magenta)
return NW_MAGENTA;
else if (strcmp(str, "grey") == 0 || strcmp(str, "gray") == 0)
else if (qstr == MP_QSTR_grey || qstr == MP_QSTR_gray)
return NW_GRAY;
else if (strcmp(str, "purple") == 0)
else if (qstr == MP_QSTR_purple)
return NW_PURPLE;
else if (strcmp(str, "orange") == 0)
else if (qstr == MP_QSTR_orange)
return NW_ORANGE;
else if (strcmp(str, "cyan") == 0)
else if (qstr == MP_QSTR_cyan)
return NW_CYAN;
else if (strcmp(str, "brown") == 0)
else if (qstr == MP_QSTR_brown)
return NW_BROWN;
else
return C_NONE;
@ -162,11 +162,8 @@ int Internal_Get_Color_From_String(const char *str) {
int Internal_Treat_Color(mp_obj_t color) {
const mp_obj_type_t *type = mp_obj_get_type(color);
if (type == &mp_type_str) {
size_t text_len;
char const *text = mp_obj_str_get_data(color, &text_len);
return Internal_Get_Color_From_String(text);
}
if (type == &mp_type_str)
return Internal_Get_Color_From_String(mp_obj_str_get_qstr(color));
else if (type == &mp_type_int)
return mp_obj_get_int(color);
@ -179,7 +176,9 @@ int Internal_Treat_Color(mp_obj_t color) {
int g = mp_obj_get_int(items[1]);
int b = mp_obj_get_int(items[2]);
return NW_RGB(r, g, b);
} else
}
else
return NW_BLACK;
}