3 A z80 code generation (overwriting a value in iy during an assignment) bug found by z88dk
8 #define PIECE_IS_NEXT 255
10 #define STARTBOARD_X 15
11 #define STARTBOARD_Y 2
16 #define NEXT_X (POS_NEXT_X+2)
17 #define NEXT_Y (POS_NEXT_Y+3)
19 #define EMPTY_GR_CHAR 32
20 #define EMPTY_GR_COLOR 0
23 typedef unsigned char byte
;
27 int x
; // signed integers to allow negative board positions
28 int y
; // -1 means piece is preview ("next")
33 #define gr4_tile(x,y,tile,color,tileset) _gr4_tile_x = (x); _gr4_tile_y = (y); _gr4_tile_tile = (tile); _gr4_tile_color = (color); _gr4_tile_tileset = (tileset); _gr4_tile()
39 byte
*_gr4_tile_tileset
;
41 byte
*_gr4_tile_source
;
47 // offset of a single tile composing a piece
53 tile_offset
*get_piece_offsets(byte piece
, byte angle
);
55 tile_offset pieces_XY
[4] = {
56 {+1,+1} , {+2,+1} , {+3,+1} , {+1,+2} ,
59 void SLOT1_VIDEO_START() {
65 // given a piece number and an angle returns the 4 byte "offsets" of the piece
66 tile_offset
*get_piece_offsets(byte piece
, byte angle
) {
67 return &pieces_XY
[(piece
*sizeof(tile_offset
)*4*2)+angle
*4];
70 void gr_erasepiece(sprite
*p
);
72 // erase piece from the screen
73 void gr_erasepiece(sprite
*p
) {
74 tile_offset
*data
= get_piece_offsets(p
->piece
, p
->angle
); // bug if this declaration is here
79 // are we erasing the "next" piece ?
80 if(py
==PIECE_IS_NEXT
) {
89 // tile_offset *data = get_piece_offsets(p->piece, p->angle); // no bug if this declaration is here
92 for(byte t
=0; t
<4; t
++) {
93 int x
= px
+ data
->offset_x
;
94 int y
= py
+ data
->offset_y
;
96 gr4_tile((byte
)x
,(byte
)y
,EMPTY_GR_CHAR
,EMPTY_GR_COLOR
,FONTS
);
110 ASSERT(_gr4_tile_x
== s
.x
+ STARTBOARD_X
+ pieces_XY
[3].offset_x
);
111 ASSERT(_gr4_tile_y
== s
.y
+ STARTBOARD_Y
+ pieces_XY
[3].offset_y
);