X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=16%2Fmodex16%2Fscroll.c;h=8a960eee044d8c229344308a6c4e8dea79acb4c4;hb=3e49e24d51e5a253c8bd3caaa447150d009ea85d;hp=034ff43f521984bcf2e1c30aa5b1faac3dfdf987;hpb=0668fdd349d09a439aa89a854754692e316df440;p=16.git diff --git a/16/modex16/scroll.c b/16/modex16/scroll.c old mode 100644 new mode 100755 index 034ff43f..8a960eee --- a/16/modex16/scroll.c +++ b/16/modex16/scroll.c @@ -1,36 +1,41 @@ #include "modex16.h" #include #include +#include "dos_kb.h" -word far *clock= (word far*) 0x046C; /* 18.2hz clock */ +//word far *clock= (word far*) 0x046C; /* 18.2hz clock */ typedef struct { - bitmap_t *data; - word tileHeight; - word tileWidth; - unsigned int rows; - unsigned int cols; + bitmap_t *data; + word tileHeight; + word tileWidth; + unsigned int rows; + unsigned int cols; + unsigned int tilex,tiley; // tile position on the map } tiles_t; typedef struct { - byte *data; - tiles_t *tiles; - int width; - int height; + byte *data; + tiles_t *tiles; + int width; + int height; } map_t; typedef struct { - map_t *map; - page_t *page; - int tx; - int ty; - word dxThresh; - word dyThresh; + map_t *map; + page_t *page; + int tx; //???? appears to be the tile position on the viewable screen map + int ty; //???? appears to be the tile position on the viewable screen map + word dxThresh; //???? + word dyThresh; //???? } map_view_t; - +struct { + int tx; //player position on the viewable map + int ty; //player position on the viewable map +} player; map_t allocMap(int w, int h); @@ -44,135 +49,164 @@ void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y); void mapDrawRow(map_view_t *mv, int tx, int ty, word y); void mapDrawCol(map_view_t *mv, int tx, int ty, word x); +#define TILEWH 16 +#define QUADWH (TILEWH/4) +//#define SWAP(a, b) tmp=a; a=b; b=tmp; void main() { - int show1=1; - int tx, ty; - int x, y; - int ch=0x0; - page_t screen; - map_t map; - map_view_t mv; - byte *ptr; - - /* create the map */ - map = allocMap(40,30); - initMap(&map); - mv.map = ↦ - - /* draw the tiles */ - ptr = map.data; - modexEnter(); - screen = modexDefaultPage(); - screen.width = 352; - mv.page = &screen; - mapGoTo(&mv, 0, 0); - modexShowPage(mv.page); - - while(1){ - // scroll all the way to the right - //for(x=0; x<(map.width*16-SCREEN_WIDTH); x++) { - if(ch==0x4d){ - mapScrollRight(&mv, 4); - modexShowPage(mv.page); - } - - // scroll all the way to the left - //for(; x>0; x--) { - if(ch==0x4b){ - mapScrollLeft(&mv, 4); - modexShowPage(mv.page); - } - - // scroll all the way down - //for(y=0; y<(map.height*16-SCREEN_HEIGHT); y++) { - if(ch==0x50){ - mapScrollDown(&mv, 4); - modexShowPage(mv.page); - } - - // scroll all the way up - //for(; y>0; y--) { - if(ch==0x48){ - mapScrollUp(&mv, 4); - modexShowPage(mv.page); - } - - // spin for a time - /*for(x=0; x<500; x++) { - modexWaitBorder(); - }*/ - //while(1){ - ch=getch(); - //printf("0x%02x\n", ch); - if(ch==0x71)break; // 'q' - if(ch==0x1b)break; // 'ESC' -} - modexLeave(); +// int show1=1; + int tx, ty; + int x, y; + //int ch=0x0; +// byte ch; + int q=0; + page_t screen;//,screen2; + map_t map; + map_view_t mv;//, mv2; + map_view_t *draw;//, *show, *tmp; + byte *ptr; + + //default player position on the viewable map + player.tx = 10; + player.ty = 8; + + setkb(1); + /* create the map */ + map = allocMap(160,120); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly + initMap(&map); + mv.map = ↦ +// mv2.map = ↦ + + /* draw the tiles */ + ptr = map.data; + modexEnter(); + screen = modexDefaultPage(); + screen.width += (TILEWH*2); + mv.page = &screen; + mapGoTo(&mv, 16, 16); +// screen2=modexNextPage(mv.page); +// mv2.page = &screen2; +// mapGoTo(&mv2, 16, 16); +// modexShowPage(mv.page); + + /* set up paging */ +// show = &mv; +// draw = &mv2; + draw = &mv; + + //TODO: set player position data here according to the viewable map screen thingy + + while(!keyp(1)) { + //TODO: top left corner & bottem right corner of map veiw be set as map edge trigger since maps are actually square + //to stop scrolling and have the player position data move to the edge of the screen with respect to the direction + //when player.tx or player.ty == 0 or player.tx == 20 or player.ty == 15 then stop because that is edge of map and you do not want to walk of the map + if(keyp(77)){ +// for(q=0; qpage); +// mapScrollRight(draw, 1); +// SWAP(draw, show); +// } + } + + if(keyp(75)){ +// for(q=0; qpage); +// mapScrollLeft(show, 1); +// SWAP(draw, show); +// } + } + + if(keyp(80)){ +// for(q=0; qpage); +// mapScrollDown(show, 1); +// SWAP(draw, show); +// } + } + + if(keyp(72)){ +// for(q=0; qpage); +// mapScrollUp(show, 1); +// SWAP(draw, show); +// } + } + + //keyp(ch); + modexShowPage(draw->page); + + } + + modexLeave(); + setkb(0); } map_t allocMap(int w, int h) { - map_t result; - - result.width =w; - result.height=h; - result.data = malloc(sizeof(byte) * w * h); + map_t result; + + result.width =w; + result.height=h; + result.data = malloc(sizeof(byte) * w * h); - return result; + return result; } void initMap(map_t *map) { - /* just a place holder to fill out an alternating pattern */ - int x, y; - int i; - int tile = 1; - map->tiles = malloc(sizeof(tiles_t)); - - /* create the tile set */ - map->tiles->data = malloc(sizeof(bitmap_t)); - map->tiles->data->width = 32; - map->tiles->data->height= 16; - map->tiles->data->data = malloc(32*16); - map->tiles->tileHeight = 16; - map->tiles->tileWidth = 16; - map->tiles->rows = 1; - map->tiles->cols = 2; - - i=0; - for(y=0; y<16; y++) { - for(x=0; x<32; x++) { - if(x<16) - map->tiles->data->data[i] = 0x00; - else - map->tiles->data->data[i] = 0x47; - i++; + /* just a place holder to fill out an alternating pattern */ + int x, y; + int i; + int tile = 1; + map->tiles = malloc(sizeof(tiles_t)); + + /* create the tile set */ + map->tiles->data = malloc(sizeof(bitmap_t)); + map->tiles->data->width = (TILEWH*2); + map->tiles->data->height= TILEWH; + map->tiles->data->data = malloc((TILEWH*2)*TILEWH); + map->tiles->tileHeight = TILEWH; + map->tiles->tileWidth =TILEWH; + map->tiles->rows = 1; + map->tiles->cols = 2; + + i=0; + for(y=0; ytiles->data->data[i] = 0x24; + else + map->tiles->data->data[i] = 0x34; + i++; + } + } + + i=0; + for(y=0; yheight; y++) { + for(x=0; xwidth; x++) { + map->data[i] = tile; + tile = tile ? 0 : 1; + i++; + } + tile = tile ? 0 : 1; } - } - - i=0; - for(y=0; yheight; y++) { - for(x=0; xwidth; x++) { - map->data[i] = tile; - tile = tile ? 0 : 1; - i++; - } - tile = tile ? 0 : 1; - } } void mapScrollRight(map_view_t *mv, byte offset) { - word x, y; /* coordinate for drawing */ + word x, y; /* coordinate for drawing */ - /* increment the pixel position and update the page */ - mv->page->dx += offset; + /* increment the pixel position and update the page */ + mv->page->dx += offset; - /* check to see if this changes the tile */ - if(mv->page->dx >= mv->dxThresh ) { + /* check to see if this changes the tile */ + if(mv->page->dx >= mv->dxThresh ) { /* go forward one tile */ mv->tx++; /* Snap the origin forward */ @@ -182,42 +216,42 @@ mapScrollRight(map_view_t *mv, byte offset) { /* draw the next column */ x= SCREEN_WIDTH + mv->map->tiles->tileWidth; - mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x); - } + mapDrawCol(mv, mv->tx + 20 , mv->ty-1, x); + } } void mapScrollLeft(map_view_t *mv, byte offset) { - word x, y; /* coordinate for drawing */ + word x, y; /* coordinate for drawing */ - /* increment the pixel position and update the page */ - mv->page->dx -= offset; + /* increment the pixel position and update the page */ + mv->page->dx -= offset; - /* check to see if this changes the tile */ - if(mv->page->dx == 0) { + /* check to see if this changes the tile */ + if(mv->page->dx == 0) { /* go backward one tile */ mv->tx--; - + /* Snap the origin backward */ mv->page->data -= 4; mv->page->dx = mv->map->tiles->tileWidth; /* draw the next column */ - mapDrawCol(mv, mv->tx-1, mv->ty-1, 0); - } + mapDrawCol(mv, mv->tx-1, mv->ty-1, 0); + } } void mapScrollUp(map_view_t *mv, byte offset) { - word x, y; /* coordinate for drawing */ + word x, y; /* coordinate for drawing */ - /* increment the pixel position and update the page */ - mv->page->dy -= offset; + /* increment the pixel position and update the page */ + mv->page->dy -= offset; - /* check to see if this changes the tile */ - if(mv->page->dy == 0 ) { + /* check to see if this changes the tile */ + if(mv->page->dy == 0 ) { /* go down one tile */ mv->ty--; /* Snap the origin downward */ @@ -227,20 +261,20 @@ mapScrollUp(map_view_t *mv, byte offset) { /* draw the next row */ y= 0; - mapDrawRow(mv, mv->tx-1 , mv->ty-1, y); - } + mapDrawRow(mv, mv->tx-1 , mv->ty-1, y); + } } void mapScrollDown(map_view_t *mv, byte offset) { - word x, y; /* coordinate for drawing */ + word x, y; /* coordinate for drawing */ - /* increment the pixel position and update the page */ - mv->page->dy += offset; + /* increment the pixel position and update the page */ + mv->page->dy += offset; - /* check to see if this changes the tile */ - if(mv->page->dy >= mv->dyThresh ) { + /* check to see if this changes the tile */ + if(mv->page->dy >= mv->dyThresh ) { /* go down one tile */ mv->ty++; /* Snap the origin downward */ @@ -250,80 +284,80 @@ mapScrollDown(map_view_t *mv, byte offset) { /* draw the next row */ y= SCREEN_HEIGHT + mv->map->tiles->tileHeight; - mapDrawRow(mv, mv->tx-1 , mv->ty+15, y); - } + mapDrawRow(mv, mv->tx-1 , mv->ty+15, y); + } } void mapGoTo(map_view_t *mv, int tx, int ty) { - int px, py; - unsigned int i; - - /* set up the coordinates */ - mv->tx = tx; - mv->ty = ty; - mv->page->dx = mv->map->tiles->tileWidth; - mv->page->dy = mv->map->tiles->tileHeight; - - /* set up the thresholds */ - mv->dxThresh = mv->map->tiles->tileWidth * 2; - mv->dyThresh = mv->map->tiles->tileHeight * 2; - - /* draw the tiles */ - modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0); - py=0; - i=mv->ty * mv->map->width + mv->tx; - for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) { - mapDrawRow(mv, tx-1, ty, py); + int px, py; + unsigned int i; + + /* set up the coordinates */ + mv->tx = tx; + mv->ty = ty; + mv->page->dx = mv->map->tiles->tileWidth; + mv->page->dy = mv->map->tiles->tileHeight; + + /* set up the thresholds */ + mv->dxThresh = mv->map->tiles->tileWidth * 2; + mv->dyThresh = mv->map->tiles->tileHeight * 2; + + /* draw the tiles */ + modexClearRegion(mv->page, 0, 0, mv->page->width, mv->page->height, 0); + py=0; + i=mv->ty * mv->map->width + mv->tx; + for(ty=mv->ty-1; py < SCREEN_HEIGHT+mv->dyThresh && ty < mv->map->height; ty++, py+=mv->map->tiles->tileHeight) { + mapDrawRow(mv, tx-1, ty, py); i+=mv->map->width - tx; - } + } } void mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y) { - word rx; - word ry; - rx = (i % t->cols) * t->tileWidth; - ry = (i / t->cols) * t->tileHeight; - modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data); + word rx; + word ry; + rx = (i % t->cols) * t->tileWidth; + ry = (i / t->cols) * t->tileHeight; + modexDrawBmpRegion(page, x, y, rx, ry, t->tileWidth, t->tileHeight, t->data); } void mapDrawRow(map_view_t *mv, int tx, int ty, word y) { - word x; - int i; + word x; + int i; - /* the position within the map array */ - i=ty * mv->map->width + tx; - for(x=0; xdxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) { + /* the position within the map array */ + i=ty * mv->map->width + tx; + for(x=0; xdxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) { if(i>=0) { - /* we are in the map, so copy! */ - mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y); + /* we are in the map, so copy! */ + mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y); } i++; /* next! */ - } + } } void mapDrawCol(map_view_t *mv, int tx, int ty, word x) { - int y; - int i; + int y; + int i; - /* location in the map array */ - i=ty * mv->map->width + tx; + /* location in the map array */ + i=ty * mv->map->width + tx; - /* We'll copy all of the columns in the screen, - i + 1 row above and one below */ - for(y=0; ydyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) { + /* We'll copy all of the columns in the screen, + i + 1 row above and one below */ + for(y=0; ydyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) { if(i>=0) { - /* we are in the map, so copy away! */ - mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y); + /* we are in the map, so copy away! */ + mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y); } i += mv->map->width; - } + } }