[WIP] cleaned and synchronised all Upsilon extension to umworks upstream branch #17

Draft
Slyvtt wants to merge 3 commits from Slyvtt/PythonExtra:numworks into numworks
11 changed files with 454 additions and 57 deletions

View File

@ -4,11 +4,13 @@ PythonExtra offre la possibilité d'utiliser certains modules de la Numworks afi
Il s'agit d'un Work in Progress (WIP) et le support est sujet à tests approfondis à ce stade. Le port concerne les modules `kandinsky`, `ion` et `time` de la Numworks qui sont spécifiques à la machine et sont désormais supportés via cette implémentation. Les modules `math`, `cmath`, `random` étant identiques entre la version `Numworks` et les modules `builtins` de MicroPython, ils ne font donc pas partie de cette implémentation mais sont parfaitement utilisables sans modification dans les scripts.
Note : les modules `turtle` et `matplotlib.pyplot` ne sont pas repris dans cette implémentation. Il est possible d'utiliser les modules `turtle`, `matplotlib` et `casioplot` de Casio Education qui sont parfaitement fonctionnels et fournis en example dans `ports/sh/examples`.
Note : les modules `turtle` et `matplotlib.pyplot` ne sont pas repris dans cette implémentation. Il est possible d'utiliser les modules `turtle`, `matplotlib` et `casioplot` de Casio Education qui sont parfaitement fonctionnels et fournis en exemple dans `ports/sh/examples`.
## `kandinsky`
### Version de base `kandinsky` Epsilon :
Le module `kandinsky` offre le support des primitives graphiques via les routines hautes performance de `gint`. Toutes les fonctions de ce module sont disponibles :
- `color(r,g,b)` : Génère la valeur de la couleur r,g,b. Vous pouvez aussi simplement utiliser un tuple pour définir une couleur : (r,g,b).
@ -36,6 +38,59 @@ Le module offre de plus un certain nombre de couleurs explicitement nommées et
- "cyan"
- "brown"
### Version étendue `kandinsky` Upsilon :
Le fork `Upsilon` de l'OS Numwork offre diverses méthodes additionnelles permettant d'étendre les capacités du module `kandinsky`.
- `draw_line(x1,y1,x2,y2,color)` : Dessine une ligne entre les points (x1,y1) et (x2,y2).
- `draw_circle(xc,yc,rc,color)` : Dessine un cercle de centre (xc,yc) et de rayon rc.
- `fill_circle(xc,yc,rc,color)` : Dessine un disque de centre (xc,yc) et de rayon rc.
- `fill_polygon(p,color)` : trace un polygone plein reliant tous les points founis dans le tableau p.
```
from math import ceil
from kandinsky import *
SCREEN_W, SCREEN_H = 320, 222
def mod(l):
x_min, y_min = l[0]
x_max, y_max = 0, 0
for k in range(len(l)):
x_min = min(x_min, l[k][0])
y_min = min(y_min, l[k][1])
x_max = max(x_max, l[k][0])
y_max = max(y_max, l[k][1])
fx = max(1, (x_max-x_min)/SCREEN_W)
fy = max(1, (y_max-y_min)/SCREEN_H)
for k in range(len(l)):
l[k][0] = ceil((l[k][0]-x_min)/fx)
l[k][1] = ceil((l[k][1]-y_min)/fy)
l = [
[0,200],
[400,200],
[400,250],
[450,150],
[0,200],
[2,62],
[223,236],
[253,222],
[274,236],
[350,184],
[121,2],
[2,62]
]
mod(l)
fill_polygon( l, (255, 0, 0) )
```
### Version étendue `kandinsky` pour fx-CG50 / Graph 90+E :
Les fonctions suivantes sont des ajouts pour tirer partie de l'écran large de la fxCG et qui sont donc une extension du module `Kandinsky`. Elles ne sont donc par définition pas compatible avec le Python Numwork. Ces fonctions sont reconnaisables à leurs appellations qui commencent toutes par `CGEXT_` :
- `CGEXT_Enable_Wide_Screen()` : Active l'écran étendu de la fxCG, aucun paramètre n'est nécessaire. Les coordonnées x de l'écran physique peuvent être négatives pour empiéter sur la bande blanche de gauche et supérieures à 319 pixels pour empièter sur la bande blanche de droite;
@ -53,62 +108,81 @@ Note 2 : En mode non étendu (par défaut à l'initialisation du module `Kandins
## `ion`
### Version de base `ion` Epsilon :
Le module `ion` donne accès à la fonction `keydown(k)` qui renvoie True si la touche k placée en argument est appuyée et False sinon.
La "conversion" des touches entre la machine Numworks et Casio fxCG50 se fait selon le mapping suivant :
| Numworks | Casio fxCG50 | Numworks Key # |
|----------|--------------|---------------------|
| KEY_LEFT | KEY_LEFT | 0 |
| KEY_UP | KEY_UP | 1 |
| KEY_DOWN | KEY_DOWN | 2 |
| KEY_RIGHT | KEY_RIGHT | 2 |
| KEY_OK | KEY_F1 | 4 |
| KEY_BACK | KEY_EXIT | 5 |
| KEY_HOME | KEY_MENU | 6 |
| KEY_ONOFF | KEY_ACON | 7 |
| ... | ... | ... |
| KEY_SHIFT | KEY_SHIFT | 12 |
| KEY_ALPHA | KEY_ALPHA | 13 |
| KEY_XNT | KEY_XOT | 14 |
| KEY_VAR | KEY_VARS | 15 |
| KEY_TOOLBOX | KEY_OPTN | 16 |
| KEY_BACKSPACE | KEY_DEL | 17 |
| KEY_EXP | KEY_EXP | 17 |
| KEY_LN | KEY_LN | 19 |
| KEY_LOG | KEY_LOG | 20 |
| KEY_IMAGINARY | KEY_F2 | 21 |
| KEY_COMMA | KEY_COMMA | 22 |
| KEY_POWER | KEY_POWER | 23 |
| KEY_SINE | KEY_SIN | 24 |
| KEY_COSINE | KEY_COS | 25 |
| KEY_TANGENT | KEY_TAN | 26 |
| KEY_PI | KEY_F3 | 27 |
| KEY_SQRT | KEY_F4 | 28 |
| KEY_SQUARE | KEY_SQUARE | 29 |
| KEY_SEVEN | KEY_7 | 30 |
| KEY_EIGHT | KEY_8 | 31 |
| KEY_NINE | KEY_9 | 32 |
| KEY_LEFTPARENTHESIS | KEY_LEFTP | 33 |
| KEY_RIGHTPARENTHESIS | KEY_RIGHTP | 34 |
| ... | ... | ... |
| KEY_FOUR | KEY_4 | 36 |
| KEY_FIVE | KEY_5 | 37 |
| KEY_SIX | KEY_6 | 38 |
| KEY_MULTIPLICATION | KEY_MUL | 39 |
| KEY_DIVISION | KEY_DIV | 40 |
| ... | ... | ... |
| KEY_ONE | KEY_1 | 42 |
| KEY_TWO | KEY_2 | 43 |
| KEY_THREE | KEY_3 | 44 |
| KEY_PLUS | KEY_ADD | 45 |
| KEY_MINUS | KEY_SUB | 46 |
| ... | ... | ... |
| KEY_ZERO | KEY_0 | 48 |
| KEY_DOT | KEY_DOT | 49 |
| KEY_EE | KEY_F5 | 50 |
| KEY_ANS | KEY_NEG | 51 |
| KEY_EXE | KEY_EXE | 52 |
| Numworks | Casio fxCG50 | Numworks Key # | Upsilon Key Name |
|----------|--------------|---------------------|---------------------|
| KEY_LEFT | KEY_LEFT | 0 | 'left' |
| KEY_UP | KEY_UP | 1 | 'up' |
| KEY_DOWN | KEY_DOWN | 2 | 'down' |
| KEY_RIGHT | KEY_RIGHT | 2 | 'right' |
| KEY_OK | KEY_F1 | 4 | 'OK' |
| KEY_BACK | KEY_EXIT | 5 | 'back' |
| KEY_HOME | KEY_MENU | 6 | 'home' |
| KEY_ONOFF | KEY_ACON | 7 | 'onOff' |
| ... | ... | ... | ... |
| KEY_SHIFT | KEY_SHIFT | 12 | 'shift' |
| KEY_ALPHA | KEY_ALPHA | 13 | 'alpha' |
| KEY_XNT | KEY_XOT | 14 | 'xnt' |
| KEY_VAR | KEY_VARS | 15 | 'var' |
| KEY_TOOLBOX | KEY_OPTN | 16 | 'toolbox' |
| KEY_BACKSPACE | KEY_DEL | 17 | 'backspace' |
| KEY_EXP | KEY_EXP | 17 | 'exp' |
| KEY_LN | KEY_LN | 19 | 'ln' |
| KEY_LOG | KEY_LOG | 20 | 'log' |
| KEY_IMAGINARY | KEY_F2 | 21 | 'imaginary' |
| KEY_COMMA | KEY_COMMA | 22 | 'comma' |
| KEY_POWER | KEY_POWER | 23 | 'power' |
| KEY_SINE | KEY_SIN | 24 | 'sin' |
| KEY_COSINE | KEY_COS | 25 | 'cos' |
| KEY_TANGENT | KEY_TAN | 26 | 'tan' |
| KEY_PI | KEY_F3 | 27 | 'pi' |
| KEY_SQRT | KEY_F4 | 28 | 'sqrt' |
| KEY_SQUARE | KEY_SQUARE | 29 | 'square' |
| KEY_SEVEN | KEY_7 | 30 | '7' |
| KEY_EIGHT | KEY_8 | 31 | '8' |
| KEY_NINE | KEY_9 | 32 | '9' |
| KEY_LEFTPARENTHESIS | KEY_LEFTP | 33 | '\_paren\_open\_' |
| KEY_RIGHTPARENTHESIS | KEY_RIGHTP | 34 | '\_paren\_close\_' |
| ... | ... | ... | ... |
| KEY_FOUR | KEY_4 | 36 | '4' |
| KEY_FIVE | KEY_5 | 37 | '5' |
| KEY_SIX | KEY_6 | 38 | '6' |
| KEY_MULTIPLICATION | KEY_MUL | 39 | '\_star\_' |
| KEY_DIVISION | KEY_DIV | 40 | '\_slash\_' |
| ... | ... | ... | ... |
| KEY_ONE | KEY_1 | 42 | '1' |
| KEY_TWO | KEY_2 | 43 | '2' |
| KEY_THREE | KEY_3 | 44 | '3' |
| KEY_PLUS | KEY_ADD | 45 | '\_plus\_' |
| KEY_MINUS | KEY_SUB | 46 | '\_hyphen\_' |
| ... | ... | ... | ... |
| KEY_ZERO | KEY_0 | 48 | '0' |
| KEY_DOT | KEY_DOT | 49 | '\_dot\_' |
| KEY_EE | KEY_F5 | 50 | 'EE' |
| KEY_ANS | KEY_NEG | 51 | 'Ans' |
| KEY_EXE | KEY_EXE | 52 | 'EXE' |
### Version de base `ion` Upsilon :
Upsilon étend les méthodes du module `ion` en ajoutant les fonctions suivantes :
- `get_keys()` : renvoi la liste des touches pressées (au format texte) selon les codes définis dans le tableau ci-dessus.
- `set_brightness( level )` : change la luminosité de l'écran (level prenant une valeur comprise entre 0 et 240 comprises).
- `get_brightness( )` : retourne la luminosité courante de l'écran (renvoie une valeur comprise entre 0 et 240 comprises).
- `battery( )` : retourne le voltage courant de la batterie (des piles sur Casio-fxCG).
- `battery_level( )` : retourne le l'état de charge de la batterie (des piles) sous forme d'un entier compris en 0 (déchargée(s)) et 4 (complètement chargée(s)).
- `battery_ischarging( )` : renvoie `True` si batterie en charge et `False` sinon (rencoie toujours `False`sur Casio fx-CG car piles sans fonction de recharge).
## `time`

View File

@ -40,6 +40,12 @@ ifeq ($(TARGETCASIO),"FXCG50")
SRC_C += \
ports/sh/numworks/modkandinsky.c \
ports/sh/numworks/modion.c \
ports/sh/numworks/syscalls/screenlight.c
SRC_ASM += \
ports/sh/numworks/syscalls/GetBatteryType.S \
ports/sh/numworks/syscalls/GetMainBatteryVoltage.S \
ports/sh/numworks/syscalls/BdispDDRegisterSelect.S
SRC_QSTR += \
ports/sh/numworks/modkandinsky.c \
@ -64,7 +70,7 @@ endif
ASSETS_O := $(SH_ASSETS:%=$(BUILD)/sh_assets/%.o)
OBJ = $(PY_O) $(ASSETS_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ = $(PY_O) $(ASSETS_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(addprefix $(BUILD)/, $(SRC_ASM:.S=.o))
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(Q)$(CC:gcc=objcopy) -O binary -R .bss -R .gint_bss $< $@

View File

@ -12,6 +12,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <gint/gint.h>
#include "syscalls/battery.h"
#include "syscalls/screenlight.h"
/* BEGINING OF KEY TRANSLATION */
// the following table aims at providing a keymap for NW on Casio
@ -69,7 +74,7 @@
#define KEY_ANS 51
#define KEY_EXE 52
int KeyTranslationMap[ 53 ] = { 0x85, 0x86, 0x75, 0x76, 0x91, // gint LEFT, UP, DOWN, RIGHT, F1
int KeyTranslationMap_NW_to_Casio[ 53 ] = { 0x85, 0x86, 0x75, 0x76, 0x91, // gint LEFT, UP, DOWN, RIGHT, F1
0x74, 0x84, 0x07, -1, -1, // gint EXIT, MENU, ACON, __, __
-1, -1, 0x81, 0x71, 0x61, // gint __, __, SHIFT, ALPHA, XOT
0x83, 0x82, 0x44, 0x13, 0x63, // gint VARS, OPTN, DEL, EXP, LN
@ -82,6 +87,63 @@ int KeyTranslationMap[ 53 ] = { 0x85, 0x86, 0x75, 0x76, 0x91, // gint LEFT, UP,
0x95, 0x14, 0x15 }; // gint F5, NEG, EXE
typedef struct
{
int key;
mp_obj_t string;
} key2mp;
static const key2mp keyMapping[] =
{
{ 0x85, MP_ROM_QSTR(MP_QSTR_left) },
{ 0x86, MP_ROM_QSTR(MP_QSTR_up) },
{ 0x75, MP_ROM_QSTR(MP_QSTR_down) },
{ 0x76, MP_ROM_QSTR(MP_QSTR_right) },
{ 0x91, MP_ROM_QSTR(MP_QSTR_OK) },
{ 0x74, MP_ROM_QSTR(MP_QSTR_back) },
{ 0x84, MP_ROM_QSTR(MP_QSTR_home) },
{ 0x07, MP_ROM_QSTR(MP_QSTR_onOff) },
{ 0x81, MP_ROM_QSTR(MP_QSTR_shift) },
{ 0x71, MP_ROM_QSTR(MP_QSTR_alpha) },
{ 0x61, MP_ROM_QSTR(MP_QSTR_xnt) },
{ 0x83, MP_ROM_QSTR(MP_QSTR_var) },
{ 0x82, MP_ROM_QSTR(MP_QSTR_toolbox) },
{ 0x44, MP_ROM_QSTR(MP_QSTR_backspace) },
{ 0x13, MP_ROM_QSTR(MP_QSTR_exp) },
{ 0x63, MP_ROM_QSTR(MP_QSTR_ln) },
{ 0x62, MP_ROM_QSTR(MP_QSTR_log) },
{ 0x92, MP_ROM_QSTR(MP_QSTR_imaginary) },
{ 0x55, MP_ROM_QSTR(MP_QSTR_comma) },
{ 0x73, MP_ROM_QSTR(MP_QSTR_power) },
{ 0x64, MP_ROM_QSTR(MP_QSTR_sin) },
{ 0x65, MP_ROM_QSTR(MP_QSTR_cos) },
{ 0x66, MP_ROM_QSTR(MP_QSTR_tan) },
{ 0x93, MP_ROM_QSTR(MP_QSTR_pi) },
{ 0x94, MP_ROM_QSTR(MP_QSTR_sqrt) },
{ 0x72, MP_ROM_QSTR(MP_QSTR_square) },
{ 0x41, MP_ROM_QSTR(MP_QSTR_7) },
{ 0x42, MP_ROM_QSTR(MP_QSTR_8) },
{ 0x43, MP_ROM_QSTR(MP_QSTR_9) },
{ 0x53, MP_ROM_QSTR(MP_QSTR__paren_open_) },
{ 0x54, MP_ROM_QSTR(MP_QSTR__paren_close_) },
{ 0x31, MP_ROM_QSTR(MP_QSTR_4) },
{ 0x32, MP_ROM_QSTR(MP_QSTR_5) },
{ 0x33, MP_ROM_QSTR(MP_QSTR_6) },
{ 0x34, MP_ROM_QSTR(MP_QSTR__star_) },
{ 0x35, MP_ROM_QSTR(MP_QSTR__slash_) },
{ 0x21, MP_ROM_QSTR(MP_QSTR_1) },
{ 0x22, MP_ROM_QSTR(MP_QSTR_2) },
{ 0x23, MP_ROM_QSTR(MP_QSTR_3) },
{ 0x24, MP_ROM_QSTR(MP_QSTR__plus_) },
{ 0x25, MP_ROM_QSTR(MP_QSTR__hyphen_) },
{ 0x11, MP_ROM_QSTR(MP_QSTR_0) },
{ 0x12, MP_ROM_QSTR(MP_QSTR__dot_) },
{ 0x95, MP_ROM_QSTR(MP_QSTR_EE) },
{ 0x14, MP_ROM_QSTR(MP_QSTR_Ans) },
{ 0x15, MP_ROM_QSTR(MP_QSTR_EXE) },
};
/* END OF KEY TRANSLATION */
@ -91,7 +153,7 @@ STATIC mp_obj_t ion_keydown(mp_obj_t arg1) {
if (key < KEY_LEFT || key > KEY_EXE )
return mp_obj_new_bool(false);
int translatedKey = KeyTranslationMap[ key ];
int translatedKey = KeyTranslationMap_NW_to_Casio[ key ];
if (translatedKey==-1)
return mp_obj_new_bool(false);
@ -102,7 +164,65 @@ STATIC mp_obj_t ion_keydown(mp_obj_t arg1) {
return mp_obj_new_bool(down);
}
/* The following function are coming from the Upsilon extension of NW Ion methods */
STATIC mp_obj_t ion_battery( void ) {
int voltage = (int) gint_world_switch( GINT_CALL( GetMainBatteryVoltage, 1) );
float value = ((float) voltage) / 100.0f;
return mp_obj_new_float( value );
}
STATIC mp_obj_t ion_battery_level( void ) {
int voltage = (int) gint_world_switch( GINT_CALL( GetMainBatteryVoltage, 1) );
if (voltage>=0 && voltage<=360) return mp_obj_new_int(0);
else if (voltage>360 && voltage<=370) return mp_obj_new_int(1);
else if (voltage>370 && voltage<=380) return mp_obj_new_int(2);
else return mp_obj_new_int(3);
}
STATIC mp_obj_t ion_battery_charging( void ) {
/* this function give the charging status of the numworks : if plugged return True and False otherwise */
/* as the Casio is not using a battery, always return False */
return mp_obj_new_bool( false );
}
STATIC mp_obj_t ion_get_keys( void ) {
mp_obj_t result = mp_obj_new_set(0, NULL);
clearevents();
for (unsigned i = 0; i < sizeof(keyMapping)/sizeof(key2mp); i++) {
if (keydown(keyMapping[i].key) !=0 ) {
mp_obj_set_store(result, keyMapping[i].string);
}
}
return result;
}
STATIC mp_obj_t ion_set_brightness(mp_obj_t arg1) {
mp_int_t level = mp_obj_get_int(arg1);
if (level<0) level=0;
else if (level>240) level=240;
gint_world_switch( GINT_CALL( setRawBacklightSubLevel, level ) );
return mp_const_none;
}
STATIC mp_obj_t ion_get_brightness( void ) {
mp_int_t level = (int) gint_world_switch( GINT_CALL( getRawBacklightSubLevel ) );
return mp_obj_new_int( level );
}
MP_DEFINE_CONST_FUN_OBJ_1(ion_keydown_obj, ion_keydown);
MP_DEFINE_CONST_FUN_OBJ_0(ion_battery_obj, ion_battery);
MP_DEFINE_CONST_FUN_OBJ_0(ion_battery_level_obj, ion_battery_level);
MP_DEFINE_CONST_FUN_OBJ_0(ion_battery_charging_obj, ion_battery_charging);
MP_DEFINE_CONST_FUN_OBJ_0(ion_get_keys_obj, ion_get_keys);
MP_DEFINE_CONST_FUN_OBJ_1(ion_set_brightness_obj, ion_set_brightness);
MP_DEFINE_CONST_FUN_OBJ_0(ion_get_brightness_obj, ion_get_brightness);
/* Module definition */
@ -167,7 +287,15 @@ STATIC const mp_rom_map_elem_t ion_module_globals_table[] = {
INT(KEY_ANS),
INT(KEY_EXE), // value 52
{ MP_ROM_QSTR(MP_QSTR_keydown), MP_ROM_PTR(&ion_keydown_obj) }
{ MP_ROM_QSTR(MP_QSTR_keydown), MP_ROM_PTR(&ion_keydown_obj) },
/* Upsilon only objects */
{ MP_ROM_QSTR(MP_QSTR_battery), MP_ROM_PTR(&ion_battery_obj) },
{ MP_ROM_QSTR(MP_QSTR_battery_level), MP_ROM_PTR(&ion_battery_level_obj) },
{ MP_ROM_QSTR(MP_QSTR_battery_charging), MP_ROM_PTR(&ion_battery_charging_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_keys), MP_ROM_PTR(&ion_get_keys_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_brightness), MP_ROM_PTR(&ion_set_brightness_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_brightness), MP_ROM_PTR(&ion_get_brightness_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ion_module_globals, ion_module_globals_table);

View File

@ -285,6 +285,84 @@ static mp_obj_t Kandinsky_draw_string(size_t n, mp_obj_t const *args) {
return mp_const_none;
}
/* Start of Upsilon extension of Kandinsky module */
static mp_obj_t Kandinsky_draw_line(size_t n, mp_obj_t const *args) {
mp_int_t x1 = mp_obj_get_int(args[0]) + DELTAXNW;
mp_int_t y1 = mp_obj_get_int(args[1]) + DELTAYNW;
mp_int_t x2 = mp_obj_get_int(args[2]) + DELTAXNW;
mp_int_t y2 = mp_obj_get_int(args[3]) + DELTAYNW;
mp_int_t color = Internal_Treat_Color(args[4]);
set_window();
dline(x1, y1, x2, y2, color);
reset_window();
return mp_const_none;
}
static mp_obj_t Kandinsky_draw_circle(size_t n, mp_obj_t const *args) {
mp_int_t cx = mp_obj_get_int(args[0]) + DELTAXNW;
mp_int_t cy = mp_obj_get_int(args[1]) + DELTAYNW;
mp_int_t r = mp_obj_get_int(args[2]);
mp_int_t color = Internal_Treat_Color(args[3]);
set_window();
dcircle(cx, cy, r, C_NONE, color);
reset_window();
return mp_const_none;
}
static mp_obj_t Kandinsky_fill_circle(size_t n, mp_obj_t const *args) {
mp_int_t cx = mp_obj_get_int(args[0]) + DELTAXNW;
mp_int_t cy = mp_obj_get_int(args[1]) + DELTAYNW;
mp_int_t r = mp_obj_get_int(args[2]);
mp_int_t color = Internal_Treat_Color(args[3]);
set_window();
dcircle(cx, cy, r, color, C_NONE);
reset_window();
return mp_const_none;
}
/* TODO: implement the fill polygon method */
/* so far the coordinates are set in the pointsX and pointsY arrays */
static mp_obj_t Kandinsky_fill_polygon(size_t n, mp_obj_t const *args) {
size_t itemLength;
mp_obj_t * items;
mp_obj_get_array(args[0], &itemLength, &items);
mp_int_t fill_color = Internal_Treat_Color(args[1]);
mp_int_t border_color = C_NONE;
if (n==3)
border_color = Internal_Treat_Color(args[2]);
int pointsX[itemLength];
int pointsY[itemLength];
if (itemLength < 3) return mp_const_none;
for(int i=0; i<(int)itemLength; i++) {
mp_obj_t *coordinates;
mp_obj_get_array_fixed_n(items[i], 2, &coordinates);
pointsX[i] = mp_obj_get_int(coordinates[0]) + DELTAXNW;
pointsY[i] = mp_obj_get_int(coordinates[1]) + DELTAYNW;
}
set_window();
dpoly( pointsX, pointsY, itemLength, fill_color, border_color );
reset_window();
return mp_const_none;
}
/* start of fxCG wide screen extension of Kandinsky module */
static mp_obj_t Kandinsky_CGEXT_Enable_Wide_Screen( void ) {
is_dwindowed = false; // we mark as not windowed
@ -312,6 +390,11 @@ static mp_obj_t Kandinsky_CGEXT_Set_Margin_Color( mp_obj_t color ) {
return mp_obj_new_bool( is_dwindowed );
}
/* Extension of Kandinsky from Upsilon - all names starting with "CGEXT_" */
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(Kandinsky_draw_line_obj,5, 5, Kandinsky_draw_line);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(Kandinsky_draw_circle_obj, 4, 4, Kandinsky_draw_circle);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(Kandinsky_fill_circle_obj, 4, 4, Kandinsky_fill_circle);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(Kandinsky_fill_polygon_obj, 2, 3, Kandinsky_fill_polygon);
/* Extension of Kandinsky for fxCG - all names starting with "CGEXT_" */
MP_DEFINE_CONST_FUN_OBJ_0(Kandinsky_CGEXT_Enable_Wide_Screen_obj, Kandinsky_CGEXT_Enable_Wide_Screen);
MP_DEFINE_CONST_FUN_OBJ_0(Kandinsky_CGEXT_Disable_Wide_Screen_obj, Kandinsky_CGEXT_Disable_Wide_Screen);
@ -333,10 +416,16 @@ STATIC const mp_rom_map_elem_t kandinsky_module_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&Kandinsky_set_pixel_obj)},
{MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(&Kandinsky_get_pixel_obj)},
{MP_ROM_QSTR(MP_QSTR_draw_string), MP_ROM_PTR(&Kandinsky_draw_string_obj)},
{MP_ROM_QSTR(MP_QSTR_CGEXT_Enable_Wide_Screen), MP_ROM_PTR(&Kandinsky_CGEXT_Enable_Wide_Screen_obj)},
{MP_ROM_QSTR(MP_QSTR_CGEXT_Disable_Wide_Screen), MP_ROM_PTR(&Kandinsky_CGEXT_Disable_Wide_Screen_obj)},
{MP_ROM_QSTR(MP_QSTR_CGEXT_Is_Wide_Screen_Enabled), MP_ROM_PTR(&Kandinsky_CGEXT_Is_Wide_Screen_Enabled_obj)},
{MP_ROM_QSTR(MP_QSTR_CGEXT_Set_Margin_Color), MP_ROM_PTR(&Kandinsky_CGEXT_Set_Margin_Color_obj)},
{MP_ROM_QSTR(MP_QSTR_draw_line), MP_ROM_PTR(&Kandinsky_draw_line_obj) },
{MP_ROM_QSTR(MP_QSTR_draw_circle), MP_ROM_PTR(&Kandinsky_draw_circle_obj) },
{MP_ROM_QSTR(MP_QSTR_fill_circle), MP_ROM_PTR(&Kandinsky_fill_circle_obj) },
{MP_ROM_QSTR(MP_QSTR_fill_polygon), MP_ROM_PTR(&Kandinsky_fill_polygon_obj) },
};
STATIC MP_DEFINE_CONST_DICT(kandinsky_module_globals,
kandinsky_module_globals_table);

View File

@ -0,0 +1,3 @@
#include "asm.h"
SYSCALL(_Bdisp_DDRegisterSelect, 0x01a2)

View File

@ -0,0 +1,4 @@
#include "asm.h"
SYSCALL( _GetBatteryType, 0x12D5)

View File

@ -0,0 +1,4 @@
#include "asm.h"
SYSCALL( _GetMainBatteryVoltage, 0x1186)

View File

@ -0,0 +1,30 @@
#ifndef _SYSCALL_H_
#define _SYSCALL_H_
/* template for generic functions with global name */
/*#define _C_LABEL(x) _ ## x*/ /* prefix fn name with _ */
#define _C_LABEL(x) x
#define _ENTRY(name) \
.text; .align 2; .global name; name:
#define ENTRY(name) \
_ENTRY(_C_LABEL(name))
/* template for syscalls */
#define SYSCALL_BARE(name, x) \
ENTRY(name) \
mov.l sc_addr, r2; \
mov.l 1f, r0; \
jmp @r2; \
nop; \
1: .long x
/* allow to have several calls in one object, by specifying
* the SYSCALL_ADDRESS separately at the end */
#define SYSCALL_ADDRESS \
sc_addr: .long 0x80020070
#define SYSCALL(name, x) \
SYSCALL_BARE(name, x) ; \
SYSCALL_ADDRESS
#endif

View File

@ -0,0 +1,22 @@
#ifndef _FXCG_BATTERY_H
#define _FXCG_BATTERY_H
#ifdef __cplusplus
extern "C" {
#endif
/* The parameter one should be always 1.
Seems to return the battery voltage*100. */
int GetMainBatteryVoltage( int one );
/* returns the battery type.
1: Alkaline batteries
2: Ni-MH */
unsigned char GetBatteryType( void );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,14 @@
#include "screenlight.h"
int getRawBacklightSubLevel()
{
Bdisp_DDRegisterSelect(0x5a1);
return (LCDC & 0xFF) - 6;
}
void setRawBacklightSubLevel(int level)
{
Bdisp_DDRegisterSelect(0x5a1);
LCDC = (level & 0xFF) + 6;
}

View File

@ -0,0 +1,23 @@
#ifndef _FXCG_SCREENLIGHT_H
#define _FXCG_SCREENLIGHT_H
#ifdef __cplusplus
extern "C" {
#endif
#define LCDC *(unsigned int*)(0xB4000000)
void Bdisp_DDRegisterSelect( int registerno );
int getRawBacklightSubLevel();
void setRawBacklightSubLevel(int level);
#ifdef __cplusplus
}
#endif
#endif