diff --git a/defs.jor b/defs.jor index ef5cd72..fb3f50c 100755 --- a/defs.jor +++ b/defs.jor @@ -19,11 +19,17 @@ s" jorth.log" open seekend deactivate const LOGFILE : defer word new-word docolon , ' noop , ' ret , ; : redefine ( cp cpdeferred ) cell + ! ; -: for ( from to -- ) here ' r> , ' r> , ; immediate ( r: to from ) +: +towards ( from to -- from+-1 ) + over > if 1 + else 1 - then ; + +: for ( from to -- ) ' r> , here ' r> , ; immediate ( r: to from ) : i ' r@ , ; immediate -: next ' r< , 1 lit ' + , ' r< , ( from+1 to ) - ' 2dup , ' - , ' BNZ_ , , - ' drop , ' drop , ; immediate +: next ' r< , ' r@ , ' +towards , ( from+1 r: to ) + ' dup , ' r@ , ' = , ' BZ_ , , + ' rdrop , ' drop , ; immediate + +: min ( x y -- x|y ) 2dup > if swap then drop ; +: max ( x y -- x|y ) 2dup < if swap then drop ; : decompile word lookup if 1 begin ( cp i ) diff --git a/footer.tif b/footer.tif index 431f113..99812bc 100755 Binary files a/footer.tif and b/footer.tif differ diff --git a/game.exe b/game.exe index 6a08a80..68e9159 100755 Binary files a/game.exe and b/game.exe differ diff --git a/game.jor b/game.jor index 33e9706..f0134d9 100755 --- a/game.jor +++ b/game.jor @@ -126,7 +126,7 @@ var prevbutton rot + swap ; var tileselect -3 const MAXTILE +8 const MAXTILE : mouseworldpos mousepos scrollpos +pos ; : mousetile mouseworldpos 4 >> swap 4 >> swap ; @@ -142,6 +142,19 @@ var tileselect MOUSEL mousedown if tileselect @ mousetile tile b! then ; +: copy-mapseg ( neww oldw y -- ) + r> ( oldw neww r: y ) + 2dup min >rot ( copyw neww oldw ) + r@ * map + ( copyw neww src ) + swap r< * map + ( copyw src dst ) + swap ( newh neww oldw r: oldh ) + 2dup < if 1 r< else r< 1 - 0 then ( newh neww copyw ystart ylim ) + for 2dup i copy-mapseg next + drop swap mapsize! ; + : save-map ( filename -- ) fdeactivate swap overwrite mapsize swap fput fput @@ -149,8 +162,8 @@ var tileselect factivate ; : load-map ( filename -- ) - fdeactivate swap open - fget fget + fdeactivate swap open tell . + fget tell . fget tell . cr .s 2dup * map fread mapsize! factivate ; @@ -220,3 +233,5 @@ JOB listen-for-jobs MODE-MOVE @ ' tick redefine ' full-draw ' draw redefine + +s" pete.map" load-map diff --git a/game.prj b/game.prj index 13d42e4..d4c8b59 100755 Binary files a/game.prj and b/game.prj differ diff --git a/jorth.c b/jorth.c index b5ad6db..73bce6e 100755 --- a/jorth.c +++ b/jorth.c @@ -291,15 +291,14 @@ void f_putc() { void f_fputc() { if (ACTIVE_FILE) { - fputc(TOP().i, ACTIVE_FILE); + fwrite(&TOP().i, 1, 1, ACTIVE_FILE); } DROP(1); } void f_fput() { if (ACTIVE_FILE) { - fputc(TOP().u & 0xff, ACTIVE_FILE); - fputc((TOP().u >> 8) & 0xff, ACTIVE_FILE); + fwrite(&TOP().u, 2, 1, ACTIVE_FILE); } DROP(1); } @@ -312,18 +311,21 @@ void f_fwrite() { // ( length p ) } void f_fgetc() { + int result = EOF; if (ACTIVE_FILE) { - PUSHI(fgetc(ACTIVE_FILE)); - } else { - PUSHI(EOF); + char byte = 0; + if (fread(&byte, 1, 1, ACTIVE_FILE) == 1) { + result = byte; + } } + PUSHI(result); } void f_fget() { if (ACTIVE_FILE) { - int low = fgetc(ACTIVE_FILE); - int high = fgetc(ACTIVE_FILE); - PUSHU(low | (high << 8)); + int result = 0; + int err = fread(&result, 2, 1, ACTIVE_FILE); + PUSHU(result); } else { PUSHU(0); // no way to signal EOF } @@ -637,7 +639,7 @@ void f_close() { void f_open() { FILE *fp; f_close(); - fp = fopen(TOP().s, "a+"); + fp = fopen(TOP().s, "ab+"); fseek(fp, 0, SEEK_SET); ACTIVE_FILE = fp; DROP(1); @@ -645,7 +647,7 @@ void f_open() { void f_overwrite() { f_close(); - ACTIVE_FILE = fopen(TOP().s, "w+"); + ACTIVE_FILE = fopen(TOP().s, "wb+"); DROP(1); } @@ -744,6 +746,10 @@ void f_inline_data_() { IP = *IP.p; } +void f_memmove() { // ( dst src size -- ) + memmove(ST2().p, ST1().p, TOP().u); + DROP(3); +} void f_quote() { if (STATE.i) { PUSHS("LIT_"); @@ -923,12 +929,14 @@ void f_init() { CDEF("fdeactivate", f_deactivate); CDEF("seek", f_seek); CDEF("seekend", f_seekend); + CDEF("tell", f_tell); CDEF("fputc", f_fputc); CDEF("fput", f_fput); CDEF("fgetc", f_fgetc); CDEF("fget", f_fget); CDEF("fwrite", f_fwrite); CDEF("fread", f_fread); + CDEF("memmove", f_memmove); CDEF("quiet", f_quiet); CDEF("loud", f_loud); CDEF("task", f_task); diff --git a/pete.map b/pete.map new file mode 100755 index 0000000..f64bffd Binary files /dev/null and b/pete.map differ diff --git a/tiles.tif b/tiles.tif index ebfcf60..debcfba 100755 Binary files a/tiles.tif and b/tiles.tif differ