Refactor scrolling, added road tile, first sprites drawn but not implemented

This commit is contained in:
Jeremy Penner 2019-01-18 23:02:56 -05:00
parent 4688bdccb0
commit 28f98c20b2
4 changed files with 62 additions and 44 deletions

BIN
sprite.tif Executable file

Binary file not shown.

106
testbed.c
View file

@ -461,25 +461,39 @@ typedef struct {
unsigned int h; unsigned int h;
int scrollX; int scrollX;
int scrollY; int scrollY;
unsigned int pageOffset; unsigned int pageOffset[2];
unsigned char *tiles; unsigned char currentPage;
} TilePage_t; unsigned int tilesOffset;
unsigned int *memTiles;
unsigned char *map;
} TiledScreen_t;
#define OFF_TILES 0x4840 TiledScreen_t screen = { 0, 0, 0, 0, { 0x0400, 0x2620 }, 0, 0, NULL, NULL };
void scrollPage(TilePage_t *page, int x, int y) { void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
x = min(max(x, 0), (page->w << 4) - 320); screen.tilesOffset = tilesOffset;
y = min(max(y, 0), (page->h << 4) - 176); screen.memTiles = memTiles;
page->scrollX = x;
page->scrollY = y;
} }
void drawPage(TilePage_t *page) { void loadMap(unsigned char *map, unsigned int w, unsigned int h) {
unsigned int startX = page->scrollX >> 4; screen.map = map;
unsigned int startY = page->scrollY >> 4; screen.w = w;
unsigned int offsetX = page->scrollX - (startX << 4); screen.h = h;
unsigned int offsetY = page->scrollY - (startY << 4); }
unsigned int drawOffset = page->pageOffset;
void scroll(int x, int y) {
x = min(max(x, 0), (screen.w << 4) - 320);
y = min(max(y, 0), (screen.h << 4) - 176);
screen.scrollX = x;
screen.scrollY = y;
}
void drawScreen() {
unsigned int startX = screen.scrollX >> 4;
unsigned int startY = screen.scrollY >> 4;
unsigned int offsetX = screen.scrollX - (startX << 4);
unsigned int offsetY = screen.scrollY - (startY << 4);
unsigned int drawOffset = screen.pageOffset[screen.currentPage];
unsigned int scrollOffset = drawOffset + (offsetX >> 3) + (offsetY * PAGE_STRIDE); unsigned int scrollOffset = drawOffset + (offsetX >> 3) + (offsetY * PAGE_STRIDE);
unsigned int x, y; unsigned int x, y;
@ -487,47 +501,44 @@ void drawPage(TilePage_t *page) {
for (y = startY; y < startY + 13; y ++) { for (y = startY; y < startY + 13; y ++) {
for (x = startX; x < startX + 21; x ++) { for (x = startX; x < startX + 21; x ++) {
blitTile(OFF_TILES + page->tiles[x + (y * page->w)], drawOffset); blitTile(screen.tilesOffset + screen.map[x + (y * screen.w)], drawOffset);
drawOffset += 2; drawOffset += 2;
} }
drawOffset += PAGE_STRIDE * 15; drawOffset += PAGE_STRIDE * 15;
} }
setDisplayOffset(scrollOffset); setDisplayOffset(scrollOffset);
screen.currentPage ^= 1;
} }
/*** S C R A T C H ***/ /*** S C R A T C H ***/
unsigned char tiles[10000]; unsigned int tiles[2*16 * 128];
TilePage_t pages[2] = { #define OFF_TILES 0x4840
{ 100, 100, 0, 0, 0x0400, tiles },
{ 100, 100, 0, 0, 0x2620, tiles }
};
void fillTiles() { unsigned char map[10000];
void fillMap() {
unsigned int x, y, z; unsigned int x, y, z;
z = 0; z = 0;
for (y = 0; y < 100; y ++) { for (y = 0; y < 100; y ++) {
for (x = 0; x < 100; x ++) { for (x = 0; x < 100; x ++) {
tiles[x + (y * 100)] = (((x + y + z) >> 2) % 3) << 5; map[x + (y * 100)] = (((x + y + z) >> 2) % 4) << 5;
} }
} }
} }
int main() { void game_init() {
FILE *f; FILE *f;
TifImageMeta_t meta; TifImageMeta_t meta;
int plane;
int x;
int y;
int z = 0;
unsigned int drawOffset;
unsigned int page = 0;
setEGAMode(); setEGAMode();
atexit(vid_cleanup); atexit(vid_cleanup);
tile_init();
fillMap();
f = fopen("FOOTER.TIF", "rb"); f = fopen("FOOTER.TIF", "rb");
meta = tifLoadMeta(f); meta = tifLoadMeta(f);
tifLoadEGA(f, meta, 0, 24, 336); tifLoadEGA(f, meta, 0, 24, 336);
@ -536,28 +547,35 @@ int main() {
f = fopen("TILES.TIF", "rb"); f = fopen("TILES.TIF", "rb");
meta = tifLoadMeta(f); meta = tifLoadMeta(f);
tifLoadEGA(f, meta, OFF_TILES, 256, 16); tifLoadEGA(f, meta, OFF_TILES, 256, 16);
tifLoad(f, meta, tiles, 128 * 16, 16);
fclose(f); fclose(f);
kbd_init();
tile_init();
setSplitScreen(351); setSplitScreen(351);
fillTiles(); loadTiles(OFF_TILES, tiles);
loadMap(map, 100, 100);
scroll(0, 0);
}
int main() {
int x;
int y;
int z = 0;
game_init();
kbd_init();
while (!keyPressed(K_ESC)) { while (!keyPressed(K_ESC)) {
page ^= 1;
x = pages[page].scrollX; x = screen.scrollX;
y = pages[page].scrollY; y = screen.scrollY;
if (keyPressed(K_LEFT)) x -= 4; if (keyPressed(K_LEFT)) x -= 8;
if (keyPressed(K_RIGHT)) x += 4; if (keyPressed(K_RIGHT)) x += 8;
if (keyPressed(K_UP)) y -= 4; if (keyPressed(K_UP)) y -= 8;
if (keyPressed(K_DOWN)) y += 4; if (keyPressed(K_DOWN)) y += 8;
scrollPage(&pages[0], x, y); scroll(x, y);
scrollPage(&pages[1], x, y); drawScreen();
drawPage(&pages[page]);
// kbd_wait();
z++; z++;
} }

Binary file not shown.

BIN
tiles.tif

Binary file not shown.