diff --git a/boot.jor b/boot.jor index f764b7a..2d3e63e 100755 --- a/boot.jor +++ b/boot.jor @@ -35,8 +35,7 @@ key const sp then then ; : interpreter - begin word dup b@ while compileword repeat - s" ok" type cr drop ; + begin word dup b@ while compileword repeat drop ; : load-input swap-input r> r> interpreter r< r< swap-input ; : loadstring ' key-string load-input drop drop ; : loadfile ' key-file load-input drop close ; diff --git a/defs.jor b/defs.jor index 10f3b98..8b161a3 100755 --- a/defs.jor +++ b/defs.jor @@ -6,6 +6,10 @@ s" jorth.log" open const LOGFILE : :noname here docolon , ] ; : 2dup over over ; +: noop ; + +: defer word new-word docolon , ' noop , ' ret , ; +: is ( cp -- ) word lookup drop cell + ! ; : decompile word lookup if 1 begin ( cp i ) diff --git a/game.exe b/game.exe index d067456..99625a7 100755 Binary files a/game.exe and b/game.exe differ diff --git a/game.jor b/game.jor index 9c4b4f5..6bba236 100755 --- a/game.jor +++ b/game.jor @@ -4,12 +4,10 @@ : start-repl activate blah s" .:: J O R T H ( jean forth) ::." type cr - begin receive loadstring again ; + begin receive loadstring s" ok" type cr again ; task const REPL REPL start-repl -task const TEST - 1 const ^ESC 28 const ^ENTER 29 const ^CTRL @@ -29,9 +27,53 @@ task const TEST then ; : sleep ( count -- ) ticks swap begin over ticks udelta over u< while suspend repeat drop drop ; -: test TEST activate blah - ^SPACE wait-key - s" SPACE" type - 30 sleep - s" is big" type ; -test + +defer tick +defer draw + +: defentity var 2 cells allot ; +: entity.x ; +: entity.y cell + ; +: entity.dir 2 cells + ; + +0 const W +1 const E +2 const N +3 const S + +: defsprite ( s n e w ) b, b, b, b, here 4 - const ; +: sprindex ( sprite dir ) + b@ ; + +3 1 0 2 defsprite s_car + +defentity player + +100 player entity.x ! +100 player entity.y ! + +: tick-player + 0 ^LEFT key-down if 3 - W player entity.dir ! then + ^RIGHT key-down if 3 + E player entity.dir ! then + player entity.x +! + 0 ^UP key-down if 3 - N player entity.dir ! then + ^DOWN key-down if 3 + S player entity.dir ! then + player entity.y +! ; + +: draw-player + player entity.x @ + player entity.y @ + s_car player entity.dir @ sprindex + draw-sprite ; + +: full-draw + player entity.x @ 152 - + player entity.y @ 92 - + scroll + + draw-player + 50 50 0 draw-sprite + 600 600 2 draw-sprite + draw-screen ; + +' tick-player is tick +' full-draw is draw diff --git a/game.prj b/game.prj index 8927fc9..de0d414 100755 Binary files a/game.prj and b/game.prj differ diff --git a/jorth.c b/jorth.c index 004a0ff..a7cd066 100755 --- a/jorth.c +++ b/jorth.c @@ -123,6 +123,11 @@ void f_bset() { DROP(1); } +void f_addset() { + TOP().p->i += ST1().i; + DROP(2); +} + void f_drop() { DROP(1); } @@ -300,6 +305,11 @@ void f_comma() { DROP(1); } +void f_allot() { + HERE = CELL_OFFSET(HERE, TOP().u); + DROP(1); +} + void f_bcomma() { *((char*)HERE) = TOP().i; HERE = CELL_OFFSET(HERE, 1); @@ -375,9 +385,6 @@ void f_execute() { f_colondispatch(); } -void f_noop() { -} - void f_lit_() { PUSHC(*IP.p); IP.p++; @@ -750,17 +757,21 @@ void f_init() { CDEF("word", f_word); CDEF("immediate", f_immediate); CDEF("execute", f_execute); - CDEF("create", f_create); + CDEF("new-word", f_create); CDEF("here", f_here); CDEF("latest", f_latest); CDEF("state", f_state); CDEF("'", f_quote); f_immediate(); CDEF("`", f_revlookup); + CDEF("wordname", f_wordname); + CDEF("wordflags", f_wordflags); + CDEF("codepointer", f_codepointer); CDEF("lookup", f_lookup); CDEF(":", f_colon); CDEF(";", f_semicolon); f_immediate(); CDEF("const", f_const); CDEF("var", f_var); + CDEF("allot", f_allot); CDEF("+", f_add); CDEF("-", f_sub); CDEF("*", f_mul); @@ -785,6 +796,7 @@ void f_init() { CDEF("^", f_bitxor); CDEF("@", f_get); CDEF("!", f_set); + CDEF("+!", f_addset); CDEF("b@", f_bget); CDEF("b!", f_bset); CDEF("dup", f_dup); @@ -814,7 +826,6 @@ void f_init() { CDEF("b,", f_bcomma); CDEF("s\"", f_string); f_immediate(); CDEF("S\"_", f_string_); - CDEF("noop", f_noop); CDEF("open", f_open); CDEF("close", f_close); CDEF("quiet", f_quiet); diff --git a/testbed.c b/testbed.c index e44853c..0e1a2a0 100755 --- a/testbed.c +++ b/testbed.c @@ -170,6 +170,7 @@ void f_drawSprite() { // ( x y sprite -- ) } void f_scroll() { // ( x y -- ) scroll(ST1().i, TOP().i); + DROP(2); } void f_ticks() { PUSHU(timer_counter); @@ -180,9 +181,9 @@ void game_f_init() { CDEF("seremit", f_seremit); CDEF("key-pressed", f_keyWasPressed); CDEF("key-down", f_keyIsDown); - CDEF("sprite", f_drawSprite); + CDEF("draw-sprite", f_drawSprite); CDEF("scroll", f_scroll); - CDEF("draw", drawScreen); + CDEF("draw-screen", drawScreen); CDEF("ticks", f_ticks); f_loadfile("game.jor"); @@ -213,7 +214,6 @@ void f_poll() { line[i] = '\0'; } } - f_taskloop(); } int main() { @@ -224,14 +224,19 @@ int main() { while (!keyIsDown(K_ESC)) { kbd_debounce(); f_poll(); + f_taskloop(); + f_runstring("tick"); + f_taskloop(); + f_runstring("draw"); - if (game.state == STATE_MAP) { +/* if (game.state == STATE_MAP) { overworldThink(); } else if (game.state == STATE_DIALOG) { dialogThink(); } drawEntity(&game.player); - drawScreen(); + drawScreen();*/ + } return 0;