diff --git a/defs.jor b/defs.jor index fb3f50c..4d8b011 100755 --- a/defs.jor +++ b/defs.jor @@ -10,15 +10,23 @@ s" jorth.log" open seekend deactivate const LOGFILE : noop ; -' cells @ const docolon ( get the colon execution token ) -: :noname here docolon , ] ; +' cells @ const $DOCOLON ( get the colon execution token ) +: :noname here $DOCOLON , ] ; -: :| inline| :noname ; immediate +: :| inline| $DOCOLON , ; immediate : |; ' ret , |inline ; immediate -: defer word new-word docolon , ' noop , ' ret , ; +: defer word new-word $DOCOLON , ' noop , ' ret , ; : 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 ) over > if 1 + else 1 - then ; diff --git a/egamap.h b/egamap.h new file mode 100755 index 0000000..ca621c5 --- /dev/null +++ b/egamap.h @@ -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) diff --git a/footer.tif b/footer.tif index 99812bc..c4d3ba6 100755 Binary files a/footer.tif and b/footer.tif differ diff --git a/game.exe b/game.exe index 68e9159..781709d 100755 Binary files a/game.exe and b/game.exe differ diff --git a/game.jor b/game.jor index f0134d9..91431c4 100755 --- a/game.jor +++ b/game.jor @@ -90,9 +90,35 @@ var footer-y : draw-footer footer-y @ split-screen ; -: text1 6 4 @ >rot ticks ( from to duration start ) @@ -103,11 +129,20 @@ var footer-y >rot suspend 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 ; -: say1 ( s -- ) clear text1 show-footer ^ENTER wait-key ; -: say2 ( s1 s2 -- ) clear text2 text1 show-footer ^ENTER wait-key ; +: footer-wait 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 ) @@ -162,8 +197,8 @@ var tileselect factivate ; : load-map ( filename -- ) - fdeactivate swap open tell . - fget tell . fget tell . cr .s + fdeactivate swap open + fget fget 2dup * map fread mapsize! factivate ; diff --git a/game.prj b/game.prj index d4c8b59..fd09030 100755 Binary files a/game.prj and b/game.prj differ diff --git a/jorth.c b/jorth.c index 73bce6e..5f80dbb 100755 --- a/jorth.c +++ b/jorth.c @@ -324,7 +324,7 @@ void f_fgetc() { void f_fget() { if (ACTIVE_FILE) { int result = 0; - int err = fread(&result, 2, 1, ACTIVE_FILE); + fread(&result, 2, 1, ACTIVE_FILE); PUSHU(result); } else { PUSHU(0); // no way to signal EOF @@ -413,9 +413,7 @@ void f_create() { // name -- void f_cdef() { // func name -- f_create(); - HERE->p = TOP().p; - HERE ++; - DROP(1); + f_comma(); } void f_docolon(); @@ -719,6 +717,12 @@ void f_var() { f_comma(); } +void f_docreate() { + PUSHCP(W.p + 2); + RPUSH(IP); + IP = *(W.p + 1); +} + void f_bz_() { if (!TOP().u) { IP.p = IP.p->p; // branch @@ -946,6 +950,7 @@ void f_init() { CDEF("stacksize", f_stacksize); CDEF("rstacksize", f_rstacksize); CDEF("task-user-size", f_taskusersize); + PCONST("$DOCREATE", f_docreate); PUSHS("boot.jor"); f_open(); diff --git a/jorth.h b/jorth.h index 348b18d..6978187 100755 --- a/jorth.h +++ b/jorth.h @@ -7,7 +7,6 @@ void f_init(); void f_cdef(); -#define CDEF(name, def) PUSHP(def); PUSHS(name); f_cdef() void f_immediate(); void f_loadfile(char *filename); @@ -64,5 +63,9 @@ void f_comma(); void f_bcomma(); void f_create(); // name -- void f_cdef(); // func name -- +void f_doconst(); 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() diff --git a/portrait.tif b/portrait.tif new file mode 100755 index 0000000..d613391 Binary files /dev/null and b/portrait.tif differ diff --git a/testbed.c b/testbed.c index d3196cc..367c2a0 100755 --- a/testbed.c +++ b/testbed.c @@ -10,6 +10,7 @@ #include "serial.h" #include "timer.h" #include "jorth.h" +#include "egamap.h" /*** T E X T ***/ char far *font = NULL; @@ -49,9 +50,7 @@ void text_draw(unsigned int vidOffset, unsigned char *s) { /*** S C R A T C H ***/ -#define NUM_TILES 128 #define NUM_SPRITES 64 -#define OFF_TILES 0x5000 #define TILE_STRIDE 64 #define SPRITE_STRIDE 80 unsigned int tiles[NUM_TILES * TILE_STRIDE]; @@ -88,7 +87,7 @@ void game_init() { f = fopen("FOOTER.TIF", "rb"); meta = tifLoadMeta(f); - tifLoadEGA(f, meta, 0, 24, 336); + tifLoadEGA(f, meta, 0, 48, 336); fclose(f); f = fopen("TILES.TIF", "rb"); @@ -102,6 +101,11 @@ void game_init() { tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5); 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); loadMap(map, 100, 100); scroll(0, 0); @@ -144,7 +148,11 @@ void f_splitscreen() { 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); DROP(3); } @@ -171,12 +179,20 @@ void f_mousebuttons() { 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() { f_init(); CDEF("seremit", f_seremit); CDEF("key-pressed", f_keyWasPressed); CDEF("key-down", f_keyIsDown); CDEF("draw-sprite", f_drawSprite); + CDEF("draw-portrait", f_drawportrait); CDEF("scroll", f_scroll); CDEF("scrollpos", f_scrollpos); CDEF("draw-screen", drawScreen); @@ -188,7 +204,7 @@ void game_f_init() { CDEF("mapsize!", f_mapsize_set); CDEF("mousepos", f_mousepos); CDEF("mousebuttons", f_mousebuttons); - + CDEF("unfuck", tile_init); f_loadfile("game.jor"); } diff --git a/tiles.c b/tiles.c index 10a774c..44db0b4 100755 --- a/tiles.c +++ b/tiles.c @@ -3,6 +3,7 @@ #include #include "video.h" #include "tiles.h" +#include "egamap.h" /*** 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_BGTILE 0x81 #define isBufIndex(d) (!((d) & 0x80)) #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 }; void loadTiles(unsigned int tilesOffset, unsigned int *memTiles) { diff --git a/tiles.h b/tiles.h index 89d68e0..1401e45 100755 --- a/tiles.h +++ b/tiles.h @@ -1,4 +1,6 @@ /*** T I L E S ***/ +#ifndef __TILES_H__ +#define __TILES_H__ void tile_init(); @@ -8,6 +10,8 @@ void drawSprite(unsigned int *sprite, int x, int y); void scroll(int newX, int newY); void drawScreen(); +void blit32x32(unsigned int offsetFrom, unsigned int offsetTo); + #define PAGE_TILES_W 21 #define PAGE_TILES_H 14 #define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W) @@ -34,4 +38,6 @@ typedef struct { unsigned char firstBuffer; } TiledScreen_t; -extern TiledScreen_t screen; \ No newline at end of file +extern TiledScreen_t screen; + +#endif \ No newline at end of file diff --git a/video.h b/video.h index 491a177..505d39d 100755 --- a/video.h +++ b/video.h @@ -15,7 +15,8 @@ #define PLANE_R 0x02 #define PLANE_I 0x03 #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)