Bigger footer, portrait support, coloured text

This commit is contained in:
Jeremy Penner 2019-02-25 22:19:08 -05:00
parent 20e7089b84
commit 114d1ff804
13 changed files with 126 additions and 25 deletions

View file

@ -10,15 +10,23 @@ s" jorth.log" open seekend deactivate const LOGFILE
: noop ; : noop ;
' cells @ const docolon ( get the colon execution token ) ' cells @ const $DOCOLON ( get the colon execution token )
: :noname here docolon , ] ; : :noname here $DOCOLON , ] ;
: :| inline| :noname ; immediate : :| inline| $DOCOLON , ; immediate
: |; ' ret , |inline ; immediate : |; ' ret , |inline ; immediate
: defer word new-word docolon , ' noop , ' ret , ; : defer word new-word $DOCOLON , ' noop , ' ret , ;
: redefine ( cp cpdeferred ) cell + ! ; : redefine ( cp cpdeferred ) cell + ! ;
: create word new-word $DOCREATE , 0 , ;
: finishcreate ( ipfirst -- )
( set cell after codepointer to first instruction of does> )
latest codepointer cell + ! ;
: does> here 4 cells + lit ' finishcreate , ' ret , ] ; immediate
: +towards ( from to -- from+-1 ) : +towards ( from to -- from+-1 )
over > if 1 + else 1 - then ; over > if 1 + else 1 - then ;

15
egamap.h Executable file
View file

@ -0,0 +1,15 @@
#include "tiles.h"
#define NUM_TILES 128
#define NUM_PORTRAITS 16
#define SIZE_FOOTER (PAGE_STRIDE * 48)
#define SIZE_PAGE (PAGE_STRIDE * (PAGE_TILES_H << 4))
#define SIZE_TILES (NUM_TILES << 5)
#define SIZE_PORTRAITS (NUM_PORTRAITS << 7)
#define OFF_FOOTER 0
#define OFF_PAGE1 (OFF_FOOTER + SIZE_FOOTER)
#define OFF_PAGE2 (OFF_PAGE1 + SIZE_PAGE)
#define OFF_TILES (OFF_PAGE2 + SIZE_PAGE)
#define OFF_PORTRAITS (OFF_TILES + SIZE_TILES)

Binary file not shown.

BIN
game.exe

Binary file not shown.

View file

@ -90,9 +90,35 @@ var footer-y
: draw-footer footer-y @ split-screen ; : draw-footer footer-y @ split-screen ;
: text1 6 4 <rot text ; 0 const BLACK
: text2 6 12 <rot text ; 1 const BLUE
: clear s" " dup text1 text2 ; 2 const GREEN
3 const CYAN
4 const RED
5 const MAGENTA
6 const BROWN
7 const LGRAY
8 const DGRAY
9 const LBLUE
10 const LGREEN
11 const LCYAN
12 const PINK
13 const LMAGENTA
14 const YELLOW
15 const WHITE
var text-color
WHITE text-color !
: texty 7 swap <rot text-color @ text ;
: text0 10 texty ;
: text1 20 texty ;
: text2 30 texty ;
: clear
text-color @
WHITE text-color !
s" " dup dup text0 text1 text2
text-color ! ;
: move-to ( target speed p -- ) : move-to ( target speed p -- )
dup r> @ >rot ticks ( from to duration start ) dup r> @ >rot ticks ( from to duration start )
@ -103,11 +129,20 @@ var footer-y
>rot suspend >rot suspend
repeat rdrop drop drop drop drop ; repeat rdrop drop drop drop drop ;
: show-footer 24 10 footer-y move-to ; : show-footer 48 10 footer-y move-to ;
: hide-footer 0 10 footer-y move-to ; : hide-footer 0 10 footer-y move-to ;
: say1 ( s -- ) clear text1 show-footer ^ENTER wait-key ; : footer-wait show-footer ^ENTER wait-key ;
: say2 ( s1 s2 -- ) clear text2 text1 show-footer ^ENTER wait-key ; : say1 ( s -- ) clear text1 footer-wait ;
: say2 ( s1 s2 -- ) clear text1 text0 footer-wait ;
: say3 ( s1 s2 s3 -- ) clear text2 text1 text0 footer-wait ;
: character ( iportrait color ) create , ,
does> dup @ text-color ! cell + @ draw-portrait ;
0 GREEN character pete
1 MAGENTA character mary
2 BROWN character chuck
( M O U S E ) ( M O U S E )
@ -162,8 +197,8 @@ var tileselect
factivate ; factivate ;
: load-map ( filename -- ) : load-map ( filename -- )
fdeactivate swap open tell . fdeactivate swap open
fget tell . fget tell . cr .s fget fget
2dup * map fread 2dup * map fread
mapsize! mapsize!
factivate ; factivate ;

BIN
game.prj

Binary file not shown.

13
jorth.c
View file

@ -324,7 +324,7 @@ void f_fgetc() {
void f_fget() { void f_fget() {
if (ACTIVE_FILE) { if (ACTIVE_FILE) {
int result = 0; int result = 0;
int err = fread(&result, 2, 1, ACTIVE_FILE); fread(&result, 2, 1, ACTIVE_FILE);
PUSHU(result); PUSHU(result);
} else { } else {
PUSHU(0); // no way to signal EOF PUSHU(0); // no way to signal EOF
@ -413,9 +413,7 @@ void f_create() { // name --
void f_cdef() { // func name -- void f_cdef() { // func name --
f_create(); f_create();
HERE->p = TOP().p; f_comma();
HERE ++;
DROP(1);
} }
void f_docolon(); void f_docolon();
@ -719,6 +717,12 @@ void f_var() {
f_comma(); f_comma();
} }
void f_docreate() {
PUSHCP(W.p + 2);
RPUSH(IP);
IP = *(W.p + 1);
}
void f_bz_() { void f_bz_() {
if (!TOP().u) { if (!TOP().u) {
IP.p = IP.p->p; // branch IP.p = IP.p->p; // branch
@ -946,6 +950,7 @@ void f_init() {
CDEF("stacksize", f_stacksize); CDEF("stacksize", f_stacksize);
CDEF("rstacksize", f_rstacksize); CDEF("rstacksize", f_rstacksize);
CDEF("task-user-size", f_taskusersize); CDEF("task-user-size", f_taskusersize);
PCONST("$DOCREATE", f_docreate);
PUSHS("boot.jor"); PUSHS("boot.jor");
f_open(); f_open();

View file

@ -7,7 +7,6 @@
void f_init(); void f_init();
void f_cdef(); void f_cdef();
#define CDEF(name, def) PUSHP(def); PUSHS(name); f_cdef()
void f_immediate(); void f_immediate();
void f_loadfile(char *filename); void f_loadfile(char *filename);
@ -64,5 +63,9 @@ void f_comma();
void f_bcomma(); void f_bcomma();
void f_create(); // name -- void f_create(); // name --
void f_cdef(); // func name -- void f_cdef(); // func name --
void f_doconst();
void f_compileword(); void f_compileword();
#define CDEF(name, def) PUSHP(def); PUSHS(name); f_cdef()
#define ICONST(name, v) CDEF(name, f_doconst); PUSHI(v); f_comma()
#define PCONST(name, p) CDEF(name, f_doconst); PUSHP(p); f_comma()

BIN
portrait.tif Executable file

Binary file not shown.

View file

@ -10,6 +10,7 @@
#include "serial.h" #include "serial.h"
#include "timer.h" #include "timer.h"
#include "jorth.h" #include "jorth.h"
#include "egamap.h"
/*** T E X T ***/ /*** T E X T ***/
char far *font = NULL; char far *font = NULL;
@ -49,9 +50,7 @@ void text_draw(unsigned int vidOffset, unsigned char *s) {
/*** S C R A T C H ***/ /*** S C R A T C H ***/
#define NUM_TILES 128
#define NUM_SPRITES 64 #define NUM_SPRITES 64
#define OFF_TILES 0x5000
#define TILE_STRIDE 64 #define TILE_STRIDE 64
#define SPRITE_STRIDE 80 #define SPRITE_STRIDE 80
unsigned int tiles[NUM_TILES * TILE_STRIDE]; unsigned int tiles[NUM_TILES * TILE_STRIDE];
@ -88,7 +87,7 @@ void game_init() {
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, 48, 336);
fclose(f); fclose(f);
f = fopen("TILES.TIF", "rb"); f = fopen("TILES.TIF", "rb");
@ -102,6 +101,11 @@ void game_init() {
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5); tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
fclose(f); fclose(f);
f = fopen("PORTRAIT.TIF", "rb");
meta = tifLoadMeta(f);
tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32);
fclose(f);
loadTiles(OFF_TILES, tiles); loadTiles(OFF_TILES, tiles);
loadMap(map, 100, 100); loadMap(map, 100, 100);
scroll(0, 0); scroll(0, 0);
@ -144,7 +148,11 @@ void f_splitscreen() {
DROP(1); DROP(1);
} }
void f_text() { // ( col line s -- )
void f_text() { // ( col line s color -- )
setWriteMode(0);
setPlaneColor(TOP().u);
DROP(1);
text_draw(ST2().u + (ST1().u * PAGE_STRIDE), TOP().s); text_draw(ST2().u + (ST1().u * PAGE_STRIDE), TOP().s);
DROP(3); DROP(3);
} }
@ -171,12 +179,20 @@ void f_mousebuttons() {
PUSHI(MOUSE.buttons); PUSHI(MOUSE.buttons);
} }
void f_drawportrait() {
setAllPlanes();
setWriteMode(1);
blit32x32(OFF_PORTRAITS + (TOP().u << 7), (PAGE_STRIDE << 3) + 1);
DROP(1);
}
void game_f_init() { void game_f_init() {
f_init(); f_init();
CDEF("seremit", f_seremit); CDEF("seremit", f_seremit);
CDEF("key-pressed", f_keyWasPressed); CDEF("key-pressed", f_keyWasPressed);
CDEF("key-down", f_keyIsDown); CDEF("key-down", f_keyIsDown);
CDEF("draw-sprite", f_drawSprite); CDEF("draw-sprite", f_drawSprite);
CDEF("draw-portrait", f_drawportrait);
CDEF("scroll", f_scroll); CDEF("scroll", f_scroll);
CDEF("scrollpos", f_scrollpos); CDEF("scrollpos", f_scrollpos);
CDEF("draw-screen", drawScreen); CDEF("draw-screen", drawScreen);
@ -188,7 +204,7 @@ void game_f_init() {
CDEF("mapsize!", f_mapsize_set); CDEF("mapsize!", f_mapsize_set);
CDEF("mousepos", f_mousepos); CDEF("mousepos", f_mousepos);
CDEF("mousebuttons", f_mousebuttons); CDEF("mousebuttons", f_mousebuttons);
CDEF("unfuck", tile_init);
f_loadfile("game.jor"); f_loadfile("game.jor");
} }

14
tiles.c
View file

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "video.h" #include "video.h"
#include "tiles.h" #include "tiles.h"
#include "egamap.h"
/*** T I L E S ***/ /*** T I L E S ***/
@ -31,13 +32,24 @@ void blitTile(unsigned int offsetFrom, unsigned int offsetTo) {
} }
} }
void blit32x32(unsigned int offsetFrom, unsigned int offsetTo) {
int y;
for (y = 0; y < 32; y ++) {
VID[offsetTo] = VID[offsetFrom ++];
VID[offsetTo + 1] = VID[offsetFrom ++];
VID[offsetTo + 2] = VID[offsetFrom ++];
VID[offsetTo + 3] = VID[offsetFrom ++];
offsetTo += PAGE_STRIDE;
}
}
#define D_NOTHING 0x80 #define D_NOTHING 0x80
#define D_BGTILE 0x81 #define D_BGTILE 0x81
#define isBufIndex(d) (!((d) & 0x80)) #define isBufIndex(d) (!((d) & 0x80))
#define nextBufferIndex(i) ((i + 1) % NUM_BUFFERS) #define nextBufferIndex(i) ((i + 1) % NUM_BUFFERS)
TiledScreen_t screen = { 0, 0, 0, 0, { 0x0600, 0x2B00 }, 0, 0, NULL, NULL, TiledScreen_t screen = { 0, 0, 0, 0, { OFF_PAGE1, OFF_PAGE2 }, 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) {

View file

@ -1,4 +1,6 @@
/*** T I L E S ***/ /*** T I L E S ***/
#ifndef __TILES_H__
#define __TILES_H__
void tile_init(); void tile_init();
@ -8,6 +10,8 @@ void drawSprite(unsigned int *sprite, int x, int y);
void scroll(int newX, int newY); void scroll(int newX, int newY);
void drawScreen(); void drawScreen();
void blit32x32(unsigned int offsetFrom, unsigned int offsetTo);
#define PAGE_TILES_W 21 #define PAGE_TILES_W 21
#define PAGE_TILES_H 14 #define PAGE_TILES_H 14
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W) #define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)
@ -35,3 +39,5 @@ typedef struct {
} TiledScreen_t; } TiledScreen_t;
extern TiledScreen_t screen; extern TiledScreen_t screen;
#endif

View file

@ -15,7 +15,8 @@
#define PLANE_R 0x02 #define PLANE_R 0x02
#define PLANE_I 0x03 #define PLANE_I 0x03
#define setPlane(p) outport(REG_TS, 2 | (0x100 << p)) #define setPlane(p) outport(REG_TS, 2 | (0x100 << p))
#define setAllPlanes() outport(REG_TS, 0x0f02) #define setPlaneColor(c) outport(REG_TS, 2 | (c << 8))
#define setAllPlanes() setPlaneColor(0x0f)
#define setWriteMode(m) outport(REG_GDC, 0x05 | m << 8) #define setWriteMode(m) outport(REG_GDC, 0x05 | m << 8)