smooth horizontal scrolling
This commit is contained in:
parent
d676190aaf
commit
b1366fe3b2
36
testbed.c
36
testbed.c
|
@ -9,6 +9,7 @@
|
||||||
#define setEGAMode() setMode(000Dh)
|
#define setEGAMode() setMode(000Dh)
|
||||||
#define setTextMode() setMode(0003h)
|
#define setTextMode() setMode(0003h)
|
||||||
|
|
||||||
|
#define REG_AC 0x03c0
|
||||||
#define REG_TS 0x03c4
|
#define REG_TS 0x03c4
|
||||||
#define REG_GDC 0x03ce
|
#define REG_GDC 0x03ce
|
||||||
#define REG_CRTC 0x03d4
|
#define REG_CRTC 0x03d4
|
||||||
|
@ -56,6 +57,12 @@ void setDisplayOffset(unsigned int offset) {
|
||||||
outport(REG_CRTC, 0x0d | (offset << 8));
|
outport(REG_CRTC, 0x0d | (offset << 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setHorizontalPan(int offset) {
|
||||||
|
inp(0x3da); // INPUT_STATUS_1?
|
||||||
|
outp(REG_AC, 0x13 | 0x20);
|
||||||
|
outp(REG_AC, offset);
|
||||||
|
}
|
||||||
|
|
||||||
#define setLogicalWidth(w) outport(REG_CRTC, 0x13 | (w << 8))
|
#define setLogicalWidth(w) outport(REG_CRTC, 0x13 | (w << 8))
|
||||||
|
|
||||||
/*** K E Y B O A R D ***/
|
/*** K E Y B O A R D ***/
|
||||||
|
@ -462,7 +469,7 @@ int tifLoad(FILE *f, TifImageMeta_t meta, unsigned int *planeBuf, int maxY, int
|
||||||
// 89ABCDEF 01234567 << 3 => BCDEFXXX 3456789A byteswap => 3456789A BCDEFXXX
|
// 89ABCDEF 01234567 << 3 => BCDEFXXX 3456789A byteswap => 3456789A BCDEFXXX
|
||||||
|
|
||||||
#define PAGE_TILES_W 21
|
#define PAGE_TILES_W 21
|
||||||
#define PAGE_TILES_H 13
|
#define PAGE_TILES_H 12
|
||||||
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
|
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
|
||||||
#define PAGE_STRIDE (PAGE_TILES_W << 1)
|
#define PAGE_STRIDE (PAGE_TILES_W << 1)
|
||||||
|
|
||||||
|
@ -504,7 +511,7 @@ typedef struct {
|
||||||
unsigned char firstBuffer;
|
unsigned char firstBuffer;
|
||||||
} TiledScreen_t;
|
} TiledScreen_t;
|
||||||
|
|
||||||
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0400, 0x2620 }, 0, 0, NULL, NULL,
|
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0400, 0x2400 }, 0, 0, NULL, NULL,
|
||||||
0, 0, 0, 0, 0 };
|
0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
|
void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) {
|
||||||
|
@ -578,8 +585,8 @@ void drawSpriteToBuf(unsigned int *sprite, int pageX, int pageY, int shift, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawSprite(unsigned int *sprite, int x, int y) {
|
void drawSprite(unsigned int *sprite, int x, int y) {
|
||||||
int pageX = (x - (screen.scrollX & 0xfff0)) >> 4;
|
int pageX = (int)(x - (screen.scrollX & 0xfff0)) >> 4;
|
||||||
int pageY = (y - (screen.scrollY & 0xfff0)) >> 4;
|
int pageY = (int)(y - (screen.scrollY & 0xfff0)) >> 4;
|
||||||
int pageOffsetX = x & 0x0f;
|
int pageOffsetX = x & 0x0f;
|
||||||
int pageOffsetY = y & 0x0f;
|
int pageOffsetY = y & 0x0f;
|
||||||
|
|
||||||
|
@ -656,6 +663,8 @@ void drawScreen() {
|
||||||
}
|
}
|
||||||
setAllPlanes();
|
setAllPlanes();
|
||||||
setDisplayOffset(scrollOffset);
|
setDisplayOffset(scrollOffset);
|
||||||
|
setHorizontalPan(screen.scrollX & 0x07);
|
||||||
|
|
||||||
screen.currentPage ^= 1;
|
screen.currentPage ^= 1;
|
||||||
screen.firstBuffer = screen.nextBuffer;
|
screen.firstBuffer = screen.nextBuffer;
|
||||||
for (di = 0; di < PAGE_TILES_COUNT; di ++) {
|
for (di = 0; di < PAGE_TILES_COUNT; di ++) {
|
||||||
|
@ -720,25 +729,22 @@ void game_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int x = 100;
|
int x = -1;
|
||||||
int y = 100;
|
int y = -1;
|
||||||
int z = 0;
|
int dir = 0;
|
||||||
|
|
||||||
game_init();
|
game_init();
|
||||||
kbd_init();
|
kbd_init();
|
||||||
|
|
||||||
while (!keyPressed(K_ESC)) {
|
while (!keyPressed(K_ESC)) {
|
||||||
|
|
||||||
if (keyPressed(K_LEFT)) x -= 3;
|
if (keyPressed(K_LEFT)) { x -= 3; dir = 2; }
|
||||||
if (keyPressed(K_RIGHT)) x += 3;
|
if (keyPressed(K_RIGHT)) { x += 3; dir = 0; }
|
||||||
if (keyPressed(K_UP)) y -= 3;
|
if (keyPressed(K_UP)) { y -= 3; dir = 1; }
|
||||||
if (keyPressed(K_DOWN)) y += 3;
|
if (keyPressed(K_DOWN)) { y += 3; dir = 3; }
|
||||||
scroll(x - 152, y - 90);
|
scroll(x - 152, y - 90);
|
||||||
drawSprite(&sprites[0 * SPRITE_STRIDE], 50, 50);
|
drawSprite(&sprites[dir * SPRITE_STRIDE], x, y);
|
||||||
drawSprite(&sprites[1 * SPRITE_STRIDE], x, y);
|
|
||||||
drawScreen();
|
drawScreen();
|
||||||
|
|
||||||
z++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
BIN
testbed.exe
BIN
testbed.exe
Binary file not shown.
Loading…
Reference in a new issue