tile rendering for chargen now working correctly
[dcpu16] / display.c
index 37db1d94e0b55c442eaed0bb3d69914a27db56f4..c1e6c20aa650b1404b9b51baf308fe28b7b6fc60 100644 (file)
--- a/display.c
+++ b/display.c
@@ -93,14 +93,14 @@ static inline
 void display_draw_cell(DPIX *pixbuf, DCPU16_WORD *cell_map, DCPU16_WORD index, int cell_x, int cell_y, DPIX fg, DPIX bg) {
     DPIX *cellstart = pixbuf; /* start of display */
     unsigned int pix_x, pix_y;
-    unsigned char *cell_bitmap = (unsigned char *)(cell_map + index);
+    unsigned char *cell_bitmap = (unsigned char *)(cell_map + (index * sizeof index));
 
     assert(cell_x < CELL_X);
     assert(cell_y < CELL_Y);
 
     cellstart += (PIX_X * PIX_BORDER); /* skip top border */
 
-    cellstart += (CELL_Y_SZ) * cell_y; /* skip down to row */
+    cellstart += (CELL_Y_SZ * PIX_X) * cell_y; /* skip down to row */
 
     cellstart += PIX_BORDER; /* skip side border */
 
@@ -109,9 +109,9 @@ void display_draw_cell(DPIX *pixbuf, DCPU16_WORD *cell_map, DCPU16_WORD index, i
     for (pix_x = 0; pix_x < CELL_X_SZ; pix_x++) {
         for (pix_y = 0; pix_y < CELL_Y_SZ; pix_y++) {
             if ((cell_bitmap[pix_x] >> pix_y) & 0x01)
-                cellstart[(pix_y * PIX_X) + pix_x] = fg;
+                cellstart[((CELL_Y_SZ - pix_y - 1) * PIX_X) + pix_x] = fg;
             else
-                cellstart[(pix_y * PIX_X) + pix_x] = bg;
+                cellstart[((CELL_Y_SZ - pix_y - 1) * PIX_X) + pix_x] = bg;
         }
     }
 }