2 Codegen for sm83 could geneate code for a left shift of a 16-bit variable that would result in stack corruption.
19 #define PLAYER_X_LEFT_BOUND_PX 8U
20 #define PLAYER_X_CENTER_BOUND_PX 88U
21 #define PLAYER_X_RIGHT_BOUND_PX 160U
22 #define PLAYER_Y_UP_BOUND_PX 16U
23 #define PLAYER_Y_CENTER_BOUND_PX 80U
24 #define PLAYER_Y_DOWN_BOUND_PX 152U
25 #define PLAYER_SPEED 21
27 #define RIGHT_BOUND 652
29 #define BOTTOM_BOUND 652
31 typedef struct PlayerObject
{
40 uint8_t topOffsetInPx
;
41 uint8_t bottomOffsetInPx
;
42 uint8_t leftOffsetInPx
;
43 uint8_t rightOffsetInPx
;
57 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) // Lack of memory
58 static uint8_t playGrid
[32U][32U]; // We need the array sizes of 32 to trigger the bug.
64 static uint8_t roomId
;
67 static uint16_t camera_max_x
= 10U * 16U;
68 static uint16_t camera_max_y
= 9U * 16U;
69 static uint8_t walkableTileCount
= 6U;
71 static uint16_t camera_x
= STARTCAM
, camera_y
= STARTCAM
, new_camera_x
= STARTCAM
, new_camera_y
= STARTCAM
;
72 static uint8_t map_pos_x
= STARTPOS
, map_pos_y
= STARTPOS
, new_map_pos_x
= STARTPOS
, new_map_pos_y
= STARTPOS
;
73 static uint8_t redraw
;
77 static void func_1(void);
78 static void func_2(void);
87 static void func_1(void)
89 player
.xVel
= player
.moveSpeed
;
91 player
.dir
= DIR_RIGHT
;
96 static void func_2(void)
98 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) // Lack of memory
99 int16_t x
= player
.xSpr
+ player
.xVel
;
100 int16_t y
= player
.ySpr
+ player
.yVel
;
102 uint8_t topOffset
= 8;
103 uint8_t bottomOffset
= 1;
104 uint8_t leftOffset
= 4;
105 uint8_t rightOffset
= 5;
107 // If you comment/uncomment one of these...
108 static uint8_t playerTopMetatileIndex
;
109 playerTopMetatileIndex
= (y
) - 16U;
111 uint8_t playerBottomMetatileIndex
= y
;
112 uint8_t playerLeftMetatileIndex
= x
;
113 uint8_t playerRightMetatileIndex
= x
;
115 uint8_t collided
= TRUE
;
119 if ((playGrid
[playerTopMetatileIndex
][playerLeftMetatileIndex
] < walkableTileCount
)
120 && (playGrid
[playerTopMetatileIndex
][playerRightMetatileIndex
] < walkableTileCount
))
124 if ((playGrid
[playerBottomMetatileIndex
][playerLeftMetatileIndex
] < walkableTileCount
)
125 && (playGrid
[playerBottomMetatileIndex
][playerRightMetatileIndex
] < walkableTileCount
))
129 if ((playGrid
[playerTopMetatileIndex
][playerLeftMetatileIndex
] < walkableTileCount
)
130 && (playGrid
[playerBottomMetatileIndex
][playerLeftMetatileIndex
] < walkableTileCount
))
134 if ((playGrid
[playerTopMetatileIndex
][playerRightMetatileIndex
] < walkableTileCount
)
135 && (playGrid
[playerBottomMetatileIndex
][playerRightMetatileIndex
] < walkableTileCount
))
144 if (collided
== FALSE
)
153 case DIR_UP
: player
.ySpr
= (playerTopMetatileIndex
); break;
154 case DIR_DOWN
: player
.ySpr
= (playerBottomMetatileIndex
); break;
155 case DIR_LEFT
: player
.xSpr
= (playerLeftMetatileIndex
+ 1U); break;
156 case DIR_RIGHT
: player
.xSpr
= (playerRightMetatileIndex
); break;