OSDN Git Service

Fixed some data type issues.
authorRobert Lowe <robert.lowe@Lap-lowe.facstaff.mc>
Sat, 6 Sep 2014 03:03:35 +0000 (23:03 -0400)
committerRobert Lowe <robert.lowe@Lap-lowe.facstaff.mc>
Sat, 6 Sep 2014 03:03:35 +0000 (23:03 -0400)
Made left, right, and goto scrolling work with new draw methods.

Made goto frame the visible screen with an offscreen area.

Started on Downward scrolling, which doesn't quite work right.

16/modex16/scroll.c
16/modex16/scroll.exe

index 4b9ca12..de8f8f2 100644 (file)
@@ -8,24 +8,26 @@ typedef struct {
     bitmap_t *data;\r
     word tileHeight;\r
     word tileWidth;\r
-    word rows;\r
-    word cols;\r
+    unsigned int rows;\r
+    unsigned int cols;\r
 } tiles_t;\r
 \r
 \r
 typedef struct {\r
     byte    *data;\r
     tiles_t *tiles;\r
-    word width;\r
-    word height;\r
+    int width;\r
+    int height;\r
 } map_t;\r
 \r
 \r
 typedef struct {\r
     map_t *map;\r
     page_t *page;\r
-    word tx;\r
-    word ty;\r
+    int tx;\r
+    int ty;\r
+    word dxThresh;\r
+    word dyThresh;\r
 } map_view_t;\r
 \r
 \r
@@ -37,7 +39,7 @@ void mapScrollRight(map_view_t *mv, byte offset);
 void mapScrollLeft(map_view_t *mv, byte offest);\r
 void mapScrollUp(map_view_t *mv, byte offset);\r
 void mapScrollDown(map_view_t *mv, byte offset);\r
-void mapGoTo(map_view_t *mv, byte tx, byte ty);\r
+void mapGoTo(map_view_t *mv, int tx, int ty);\r
 void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y);\r
 void mapDrawRow(map_view_t *mv, int tx, int ty, word y);\r
 void mapDrawCol(map_view_t *mv, int tx, int ty, word x);\r
@@ -63,19 +65,26 @@ void main() {
     screen.width = 352;\r
     mv.page = &screen;\r
     mapGoTo(&mv, 0, 0);\r
+    modexShowPage(mv.page);\r
 \r
-\r
-       /* scroll all the way to the right */\r
-\r
-    for(x=0; x<((20)*16-SCREEN_WIDTH); x++) {\r
+    /* scroll all the way to the right */\r
+    for(x=0; x<(map.width*16-SCREEN_WIDTH); x++) {\r
        mapScrollRight(&mv, 1);\r
        modexShowPage(mv.page);\r
     }\r
-    for(x=0; x<((40/*+0.50625*/)*16-SCREEN_WIDTH); x++) {\r
+\r
+    /* scroll all the way to the left */\r
+    for(; x>0; x--) {\r
        mapScrollLeft(&mv, 1);\r
        modexShowPage(mv.page);\r
     }\r
 \r
+    /* scroll all the way down */\r
+    for(y=0; y<(map.height*16-SCREEN_HEIGHT); y++) {\r
+        mapScrollDown(&mv, 1);\r
+        modexShowPage(mv.page);\r
+    }\r
+\r
     /* spin for a time */\r
     for(x=0; x<500; x++) {\r
         modexWaitBorder();\r
@@ -141,55 +150,44 @@ initMap(map_t *map) {
 void\r
 mapScrollRight(map_view_t *mv, byte offset) {\r
     word x, y;  /* coordinate for drawing */\r
-    unsigned int i;\r
 \r
     /* increment the pixel position and update the page */\r
     mv->page->dx += offset;\r
 \r
     /* check to see if this changes the tile */\r
-    if(mv->page->dx >= 16) {\r
+    if(mv->page->dx >= mv->dxThresh ) {\r
        /* go forward one tile */\r
        mv->tx++;\r
        /* Snap the origin forward */\r
        mv->page->data += 4;\r
-       mv->page->dx =0;\r
+       mv->page->dx = mv->map->tiles->tileWidth;\r
 \r
 \r
        /* draw the next column */\r
-       x= SCREEN_WIDTH;\r
-       i= mv->ty * mv->map->width + mv->tx + 20;\r
-       for(y=0; y<SCREEN_HEIGHT; y+=16) {\r
-           mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);\r
-           i += mv->map->width;\r
-       }\r
+       x= SCREEN_WIDTH + mv->map->tiles->tileWidth;\r
+        mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x);\r
     }\r
 }\r
 \r
 \r
 void\r
 mapScrollLeft(map_view_t *mv, byte offset) {\r
-       word x, y;  /* coordinate for drawing */\r
-    unsigned int i;\r
+    word x, y;  /* coordinate for drawing */\r
 \r
     /* increment the pixel position and update the page */\r
     mv->page->dx -= offset;\r
 \r
     /* check to see if this changes the tile */\r
-    if(mv->page->dx >= 16) {\r
-       /* go forward one tile */\r
-       mv->tx++;\r
-       /* Snap the origin forward */\r
+    if(mv->page->dx == 0) {\r
+       /* go backward one tile */\r
+       mv->tx--;\r
+        \r
+       /* Snap the origin backward */\r
        mv->page->data -= 4;\r
-       mv->page->dx =16;\r
-\r
+       mv->page->dx = mv->map->tiles->tileWidth;\r
 \r
        /* draw the next column */\r
-       x= SCREEN_WIDTH;\r
-       i= mv->ty * mv->map->width + mv->tx + 20;\r
-       for(y=0; y<SCREEN_HEIGHT; y+=16) {\r
-           mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, (int)mv->page->dx + x, (int)mv->page->dy+y);\r
-           i += mv->map->width;\r
-       }\r
+        mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);\r
     }\r
 }\r
 \r
@@ -201,30 +199,49 @@ mapScrollUp(map_view_t *mv, byte offset) {
 \r
 void\r
 mapScrollDown(map_view_t *mv, byte offset) {\r
+    word x, y;  /* coordinate for drawing */\r
+\r
+    /* increment the pixel position and update the page */\r
+    mv->page->dy += offset;\r
+\r
+    /* check to see if this changes the tile */\r
+    if(mv->page->dy >= mv->dyThresh ) {\r
+       /* go down one tile */\r
+       mv->ty++;\r
+       /* Snap the origin downward */\r
+       mv->page->data += SCREEN_WIDTH*4;\r
+       mv->page->dy = mv->map->tiles->tileHeight;\r
+\r
+\r
+       /* draw the next row */\r
+       y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;\r
+        mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);\r
+    }\r
+\r
 }\r
 \r
 \r
 void\r
-mapGoTo(map_view_t *mv, byte tx, byte ty) {\r
+mapGoTo(map_view_t *mv, int tx, int ty) {\r
     int px, py;\r
     unsigned int i;\r
 \r
     /* set up the coordinates */\r
     mv->tx = tx;\r
     mv->ty = ty;\r
-    mv->page->dx = 0;\r
-    mv->page->dy = 0;\r
+    mv->page->dx = mv->map->tiles->tileWidth;\r
+    mv->page->dy = mv->map->tiles->tileHeight;\r
+\r
+    /* set up the thresholds */\r
+    mv->dxThresh = mv->map->tiles->tileWidth * 2;\r
+    mv->dyThresh = mv->map->tiles->tileHeight * 2;\r
 \r
     /* draw the tiles */\r
     modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0);\r
     py=0;\r
     i=mv->ty * mv->map->width + mv->tx;\r
-    for(ty=mv->ty; py < SCREEN_HEIGHT && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {\r
-       px=0;\r
-       for(tx=mv->tx; px < SCREEN_WIDTH+16 && tx < mv->map->width+1; tx++, px+=mv->map->tiles->tileWidth) {\r
-           mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, px, py);\r
-           i++;\r
-       }\r
+    for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) {\r
+        mapDrawRow(mv, tx-1, ty, py);\r
        i+=mv->map->width - tx;\r
     }\r
 }\r
@@ -247,7 +264,7 @@ mapDrawRow(map_view_t *mv, int tx, int ty, word y) {
 \r
     /* the position within the map array */\r
     i=ty * mv->map->width + tx;\r
-    for(x=0; x<SCREEN_HEIGHT+2 & tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {\r
+    for(x=0; x<SCREEN_WIDTH+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {\r
        if(i>=0) {\r
            /* we are in the map, so copy! */\r
            mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
@@ -267,7 +284,7 @@ mapDrawCol(map_view_t *mv, int tx, int ty, word x) {
 \r
     /* We'll copy all of the columns in the screen, \r
        i + 1 row above and one below */\r
-    for(y=0; y<SCREEN_HEIGHT+2 && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {\r
+    for(y=0; y<SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {\r
        if(i>=0) {\r
            /* we are in the map, so copy away! */\r
            mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);\r
index 8e82eda..0fe8502 100644 (file)
Binary files a/16/modex16/scroll.exe and b/16/modex16/scroll.exe differ