]> 4ch.mooo.com Git - 16.git/blobdiff - src/scroll.c
new file: doc/parody.doc
[16.git] / src / scroll.c
index e0a6efca43634ea1ca9052f6125704d3076dd359..65929b5a9bca125bb8a076b16a0ecef6929f3839 100644 (file)
@@ -1,7 +1,29 @@
+/* Project 16 Source Code~
+ * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
+ *
+ * This file is part of Project 16.
+ *
+ * Project 16 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Project 16 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
 #include "src/lib/dos_kb.h"\r
 #include "src/lib/mapread.h"\r
-#include "src/lib/wtest/wtest.c"\r
-#include "src/lib/planar.c"\r
+#include "src/lib/wcpu/wcpu.h"\r
+#include "src/lib/planar.h"\r
 //====#include "src\lib\ems.c"\r
 \r
 //word far *clock= (word far*) 0x046C; /* 18.2hz clock */\r
@@ -39,17 +61,17 @@ typedef struct
 \r
 map_t allocMap(int w, int h);\r
 void initMap(map_t *map);\r
-void mapScrollRight(map_view_db_t *mvdb, byte offset, word id);\r
-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 mapScrollRight(map_view_t *mv, byte offset, word id);\r
+void mapScrollLeft(map_view_t *mv, byte offest, word id);\r
+void mapScrollUp(map_view_t *mv, byte offset, word id);\r
+void mapScrollDown(map_view_t *mv, byte offset, word id);\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
 void qclean();\r
 void pdump(map_view_t *pee);\r
-void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp);\r
+void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, short scrolloffsetswitch, int x, int y, int ls, int lp, bitmap_t *bmp);
 \r
 #define TILEWH 16\r
 #define QUADWH                 TILEWH/2\r
@@ -63,7 +85,7 @@ void animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword
 //#define TRIGGY 9\r
 \r
 void main() {\r
-       size_t oldfreemem=GetFreeSize();\r
+//++++ size_t oldfreemem=GetFreeSize();\r
        /*long emmhandle;\r
        long emsavail;\r
        char teststr[80];*/\r
@@ -76,9 +98,9 @@ void main() {
        static int persist_aniframe = 0;    /* gonna be increased to 1 before being used, so 0 is ok for default */\r
        page_t screen, screen2, screen3;\r
        map_t map;\r
-       map_view_t mv, mv2, mv3;\r
+       map_view_t mv[3];//mv, mv2, mv3;\r
        map_view_t *bg, *spri, *mask;//, *tmp;
-       map_view_db_t pgid[4];
+       //map_view_db_t pgid[4];
        byte *dpal, *gpal;\r
        byte *ptr;\r
        byte *mappalptr;\r
@@ -121,9 +143,9 @@ void main() {
 //---- map = allocMap(map.width,map.height); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly\r
        //if(isEMS()) printf("%d tesuto\n", coretotalEMS());\r
 //---- initMap(&map);\r
-       mv.map = &map;\r
-       mv2.map = &map;\r
-       mv3.map = &map;\r
+       mv[0].map = &map;\r
+       mv[1].map = &map;\r
+       mv[2].map = &map;\r
 \r
        /* draw the tiles */\r
        ptr = map.data;\r
@@ -184,7 +206,7 @@ void main() {
        //printf("      %d\n", sizeof(ptmp.data));\r
        //printf("1:    %d\n", paloffset);\r
        map.tiles->data->offset=(paloffset/3);\r
-       modexPalUpdate(map.tiles->data, &paloffset, 0, 0);\r
+       //XTmodexPalUpdate(map.tiles->data, &paloffset, 0, 0);\r
        printf("\n====\n");\r
        printf("0       paloffset=      %d\n", paloffset/3);\r
        printf("====\n\n");\r
@@ -196,21 +218,18 @@ void main() {
        /* setup camera and screen~ */\r
        screen = modexDefaultPage();\r
        screen.width += (TILEWH*2);\r
-       screen.height += (TILEWH*2)+QUADWH;\r
-       mv.page = &screen;\r
-       screen2 = modexNextPage(mv.page);\r
-       mv2.page = &screen2;\r
-       screen3 = modexNextPage0(mv2.page, 352, 176);   //(352*176)+1024 is the remaining amount of memory left wwww\r
+       screen.height += (TILEWH*2);//+QUADWH;\r
+       mv[0].page = &screen;\r
+       screen2 = modexNextPage(mv[0].page);\r
+       mv[1].page = &screen2;\r
+       screen3 = modexNextPage0(mv[1].page, 320, 240); //(352*176)+1024 is the remaining amount of memory left wwww\r
        //screen3 = modexNextPage0(mv2.page, 320, 192); //(352*176)+1024 is the remaining amount of memory left wwww\r
-       mv3.page = &screen3;\r
+       mv[2].page = &screen3;\r
 \r
        /* set up paging */\r
-       bg = &mv;\r
-       spri = &mv2;\r
-       mask = &mv3;
-       pgid[0].mv = &mv;
-       pgid[1].mv = &mv2;
-       pgid[2].mv = &mv3;\r
+       bg = &mv[0];\r
+       spri = &mv[1];\r
+       mask = &mv[2];
 \r
 //TODO: LOAD map data and position the map in the middle of the screen if smaller then screen\r
        mapGoTo(bg, 0, 0);\r
@@ -241,7 +260,8 @@ void main() {
        modexDrawSpriteRegion(spri->page, player.x-4, player.y-TILEWH, 24, 64, 24, 32, &ptmp);\r
 \r
        modexShowPage(spri->page);\r
-//     printf("Total used @ before loop:                       %zu\n", oldfreemem-GetFreeSize());\r
+//     printf("Total used @ before loop:                       %zu\n", oldfreemem-GetFreeSize());
+       modexClearRegion(mv[2].page, 0, 0, mv[2].page->width, mv[2].page->height, 1);\r
        modexFadeOn(4, gpal);\r
        while(!keyp(1) && player.hp>0)\r
        {\r
@@ -264,9 +284,9 @@ void main() {
                        {\r
                                INC_PER_FRAME;\r
                                //animatePlayer(bg, spri, mask, 1, 1, player.x, player.y, persist_aniframe, q, &ptmp);\r
-                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);\r
-                               mapScrollRight(pgid, SPEED, 0);\r
-                               mapScrollRight(pgid, SPEED, 1);\r
+                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
+                               mapScrollRight(mv, SPEED, 0);\r
+                               mapScrollRight(mv, SPEED, 1);
                                //mapScrollRight(mask, SPEED);\r
                                modexShowPage(spri->page);\r
                                player.q++;\r
@@ -307,8 +327,8 @@ void main() {
                                INC_PER_FRAME;\r
                                //animatePlayer(bg, spri, mask, 3, 1, player.x, player.y, persist_aniframe, q, &ptmp);\r
                                animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);\r
-                               mapScrollLeft(bg, SPEED);\r
-                               mapScrollLeft(spri, SPEED);\r
+                               mapScrollLeft(mv, SPEED, 0);\r
+                               mapScrollLeft(mv, SPEED, 1);\r
                                //mapScrollLeft(mask, SPEED);\r
                                modexShowPage(spri->page);\r
                                player.q++;\r
@@ -348,9 +368,9 @@ void main() {
                        {\r
                                INC_PER_FRAME;\r
                                //animatePlayer(bg, spri, mask, 2, 1, player.x, player.y, persist_aniframe, q, &ptmp);\r
-                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);\r
-                               mapScrollDown(bg, SPEED);\r
-                               mapScrollDown(spri, SPEED);\r
+                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
+                               mapScrollDown(mv, SPEED, 0);\r
+                               mapScrollDown(mv, SPEED, 1);\r
                                //mapScrollDown(mask, SPEED);\r
                                modexShowPage(spri->page);\r
                                player.q++;\r
@@ -390,9 +410,9 @@ void main() {
                        {\r
                                INC_PER_FRAME;\r
                                //animatePlayer(bg, spri, mask, 0, 1, player.x, player.y, persist_aniframe, q, &ptmp);\r
-                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);\r
-                               mapScrollUp(bg, SPEED);\r
-                               mapScrollUp(spri, SPEED);\r
+                               animatePlayer(bg, spri, player.d-1, 1, player.x, player.y, persist_aniframe, player.q, &ptmp);
+                               mapScrollUp(mv, SPEED, 0);\r
+                               mapScrollUp(mv, SPEED, 1);\r
                                //mapScrollUp(mask, SPEED);\r
                                modexShowPage(spri->page);\r
                                player.q++;\r
@@ -595,8 +615,8 @@ void main() {
        printf("player.hp: %d", player.hp);     printf("        player.q: %d", player.q);       printf("        player.d: %d\n", player.d);\r
        printf("tile data value at player trigger position: %d\n", bg->map->data[(player.triggerx-1)+(map.width*(player.triggery-1))]);\r
        printf("palette offset: %d\n", paloffset/3);\r
-       printf("Total used: %zu\n", oldfreemem-GetFreeSize());\r
-       printf("Total free: %zu\n", GetFreeSize());\r
+//++++ printf("Total used: %zu\n", oldfreemem-GetFreeSize());\r
+//++++ printf("Total free: %zu\n", GetFreeSize());\r
        printf("temporary player sprite 0: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45556867\n");\r
        printf("temporary player sprite 1: http://www.pixiv.net/member_illust.php?mode=medium&illust_id=44606385\n");\r
        printf("Screen: %dx", screen.width);    printf("%d\n", screen.height);\r
@@ -707,104 +727,111 @@ initMap(map_t *map) {
                }\r
                //tile = tile ? 0 : 1;\r
        }*/\r
-}\r
-\r
+}
+
 \r
 void\r
-mapScrollRight(map_view_db_t *mvdb, byte offset, word id) {\r
+mapScrollRight(map_view_t *mv, byte offset, word id)
+{\r
        word x, y;  /* coordinate for drawing */\r
 \r
        /* increment the pixel position and update the page */\r
-       mvdb[id].mv->page->dx += offset;\r
+       mv[id].page->dx += offset;\r
 \r
        /* check to see if this changes the tile */\r
-       if(mvdb[id].mv->page->dx >= mvdb[id].mv->dxThresh ) {\r
+       if(mv[id].page->dx >= mv[id].dxThresh ) {\r
        /* go forward one tile */\r
-       mvdb[id].mv->tx++;\r
+       mv[id].tx++;\r
        /* Snap the origin forward */\r
-       mvdb[id].mv->page->data += 4;\r
-       mvdb[id].mv->page->dx = mvdb[id].mv->map->tiles->tileWidth;\r
+       mv[id].page->data += 4;\r
+       mv[id].page->dx = mv[id].map->tiles->tileWidth;\r
 \r
        /* draw the next column */\r
-       x= SCREEN_WIDTH + mvdb[id].mv->map->tiles->tileWidth;\r
-               if(mvdb[id].mv->page->id==0)
-                       mapDrawCol(mvdb[id].mv, mvdb[id].mv->tx + 20 , mvdb[id].mv->ty-1, x);
+       x= SCREEN_WIDTH + mv[id].map->tiles->tileWidth;\r
+               if(id==0)
+                       mapDrawCol(&mv[0], mv[0].tx + 20 , mv[0].ty-1, x);
                else
-                       modexCopyPageRegion(mvdb[id].mv->page, mvdb[0].mv->page, x, 0, x, 0, mvdb[id].mv->map->tiles->tileWidth, mvdb[id].mv->map->tiles->tileHeight*17);
-//              mv[0]\r
+                       modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);
        }\r
 }\r
 \r
 \r
 void\r
-mapScrollLeft(map_view_t *mv, byte offset) {\r
+mapScrollLeft(map_view_t *mv, byte offset, word id)
+{\r
        word x, y;  /* coordinate for drawing */\r
 \r
        /* increment the pixel position and update the page */\r
-       mv->page->dx -= offset;\r
+       mv[id].page->dx -= offset;\r
 \r
        /* check to see if this changes the tile */\r
-       if(mv->page->dx == 0) {\r
+       if(mv[id].page->dx == 0) {\r
        /* go backward one tile */\r
-       mv->tx--;\r
+       mv[id].tx--;\r
 \r
        /* Snap the origin backward */\r
-       mv->page->data -= 4;\r
-       mv->page->dx = mv->map->tiles->tileWidth;\r
-       //}\r
-       /* draw the next column */\r
-               if(mv->page->id==0)\r
-               mapDrawCol(mv, mv->tx-1, mv->ty-1, 0);\r
+       mv[id].page->data -= 4;\r
+       mv[id].page->dx = mv[id].map->tiles->tileWidth;\r
+\r
+       /* draw the next column */
+       x= 0;\r
+               if(id==0)\r
+                       mapDrawCol(&mv[0], mv[0].tx-1, mv[0].ty-1, 0);
+               else
+                       modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*17);\r
        }\r
 }\r
 \r
 \r
 void\r
-mapScrollUp(map_view_t *mv, byte offset) {\r
+mapScrollUp(map_view_t *mv, byte offset, word id)
+{\r
        word x, y;  /* coordinate for drawing */\r
 \r
        /* increment the pixel position and update the page */\r
-       mv->page->dy -= offset;\r
+       mv[id].page->dy -= offset;\r
 \r
        /* check to see if this changes the tile */\r
-       if(mv->page->dy == 0 ) {\r
+       if(mv[id].page->dy == 0 ) {\r
        /* go down one tile */\r
-       mv->ty--;\r
+       mv[id].ty--;\r
        /* Snap the origin downward */\r
-       mv->page->data -= mv->page->width*4;\r
-       mv->page->dy = mv->map->tiles->tileHeight;\r
-       //}\r
+       mv[id].page->data -= mv[id].page->width*4;\r
+       mv[id].page->dy = mv[id].map->tiles->tileHeight;\r
 \r
        /* draw the next row */\r
        y= 0;\r
-               if(mv->page->id==0)\r
-               mapDrawRow(mv, mv->tx-1 , mv->ty-1, y);\r
+               if(id==0)\r
+                       mapDrawRow(&mv[0], mv[0].tx-1 , mv[0].ty-1, 0);
+               else\r
+                       modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);
        }\r
 }\r
 \r
 \r
 void\r
-mapScrollDown(map_view_t *mv, byte offset) {\r
+mapScrollDown(map_view_t *mv, byte offset, word id)
+{\r
        word x, y;  /* coordinate for drawing */\r
 \r
        /* increment the pixel position and update the page */\r
-       mv->page->dy += offset;\r
+       mv[id].page->dy += offset;\r
 \r
        /* check to see if this changes the tile */\r
-       if(mv->page->dy >= mv->dyThresh ) {\r
+       if(mv[id].page->dy >= mv[id].dyThresh ) {\r
        /* go down one tile */\r
-       mv->ty++;\r
+       mv[id].ty++;\r
        /* Snap the origin downward */\r
-       mv->page->data += mv->page->width*4;\r
-       mv->page->dy = mv->map->tiles->tileHeight;\r
-       //}\r
+       mv[id].page->data += mv[id].page->width*4;\r
+       mv[id].page->dy = mv[id].map->tiles->tileHeight;\r
 \r
        /* draw the next row */\r
-       y= SCREEN_HEIGHT + mv->map->tiles->tileHeight;\r
-               if(mv->page->id==0)\r
-               mapDrawRow(mv, mv->tx-1 , mv->ty+15, y);\r
+       y= SCREEN_HEIGHT + mv[id].map->tiles->tileHeight;\r
+               if(id==0)\r
+                       mapDrawRow(&mv[0], mv[0].tx-1 , mv[0].ty+15, y);
+               else
+                       modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*22, mv[id].map->tiles->tileHeight);\r
        }\r
-\r
 }\r
 \r
 \r
@@ -950,5 +977,6 @@ animatePlayer(map_view_t *src, map_view_t *dest, /*map_view_t *top, */sword d, s
        //modexClearRegion(top->page, 66, 66, 2, 40, 0);\r
        //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);\r
        //turn this off if XT\r
-       if(detectcpu() > 0) modexWaitBorder();\r
+       //XTif(detectcpu() > 0)
+       modexWaitBorder();\r
 }\r