Implement text drawing

This commit is contained in:
Jeremy Penner 2019-02-15 19:39:50 -05:00
parent 835a5159cf
commit 08e8926abb
6 changed files with 50 additions and 96 deletions

BIN
game.exe

Binary file not shown.

View file

@ -1,7 +1,7 @@
: blah
' seremit task-emit !
' log-emit task-echo ! ;
blah
' seremit task-emit !
: start-repl activate blah

BIN
game.prj

Binary file not shown.

133
testbed.c
View file

@ -11,6 +11,42 @@
#include "timer.h"
#include "jorth.h"
/*** T E X T ***/
char far *font = NULL;
void text_init() {
unsigned int fontSeg, fontOff;
asm {
push es
push bp
mov ah, 11h
mov al, 30h
mov bh, 3
int 10h
mov ax, bp
pop bp
mov fontSeg, es
mov fontOff, ax
pop es
}
font = MK_FP(fontSeg, fontOff);
}
void text_draw_char(unsigned int vidOffset, unsigned char c) {
unsigned int fontOffset = c << 3;
int i;
for (i = 0; i < 8; i ++) {
VID[vidOffset] = font[fontOffset++];
vidOffset += PAGE_STRIDE;
}
}
void text_draw(unsigned int vidOffset, unsigned char *s) {
while (*s) {
text_draw_char(vidOffset++, *s++);
}
}
/*** S C R A T C H ***/
#define NUM_TILES 128
@ -34,68 +70,16 @@ void fillMap() {
}
}
#define DIR_N 0
#define DIR_E 1
#define DIR_W 2
#define DIR_S 3
#define STATE_MAP 0
#define STATE_DIALOG 1
struct entity;
typedef struct entity Entity_t;
struct entity {
int x;
int y;
int dir;
int sprites[4];
};
void drawEntity(Entity_t *entity) {
int isprite = entity->sprites[entity->dir];
drawSprite(&sprites[isprite * SPRITE_STRIDE], entity->x, entity->y);
}
void playerThink(Entity_t *self) {
if (keyIsDown(K_LEFT)) { self->x -= 3; self->dir = DIR_W; }
if (keyIsDown(K_RIGHT)) { self->x += 3; self->dir = DIR_E; }
if (keyIsDown(K_UP)) { self->y -= 3; self->dir = DIR_N; }
if (keyIsDown(K_DOWN)) { self->y += 3; self->dir = DIR_S; }
}
typedef struct {
int dy;
int y;
} Footer_t;
typedef struct {
Entity_t player;
Footer_t footer;
int state;
} Game_t;
Game_t game;
void game_init() {
FILE *f;
TifImageMeta_t meta;
game.player.x = 100;
game.player.y = 100;
game.player.dir = DIR_E;
game.player.sprites[DIR_E] = 0;
game.player.sprites[DIR_N] = 1;
game.player.sprites[DIR_W] = 2;
game.player.sprites[DIR_S] = 3;
game.footer.y = 0;
game.state = STATE_MAP;
setEGAMode();
atexit(vid_cleanup);
kbd_init();
timer_init(TIMER_30HZ);
text_init();
tile_init();
fillMap();
@ -121,34 +105,6 @@ void game_init() {
scroll(0, 0);
}
void showDialog() {
game.state = STATE_DIALOG;
game.footer.dy = 1;
}
void dialogThink() {
if (keyWasPressed(K_SPACE)) {
game.footer.dy = -1;
}
game.footer.y += game.footer.dy;
if (game.footer.dy > 0 && game.footer.y > 24) {
game.footer.y = 24;
game.footer.dy = 0;
} else if (game.footer.dy < 0 && game.footer.y < 0) {
game.footer.y = 0;
game.footer.dy = 0;
game.state = STATE_MAP;
}
setSplitScreen(399 - (game.footer.y << 1));
}
void overworldThink() {
if (keyWasPressed(K_SPACE)) {
showDialog();
}
playerThink(&game.player);
scroll(game.player.x - 152, game.player.y - 92);
}
void f_seremit() {
ser_write_byte(TOP().i);
@ -179,6 +135,11 @@ void f_splitscreen() {
setSplitScreen(399 - (TOP().i << 1));
DROP(1);
}
void f_text() { // ( col y s -- )
text_draw(ST2().u + (ST1().u * PAGE_STRIDE), TOP().s);
DROP(3);
}
void game_f_init() {
f_init();
CDEF("seremit", f_seremit);
@ -189,6 +150,7 @@ void game_f_init() {
CDEF("draw-screen", drawScreen);
CDEF("split-screen", f_splitscreen);
CDEF("ticks", f_ticks);
CDEF("text", f_text);
f_loadfile("game.jor");
}
@ -232,15 +194,6 @@ int main() {
f_runstring("tick");
f_taskloop();
f_runstring("draw");
/* if (game.state == STATE_MAP) {
overworldThink();
} else if (game.state == STATE_DIALOG) {
dialogThink();
}
drawEntity(&game.player);
drawScreen();*/
}
return 0;

View file

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "video.h"
#include "tiles.h"
/*** T I L E S ***/
@ -17,11 +18,6 @@
// which is wrong. So instead we do:
// 89ABCDEF 01234567 << 3 => BCDEFXXX 3456789A byteswap => 3456789A BCDEFXXX
#define PAGE_TILES_W 21
#define PAGE_TILES_H 14
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
#define PAGE_STRIDE (PAGE_TILES_W << 1)
void tile_init() {
setLogicalWidth(PAGE_STRIDE >> 1);
}

View file

@ -7,3 +7,8 @@ void loadMap(unsigned char *map, unsigned int w, unsigned int h);
void drawSprite(unsigned int *sprite, int x, int y);
void scroll(int newX, int newY);
void drawScreen();
#define PAGE_TILES_W 21
#define PAGE_TILES_H 14
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
#define PAGE_STRIDE (PAGE_TILES_W << 1)