OSDN Git Service

==== chikyuu sprite sheet added ====
[proj16/16.git] / src / lib / scroll16.c
index 9eae294..5f5aa9c 100755 (executable)
@@ -30,6 +30,10 @@ void walk(map_view_t *pip, player_t *player, word pn)
        //printf("player[%d].d=%d\n", pn, player[pn].d);
        switch(player[pn].d)
        {
+               //no direction
+               case 2:
+                       pip[0].video->startclk = (*clockw);
+               break;
                //right movement
                case 3:
                        //printf("pip[0].page->tilesw=%d        ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
@@ -40,13 +44,13 @@ void walk(map_view_t *pip, player_t *player, word pn)
                                {
                                        INC_PER_FRAME;
                                        animatePlayer(pip, player, pn, 1);
-                                       if(!pageflipflop) mapScrollRight(pip, player, !(pip[0].video->p), pn); else{
-                                       mapScrollRight(pip, player, 0, pn);
-                                       mapScrollRight(pip, player, 1, pn);
+                                       ScrollRight(pip, player, 3, pn);
                                        ScrollRight(pip, player, 2, pn);
-                                       ScrollRight(pip, player, 3, pn); }
+                                       mapScrollRight(pip, player, !(pip[0].video->p), pn);
+                                       mapScrollRight(pip, player, (pip[0].video->p), pn);
                                        if(!pageflipflop) modexShowPage(pip[1].page);
                                        player[pn].q++;
+                                       pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
                                } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
                        }
                        else if(player[pn].tx < pip[0].map->width && !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))
@@ -84,13 +88,13 @@ void walk(map_view_t *pip, player_t *player, word pn)
                                {
                                        INC_PER_FRAME;
                                        animatePlayer(pip, player, pn, 1);
-                                       if(!pageflipflop) mapScrollLeft(pip, player, !(pip[0].video->p), pn); else{
-                                       mapScrollLeft(pip, player, 0, pn);
-                                       mapScrollLeft(pip, player, 1, pn);
+                                       ScrollLeft(pip, player, 3, pn);
                                        ScrollLeft(pip, player, 2, pn);
-                                       ScrollLeft(pip, player, 3, pn); }
+                                       mapScrollLeft(pip, player, !(pip[0].video->p), pn);
+                                       mapScrollLeft(pip, player, (pip[0].video->p), pn);
                                        if(!pageflipflop) modexShowPage(pip[1].page);
                                        player[pn].q++;
+                                       pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
                                } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
                        }
                        else if(player[pn].tx > 1 && !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))
@@ -128,13 +132,13 @@ void walk(map_view_t *pip, player_t *player, word pn)
                                {
                                        INC_PER_FRAME;
                                        animatePlayer(pip, player, pn, 1);
-                                       if(!pageflipflop) mapScrollDown(pip, player, !(pip[0].video->p), pn); else{
-                                       mapScrollDown(pip, player, 0, pn);
-                                       mapScrollDown(pip, player, 1, pn);
+                                       ScrollDown(pip, player, 3, pn);
                                        ScrollDown(pip, player, 2, pn);
-                                       ScrollDown(pip, player, 3, pn); }
+                                       mapScrollDown(pip, player, !(pip[0].video->p), pn);
+                                       mapScrollDown(pip, player, (pip[0].video->p), pn);
                                        if(!pageflipflop) modexShowPage(pip[1].page);
                                        player[pn].q++;
+                                       pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
                                } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
                        }
                        else if(player[pn].ty < pip[0].map->height && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))
@@ -172,13 +176,13 @@ void walk(map_view_t *pip, player_t *player, word pn)
                                {
                                        INC_PER_FRAME;
                                        animatePlayer(pip, player, pn, 1);
-                                       if(!pageflipflop) mapScrollUp(pip, player, !(pip[0].video->p), pn); else{
-                                       mapScrollUp(pip, player, 0, pn);
-                                       mapScrollUp(pip, player, 1, pn);
+                                       ScrollUp(pip, player, 3, pn);
                                        ScrollUp(pip, player, 2, pn);
-                                       ScrollUp(pip, player, 3, pn); }
+                                       mapScrollUp(pip, player, !(pip[0].video->p), pn);
+                                       mapScrollUp(pip, player, (pip[0].video->p), pn);
                                        if(!pageflipflop) modexShowPage(pip[1].page);
                                        player[pn].q++;
+                                       pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
                                } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
                        }
                        else if(player[pn].ty > 1 && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX &&  player[pn].ty-1 == TRIGGY))
@@ -376,7 +380,7 @@ void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
        /* draw the next column */
        x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
        if(player[plid].q%4)
-               if(pageflipflop){
+               if(!pageflipflop){
                if(id==0)
                        mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
                else
@@ -406,7 +410,7 @@ void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
        /* draw the next column */
        x= 0;
        if(player[plid].q%4)
-               if(pageflipflop){
+               if(!pageflipflop){
                if(id==0)
                        mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
                else
@@ -435,7 +439,7 @@ void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
        /* draw the next row */
        y= 0;
        if(player[plid].q%3)
-               if(pageflipflop){
+               if(!pageflipflop){
                if(id==0)
                        mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
                else
@@ -463,7 +467,7 @@ void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
        /* draw the next row */
        y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
        if(player[plid].q%3)
-               if(pageflipflop){
+               if(!pageflipflop){
                if(id==0)
                        mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
                else
@@ -479,8 +483,13 @@ void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
        mv[0].video->page[id].dx += player[plid].speed;
 
        /* check to see if this changes the tile */
-       if(mv[0].video->page[id].dx >= mv[id].dxThresh )
+       if(mv[0].video->page[id].dx >= mv[0].dxThresh )
        {
+               /* block copy pattern to where we will draw the sprite */
+               vga_setup_wm1_block_copy();
+               _fmemmove(mv[0].video->page[id].data+4, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
+               /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
+               vga_restore_rm0wm0();
                /* Snap the origin forward */
                mv[0].video->page[id].data += 4;
                mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
@@ -496,6 +505,11 @@ void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
        /* check to see if this changes the tile */
        if(mv[0].video->page[id].dx == 0)
        {
+               /* block copy pattern to where we will draw the sprite */
+               vga_setup_wm1_block_copy();
+               _fmemmove(mv[0].video->page[id].data-4, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
+               /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
+               vga_restore_rm0wm0();
                /* Snap the origin backward */
                mv[0].video->page[id].data -= 4;
                mv[0].video->page[id].dx = mv[0].map->tiles->tileWidth;
@@ -510,8 +524,13 @@ void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
        /* check to see if this changes the tile */
        if(mv[0].video->page[id].dy == 0)
        {
+               /* block copy pattern to where we will draw the sprite */
+               vga_setup_wm1_block_copy();
+               _fmemmove(mv[0].video->page[id].data-mv[0].video->page[id].pi, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
+               /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
+               vga_restore_rm0wm0();
                /* Snap the origin backward */
-               mv[0].video->page[id].data -= 4;
+               mv[0].video->page[id].data -= mv[0].video->page[id].pi;
                mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
        }
 }
@@ -522,15 +541,17 @@ void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
        mv[0].video->page[id].dy += player[plid].speed;
 
        /* check to see if this changes the tile */
-       if(mv[0].video->page[id].dy >= mv[id].dxThresh )
+       if(mv[0].video->page[id].dy >= mv[0].dxThresh )
        {
+               /* block copy pattern to where we will draw the sprite */
+               vga_setup_wm1_block_copy();
+               _fmemmove(mv[0].video->page[id].data+mv[0].video->page[id].pi, mv[0].video->page[id].data, mv[0].video->page[id].pagesize);
+               /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
+               vga_restore_rm0wm0();
                /* Snap the origin forward */
-               mv[0].video->page[id].data += 4;
+               mv[0].video->page[id].data += mv[0].video->page[id].pi;
                mv[0].video->page[id].dy = mv[0].map->tiles->tileWidth;
        }
-//     modexClearRegion(&(mv[0].video->page[id]), 0, 0,
-//                      mv[0].video->page[id].width-1,
-//               mv[0].video->page[id].height-1, id*2);
 }
 
 sword chkmap(map_t *map, word q)
@@ -576,6 +597,7 @@ sword chkmap(map_t *map, word q)
        return 0;
 }
 
+//TODO: player position here
 void mapGoTo(map_view_t *mv, int tx, int ty)
 {
        int px, py;
@@ -584,12 +606,12 @@ void mapGoTo(map_view_t *mv, int tx, int ty)
        /* set up the coordinates */
        mv[0].tx = mv[1].tx = tx;
        mv[0].ty = mv[1].ty = ty;
-       mv[0].page->dx = mv[1].page->dx = mv->map->tiles->tileWidth;
-       mv[0].page->dy = mv[1].page->dy = mv->map->tiles->tileHeight;
+       mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
+       mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
 
        /* set up the thresholds */
-       mv[0].dxThresh = mv[1].dxThresh = mv->map->tiles->tileWidth * 2;
-       mv[0].dyThresh = mv[1].dyThresh = mv->map->tiles->tileHeight * 2;
+       mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
+       mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2;
 
        /* draw the tiles */
        modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
@@ -600,6 +622,17 @@ void mapGoTo(map_view_t *mv, int tx, int ty)
        i+=mv->map->width - tx;
        }
        modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
+       {
+               unsigned int k,j,o;
+               /* fill screen with a distinctive pattern */
+               for (k=0;k < vga_state.vga_width;k++) {
+                       o = k >> 2;
+                       vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
+                               for (j=0;j < (mv[0].page->height)+(mv[1].page->height)+(mv[2].page->height)+(mv[3].page->height);j++,o += vga_state.vga_stride)
+                                       vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
+               }
+       }
+       modexCopyPageRegion(mv[3].page, mv[!(mv->video->p)].page, 0/**/, 0/**/, 0, 128, 28, 36);
 }
 
 
@@ -626,7 +659,7 @@ mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
                        case 0:
 #ifndef TILERENDER
                                modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
-                               modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
+                               //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
 #else
                                PBUFBFUN                (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
                                /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
@@ -727,7 +760,7 @@ void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
 }*/
 
 unsigned char shinku_fps_indicator_page = 2;
-boolean pageflipflop=0;
+boolean pageflipflop;
 //gv->video.p
 
 /*     sync    */
@@ -741,6 +774,8 @@ void shinku(global_game_variables_t *gv)
        word bgcol = 0;
        word type = 1;
        byte o,o2,i;
+       //modexClearRegion(&gv->video.page[2], 0, 0, gv->video.page[2].sw, gv->video.page[2].sh, 47);
+       //modexClearRegion(&gv->video.page[3], 0, 0, gv->video.page[3].sw, gv->video.page[3].sh, 45);
        //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
        /* block copy to visible RAM from offscreen */
 //     vga_setup_wm1_block_copy();
@@ -775,16 +810,24 @@ void shinku(global_game_variables_t *gv)
                break;
                case 1:
                        //turn this off if XT
-                       modexWaitBorder();
-                       //vga_wait_for_vsync();
+                       //modexWaitBorder();
+                       vga_wait_for_vsync();
                        gv->kurokku.frames_per_second=60;
                break;
        }
        if(pageflipflop){
+       if(gv->video.r){
+               /* block copy pattern to where we will draw the sprite */
+               vga_setup_wm1_block_copy();
+               //_fmemmove((gv->video.page[(gv->video.p)]).data, (gv->video.page[(!gv->video.p)]).data, gv->video.page[(!gv->video.p)].pagesize);
                modexCopyPageRegion(&(gv->video.page[(gv->video.p)]), &(gv->video.page[(!gv->video.p)]), 0, 0, 0, 0, gv->video.page[gv->video.p].width, gv->video.page[!gv->video.p].height);
-               //modexShowPage(&(gv->video.page[gv->video.p])); //this is slow as fack too!!
-               modexShowPage(&(gv->video.page[1])); //this is slow as fack too!!
-               //gv->video.p=!gv->video.p;
+               /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
+               vga_restore_rm0wm0();
+               modexShowPage(&(gv->video.page[gv->video.p]));
+               gv->video.p=!gv->video.p;
+               gv->video.r=!gv->video.r;
+               gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
+       }
        }
 }
 
@@ -830,6 +873,7 @@ void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scroll
                break;
        }
 
+       //modexCopyPageRegion(pip[!(pip->video->p)].page, pip[3].page, 0, 128, x-4, y-4, 28, 36);
 #ifdef SPRITE
 // #define FRAME1 PBUFSFUN(pip[1].page, x, y, 48, dire, 24, 32,        PLAYERBMPDATA);
 // #define FRAME2 PBUFSFUN(pip[1].page, x, y, 24, dire, 24, 32,        PLAYERBMPDATA);
@@ -845,16 +889,18 @@ void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scroll
 #define FRAME3 modexClearRegion(pip[!(pip->video->p)].page, x, y, 24, 32, dire);
 #define FRAME4 modexClearRegion(pip[!(pip->video->p)].page, x, y, 24, 32, 1+dire);
        #endif
-//     if(pageflipflop)
+       if(!pageflipflop)
+               modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 36);
 //modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
-       modexCopyPageRegion(pip[pip->video->p].page,
- pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);
+       //modexCopyPageRegion(pip[3].page, pip[!(pip->video->p)].page, x-4, y-4, 0, 128, 28, 36);
+       /*modexCopyPageRegion(pip[pip->video->p].page,
+ pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);*/
 //     else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
-       //modexCopyPageRegion(pip[2].page, pip[1].page, 16, 16, 16, 16, (14*8)+4, 8+4);
        if(2>ls && ls>=1) { FRAME1 }else
        if(3>ls && ls>=2) { FRAME2 }else
        if(4>ls && ls>=3) { FRAME3 }else
        if(5>ls && ls>=4) { FRAME4 }
+       pip->video->r=1;
        //TODO: mask copy //modexCopyPageRegion(dest->page, src->page, x-4, y-4, x-4, y-4, 28, 40);
        //modexClearRegion(top->page, 66, 66, 2, 40, 0);
        //modexCopyPageRegion(dest->page, top->page, 66, 66, 66, 66, 2, 40);