Looking at the code, I saw that one of the large functions was "_sprite" which took 1663 bytes. Found out that the main culprit was the *40 repeated on every line: The compiler in the OSDK does not do this type of optimisation, so each of the calls actually calls the "mul16u" function, that takes a lot of room and a lot of CPU time.
image_2025-12-09_202843516.png
The version on the right just precalculated two pointers with the "invariants" and that was enough to reduce the size to 1349 bytes and only keep the first *40 for the first entry.
A proper optimization would be to have a table to target the scanline, like you have for the screen location.
The next candidate for optimization would be the "drawtiles()" function which calls sub functions to draw each tile: Since the tile order never changes (contrarily to sprites), the entire routine should be just one function that draws all the tiles in one go so you don't have to recompute the screen address or the X position: Just draw from left to right and top to bottom updating the current position, and you can remove pretty much all the parameters of the function.
Like in this code:
Code: Select all
for (iy=0;iy<11;iy++)
{
iy_map_width= map_width_index_y_lookup_table[iy+1];
map_y_index = map_y_index_lookup_table[mapy];
drawtile(0,iy,mapdx,mapdy,map[mapx+iy_map_width+0+map_y_index],inv);
drawtile(1,iy,mapdx,mapdy,map[mapx+iy_map_width+1+map_y_index],inv);
drawtile(2,iy,mapdx,mapdy,map[mapx+iy_map_width+2+map_y_index],inv);
drawtile(3,iy,mapdx,mapdy,map[mapx+iy_map_width+3+map_y_index],inv);
drawtile(4,iy,mapdx,mapdy,map[mapx+iy_map_width+4+map_y_index],inv);
drawtile(5,iy,mapdx,mapdy,map[mapx+iy_map_width+5+map_y_index],inv);
drawtile(6,iy,mapdx,mapdy,map[mapx+iy_map_width+6+map_y_index],inv);
drawtile(7,iy,mapdx,mapdy,map[mapx+iy_map_width+7+map_y_index],inv);
drawtile(8,iy,mapdx,mapdy,map[mapx+iy_map_width+8+map_y_index],inv);
drawtile(9,iy,mapdx,mapdy,map[mapx+iy_map_width+9+map_y_index],inv);
drawtile(10,iy,mapdx,mapdy,map[mapx+iy_map_width+10+map_y_index],inv);
drawtile(11,iy,mapdx,mapdy,map[mapx+iy_map_width+11+map_y_index],inv);
drawtile(12,iy,mapdx,mapdy,map[mapx+iy_map_width+12+map_y_index],inv);
drawtile(13,iy,mapdx,mapdy,map[mapx+iy_map_width+13+map_y_index],inv);
}
you push on the stack iy,mapdx,mapdy,inv to each of the 14 calls... despite none of these values ever changing in a scanline.
If instead you use some zero page variable for these values, you can just use it directly instead of passing it.
You do not have the required permissions to view the files attached to this post.