1
- #include <stdlib.h>
2
1
#include "modtc32.h"
3
2
#include "port.h"
4
3
#include "py/binary.h"
5
4
#include "py/mphal.h"
6
5
#include "py/runtime.h"
6
+ #include <stdlib.h>
7
7
8
8
#include "extmod/font_petme128_8x8.h"
9
9
@@ -699,58 +699,72 @@ static mp_obj_t screen_poly(size_t n_args, const mp_obj_t *args_in) {
699
699
}
700
700
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (screen_poly_obj , 5 , 6 , screen_poly ) ;
701
701
702
- static void drawchar (char c , int x , int y , int col , int rx , int ry , int dx ,
703
- int dy ) {
702
+ static void drawchar (char c , int x , int y , int fg , int bg , int rx , int ry ,
703
+ int dx , int dy ) {
704
704
const uint8_t * cd = & font_petme128_8x8 [(c - 32 ) * 8 ];
705
705
// loop over char data
706
706
for (int j = 0 ; j < 8 ; j ++ ) {
707
707
uint8_t column = * cd ++ ;
708
- int k = 0 ;
709
- while (column ) {
710
- if (column & 1 ) { // only draw if pixel set
708
+ for ( int k = 0 ; k < 8 ; k ++ ) {
709
+ int c = (column & 1 ) ? fg : bg ;
710
+ if (c != - 1 ) {
711
711
int xx1 = x + rx * j + dx * k ;
712
712
int yy1 = y + ry * j + dy * k ;
713
713
int xx2 = xx1 + rx + dx ;
714
714
int yy2 = yy1 + ry + dy ;
715
- fill_rect (MIN (xx1 , xx2 ), MIN (yy1 , yy2 ), abs (rx + dx ), abs (ry + dy ),
716
- col );
715
+ fill_rect (MIN (xx1 , xx2 ), MIN (yy1 , yy2 ), abs (rx + dx ), abs (ry + dy ), c );
717
716
}
718
- k ++ ;
719
717
column >>= 1 ;
720
718
}
721
719
}
722
720
}
723
721
724
- static mp_obj_t screen_text (size_t n_args , const mp_obj_t * args_in ) {
722
+ static mp_obj_t screen_text (size_t n_args , const mp_obj_t * pos_args ,
723
+ mp_map_t * kw_args ) {
725
724
static const int8_t directions [4 ][2 ][2 ] = {{{1 , 0 }, {0 , 1 }},
726
725
{{0 , 1 }, {-1 , 0 }},
727
726
{{-1 , 0 }, {0 , -1 }},
728
727
{{0 , -1 }, {1 , 0 }}};
729
728
730
- const char * str = mp_obj_str_get_str (args_in [1 ]);
731
- mp_int_t x = mp_obj_get_int (args_in [2 ]);
732
- mp_int_t y = mp_obj_get_int (args_in [3 ]);
733
- mp_int_t col = 0xffff ;
734
- mp_int_t rx , ry ;
735
- mp_int_t dx , dy ;
736
- mp_int_t dir = 0 ;
737
- if (n_args >= 5 ) {
738
- col = mp_obj_get_int (args_in [4 ]);
739
- }
740
- if (n_args >= 6 ) {
741
- dir = mp_obj_get_int (args_in [5 ]) & 3 ;
742
- }
743
- rx = directions [dir ][0 ][0 ];
744
- ry = directions [dir ][0 ][1 ];
745
- dx = directions [dir ][1 ][0 ];
746
- dy = directions [dir ][1 ][1 ];
747
- if (n_args >= 7 ) {
748
- int scale = mp_obj_get_int (args_in [6 ]);
749
- rx *= scale ;
750
- ry *= scale ;
751
- dx *= scale ;
752
- dy *= scale ;
753
- }
729
+ enum {
730
+ ARG_self ,
731
+ ARG_text ,
732
+ ARG_x ,
733
+ ARG_y ,
734
+ ARG_fg ,
735
+ ARG_bg ,
736
+ ARG_dir ,
737
+ ARG_xscale ,
738
+ ARG_yscale
739
+ };
740
+
741
+ static const mp_arg_t allowed_args [] = {
742
+ {MP_QSTR_self , MP_ARG_REQUIRED | MP_ARG_OBJ },
743
+ {MP_QSTR_text , MP_ARG_REQUIRED | MP_ARG_OBJ },
744
+ {MP_QSTR_x , MP_ARG_REQUIRED | MP_ARG_INT },
745
+ {MP_QSTR_y , MP_ARG_REQUIRED | MP_ARG_INT },
746
+ {MP_QSTR_fg , MP_ARG_INT , {.u_int = 0xffff }},
747
+ {MP_QSTR_bg , MP_ARG_INT , {.u_int = -1 }},
748
+ {MP_QSTR_dir , MP_ARG_INT , {.u_int = 0 }},
749
+ {MP_QSTR_xscale , MP_ARG_INT , {.u_int = 1 }},
750
+ {MP_QSTR_yscale , MP_ARG_INT , {.u_int = 1 }}};
751
+
752
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
753
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ),
754
+ allowed_args , args );
755
+
756
+ const char * str = mp_obj_str_get_str (args [ARG_text ].u_obj );
757
+ mp_int_t x = args [ARG_x ].u_int ;
758
+ mp_int_t y = args [ARG_y ].u_int ;
759
+ mp_int_t fg = args [ARG_fg ].u_int ;
760
+ mp_int_t bg = args [ARG_bg ].u_int ;
761
+ mp_int_t dir = args [ARG_dir ].u_int ;
762
+ mp_int_t xscale = args [ARG_xscale ].u_int ;
763
+ mp_int_t yscale = args [ARG_yscale ].u_int ;
764
+ mp_int_t rx = directions [dir ][0 ][0 ] * xscale ;
765
+ mp_int_t ry = directions [dir ][0 ][1 ] * yscale ;
766
+ mp_int_t dx = directions [dir ][1 ][0 ] * xscale ;
767
+ mp_int_t dy = directions [dir ][1 ][1 ] * yscale ;
754
768
755
769
// loop over chars
756
770
for (; * str ; ++ str ) {
@@ -759,13 +773,13 @@ static mp_obj_t screen_text(size_t n_args, const mp_obj_t *args_in) {
759
773
if (chr < 32 || chr > 127 ) {
760
774
chr = 127 ;
761
775
}
762
- drawchar (chr , x , y , col , rx , ry , dx , dy );
776
+ drawchar (chr , x , y , fg , bg , rx , ry , dx , dy );
763
777
x += rx * 8 ;
764
778
y += ry * 8 ;
765
779
}
766
780
return mp_const_none ;
767
781
}
768
- static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (screen_text_obj , 4 , 7 , screen_text ) ;
782
+ static MP_DEFINE_CONST_FUN_OBJ_KW (screen_text_obj , 4 , screen_text ) ;
769
783
770
784
static const mp_rom_map_elem_t screen_locals_dict_table [] = {
771
785
{MP_ROM_QSTR (MP_QSTR_readreg ), MP_ROM_PTR (& screen_readreg_obj )},
0 commit comments