Skip to content

Commit 4241fd4

Browse files
authored
Merge pull request #4051 from jamesbowman/main
EVE: change fixed-point integer arguments to floating point
2 parents a2ac2da + dff3423 commit 4241fd4

File tree

3 files changed

+92
-86
lines changed

3 files changed

+92
-86
lines changed

shared-bindings/_eve/__init__.c

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -604,22 +604,6 @@ STATIC mp_obj_t _jump(mp_obj_t self, mp_obj_t a0) {
604604
}
605605
STATIC MP_DEFINE_CONST_FUN_OBJ_2(jump_obj, _jump);
606606

607-
//| def LineWidth(self, width: int) -> None:
608-
//| """Set the width of rasterized lines
609-
//|
610-
//| :param int width: line width in :math:`1/16` pixel. Range 0-4095. The initial value is 16
611-
//|
612-
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
613-
//| ...
614-
//|
615-
616-
STATIC mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
617-
uint32_t width = mp_obj_get_int_truncated(a0);
618-
common_hal__eve_LineWidth(EVEHAL(self), width);
619-
return mp_const_none;
620-
}
621-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
622-
623607
//| def Macro(self, m: int) -> None:
624608
//| """Execute a single command from a macro register
625609
//|
@@ -662,22 +646,6 @@ STATIC mp_obj_t _palettesource(mp_obj_t self, mp_obj_t a0) {
662646
}
663647
STATIC MP_DEFINE_CONST_FUN_OBJ_2(palettesource_obj, _palettesource);
664648

665-
//| def PointSize(self, size: int) -> None:
666-
//| """Set the radius of rasterized points
667-
//|
668-
//| :param int size: point radius in :math:`1/16` pixel. Range 0-8191. The initial value is 16
669-
//|
670-
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
671-
//| ...
672-
//|
673-
674-
STATIC mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
675-
uint32_t size = mp_obj_get_int_truncated(a0);
676-
common_hal__eve_PointSize(EVEHAL(self), size);
677-
return mp_const_none;
678-
}
679-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
680-
681649
//| def RestoreContext(self) -> None:
682650
//| """Restore the current graphics context from the context stack"""
683651
//| ...
@@ -836,48 +804,6 @@ STATIC mp_obj_t _tag(mp_obj_t self, mp_obj_t a0) {
836804
}
837805
STATIC MP_DEFINE_CONST_FUN_OBJ_2(tag_obj, _tag);
838806

839-
//| def VertexTranslateX(self, x: int) -> None:
840-
//| """Set the vertex transformation's x translation component
841-
//|
842-
//| :param int x: signed x-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
843-
//|
844-
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
845-
//| ...
846-
//|
847-
848-
STATIC mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
849-
uint32_t x = mp_obj_get_int_truncated(a0);
850-
common_hal__eve_VertexTranslateX(EVEHAL(self), x);
851-
return mp_const_none;
852-
}
853-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
854-
855-
//| def VertexTranslateY(self, y: int) -> None:
856-
//| """Set the vertex transformation's y translation component
857-
//|
858-
//| :param int y: signed y-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
859-
//|
860-
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
861-
//| ...
862-
//|
863-
864-
865-
STATIC mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
866-
uint32_t y = mp_obj_get_int_truncated(a0);
867-
common_hal__eve_VertexTranslateY(EVEHAL(self), y);
868-
return mp_const_none;
869-
}
870-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
871-
872-
//| def VertexFormat(self, frac: int) -> None:
873-
//| """Set the precision of vertex2f coordinates
874-
//|
875-
//| :param int frac: Number of fractional bits in X,Y coordinates, 0-4. Range 0-7. The initial value is 4
876-
//|
877-
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
878-
//| ...
879-
//|
880-
881807
STATIC mp_obj_t _vertexformat(mp_obj_t self, mp_obj_t a0) {
882808
uint32_t frac = mp_obj_get_int_truncated(a0);
883809
common_hal__eve_VertexFormat(EVEHAL(self), frac);
@@ -975,6 +901,82 @@ STATIC mp_obj_t _vertex2f(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
975901
}
976902
STATIC MP_DEFINE_CONST_FUN_OBJ_3(vertex2f_obj, _vertex2f);
977903

904+
//| def LineWidth(self, width: float) -> None:
905+
//| """Set the width of rasterized lines
906+
//|
907+
//| :param float width: line width in pixels. Range 0-511. The initial value is 1
908+
//|
909+
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
910+
//| ...
911+
//|
912+
913+
STATIC mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
914+
mp_float_t width = mp_obj_get_float(a0);
915+
common_hal__eve_LineWidth(EVEHAL(self), width);
916+
return mp_const_none;
917+
}
918+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
919+
920+
//| def PointSize(self, size: float) -> None:
921+
//| """Set the diameter of rasterized points
922+
//|
923+
//| :param float size: point diameter in pixels. Range 0-1023. The initial value is 1
924+
//|
925+
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
926+
//| ...
927+
//|
928+
929+
STATIC mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
930+
mp_float_t size = mp_obj_get_float(a0);
931+
common_hal__eve_PointSize(EVEHAL(self), size);
932+
return mp_const_none;
933+
}
934+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
935+
936+
//| def VertexTranslateX(self, x: float) -> None:
937+
//| """Set the vertex transformation's x translation component
938+
//|
939+
//| :param float x: signed x-coordinate in pixels. Range ±4095. The initial value is 0
940+
//|
941+
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
942+
//| ...
943+
//|
944+
945+
STATIC mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
946+
mp_float_t x = mp_obj_get_float(a0);
947+
common_hal__eve_VertexTranslateX(EVEHAL(self), x);
948+
return mp_const_none;
949+
}
950+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
951+
952+
//| def VertexTranslateY(self, y: float) -> None:
953+
//| """Set the vertex transformation's y translation component
954+
//|
955+
//| :param float y: signed y-coordinate in pixels. Range ±4095. The initial value is 0
956+
//|
957+
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
958+
//| ...
959+
//|
960+
961+
962+
STATIC mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
963+
mp_float_t y = mp_obj_get_float(a0);
964+
common_hal__eve_VertexTranslateY(EVEHAL(self), y);
965+
return mp_const_none;
966+
}
967+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
968+
969+
//| def VertexFormat(self, frac: int) -> None:
970+
//| """Set the precision of vertex2f coordinates
971+
//|
972+
//| :param int frac: Number of fractional bits in X,Y coordinates, 0-4. Range 0-7. The initial value is 4
973+
//|
974+
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
975+
//| ...
976+
//|
977+
978+
//}
979+
978980
// Append an object x to the FIFO
979981
#define ADD_X(self, x) \
980982
common_hal__eve_add(EVEHAL(self), sizeof(x), &(x));

shared-bindings/_eve/__init__.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ void common_hal__eve_ColorRGB(common_hal__eve_t *eve, uint32_t red, uint32_t gre
6161
void common_hal__eve_Display(common_hal__eve_t *eve);
6262
void common_hal__eve_End(common_hal__eve_t *eve);
6363
void common_hal__eve_Jump(common_hal__eve_t *eve, uint32_t dest);
64-
void common_hal__eve_LineWidth(common_hal__eve_t *eve, uint32_t width);
64+
void common_hal__eve_LineWidth(common_hal__eve_t *eve, mp_float_t width);
6565
void common_hal__eve_Macro(common_hal__eve_t *eve, uint32_t m);
6666
void common_hal__eve_Nop(common_hal__eve_t *eve);
6767
void common_hal__eve_PaletteSource(common_hal__eve_t *eve, uint32_t addr);
68-
void common_hal__eve_PointSize(common_hal__eve_t *eve, uint32_t size);
68+
void common_hal__eve_PointSize(common_hal__eve_t *eve, mp_float_t size);
6969
void common_hal__eve_RestoreContext(common_hal__eve_t *eve);
7070
void common_hal__eve_Return(common_hal__eve_t *eve);
7171
void common_hal__eve_SaveContext(common_hal__eve_t *eve);
@@ -76,8 +76,8 @@ void common_hal__eve_StencilMask(common_hal__eve_t *eve, uint32_t mask);
7676
void common_hal__eve_StencilOp(common_hal__eve_t *eve, uint32_t sfail, uint32_t spass);
7777
void common_hal__eve_TagMask(common_hal__eve_t *eve, uint32_t mask);
7878
void common_hal__eve_Tag(common_hal__eve_t *eve, uint32_t s);
79-
void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, uint32_t x);
80-
void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, uint32_t y);
79+
void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, mp_float_t x);
80+
void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, mp_float_t y);
8181
void common_hal__eve_VertexFormat(common_hal__eve_t *eve, uint32_t frac);
8282
void common_hal__eve_Vertex2ii(common_hal__eve_t *eve, uint32_t x, uint32_t y, uint32_t handle, uint32_t cell);
8383

shared-module/_eve/__init__.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ void common_hal__eve_Jump(common_hal__eve_t *eve, uint32_t dest) {
226226
}
227227

228228

229-
void common_hal__eve_LineWidth(common_hal__eve_t *eve, uint32_t width) {
230-
C4(eve, ((14 << 24) | ((width & 4095))));
229+
void common_hal__eve_LineWidth(common_hal__eve_t *eve, mp_float_t width) {
230+
int16_t iw = (int)(8 * width);
231+
C4(eve, ((14 << 24) | ((iw & 4095))));
231232
}
232233

233234

@@ -246,8 +247,9 @@ void common_hal__eve_PaletteSource(common_hal__eve_t *eve, uint32_t addr) {
246247
}
247248

248249

249-
void common_hal__eve_PointSize(common_hal__eve_t *eve, uint32_t size) {
250-
C4(eve, ((13 << 24) | ((size & 8191))));
250+
void common_hal__eve_PointSize(common_hal__eve_t *eve, mp_float_t size) {
251+
int16_t is = (int)(8 * size);
252+
C4(eve, ((13 << 24) | ((is & 8191))));
251253
}
252254

253255

@@ -301,13 +303,15 @@ void common_hal__eve_Tag(common_hal__eve_t *eve, uint32_t s) {
301303
}
302304

303305

304-
void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, uint32_t x) {
305-
C4(eve, ((43 << 24) | (((x) & 131071))));
306+
void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, mp_float_t x) {
307+
int16_t ix = (int)(16 * x);
308+
C4(eve, ((43 << 24) | (ix & 131071)));
306309
}
307310

308311

309-
void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, uint32_t y) {
310-
C4(eve, ((44 << 24) | (((y) & 131071))));
312+
void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, mp_float_t y) {
313+
int16_t iy = (int)(16 * y);
314+
C4(eve, ((44 << 24) | (iy & 131071)));
311315
}
312316

313317

0 commit comments

Comments
 (0)