45
45
46
46
typedef struct _mp_obj__EVE_t {
47
47
mp_obj_base_t base ;
48
- mp_obj_t dest [3 ];
49
- size_t n ;
50
- uint8_t buf [512 ];
48
+ mp_obj_t dest [3 ]; // Own 'write' method, plus argument
49
+ int vscale ; // fixed-point scaling used for Vertex2f
50
+ size_t n ; // Current size of command buffer
51
+ uint8_t buf [512 ]; // Command buffer
51
52
} mp_obj__EVE_t ;
52
53
53
54
STATIC const mp_obj_type_t _EVE_type ;
@@ -59,7 +60,6 @@ STATIC void _write(mp_obj__EVE_t *_EVE, mp_obj_t b) {
59
60
60
61
STATIC mp_obj_t _register (mp_obj_t self , mp_obj_t o ) {
61
62
mp_obj__EVE_t * _EVE = mp_instance_cast_to_native_base (self , & _EVE_type );
62
- _EVE -> n = 0 ;
63
63
mp_load_method (o , MP_QSTR_write , _EVE -> dest );
64
64
return mp_const_none ;
65
65
}
@@ -115,14 +115,24 @@ STATIC mp_obj_t _cmd0(mp_obj_t self, mp_obj_t n) {
115
115
}
116
116
STATIC MP_DEFINE_CONST_FUN_OBJ_2 (cmd0_obj , _cmd0 );
117
117
118
- STATIC mp_obj_t _vertex2f (mp_obj_t self , mp_obj_t a0 , mp_obj_t a1 ) {
119
- int16_t x = (int16_t )(16 * mp_obj_get_float (a0 ));
120
- int16_t y = (int16_t )(16 * mp_obj_get_float (a1 ));
118
+ STATIC mp_obj_t _vertex2f (mp_obj_t self , mp_obj_t a0 , mp_obj_t a1 ) {
119
+ mp_obj__EVE_t * _EVE = mp_instance_cast_to_native_base (self , & _EVE_type );
120
+ int16_t x = (int16_t )(_EVE -> vscale * mp_obj_get_float (a0 ));
121
+ int16_t y = (int16_t )(_EVE -> vscale * mp_obj_get_float (a1 ));
121
122
C4 (self , (0x40000000 | ((x & 32767 ) << 15 ) | (y & 32767 )));
122
123
return mp_const_none ;
123
124
}
124
125
STATIC MP_DEFINE_CONST_FUN_OBJ_3 (vertex2f_obj , _vertex2f );
125
126
127
+ STATIC mp_obj_t _vertexformat (mp_obj_t self , mp_obj_t a0 ) {
128
+ mp_obj__EVE_t * _EVE = mp_instance_cast_to_native_base (self , & _EVE_type );
129
+ uint32_t frac = mp_obj_get_int_truncated (a0 );
130
+ C4 (self , ((0x27 << 24 ) | (frac & 3 )));
131
+ _EVE -> vscale = 1 << frac ;
132
+ return mp_const_none ;
133
+ }
134
+ STATIC MP_DEFINE_CONST_FUN_OBJ_2 (vertexformat_obj , _vertexformat );
135
+
126
136
STATIC mp_obj_t _cmd (size_t n_args , const mp_obj_t * args ) {
127
137
mp_obj_t self = args [0 ];
128
138
mp_obj_t num = args [1 ];
@@ -180,6 +190,7 @@ STATIC const mp_rom_map_elem_t _EVE_locals_dict_table[] = {
180
190
{ MP_ROM_QSTR (MP_QSTR_cc ), MP_ROM_PTR (& cc_obj ) },
181
191
{ MP_ROM_QSTR (MP_QSTR_flush ), MP_ROM_PTR (& flush_obj ) },
182
192
{ MP_ROM_QSTR (MP_QSTR_Vertex2f ), MP_ROM_PTR (& vertex2f_obj ) },
193
+ { MP_ROM_QSTR (MP_QSTR_VertexFormat ), MP_ROM_PTR (& vertexformat_obj ) },
183
194
{ MP_ROM_QSTR (MP_QSTR_cmd ), MP_ROM_PTR (& cmd_obj ) },
184
195
{ MP_ROM_QSTR (MP_QSTR_cmd0 ), MP_ROM_PTR (& cmd0_obj ) },
185
196
ROM_DECLS
@@ -197,6 +208,8 @@ STATIC mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, const mp
197
208
mp_obj__EVE_t * o = m_new_obj (mp_obj__EVE_t );
198
209
mp_printf (& mp_plat_print , "_EVE %p make_new\n" , o );
199
210
o -> base .type = & _EVE_type ;
211
+ o -> n = 0 ;
212
+ o -> vscale = 16 ;
200
213
return MP_OBJ_FROM_PTR (o );
201
214
}
202
215
0 commit comments