├── .gitmodules ├── prg └── dummy.txt ├── ramen.bat ├── sample └── platformer │ ├── preamble.f │ ├── test.f │ ├── blackness.f │ ├── bg.f │ ├── data │ ├── tiles.png │ ├── tiles.tsx │ └── level01.tmx │ ├── break.f │ ├── map.f │ ├── camera.f │ ├── helpers.f │ ├── lib │ ├── buffer2d.f │ ├── collision.f │ ├── array2d.f │ └── tilemap2.f │ ├── platformer.f │ ├── player.f │ ├── particles.f │ └── tools.f ├── .gitignore ├── afkit ├── dep │ ├── wincon.dll │ ├── zlib │ │ ├── libzlib.dll │ │ └── zlib.f │ └── allegro5 │ │ ├── 5.2.3 │ │ ├── libenet.dll │ │ ├── libogg-0.dll │ │ ├── libpng16.dll │ │ ├── libzlib.dll │ │ ├── libFLAC-8.dll │ │ ├── libjpeg-62.dll │ │ ├── libphysfs.dll │ │ ├── libFLAC++-6.dll │ │ ├── libfreetype.dll │ │ ├── libstdc++-6.dll │ │ ├── libtheora-0.dll │ │ ├── libturbojpeg.dll │ │ ├── libvorbis-0.dll │ │ ├── libgcc_s_dw2-1.dll │ │ ├── libtheoradec-1.dll │ │ ├── libtheoraenc-1.dll │ │ ├── libvorbisenc-2.dll │ │ ├── libvorbisfile-3.dll │ │ ├── libwinpthread-1.dll │ │ ├── allegro_monolith-5.2.dll │ │ └── allegro_monolith-debug-5.2.dll │ │ ├── allegro5_07_misc.f │ │ ├── allegro5_06_fs.f │ │ ├── allegro-5.2.x.f │ │ ├── allegro5_03_keys.f │ │ ├── allegro5_02_events.f │ │ └── allegro5_04_audio.f ├── SUMMARY.md ├── plat │ ├── sfwin32.f │ ├── gfwin32.f │ ├── sflinux.f │ ├── win │ │ ├── clipb.f │ │ └── fpext.f │ ├── sf.f │ └── sf │ │ └── fixedp.f ├── ans │ ├── depend.f │ ├── param-enclosures.f │ ├── version.f │ ├── strops.f │ ├── files.f │ └── roger.f ├── platforms.f ├── LICENSE.md ├── audio-allegro.f ├── README.md ├── piston.f └── afkit.f ├── make_platformer.bat ├── ramen ├── SUMMARY.md ├── ide │ ├── data │ │ ├── consolab.ttf │ │ └── consolas16.png │ ├── v2d.f │ └── ide.f ├── lib │ ├── a.f │ ├── pjoy.f │ ├── utils.f │ ├── std │ │ ├── kb.f │ │ ├── audio.f │ │ ├── zsort.f │ │ ├── rangetools.f │ │ ├── transform.f │ │ ├── v2d.f │ │ ├── task.f │ │ ├── sprites.f │ │ └── actor.f │ ├── upscale.f │ ├── tween.f │ └── rsort.f ├── minimal.f ├── ramen.f ├── buffer.f ├── sample.f ├── basic.f ├── system.f ├── res.f ├── font.f ├── types.f ├── make_sfwin.bat ├── LICENSE.md ├── publish.f ├── assets.f ├── default.f ├── structs.f ├── image.f ├── base.f ├── README.md ├── fixops.f └── draw.f ├── kitconfig.f ├── venery ├── README.md ├── venery.komodoproject ├── .komodotools │ └── sf_include_venery_f-1.ktf ├── notes.txt ├── test.f ├── string.f ├── array.f ├── nodetree.f └── venery.f ├── ex ├── actors-1.f ├── actors-2.f └── bubbles.f ├── loader.f ├── common-ui.f ├── .komodotools └── sf_include_loader_f.komodotool ├── RamenEngine.komodoproject ├── LICENSE.md ├── README.md └── allegro5.cfg /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /prg/dummy.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ramen.bat: -------------------------------------------------------------------------------- 1 | sf include loader.f -------------------------------------------------------------------------------- /sample/platformer/preamble.f: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample/platformer/test.f: -------------------------------------------------------------------------------- 1 | .( hi) -------------------------------------------------------------------------------- /sample/platformer/blackness.f: -------------------------------------------------------------------------------- 1 | blackness as 2 | :now draw> black viewwh rectf ; 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | session.f 2 | allegro\.log 3 | _*.* 4 | bin 5 | private 6 | temp 7 | prg/*/ -------------------------------------------------------------------------------- /afkit/dep/wincon.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/wincon.dll -------------------------------------------------------------------------------- /make_platformer.bat: -------------------------------------------------------------------------------- 1 | ./ramen/make_sfwin.bat platformer sample/platformer/platformer.f sample\platformer -------------------------------------------------------------------------------- /sample/platformer/bg.f: -------------------------------------------------------------------------------- 1 | bg0 as 2 | 3 | /tilemap \ this draws the background 4 | -------------------------------------------------------------------------------- /afkit/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | * [README](README.md) 4 | * [LICENSE](license.md) 5 | 6 | -------------------------------------------------------------------------------- /ramen/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | * [README](README.md) 4 | * [LICENSE](license.md) 5 | 6 | -------------------------------------------------------------------------------- /afkit/dep/zlib/libzlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/zlib/libzlib.dll -------------------------------------------------------------------------------- /ramen/ide/data/consolab.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/ramen/ide/data/consolab.ttf -------------------------------------------------------------------------------- /ramen/ide/data/consolas16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/ramen/ide/data/consolas16.png -------------------------------------------------------------------------------- /sample/platformer/data/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/sample/platformer/data/tiles.png -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libenet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libenet.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libogg-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libogg-0.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libpng16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libpng16.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libzlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libzlib.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libFLAC-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libFLAC-8.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libjpeg-62.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libjpeg-62.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libphysfs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libphysfs.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libFLAC++-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libFLAC++-6.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libfreetype.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libfreetype.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libstdc++-6.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libstdc++-6.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libtheora-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libtheora-0.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libturbojpeg.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libturbojpeg.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libvorbis-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libvorbis-0.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libgcc_s_dw2-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libgcc_s_dw2-1.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libtheoradec-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libtheoradec-1.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libtheoraenc-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libtheoraenc-1.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libvorbisenc-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libvorbisenc-2.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libvorbisfile-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libvorbisfile-3.dll -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/libwinpthread-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/libwinpthread-1.dll -------------------------------------------------------------------------------- /afkit/plat/sfwin32.f: -------------------------------------------------------------------------------- 1 | : platform s" sfwin32" ; 2 | 3 | requires fpmath 4 | include afkit/dep/allegro5/allegro-5.2.x.f 5 | include afkit/plat/sf.f 6 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/allegro_monolith-5.2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/allegro_monolith-5.2.dll -------------------------------------------------------------------------------- /ramen/lib/a.f: -------------------------------------------------------------------------------- 1 | 0 value a@ 2 | : @+ a@ @ cell +to a@ ; 3 | : !+ a@ ! cell +to a@ ; 4 | : a! to a@ ; 5 | : a!> r> a@ >r swap a! call r> a! ; 6 | : +a cells +to a@ ; -------------------------------------------------------------------------------- /ramen/lib/pjoy.f: -------------------------------------------------------------------------------- 1 | \ fixed point joystick wordset adapter 2 | : joy[] 1i joy[] ; 3 | : #joys #joys 1p ; 4 | : stick 2i stick f>p f>p swap ; 5 | : btn 2i btn ; 6 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/5.2.3/allegro_monolith-debug-5.2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramenengine/RamenEngine/HEAD/afkit/dep/allegro5/5.2.3/allegro_monolith-debug-5.2.dll -------------------------------------------------------------------------------- /ramen/lib/utils.f: -------------------------------------------------------------------------------- 1 | : array: create array, ; 2 | : stack: create stack, ; 3 | : nodetree: create _node static, ; 4 | : vector: create 3, ; 5 | : color: create 4, ; 6 | -------------------------------------------------------------------------------- /afkit/plat/gfwin32.f: -------------------------------------------------------------------------------- 1 | : platform s" gfwin32" ; 2 | 3 | \ include afkit/ans/ffl/sfwin32/ffl.f \ FFL: DOM; FFL loads FPMATH 4 | include afkit/dep/allegro5/allegro-5.2.x.f 5 | 6 | \ include afkit/plat/sf.f 7 | -------------------------------------------------------------------------------- /kitconfig.f: -------------------------------------------------------------------------------- 1 | \ Place this at the root of your hard drive (e.g. C:/) to configure AFKit at a global level. 2 | 3 | \ true constant HD 4 | true constant allegro-audio 5 | \ true constant allegro-debug 6 | include afkit/plat/sfwin32.f -------------------------------------------------------------------------------- /venery/README.md: -------------------------------------------------------------------------------- 1 | in-progress!!! 2 | 3 | status: 4 | 5 | essential functionality on arrays, strings, and node trees. 6 | 7 | more collection types and functions to come. 8 | 9 | docs: 10 | glossary at top of venery.f 11 | -------------------------------------------------------------------------------- /sample/platformer/break.f: -------------------------------------------------------------------------------- 1 | 2 | : break 3 | at@ nip 16 + groundy ! green 4 | at@ 16 for 16 for 5 | 2dup i j 2+ at 115 *particle 6 | -0.02 0.02 between 0 0.1 between vx 2! 0.03 ay ! \ 0.01e afade sf! 7 | loop loop 2drop ; -------------------------------------------------------------------------------- /sample/platformer/map.f: -------------------------------------------------------------------------------- 1 | ( load the map ) 2 | 3 | : reload 4 | s" level01.buf" >data tilebuf count2d @file 5 | 0 0 at s" tiles.png" >data loadtiles 6 | \ s" objects1" find-objgroup my-handlers load-objects \ load object layer 7 | ; 8 | reload 9 | -------------------------------------------------------------------------------- /sample/platformer/data/tiles.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro5_07_misc.f: -------------------------------------------------------------------------------- 1 | \ function: al_get_opengl_extension_list ( -- ALLEGRO_OGL_EXT_LIST ) 2 | 3 | [defined] linux [if] 4 | linux-library liballegro 5 | function: al_get_x_window_id ( display -- id ) 6 | function: al_x_set_initial_icon ( bitmap -- bool ) 7 | [then] -------------------------------------------------------------------------------- /ramen/lib/std/kb.f: -------------------------------------------------------------------------------- 1 | : keydown over #5 rshift #1 + #2 lshift + @ swap #31 and #1 swap lshift and 0<> ; 2 | : klast kblast keydown ; 3 | : kstate kbstate keydown ; 4 | : kdelta >r r@ kstate #1 and r> klast #1 and - ; 5 | : pressed kdelta #1 = ; 6 | : released kdelta #-1 = ; 7 | -------------------------------------------------------------------------------- /ramen/minimal.f: -------------------------------------------------------------------------------- 1 | ( Minimal library set ) 2 | 3 | depend ramen/lib/std/rangetools.f 4 | depend ramen/lib/std/v2d.f 5 | depend ramen/lib/std/kb.f 6 | depend ramen/lib/std/audio.f 7 | depend ramen/lib/utils.f 8 | 9 | cr .( Finished loading the Minimal packet. ) -------------------------------------------------------------------------------- /ex/actors-1.f: -------------------------------------------------------------------------------- 1 | include ramen/ramen.f 2 | empty 3 | depend ramen/basic.f 4 | 5 | : /bubble draw> lblue 64 globalscale / circlef ; 6 | 7 | 0 0 viewwh middle at stage *actor as 8 | /bubble 9 | 10 | \ Now make the actor do something by calling act>: 11 | 12 | : jitter act> 2 2 2rnd 1 1 2- x 2+! ; 13 | 14 | jitter 15 | -------------------------------------------------------------------------------- /loader.f: -------------------------------------------------------------------------------- 1 | true constant dev 2 | 3 | include ramen/ramen.f 4 | ide 5 | 6 | : platformer s" ld sample/platformer/platformer" evaluate ; 7 | 8 | permanent off \ "gild" system assets 9 | gild \ and gild the dictionary 10 | 11 | s" session.f" file-exists [if] 12 | include session.f 13 | [then] 14 | 15 | -------------------------------------------------------------------------------- /common-ui.f: -------------------------------------------------------------------------------- 1 | s" help" button 2 | 3 | option: mapedit s" ld dev/mapedit/mapedit" evaluate ; 4 | option: newyear s" ld sample/newyear/newyear" evaluate ; 5 | option: loz s" ld sample/zelda/main" evaluate ; 6 | option: loztests s" ld sample/zelda/tests" evaluate ; 7 | option: platformer s" ld sample/platformer/platformer" evaluate ; 8 | nr 9 | -------------------------------------------------------------------------------- /venery/venery.komodoproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1 6 | 7 | 8 | -------------------------------------------------------------------------------- /afkit/ans/depend.f: -------------------------------------------------------------------------------- 1 | [undefined] depend [if] 2 | 3 | : defined ( - c-addr 0 | xt -1 | - xt 1 ) bl word find ; 4 | : exists ( - flag ) defined 0 <> nip ; 5 | 6 | \ Conditional INCLUDE 7 | : include ( - ) 8 | >in @ >r bl parse included r> >in ! create ; 9 | : depend ( - ) 10 | >in @ exists if drop exit then >in ! 11 | include ; 12 | 13 | [then] -------------------------------------------------------------------------------- /ramen/ramen.f: -------------------------------------------------------------------------------- 1 | [undefined] [ramen] [if] 2 | include afkit/ans/version.f 3 | #2 #0 #0 [version] [ramen] 4 | 5 | cr .( Loading Ramen... ) \ " 6 | include ramen/base.f \ gilded 7 | [in-platform] sf [if] 8 | include ramen/ide/ide.f \ gilded 9 | include ramen/system.f \ gilded, extends `IDE` 10 | [then] 11 | [then] 12 | 13 | cr .( Loaded Ramen. ) \ " -------------------------------------------------------------------------------- /venery/.komodotools/sf_include_venery_f-1.ktf: -------------------------------------------------------------------------------- 1 | // komodo tool: sf include venery.f 2 | // ================================ 3 | // cwd: %p 4 | // doNotOpenOutputWindow: 1 5 | // insertOutput: 0 6 | // is_clean: true 7 | // keyboard_shortcut: F5###F4 8 | // operateOnSelection: 0 9 | // parseOutput: 0 10 | // runIn: no-console 11 | // showParsedOutputList: 0 12 | // type: command 13 | // version: 1.1.5 14 | // ================================ 15 | sf include venery.f -------------------------------------------------------------------------------- /ex/actors-2.f: -------------------------------------------------------------------------------- 1 | include ramen/ramen.f 2 | empty 3 | depend ramen/basic.f 4 | 5 | 0 0 viewwh middle at stage *actor as 6 | 7 | :now draw> red 64 circlef ; 8 | 9 | : oscillate ( n - ) 10 | perform> 11 | begin 12 | 30 for dup x +! pause loop 13 | 10 pauses 14 | negate 15 | 30 for dup x +! pause loop 16 | 10 pauses 17 | negate 18 | again 19 | ; 20 | 21 | 2 oscillate 22 | \ 4 oscillate 23 | \ 2 oscillate 24 | -------------------------------------------------------------------------------- /.komodotools/sf_include_loader_f.komodotool: -------------------------------------------------------------------------------- 1 | { 2 | "insertOutput": 0, 3 | "parseRegex": "", 4 | "doNotOpenOutputWindow": 1, 5 | "keyboard_shortcut": "F5", 6 | "name": "sf include loader.f", 7 | "operateOnSelection": 0, 8 | "value": [ 9 | "sf include loader.f" 10 | ], 11 | "parseOutput": 0, 12 | "version": "1.1.5", 13 | "env": "", 14 | "showParsedOutputList": 0, 15 | "type": "command", 16 | "cwd": "%p", 17 | "runIn": "no-console" 18 | } -------------------------------------------------------------------------------- /afkit/dep/zlib/zlib.f: -------------------------------------------------------------------------------- 1 | cd afkit/dep/zlib 2 | [defined] linux [if] 3 | library libz.so 4 | [else] 5 | library libzlib 6 | [then] 7 | cd ../../.. 8 | 9 | function: compress ( dest-adr &destlen src-adr srclen -- result ) 10 | function: uncompress ( dest-adr &destlen src-adr srclen -- result ) 11 | 12 | variable destlen 13 | : decompress ( src #len dest #len - #outputlen ) 14 | destlen ! 15 | destlen 2swap uncompress dup if h. -1 abort" Zlib error" else drop then 16 | destlen @ ; 17 | 18 | -------------------------------------------------------------------------------- /ramen/lib/std/audio.f: -------------------------------------------------------------------------------- 1 | \ Audio API 1 2 | 3 | variable sid 4 | variable strm 5 | 6 | ALLEGRO_PLAYMODE_ONCE constant once 7 | ALLEGRO_PLAYMODE_BIDIR constant bidir 8 | ALLEGRO_PLAYMODE_LOOP constant looping 9 | 10 | : play ( sample - ) 11 | dup >r >smp 1e 0e 1e 3sf r> sample.loop @ sid al_play_sample ; 12 | 13 | : stream ( adr c loopmode - ) 14 | >r 15 | zstring #3 #2048 al_load_audio_stream strm ! 16 | strm @ r> al_set_audio_stream_playmode drop 17 | strm @ mixer al_attach_audio_stream_to_mixer drop ; 18 | 19 | -------------------------------------------------------------------------------- /sample/platformer/camera.f: -------------------------------------------------------------------------------- 1 | 2 | ( camera ) 3 | : /follow 4 | act> me stage push \ keep the camera on top of everything, makes it process last 5 | physics> \ assign physics 6 | guy 's x 2@ 2pfloor viewwh 2halve 2pfloor 2- x 2! \ position relative to player so it is centered 7 | x 2@ 0 0 2max x 2! \ prevent view going out of bounds. (x/y can't be less than 0,0) 8 | x 2@ 2pfloor bg0 's scrollx 2! \ scroll the background. 9 | ; 10 | cam as /follow \ create the camera 11 | -------------------------------------------------------------------------------- /afkit/ans/param-enclosures.f: -------------------------------------------------------------------------------- 1 | \ Parameter enclosures 2 | \ a simple runtime relative stack depth checking mechanism. 3 | 4 | \ example: 5 | \ 1( 123 ) \ stack ok, nothing happens 6 | \ 1( 123 321 ) \ throws an error 7 | \ 1( ) \ throws an error 8 | 9 | 0 value (depth) 10 | : 1( ( - ) state @ if s" depth >r" evaluate else depth to (depth) then ; immediate 11 | : (stackerr) - #1 <> abort" stack check error" ; 12 | : ) ( ... - ... ) 13 | state @ if s" depth r> (stackerr) " evaluate 14 | else depth (depth) (stackerr) then ; immediate 15 | 16 | -------------------------------------------------------------------------------- /ramen/buffer.f: -------------------------------------------------------------------------------- 1 | asset: %buffer 2 | %buffer svar buffer.data 3 | %buffer svar buffer.size 4 | 5 | : recreate-buffer ( buffer - ) 6 | >r r@ buffer.size @ allocate throw r> buffer.data ! ; 7 | 8 | : unload-buffer ( buffer - ) 9 | buffer.data @ free throw ; 10 | 11 | : init-buffer ( size buffer - ) 12 | >r dup r@ buffer.size ! allocate throw r@ buffer.data ! 13 | ['] recreate-buffer ['] unload-buffer r> register ; 14 | 15 | : buffer ( size - ) 16 | %buffer *struct init-buffer ; 17 | 18 | : buffer: ( size - ) 19 | create buffer does> buffer.data @ ; -------------------------------------------------------------------------------- /venery/notes.txt: -------------------------------------------------------------------------------- 1 | generic collections 2 | 3 | array 4 | 5 | string 6 | 7 | nodetree 8 | 9 | dynamic array 10 | 11 | dynamic string 12 | 13 | map ? 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | features 22 | - same words work on different collections 23 | - optional bounds checking 24 | 25 | 26 | 27 | 28 | questions/ideas: 29 | - ENOUGH could be called DONE ... 30 | - should slice/split take destinations and what order should it be in? 31 | - mixing different 32 | - expose the struct words so it's more of a complete package ... add reflection and ability to create custom field definers 33 | -------------------------------------------------------------------------------- /afkit/plat/sflinux.f: -------------------------------------------------------------------------------- 1 | : platform s" sflinux" ; 2 | 3 | include afkit/ans/ffl/sflinux/ffl.f \ FFL: DOM; FFL loads FPMATH 4 | include afkit/dep/allegro5/allegro-5.2.x.f 5 | 6 | library libX11.so 7 | 8 | function: XOpenDisplay ( zdisplayname - display ) 9 | function: XDefaultScreen ( &display - display ) 10 | 11 | function: XSync ( display discard - ) 12 | function: XMapWindow ( display window - ) 13 | function: XRaiseWindow ( display window - ) 14 | 15 | function: XSetInputFocus ( display window revert time - ) 16 | function: XGetInputFocus ( display &window &revert - ) 17 | 18 | include afkit/plat/sf.f 19 | -------------------------------------------------------------------------------- /afkit/plat/win/clipb.f: -------------------------------------------------------------------------------- 1 | create clp 256 allot 2 | : clipb@ ( - adr c ) 3 | GetForegroundWindow OpenClipboard -exit 4 | CF_TEXT GetClipboardData ?dup -exit GlobalLock 5 | dup zcount clp place 6 | GlobalUnlock drop 7 | CloseClipboard drop 8 | clp count ; 9 | 0 value gh 0 value gm 10 | : clipb! ( adr c - ) 11 | GetForegroundWindow OpenClipboard -exit 12 | EmptyClipboard DROP 13 | GMEM_MOVEABLE over #1 + GlobalAlloc to gh 14 | gh GlobalLock to gm 15 | gm swap move 16 | CF_TEXT gh SetClipboardData DROP 17 | gh GlobalUnlock DROP 18 | CloseClipboard drop ; 19 | -------------------------------------------------------------------------------- /ramen/sample.f: -------------------------------------------------------------------------------- 1 | asset: %sample 2 | %sample svar sample.smp 3 | %sample svar sample.loop 4 | : >smp sample.smp @ ; 5 | 6 | : reload-sample ( sample - ) 7 | >r r@ srcfile count findfile zstring al_load_sample r> sample.smp ! ; 8 | 9 | : unload-sample 10 | sample.smp @ al_destroy_sample ; 11 | 12 | : init-sample ( looping adr c sample - ) 13 | >r r@ srcfile place r@ sample.loop ! ['] reload-sample ['] unload-sample r@ register 14 | r> reload-sample ; 15 | 16 | \ sample: create named sample 17 | : sample: ( path c loopmode - >name> sample ) 18 | -rot create %sample *struct init-sample ; 19 | 20 | -------------------------------------------------------------------------------- /ramen/basic.f: -------------------------------------------------------------------------------- 1 | ( Basic library set ) 2 | 3 | depend ramen/lib/std/actor.f 4 | depend ramen/lib/std/rangetools.f 5 | depend ramen/lib/std/task.f 6 | depend ramen/lib/std/v2d.f 7 | depend ramen/lib/std/kb.f 8 | depend ramen/lib/std/audio.f 9 | depend ramen/lib/std/sprites.f 10 | depend ramen/lib/std/transform.f 11 | depend ramen/lib/utils.f 12 | 13 | : show-stage ( - ) show> ramenbg mount stage draws ; 14 | show-stage 15 | 16 | : think stage acts stage multi ; 17 | : physics stage each> as vx 2@ x 2+! ; 18 | : default-step step> think physics sweep ; 19 | default-step 20 | 21 | cr .( Finished loading the Basic packet. ) -------------------------------------------------------------------------------- /venery/test.f: -------------------------------------------------------------------------------- 1 | only forth definitions 2 | 3 | \ test 4 | create s 100 *stack drop 5 | : numbers locals| c | c vacate c capacity 0 do i c push loop ; 6 | s numbers 7 | 8 | :noname %node venery:sizeof allocate throw dup /node ; is new-node 9 | :noname free throw ; is free-node 10 | 11 | new-node constant p 12 | new-node constant n1 n1 p push 13 | new-node constant n2 n2 p push 14 | new-node constant n3 n3 p push 15 | new-node constant n4 n4 p push 16 | new-node constant p2 17 | new-node constant n5 n5 p2 push 18 | new-node constant n6 n6 p2 push 19 | new-node constant n7 n7 p2 push 20 | new-node constant n8 n8 p2 push 21 | 22 | only forth definitions 23 | -------------------------------------------------------------------------------- /ramen/system.f: -------------------------------------------------------------------------------- 1 | \ system events extension stub 2 | 3 | : ext-mouse 4 | etype ALLEGRO_EVENT_MOUSE_AXES = if 5 | evt ALLEGRO_MOUSE_EVENT.x 2@ 2p mouse 2! 6 | repl? if 7 | evt ALLEGRO_MOUSE_EVENT.dz @ 0 > if ide:pageup ;then 8 | evt ALLEGRO_MOUSE_EVENT.dz @ 0 < if ide:pagedown ;then 9 | ;then 10 | ;then 11 | ; 12 | 13 | 14 | : ext-kb 15 | etype ALLEGRO_EVENT_KEY_DOWN = keycode = and if 16 | page 17 | repl? if repl off else repl on then 18 | ;then 19 | ; 20 | : (system) ext-kb ext-mouse ide-system ; 21 | 22 | also ideing 23 | : ide rasa /repl ['] (system) is ?system ['] ?rest catch ?.catch go -ide ; 24 | previous 25 | 26 | marker (empty) 27 | -------------------------------------------------------------------------------- /sample/platformer/helpers.f: -------------------------------------------------------------------------------- 1 | ( some helpers ) 2 | 3 | _actor fields: \ add some variables to the _ACTOR class 4 | var onground gravity onground off hitceiling off tilebuf collide-tilemap ; \ we do tilemap collision here 14 | 15 | : tile@ ( x y - n ) 16 16 2/ tilebuf loc @ ; 16 | : tile! ( n x y - ) 16 16 2/ tilebuf loc ! ; -------------------------------------------------------------------------------- /RamenEngine.komodoproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | *.*~;*.bak;*.tmp;CVS;.#*;*.pyo;*.pyc;.svn;_svn;.git;.hg;.bzr;*%25*;tmp*.html;.DS_Store;*.swp;*.kpf;*.komodoproject;.komodotools;__pycache__;*.fs;*.api;bin 7 | None 8 | None 9 | 1 10 | 11 | 12 | -------------------------------------------------------------------------------- /ramen/res.f: -------------------------------------------------------------------------------- 1 | : destxy penx 2@ [undefined] HD [if] 2pfloor [then] ; 2 | 3 | : bmpw dup -exit al_get_bitmap_width 1p ; 4 | : bmph dup -exit al_get_bitmap_height 1p ; 5 | : bmpwh dup bmpw swap bmph ; 6 | 7 | : resolution ( w h - ) 2i 2dup res 2@ d= not if resolution else 2drop then ; 8 | 9 | : displayw display al_get_display_width 1p ; 10 | : displayh display al_get_display_height 1p ; 11 | : displaywh displayw displayh ; 12 | 13 | : globalscale #globalscale 1p ; 14 | : viewwh res xy@ 2p ; 15 | : vieww viewwh drop ; 16 | : viewh viewwh nip ; 17 | 18 | : fps fps 1p ; 19 | 20 | : gscale globalscale dup 2* ; 21 | 22 | : mountx mountx 1p ; 23 | : mounty mounty 1p ; 24 | : mountxy mountxy 2p ; 25 | : mountw mountw 1p ; 26 | : mounth mounth 1p ; 27 | : mountwh mountwh 2p ; -------------------------------------------------------------------------------- /sample/platformer/lib/buffer2d.f: -------------------------------------------------------------------------------- 1 | depend sample/platformer/lib/array2d.f 2 | 3 | decimal \ necessary because tilemaps can be quite large 4 | : init-buffer2d ( array2d - ) 5 | >r r@ array2d.cols 2@ 2i i* cells allocate throw r> array2d.data ! ; 6 | fixed 7 | 8 | : recreate-buffer2d ( asset - ) 9 | /assetheader + init-buffer2d ; 10 | 11 | : unload-buffer2d 12 | /assetheader + array2d.data @ free throw ; 13 | 14 | : init-buffer2d ( cols rows buffer2d - ) 15 | >r udup r@ array2d.cols 2! 16 | cells r@ array2d.pitch ! 17 | ['] recreate-buffer2d ['] unload-buffer2d r@ /assetheader - register 18 | r> init-buffer2d ; 19 | 20 | : buffer2d: ( cols rows - ) ( - array2d ) 21 | create /assetheader /allot %array2d *struct init-buffer2d 22 | does> /assetheader + ; -------------------------------------------------------------------------------- /afkit/platforms.f: -------------------------------------------------------------------------------- 1 | : PARSE-WORD ( "name" - c-addr u ) /SOURCE OVER >R BL SKIP DROP R> - >IN +! BL PARSE ; 2 | : [platform] platform parse-word compare 0= ; immediate 3 | : [in-platform] platform parse-word search nip nip ; immediate 4 | 5 | [in-platform] win32 [if] 6 | #2 attribute cr .( ====== Windows note ====== ) #0 attribute 7 | cr .( The audio codec and other addons will not work on Windows unless ) 8 | cr .( you copy all of the Allegro DLL's to your host Forth's bin folder. ) 9 | cr .( You can still load the Allegro DLL without doing this; you just won't ) 10 | cr .( be able to play anything but WAV files or call certain other functions.) 11 | cr 12 | [then] 13 | 14 | [in-platform] win32 [if] true constant win32 [then] 15 | [in-platform] linux [if] true constant linux [then] 16 | -------------------------------------------------------------------------------- /ramen/font.f: -------------------------------------------------------------------------------- 1 | asset: %font 2 | %font svar font.fnt 3 | %font svar font.size 4 | %font svar font.flags 5 | : >fnt ( font - ALLEGRO_FONT ) font.fnt @ ; 6 | 7 | : reload-font ( font - ) 8 | >r r@ srcfile count findfile zstring r@ font.size @ 1i r@ font.flags @ al_load_font r> font.fnt ! ; 9 | 10 | : unload-font ( font - ) 11 | font.fnt @ al_destroy_font ; 12 | 13 | : init-font ( path c size flags font - ) 14 | >r r@ font.flags ! r@ font.size ! 15 | r@ srcfile place ['] reload-font ['] unload-font r@ register 16 | r> reload-font ; 17 | 18 | : font: ( path c size flags - ) 19 | create %font *struct init-font ; 20 | 21 | create (chr) 0 c, 0 c, 22 | : chrw ( font chr - n ) (chr) c! >fnt (chr) al_get_text_width 1p ; 23 | : chrh ( font - n ) >fnt al_get_font_line_height 1p ; 24 | -------------------------------------------------------------------------------- /ramen/lib/std/zsort.f: -------------------------------------------------------------------------------- 1 | ( Z-sorting extension ) 2 | 3 | depend ramen/lib/rsort.f 4 | 5 | extend: _actor 6 | var zorder \ defines z order. lower = more behind, higher = more in front 7 | ;class 8 | 9 | extend: _objlist 10 | var zsort \ enables zsort on object lists 11 | ;class 12 | 13 | define internal 14 | : drawem ( adr cells - ) cells bounds do i @ as draw cell +loop ; 15 | : #queued ( adr - #cells ) here swap - cell/ ; 16 | : (enqueue) ( objlist - ) each> as hidden @ ?exit me , ; 17 | : enqueue ( objlist - adr #cells ) here swap (enqueue) dup #queued ; 18 | 19 | using internal 20 | : zorder@ 's zorder @ ; 21 | : zdraws ( objlist - ) 22 | here >r 23 | ( objlist ) enqueue 24 | 2dup ['] zorder@ rsort 25 | drawem 26 | r> reclaim ; 27 | : draws ( objlist - ) 28 | dup 's zsort @ if zdraws ;then 29 | draws ; 30 | 31 | previous 32 | stage 's zsort on 33 | -------------------------------------------------------------------------------- /ramen/types.f: -------------------------------------------------------------------------------- 1 | \ essential "types" 2 | 3 | struct: %color 4 | %color svar color.r 5 | %color svar color.g 6 | %color svar color.b 7 | %color svar color.a 8 | 9 | struct: %rect 10 | %rect svar rect.x 11 | %rect svar rect.y 12 | %rect svar rect.w 13 | %rect svar rect.h 14 | 15 | : x@ @ ; : x! ! ; 16 | : y@ cell+ @ ; : y! cell+ ! ; 17 | : w@ rect.w @ ; : w! rect.w ! ; 18 | : h@ rect.h @ ; : h! rect.h ! ; 19 | : xy@ 2@ ; : xy! 2! ; 20 | : wh@ rect.w 2@ ; : wh! rect.w 2! ; 21 | : xywh@ 4@ ; : xywh! 4! ; 22 | : x2@ dup x@ swap w@ + ; : x2! >r r@ x@ - r> w! ; 23 | : y2@ dup y@ swap h@ + ; : y2! >r r@ y@ - r> h! ; 24 | : xy2@ dup 2@ rot wh@ 2+ ; : xy2! >r r@ xy@ 2- r> wh! ; 25 | 26 | : aabb@ xywh@ 2over 2+ ; 27 | 28 | create srcrect 0 , 0 , 0 , 0 , 29 | -------------------------------------------------------------------------------- /ramen/make_sfwin.bat: -------------------------------------------------------------------------------- 1 | REM params: 2 | SETLOCAL 3 | 4 | if %1=="" ( 5 | SET buildname=build 6 | ) else ( 7 | SET buildname=%1 8 | ) 9 | 10 | @REM Create fresh directory 11 | md bin\%buildname%\data 12 | del /s /q bin\%buildname% 13 | 14 | @REM Copy essential Ramen assets 15 | copy /y ramen\ide\data\*.* bin\%buildname%\data 16 | 17 | @REM Copy data and dynamic libraries 18 | if %3=="" ( 19 | copy /y data\*.* bin\%buildname%\data 20 | ) else ( 21 | copy /y %3\data\*.* bin\%buildname%\data 22 | ) 23 | 24 | @REM copy afkit\dep\allegro5\5.2.3\*.dll bin\%buildname% 25 | 26 | FOR /R afkit/dep %%x IN (*.dll) DO copy "%%x" bin\%buildname% /Y 27 | FOR /R prg %%x IN (*.dll) DO copy "%%x" bin\%buildname% /Y 28 | 29 | @REM Run SwiftForth to compile and export 30 | if %2=="" ( 31 | sf include main.f publish bin\%buildname%\%buildname% 32 | ) else ( 33 | sf include %2 publish bin\%buildname%\%buildname% 34 | ) 35 | 36 | 37 | -------------------------------------------------------------------------------- /ramen/ide/v2d.f: -------------------------------------------------------------------------------- 1 | : vector: ( x y - ) create swap , , ; 2 | 2 cells constant /vector 3 | : 2. swap . . ; 4 | : 2? swap ? ? ; 5 | : x@ @ ; 6 | : y@ cell+ @ ; 7 | : x! ! ; 8 | : y! cell+ ! ; 9 | : x+! +! ; 10 | : y+! cell+ +! ; 11 | : vclamp ( lowx lowy highx highy vec - ) >r 2@ 2min 2max r> 2! ; 12 | : 0v 0 0 rot 2! ; 13 | : 1v 1 1 rot 2! ; 14 | : 2rnd ( x y - x y ) rnd swap rnd swap ; 15 | : uvec ( deg - x y ) >r r@ cos r> sin ; \ get unit vector from angle 16 | : vec ( deg len - x y ) >r uvec r> dup 2* ; 17 | : angle ( x y - deg ) 1pf 1pf fatan2 r>d f>p 360 + 360 mod ; 18 | : hypot ( x y - n ) 2pf fdup f* fswap fdup f* f+ fsqrt f>p ; 19 | : 2rotate ( x y deg - x y ) 20 | swap >rad dup cos swap sin locals| sin(ang) cos(ang) y x | 21 | x cos(ang) * y sin(ang) * - 22 | x sin(ang) * y cos(ang) * + ; 23 | : vscale ( x y vec - ) 24 | >r 2@ 2* r> 2! ; 25 | : vlerp ( vec1 vec2 n - x y ) 26 | locals| n v2 v1 | 27 | v1 x@ v2 x@ n lerp v1 y@ v2 y@ n lerp ; 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 6 | -------------------------------------------------------------------------------- /afkit/LICENSE.md: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 6 | -------------------------------------------------------------------------------- /ramen/LICENSE.md: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 6 | -------------------------------------------------------------------------------- /afkit/audio-allegro.f: -------------------------------------------------------------------------------- 1 | \ Allegro's audio API has been loaded already, so we don't load it here. 2 | 3 | 0 value mixer 4 | 0 value voice 5 | 6 | : -audio 7 | mixer -exit 8 | mixer 0 al_set_mixer_playing drop 9 | ; 10 | 11 | : +audio 12 | mixer if mixer #1 al_set_mixer_playing drop exit then 13 | #44100 ALLEGRO_AUDIO_DEPTH_INT16 ALLEGRO_CHANNEL_CONF_2 al_create_voice to voice 14 | #44100 ALLEGRO_AUDIO_DEPTH_FLOAT32 ALLEGRO_CHANNEL_CONF_2 al_create_mixer to mixer 15 | mixer voice al_attach_mixer_to_voice 0= abort" Couldn't initialize audio" 16 | mixer al_set_default_mixer drop 17 | mixer #1 al_set_mixer_playing drop 18 | ; 19 | 20 | : initaudio 21 | 0 to mixer 0 to voice 22 | al_init_acodec_addon not if s" Allegro: Couldn't initialize audio codec addon." alert -1 abort then 23 | al_install_audio not if s" Allegro: Couldn't initialize audio." alert -1 abort then 24 | #32 al_reserve_samples not if s" Allegro: Error reserving samples." alert -1 abort then 25 | +audio 26 | ; 27 | 28 | : updateaudio 29 | ; 30 | -------------------------------------------------------------------------------- /ramen/lib/std/rangetools.f: -------------------------------------------------------------------------------- 1 | : aabb ( x y w h - x1 y1 x2 y2 ) 2over 2+ ; 2 | : lowerupper ( n n - lower higher ) 2dup > if swap then ; 3 | : between ( n n - n ) lowerupper over - #1 + rnd + ; 4 | : vary ( n rnd - n ) dup 0.5 * -rot rnd + swap - ; 5 | : 2vary ( n n rnd rnd - n n ) rot swap vary >r vary r> ; 6 | : either ( a b - a | b ) 2 rnd if drop else nip then ; 7 | : 2ratio ( x y w h xfactor. yfactor. - x y ) 2* 2+ ; 8 | : middle ( x y w h - x y ) 0.5 0.5 2ratio ; 9 | : 2halve 0.5 0.5 2* ; 10 | 11 | \ center a rectangle (1) in the middle of another one (2). returns x/y of top-left corner. 12 | : center ( w1 h1 x y w2 h2 - x y ) 2halve 2rot 2halve 2- 2+ ; 13 | 14 | \ find a random position in the rectangle (x,y,x+w,y+h) 15 | : 2rnd ( x y - x y ) rnd swap rnd swap ; 16 | : somewhere ( x y w h - x y ) 2rnd 2+ ; 17 | 18 | \ find if 2 rectangles (x1,y1,x2,y2) and (x3,y3,x4,y4) overlap. 19 | : overlap? ( xyxy xyxy - flag ) 20 | 2swap 2rot rot >= -rot <= and >r rot >= -rot <= and r> and ; 21 | 22 | : within? ( xy xyxy - flag ) 2>r 2>r 2dup 2r> 2r> overlap? ; 23 | 24 | -------------------------------------------------------------------------------- /sample/platformer/platformer.f: -------------------------------------------------------------------------------- 1 | include ramen/ramen.f \ goes first 2 | empty \ closes and frees any previous project 3 | project: sample/platformer \ sets the project's root folder so that LD knows where to look 4 | depend ramen/basic.f 5 | ld lib/tilemap2 6 | depend afkit/ans/param-enclosures.f 7 | ld tools 8 | 320 240 resolution 9 | 10 | create startxy 0 , 0 , 11 | stage actor: cam 12 | 13 | ld map \ loads the map data 14 | ld helpers \ physics and tile stuff 15 | ld particles \ simple particle system 16 | ld break \ effect to turn tiles into particles 17 | 18 | ( ---=== set up playfield ===--- ) 19 | stage actor: blackness ld blackness 20 | stage actor: bg0 ld bg 21 | particles stage push 22 | stage actor: guy ld player 23 | ld camera 24 | 25 | ( define initialization code for exported game ) 26 | :make cold 27 | reload \ reload the tilemap data 28 | ; 29 | 30 | ( test stuff ) 31 | : test guy 0 0 from stage *actor as blue /b6ox ; 32 | :now stage *actor as act> pressed if test then ; 33 | -------------------------------------------------------------------------------- /ramen/lib/upscale.f: -------------------------------------------------------------------------------- 1 | \ fat pixels and subscreens 2 | 3 | depend ramen/draw.f 4 | 2048 2048 canvas: canv 5 | create tempres 0 , 0 , 6 | variable upscaling 7 | 8 | 9 | transform: p 10 | : 2d 11 | p al_identity_transform 12 | p 0 0 -16384 3af upscaling @ if viewwh globalscale dup 2* else displaywh then 16384 3af 13 | al_orthographic_transform 14 | p al_use_projection_transform 15 | ALLEGRO_DEPTH_TEST #0 al_set_render_state 16 | ; 17 | 18 | 19 | : (size) viewwh canv resize-canvas ; 20 | : (upscale) ( code - ) 21 | canv >bmp onto> 22 | black 0 alpha backdrop unmount 23 | upscaling on call upscaling off ; 24 | : upscaled ( draw-xt - ) >code (size) (upscale) ; 25 | 26 | : ?blitthen> ( draw-xt upscale-xt - ) 27 | catch dup if display onto 2d 0 0 at upscaling off then 28 | r> call mount canv >bmp blit throw ; 29 | 30 | : upscale> ( - ) 31 | r> code> ['] upscaled ?blitthen> noop ; 32 | 33 | : subscreen> ( w h - ) 34 | res 2@ tempres 2! 35 | ( w h ) 2i res 2! 36 | r> code> ['] upscaled ?blitthen> 37 | tempres 2@ res 2! ; 38 | -------------------------------------------------------------------------------- /afkit/ans/version.f: -------------------------------------------------------------------------------- 1 | [undefined] [version] [if] 2 | : packver swap 8 lshift or swap 24 lshift or ; 3 | : (checkver) ( ver ver - ) 4 | over 0 = if 2drop exit then 5 | 2dup 6 | swap $ff000000 and swap $ff000000 and <> abort" Incompatible major version!" 7 | 2dup 8 | swap $00ffffff and swap $00ffffff and > abort" Incompatible minor version and/or revision!" 9 | swap $00ffff00 and swap $00ffff00 and < if 10 | cr #2 attribute ." Version mismatch warning: " 11 | #3 attribute 12 | space including -path type ." : " 13 | space tib #tib @ type 14 | #0 attribute 15 | then 16 | ; 17 | : .line cr tib #tib @ type ; 18 | : [version] ( M m R - ) .line packver constant ; 19 | : [checkver] ( M m R packver - ) 20 | depth 4 < abort" Missing version spec!" 21 | >r packver r> (checkver) ; 22 | 23 | [then] 24 | 25 | \ versions are expressed as three values M = major, m = minor, R = revision 26 | \ in documentation, they're expressed as M.m.r 27 | \ Major versions are always source breaking 28 | \ Minor versions are generally additions, but also sometimes deletions, renames, and semantic changes 29 | \ Revisions are bugfixes, and benign tweaks such as dox and housekeeping 30 | 31 | 32 | -------------------------------------------------------------------------------- /afkit/ans/strops.f: -------------------------------------------------------------------------------- 1 | : zcount ( zaddr - addr n ) dup dup if 65535 0 scan drop over - then ; 2 | : zlength ( zaddr - n ) zcount nip ; 3 | : zplace ( from n to - ) tuck over + >r cmove 0 r> c! ; 4 | : zappend ( from n to - ) zcount + zplace ; 5 | create $buffers 16384 allot \ string concatenation buffer stack (circular) 6 | variable >s \ pointer into $buffers 7 | : s[ ( adr c - ) >s @ 256 + 16383 and >s ! >s @ $buffers + place ; 8 | : +s ( adr c - ) >s @ $buffers + append ; 9 | : +c ( c - ) >s @ $buffers + count + c! 1 >s @ $buffers + +! ; 10 | create $outbufs 16384 allot \ output buffers; circular stack of buffers 11 | variable >out 12 | : ]s ( - adr c ) \ fetch finished string 13 | >s @ $buffers + count >out @ $outbufs + place 14 | >out @ $outbufs + count 15 | >out @ 256 + 16383 and >out ! 16 | >s @ 256 - 16383 and >s ! ; 17 | : zstring ( addr c - zaddr ) s[ ]s over + 0 swap c! ; 18 | : addchar ( c adr - ) dup >r count + c! 1 r> c+! ; 19 | : uncount ( adr c - adr-1 ) drop 1 - ; 20 | : strjoin ( first c second c - first+second c ) 2swap s[ +s ]s ; 21 | \ : input ( adr c - ) over 1 + swap accept swap c! ; 22 | : ( - addr c ) 0 parse -trailing bl skip ; \ rol=remainder of line 23 | -------------------------------------------------------------------------------- /sample/platformer/player.f: -------------------------------------------------------------------------------- 1 | ( player ) 2 | : aligned at@ 2dup 16 16 2mod 2- at ; 3 | : ?dig 4 | dir @ 0 = if x 2@ 22 u+ tile@ 1 = if me 22 0 from aligned 0 at@ tile! me { break } then then 5 | dir @ 180 = if x 2@ -8 u+ tile@ 1 = if me -8 0 from aligned 0 at@ tile! me { break } then then 6 | ; 7 | : ?jump 8 | onground @ -exit 9 | pressed -exit \ if on the ground, then check if player jumps 10 | -2 vy ! \ initial y velocity 11 | \ allow player to propel upward for up to 23 frames: 12 | 23 for kstate if -0.17 vy +! else unloop ;then pause loop 13 | ; 14 | : /jumping 0 perform> begin ?jump pause again ; 15 | : /controls 16 | /jumping 17 | act> 18 | 0 19 | kstate if drop 180 dir ! -1.25 then 20 | kstate if drop 0 dir ! 1.25 then 21 | vx ! 22 | pressed if ?dig then 23 | hitceiling @ if /jumping then \ reset the jumping task if we hit the ceiling 24 | ; 25 | \ draw a box, offset by the background's scroll coords. TINTED sets TINT according to FORE (set by RED) 26 | : /box tinted draw> cam 's x 2@ 2pfloor 2negate +at tint 4@ rgba 14 14 rectf ; 27 | 28 | guy as 29 | red /box /solid \ /SOLID enables tilemap collision 30 | /controls \ and enable the controls 31 | startxy 2@ x 2! \ and put him at the starting position 32 | -------------------------------------------------------------------------------- /ramen/publish.f: -------------------------------------------------------------------------------- 1 | ( ---=== Publish: SwiftForth ===--- ) 2 | 3 | create default-font \ note not a registered asset 4 | /assetheader /allot al-default-font , 8 , 0 , 5 | 6 | defer cold :make cold ; \ cold boot: executed once at runtime 7 | defer warm :make warm ; \ warm boot: executed potentially multiple times 8 | 9 | : boot 10 | false to allegro? 11 | fullscreen 12 | al-default-font default-font font.fnt ! 13 | project off 14 | oscursor off 15 | fixed 16 | ['] initdata catch abort" An asset failed to load." 17 | ; 18 | 19 | : kickoff 20 | boot cold warm go ; 21 | 22 | : error ( message count - ) 23 | zstring >r display z" Bad trouble" z" " r> z" Shoot" ALLEGRO_MESSAGEBOX_ERROR 24 | al_show_native_message_box drop ; 25 | 26 | : runtime 27 | [in-platform] sf [if] 28 | ['] kickoff catch ?dup if 29 | (THROW) error 30 | then 31 | [else] 32 | kickoff 33 | [then] 34 | bye ; 35 | 36 | : relify 37 | dup asset? if srcfile dup count s" data/" search if rot place else 3drop then 38 | else drop then ; 39 | 40 | [in-platform] sf [if] 41 | [defined] program [if] 42 | 43 | : publish ( - ) 44 | cr ." Publishing to " >in @ bl parse type >in ! ." .exe ... " 45 | ['] relify assets each 46 | ['] runtime 'main ! 47 | program 48 | >host ; 49 | 50 | [else] 51 | cr .( PROGRAM not defined; PUBLISH disabled ) 52 | [then] 53 | [then] -------------------------------------------------------------------------------- /sample/platformer/particles.f: -------------------------------------------------------------------------------- 1 | \ the bottleneck is probably rendering. could be sped up by drawing a vertex list. 2 | 3 | _node sizeof 32 cells class: _particle 4 | var x var y var vx var vy 5 | var fric var lifetime var lifespan var gnd 6 | var fr = ; 24 | _particle :- stopped lifetime @ 10 >= y @ pfloor gnd @ 1 - >= and vy @ abs 0.2 < and ; 25 | _particle :- ?die lifetime ++ expired stopped or if r> drop die then ; 26 | _particle :- fade fa sf@ afade sf@ f- fa sf! ; 27 | _particle :- friction vx 2@ fric @ dup 2* vx 2! ; 28 | _particle :- accel ax 2@ vx 2+! ; 29 | _particle :- bounce y @ gnd @ min y ! vy @ -0.8 -0.33 between * vy ! vy @ abs 0.5 < ?exit 30 | vx @ -0.25 0.25 between + vx ! ; 31 | _particle :- ?bounce gnd @ -exit y @ vy @ + gnd @ >= -exit bounce r> drop ; 32 | _particle :- step ?die ?bounce accel friction vx 2@ x 2+! ; 33 | _particle :+ +particles particles each> as step fade ; 34 | _particle :- draw fr 4@ fore 4! x 2@ at pixel ; 35 | _particle :+ draw-particles cam view> particles each> as draw ; 36 | 37 | particles as :now draw> me { draw-particles } act> +particles ; -------------------------------------------------------------------------------- /ramen/lib/std/transform.f: -------------------------------------------------------------------------------- 1 | ( transformation stack ) 2 | create mstack 16 cells 32 * /allot 3 | transform: t:m 4 | variable (m) 5 | 6 | : mactive ( - adr ) (m) @ 16 cells - [ 16 cells 32 * #1 - ]# and mstack + ; 7 | : mtop ( - adr ) (m) @ [ 16 cells 32 * #1 - ]# and mstack + ; 8 | : mget ( - ) al_get_current_transform mtop 16 cells move ; 9 | : tpush ( - ) 16 cells (m) +! mactive al_use_transform mactive mtop 16 cells move ; 10 | : tpop ( - ) -16 cells (m) +! mactive al_use_transform mactive mtop 16 cells move ; 11 | 12 | ( transformation ops ) 13 | : translate ( x y - ) 2af mtop -rot al_translate_transform ; 14 | : scale ( sx sy - ) 2af mtop -rot al_scale_transform ; 15 | : rotate ( angle - ) >rad 1af mtop swap al_rotate_transform ; 16 | : hshear ( n - ) 1af mtop swap al_horizontal_shear_transform ; 17 | : vshear ( n - ) 1af mtop swap al_vertical_shear_transform ; 18 | : identity ( - ) mtop al_identity_transform ; 19 | : compose ( - ) mtop mactive al_compose_transform ; 20 | : mount ( - ) tpop mount mget tpush ; 21 | : unmount ( - ) tpop unmount mget tpush ; 22 | 23 | identity tpush 24 | 25 | : transform ( - ) 26 | identity 27 | sx 2@ scale 28 | ang @ rotate 29 | x 2@ [undefined] HD [if] 2pfloor [then] translate 30 | compose 31 | 0 0 at 32 | ; 33 | 34 | : view ( - ) 35 | x 2@ [undefined] HD [if] 2pfloor [then] 2negate translate 36 | ang @ negate rotate 37 | 1 1 sx 2@ 2/ scale 38 | ; 39 | 40 | : view> ( - ) 41 | view tpush r> call tpop ; 42 | 43 | : transform> ( - ) 44 | r> at@ 2>r transform tpush call tpop 2r> at ; 45 | -------------------------------------------------------------------------------- /ex/bubbles.f: -------------------------------------------------------------------------------- 1 | include ramen/ramen.f 2 | empty 3 | depend ramen/basic.f 4 | 5 | _actor fields: var radius 6 | _actor >prototype { 16 radius ! } 7 | 8 | : sf@+ dup sf@ cell+ ; 9 | : tinted fore sf@+ f>p swap sf@+ f>p swap sf@+ f>p swap sf@+ f>p nip tint 4! ; 10 | : view/ globalscale dup 2/ ; 11 | : mousexy mouse 2@ view/ ; 12 | : mdelta mouse 2@ mickey 2@ 2- view/ ; 13 | 14 | ( beat counter ) 15 | 0 value beat 16 | stage *actor as 17 | :now act> beat 1 + 24 mod to beat ; 18 | 19 | ( draw bubble and line connecting to previous ) 20 | role: [bubble] 21 | : prev me node.previous ; 22 | : rope prev @ @ -exit prev @ { role @ [bubble] = if x 2@ line then } ; 23 | 24 | ( wiggling and rising motion ) 25 | : /rise 26 | act> 27 | y @ -1000 < if me dismiss ;then 28 | radius @ 0.5 - 3 max radius ! 29 | beat 0= 4 rnd 1 < and if radius @ 10 max radius ! then 30 | vx @ 0 > if -1 vx +! then 31 | vx @ 0 < if 1 vx +! then 32 | vy @ -2 > if -2 vy +! then 33 | ; 34 | 35 | : /bubble /rise tinted [bubble] role ! 36 | draw> tint 4@ rgba rope radius @ circlef ; 37 | 38 | : *bubble ( -- actor ) 39 | stage *actor { 40 | /bubble 41 | me } 42 | ; 43 | 44 | ( bubble generator - controlled with mouse ) 45 | stage *actor as 46 | : 2abs abs swap abs swap ; 47 | : propel ( vx vy ) 2 2 2/ vx 2! ; 48 | : inflate ( vx vy ) 2abs + 2 / 3 + radius ! ; 49 | : spurt me 0 0 from vx 2@ 1 rnd 1 rnd 1 rnd rgb *bubble { 2dup propel inflate } ; 50 | : control mousexy x 2@ 2- vx 2! ; 51 | : /spurt act> control spurt ; 52 | : /gen /spurt draw> 5 ang +! transform> -5 -5 +at white 10 10 rect ; 53 | 54 | create gen stage actor, /gen 55 | -------------------------------------------------------------------------------- /ramen/lib/std/v2d.f: -------------------------------------------------------------------------------- 1 | 2 | \ 2D vectors! fixed point or integer either works 3 | \ in experimental stage 4 | \ future ideas: 5 | \ - "V" registers with push and pop words. all "vector" params implicit? 6 | 7 | : vector: ( x y - ) create swap , , ; 8 | 2 cells constant /vector 9 | : 2. swap . . ; 10 | : 3. rot . 2. ; 11 | : 2? swap ? ? ; 12 | : vadd swap 2@ rot 2+! ; 13 | : x@ @ ; 14 | : y@ cell+ @ ; 15 | : x! ! ; 16 | : y! cell+ ! ; 17 | : x+! +! ; 18 | : y+! cell+ +! ; 19 | : vcopy swap 2@ rot 2! ; 20 | : vclamp ( lowx lowy highx highy vec - ) >r 2@ 2min 2max r> 2! ; 21 | : 2rnd ( x y - x y ) rnd swap rnd swap ; 22 | : vrnd >r 2rnd r> 2! ; 23 | : uvec ( deg - x y ) >r r@ cos r> sin ; \ get unit vector from angle 24 | : vec ( deg len - x y ) >r uvec r> dup 2* ; 25 | : angle ( x y - deg ) 1pf 1pf fatan2 r>d f>p 360 + 360 mod ; 26 | : magnitude ( x y - n ) 2pf fdup f* fswap fdup f* f+ fsqrt f>p ; 27 | : normalize ( vec - ) dup 2@ 2dup 0 0 d= ?exit 2dup magnitude dup 2/ ( 1 1 2+ ) rot 2! ; 28 | : vdif ( vec1 vec2 - x y ) 2@ rot 2@ 2- ; 29 | : proximity ( vec1 vec2 - n ) vdif magnitude ; \ distance between two vectors 30 | : hypot ( vec - n ) 2@ 1pf fdup f* 1pf fdup f* f+ fsqrt f>p ; 31 | : dotp ( vec1 vec2 - n ) swap 2@ rot 2@ -rot ( b.x a.y ) * >r ( a.x b.y ) * r> - ; 32 | : rotate ( deg vec - ) 33 | swap dup cos swap sin locals| sin(ang) cos(ang) v | 34 | v x@ cos(ang) * v y@ sin(ang) * - 35 | v x@ sin(ang) * v y@ cos(ang) * + v 2! ; 36 | : scale ( x y vec - ) 37 | >r 2@ 2* r> 2! ; 38 | : vlerp ( vec1 vec2 n - ) 39 | locals| n v2 v1 | 40 | v1 x@ v2 x@ n lerp v1 y@ v2 y@ n lerp v2 2! ; 41 | -------------------------------------------------------------------------------- /ramen/assets.f: -------------------------------------------------------------------------------- 1 | ( ---=== Asset framework ===--- ) 2 | 3 | cell #256 + cell+ constant /assetheader 4 | defer initdata ( - ) 5 | 6 | create assets 1000 *stack drop 7 | variable permanent permanent on 8 | variable #permanents 9 | 10 | \ "permanent" or "system" assets; not needed by games so reloader is a no-op 11 | : ?permanent permanent @ -exit nip ['] drop swap 1 #permanents +! ; 12 | 13 | : register ( reloader-xt unloader-xt asset - ) 14 | cr ." [Asset] " #tib 2@ swap type 15 | ?permanent dup assets push 2! ; 16 | 17 | 18 | \ structure: reloader , unloader , filepath ... 19 | : reload ( asset - ) ( asset - ) dup @ execute ; 20 | : unload ( asset - ) ( asset - ) dup cell+ @ execute ; 21 | : srcfile ( asset - adr ) cell+ cell+ ; 22 | 23 | 24 | : -assets ( - ) ['] unload assets each #permanents @ assets truncate ; 25 | 26 | 27 | \ Note: Don't worry that the paths during development are absolute; 28 | \ in publish.f, all asset paths are "normalized". 29 | : findfile ( path c - path c ) 30 | locals| c fn | 31 | fn c 2dup file-exists ?exit 32 | including -name #1 + 2swap strjoin 2dup file-exists ?exit 33 | true abort" File not found" ; 34 | 35 | : asset: ( - ) struct: /assetheader lastbody struct.size ! ; 36 | : .asset ( asset - ) srcfile count dup if type else 2drop then ; 37 | : .assets ( - ) assets each> cr .asset ; 38 | : asset? srcfile count nip 0<> ; 39 | 40 | ( Loadtrigs ) 41 | 3 cells constant loadtrig-size 42 | 43 | : +loadtrig ( xt - ) 44 | cr ." [Loadtrig] " #tib 2@ swap type 45 | here assets push , ['] drop , 0 , ; 46 | 47 | ( Standard synchronous loader ) 48 | :make initdata assets each> reload ; 49 | -------------------------------------------------------------------------------- /ramen/default.f: -------------------------------------------------------------------------------- 1 | \ -------------------------------------------------------------------------------------------------- 2 | \ some graphics tools for the default engine state 3 | 4 | \ draw a rectangular vertical gradient 5 | define internal 6 | create gv 4 /ALLEGRO_VERTEX * /allot 7 | create gi 0 , #1 , #2 , #3 , 8 | using internal 9 | : v! ( x y a n - ) /ALLEGRO_VERTEX * + >r 2af r> 2! ; 10 | : color! ( color a n - ) /ALLEGRO_VERTEX * + >r 4@ 4af r> ALLEGRO_VERTEX.r 4! ; 11 | : vgradient ( color1 color2 w h - ) 12 | at@ 2+ at@ locals| y x y2 x2 c2 c1 | 13 | x y gv 0 v! x2 y gv 1 v! x2 y2 gv 2 v! x y2 gv 3 v! 14 | c1 gv 2dup 0 color! 1 color! c2 gv 2dup 2 color! 3 color! 15 | gv 0 0 gi #4 ALLEGRO_PRIM_TRIANGLE_FAN al_draw_indexed_prim ; 16 | previous 17 | 18 | \ convert lch, hsl, hsv to rgb 19 | \ hue is in degrees 20 | create (fc) 3 cells allot 21 | : !color ( adr - ) >r (fc) color.r sf@ f>p (fc) color.g sf@ f>p (fc) color.b sf@ f>p r> 3! ; 22 | : lch! ( l c h color - ) >r >rad 3af (fc) dup cell+ dup cell+ al_color_lch_to_rgb r> !color ; 23 | : hsl! ( h s l color - ) >r 3af (fc) dup cell+ dup cell+ al_color_hsl_to_rgb r> !color ; 24 | : hsv! ( h s v color - ) >r 3af (fc) dup cell+ dup cell+ al_color_hsv_to_rgb r> !color ; 25 | \ -------------------------------------------------------------------------------------------------- 26 | 27 | \ default engine state; chill vibes 28 | create c1 0 , 0 , 0 , 1 , 29 | create c2 0 , 0 , 0 , 1 , 30 | : colorcycle 31 | 0.4 0.4 now 1p -20 / 75 + c1 lch! 32 | 0.4 0.4 now 1p -20 / c2 lch! 33 | c1 c2 34 | ; 35 | : ramenbg ( - ) 0 0 at unmount colorcycle displaywh vgradient ; 36 | -------------------------------------------------------------------------------- /afkit/ans/files.f: -------------------------------------------------------------------------------- 1 | decimal 2 | 3 | : file! ( addr count filename c - ) \ file store 4 | w/o create-file throw >r 5 | r@ write-file throw 6 | r> close-file throw ; 7 | 8 | : @file ( filename c dest maxsize - ) \ fetch file into a mem range 9 | locals| maxsize dest c filename | 10 | filename c r/o open-file throw >r 11 | dest r@ file-size throw drop maxsize min r@ read-file throw drop 12 | r> close-file throw ; 13 | 14 | 15 | \ system heap version 16 | 17 | : file@ ( filename c - mem size ) 18 | r/o open-file throw >r 19 | r@ file-size throw d>s dup dup allocate throw dup rot 20 | r@ read-file throw drop 21 | r> close-file throw 22 | swap ; 23 | 24 | \ dictionary version 25 | 26 | : file ( filename c - addr size ) 27 | file@ 2dup here dup >r swap dup /allot move swap free throw r> swap ; 28 | 29 | : file, ( filename c - ) \ file comma 30 | file 2drop ; 31 | 32 | : ending ( addr len char - addr len ) 33 | >r begin 2dup r@ scan 34 | ?dup while 2swap 2drop #1 /string 35 | repeat r> 2drop ; 36 | 37 | : -EXT ( a n - a n ) 2DUP [CHAR] . ENDING NIP - 1- 0 MAX ; 38 | 39 | [defined] linux [if] 40 | : slashes 2dup over + swap do i c@ [char] \ = if [char] / i c! then #1 +loop ; 41 | : -filename ( a n - a n ) slashes 2dup [char] / ending nip - ; 42 | : -PATH ( a n - a n ) slashes [CHAR] / ENDING 0 MAX ; 43 | [else] 44 | : slashes 2dup over + swap do i c@ [char] / = if [char] \ i c! then #1 +loop ; 45 | : -filename ( a n - a n ) slashes 2dup [char] \ ending nip - ; 46 | : -PATH ( a n - a n ) slashes [CHAR] \ ENDING 0 MAX ; 47 | [then] 48 | 49 | : 0file ( adr c len - ) 50 | locals| len c adr | 51 | here len erase here len adr c file! ; 52 | -------------------------------------------------------------------------------- /afkit/plat/sf.f: -------------------------------------------------------------------------------- 1 | \ None of this needs to be ported to other systems. All non-essential. 2 | 3 | : l locate ; 4 | : e edit ; 5 | 6 | \ variable newquit 7 | \ create backup 11 cells allot 8 | \ 9 | \ : savestack 10 | \ dup 11 | \ depth 10 min cells backup ! 12 | \ sp@ backup cell+ backup @ move 13 | \ drop ; 14 | \ 15 | \ : restorestack 16 | \ s0 @ backup @ - dup sp! 17 | \ backup cell+ swap backup @ move 18 | \ drop ; 19 | \ 20 | \ : (QUIT) ( - ) 21 | \ .STACK BEGIN 22 | \ REFILL DROP INTERPRET savestack PROMPT AGAIN ; 23 | \ 24 | \ : asdfQUIT ( - ) 25 | \ BEGIN 26 | \ R0 @ RP! \ clear return stack 27 | \ /INTERPRETER 28 | \ newquit @ not if newquit on else prompt then 29 | \ ['] (QUIT) CATCH .catch 30 | \ restorestack 31 | \ \ S0 @ SP! \ resets datastack 32 | \ \ /NDP \ resets fstack 33 | \ AGAIN ; 34 | \ 35 | \ THIS DOESN'T WORK ^^^ 36 | 37 | 38 | \ : newprompt 39 | \ cr 40 | \ DEPTH 0> if DEPTH 0 DO S0 @ I 1+ CELLS - @ h. LOOP ." > " THEN 41 | \ depth 0= if ." > " then 42 | \ \ newquit @ not if quit then 43 | \ ; 44 | \ 45 | \ \ FDEPTH ?DUP IF 46 | \ \ ." FSTACK: " 47 | \ \ 0 DO I' I - 1- FPICK N. LOOP 48 | \ \ THEN ; 49 | 50 | \ ' newprompt is prompt 51 | 52 | : /s s0 @ sp! ; 53 | : empty /s empty ; 54 | 55 | : .s base @ >r hex .s r> base ! ; 56 | 57 | 58 | create ldr 256 /allot 59 | : rld ldr count nip -exit ldr count included ; 60 | : ld bl parse ldr place s" .f" ldr append rld ; 61 | 62 | 63 | \ don't touch this 64 | : (EVALUATE) 65 | SAVE-INPUT N>R 66 | ( c-addr u ) #TIB 2! >IN OFF LINE OFF BLK OFF -1 'SOURCE-ID ! 67 | ['] INTERPRET CATCH ( * ) 68 | ( * ) DUP IF POSTPONE [ THEN 69 | NR> RESTORE-INPUT DROP ( * ) THROW ; 70 | 71 | warning off -------------------------------------------------------------------------------- /ramen/structs.f: -------------------------------------------------------------------------------- 1 | also venery 2 | 0 value lastfield 3 | 4 | struct %struct 5 | %struct %node sembed struct>node 6 | %struct svar struct.size 7 | 8 | struct %field 9 | %field %node sembed field>node 10 | %field svar field.offset 11 | %field svar field.size 12 | %field svar field.inspector 13 | 14 | : struct: create %struct *struct /node ; 15 | 16 | : (.field) ( adr size - ) 17 | bounds ?do i @ dup if . else i. then cell +loop ; 18 | 19 | : create-field ( struct bytes - ) ( - field ) 20 | swap >r 21 | create 22 | here to lastfield 23 | %field *struct dup /node dup r@ push 24 | r@ struct.size @ over field.offset ! 25 | ['] (.field) over field.inspector ! \ initialize the inspector 26 | udup field.size ! 27 | r> struct.size +! ; 28 | 29 | previous 30 | 31 | 32 | : sfield ( struct bytes - ) ( adr - adr+n ) 33 | create-field 34 | does> [ 0 field.offset ]# + @ + ; 35 | 36 | : svar ( struct - ) ( adr - adr+n ) 37 | cell sfield ; 38 | 39 | : sizeof ( struct - size ) 40 | struct.size @ ; 41 | 42 | : *struct ( struct - adr ) 43 | here swap sizeof /allot ; 44 | 45 | : struct, ( struct - ) 46 | *struct drop ; 47 | 48 | : is> ( - ; ) ( adr size - ) 49 | r> code> lastfield field.inspector ! ; 50 | 51 | : (.fields) 52 | each> ( adr field ) 53 | normal 54 | dup body> >name ccount type space 55 | bright 56 | 2dup dup field.size @ swap field.inspector @ execute 57 | field.size @ + \ go to next field in the passed instance 58 | ; 59 | 60 | : .fields ( adr struct - ) 61 | dup node.first @ field.offset @ u+ (.fields) drop ; 62 | 63 | [defined] h. [if] 64 | : drop @ dup 0= if #5 attribute then ." $" h. normal ; 65 | : drop sf@ f. ." e" ; 71 | [then] 72 | : drop ccount type ; 73 | : drop count type ; 74 | : drop @ if ." true " else ." false " then ; 75 | : drop @ .name ; 76 | : drop @ dup if >body .name else i. then ; 77 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro5_06_fs.f: -------------------------------------------------------------------------------- 1 | decimal \ important 2 | 3 | function: al_create_fs_entry ( path -- entry ) 4 | function: al_destroy_fs_entry ( entry -- ) 5 | function: al_get_fs_entry_name ( entry -- cname ) 6 | 7 | : bit dup constant 1 lshift ; 8 | 1 9 | bit ALLEGRO_FILEMODE_READ \ 1 10 | bit ALLEGRO_FILEMODE_WRITE \ 1 << 1 11 | bit ALLEGRO_FILEMODE_EXECUTE \ 1 << 2 12 | bit ALLEGRO_FILEMODE_HIDDEN \ 1 << 3 13 | bit ALLEGRO_FILEMODE_ISFILE \ 1 << 4 14 | bit ALLEGRO_FILEMODE_ISDIR \ 1 << 5 15 | drop 16 | 17 | \ AL_FUNC(bool, al_update_fs_entry, (ALLEGRO_FS_ENTRY *e)); 18 | 19 | function: al_get_fs_entry_mode ( fsentry -- n ) 20 | 21 | function: al_get_fs_entry_atime ( ALLEGRO_FS_ENTRY -- ms ) 22 | function: al_get_fs_entry_mtime ( ALLEGRO_FS_ENTRY -- ms ) 23 | function: al_get_fs_entry_ctime ( ALLEGRO_FS_ENTRY -- ms ) 24 | function: al_get_fs_entry_size ( ALLEGRO_FS_ENTRY -- ofs ) 25 | function: al_fs_entry_exists ( ALLEGRO_FS_ENTRY -- flag ) 26 | function: al_remove_fs_entry ( ALLEGRO_FS_ENTRY -- flag ) 27 | 28 | function: al_open_directory ( ALLEGRO_FS_ENTRY -- bool ) 29 | function: al_read_directory ( ALLEGRO_FS_ENTRY -- fsentry ) 30 | function: al_close_directory ( ALLEGRO_FS_ENTRY -- bool ) 31 | 32 | 33 | \ AL_FUNC(bool, al_filename_exists, (const char *path)); 34 | \ AL_FUNC(bool, al_remove_filename, (const char *path)); 35 | 36 | function: al_get_current_directory ( -- char* ) 37 | function: al_change_directory ( char* -- bool ) 38 | 39 | \ AL_FUNC(bool, al_make_directory, (const char *path)); 40 | \ 41 | \ AL_FUNC(ALLEGRO_FILE *, al_open_fs_entry, (ALLEGRO_FS_ENTRY *e, 42 | \ const char *mode)); 43 | \ 44 | 45 | 46 | \ /* Helper function for iterating over a directory using a callback. */ 47 | 48 | -1 49 | enum ALLEGRO_FOR_EACH_FS_ENTRY_ERROR \ = -1 50 | enum ALLEGRO_FOR_EACH_FS_ENTRY_OK \ = 0 51 | enum ALLEGRO_FOR_EACH_FS_ENTRY_SKIP \ = 1 52 | enum ALLEGRO_FOR_EACH_FS_ENTRY_STOP \ = 2 53 | drop 54 | 5 1 9 [compatible] function: al_for_each_fs_entry ( fs_entry_dir callback extra -- int ) \ ( fs_entry extra -- enum ) 55 | \ AL_FUNC(int, al_for_each_fs_entry, (ALLEGRO_FS_ENTRY *dir, 56 | \ int (*callback)(ALLEGRO_FS_ENTRY *entry, void *extra), 57 | \ void *extra)); 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ramen 2.0 2 | 3 | a 2D game dev framework and optional engine for making commercial-quality PC games in Forth. 4 | 5 | Update: 6 | i've gone from a submodule-based system to including all dependencies in the repository. 7 | 8 | the following repositories will house the stable releases of each dependency from now on: 9 | 10 | - [AllegroForthKit](https://github.com/RogerLevy/afkit) 11 | - [Ramen](https://github.com/RogerLevy/ramen) (archived for history) 12 | - [Workspace](https://github.com/RogerLevy/ws) 13 | - [Venery](https://github.com/RogerLevy/venery) 14 | 15 | ## Features 16 | 17 | * Built on Allegro 5, using [AllegroForthKit](https://github.com/RogerLevy/AllegroForthKit). 18 | * Sprite animation 19 | * Multiple display list support 20 | * Interactive commandline console 21 | * Fast rectangle collision detection 22 | * Roundrobin multitasking 23 | * Graphics primitives such as line, rectangle, ellipse, blit, text, etc. 24 | * Publish facility 25 | * Z-sorted rendering 26 | * Basic sound support 27 | * Collections with [Venery](https://github.com/RogerLevy/venery) 28 | 29 | ## Getting Started 30 | 31 | 1. Download [SwiftForth](https://www.forth.com/swiftforth/). 32 | 1. After installation is complete, add SwiftForth's bin\ folder to your PATH. 33 | 1. Copy kitconfig.f to your drive's root folder and customize it if desired. 34 | 1. Run ramen.bat 35 | 36 | Note: SwiftForth's evaluation version doesn't support creating executables, therefore none of the make scripts will work. Work on porting to GForth is underway. 37 | 38 | ## Help 39 | 40 | * Submit [Issues](https://github.com/RogerLevy/ramen/issues) 41 | * Tweet [@RamenEngine](https://twitter.com/RamenEngine) 42 | 43 | ## Links and Resources 44 | 45 | * [Forth: The Hacker's Language on HACKADAY](https://hackaday.com/2017/01/27/forth-the-hackers-language/) 46 | * [Programming Forth by Stephen Pelc](http://www.mpeforth.com/arena/ProgramForth.pdf) 47 | * [Forth Programming 21st Century on Facebook](https://www.facebook.com/groups/PROGRAMMINGFORTH/) - The current active and growing forum on the web for modern desktop Forth programming \(as opposed to on embedded or classic computers.\) 48 | * [Allegro 5.2.3 Documentation](http://liballeg.org/a5docs/5.2.3/) 49 | * [Allegro.cc forum](https://www.allegro.cc/forums) - A very helpful and fairly active community. And gladly, language-agnostic. 50 | * [The DPANS94 Forth Standard](http://dl.forth.com/sitedocs/dpans94.pdf) 51 | -------------------------------------------------------------------------------- /ramen/image.f: -------------------------------------------------------------------------------- 1 | 2 | asset: %image 3 | %image svar image.bmp 4 | %image svar image.subw 5 | %image svar image.subh 6 | %image svar image.subcols 7 | %image svar image.subrows 8 | %image svar image.subcount 9 | %image svar canvas.w 10 | %image svar canvas.h 11 | %image svar image.regions 12 | 13 | 14 | \ get dimensions, fixed point 15 | : imagew image.bmp @ bmpw ; 16 | : imageh image.bmp @ bmph ; 17 | : imagewh image.bmp @ bmpwh ; 18 | 19 | \ reload-image ( image - ) (re)load from file 20 | \ init-image ( path c image - ) normal asset init 21 | \ image: ( path c - ) declare named image. 22 | \ >bmp ( image - ALLEGRO_BITMAP ) 23 | : reload-image >r r@ srcfile count findfile zstring al_load_bitmap r> image.bmp ! ; 24 | : unload-image image.bmp @ al_destroy_bitmap ; 25 | : init-image >r r@ srcfile place ['] reload-image ['] unload-image r@ register r> reload-image ; 26 | : image: create %image *struct init-image ; 27 | : >bmp image.bmp @ ; 28 | 29 | \ load-image ( path c image - ) 30 | \ free-image ( image - ) 31 | : free-image image.bmp @ -bmp ; 32 | : load-image dup free-image init-image ; 33 | 34 | \ Canvas (images without source files) 35 | 36 | \ recreate-canvas ( image - ) 37 | \ resize-canvas ( w h image - ) 38 | \ init-canvas ( w h image - ) 39 | \ canvas: ( w h - ) 40 | : recreate-canvas #24 al_set_new_bitmap_depth >r r@ canvas.w 2@ 2i al_create_bitmap r> image.bmp ! ; 41 | : unload-canvas unload-image ; 42 | :slang ?samesize >r 2dup r@ canvas.w 2@ d= if 2drop r> r> 2drop exit then r> ; 43 | : resize-canvas ?samesize >r r@ free-image r@ canvas.w 2! r> recreate-canvas ; 44 | : init-canvas >r ['] recreate-canvas ['] unload-canvas r@ register r@ canvas.w 2! r> recreate-canvas ; 45 | : canvas: create %image *struct init-canvas ; 46 | 47 | \ Sub-image stuff 48 | 49 | \ subdivide ( tilew tileh image - ) calculate subimage parameters 50 | \ subxy ( n img - x y ) locate a subimg by index 51 | \ subxywh ( n img - x y w h ) get full rect of subimage 52 | : subdivide 53 | >r 2dup r@ image.subw 2! 54 | r@ imagewh r@ image.subw 2@ 2/ 2pfloor r@ image.subcols 2! 55 | * r> image.subcount ! ; 56 | : subxy >r pfloor r@ image.subcols @ /mod 2pfloor r> image.subw 2@ 2* ; 57 | : subwh image.subw 2@ ; 58 | : subxywh dup >r subxy r> subwh ; 59 | 60 | : tileset: ( tilew tileh imagepath c - ) 61 | image: lastbody subdivide ; 62 | -------------------------------------------------------------------------------- /ramen/base.f: -------------------------------------------------------------------------------- 1 | exists ramen [if] \\ [then] 2 | true constant ramen 3 | include afkit/afkit.f \ AllegroForthKit 4 | #1 #6 #0 [afkit] [checkver] 5 | 6 | ( Low-level ) 7 | 0 value (count) 8 | 0 value (ts) 9 | 0 value (bm) 10 | [undefined] LIGHTWEIGHT [if] 11 | include afkit/dep/zlib/zlib.f 12 | [then] 13 | include ramen/fixops.f 14 | include afkit/plat/sf/fixedp.f \ must come after fixops. 15 | include ramen/res.f 16 | include venery/venery.f 17 | include ramen/structs.f 18 | 19 | : ?p. p. ; \ dup $0000fff and if p. else i. then ; 20 | : bounds ?do i @ ." #" i. cell +loop ; 21 | : dump ; 22 | : nip ." ( " cell i/ i. ." )" space ; 23 | : bounds ?do i @ ?p. cell +loop ; 24 | : sfield sfield noop ; 47 | : void ( - ) stop show> ramenbg ; 48 | 49 | : project: ( -- ) 50 | bl parse project place s" /" project append 51 | project count slashes 2drop ; 52 | 53 | : .project project count type ; 54 | 55 | variable ldl 56 | 57 | : ?project project count nip ?exit ldr count -filename project place ; 58 | 59 | : (included) 1 ldl +! ['] included catch 60 | dup 0= if -1 ldl +! ?project else 0 ldl ! then 61 | throw ; 62 | 63 | : rld ldr count nip -exit ldr count (included) ; 64 | 65 | : ld ( -- ) 66 | bl parse s" .f" strjoin 2>r 67 | 2r@ file-exists not if 68 | project count 2r> strjoin 2>r 69 | then 70 | ldl @ 0= if 2r@ ldr place then 71 | 72 | 2r@ (included) 73 | 2r> 2drop ; 74 | 75 | : empty 76 | displaywh resolution 77 | oscursor on 78 | page 79 | cr 80 | ." [Empty]" 81 | void 82 | -assets 83 | 0 to now 84 | source-id 0> if including -name #1 + slashes project place then \ swiftforth 85 | empty 86 | ; 87 | : gild 88 | only forth definitions 89 | s" marker (empty)" evaluate 90 | cr ." [Gild] " 91 | ; 92 | : now now 1p ; \ must go last 93 | 94 | 95 | gild void -------------------------------------------------------------------------------- /venery/string.f: -------------------------------------------------------------------------------- 1 | 2 | ( String ) 3 | struct %string 4 | %string %collection sembed string.collection 5 | %string svar string.data 6 | 7 | collection-vtable-size vtable string-vtable ( collection 0 ) 8 | \ [] ( index collection -- adr ) 9 | :vector array.data @ swap bytes + ; 10 | \ truncate ( n collection -- ) 11 | :vector collection.length dup @ rot min swap ! ; 12 | \ push ( val collection -- ) 13 | :vector >r r@ length r@ [] c! 1 r> collection.length +! ; 14 | \ pop ( collection -- val ) 15 | :vector >r r@ length 1 - r@ [] c@ -1 r> collection.length +! ; 16 | \ each ( xt collection -- ) ( val -- ) 17 | :vector xt >r swap to xt dup string.data @ swap length bounds ?do 18 | i c@ xt execute 1 bytes +loop r> to xt ; 19 | \ deletes ( index count collection -- ) 20 | :vector 3dup nip length >= if 3drop exit then 21 | locals| c n i | 22 | i n + c length min i - to n \ adjust count if needed 23 | i bytes c string.data @ + \ dest 24 | dup n bytes + \ src 25 | swap \ src dest 26 | c string.data @ c length bytes + \ end 27 | over - ?move 28 | n negate c collection.length +! ; 29 | \ .each ( collection -- ) 30 | :vector dup string.data @ swap length dup 1i i. ." : " type ; 31 | \ remove ( val collection -- ) \ remove all instances 32 | :vector locals| c itm | 33 | c length 0 ?do 34 | i c length >= if unloop exit then 35 | i c [] c@ itm = if i 1 c deletes then 36 | loop ; 37 | \ ?@ ( adr collection -- val ) \ adr is val adr, or node, depending, e.g. in EACH SOME DIFF 38 | :vector drop c@ ; 39 | \ removeat ( i collection -- ) \ deletes or removes the value at i, depending. 40 | :vector 1 swap deletes ; 41 | \ insert ( val i dest-collection -- ) 42 | :vector locals| dest i val | 43 | dest 1 more? abort" Error in INSERT: Destination collection is full." 44 | dest string.data @ i bytes + dup 1 bytes + dest length i - bytes move 45 | val i dest [] c! 46 | 1 dest collection.length +! ; 47 | 2drop 48 | 49 | 50 | : *empty-string ( n -- string ) 51 | %string *struct >r 52 | string-vtable r@ collection.vtable ! 53 | here r@ string.data ! 54 | dup /allot 55 | r@ collection.capacity ! 56 | r> ; 57 | 58 | : set-string ( adr n string - ) 59 | >r 60 | 2dup r@ string.data @ swap move 61 | nip 62 | r> collection.length ! 63 | ; 64 | 65 | : *string ( adr length capacity -- string ) \ data will be copied from adr 66 | *empty-string >r 67 | r@ set-string 68 | r> ; -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro-5.2.x.f: -------------------------------------------------------------------------------- 1 | decimal \ important 2 | 3 | [undefined] #defined [if] 4 | : #define create 0 parse bl skip evaluate , does> @ ; 5 | : #fdefine create 0 parse bl skip evaluate sf, does> sf@ ; 6 | [then] 7 | 8 | : cfield create over , + does> @ + ; 9 | : cvar cell cfield ; 10 | : fload include ; 11 | : ?constant constant ; 12 | 13 | \ intent: speeding up some often-used short routines 14 | \ usage: macro: ; \ entire declaration must be a one-liner! 15 | : macro: ( - ; ) \ define a macro; the given string will be evaluated when called 16 | create immediate 17 | [char] ; parse string, 18 | does> count evaluate ; 19 | 20 | [undefined] ALLEGRO_VERSION_INT [if] 21 | [defined] linux [if] $5020401 [else] $5020300 [then] 22 | constant ALLEGRO_VERSION_INT 23 | [then] 24 | 25 | ALLEGRO_VERSION_INT $ffffff00 and $5020300 = [if] cd afkit/dep/allegro5/5.2.3 [then] 26 | ALLEGRO_VERSION_INT $ffffff00 and $5020400 = [if] cd afkit/dep/allegro5/5.2.4 [then] 27 | 28 | cr .( Loading Allegro ) ALLEGRO_VERSION_INT h. .( ... ) 29 | 30 | [defined] linux [if] 31 | create libcmd 256 allot 32 | : linux-library 33 | s" library " libcmd place 34 | 0 parse libcmd append 35 | s" .so.5.2" libcmd append 36 | libcmd count evaluate 37 | ; 38 | linux-library liballegro 39 | linux-library liballegro_memfile 40 | linux-library liballegro_primitives 41 | linux-library liballegro_acodec 42 | linux-library liballegro_audio 43 | linux-library liballegro_color 44 | linux-library liballegro_font 45 | linux-library liballegro_image 46 | linux-library liballegro_font 47 | [else] 48 | : linux-library 0 parse 2drop ; 49 | [defined] allegro-debug [if] 50 | library allegro_monolith-debug-5.2.dll 51 | [else] 52 | library allegro_monolith-5.2.dll 53 | [then] 54 | cd ../../../.. 55 | [then] 56 | 57 | : void ; 58 | 59 | : /* postpone \ ; immediate 60 | 61 | 62 | : [COMPATIBLE] ( ver subver rev -- ) 63 | 8 lshift swap 16 lshift rot 24 lshift or or ALLEGRO_VERSION_INT $ffffff00 and > if 0 parse 2drop then ; 64 | 65 | 66 | \ ----------------------------- load files -------------------------------- 67 | 68 | include afkit/dep/allegro5/allegro5_01_general.f 69 | include afkit/dep/allegro5/allegro5_02_events.f 70 | include afkit/dep/allegro5/allegro5_03_keys.f 71 | include afkit/dep/allegro5/allegro5_04_audio.f 72 | include afkit/dep/allegro5/allegro5_05_graphics.f 73 | include afkit/dep/allegro5/allegro5_06_fs.f 74 | include afkit/dep/allegro5/allegro5_07_misc.f 75 | 76 | \ =============================== END ================================== 77 | 78 | .( Done ) 79 | -------------------------------------------------------------------------------- /sample/platformer/lib/collision.f: -------------------------------------------------------------------------------- 1 | ( Simple tilemap collision ) 2 | depend sample/platformer/lib/array2d.f 3 | 4 | ( what sides the object collided ) 5 | 0 value lwall? 6 | 0 value rwall? 7 | 0 value floor? 8 | 0 value ceiling? 9 | 10 | [undefined] tstep@ [if] : tstep@ 16 16 ; [then] 11 | 12 | extend: _actor 13 | var mbw var mbh \ object collision box width,height 14 | ;class 15 | 16 | defer on-tilemap-collide ' drop is on-tilemap-collide ( tilecell - ) 17 | defer tileprops@ :noname drop 0 ; is tileprops@ ( tilecell - bitmask ) 18 | 19 | #1 20 | bit BIT_CEL 21 | bit BIT_FLR 22 | bit BIT_WLT 23 | bit BIT_WRT 24 | value tile-bits 25 | 26 | define collisioning 27 | 28 | 0 value map 29 | : map@ ( col row - tile ) map loc @ ; 30 | 31 | : cel? BIT_CEL and ; \ ' ceiling ' 32 | : flr? BIT_FLR and ; \ ' floor ' 33 | : wlt? BIT_WLT and ; \ ' wall left ' 34 | : wrt? BIT_WRT and ; \ ' wall right ' 35 | 36 | : vector create 0 , here 0 , constant ; 37 | vector nx ny 38 | 39 | : gap ( - n ) tstep@ drop ; \ just square tiles supported for now 40 | 41 | : px x @ ; 42 | : py y @ ; 43 | 44 | variable t 45 | : xy>cr ( x y tilesize - ) dup 2/ 2pfloor ; 46 | : pt gap xy>cr map@ dup t ! tileprops@ ; \ point 47 | 48 | ( increment coordinates ) 49 | : ve+ swap gap + mbw @ #1 - px + min swap ; 50 | : he+ gap + mbh @ #1 - ny @ + min ; 51 | 52 | : +vy ny +! ny @ py - vy ! ; 53 | : +vx nx +! nx @ px - vx ! ; 54 | 55 | ( push up/down ) 56 | : pu ( xy ) nip gap mod negate +vy true to floor? t @ on-tilemap-collide ; 57 | : pd ( xy ) nip gap mod negate gap + +vy true to ceiling? t @ on-tilemap-collide ; 58 | 59 | ( check up/down ) 60 | : cu mbw @ gap / 2 + for 2dup pt cel? if pd unloop exit then ve+ loop 2drop ; 61 | : cd mbw @ gap / 2 + for 2dup pt flr? if pu unloop exit then ve+ loop 2drop ; 62 | 63 | ( push left/right ) 64 | : pl ( xy ) drop gap mod negate ( -1.0 + ) +vx true to rwall? t @ on-tilemap-collide ; 65 | : pr ( xy ) drop gap mod negate gap + +vx true to lwall? t @ on-tilemap-collide ; 66 | 67 | ( check left/right ) 68 | : cl mbh @ gap / 2 + for 2dup pt wrt? if pr unloop exit then he+ loop 2drop ; 69 | : crt mbh @ gap / 2 + for 2dup pt wlt? if pl unloop exit then he+ loop 2drop ; 70 | 71 | : ud vy @ -exit vy @ 0 < if px ny @ cu exit then px ny @ mbh @ + cd ; 72 | : lr vx @ -exit vx @ 0 < if nx 2@ cl exit then nx @ mbw @ + ny @ crt ; 73 | 74 | : init px py vx 2@ 2+ nx 2! 0 to lwall? 0 to rwall? 0 to floor? 0 to ceiling? ; 75 | 76 | only forth definitions fixed 77 | also collisioning 78 | 79 | : collide-tilemap ( array2d - ) to map init ud lr ; 80 | 81 | only forth definitions -------------------------------------------------------------------------------- /venery/array.f: -------------------------------------------------------------------------------- 1 | 2 | ( Array ) 3 | struct %array 4 | %array %collection sembed array.collection 5 | %array svar array.data 6 | 7 | collection-vtable-size vtable array-vtable ( collection 0 ) 8 | \ [] ( index collection -- adr ) 9 | :vector array.data @ swap cells + ; 10 | \ truncate ( n collection -- ) 11 | :vector collection.length dup @ rot min swap ! ; 12 | \ push ( val collection -- ) 13 | :vector >r r@ length r@ [] ! 1 r> collection.length +! ; 14 | \ pop ( collection -- val ) 15 | :vector >r r@ length 1 - r@ [] @ -1 r> collection.length +! ; 16 | \ each ( xt collection -- ) ( val -- ) 17 | :vector xt >r swap to xt dup array.data @ swap length cells bounds ?do 18 | i @ xt execute cell +loop r> to xt ; 19 | \ deletes ( index count collection -- ) 20 | :vector 3dup nip length >= if 3drop exit then 21 | locals| c n i | 22 | i n + c length min i - to n \ adjust count if needed 23 | i cells c array.data @ + \ dest 24 | dup n cells + \ src 25 | swap \ src dest 26 | c array.data @ c length cells + \ end 27 | over - ?move 28 | n negate c collection.length +! ; 29 | \ .each ( collection -- ) 30 | :vector dup length 1i i. ." items: " each> . ; 31 | \ remove ( val collection -- ) \ remove all instances 32 | :vector locals| c itm | 33 | c length 0 ?do 34 | i c length >= if unloop exit then 35 | i c [] @ itm = if i 1 c deletes then 36 | loop ; 37 | \ ?@ ( adr collection -- val ) \ adr is val adr, or node, depending, e.g. in EACH SOME DIFF 38 | :vector drop @ ; 39 | \ removeat ( i collection -- ) \ deletes or removes the value at i, depending. 40 | :vector 1 swap deletes ; 41 | \ insert ( val i dest-collection -- ) 42 | :vector locals| dest i val | 43 | dest 1 more? abort" Error in INSERT: Destination collection is full." 44 | dest array.data @ i cells + dup cell+ dest length i - cells move 45 | val i dest [] ! 46 | 1 dest collection.length +! ; 47 | 2drop 48 | 49 | : *array ( n -- array ) 50 | %array *struct >r 51 | array-vtable r@ collection.vtable ! 52 | here r@ array.data ! dup r@ collection.length ! 53 | dup r@ collection.capacity ! 54 | cells /allot 55 | r> ; 56 | : *stack ( n -- array ) 57 | %array *struct >r 58 | array-vtable r@ collection.vtable ! 59 | here r@ array.data ! 0 r@ collection.length ! 60 | dup r@ collection.capacity ! 61 | cells /allot 62 | r> ; 63 | 64 | : array, *array drop ; 65 | : stack, *stack drop ; 66 | 67 | : 0array ( array/stack - ) 68 | 0 over [] ( array adr ) over collection.capacity @ cells erase 69 | ( array ) vacate ; -------------------------------------------------------------------------------- /sample/platformer/data/level01.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | eJzt2OGOqyoUgFHn/V/65v64iZcAAiJs61qJmZnW6rbphz3nOAAAxv0lG/Ad+odvStvXP3xDrn39w7u1NFxqX/8QX63fu/33rgPWDFhrpNuW5kfXEGCd3m61D7+jt9/e/tNjzPq3AnDfzHavjjPz/wqA++40PfIdQP8Qx+r+c+cE9ljVf+07ALDHyv5954dYNA/f1drkrOa1DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABABH+7BwjMe0Mkfw9tPec//3yL0Wuu7fu294D329n/6JrRa9U1tlzHVf/WAFaK1H/62tzftWO0PH517qeuPf2eM7p+wExR+295rGXtiLidZ0zfj/RxawJP2tX+ynM/1e7o63Odp8esPQazvLH/J+d+4rhX60j6e2kemG13/+nPkX4ibKV5rh7PvQ+l/a0BzLa7/97jzp5v9nF798n9nXt/jszzcFeE/o8j30Ktnadmb10vZs6SHis9/uj7C1ee6qXlc9pz7zy/Jv29pafRDlt7a5llZK3RP09add+snffq79K6ctVabb+ruc5/t7jTe+mcuXPrn5ki9N/TzZ2Ze96P89+9r7taj3qvIX0dzLKz//P5SzP1/n2n/dI8vfu2zqJ/dtvRfu78pZl65zzv/7TWe3vusd73Mv0JM0TsvzZX+pqWxmYqrUml2Vsfa7le3wV4Uu3zVWr0/PtIb739j3wnqM11d424mj13jp71K3e82rlhVG//tdf2nLO10VoXs76PzFJqP93nzhqmf2aafR9sfd1I/3fu96XHZq8ff8nP0j4961ru+PBmT/Q/ev7ScXrPced+3rO/NQDGjH6veOrfFaXvAOfnc68B6mrNtnQ98u+K0Rlrz/fsD61m3At774srP789/R+Z/WrPzdLyb4r0b/0zw+r+Z3yXbrknj8ySe+2d/mc1qn+esuP+n5579Lk7/ae95xpvvb7ad4vS83fon1l29p/O0Pp4br/Wc+S6b+0/N1PL7LX5SsdrWdusAdwVof//5qjN1nINLfu0rAM919nyWO06arMcmdfMer/hbGX/pf2vWrpquHSu3LFX9V9runUtSq9H/8y2sv+eGY6jfOxcT6Xna/2W9i299omtdq7cNeWuF0bt7r+3iVm9HcnvV9eVW5NmzNp6bv3zhJ39zzzv3f5nvhe93ZfOnZsrnRnu2Nn/7BlmrhN3mx7pP/czPWb6HNzR2/bs/nc0nzv/inl614bcTOlzcMes/kc+k7n74OiMrQ33HO/JNamH/nnKzs/1U7Ps6PzONY68DmaI1P+KOSOuHa3vpf6Zbcc98Ilzz5h3R9Olc1/tAzPsav9JrbNGnT8V+b3m3b5679/R1Kz3CmZ5W0OzZ47+XeZf0efjvd7azC/1XprjL3k+wqz8ltUNzfocR+x/9rHT/mG2aA21ith/y7y9+7v386RIDc1sOlr/qdK503t+Oqd1gJl2NnTns7y6/xXrRdq5/nnaW++hke7/s45Xm03/PCFKQ70i9d86Z+t+uXu+/nnC7oZGX/uW/q+kjeufld7a0K7+Z15vqfOrx2GWSP3PbPrO7D3XVTpWyzH0z26R+u+x6/4/Y+b0b/2zy9sa+s8b+z9L+z4/pn9WidDQyHFW9t87X8u+Pa3rn6dE6H/EG+//V/f8dD/987ToDc3sfObsvcep3deP4/+v1z+rRO+/ZHf/rfOV5k330T87RG6oJnr/V/Memd9z+9b2g7siNdRzvK/2n+4Ld7ypobPV/df2b3kufSx9Tv/s8Jb+Z/a+cnb9E9kbGsp5sv8Z11Q7R9p1qferdQLuekv/K+//s/vPPVe6ptxrd62x/L5o/bce88n+Z8yZa3hk9uO4NyfUROu/1cr+R9akI/P76Nzn18NMUfu/Ou7u+//VTLkZWx6r7QOzRWuo1e7+c69veWy0f3iC/ufPlZuz5ffS+gFPidjQzLmi91+695eOBzNFbKjFyvWh5z2Y9frzdcJT9P9M/+c503mvrgFWidh/y7F3tz5rbTg/B6vpf037R+bv9HpgNf3H6B92iNR/z7F3N61/fkHk/lfMrX++TP/657si9D9yrN1N659fsKv/u8fa3bT++QX61z/fFaX/XXPrny/b1f/53Dvn1j9fpv91/UM0uz/jo6/f3bT++QW7P+Ojx9ndtP75BRE+4/qHPSJ8xvUPe0T4jI8ca3fT+ucX7G4j2gZfsru3aBt8ye7eom3wJbt7i7bBl+zuLdoGX7K7t2gbfMnu3qJt8CW7e4u2wZfs7i3aBl+yu7doG3zV7vYibPBVu9uLsMFX7W4vwgZftbu9CBt81e72ImzwVbvbi7DBV+1uL8IGvI/+AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAn/QM3CBo3 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ramen/lib/std/task.f: -------------------------------------------------------------------------------- 1 | 0 value task \ current task 2 | 3 | fixed 4 | 5 | extend: _actor 6 | var sp = sp@ dtop < and ; 44 | : halt (task) off running? if pause then ; 45 | : end me dismiss halt ; 46 | : ?end -exit end ; 47 | 48 | decimal 49 | : ?stacks (rs) @ ?exit _taskstack dynamic (rs) ! ; 50 | : perform ( n xt - ) 51 | ?stacks \ tasks don't allocate their return stacks until their first PERFORM 52 | (task) on 53 | running? if 54 | rtop cell- rp! 55 | ( xt ) >code >r 56 | ( n ) 57 | dtop cell- cell- sp! 58 | ;then 59 | ( xt ) >code rtop cell- cell- ! 60 | ( n ) dtop cell- ! 61 | dtop cell- cell- sp ! 62 | ['] halt >code rtop cell- ! 63 | rtop cell- cell- rp ! 64 | ; 65 | : perform> ( n - ) 66 | r> code> perform ; 67 | 68 | fixed 69 | 70 | \ pulse the multitasker. 71 | : multi ( objlist - ) 72 | dup 0= if drop ;then 73 | dup length 0= if drop ;then 74 | >first main node.next ! 75 | dup 76 | sp@ main 's sp ! 77 | rp@ main 's rp ! 78 | main { 79 | begin 80 | ['] pause catch if 81 | cr ." A task crashed. Halting it." 82 | dtop cell- sp! .me 83 | cr ." Data stack: " 84 | .ds 85 | (task) off \ don't call HALT, we don't want PAUSE 86 | then 87 | me node.next @ 0= me main = or until 88 | } 89 | drop 90 | main to task 91 | ; 92 | 93 | : free-task ( - ) 94 | (rs) @ -exit (rs) @ destroy ; 95 | 96 | 97 | : task:free-node 98 | dup _actor is? not if destroy ;then 99 | dup actor:free-node 100 | { free-task } 101 | ; 102 | 103 | 104 | \ : empty sp@ main 's sp ! rp@ main 's rp ! empty ; 105 | sp@ main 's sp ! rp@ main 's rp ! 106 | 107 | ' task:free-node is free-node 108 | 109 | -------------------------------------------------------------------------------- /ramen/lib/tween.f: -------------------------------------------------------------------------------- 1 | variable (delay) 2 | variable (length) 3 | 4 | 5 | 6 | create tweens _node static, 7 | 8 | _node sizeof 0 class: _tween 9 | 10 | \ to prevent tweening objects that don't exist anymore 11 | var target parent remove ; 33 | 34 | : store ( val - ) dest @ ! ; \ storer @ execute ; 35 | 36 | : target! dup target ! { ?id } ?dup if @ targetid ! then ; 37 | 38 | : orphaned? ( - flag ) target @ { ?id } dup if @ targetid @ <> then ; 39 | 40 | : tween+ ( - ) 41 | now starttime @ < ?exit 42 | orphaned? if me dismiss ;then 43 | startval @ delta @ now starttime @ - endtime @ starttime @ - / ( start delta ratio ) 44 | in/out @ execute ease @ execute store 45 | now endtime @ = if me dismiss ;then 46 | ; 47 | 48 | 49 | using tweening 50 | 51 | : does-xt does> @ ; 52 | : :xt create does-xt here 0 , :noname swap ! ; 53 | 54 | \ ease modifiers ( start delta ratio -- progress ) 55 | ' noop constant in 56 | :xt out 57 | negate 1.0 + >r swap over + swap negate r> ; 58 | :xt inout 59 | dup 0.5 < if 0.5 2 2* ;then 60 | 0.5 - #1 lshift >r #1 rshift dup u+ r> [ out compile, ] 61 | ; 62 | 63 | 64 | ( Ease functions ) 65 | \ all these describe the "in" animations, transformed by IN OUT and INOUT. 66 | 67 | \ exponential formula: c * math.pow(2, 10 * (t / d - 1)) + b; 68 | \ quadratic formula: c * (t /= d) * t + b 69 | 70 | ( startval ratio delta -- val ) 71 | :xt LINEAR * + ; 72 | :xt EXPONENTIAL 1 - 10 * 2e 1pf f** f>p * + ; 73 | :xt SINE 90 * 90 - sin 1 + * + ; 74 | :xt QUADRATIC dup * * + ; 75 | :xt CUBIC dup * dup * * + ; 76 | :xt QUARTIC dup * dup * dup * * + ; 77 | :xt QUINTIC dup * dup * dup * dup * * + ; 78 | :xt CIRCULAR dup * 1 swap - sqrt 1 - * negate + ; 79 | : overshoot-func >r dup dup r@ 1 + * r> - * * * + ; 80 | :xt OVERSHOOT 1.70158 overshoot-func ; 81 | 82 | \ call this before calling TWEEN 83 | : timespan ( delay length - ) \ in frames 84 | (length) ! (delay) ! ; 85 | 86 | : *tween ( adr start end ease-xt in/out-xt - tween ) 87 | me _tween dynamic { 88 | me tweens push target! 89 | in/out ! ease ! over - delta ! startval ! 90 | dest ! 91 | (delay) @ now + dup starttime ! 92 | (length) @ + endtime ! 93 | me } 94 | ; 95 | 96 | : tween ( adr start end ease-xt in/out-xt - ) 97 | *tween drop ; 98 | 99 | : tweento ( adr end ease-xt in/out-xt - ) 100 | 2>r over @ swap 2r> tween ; 101 | 102 | : tweens+ ( - ) 103 | tweens each> as tween+ ; 104 | 105 | stage actor: tweener 106 | :now act> me stage push me { tweens+ } ; 107 | 108 | previous 109 | -------------------------------------------------------------------------------- /ramen/lib/rsort.f: -------------------------------------------------------------------------------- 1 | 2 | \ 16-bit positive-integer-fixed-point-identifier optimized radix sort! 3 | \ supports sorting a range of numbers between and including 0 ~ 65535 4 | 5 | \ the "radix" in a radix sort is a position or digit within the numbers 6 | \ we're sorting. with each pass, we move the radix one digit. in this case, 7 | \ we start at the right and move to the left until we reach the most significant 8 | \ digit. after all passes are complete, the list is magically sorted. 9 | 10 | \ a radix sort involves no comparisons, but requires a large amount of memory. 11 | \ to control memory use we limit the range of values that this routine 12 | \ can recognize. 13 | 14 | \ for this routine to require just 4 passes, we do it by nybbles, 15 | \ which requires 16 buckets * 2. each bucket needs to be big enough for the 16 | \ entire array, otherwise we'd need extra passes to figure out how big each one 17 | \ needs to be and there'd be more code and we have tons of RAM. 18 | \ since this is meant to be used for the stage, a reasonable maximum limit is 19 | \ 8192 items which works out to 1MB. 20 | 21 | \ $0fff f000 <--- significant bits. 22 | 23 | [undefined] src [if] 24 | 0 value src 25 | 0 value dest 26 | : src! to src ; 27 | : dest! to dest ; 28 | [then] 29 | 30 | define rsorting 31 | decimal 32 | 33 | $0000f000 constant nyb0 34 | nyb0 value radix 35 | 12 constant pass1shift 36 | pass1shift value radixShift 37 | 38 | 15 constant bucketShift 39 | 8192 constant #max \ actual max is #MAX - 1, one cell is reserved for bucket count 40 | 41 | defer @key ( item - key ) 42 | 43 | create table0 #max cells 16 * allot 44 | create table1 #max cells 16 * allot 45 | table0 value table 46 | 47 | : other table table0 = if table1 else table0 then to table ; 48 | : radix++ radix 4 << to radix 4 +to radixShift ; 49 | : bucket ( bucket# - bucket ) bucketShift << table + ; 50 | : !bucket ( n bucket# - ) bucket 1 over +! dup @ cells + ! ; 51 | : /buckets ( - ) 16 0 do 0 i bucket ! loop ; 52 | 53 | : irpass ( first-item count - ) 54 | cells bounds ?do i @ dup @key radix and radixShift >> !bucket cell +loop ; 55 | 56 | : tablepass ( - ) 57 | other /buckets 16 0 do other i bucket @+ other irpass loop radix++ ; 58 | 59 | : irinit ( xt - ) 60 | is @key 61 | pass1shift to radixShift nyb0 to radix 62 | table0 to table /buckets other /buckets other ; 63 | 64 | : !result ( - ) 65 | 16 0 do i bucket @+ cells dup >r dest swap move r> +to dest loop ; 66 | 67 | only forth definitions also rsorting 68 | fixed 69 | : rsort ( addr cells xt - ) \ destructive, XT is @KEY ( addr - key ) 70 | swap 1i swap 71 | over 0= if 2drop drop exit then 72 | irinit over src! irpass radix++ 73 | tablepass tablepass tablepass 74 | src dest! !result 75 | ; 76 | 77 | \ test 78 | fixed 79 | marker dispose 80 | create sortable 4123 , 9 , 5 , 1 , 401 , 234 , 100 , 5 , 99 , 4123 , 23 , 3 , 400 , 50 , 81 | : test <> abort" rsort.f: unit test failed!" ; 82 | sortable 14 ' noop rsort 83 | sortable 84 | @+ 1 test 85 | @+ 3 test 86 | @+ 5 test 87 | @+ 5 test 88 | @+ 9 test 89 | @+ 23 test 90 | @+ 50 test 91 | @+ 99 test 92 | @+ 100 test 93 | @+ 234 test 94 | @+ 400 test 95 | @+ 401 test 96 | @+ 4123 test 97 | @+ 4123 test 98 | drop 99 | dispose 100 | -------------------------------------------------------------------------------- /sample/platformer/lib/array2d.f: -------------------------------------------------------------------------------- 1 | fixed 2 | struct: %array2d 3 | %array2d svar array2d.cols 4 | %array2d svar array2d.rows 5 | %array2d svar array2d.pitch 6 | %array2d svar array2d.data 7 | %array2d svar array2d.ref \ another array2d 8 | %array2d svar array2d.col \ coords in the referenced array2d 9 | %array2d svar array2d.row 10 | 11 | : 2move ( src /pitch dest /pitch /bytes #rows - ) 12 | locals| #rows #bytes destpitch dest srcpitch src | 13 | #rows for 14 | src dest #bytes move 15 | srcpitch +to src destpitch +to dest 16 | loop ; 17 | 18 | \ incomplete ... need to adjust address for negative clip 19 | : clip ( col row #cols #rows #destcols #destrows - col row #cols #rows ) 20 | 2>r 2over 2+ 0 0 2r@ 2clamp 2swap 0 0 2r> 2clamp 2swap 2over 2- ; 21 | 22 | : array2d-head, ( cols rows - ) 23 | udup 2pfloor 2, cells ( pitch ) , here 4 cells + , 24 | 0 , 0 , 0 , ; 25 | 26 | \ by default the data field is set to the adjacent dictionary space 27 | : array2d, ( numcols numrows - ) 28 | 2dup array2d-head, * cells /allot ; 29 | 30 | : array2d: ( numcols numrows - ) 31 | create array2d, ; 32 | 33 | : dims ( array2d - numcols numrows ) 34 | array2d.cols 2@ ; 35 | 36 | : cols dims drop ; 37 | : rows dims nip ; 38 | 39 | 40 | : (clamp) ( col row array2d - col row array2d ) 41 | >r 2pfloor 0 0 r@ array2d.cols 2@ 2clamp r> ; 42 | 43 | : ?ref 44 | dup array2d.ref @ ?dup if nip then ; 45 | 46 | : >data 47 | ?ref array2d.data @ ; 48 | 49 | : pitch@ 50 | ?ref array2d.pitch @ ; 51 | 52 | : colrow+ 53 | array2d.col 2@ 2+ ; 54 | 55 | : loc ( col row array2d - adr ) 56 | (clamp) >r r@ colrow+ r@ pitch@ * swap cells + r> >data + ; 57 | 58 | : count2d ( array2d - data size ) 59 | dup >data swap array2d.cols 2@ * cells ; 60 | 61 | : section2d: ( array2d col row #cols #rows - ) 62 | create array2d-head, lastbody array2d.ref 3! ; 63 | 64 | : adr-pitch ( col row array2d - adr /pitch ) 65 | dup >r loc r> pitch@ ; 66 | 67 | : eachrow ( ... col row #cols #rows XT array2d - ... ) ( ... adr #cells - ... ) 68 | swap >r >r r@ dims clip 2swap r> adr-pitch 69 | r> locals| xt pitch src #rows #cols | 70 | #rows 0 do src #cols xt execute pitch +to src loop ; 71 | 72 | : eachrow> ( ... col row #cols #rows array2d - ... ) ( ... adr #cells - ... ) 73 | r> code> swap eachrow ; 74 | 75 | : fill2d ( val col row #cols #rows array2d - ) 76 | eachrow> third ifill ; 77 | 78 | : clear2d ( array2d - ) 79 | >r 0 0 0 r@ dims r> fill2d ; 80 | 81 | : 2d. >r 0 0 r@ dims 16 16 2min r> 82 | eachrow> cr cells bounds do i @ h. cell +loop ; 83 | 84 | : put2d ( src-array2d dest-array2d col row - ) \ uses SRCRECT ; no clipping 85 | rot adr-pitch 2>r 86 | srcrect xy@ rot adr-pitch 2r> ( adr pitch adr pitch ) 87 | srcrect wh@ >r cells r> 2move ; 88 | 89 | 90 | \ TABLE2D: ( cols - array2d adr ) 91 | \ TABLE2D ( cols - array2d array2d adr ) the table will be left on the stack after ;TABLE2D 92 | \ ;TABLE2D ( array2d adr - ) call to terminate the definition 93 | 94 | : table2d here swap 0 array2d-head, dup here ; 95 | : table2d: create table2d nip ; 96 | : ;table2d here swap - cell/ over array2d.cols @ / pceil swap array2d.rows ! ; 97 | 98 | \ test 99 | marker dispose 100 | create a 10 15 array2d, 101 | create b 12 7 array2d, 102 | a count2d cell/ 5 ifill 103 | b count2d cell/ 10 ifill 104 | dispose 105 | -------------------------------------------------------------------------------- /afkit/plat/win/fpext.f: -------------------------------------------------------------------------------- 1 | \ Words for passing floats and doubles to DLL's 2 | 3 | \ iCODE 4sf ( f: x y z t - ) ( s: - x y z t ) 4 | \ 4 >fs \ make sure data on hardware stack 5 | \ 16 # EBP SUB \ room for 4 integers and tos 6 | \ 12 [EBP] DWORD FSTP \ convert t 7 | \ 0 [EBP] DWORD FSTP \ convert z 8 | \ 4 [EBP] DWORD FSTP \ convert y 9 | \ 8 [EBP] DWORD FSTP \ convert x 10 | \ 12 [EBP] EBX XCHG \ swap t and old tos 11 | \ RET END-CODE 12 | \ 13 | \ iCODE 1df ( f: x - ) ( s: - xl xh ) 14 | \ >f \ make sure data on hardware stack 15 | \ 8 # EBP SUB \ make room for double 16 | \ 0 [EBP] QWORD FSTP \ convert 17 | \ 4 [EBP] EBX XCHG \ swap xh and old tos 18 | \ RET END-CODE 19 | \ 20 | \ iCODE 3sf ( f: x y z - ) ( s: - x y z ) 21 | \ 3 >fs \ make sure data on hardware stack 22 | \ 12 # EBP SUB \ room for 3 integers and tos 23 | \ 8 [EBP] DWORD FSTP \ convert z 24 | \ 0 [EBP] DWORD FSTP \ convert y 25 | \ 4 [EBP] DWORD FSTP \ convert x 26 | \ 8 [EBP] EBX XCHG \ swap z and old tos 27 | \ RET END-CODE 28 | \ 29 | \ iCODE 2sf ( f: x y z - ) ( s: - x y z ) 30 | \ 2 >fs \ make sure data on hardware stack 31 | \ 8 # EBP SUB \ room for 2 integers and tos 32 | \ 4 [EBP] DWORD FSTP \ convert y 33 | \ 0 [EBP] DWORD FSTP \ convert x 34 | \ 4 [EBP] EBX XCHG \ swap z and old tos 35 | \ RET END-CODE 36 | \ 37 | \ iCODE 1sf ( f: x - ) ( s: - x ) 38 | \ 1 >fs \ make sure data on hardware stack 39 | \ 4 # EBP SUB \ room for 1 integers and tos 40 | \ 0 [EBP] DWORD FSTP \ convert x 41 | \ 0 [EBP] EBX XCHG \ swap x and old tos 42 | \ RET END-CODE 43 | 44 | 45 | variable sf 46 | : 1sf sf sf! sf @ ; 47 | : 2sf 1sf 1sf swap ; 48 | : 3sf 1sf 2sf rot ; 49 | : 4sf 2sf 2sf 2swap ; 50 | 51 | variable df 52 | : 1df df f! df 2@ ; 53 | 54 | : 0e ( - f: n ) STATE @ IF POSTPONE #0.0e ELSE #0.0e THEN ; immediate 55 | : 1e ( - f: n ) STATE @ IF POSTPONE #1.0e ELSE #1.0e THEN ; immediate 56 | 57 | : 2s>f swap s>f s>f ; ( x y - f: x y ) 58 | : 3s>f rot s>f swap s>f s>f ; ( x y z - f: x y z ) 59 | : 4s>f 2swap 2s>f 2s>f ; 60 | : c>f s>f 255e f/ ; ( c - f: n ) 61 | 62 | : fValue ( "name" - ) 63 | Create f, immediate does> state @ if s" literal f@ " evaluate exit then 64 | f@ ; 65 | 66 | : fto ( f: v - ) 67 | ' >body state @ 68 | if postpone literal 69 | postpone f! 70 | else f! 71 | then ; immediate 72 | 73 | \ \ NOTE: these are not conversion routines, these are TRANSFER routines. the numbers 74 | \ \ returned on the data static are unusable except by DLL's. 75 | \ 76 | \ : 2df 1df 2>r 1df 2r> ; ( f: x y - ) ( s: float float ) 77 | \ 78 | \ : 3df ( f: x y z - ) ( s: float float float ) 79 | \ 1df 2>r 1df 2>r 1df 2r> 2r> ; 80 | \ 81 | \ : 4df ( f: x y z a - ) ( s: float float float float ) 82 | \ 1df 2>r 1df 2>r 1df 2>r 1df 2r> 2r> 2r> ; 83 | \ 84 | \ : 5df ( f: x y z a b - ) ( s: float float float float float ) 85 | \ 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2r> 2r> 2r> 2r> ; 86 | \ 87 | \ : 6df ( f: x y z a b c - ) ( s: float float float float float float ) 88 | \ 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2r> 2r> 2r> 2r> 2r> ; 89 | \ 90 | \ : 9df ( f: x y z a b c d e f - ) ( s: float float float float float float float float float ) 91 | \ 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 2>r 1df 92 | \ 2r> 2r> 2r> 2r> 2r> 2r> 2r> 2r> ; 93 | -------------------------------------------------------------------------------- /sample/platformer/tools.f: -------------------------------------------------------------------------------- 1 | depend sample/platformer/lib/tilemap2.f 2 | 3 | ( misc ) 4 | : enum dup constant 1 + ; 5 | : ztype zcount type ; 6 | : live-for ( n - ) perform> pauses end ; 7 | : (those) ( filter-xt code objlist - filter-xt code ) 8 | each> as over execute if dup >r then ; 9 | : those> ( filter-xt objlist - ) ( - ) \ note you can't pass anything to 10 | r> me { swap (those) 2drop } ; 11 | : njump ( n adr - ) 12 | swap cells + @ execute ; 13 | : rndcolor ( - ) 1 rnd 1 rnd 1 rnd rgb ; 14 | : bit# ( bitmask - n ) 15 | #1 32 for 2dup and if 2drop i unloop ;then 1 << loop 2drop -1 ; 16 | : sf@+ dup sf@ cell+ ; 17 | : tinted fore sf@+ f>p swap sf@+ f>p swap sf@+ f>p swap sf@+ f>p nip tint 4! ; 18 | : /sprite draw> sprite ; 19 | : *sprite ( image - obj ) stage *actor { tinted img ! /sprite me } ; 20 | : csprite img @ imagewh 0.5 0.5 2* cx 2! sprite ; 21 | : *csprite ( image - obj ) stage *actor { tinted img ! draw> csprite me } ; 22 | : >data project count s" data/" strjoin 2swap strjoin ; \ prepend assets with data path 23 | : hide 's hidden on ; 24 | : reveal 's hidden off ; 25 | : dynamic? dyn @ 0<> ; 26 | : static? dyn @ 0= ; 27 | 28 | ( directional key tools ) 29 | variable lastkeydir 30 | : left? kstate ; 31 | : right? kstate ; 32 | : up? kstate ; 33 | : down? kstate ; 34 | : pleft? pressed ; 35 | : pright? pressed ; 36 | : pup? pressed ; 37 | : pdown? pressed ; 38 | : dirkeys? left? right? or up? or down? or ; 39 | : rdirkeys? released released or released or released or ; 40 | : pdirkeys? pressed pressed or pressed or pressed or ; 41 | : keydir ( -- n ) 42 | left? if 180 exit then 43 | right? if 0 exit then 44 | up? if 270 exit then 45 | down? if 90 exit then 46 | -1 ; 47 | : pkeydir ( -- n ) 48 | pleft? if 180 exit then 49 | pright? if 0 exit then 50 | pup? if 270 exit then 51 | pdown? if 90 exit then 52 | -1 ; 53 | : !dirkey 54 | pdirkeys? if pkeydir lastkeydir ! exit then 55 | rdirkeys? if keydir lastkeydir ! exit then ; 56 | 57 | ( tasks ) 58 | objlist: tasks 59 | 60 | extend: _actor 61 | var (xt) ?end then ; 67 | : target! dup target ! { ?id } ?dup if @ targetid ! then ; 68 | : *task me tasks *actor target! act> ?waste ; 69 | : (after) perform> pauses (xt) @ target @ { execute } end ; 70 | : after ( xt n - ) me { *task swap (xt) ! (after) } ; 71 | : after> ( n - ) r> code> swap after ; 72 | : (every) perform> begin (xt) @ target @ { execute } dup pauses again ; 73 | : every ( xt n - ) me { *task swap (xt) ! (every) } ; 74 | : every> ( n - ) r> code> swap every ; 75 | 76 | ( physics ) 77 | _actor fields: var 'physics r> 'physics ! ; 79 | : ?physics 'physics @ ?dup if >r then ; 80 | 81 | ( tilemap collision ) 82 | _actor fields: var onmaphit ; 84 | :make on-tilemap-collide onmaphit @ execute ; 85 | 86 | ( extend loop ) 87 | : think ( - ) stage acts tasks multi stage multi tasks acts ; 88 | : physics ( - ) stage each> as ?physics vx 2@ x 2+! ; 89 | : tools:step ( - ) step> think physics sweep ; 90 | tools:step 91 | 92 | ( canned movements ) 93 | : control-8way 94 | act> 95 | 0 96 | kstate if drop -1 then 97 | kstate if drop 1 then 98 | 0 99 | kstate if drop -1 then 100 | kstate if drop 1 then 101 | vx 2! 102 | ; 103 | -------------------------------------------------------------------------------- /afkit/ans/roger.f: -------------------------------------------------------------------------------- 1 | : zcount ( zaddr - addr n ) dup dup if 65535 0 scan drop over - then ; 2 | : zlength ( zaddr - n ) zcount nip ; 3 | : zplace ( from n to - ) tuck over + >r cmove 0 r> c! ; 4 | : zappend ( from n to - ) zcount + zplace ; 5 | [undefined] third [if] : third >r over r> swap ; [then] 6 | [undefined] @+ [if] : @+ dup @ swap cell+ swap ; [then] 7 | : u+ rot + swap ; \ "under plus" 8 | : ?lit state @ if postpone literal then ; 9 | : do postpone ?do ; immediate 10 | : for s" 0 ?do" evaluate ; immediate 11 | : /allot here over allot swap erase ; 12 | : allotment here swap /allot ; 13 | : move, here over allot swap move ; 14 | : h? @ h. ; 15 | : reclaim h ! ; 16 | : ]# ] postpone literal ; 17 | : << s" lshift" evaluate ; immediate 18 | : >> s" rshift" evaluate ; immediate 19 | : bit dup constant 1 lshift ; 20 | : clamp ( n low high - n ) -rot max min ; 21 | : and! dup >r @ and r> ! ; 22 | : or! dup >r @ or r> ! ; 23 | : xor! dup >r @ xor r> ! ; 24 | : not! >r invert r> and! ; 25 | : @! dup @ >r ! r> ; 26 | : bounds over + swap ; 27 | : lastbody last @ name> >body ; 28 | : ccount dup c@ 1 u+ ; 29 | : .name dup if body> >name ccount type space else . then ; 30 | : $= compare 0= ; 31 | 32 | : count dup @ cell u+ ; 33 | : string, dup , move, ; 34 | : place 2dup ! cell+ swap move ; 35 | : append 2dup 2>r count + swap move 2r> +! ; 36 | : count! ! ; 37 | : count+! +! ; 38 | : ," [char] " parse string, ; 39 | : included 2dup cr ." [Include] " type included ; 40 | 41 | \ lo and hi are inclusive 42 | : inrange ( n lo hi - flag ) over - >r - r> #1 + u< ; 43 | 44 | : ifill ( addr count val - ) -rot 0 do over !+ loop 2drop ; 45 | : ierase 0 ifill ; 46 | : imove ( from to count - ) cells move ; 47 | : time? ( xt - ) ucounter 2>r execute ucounter 2r> d- d>s . ; 48 | 49 | : kbytes #1024 * ; 50 | : megs #1048576 * ; 51 | : udup over swap ; 52 | : 2, swap , , ; 53 | : 3, rot , swap , , ; 54 | : 4, 2swap swap , , swap , , ; 55 | : :make :noname postpone [ [compile] is ] ; 56 | : reverse ( ... count - ... ) 1 + 1 ?do i 1 - roll loop ; 57 | : ;then s" exit then" evaluate ; immediate 58 | : free dup 0= if ;then free ; 59 | 60 | \ Random numbers 61 | 0 VALUE seed 62 | : /rnd ucounter drop to seed ; /rnd 63 | : random ( - u ) seed $107465 * $234567 + DUP TO seed ; 64 | : rnd ( n - 0..n-1 ) random um* nip ; 65 | 66 | \ readability helper: slang words. callable once then they self-destruct. 67 | : ?compile state @ if compile, else execute then ; 68 | : does-slang does> dup @ ?compile 0 swap body> >name c! ; 69 | : :slang ( - ; ) create immediate here 0 , does-slang :noname swap ! ; 70 | 71 | \ vocabulary helpers 72 | : define 73 | >in @ 74 | exists if >in ! also ' execute definitions exit then \ already defined 75 | dup >in ! vocabulary 76 | >in ! also ' execute definitions ; 77 | : using only forth definitions also ; 78 | vocabulary internal 79 | 80 | \ on-stack vector stuff (roger) 81 | : 2! swap over cell+ ! ! ; 82 | : 2@ dup @ swap cell+ @ ; 83 | : 2+! swap over cell+ +! +! ; 84 | : 3@ dup @ swap cell+ dup @ swap cell+ @ ; 85 | : 4@ dup @ swap cell+ dup @ swap cell+ dup @ swap cell+ @ ; 86 | : 3! dup >r 2 cells + ! r> 2! ; 87 | : 4! dup >r 2 cells + 2! r> 2! ; 88 | : 2min rot min >r min r> ; 89 | : 2max rot max >r max r> ; 90 | : 2+ rot + >r + r> ; 91 | : 2- rot swap - >r - r> ; 92 | : 2negate negate swap negate swap ; 93 | : 2clamp ( x y lowx lowy highx highy - x y ) 2>r 2max 2r> 2min ; 94 | 95 | \ Word tools 96 | : defined ( - c-addr 0 | xt -1 | - xt 1 ) bl word find ; 97 | : exists ( - flag ) defined 0 <> nip ; 98 | 99 | \ compile and exec 100 | : :now :noname [char] ; parse evaluate postpone ; execute ; 101 | 102 | include afkit/ans/depend.f 103 | 104 | defer alert ( a c - ) 105 | :make alert type true abort ; 106 | -------------------------------------------------------------------------------- /ramen/lib/std/sprites.f: -------------------------------------------------------------------------------- 1 | ( Sprite objects ) 2 | 3 | \ animation format: 4 | \ region table, 5 | \ image, 6 | \ speed, 7 | \ <...frame indices...>, 8 | \ $DEADBEEF, 9 | \ offset to loop start, (from location of $DEADBEEF) 10 | 11 | defer animlooped ( - ) :make animlooped ; \ define this in your app to do stuff every time an animation ends/loops 12 | 13 | \ Region tables 14 | 6 cells constant /region 15 | \ x , y , w , h , originx , originy , 16 | 17 | cell constant /frame 18 | \ index+flip , ... 19 | \ hflip = $1 20 | \ vflip = $2 21 | \ index is fixed point 22 | 23 | extend: _actor 24 | \ Transformation info 25 | var sx var sy \ scale 26 | var ang \ rotation 27 | var cx var cy \ center 28 | %color sizeof field tint 29 | 30 | \ animation state; all can be modified freely. only required value is IMG. 31 | var img prototype as 39 | 1 1 sx 2! 40 | 1 1 1 1 tint 4! 41 | 1 anmspd ! 42 | 43 | ( Drawing ) 44 | : bsprite ( srcx srcy w h flip ) 45 | locals| flip h w y x | 46 | img @ -exit 47 | img @ >bmp x y w h 4af tint 4@ 4af cx 2@ destxy 4af sx 2@ 2af 48 | ang @ >rad 1af flip 49 | al_draw_tinted_scaled_rotated_bitmap_region ; 50 | 51 | ( Frame stuff ) 52 | : rgntbl img @ image.regions ; 53 | 54 | : framexywh ( n rgntbl - srcx srcy w h ) 55 | swap /region * + 4@ ; 56 | 57 | : >region ( n - srcx srcy w h ) 58 | img @ 0= if 0 0 0 0 ;then 59 | rgntbl @ if 60 | rgntbl @ framexywh 61 | ;then 62 | img @ image.subw @ if 63 | img @ subxywh 64 | else 65 | 0 0 img @ imagewh 66 | then 67 | ; 68 | 69 | ( Animation ) 70 | : >frame ( anm - adr ) 71 | ( skip the settings ) 2 cells + anmctr @ pfloor /frame * + ; 72 | 73 | : curflip ( index - index n ) 74 | anm @ if anm @ >frame @ #3 and ;then dup 3 and ; 75 | 76 | : ?regorg ( index - index ) \ apply the region origin 77 | img @ -exit rgntbl @ -exit 78 | rgntbl @ over /region * + 4 cells + 2@ cx 2! ; 79 | 80 | : frame@ ( - n ) \ fetch FRM if ANM is 0 81 | anm @ dup if >frame @ else drop frm @ then ; 82 | 83 | \ NSPRITE 84 | \ draw a sprite either from a subdivided image, animation, or image plus region table. 85 | \ if there's no animation, you can pack the flip info into the index. (lower 2 bits) 86 | \ IMG must be subdivided and/or it must have a region table. (region table takes precedence.) 87 | \ if neither, then the whole IMG will be drawn 88 | : nsprite ( index - ) 89 | img @ 0= if drop ;then 90 | anm @ if frm ! frame@ then 91 | ?regorg >region curflip bsprite ; 92 | 93 | : +frame ( speed - ) \ Advance the animation 94 | ?dup -exit anm @ -exit 95 | anmctr +! 96 | ( looping: ) 97 | frame@ $deadbeef = if anm @ >frame cell+ @ anmctr +! animlooped then 98 | ; 99 | 100 | : sprite ( - ) \ draw sprite and advance the animation if any 101 | frame@ nsprite anmspd @ +frame ; 102 | 103 | \ Play an animation from the beginning, using its settings 104 | : animate ( anim - ) 105 | dup anm ! @+ img ! @+ anmspd ! drop 0 anmctr ! ; 106 | 107 | \ Define animations 108 | : anim: ( image speed - loopadr ) 109 | create 2, here ; 110 | : autoanim: ( image speed - loopadr ) ( - ) 111 | anim: does> animate ; 112 | 113 | : ,, for dup , loop drop ; 114 | : loop: drop here ; 115 | : ;anim ( loopaddr - ) $deadbeef , here - /frame i/ 1p 1 + , ; 116 | : range, ( start len - ) bounds do i , loop ; 117 | 118 | \ flipped frame utilities 119 | : ,h #1 or , ; 120 | : ,v #2 or , ; 121 | : ,hv #3 or , ; 122 | -------------------------------------------------------------------------------- /venery/nodetree.f: -------------------------------------------------------------------------------- 1 | ( Node tree ) 2 | struct %node 3 | %node %collection sembed node.collection 4 | %node svar node.parent 5 | %node svar node.previous 6 | %node svar node.next 7 | %node svar node.first 8 | %node svar node.last 9 | 10 | collection-vtable-size vtable node-vtable ( collection 0 ) 11 | \ [] ( index node -- node|0 ) 12 | :vector 13 | dup length 0 = if 2drop 0 exit then 14 | node.first @ swap 0 ?do node.next @ loop ; 15 | \ truncate ( newlength node -- ) 16 | :vector 17 | locals| c newlen | 18 | newlen c length over - c deletes 19 | newlen c collection.length dup @ rot min swap ! ; 20 | \ push ( node destnode -- ) 21 | :vector 22 | locals| b a | 23 | a node.parent @ ?dup if a swap remove then 24 | b node.last @ a node.previous ! 25 | b node.first @ 0 = if a b node.first ! then 26 | a b node.last ! 27 | a node.previous @ ?dup if a swap node.next ! then 28 | b a node.parent ! 29 | 1 b collection.length +! 30 | ; 31 | \ pop ( node -- node|0 ) 32 | :vector 33 | locals| a | 34 | a node.last @ dup 0 = abort" Tried to pop from empty node" 35 | dup a remove ; 36 | \ each ( xt collection -- ) ( val -- ) 37 | :vector 38 | dup length 0 = over 0 = or if 2drop exit then 39 | xt >r swap to xt 40 | node.first @ begin ?dup while 41 | dup node.next @ >r 42 | xt execute 43 | r> 44 | repeat 45 | r> to xt ; 46 | \ deletes ( index count collection -- ) 47 | :vector 3dup nip length >= if 3drop exit then 48 | locals| c n i0 | 49 | n 0 do 50 | i0 c [] dup c remove free-node 51 | loop 52 | ; 53 | \ .each ( collection -- ) 54 | :vector locals| c | c length dup 1i i. ." items: " 0 ?do i c [] . loop ; 55 | \ remove ( node collection -- ) 56 | :vector locals| c n | 57 | n 0 = if exit then 58 | n node.parent @ 0 = if exit then \ not already in any container 59 | n node.parent @ c = not if abort" Tried to remove node from an unrelated node" then 60 | -1 c collection.length +! 61 | c length if 62 | n c node.first @ = if n node.next @ c node.first ! then 63 | n c node.last @ = if n node.previous @ c node.last ! then 64 | else 65 | 0 c node.first ! 0 c node.last ! 66 | then 67 | 0 n node.parent ! 68 | n node.previous @ if n node.next @ n node.previous @ node.next ! then 69 | n node.next @ if n node.previous @ n node.next @ node.previous ! then 70 | 0 n node.previous ! 0 n node.next ! ; 71 | \ ?@ ( adr collection -- val ) \ adr is val adr, or node, depending, e.g. in EACH SOME DIFF 72 | :vector drop ; 73 | \ removeat ( i collection -- ) \ deletes or removes the value at i, depending. 74 | :vector dup >r [] r> remove ; 75 | \ insert ( node i dest-collection -- ) 76 | :vector 2dup [] locals| sibling b i a | 77 | a node.parent @ ?dup if a swap remove then 78 | i b length 1 - >= if 79 | a b push 80 | exit 81 | then 82 | i 0 = if 83 | b node.first @ a node.next ! 84 | a b node.first ! 85 | a dup node.next @ node.previous ! 86 | else 87 | sibling a node.next ! 88 | sibling node.previous @ a node.previous ! 89 | a sibling node.previous ! 90 | a dup node.previous @ node.next ! 91 | then 92 | b a node.parent ! 93 | 1 b collection.length +! ; 94 | 2drop 95 | 96 | : /node ( node -- ) 97 | $ffffffff over collection.capacity ! 98 | node-vtable swap collection.vtable ! ; 99 | 100 | : 0node ( node -- ) 101 | dup %node venery:sizeof erase /node ; 102 | -------------------------------------------------------------------------------- /ramen/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | Ramen is a 2D game engine written in standard Forth. 4 | 5 | This is the package repository, containing only Ramen and none of its dependencies or any examples. 6 | 7 | Currently all documentation pertains to the 1.0 branch. 8 | 9 | 2.0 is being developed on the Master branch. The new main distribution repository, containing all dependencies (as submodules) and examples, is at https://github.com/RogerLevy/RamenEngine. 10 | 11 | I didn't see any conversion on 1.0/1.x (and probably for good reason) and I don't expect anyone to use it right now , but here is a link to the 1.x documentation anyway: [Documentation](https://rogerlevy.gitbook.io/ramen/v/docs/) 12 | 13 | 14 | 15 | ## Features 16 | 17 | * Built with Allegro 5, using [AllegroForthKit](https://github.com/RogerLevy/AllegroForthKit). 18 | * [Tiled](https://www.mapeditor.org/) map support \(partial\) 19 | * Sprite animation 20 | * Multiple display list support 21 | * Interactive commandline console 22 | * Fast rectangle collision detection 23 | * Roundrobin multitasking 24 | * Graphics primitives such as line, rectangle, ellipse, blit, text, etc. 25 | * Publish facility 26 | * Z-sorted rendering 27 | * Basic sound support 28 | * Collections with [Venery](https://github.com/RogerLevy/venery) 29 | 30 | ## See Ramen in Action 31 | 32 | Want to watch some videos? Here's footage of examples from Ramen's predecessor. They're being updated to work on Ramen. 33 | 34 | [https://www.youtube.com/playlist?list=PLO8m1cHe8erpbejS5yZVJAsQNI4Lmpo\_Y](https://www.youtube.com/playlist?list=PLO8m1cHe8erpbejS5yZVJAsQNI4Lmpo_Y) 35 | 36 | Also check out [The Lady](https://store.steampowered.com/app/341060/The_Lady/%20), a commercial game I wrote in Forth to prove it can be done. Large chunks of this game's engine live on in Ramen. 37 | 38 | ## Getting Started 39 | 40 | 1. Download [SwiftForth](https://www.forth.com/swiftforth/). After installing add the bin folder to your path. 41 | 2. Download or clone [ramenExamples](https://github.com/RogerLevy/ramenExamples) 42 | 3. \(If you download a release directly into your project, rename the folder to just `ramen`\). 43 | 4. Copy and rename `afkit/kitconfig.f_` and `afkit/allegro5.cfg_` to the project root, removing the underscores. Edit them if needed. 44 | 5. Optionally get [Komodo Edit](https://www.activestate.com/komodo-ide/downloads/edit) and loading the project file - just hit F5 and the IDE should start. 45 | 6. Otherwise load up SwiftForth, navigate to the project directory with `cd` and `include session.f` - the IDE should start. 46 | 7. You can `ld` any of these: `depth` `flies` `rectland` `island` `stickerknight` 47 | 8. Hit Tab to toggle between IDE and the running demo. Only `rectland` has any controls. 48 | 9. For a more advanced example check out [LinkGoesForth](https://github.com/RogerLevy/linkgoesforth). Note the IDE is active by default. The game won't receive input until you toggle out of it. 49 | 50 | ## Help 51 | 52 | * Submit [Issues](https://github.com/RogerLevy/ramen/issues) 53 | * Tweet [@RamenEngine](https://twitter.com/RamenEngine) 54 | 55 | ## Links and Resources 56 | 57 | * [Forth: The Hacker's Language on HACKADAY](https://hackaday.com/2017/01/27/forth-the-hackers-language/) 58 | * [Programming Forth by Stephen Pelc](http://www.mpeforth.com/arena/ProgramForth.pdf) 59 | * [Forth Programming 21st Century on Facebook](https://www.facebook.com/groups/PROGRAMMINGFORTH/) - The current active and growing forum on the web for modern desktop Forth programming \(as opposed to on embedded or classic computers.\) 60 | * [Allegro 5.2.3 Documentation](http://liballeg.org/a5docs/5.2.3/) 61 | * [Allegro.cc forum](https://www.allegro.cc/forums) - A very helpful and fairly active community. And gladly, language-agnostic. 62 | * [The DPANS94 Forth Standard](http://dl.forth.com/sitedocs/dpans94.pdf) 63 | 64 | ## Projects 65 | 66 | * [Zelda clone](https://github.com/RogerLevy/linkgoesforth) 67 | * [Starfox-like Dogfighting game](https://github.com/RogerLevy/triplestrength) 68 | * [3D Packet](https://github.com/RogerLevy/3dpack) 69 | * [Bento 2D Physics Packet](https://github.com/RogerLevy/bento) 70 | -------------------------------------------------------------------------------- /ramen/lib/std/actor.f: -------------------------------------------------------------------------------- 1 | 0 value lastRole \ used by map loaders (when loading objects scripts) 2 | variable nextid 3 | 4 | 0 4 kbytes class: _role 5 | ;class 6 | 7 | 512 cells node-class: _actor 8 | var role prototype ; \ default role-var and action values for all newly created roles 21 | 22 | 64 cells node-class: _objlist 23 | ;class 24 | 25 | create objlists _node static, \ parent of all objlists 26 | 27 | : >first ( node - node|0 ) node.first @ ; 28 | : >last ( node - node|0 ) node.last @ ; 29 | : >parent ( node - node|0 ) node.parent @ ; 30 | : ?id id $80000000 and 0= if id else 0 then ; 31 | : !id 1 nextid +! nextid @ id ! ; 32 | : *actor ( parent - actor ) _actor dynamic { me swap push !id at@ x 2! dyn on me } ; 33 | : detach ( node - ) dup >parent dup if remove else drop drop then ; 34 | : dismiss ( actor - ) 's marked on ; 35 | 36 | : actor:free-node 37 | dup _actor is? not if destroy ;then 38 | { 39 | dyn @ if me destroy then 40 | id off \ necessary for breaking connections 41 | } 42 | ; 43 | 44 | ' actor:free-node is free-node 45 | 46 | \ making stuff move and displaying them 47 | : ?call ( adr - ) ?dup -exit call ; 48 | : draw ( - ) en @ -exit hidden @ ?exit x 2@ at drw @ ?call ; 49 | : draws ( objlist ) each> as draw ; 50 | : act ( - ) en @ -exit beha @ ?call ; 51 | : sweep ( - ) objlists each> each> as marked @ -exit marked off id off me free-node ; 52 | : acts ( objlist ) each> as act ; 53 | : draw> ( - ) r> drw ! hidden off ; 54 | : act> ( - ) r> beha ! ; 55 | : from ( actor x y - ) rot 's x 2@ 2+ at ; 56 | : -act ( - ) act> noop ; 57 | : objlist: ( - ) create _objlist static objlists push ; 58 | 59 | ( stage ) 60 | objlist: stage \ default object list 61 | 62 | : one ( - actor ) 63 | stage *actor ; 64 | 65 | ( static actors ) 66 | : actor, ( parent - ) _actor static as me swap push !id ; 67 | : actor: ( parent - ) create actor, _actor fields: ; 68 | 69 | ( role stuff ) 70 | 71 | : role's ( - adr ) 72 | s" role @" evaluate ' >body _role superfield>offset ?literal s" +" evaluate 73 | ; immediate 74 | 75 | ( actions ) 76 | : is-action? field.attributes @ ; 77 | 78 | : action: ( - ) ( ??? - ??? ) 79 | _role fields: 80 | cell ?superfield _role superfield>offset role @ + @ execute ; 84 | 85 | : role-var class _role to class var to class ; 86 | : role-field class >r _role to class field r> to class ; 87 | 88 | : :to ( role - ... ) 89 | postpone 's :noname swap ! ; 90 | 91 | : :action ( - ; ) ( ??? - ??? ) 92 | >in @ action: >in ! basis :to ; 93 | 94 | 95 | : -> ( role - ) 96 | postpone 's s" @ execute" evaluate ; immediate 97 | 98 | ( create role ) 99 | : ?update ( - ) 100 | >in @ 101 | defined if >body to lastRole r> drop drop ;then 102 | drop 103 | >in ! ; 104 | 105 | : role: ( - ) 106 | ?update create _role static as 107 | me to lastRole 108 | _actor fields: 109 | ['] is-action? _role >fields some> 110 | :noname swap 111 | field.offset @ 112 | dup basis + postpone literal s" @ execute ; " evaluate \ compile "bridge" code 113 | lastRole + ! \ assign our "bridge" to the corresponding action 114 | ; 115 | 116 | 117 | ( inspection ) 118 | : .role ( actor - ) 119 | >class ?dup if peek else ." No role" then ; 120 | 121 | : .objlist ( objlist - ) 122 | dup length 1i i. each> 123 | { cr me h. ." ID: " id ? ." X/Y: " x 2@ 2. } ; 124 | 125 | _actor >prototype as 126 | en on 127 | basis role ! 128 | -------------------------------------------------------------------------------- /ramen/fixops.f: -------------------------------------------------------------------------------- 1 | \ Basic Fixed-point ops (assuming no fixed-point literal support) 2 | \ the following words will be redefined 3 | \ * / /mod 4 | \ loop 5 | \ the following words will remain untouched 6 | \ + - mod */ 7 | \ the following words will use prefixes to avoid collision with float words 8 | \ pfloor pceil 9 | \ additional words for conversion to and from other formats 10 | \ 1p 2p 3p 4p --- int to fixed 11 | \ 1i 2i 3i 4i --- fixed to int 12 | \ 1pf 2pf 3pf 4pf --- fixed to float 13 | 14 | \ words should take fixed unless otherwise noted: 15 | \ ( n - ) <-- fixed 16 | \ ( n# - ) < - integer ( #n ) means # of n's, in fixed point. ( #n# - ) means # of n's, in integer. 17 | 18 | 12 constant /FRAC 19 | $FFFFF000 constant INT_MASK 20 | $00000FFF constant FRAC_MASK 21 | : FPRES s" 4096e" evaluate ; immediate 22 | 4096 constant PGRAN 23 | $1000 constant 1.0 24 | 25 | : i* * ; 26 | : i/ / ; 27 | : iloop postpone loop ; immediate 28 | 29 | : 1p state @ if /frac postpone literal postpone lshift else /frac lshift then ; immediate 30 | 31 | 32 | [in-platform] sf [if] 33 | icode arshift ( x1 n - x2 ) 34 | ebx ecx mov \ shift count in ecx 35 | pop(ebx) \ get new tos 36 | ebx cl sar \ and shift bits right 37 | ret end-code 38 | package OPTIMIZING-COMPILER 39 | optimize (literal) arshift with lit-shift assemble sar 40 | end-package 41 | : 1i state @ if /frac postpone literal postpone arshift else /frac arshift then ; immediate 42 | [else] 43 | : 1i state @ if 1.0 postpone literal postpone / else 1.0 / then ; immediate 44 | [then] 45 | 46 | : 2p 1p swap 1p swap ; 47 | : 3p 1p rot 1p rot 1p rot ; 48 | : 4p 2p 2swap 2p 2swap ; 49 | : 2i swap 1i swap 1i ; 50 | : 3i >r 1i swap 1i swap r> 1i ; 51 | : 4i swap 1i swap 1i 2>r swap 1i swap 1i 2r> ; 52 | : 1pf s>f FPRES f/ ; 53 | : 2pf swap 1pf 1pf ; 54 | : pfloor INT_MASK and ; 55 | : pfrac FRAC_MASK and ; 56 | : pceil #1 - pfloor 1.0 + ; 57 | : 2pfloor pfloor swap pfloor swap ; 58 | : 2pceil pceil swap pceil swap ; 59 | : f>p FPRES f* f>s ; 60 | 61 | wordlist constant fixpointing 62 | : fixed fixpointing +order decimal ; \ assumes no support for fixed point literals 63 | : decimal fixpointing -order decimal ; 64 | 65 | \ NTS: keep these as one-liners, I might make them macros... 66 | fixed definitions 67 | : * ( n n - n ) 1pf s>f f* f>s ; 68 | : / ( n n - n ) swap s>f 1pf f/ f>s ; 69 | : /mod ( n n - r q ) 2dup mod -rot / pfloor ; 70 | : loop s" 1.0 +loop" evaluate ; immediate 71 | previous definitions 72 | 73 | \ Literal helpers 74 | \ : .0 1p ; 75 | \ : .125 1p $200 or ; 76 | \ : .25 1p $400 or ; 77 | \ : .375 1p $600 or ; 78 | \ : .5 1p $800 or ; 79 | \ : .625 1p $a00 or ; 80 | \ : .75 1p $c00 or ; 81 | \ : .875 1p $e00 or ; 82 | 83 | \ External library helpers 84 | : 1af 1pf 1sf ; \ covert a fixed point value to allegro on-stack float 85 | : 2af 1pf 1pf 1sf 1sf ; 86 | : 3af 1pf 1pf 1pf 1sf 1sf 1sf ; 87 | : 4af 1pf 1pf 1pf 1pf 1sf 1sf 1sf 1sf ; 88 | 89 | \ advanced fixed point math 90 | : cos ( deg - n ) 1pf cos f>p ; 91 | : sin ( deg - n ) 1pf sin f>p ; 92 | : asin ( n - deg ) 1pf fasin r>d f>p ; 93 | : acos ( n - deg ) 1pf facos r>d f>p ; 94 | fixed 95 | : lerp ( src dest factor - n ) >r over - r> * + ; 96 | : anglerp ( src dest factor - n ) 97 | >r over - 360 mod 540 + 360 mod 180 - r> * + ; 98 | 99 | : sqrt ( n - n ) 1pf fsqrt f>p ; 100 | : tan ( rad - n ) 1pf ftan f>p ; 101 | : atan ( n - n ) 1pf fatan f>p ; 102 | : atan2 ( n n - n ) 2pf fatan2 f>p ; 103 | : log2 ( n - n ) 1e 1pf y*log2(x) f>p ; \ binary logarithm (for fixed-point) 104 | : rescale ( n min1 max1 min2 max2 - n ) \ transform a number from one range to another. 105 | locals| max2 min2 max1 min1 n | 106 | n min1 - max1 min1 - / max2 min2 - * min2 + ; 107 | : >rad 1pf d>r f>p ; 108 | 109 | \ on-stack vector stuff (fixed point specific) 110 | : 2* rot * >r * r> ; 111 | : 2/ rot swap / >r / r> ; 112 | : 2mod rot swap mod >r mod r> ; 113 | -------------------------------------------------------------------------------- /afkit/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | AllegroForthKit \(aka AFKit\) is a framework for making games \(and other apps\) in standard Forth using [Allegro 5](www.liballeg.org). 4 | 5 | [Documentation on GitBook](https://rogerlevy.gitbook.io/afkit/v/docs/) 6 | 7 | ## Overview 8 | 9 | The main point of this framework is to bring up a hardware-accelerated graphics window. 10 | 11 | The portable low-level gaming library Allegro 5 powers it. [http://liballeg.org/](http://liballeg.org/) 12 | 13 | [Forth Foundation Library](http://soton.mpeforth.com/flag/ffl/index.html) is included for capabilities often required when working with modern libaries and file formats- features such as XML, Base64, MD5 etc. XML DOM access and Base64 are automatically loaded. 14 | 15 | AFKit is not a comprehensive game development library; it is a cleaned-up version of [Bubble](http://github.com/rogerlevy/bubble/) with fixed-point, Komodo-specific, and game-development-framework files removed and provisions for portability added. For a more complete game development package check out [Ramen](http://github.com/rogerlevy/ramen/). 16 | 17 | ## Cross-platform Support 18 | 19 | ### Currently officially supported platforms: 20 | 21 | * sfwin32 - [SwiftForth](https://www.forth.com/download/) \(Win32\) 22 | * sflinux32 - [SwiftForth](https://www.forth.com/download/) \(Linux\) 23 | 24 | ### Details 25 | 26 | /kitconfig.f specifies compile-time parameters, and loads the appropriate platform config file. That files defines the PLATFORM string, which follows this format: `` For example: sfwin32 = SwiftForth, Windows, 32-bit 27 | 28 | The platform config file creates other compile-time constants and loading platform-specific files such as FFL and Allegro. These files are the appropriate place to put "adapter" definitions or include other optional libraries. 29 | 30 | ## Getting Started 31 | 32 | If you downloaded a release, put it in your project folder. 33 | 34 | Make copies of kitconfig.f _and allegro5.cfg_, removing the underscores. 35 | 36 | Set platform to the appropriate string. See the Cross-platform Support section. 37 | 38 | On Linux, you will need to install Allegro and the addons. As of this writing 5.2 is the latest version. 39 | 40 | ```text 41 | sudo apt-get install liballegro5.2:i386 \ 42 | liballegro-acodec5.2:i386 \ 43 | liballegro-audio5.2:i386 \ 44 | liballegro-dialog5.2:i386 \ 45 | liballegro-image5.2:i386 \ 46 | liballegro-physfs5.2:i386 \ 47 | liballegro-ttf5.2:i386 \ 48 | liballegro-video5.2:i386 49 | ``` 50 | 51 | ### SwiftForth 52 | 53 | [SwiftForth](https://www.forth.com/download/) is available from [FORTH Inc](http://www.forth.com). The trial is fully functional apart from lacking source code. 54 | 55 | From the SwiftForth prompt, change the current path to the root of your project \(if needed\) and "0 0 0 INCLUDE afkit/afkit.f" or "include afkit/main.f" and type `go` for a simple demonstration. 56 | 57 | ## Audio 58 | 59 | When allegro-audio is defined, audio-allegro.f will be loaded, which reserves 32 samples for playing samples with play\_sample, and a default mixer and voice. 60 | 61 | ## The Piston \(main loop\) - afkit/piston.f 62 | 63 | This is a standard main loop with many features. 64 | 65 | To enter the main loop type GO or just press enter without entering anything. A default program defined in display.f will run. Stop the loop by pressing F12. 66 | 67 | The piston has 3 phases. The event handling phase, the step phase, and the display phase. 3 words are used to tell the loop what to do during these phases. These words have a syntax similar to DOES>. 68 | 69 | * SHOW> sets the display. 70 | * STEP> sets the logic. 71 | * PUMP> sets the event handler. 72 | 73 | ## Links and Resources 74 | 75 | * [Forth: The Hacker's Language on HACKADAY](https://hackaday.com/2017/01/27/forth-the-hackers-language/) 76 | * [Programming Forth by Stephen Pelc](http://www.mpeforth.com/arena/ProgramForth.pdf) 77 | * [Forth Programming 21st Century on Facebook](https://www.facebook.com/groups/PROGRAMMINGFORTH/) - The current active and growing forum on the web for modern desktop Forth programming \(as opposed to on embedded or classic computers.\) 78 | * [Allegro 5.2.3 Documentation](http://liballeg.org/a5docs/5.2.3/) 79 | * [Allegro.cc forum](https://www.allegro.cc/forums) - A very helpful and fairly active community. And gladly, language-agnostic. 80 | * [The DPANS94 Forth Standard](http://dl.forth.com/sitedocs/dpans94.pdf) 81 | 82 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro5_03_keys.f: -------------------------------------------------------------------------------- 1 | decimal \ important 2 | 3 | #define 1 4 | #define 2 5 | #define 3 6 | #define 4 7 | #define 5 8 | #define 6 9 | #define 7 10 | #define 8 11 | #define 9 12 | #define 10 13 | #define 11 14 | #define 12 15 | #define 13 16 | #define 14 17 | #define 15 18 | #define

16 19 | #define 17 20 | #define 18 21 | #define 19 22 | #define 20 23 | #define 21 24 | #define 22 25 | #define 23 26 | #define 24 27 | #define 25 28 | #define 26 29 | 30 | #define <0> 27 31 | #define <1> 28 32 | #define <2> 29 33 | #define <3> 30 34 | #define <4> 31 35 | #define <5> 32 36 | #define <6> 33 37 | #define <7> 34 38 | #define <8> 35 39 | #define <9> 36 40 | 41 | #define 37 42 | #define 38 43 | #define 39 44 | #define 40 45 | #define 41 46 | #define 42 47 | #define 43 48 | #define 44 49 | #define 45 50 | #define 46 51 | 52 | #define 47 53 | #define 48 54 | #define 49 55 | #define 50 56 | #define 51 57 | #define 52 58 | #define 53 59 | #define 54 60 | #define 55 61 | #define 56 62 | #define 57 63 | #define 58 64 | 65 | #define 59 66 | constant 67 | #define 60 68 | constant <`> 69 | constant <~> 70 | #define 61 71 | constant <-> 72 | #define 62 73 | constant <=> 74 | constant <+> 75 | #define 63 76 | constant 77 | #define 64 78 | #define 65 79 | constant <[> 80 | #define 66 81 | constant <]> 82 | #define 67 83 | #define 68 84 | constant <;> 85 | #define 69 86 | constant <'> 87 | #define 70 88 | constant <\> 89 | #define 71 /* DirectInput calls this DIK_OEM_102: "< > | on UK/Germany keyboards" */ 90 | #define 72 91 | constant <,> 92 | #define 73 93 | constant <.> 94 | #define 74 95 | constant 96 | #define 75 97 | 98 | #define 76 99 | constant 100 | #define 77 101 | constant 102 | #define 78 103 | #define 79 104 | #define 80 105 | #define 81 106 | #define 82 107 | #define 83 108 | #define 84 109 | #define 85 110 | 111 | #define 86 112 | #define 87 113 | #define 88 114 | #define 89 115 | #define 90 116 | #define 91 117 | 118 | #define 92 119 | #define 93 120 | 121 | #define 94 122 | #define 95 123 | #define 96 124 | #define 97 125 | #define 98 126 | #define 99 127 | #define 100 128 | #define 101 129 | #define 102 130 | 131 | #define 103 /* MacOS X */ 132 | #define 104 /* MacOS X */ 133 | #define 105 /* MacOS X -- TODO: ask lillo what this should be */ 134 | #define 106 /* MacOS X */ 135 | #define 107 136 | 137 | \ /* All codes up to before #define 215 143 | #define 216 144 | #define 217 145 | #define 218 146 | #define 219 147 | #define 220 148 | #define 221 149 | #define 222 150 | #define

223 151 | #define 224 152 | #define 225 153 | #define 226 154 | 155 | 156 | #define ALLEGRO_KEYMOD_SHIFT $00001 157 | #define ALLEGRO_KEYMOD_CTRL $00002 158 | #define ALLEGRO_KEYMOD_ALT $00004 159 | #define ALLEGRO_KEYMOD_LWIN $00008 160 | #define ALLEGRO_KEYMOD_RWIN $00010 161 | #define ALLEGRO_KEYMOD_MENU $00020 162 | #define ALLEGRO_KEYMOD_ALTGR $00040 163 | #define ALLEGRO_KEYMOD_COMMAND $00080 164 | #define ALLEGRO_KEYMOD_SCROLLLOCK $00100 165 | #define ALLEGRO_KEYMOD_NUMLOCK $00200 166 | #define ALLEGRO_KEYMOD_CAPSLOCK $00400 167 | #define ALLEGRO_KEYMOD_INALTSEQ $00800 168 | #define ALLEGRO_KEYMOD_ACCENT1 $01000 169 | #define ALLEGRO_KEYMOD_ACCENT2 $02000 170 | #define ALLEGRO_KEYMOD_ACCENT3 $04000 171 | #define ALLEGRO_KEYMOD_ACCENT4 $08000 172 | -------------------------------------------------------------------------------- /sample/platformer/lib/tilemap2.f: -------------------------------------------------------------------------------- 1 | ( ---=== Tilemap rendering and objects ===--- ) 2 | 3 | depend sample/platformer/lib/array2d.f 4 | depend sample/platformer/lib/buffer2d.f 5 | 6 | 512 512 buffer2d: tilebuf 7 | 8 stack: tilebanks 8 | 9 | \ note that these can be resized and re-subdivided to whatever dimensions you want at any time. 10 | 256 1024 canvas: tilebank0 tilebank0 tilebanks push 16 16 tilebank0 subdivide 11 | 256 1024 canvas: tilebank1 tilebank1 tilebanks push 16 16 tilebank1 subdivide 12 | 256 1024 canvas: tilebank2 tilebank2 tilebanks push 16 16 tilebank2 subdivide 13 | 256 1024 canvas: tilebank3 tilebank3 tilebanks push 16 16 tilebank3 subdivide 14 | 256 1024 canvas: tilebank4 tilebank4 tilebanks push 16 16 tilebank4 subdivide 15 | 256 1024 canvas: tilebank5 tilebank5 tilebanks push 16 16 tilebank5 subdivide 16 | 256 1024 canvas: tilebank6 tilebank6 tilebanks push 16 16 tilebank6 subdivide 17 | 256 1024 canvas: tilebank7 tilebank7 tilebanks push 16 16 tilebank7 subdivide 18 | 19 | 0 value tb 20 | 21 | : tilebank ( n - ) 22 | 7 and tilebanks [] @ to tb ; 0 tilebank 23 | 24 | : puttiles ( bitmap -- ) \ rect is in SRCRECT, dest x,y in pen, dest bank is specified with TILEBANK 25 | tb >bmp onto> srcrect xywh@ movebmp ; 26 | 27 | : entire ( bitmap - ) 28 | 0 0 rot bmpwh srcrect xywh! ; 29 | 30 | : (loadtiles) ( bitmap ) 31 | dup entire dup puttiles -bmp ; 32 | 33 | : loadtiles ( path count -- ) \ dest x,y in pen, dest bank is specified with TILEBANK 34 | loadbmp (loadtiles) ; 35 | 36 | : dimbank ( tilew tileh bankw bankh -- ) 37 | tb resize-canvas tb subdivide ; 38 | 39 | : loadtileset ( path count tilew tileh -- ) 40 | 2>r 0 0 at loadbmp 2r> third bmpwh dimbank (loadtiles) ; 41 | 42 | 43 | \ ------------------------------------------------------------------------------------------------- 44 | \ Render a tilemap 45 | 46 | \ Given a starting address, a pitch, and a tileset base, render tiles to fill the current 47 | \ clip rectangle of the current destination bitmap. 48 | 49 | \ The tilemap is arranged in 32-bit cells, here's the format: 50 | \ 00vh 00tt tttt tttt tttt 0000 0000 0000 ( t=tile # 0-16383, v=vflip, h=hflip) 51 | 52 | \ TILEMAP draws within the current clipping rectangle. 53 | 54 | \ ------------------------------------------------------------------------------------------------- 55 | 56 | 57 | decimal \ for speed 58 | 59 | : tile>rgn ( tiledata - bitmap x y w h ) 60 | tb >bmp swap $003ff000 and 1.0 - tb subxywh ; 61 | 62 | : draw-region ( bitmap x y w h flip - ) 63 | >r 4af at@ 2af r> al_draw_bitmap_region ; 64 | 65 | : tile ( tiledat - ) 66 | ?dup -exit dup >r tile>rgn r> #28 >> draw-region ; 67 | 68 | fixed 69 | 70 | 71 | : tstep@ ( - w h ) 72 | tb image.subw 2@ ; 73 | 74 | : draw-tilemap ( addr /pitch - ) 75 | hold> tstep@ clipwh 2over 2/ 2 1 2+ locals| rows cols th tw pitch | 76 | rows for 77 | at@ ( addr x y ) 78 | third cols cells over + swap do 79 | i @ tile tw 0 +at 80 | cell +loop 81 | th + at ( addr ) pitch + 82 | loop drop ; 83 | 84 | 85 | : scrollofs ( scrollx scrolly tilew tileh pen=xy - col row pen=offsetted ) 86 | [undefined] HD [if] 2swap 2pfloor 2swap [then] 87 | 2over 2over 2mod 2negate +at 2/ 2pfloor ; 88 | 89 | \ Isometric support 90 | : >iso ( x y - x y ) 2dup swap 1 >> - >r + r> ; 91 | : >car ( x y - x y ) 2dup 2 / swap 2 / + >r - r> ; 92 | 93 | : draw-isotilemap ( addr /pitch cols rows - ) 94 | hold> tstep@ locals| th tw rows cols pitch | 95 | rows for 96 | at@ ( addr x y ) 97 | third cols for 98 | dup @ tile cell+ tw th +at 99 | loop drop 100 | tw negate th 2+ at ( addr ) pitch + 101 | loop drop ; 102 | 103 | 104 | ( ---=== Tilemap objects ===--- ) 105 | \ They don't allocate any buffers for map data. 106 | \ A part of the singular buffer TILEBUF is located using the scrollx/scrolly values. 107 | 108 | 109 | extend: _actor 110 | var scrollx var scrolly \ used to define starting column and row! 111 | var w var h \ width & height in pixels (or tiles in the case of isometric...) 112 | var tbi \ tilebank index 113 | ;class 114 | 115 | : tilemap ( - ) 116 | tbi @ tilebank 117 | at@ w 2@ clip> 118 | scrollx 2@ 0 0 2max scrollx 2! 119 | scrollx 2@ tstep@ scrollofs tilebuf loc tilebuf pitch@ draw-tilemap ; 120 | 121 | : /tilemap ( - ) 122 | viewwh w 2! 123 | draw> tilemap ; 124 | 125 | \ : /isotilemap ( cols rows - ) 126 | \ w 2! 127 | \ draw> 128 | \ scrollx 2@ 0 0 2max scrollx 2! 129 | \ tbi @ tilebank 130 | \ scrollx 2@ tilebuf loc tilebuf pitch@ w 2@ isotilemap ; 131 | 132 | \ Tilemap collision 133 | depend sample/platformer/lib/collision.f 134 | -------------------------------------------------------------------------------- /ramen/draw.f: -------------------------------------------------------------------------------- 1 | \ Basic graphics option 2 | 3 | create fore 1e sf, 1e sf, 1e sf, 1e sf, 4 | : rgb ( r g b ) 3af fore 3! ; 5 | : alpha ( a ) 1af fore 3 cells + ! ; 6 | : rgba alpha rgb ; 7 | 8 | 9 | \ Predefined Colors; stored in fixed-point so you can modify them with `['] >BODY` 10 | : 8>p s>f 255e f/ f>p ; 11 | : createcolor create rot 8>p , swap 8>p , 8>p , 1 , does> 3@ 3af fore 3! 1 alpha ; 12 | hex 13 | 00 00 00 createcolor black 39 41 45 createcolor dgrey 14 | 9d 9d 9d createcolor grey cc cc cc createcolor lgrey 15 | ff ff ff createcolor white f8 e0 a0 createcolor beige 16 | e0 68 fb createcolor pink ce 26 33 createcolor red 17 | 73 29 30 createcolor dred eb 89 31 createcolor lbrown 18 | a4 64 22 createcolor brown f7 e2 5b createcolor yellow 19 | bc b3 30 createcolor dyellow ae 3c 27 createcolor lgreen 20 | 44 89 1a createcolor green 21 5c 2e createcolor dgreen 21 | 27 c1 a7 createcolor cyan 14 80 7e createcolor dcyan 22 | 24 5a ef createcolor blue 34 2a 97 createcolor dblue 23 | 31 a2 f2 createcolor lblue 93 73 eb createcolor purple 24 | 96 4b a8 createcolor dpurple cb 5c cf createcolor magenta 25 | 80 00 80 createcolor dmagenta ff ff 80 createcolor lyellow 26 | da 42 00 createcolor orange 27 | fixed 28 | 29 | 30 | \ Bitmaps, backbuffer 31 | : *bmp ( w h - bmp ) 2i al_create_bitmap ; 32 | : onto> ( bmp - ) 33 | r> al_get_target_bitmap >r at@ 2>r 34 | swap onto 0 0 at call 35 | 2r> at r> al_set_target_bitmap ; 36 | : movebmp ( src sx sy w h ) write-src BLEND> 4af destxy 2af 0 al_draw_bitmap_region ; 37 | : backbuf display al_get_backbuffer ; 38 | : backdrop fore 4@ al_clear_to_color white 0 0 at ; 39 | : drench ( bmp ) onto> backdrop ; 40 | 41 | 42 | 43 | \ Bitmap drawing words 44 | \ The anchor for rotation and scaling with XBLIT is the center of the passed bitmap. 45 | 46 | 47 | : blit ( bmp ) 48 | dup 0= if drop ;then destxy 2af 0 al_draw_bitmap ; 49 | : tblit ( bmp ) 50 | dup 0= if drop ;then 51 | fore 4@ destxy 2af 0 al_draw_tinted_bitmap ; 52 | : sblit ( bmp destw desth ) 53 | locals| dh dw | 54 | ?dup -exit 55 | ( bmp ) dup >r fore 4@ 0 0 r> bmpwh 4af destxy dw dh 4af 0 al_draw_tinted_scaled_bitmap ; 56 | : >center bmpwh 1 >> swap 1 >> swap ; 57 | : xblit ( bmp scalex scaley angle flip ) 58 | locals| flip ang sy sx bmp | 59 | bmp -exit 60 | bmp fore 4@ bmp >center destxy 4af sx sy ang >rad 3af flip 61 | al_draw_tinted_scaled_rotated_bitmap ; 62 | : bblit ( bmp x y w h flip ) 63 | locals| flip h w y x bmp | 64 | bmp fore 4@ x y w h 4af destxy 2af flip al_draw_tinted_bitmap_region ; 65 | 66 | 67 | \ Text; uses Ramen font assets 68 | variable fnt default-font fnt ! 69 | : stringw ( adr c - n ) zstring fnt @ >fnt swap al_get_text_width 1p ; 70 | : stringwh ( adr c - w h ) stringw fnt @ chrh ; 71 | : (print) ( str count alignment - ) 72 | -rot zstring >r >r fnt @ >fnt fore 4@ destxy 2af r> r> al_draw_text ; 73 | : print ( str c - ) ALLEGRO_ALIGN_LEFT (print) ; 74 | : printr ( str c - ) ALLEGRO_ALIGN_RIGHT (print) ; 75 | : printc ( str c - ) ALLEGRO_ALIGN_CENTER (print) ; 76 | : font> ( font - ) r> fnt @ >r swap fnt ! call r> fnt ! ; 77 | 78 | \ Primitives 79 | 1e fnegate 1sf constant hairline 80 | : pofs 0.625 dup 2+ ; 81 | : -pofs -1 dup 2+ ; 82 | : line ( dx dy ) destxy pofs 2swap 4af fore 4@ hairline al_draw_line ; 83 | : pixel destxy pofs 2af fore 4@ al_draw_pixel ; 84 | : rect ( w h ) -pofs destxy pofs 2swap 2over 2+ 4af fore 4@ hairline al_draw_rectangle ; 85 | : rectf ( w h ) destxy 2swap 2over 2+ 4af fore 4@ al_draw_filled_rectangle ; 86 | : rrect ( w h rx ry ) 2>r -pofs destxy pofs 2swap 2over 2+ 4af 2r> 2af fore 4@ hairline al_draw_rounded_rectangle ; 87 | : rrectf ( w h rx ry ) 2>r destxy 2swap 2over 2+ 4af 2r> 2af fore 4@ al_draw_filled_rounded_rectangle ; 88 | : oval ( rx ry ) destxy 2swap 4af fore 4@ hairline al_draw_ellipse ; 89 | : ovalf ( rx ry ) destxy 2swap 4af fore 4@ al_draw_filled_ellipse ; 90 | : circle dup oval ; 91 | : circlef dup ovalf ; 92 | 93 | create ftemp 2 cells allot 94 | : 2transform ( x y transform - x y ) \ transform coordinates 95 | >r 2pf 2sf ftemp 2! 96 | r> ftemp dup cell+ al_transform_coordinates 97 | ftemp sf@ f>p ftemp cell+ sf@ f>p ; 98 | 99 | : 2screen ( x y - x y ) al_get_current_transform 2transform ; \ convert coordinates into screen space 100 | 101 | \ Clipping rectangle 102 | define internal 103 | variable cx variable cy variable cw variable ch \ old clip 104 | variable ccx variable ccy variable ccw variable cch \ current clip 105 | using internal 106 | viewwh ch ! cw ! 107 | : clipxy ccx @ ccy @ ; 108 | : clipwh ccw @ cch @ ; 109 | 0 value (code) 110 | 111 | : clip> ( x y w h - ) \ note this won't work properly for rotated transforms. 112 | \ TODO: implement our own clipping box using the alpha channel or something 113 | r> to (code) 114 | 115 | 116 | ccx @ ccy @ ccw @ cch @ 2>r 2>r 117 | 118 | 2over 2over cch ! ccw ! ccy ! ccx ! 119 | 120 | cx cy cw ch al_get_clipping_rectangle 121 | 122 | 2over 2+ 123 | 2screen 2swap 2screen 2swap 124 | 2over 2- 125 | 126 | 4i al_set_clipping_rectangle (code) call 127 | 128 | cx @ cy @ cw @ ch @ al_set_clipping_rectangle 129 | 130 | 2r> 2r> cch ! ccw ! ccy ! ccx ! ; 131 | previous 132 | 133 | ( standard 2D mode; no need to call unless you do stuff to the projection matrix ) 134 | transform: p 135 | : 2d 136 | p al_identity_transform 137 | p 0 0 -16384 3af displaywh 16384 3af al_orthographic_transform 138 | p al_use_projection_transform 139 | ALLEGRO_DEPTH_TEST #0 al_set_render_state 140 | ; 141 | -------------------------------------------------------------------------------- /allegro5.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration file for the Allegro 5 library. 3 | # 4 | # This file should be either in the same directory as your program. 5 | # 6 | # On Unix, this file may also be stored as ~/.allegro5rc or /etc/allegro5rc. 7 | # If multiple files exist, they will be merged, with values from more specific 8 | # files overriding the less specific files. 9 | 10 | [graphics] 11 | 12 | # Graphics driver. 13 | # Can be 'default', 'opengl' or 'direct3d' (Windows only). 14 | driver=opengl 15 | 16 | # Display configuration selection mode. 17 | # 18 | # Under Linux, it can be used to force the old GLX 1.2 way of choosing 19 | # display settings or the new FBConfig method introduced with GLX 1.3. 20 | # 21 | # Under Windows, when using the OpenGL driver, setting it to old will 22 | # use DescribePixelFormat and new will use wglGetPixelFormatAttribivARB 23 | # (provided by WGL_ARB_pixel_format extension). 24 | # 25 | # Can be 'old' and 'new'. Default is 'new'. 26 | config_selection=new 27 | 28 | # What method to use to detect legacy cards for the Direct3D backend of the 29 | # primitives addon. Can be 'default', which means it'll check that the pixel 30 | # shader version supported is below some value. 'force_legacy' will force it to 31 | # detect as a legacy card. 'force_modern' will force it to detect is as a modern 32 | # card. 33 | prim_d3d_legacy_detection=default 34 | 35 | [audio] 36 | 37 | # Driver can be 'default', 'openal', 'alsa', 'oss', 'pulseaudio' or 'directsound' 38 | # depending on platform. 39 | driver=default 40 | 41 | # Mixer quality can be 'linear' (default), 'cubic' (best), or 'point' (bad). 42 | # default_mixer_quality=linear 43 | 44 | # The frequency to use for the default voice/mixer. Default: 44100. 45 | # primary_voice_frequency=44100 46 | # primary_mixer_frequency=44100 47 | 48 | # Can be 'int16', otherwise defaults to float32. 49 | # primary_voice_depth=float32 50 | # primary_mixer_depth=float32 51 | 52 | [oss] 53 | 54 | # You can skip probing for OSS4 driver by setting this option to 'yes'. 55 | # Default is 'no'. 56 | force_ver3=no 57 | 58 | # When OSS3 is used, you can choose a sound device here. 59 | # Default is '/dev/dsp'. 60 | device=/dev/dsp 61 | 62 | [alsa] 63 | 64 | # Set the ALSA sound device. 65 | # Default is 'default'. 66 | device=default 67 | 68 | # Set the ALSA capture device, e.g. hw:0,0 69 | # Default is 'default'. 70 | capture_device=default 71 | 72 | [pulseaudio] 73 | 74 | # Set the buffer size (in samples) 75 | buffer_size=1024 76 | 77 | [directsound] 78 | 79 | # Set the DirectSound buffer size (in samples) 80 | buffer_size = 4096 81 | 82 | [opengl] 83 | 84 | # If you want to support old OpenGL versions, you can make Allegro 85 | # believe an older version than what you actually have is used with 86 | # this key. This is only for testing/debugging purposes. 87 | 88 | # force_opengl_version = 1.2 89 | 90 | [opengl_disabled_extensions] 91 | 92 | # Any OpenGL extensions can be listed here to make Allegro report them 93 | # as not available. The extensions used by Allegro itself if available 94 | # are shown below - uncommenting them would disable them: 95 | 96 | # GL_ARB_texture_non_power_of_two=0 97 | # GL_EXT_framebuffer_object=0 98 | 99 | [joystick] 100 | 101 | # Linux: Allegro normally searches for joystick device N at /dev/input/jsN. 102 | # You can override the device file path on a per-device basis, like this. 103 | 104 | # device0=/dev/input/by-id/usb-blahblah-joystick 105 | 106 | # Windows: You can choose between the XINPUT or DIRECTINPUT driver for 107 | # joysticks and force feedback joysticks. Xinput is the more modern 108 | # system, but DirectInput has more force feedback capabilities for older 109 | # joysticks. 110 | driver=XINPUT 111 | 112 | # Windows: Use this to force an XInput DLL version, example "3" forces 113 | # xinput1_3.dll. By default, the latest version is used. 114 | 115 | # force_xinput_version = 3 116 | 117 | [keyboard] 118 | 119 | # You can trap/untrap the mouse cursor within a window with a key combination 120 | # of your choice, e.g. "Ctrl-G", "Shift-Ctrl-G", "Ctrl-LShift", "RWin". 121 | # This feature currently only works on X11 and Windows. 122 | 123 | # toggle_mouse_grab_key = ScrollLock 124 | 125 | 126 | [trace] 127 | # Comma-separated list of channels to log. Default is "all" which 128 | # disables channel filtering. Some possible channels are: 129 | # system,display,keyboard,opengl 130 | # Channel names can be prefixed with - to exclude only those channels. 131 | # Each addon and source-file can define additional channels though so 132 | # there are more. 133 | channels=all 134 | 135 | # Log-level. Can be one of debug, info, warn, error, none or empty. 136 | # In debug builds if it is empty or unset, then the level is set to debug. 137 | # In release builds if it is empty or unset, then the level is set to none. 138 | level= 139 | 140 | # Set to 0 to disable line numbers in log files. 141 | lines=1 142 | 143 | # Set to 0 to disable timestamps in log files. 144 | timestamps=1 145 | 146 | # Set to 0 to disable function names in log files. 147 | functions=1 148 | 149 | [xkeymap] 150 | # Override X11 keycode. The below example maps X11 code 52 (Y) to Allegro 151 | # code 26 (Z) and X11 code 29 (Z) to Allegro code 25 (Y). 152 | # 52=26 153 | # 29=25 154 | 155 | 156 | [shader] 157 | # If you want to support override version of the d3dx9_xx.dll library 158 | # define this value. 159 | # By default, latest installed version is used. 160 | 161 | # force_d3dx9_version = 36 162 | 163 | [ttf] 164 | 165 | # Set these to something other than 0 to override the default page sizes for TTF 166 | # glyphs. 167 | min_page_size = 0 168 | max_page_size = 0 169 | 170 | # This entry contains characters that will be pre-catched during font loading. 171 | # cache_text = a bcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 172 | 173 | # Uncomment if you want only the characters in the cache_text entry to ever be drawn 174 | # skip_cache_misses = true 175 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro5_02_events.f: -------------------------------------------------------------------------------- 1 | decimal \ important 2 | 3 | 1 constant ALLEGRO_EVENT_JOYSTICK_AXIS 4 | 2 constant ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN 5 | 3 constant ALLEGRO_EVENT_JOYSTICK_BUTTON_UP 6 | 4 constant ALLEGRO_EVENT_JOYSTICK_CONFIGURATION 7 | 10 constant ALLEGRO_EVENT_KEY_DOWN 8 | 11 constant ALLEGRO_EVENT_KEY_CHAR 9 | 12 constant ALLEGRO_EVENT_KEY_UP 10 | 20 constant ALLEGRO_EVENT_MOUSE_AXES 11 | 21 constant ALLEGRO_EVENT_MOUSE_BUTTON_DOWN 12 | 22 constant ALLEGRO_EVENT_MOUSE_BUTTON_UP 13 | 23 constant ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY 14 | 24 constant ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY 15 | 25 constant ALLEGRO_EVENT_MOUSE_WARPED 16 | 30 constant ALLEGRO_EVENT_TIMER 17 | 40 constant ALLEGRO_EVENT_DISPLAY_EXPOSE 18 | 41 constant ALLEGRO_EVENT_DISPLAY_RESIZE 19 | 42 constant ALLEGRO_EVENT_DISPLAY_CLOSE 20 | 43 constant ALLEGRO_EVENT_DISPLAY_LOST 21 | 44 constant ALLEGRO_EVENT_DISPLAY_FOUND 22 | 45 constant ALLEGRO_EVENT_DISPLAY_SWITCH_IN 23 | 46 constant ALLEGRO_EVENT_DISPLAY_SWITCH_OUT 24 | 47 constant ALLEGRO_EVENT_DISPLAY_ORIENTATION 25 | 48 constant ALLEGRO_EVENT_DISPLAY_HALT_DRAWING 26 | 49 constant ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING 27 | 50 constant ALLEGRO_EVENT_TOUCH_BEGIN 28 | 51 constant ALLEGRO_EVENT_TOUCH_END 29 | 52 constant ALLEGRO_EVENT_TOUCH_MOVE 30 | 53 constant ALLEGRO_EVENT_TOUCH_CANCEL 31 | 60 constant ALLEGRO_EVENT_DISPLAY_CONNECTED 32 | 61 constant ALLEGRO_EVENT_DISPLAY_DISCONNECTED 33 | \ /* 34 | \ * Event structures 35 | \ * 36 | \ * All event types have the following cfields in common. 37 | \ * 38 | \ * type -- the type of event this is 39 | \ * timestamp -- when this event was generated 40 | \ * source -- which event source generated this event 41 | \ * 42 | \ * For people writing event sources: The common cfields must be at the 43 | \ * very start of each event structure, i.e. put _AL_EVENT_HEADER at the 44 | \ * front. 45 | \ */ 46 | 47 | \ #define _AL_EVENT_HEADER( srctype) 48 | 49 | 0 50 | cvar ALLEGRO_EVENT.type 51 | cvar ALLEGRO_EVENT.source 52 | 2 cells cfield ALLEGRO_EVENT.timestamp 53 | constant /ALLEGRO_ANY_EVENT 54 | 55 | /ALLEGRO_ANY_EVENT 56 | cvar ALLEGRO_DISPLAY_EVENT.x 57 | cvar ALLEGRO_DISPLAY_EVENT.y 58 | cvar ALLEGRO_DISPLAY_EVENT.width 59 | cvar ALLEGRO_DISPLAY_EVENT.height 60 | cvar ALLEGRO_DISPLAY_EVENT.orientation 61 | constant /ALLEGRO_DISPLAY_EVENT 62 | 63 | 64 | /ALLEGRO_ANY_EVENT 65 | cvar ALLEGRO_JOYSTICK_EVENT.*id 66 | cvar ALLEGRO_JOYSTICK_EVENT.stick 67 | cvar ALLEGRO_JOYSTICK_EVENT.axis 68 | cvar ALLEGRO_JOYSTICK_EVENT.pos ( float ) 69 | cvar ALLEGRO_JOYSTICK_EVENT.button 70 | constant /ALLEGRO_JOYSTICK_EVENT 71 | 72 | /ALLEGRO_ANY_EVENT 73 | cvar ALLEGRO_KEYBOARD_EVENT.display 74 | cvar ALLEGRO_KEYBOARD_EVENT.keycode /* the physical key pressed*/ 75 | cvar ALLEGRO_KEYBOARD_EVENT.unichar /* unicode character or negative*/ 76 | cvar ALLEGRO_KEYBOARD_EVENT.modifiers /* bitcfield*/ 77 | cvar ALLEGRO_KEYBOARD_EVENT.repeat /* auto-repeated or not*/ 78 | constant /ALLEGRO_KEYBOARD_EVENT 79 | 80 | 81 | /ALLEGRO_ANY_EVENT 82 | cvar ALLEGRO_MOUSE_EVENT.display 83 | \ /* ( display) Window the event originate from 84 | \ * ( x, y) Primary mouse position 85 | \ * ( z) Mouse wheel position ( 1D 'wheel'), or, 86 | \ * ( w, z) Mouse wheel position ( 2D 'ball') 87 | \ * ( pressure) The pressure applied, for stylus ( 0 or 1 for normal mouse) 88 | \ */ 89 | cvar ALLEGRO_MOUSE_EVENT.x 90 | cvar ALLEGRO_MOUSE_EVENT.y 91 | cvar ALLEGRO_MOUSE_EVENT.z 92 | cvar ALLEGRO_MOUSE_EVENT.w 93 | cvar ALLEGRO_MOUSE_EVENT.dx 94 | cvar ALLEGRO_MOUSE_EVENT.dy 95 | cvar ALLEGRO_MOUSE_EVENT.dz 96 | cvar ALLEGRO_MOUSE_EVENT.dw 97 | cvar ALLEGRO_MOUSE_EVENT.button 98 | cvar ALLEGRO_MOUSE_EVENT.pressure ( float ) 99 | constant /ALLEGRO_MOUSE_EVENT 100 | 101 | 102 | 103 | /ALLEGRO_ANY_EVENT 104 | 2 cells cfield ALLEGRO_TIMER_EVENT.count 105 | 2 cells cfield ALLEGRO_TIMER_EVENT.error \ double-float 106 | constant /ALLEGRO_TIMER_EVENT 107 | 108 | 109 | 110 | \ /* Type: ALLEGRO_USER_EVENT 111 | \ */ 112 | \ typedef struct ALLEGRO_USER_EVENT ALLEGRO_USER_EVENT 113 | \ 114 | \ struct ALLEGRO_USER_EVENT 115 | \ { 116 | \ _AL_EVENT_HEADER( struct ALLEGRO_EVENT_SOURCE) 117 | \ struct ALLEGRO_USER_EVENT_DESCRIPTOR*__internal__descr 118 | \ intptr_t data1 119 | \ intptr_t data2 120 | \ intptr_t data3 121 | \ intptr_t data4 122 | \ } 123 | 124 | 125 | 126 | /* Event sources */ 127 | 128 | \ for user events: 129 | function: al_init_user_event_source ( ALLEGRO_EVENT_SOURCE* -- ) 130 | \ function: al_destroy_user_event_source ( ALLEGRO_EVENT_SOURCE* -- ) 131 | \ /* The second argument is ALLEGRO_EVENT instead of ALLEGRO_USER_EVENT 132 | \ * to prevent users passing a pointer to a too-short structure. 133 | \ */ 134 | function: al_emit_user_event ( ALLEGRO_EVENT_SOURCE* ALLEGRO_EVENT* dtor -- ) 135 | \ function: al_unref_user_event ( ALLEGRO_USER_EVENT* -- ) 136 | \ function: al_set_event_source_data ( ALLEGRO_EVENT_SOURCE* intptr_t data -- ) 137 | \ AL_FUNC( intptr_t al_get_event_source_data ( const ALLEGRO_EVENT_SOURCE* -- ) 138 | 139 | 140 | 141 | /* Event queues */ 142 | 143 | function: al_create_event_queue ( -- ALLEGRO_EVENT_QUEUE* ) 144 | function: al_destroy_event_queue ( ALLEGRO_EVENT_QUEUE* -- ) 145 | function: al_register_event_source ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT_SOURCE* -- ) 146 | function: al_unregister_event_source ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT_SOURCE* -- ) 147 | function: al_is_event_queue_empty ( ALLEGRO_EVENT_QUEUE* -- bool ) 148 | function: al_get_next_event ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT*ret_event -- bool ) 149 | function: al_peek_next_event ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT*ret_event -- bool ) 150 | function: al_drop_next_event ( ALLEGRO_EVENT_QUEUE* -- bool ) 151 | function: al_flush_event_queue ( ALLEGRO_EVENT_QUEUE* -- ) 152 | function: al_wait_for_event ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT*ret_event -- ) 153 | \ function: al_wait_for_event_timed ( ALLEGRO_EVENT_QUEUE* ALLEGRO_EVENT*ret_event float-secs -- bool ) 154 | \ function: al_wait_for_event_until ( ALLEGRO_EVENT_QUEUE*queue ALLEGRO_EVENT*ret_event ALLEGRO_TIMEOUT*timeout -- ) 155 | 156 | 157 | function: al_acknowledge_resize ( display -- ) 158 | function: al_reset_new_display_options ( -- ) 159 | -------------------------------------------------------------------------------- /afkit/plat/sf/fixedp.f: -------------------------------------------------------------------------------- 1 | \ this module simplifies game dev by making fixed point numbers THE DEFAULT. 2 | \ the new format will be 20:12. 3 | \ (that provides a range of roughly -0.5m~0.5m with a granularity of 1/4096) 4 | \ NOTE TO SELF: this number system isn't meant to replace floats. floats should 5 | \ continue to be used where precision or wide range is needed. 6 | \ the following bits of the Forth system will be modified: 7 | \ literals will by default be interpreted as fixed point. regardless of 8 | \ if there is a decimal point. 9 | \ to specify integer literals, suffix with #. 10 | \ a new "base" for display will be added ( FIXED ) which 11 | \ will affect .s . ? and friends 12 | \ the following words will be redefined or otherwise altered 13 | \ * / /mod .s . ? 14 | \ ++ -- 15 | \ loop 16 | \ the following words will remain untouched 17 | \ + - mod 18 | \ "compiler oriented words": cells allot /allot erase move fill 19 | \ the following words will use prefixes to avoid collision with float words 20 | \ pfloor pceil 21 | \ additional words for conversion to other formats 22 | \ 1i 2i 3i 4i 23 | \ 1pf 2pf 24 | \ stack diagrams 25 | \ n = fixed-point 26 | \ i = integer 27 | 28 | [in-platform] sf [if] 29 | requires fpmath 30 | [then] 31 | 32 | only forth definitions 33 | 34 | [undefined] s[ [if] 35 | create $buffers 16384 allot \ string concatenation buffer stack (circular) 36 | variable >s \ pointer into $buffers 37 | : s[ ( adr c - ) >s @ 256 + 16383 and >s ! >s @ $buffers + place ; 38 | : +s ( adr c - ) >s @ $buffers + append ; 39 | : c+s ( c - ) >s @ $buffers + count + c! 1 >s @ $buffers + c+! ; 40 | create $outbufs 16384 allot \ output buffers; circular stack of buffers 41 | variable >out 42 | : ]s ( - adr c ) \ fetch finished string 43 | >s @ $buffers + count >out @ $outbufs + place 44 | >out @ $outbufs + count 45 | >out @ 256 + 16383 and >out ! 46 | >s @ 256 - 16383 and >s ! ; 47 | [then] 48 | 49 | only forth definitions 50 | 12 constant /FRAC 51 | $FFFFF000 constant INT_MASK 52 | $00000FFF constant FRAC_MASK 53 | \ 4096e fconstant FPRES 54 | \ #define FPRES 4096e 55 | : FPRES s" 4096e" evaluate ; immediate 56 | 4096 constant PGRAN 57 | $1000 constant 1.0 58 | 1.0 negate constant -1.0 59 | variable ints ints on \ set/disable integer mode on both display and interpretation 60 | 61 | wordlist constant fixpointing 62 | 63 | \ private 64 | 65 | : ?: >in @ exists if 0 parse 2drop drop exit else >in ! : then ; 66 | 67 | ?: 1p state @ if /frac postpone literal postpone lshift else /frac lshift then ; immediate 68 | ?: 1i state @ if 1.0 postpone literal postpone / else 1.0 / then ; immediate 69 | 70 | ?: 2p 1p swap 1p swap ; 71 | ?: 2i swap 1i swap 1i ; 72 | ?: 3i rot 1i rot 1i rot 1i ; 73 | ?: 4i 2i 2swap 2i 2swap ; 74 | ?: 1pf s>f FPRES f/ ; 75 | ?: 2pf swap 1pf 1pf ; 76 | ?: pfloor INT_MASK and ; 77 | ?: pceil pfloor 1.0 + ; 78 | ?: 2pfloor pfloor swap pfloor swap ; 79 | ?: 2pceil pceil swap pceil swap ; 80 | ?: f>p FPRES f* f>s ; 81 | ?: p* 1pf s>f f* f>s ; 82 | ?: p/ swap s>f 1pf f/ f>s ; 83 | ?: i. base @ >r decimal . r> base ! ; 84 | ?: i? @ i. ; 85 | ?: p. 1pf f. ; 86 | 87 | fixpointing +order definitions 88 | : * ( n n - n ) p* ; 89 | : / ( n n - n ) p/ ; 90 | : /mod ( n n - r q ) 2dup mod -rot p/ pfloor ; 91 | : 2* rot p* >r p* r> ; 92 | : 2/ rot swap p/ >r p/ r> ; 93 | : . ints @ if i. else p. then ; 94 | : ? @ . ; 95 | : 2. swap . . ; 96 | : 3. rot . 2. ; 97 | : 2? dup ? cell+ ? ; 98 | : 3? dup ? cell+ dup ? cell+ ? ; 99 | 100 | \ --------------------------- swiftforth-specific ----------------------------- 101 | only forth definitions 102 | \ extend literals to support fixed-point 103 | variable sign 104 | : pconvert ( a - 0 | a -1 ) ( - | r ) 105 | ( a c f) drop [char] - = sign ! 106 | ( a d n) 0= if 2drop drop 0 exit then d>f 107 | ( a c f) 0= if fdrop 2drop 0 exit then drop 108 | ( a d n) -rot d>f t10** f/ f+ 109 | sign @ if fnegate then 110 | \ ( a c f) if fdrop 2drop 0 exit then drop 111 | -1 ; 112 | 113 | : >pfloat ( caddr n - true | false ) ( - r ) 114 | r-buf r@ zplace 115 | r@ pconvert ( 0 | a\f ) if 116 | r> zcount + = dup ?exit fdrop exit 117 | then r> drop 0 ; 118 | 119 | : pnumber? ( addr len 0 | p.. xt - addr len 0 | p.. xt ) 120 | dup ?exit drop 121 | 2dup >pfloat if 122 | 2drop 123 | FPRES f* (f>s) ['] literal 124 | exit 125 | then 126 | 0 ; 127 | 128 | \ decimal-point-less conversion 129 | : pnumber2? ( addr len 0 | ... xt - addr len 0 | ... xt ) 130 | dup ?exit drop 131 | base @ 10 = ints @ 0 = and if 132 | 2dup 133 | number? 1 = if 134 | nip nip /FRAC lshift ['] literal 135 | exit 136 | then 137 | then 0 ; 138 | 139 | fixpointing +order definitions 140 | \ : .S ( ? - ? ) 141 | \ CR DEPTH 0> IF DEPTH 0 ?DO S0 @ I 1+ CELLS - @ . LOOP THEN 142 | \ DEPTH 0< ABORT" Underflow" 143 | \ FDEPTH ?DUP IF 144 | \ ." FSTACK: " 145 | \ 0 DO I' I - 1- FPICK N. LOOP 146 | \ THEN ; 147 | 148 | \ -------- Add fixed-point interpreter to SwiftForth ------- 149 | only forth definitions fixpointing +order 150 | 151 | PACKAGE STATUS-TOOLS 152 | public 153 | [undefined] linux [if] 154 | : SB.BASE2 ( - ) 155 | ints @ 0 = if 156 | s" FIX" 157 | else 158 | BASE @ PSTK (.BASE) 159 | then 160 | 1 SF-STATUS PANE-TYPE ; 161 | : SB.STACK2 ( - ) 162 | ints @ if 163 | PSTK Z(.S) ZCOUNT s[ 164 | else 165 | s" " s[ 166 | DEPTH 0 >= IF 167 | DEPTH 0 ?DO 168 | S0 @ I 1 + CELLS - @ 169 | dup 0 < if s" " +s then 170 | 1pf 3 (f.) +s 171 | LOOP 172 | ELSE 173 | s" Underflow" +s 174 | THEN 175 | then 176 | FDEPTH ?DUP IF 177 | s" FSTACK:" +s 178 | 0 DO I' I - 1 - FPICK 3 (f.) +s LOOP 179 | THEN 180 | ]s 0 SF-STATUS PANE-RIGHT ; 181 | 182 | : STATUS.STACK2 ( - ) SB.BASE2 SB.STACK2 ; 183 | 184 | ' status.stack2 is .stack 185 | [then] \ not linux 186 | 187 | ' pnumber2? number-conversion >chain 188 | ' pnumber? number-conversion >chain 189 | 190 | END-PACKAGE 191 | 192 | \ ------------------------------------------------------------ 193 | only forth fixpointing +order definitions 194 | : cells 1i #2 lshift ; 195 | : cell/ #2 rshift 1p ; 196 | : bytes 1i ; 197 | : loop s" 1.0 +loop" evaluate ; immediate 198 | : << 1i lshift ; 199 | : >> 1i rshift ; 200 | : .0 ; immediate 201 | : ifill swap 1i swap ifill ; 202 | : ierase 0 ifill ; 203 | : imove 1i imove ; 204 | : kbytes 1i #1024 i* ; 205 | : megs 1i #1048576 i* ; 206 | : ++ 1.0 swap +! ; 207 | : -- -1.0 swap +! ; 208 | : reverse ( ... count - ... ) 1 + 1 ?do i 1 - 1i roll loop ; 209 | 210 | only forth definitions fixpointing +order 211 | : fixed fixpointing +order ints off #10 base ! ; 212 | : decimal fixpointing -order ints on #10 base ! ; 213 | : hex fixpointing -order ints on hex ; 214 | : include ints @ >r fixed include r> ?exit fixed ; 215 | : included ints @ >r fixed included r> ?exit fixed ; 216 | : (only) only execute ints @ ?exit fixpointing +order ; 217 | : only 218 | state @ if postpone ['] postpone (only) 219 | else ' (only) then ; immediate 220 | 221 | 222 | : definitions 223 | get-order over fixpointing = if fixpointing -order definitions fixpointing +order 224 | else definitions then set-order ; 225 | 226 | : using only forth definitions also ; 227 | 228 | 229 | fixed 230 | -------------------------------------------------------------------------------- /afkit/piston.f: -------------------------------------------------------------------------------- 1 | \ Universal main loop, simple version; no fixed point 2 | \ It just processes events and spits out frames, no timer, no frameskipping. 3 | \ The previous version tried to have frameskipping and framepacing, but it became choppy after 4 | \ an hour or two running and I couldn't figure out the cause. 5 | \ The loop has some common controls: 6 | \ ALT-F12 - break the loop 7 | \ ALT-F4 - quit the process 8 | 9 | \ Values 10 | 0 value now \ in frames ( read-only ) 11 | 0 value showerr 12 | 0 value steperr 13 | 0 value pumperr 14 | 0 value alt? \ part of fix for alt-enter bug when game doesn't have focus 15 | 0 value ctrl? 16 | 0 value shift? 17 | 0 value breaking? 18 | 0 value 'pump 19 | 0 value 'step 20 | 0 value 'show 21 | 0 value me \ for Ramen 22 | 0 value offsetTable 23 | 24 | \ Mouse 25 | create mouse 0 , 0 , 26 | create (mouse) 0 , 0 , 27 | create mickey 0 , 0 , 28 | 29 | \ Flags 30 | variable eco \ enable to save CPU (for repl/editors etc) 31 | variable oscursor oscursor on \ turn off to hide the OS's mouse cursor 32 | variable repl \ <>0 = repl active/visible 33 | 34 | \ Defers 35 | defer ?overlay ' noop is ?overlay \ render ide ( - ) 36 | defer ?system ' noop is ?system \ system events ( - ) 37 | defer repl? :noname 0 ; is repl? 38 | 39 | \ Event stuff 40 | create evt 256 /allot 41 | : etype ( - ALLEGRO_EVENT_TYPE ) evt ALLEGRO_EVENT.TYPE @ ; 42 | 43 | : !mickey (mouse) 2@ mickey 2! mouse 2@ (mouse) 2! ; 44 | : poll ( - ) pollKB pollJoys !mickey ; 45 | : break ( - ) true to breaking? ; 46 | 47 | defer bye 48 | 49 | :make bye al_uninstall_system 0 ExitProcess ; 50 | 51 | define internal 52 | transform: m1 53 | variable clipx 54 | variable clipy 55 | variable clipw 56 | variable cliph 57 | 58 | 59 | using internal 60 | : clip ( x y w h - ) 61 | #globalscale * s>f cliph sf! 62 | #globalscale * s>f clipw sf! 63 | s>f clipy sf! 64 | s>f clipx sf! 65 | m1 clipx clipy al_transform_coordinates 66 | clipx sf@ f>s 67 | clipy sf@ f>s 68 | clipw sf@ f>s 69 | cliph sf@ f>s al_set_clipping_rectangle 70 | ; 71 | 72 | : mountw ( - n ) res x@ #globalscale * ; 73 | : mounth ( - n ) res y@ #globalscale * ; 74 | : mountwh ( - w h ) mountw mounth ; 75 | 76 | : mountx ( - n ) displayw 2 / mountw 2 / - ; 77 | : mounty ( - n ) repl @ if 0 else displayh 2 / mounth 2 / - then ; 78 | : mountxy ( - x y ) mountx mounty ; 79 | 80 | 81 | : mount ( - ) 82 | m1 al_identity_transform 83 | m1 #globalscale s>f 1sf dup al_scale_transform 84 | fs @ if 85 | m1 mountxy swap s>f s>f 2sf al_translate_transform 86 | then 87 | \ m1 0.625e 0.625e 2sf al_translate_transform 88 | m1 al_use_transform 89 | 90 | 0 0 res xy@ clip 91 | 92 | ALLEGRO_ADD ALLEGRO_ALPHA ALLEGRO_INVERSE_ALPHA 93 | ALLEGRO_ADD ALLEGRO_ONE ALLEGRO_ONE 94 | al_set_separate_blender 95 | 96 | ; 97 | : unmount ( - ) 98 | m1 al_identity_transform 99 | \ m1 0.625e 0.625e 2sf al_translate_transform 100 | m1 al_use_transform 101 | 0 0 displaywh clip 102 | ALLEGRO_ADD ALLEGRO_ALPHA ALLEGRO_INVERSE_ALPHA 103 | ALLEGRO_ADD ALLEGRO_ONE ALLEGRO_ONE 104 | al_set_separate_blender 105 | ; 106 | 107 | variable (catch) 108 | : try ( code - IOR ) 109 | dup -exit 110 | [defined] dev [if] 111 | sp@ cell+ >r code> catch (catch) ! r> sp! 112 | (catch) @ 113 | [else] 114 | call 0 115 | [then] ; 116 | 117 | : suspend ( - ) 118 | begin 119 | eventq evt al_wait_for_event 120 | etype ALLEGRO_EVENT_DISPLAY_SWITCH_IN = if 121 | clearkb false to alt? 122 | exit 123 | then 124 | again 125 | ; 126 | 127 | : standard-events ( - ) 128 | etype ALLEGRO_EVENT_DISPLAY_RESIZE = if display al_acknowledge_resize ;then 129 | etype ALLEGRO_EVENT_DISPLAY_CLOSE = if bye ;then 130 | [defined] dev [if] etype ALLEGRO_EVENT_DISPLAY_SWITCH_OUT = if suspend ;then [then] 131 | 132 | \ still needed in published games, don't remove 133 | etype ALLEGRO_EVENT_DISPLAY_SWITCH_IN = if 134 | clearkb false to alt? 135 | ;then 136 | 137 | etype ALLEGRO_EVENT_KEY_DOWN = if 138 | evt ALLEGRO_KEYBOARD_EVENT.keycode @ case 139 | of true to alt? endof 140 | of true to alt? endof 141 | of true to ctrl? endof 142 | of true to ctrl? endof 143 | of true to shift? endof 144 | of true to shift? endof 145 | of alt? -exit bye endof 146 | of alt? -exit break endof 147 | endcase 148 | ;then 149 | etype ALLEGRO_EVENT_KEY_UP = if 150 | evt ALLEGRO_KEYBOARD_EVENT.keycode @ case 151 | of false to alt? endof 152 | of false to alt? endof 153 | of false to ctrl? endof 154 | of false to ctrl? endof 155 | of false to shift? endof 156 | of false to shift? endof 157 | endcase 158 | ;then 159 | ; 160 | 161 | : al-emit-user-event ( type - ) \ EVT is expected to be filled, except for the type 162 | evt ALLEGRO_EVENT.type ! uesrc evt 0 al_emit_user_event ; 163 | 164 | : ?hidemouse ( - ) 165 | display oscursor @ if al_show_mouse_cursor else al_hide_mouse_cursor then ; 166 | 167 | : 2s>f ( ix iy - f: x y ) swap s>f s>f ; 168 | : refit ( - ) \ find biggest integer scaling that fits display 169 | displaywh 2s>f f/ 170 | res xy@ 2s>f f/ f> if 171 | displayh res y@ / 172 | else 173 | displayw res x@ / 174 | then 175 | to #globalscale 176 | ; 177 | 178 | : onto ( bmp - ) dup display = if al_get_backbuffer then al_set_target_bitmap ; 179 | : ?greybg ( - ) display onto unmount 0.1e 0.1e 0.1e 1e 4sf al_clear_to_color ; 180 | : show ( - ) 181 | refit 182 | at@ 2>r 183 | me >r offsetTable >r 184 | ?greybg mount display onto 185 | 'show try to showerr 186 | unmount display onto ?overlay 187 | r> to offsetTable r> to me 188 | 2r> at ; 189 | : present ( - ) al_flip_display ; 190 | : ?suppress ( - ) repl? if clearkb then ; 191 | : step ( - ) 192 | me >r offsetTable >r at@ 2>r 193 | ?suppress 'step try to steperr 1 +to now 194 | 2r> at r> to offsetTable r> to me ; 195 | : pump ( - ) repl? ?exit 'pump try to pumperr ; 196 | 197 | : /go ( - ) resetkb false to breaking? >display false to alt? false to ctrl? false to shift? ; 198 | : go/ ( - ) eventq al_flush_event_queue >host false to breaking? ; 199 | : show> ( - ) r> to 'show ; ( - ) ( - ) 200 | : step> ( - ) r> to 'step ; ( - ) ( - ) 201 | : pump> ( - ) r> to 'pump ; ( - ) ( - ) 202 | : get-next-event ( - ) eco @ if al_wait_for_event #1 else al_get_next_event then ; 203 | : @event ( - flag ) eventq evt get-next-event ; 204 | : attend ( - ) 205 | begin @event breaking? not and while 206 | me >r offsetTable >r pump standard-events r> to offsetTable r> to me 207 | ?system 208 | eco @ ?exit 209 | repeat ; 210 | : frame ( - ) show present attend poll step ?hidemouse ; 211 | : go ( - ) /go begin frame breaking? until go/ ; 212 | 213 | \ default demo: dark blue screen with bouncing white square 214 | define internal 215 | variable x variable vx 1 vx ! 216 | variable y variable vy 1 vy ! 217 | :noname 218 | show> 219 | 0e 0e 0.5e 1e 4sf al_clear_to_color 220 | x @ y @ over 50 + over 50 + 4s>f 4sf 1e 1e 1e 1e 4sf al_draw_filled_rectangle 221 | vx @ x +! vy @ y +! 222 | vx @ 0< if x @ 0 < if vx @ negate vx ! then then 223 | vy @ 0< if y @ 0 < if vy @ negate vy ! then then 224 | vx @ 0> if x @ res x@ 50 - >= if vx @ negate vx ! then then 225 | vy @ 0> if y @ res y@ 50 - >= if vy @ negate vy ! then then 226 | ; execute 227 | only forth definitions 228 | -------------------------------------------------------------------------------- /venery/venery.f: -------------------------------------------------------------------------------- 1 | ( --- Collections. --- ) 2 | 3 | \ VECTORED COMMANDS: 4 | \ [] ( i collection -- adr ) 5 | \ Get the address at index i. Address may be the address of a value, or in the case 6 | \ of nodetrees, a node. 7 | \ TRUNCATE ( newlength collection -- ) 8 | \ Sets collection to a specific length and deletes the remainder. 9 | \ PUSH ( val collection -- ) 10 | \ Add val to end of collection. 11 | \ POP ( collection -- val ) 12 | \ Fetch vel from end of collection and remove it. 13 | \ EACH ( xt collection -- ) ( val -- ) 14 | \ Itterate over all the items in a collection. Val in the case of nodetrees will be a node. 15 | \ DELETES ( index count collection -- ) 16 | \ Delete range from a collection. 17 | \ .EACH ( collection -- ) 18 | \ Print the contents of a collection. 19 | \ REMOVE ( val collection -- ) 20 | \ Removes all the instances of val from a collection. 21 | \ ?@ ( adr collection -- val ) 22 | \ Fetches val from item adr in a collection. (No-op on nodes.) 23 | \ REMOVEAT ( i collection -- ) 24 | \ Removes the value at index i. (Does not delete in the case of nodes.) 25 | \ INSERT ( val i dest-collection -- ) 26 | \ Inserts a value at index i. 27 | \ For example inserting at index 0 makes it the first item and shifts all other items up by 1 index. 28 | 29 | \ GENERIC COMMANDS: 30 | \ LENGTH ( collection -- n ) 31 | \ Get the current length of a collection. 32 | \ INBOUNDS? ( n collection -- flag ) 33 | \ Check if an index is under the current length. 34 | \ CAPACITY ( collection -- n ) 35 | \ Get the total capacity of a collection. (Can be different from its length.) 36 | \ VACATE ( collection -- ) 37 | \ Deletes all items from a collection. 38 | \ >TOP ( collection -- adr ) \ pronounced "to-top" 39 | \ Get the address of the topmost item of a collection. (Index length - 1) 40 | \ PUSHES ( ... n collection - ) 41 | \ Push several items from the stack to a collection. 42 | \ POPS ( n collection - ... ) 43 | \ Pop several items from a collection onto the stack. 44 | \ EACH> ( collection -- ) \ pronounced "each-ket" 45 | \ DOES> style EACH. 46 | \ SOME ( xt filter-xt collection -- ) ( val -- ) ( val -- flag ) 47 | \ Iterate on items satisfying the filter. 48 | \ SOME> ( filter-xt collection -- ) ( val -- flag ) \ pronounced "some-ket" 49 | \ DOES> style SOME. 50 | \ []@ ( i collection -- val ) \ pronounced "brackets-fetch" 51 | \ Fetch item from collection at given index i. 52 | \ GATHER ( src-collection dest-collection -- ) 53 | \ Pushes all the items from one collection to another. 54 | \ COPY ( src-collection dest-collection -- ) 55 | \ Same as gather but vacates the destination collection. 56 | \ UNSERT ( i collection -- val ) 57 | \ Reverse of INSERT; extracts a value/node from a collection at given index i. 58 | \ WHICH ( i xt collection -- i | -1 ) ( val -- flag ) 59 | \ Returns first index of item that satisfies given test xt. 60 | \ If it's not found, it returns -1. 61 | \ INDEXOF ( index val collection -- index ) 62 | \ Get the index of the first instance of val, starting the search at given index. 63 | 64 | \ TODO: (generics) 65 | \ DIFF ( filter-xt src-collection dest-collection -- ) ( adr -- flag ) 66 | 67 | \ Other TODO: 68 | \ SPLICE ( src-collection start-i length dest-i dest-collection -- ) \ collections must be the same type 69 | \ dynamic collection allocation support 70 | \ GRAFT ( src-node dest-node -- ) \ efficiently move children of one node (collection?) to another 71 | \ DONE / ENOUGH / ??? Break from itteration. 72 | 73 | defer new-node ( -- node ) 74 | defer free-node ( node -- ) 75 | 76 | 77 | vocabulary venery 78 | : venery:internal only forth also venery definitions ; 79 | : venery:public only forth definitions also venery ; 80 | 81 | venery:internal 82 | 0 value xt 83 | 0 value xt2 84 | 0 value filter 85 | : /allot here over allot swap erase ; 86 | : bounds over + swap ; 87 | : ?move dup if move else drop drop drop then ; 88 | : sfield ( struct bytes - ) ( adr - adr+n ) 89 | create over @ , swap +! does> @ + ; 90 | : svar cell sfield ; 91 | : struct variable ; 92 | : sembed @ sfield ; 93 | : *struct here swap @ /allot ; 94 | : sizeof @ ; 95 | [undefined] bytes [if] : bytes ; [then] 96 | 97 | venery:public 98 | struct %collection 99 | %collection svar collection.class \ for compatibility with Super Objects 100 | %collection svar collection.vtable 101 | %collection svar collection.length 102 | %collection svar collection.capacity 103 | %collection svar collection.dynamic 104 | venery:internal 105 | 106 | : vector ( n - n+1 ) ( ??? collection - ??? ) 107 | create dup cells , 1 + 108 | does> @ over collection.vtable @ + @ execute ; 109 | 110 | : vtable ( n - collection 0 ) 111 | create here swap cells /allot 0 ; 112 | 113 | : :vector ( collection ofs - ; collection ofs+cell ) 114 | 2dup :noname -rot cells + ! 1 + ; 115 | 116 | venery:public 117 | 118 | 0 119 | vector [] ( i collection -- adr ) \ pronounced "brackets" 120 | vector truncate ( newlength collection -- ) 121 | vector push ( val collection -- ) 122 | vector pop ( collection -- val ) 123 | vector each ( xt collection -- ) ( val -- ) 124 | vector deletes ( index count collection -- ) 125 | vector .each ( collection -- ) 126 | vector remove ( val collection -- ) 127 | vector ?@ ( adr collection -- val ) \ pronounced "question-fetch" or "q-fetch" 128 | vector removeat ( i collection -- ) 129 | vector insert ( val i dest-collection -- ) 130 | constant collection-vtable-size 131 | 132 | : length ( collection -- n ) 133 | collection.length @ ; 134 | 135 | : inbounds? ( n collection -- flag ) 136 | length < ; 137 | 138 | : capacity ( collection -- n ) 139 | collection.capacity @ ; 140 | 141 | : vacate ( collection -- ) 142 | 0 swap truncate ; 143 | 144 | : >top ( collection -- adr ) 145 | dup length 1 - swap [] ; 146 | 147 | : pushes ( ... n collection - ) 148 | locals| s | 0 ?do s push loop ; 149 | 150 | : pops ( n collection - ... ) 151 | locals| s | 0 ?do s pop loop ; 152 | 153 | : each> ( collection -- ) ( val -- ) 154 | dup 0= if drop r> drop exit then 155 | r> code> swap each ; 156 | 157 | : (some) dup >r filter execute if r> xt2 execute else r> drop then ; 158 | : some ( xt filter-xt collection -- ) ( val -- ) ( val -- flag ) 159 | dup 0= if drop r> 3drop exit then 160 | xt2 >r -rot filter >r to filter to xt2 161 | ['] (some) swap each 162 | r> to xt2 r> to filter 163 | ; 164 | 165 | : some> ( filter-xt collection -- ) ( val -- flag ) ( val -- ) 166 | r> code> -rot some ; 167 | 168 | : []@ ( i collection -- val ) 169 | dup >r [] r> ?@ ; 170 | 171 | : gather ( src-collection dest-collection -- ) 172 | locals| b a | 173 | a length b length + b capacity > abort" Error in GATHER: Destination collection is too small." 174 | a length 0 do i a []@ b push loop ; 175 | 176 | : copy ( src-collection dest-collection -- ) 177 | dup vacate gather ; 178 | 179 | : more? ( collection n -- flag ) \ checks if out of space or empty after n items added/subtracted 180 | swap dup >r length + dup 0 < swap r> capacity > or ; 181 | 182 | : unsert ( i collection -- val ) 183 | locals| a i | 184 | a -1 more? abort" Error in UNSERT: Collection is empty." 185 | i a []@ 186 | i a removeat 187 | ; 188 | 189 | : which ( i test-xt collection -- i | -1 ) ( val -- flag ) 190 | xt >r swap to xt 191 | dup length rot do 192 | i swap >r r@ []@ xt execute if 193 | r> drop i unloop r> to xt exit 194 | then 195 | r> loop 196 | drop r> to xt 197 | -1 198 | ; 199 | 200 | : which@ ( i test-xt collection -- val | 0 ) ( val -- flag ) 201 | dup >r which dup -1 = if drop r> drop 0 exit then 202 | r> []@ 203 | ; 204 | 205 | : indexof ( index val collection -- index | -1 ) 206 | locals| c itm | 207 | begin dup c inbounds? while 208 | dup c []@ itm = ?exit 209 | 1 + 210 | repeat 211 | drop -1 ; 212 | 213 | : pushes ( ... n collection - ) 214 | locals| c | 0 ?do c push loop ; 215 | 216 | : pops ( n collection - ... ) 217 | locals| c | 0 ?do c pop loop ; 218 | 219 | : each@ ( collection - ... ) 220 | each> noop ; 221 | 222 | : venery:sizeof ( collection - size ) 223 | sizeof ; 224 | 225 | 226 | include venery/array.f 227 | include venery/string.f 228 | include venery/nodetree.f 229 | 230 | only forth definitions 231 | -------------------------------------------------------------------------------- /afkit/dep/allegro5/allegro5_04_audio.f: -------------------------------------------------------------------------------- 1 | linux-library liballegro_acodec 2 | 3 | decimal \ important 4 | 5 | \ addon: codec 6 | function: al_init_acodec_addon ( -- bool ) 7 | function: al_get_allegro_acodec_version ( -- n ) 8 | 9 | \ addon: audio 10 | #define ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT 513 11 | #define ALLEGRO_EVENT_AUDIO_STREAM_FINISHED 514 12 | 13 | \ /* Sample depth and type, and signedness. Mixers only use 32-bit signed 14 | \ * float (-1..+1). The unsigned value is a bit-flag applied to the depth 15 | \ * value. 16 | \ */ 17 | #define ALLEGRO_AUDIO_DEPTH_INT8 $00 18 | #define ALLEGRO_AUDIO_DEPTH_INT16 $01 19 | #define ALLEGRO_AUDIO_DEPTH_INT24 $02 20 | #define ALLEGRO_AUDIO_DEPTH_FLOAT32 $03 21 | #define ALLEGRO_AUDIO_DEPTH_UNSIGNED $08 22 | ALLEGRO_AUDIO_DEPTH_INT8 ALLEGRO_AUDIO_DEPTH_UNSIGNED or constant ALLEGRO_AUDIO_DEPTH_UINT8 23 | ALLEGRO_AUDIO_DEPTH_INT16 ALLEGRO_AUDIO_DEPTH_UNSIGNED or constant ALLEGRO_AUDIO_DEPTH_UINT16 24 | ALLEGRO_AUDIO_DEPTH_INT24 ALLEGRO_AUDIO_DEPTH_UNSIGNED or constant ALLEGRO_AUDIO_DEPTH_UINT24 25 | 26 | #define ALLEGRO_PLAYMODE_ONCE $100 27 | #define ALLEGRO_PLAYMODE_LOOP $101 28 | #define ALLEGRO_PLAYMODE_BIDIR $102 29 | #define _ALLEGRO_PLAYMODE_STREAM_ONCE $103 \ /* internal-*/ 30 | #define _ALLEGRO_PLAYMODE_STREAM_ONEDIR $104 \ /* internal-*/ 31 | 32 | #define ALLEGRO_MIXER_QUALITY_POINT $110 33 | #define ALLEGRO_MIXER_QUALITY_LINEAR $111 34 | #define ALLEGRO_MIXER_QUALITY_CUBIC $112 35 | 36 | #fdefine ALLEGRO_AUDIO_PAN_NONE -1000.0e 37 | 38 | #define ALLEGRO_CHANNEL_CONF_1 $10 39 | #define ALLEGRO_CHANNEL_CONF_2 $20 40 | #define ALLEGRO_CHANNEL_CONF_3 $30 41 | #define ALLEGRO_CHANNEL_CONF_4 $40 42 | #define ALLEGRO_CHANNEL_CONF_5_1 $51 43 | #define ALLEGRO_CHANNEL_CONF_6_1 $61 44 | #define ALLEGRO_CHANNEL_CONF_7_1 $71 45 | 46 | \ general 47 | function: al_reserve_samples ( int-reserve_samples -- bool ) 48 | function: al_install_audio ( -- bool ) 49 | function: al_uninstall_audio ( -- ) 50 | function: al_play_sample ( ALLEGRO_SAMPLE-*data, float-gain, float-pan, float-speed, ALLEGRO_PLAYMODE-loop, ALLEGRO_SAMPLE_ID-*ret_id -- ) 51 | function: al_stop_sample ( ALLEGRO_SAMPLE_ID-*spl_id -- ) 52 | function: al_stop_samples ( -- ) 53 | function: al_destroy_sample ( sample -- ) 54 | function: al_load_sample ( const-char-*filename -- ALLEGRO_SAMPLE ) 55 | function: al_load_audio_stream ( const-char-*filename, size_t-buffer_count, unsigned-int-samples -- ALLEGRO_AUDIO_STREAM ) 56 | function: al_save_sample ( const-char-*filename, ALLEGRO_SAMPLE-*spl -- bool ) 57 | 58 | \ stream 59 | function: al_create_audio_stream ( size_t-buffer_count, unsigned-int-samples, unsigned-int-freq, ALLEGRO_AUDIO_DEPTH-depth, ALLEGRO_CHANNEL_CONF-chan_conf -- ALLEGRO_AUDIO_STREAM ) 60 | function: al_destroy_audio_stream ( ALLEGRO_AUDIO_STREAM-*stream -- ) 61 | function: al_drain_audio_stream ( ALLEGRO_AUDIO_STREAM-*stream -- ) 62 | 63 | \ function: unsigned-int, al_get_audio_stream_frequency ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 64 | \ function: unsigned-int, al_get_audio_stream_length ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 65 | \ function: unsigned-int, al_get_audio_stream_fragments ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 66 | \ function: unsigned-int, al_get_available_audio_stream_fragments ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 67 | 68 | \ function: float, al_get_audio_stream_speed ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 69 | \ function: float, al_get_audio_stream_gain ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 70 | \ function: float, al_get_audio_stream_pan ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 71 | 72 | \ function: ALLEGRO_CHANNEL_CONF, al_get_audio_stream_channels ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 73 | \ function: ALLEGRO_AUDIO_DEPTH, al_get_audio_stream_depth ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 74 | \ function: ALLEGRO_PLAYMODE, al_get_audio_stream_playmode ( const-ALLEGRO_AUDIO_STREAM-*stream -- ) 75 | 76 | function: al_get_audio_stream_playing ( stream -- bool ) 77 | \ function: al_get_audio_stream_attached ( const-ALLEGRO_AUDIO_STREAM-*spl -- ) 78 | 79 | function: al_get_audio_stream_fragment ( const-ALLEGRO_AUDIO_STREAM-*stream -- addr ) 80 | 81 | function: al_set_audio_stream_speed ( ALLEGRO_AUDIO_STREAM-*stream, float-val -- bool ) 82 | function: al_set_audio_stream_gain ( ALLEGRO_AUDIO_STREAM-*stream, float-val -- bool ) 83 | function: al_set_audio_stream_pan ( ALLEGRO_AUDIO_STREAM-*stream, float-val -- bool ) 84 | 85 | function: al_set_audio_stream_playmode ( ALLEGRO_AUDIO_STREAM-*stream, ALLEGRO_PLAYMODE-val -- bool ) 86 | function: al_set_audio_stream_playing ( ALLEGRO_AUDIO_STREAM-*stream, bool-val -- bool ) 87 | \ function: al_detach_audio_stream ( ALLEGRO_AUDIO_STREAM-*stream -- bool ) 88 | function: al_set_audio_stream_fragment ( ALLEGRO_AUDIO_STREAM-*stream,-*val -- bool ) 89 | 90 | function: al_rewind_audio_stream ( ALLEGRO_AUDIO_STREAM-*stream -- bool ) 91 | function: al_seek_audio_stream_secs ( ALLEGRO_AUDIO_STREAM-*stream, double time -- bool ) 92 | function: al_get_audio_stream_position_secs ( ALLEGRO_AUDIO_STREAM-*stream -- n ) 93 | function: al_get_audio_stream_length_secs ( ALLEGRO_AUDIO_STREAM-*stream -- n ) 94 | function: al_set_audio_stream_loop_secs ( ALLEGRO_AUDIO_STREAM-*stream, double start, double end -- bool ) 95 | \ function: al_get_audio_stream_event_source ( ALLEGRO_AUDIO_STREAM-*stream -- ALLEGRO_EVENT_SOURCE-* ) 96 | 97 | 98 | 99 | 100 | 101 | \ sample instance 102 | 103 | function: al_create_sample_instance ( sample -- instance ) 104 | function: al_destroy_sample_instance ( instance -- ) 105 | function: al_get_sample_instance_position ( sample -- n ) 106 | function: al_set_sample ( sample data -- bool ) 107 | function: al_get_sample_frequency ( sample -- n ) 108 | 109 | function: al_set_sample_instance_position ( ALLEGRO_SAMPLE_INSTANCE-*spl, unsigned-int-val -- bool ) 110 | function: al_set_sample_instance_length ( ALLEGRO_SAMPLE_INSTANCE-*spl, unsigned-int-val -- bool ) 111 | function: al_get_sample_instance_length ( ALLEGRO_SAMPLE_INSTANCE-*spl -- int ) 112 | 113 | function: al_set_sample_instance_speed ( ALLEGRO_SAMPLE_INSTANCE-*spl, float-val -- bool ) 114 | function: al_set_sample_instance_gain ( ALLEGRO_SAMPLE_INSTANCE-*spl, float-val -- bool ) 115 | function: al_set_sample_instance_pan ( ALLEGRO_SAMPLE_INSTANCE-*spl, float-val -- bool ) 116 | function: al_set_sample_instance_playmode ( ALLEGRO_SAMPLE_INSTANCE-*spl, ALLEGRO_PLAYMODE-val -- bool ) 117 | function: al_set_sample_instance_playing ( ALLEGRO_SAMPLE_INSTANCE-*spl, bool-val -- bool ) 118 | function: al_get_sample_instance_playing ( ALLEGRO_SAMPLE_INSTANCE-*spl, -- bool ) 119 | function: al_play_sample_instance ( ALLEGRO_SAMPLE_INSTANCE-*spl -- bool ) 120 | function: al_stop_sample_instance ( ALLEGRO_SAMPLE_INSTANCE-*spl -- bool ) 121 | function: al_get_sample_instance_frequency ( const-ALLEGRO_SAMPLE_INSTANCE-*spl -- int ) 122 | 123 | 124 | \ mixer 125 | function: al_get_default_mixer ( -- mixer ) 126 | function: al_set_default_mixer ( mixer -- bool ) 127 | function: al_restore_default_mixer ( -- ) 128 | 129 | function: al_create_mixer ( unsigned-int-freq, ALLEGRO_AUDIO_DEPTH-depth, ALLEGRO_CHANNEL_CONF-chan_conf -- ALLEGRO_MIXER* ) 130 | function: al_destroy_mixer ( ALLEGRO_MIXER-*mixer -- ) 131 | function: al_attach_sample_instance_to_mixer ( ALLEGRO_SAMPLE_INSTANCE-*stream, ALLEGRO_MIXER-*mixer -- bool ) 132 | function: al_attach_audio_stream_to_mixer ( ALLEGRO_AUDIO_STREAM-*stream, ALLEGRO_MIXER-*mixer -- bool ) 133 | function: al_attach_mixer_to_mixer ( ALLEGRO_MIXER-*stream, ALLEGRO_MIXER-*mixer -- bool ) 134 | function: al_set_mixer_postprocess_callback ( ALLEGRO_MIXER-*mixer, callback[buf,numsamps,userdata--] userdata -- bool ) 135 | 136 | function: al_get_mixer_frequency ( const-ALLEGRO_MIXER-*mixer -- n ) 137 | \ function: ALLEGRO_CHANNEL_CONF, al_get_mixer_channels ( const-ALLEGRO_MIXER-*mixer -- ) 138 | function: al_get_mixer_depth ( const-ALLEGRO_MIXER-*mixer -- depth ) 139 | \ function: ALLEGRO_MIXER_QUALITY, al_get_mixer_quality ( const-ALLEGRO_MIXER-*mixer -- ) 140 | \ function: float, al_get_mixer_gain ( const-ALLEGRO_MIXER-*mixer -- ) 141 | \ function: al_get_mixer_playing ( const-ALLEGRO_MIXER-*mixer -- ) 142 | \ function: al_get_mixer_attached ( const-ALLEGRO_MIXER-*mixer -- ) 143 | function: al_set_mixer_frequency ( ALLEGRO_MIXER-*mixer, unsigned-int-val -- bool ) 144 | function: al_set_mixer_quality ( ALLEGRO_MIXER-*mixer, ALLEGRO_MIXER_QUALITY-val -- bool ) 145 | function: al_set_mixer_gain ( ALLEGRO_MIXER-*mixer, float-gain -- bool ) 146 | function: al_set_mixer_playing ( ALLEGRO_MIXER-*mixer, bool-val -- bool ) 147 | function: al_detach_mixer ( ALLEGRO_MIXER-*mixer -- bool ) 148 | 149 | \ voice 150 | function: al_create_voice ( unsigned-int-freq, ALLEGRO_AUDIO_DEPTH-depth, ALLEGRO_CHANNEL_CONF-chan_conf -- ALLEGRO_VOICE* ) 151 | function: al_destroy_voice ( ALLEGRO_VOICE-*voice -- ) 152 | function: al_attach_sample_instance_to_voice ( ALLEGRO_SAMPLE_INSTANCE-*stream, ALLEGRO_VOICE-*voice -- bool ) 153 | function: al_attach_audio_stream_to_voice ( ALLEGRO_AUDIO_STREAM-*stream, ALLEGRO_VOICE-*voice -- bool ) 154 | function: al_attach_mixer_to_voice ( ALLEGRO_MIXER-*mixer, ALLEGRO_VOICE-*voice -- bool ) 155 | \ function: al_detach_voice ( ALLEGRO_VOICE-*voice -- ) 156 | 157 | function: al_set_voice_position ( ALLEGRO_VOICE-*voice, unsigned-int-val -- bool ) 158 | function: al_set_default_voice ( voice -- bool ) 159 | function: al_get_default_voice ( -- voice ) 160 | -------------------------------------------------------------------------------- /afkit/afkit.f: -------------------------------------------------------------------------------- 1 | include afkit/ans/version.f 2 | #1 #6 #0 [version] [afkit] 3 | 4 | \ Load external libraries 5 | [undefined] EXTERNALS_LOADED [if] \ ensure that external libs are only ever loaded once. 6 | s" \kitconfig.f" file-exists [if] 7 | include \kitconfig.f 8 | [else] 9 | s" kitconfig.f" file-exists [if] 10 | include kitconfig.f 11 | [else] 12 | s" Missing kitconfig.f!!! " type QUIT 13 | [then] 14 | [then] 15 | include afkit/platforms.f 16 | 17 | true constant EXTERNALS_LOADED 18 | 19 | : empty only forth definitions s" (empty) marker (empty)" evaluate ; 20 | marker (empty) 21 | [then] 22 | 23 | \ Load support libraries 24 | include afkit/plat/win/fpext.f \ depends on FPMATH 25 | include afkit/ans/strops.f \ ANS 26 | include afkit/ans/files.f \ ANS 27 | include afkit/ans/roger.f \ ANS 28 | 29 | [defined] allegro-audio [if] include afkit/audio-allegro.f [then] 30 | 31 | \ -------------------------------------------------------------------------------------------------- 32 | 0 value al-default-font 33 | 0 value fps 34 | 0 value allegro? 35 | 0 value eventq 36 | 0 value display 37 | create uesrc 32 cells /allot 38 | variable fs \ enables fullscreen when on 39 | 1 value #globalscale 40 | create res 0 , 0 , 41 | defer >host 42 | _AL_MAX_JOYSTICK_STICKS constant MAX_STICKS 43 | create joysticks MAX_STICKS /ALLEGRO_JOYSTICK_STATE * /allot 44 | 16 cells constant /transform 45 | /ALLEGRO_KEYBOARD_STATE 17 * constant /kstates 46 | create kbstate /kstates /allot \ current frame's state (* 17 inputs) 47 | create kblast /kstates /allot \ last frame's state 48 | create penx 0 , here 0 , constant peny 49 | 0 value oldblender 50 | 0 value currentblender 51 | 0 constant FLIP_NONE 52 | 1 constant FLIP_H 53 | 2 constant FLIP_V 54 | 3 constant FLIP_HV 55 | 56 | \ -------------------------------------------------------------------------------------------------- 57 | \ Initializing Allegro and creating the display window 58 | 59 | : init-allegro-all 60 | al_init 0= abort" Couldn't initialize Allegro." 61 | al_init_image_addon 0= abort" Allegro: Couldn't initialize image addon." 62 | al_init_primitives_addon 0= abort" Allegro: Couldn't initialize primitives addon." 63 | al_init_font_addon 0= abort" Allegro: Couldn't initialize font addon." 64 | al_init_ttf_addon 0= abort" Allegro: Couldn't initialize TTF addon." 65 | al_install_mouse 0= abort" Allegro: Couldn't initialize mouse." 66 | al_install_keyboard 0= abort" Allegro: Couldn't initialize keyboard." 67 | al_install_joystick 0= abort" Allegro: Couldn't initialize joystick." 68 | al_init_native_dialog_addon 0= abort" Allegro: Couldn't initialize native dialogs." 69 | ; 70 | 71 | \ ------------------------------------ initializing the display ------------------------------------ 72 | 73 | : assertAllegro ( - ) 74 | allegro? ?exit true to allegro? init-allegro-all 75 | [defined] allegro-audio [if] initaudio [then] 76 | ; 77 | 78 | : xy@ ( adr - x y ) dup @ swap cell+ @ ; 79 | : x@ ( adr - x ) xy@ drop ; 80 | : y@ ( adr - y ) xy@ nip ; 81 | 82 | : displayw ( - n ) display al_get_display_width ; 83 | : displayh ( - n ) display al_get_display_height ; 84 | : displaywh ( - w h ) displayw displayh ; 85 | 86 | : init-display ( w h - ) 87 | assertAllegro 88 | fs @ if 2drop -1 -1 then 89 | locals| h w | 90 | 91 | ALLEGRO_DEPTH_SIZE #24 ALLEGRO_SUGGEST al_set_new_display_option 92 | ALLEGRO_VSYNC 1 ALLEGRO_SUGGEST al_set_new_display_option 93 | 94 | w h al_create_display to display 95 | displaywh res 2! 96 | 97 | \ 0 native al_get_monitor_info 0= abort" Couldn't get monitor info; try replugging the monitor or restarting" 98 | 99 | display al_get_display_refresh_rate dup 0= if drop 60 then to fps 100 | 101 | al_create_builtin_font to al-default-font 102 | 103 | al_create_event_queue to eventq 104 | eventq display al_get_display_event_source al_register_event_source 105 | eventq al_get_mouse_event_source al_register_event_source 106 | eventq al_get_keyboard_event_source al_register_event_source 107 | uesrc al_init_user_event_source 108 | eventq uesrc al_register_event_source 109 | 110 | ALLEGRO_DEPTH_TEST 0 al_set_render_state 111 | ; 112 | 113 | : valid? ( adr - flag ) ['] @ catch nip 0 = ; 114 | : scaled-res ( - w h ) res x@ #globalscale * res y@ #globalscale * ; 115 | : +display ( - ) display valid? ?exit scaled-res init-display ; 116 | : -display ( - ) display valid? -exit 117 | display al_destroy_display 0 to display 118 | eventq al_destroy_event_queue 0 to eventq ; 119 | : -allegro ( - ) -display false to allegro? al_uninstall_system ; 120 | : resolution ( w h - ) res 2! fs @ 0= if -display +display then ; 121 | 122 | \ ----------------------------------- words for switching windows ---------------------------------- 123 | [defined] linux [if] 124 | variable _hwnd 125 | variable _disp 126 | 127 | 0 XOpenDisplay _disp ! 128 | _disp @ _hwnd here XGetInputFocus 129 | 130 | : HWND ( - handle ) _hwnd @ ; 131 | 132 | : btf ( window - ) 133 | 0 XOpenDisplay _disp ! 134 | _disp @ over 0 0 XSetInputFocus 135 | _disp @ swap XRaiseWindow 136 | _disp @ 0 XSync ; 137 | 138 | : >display ( - ) 139 | display al_get_x_window_id focus ; 140 | [else] 141 | : btf ( winapi-window - ) 142 | dup 1 ShowWindow drop dup BringWindowToTop drop SetForegroundWindow drop ; 143 | : >display ( - ) 144 | display al_get_win_window_handle btf ; 145 | [then] 146 | 147 | :make >host HWND btf ; 148 | 149 | \ ----------------------------------------------- keyboard ----------------------------------------- 150 | 151 | : pollKB ( - ) 152 | kbstate kblast /ALLEGRO_KEYBOARD_STATE move 153 | kbstate al_get_keyboard_state ; 154 | 155 | : clearkb ( - ) 156 | kblast /kstates erase 157 | kbstate /kstates erase ; 158 | 159 | : resetkb ( - ) 160 | clearkb 161 | al_uninstall_keyboard 162 | al_install_keyboard not abort" Error re-establishing the keyboard :/" 163 | eventq al_get_keyboard_event_source al_register_event_source ; 164 | 165 | \ ----------------------------------------- end keyboard ------------------------------------------- 166 | \ ----------------------------------------- joysticks ---------------------------------------------- 167 | \ NTS: we don't handle connecting/disconnecting devices yet, 168 | \ though Allegro 5 /does/ support it. (via an event) 169 | 170 | : joy[] ( n - adr ) /ALLEGRO_JOYSTICK_STATE * joysticks + ; 171 | : >joyhandle ( n - ALLEGRO_JOYSTICK_STATE ) al_get_joystick ; 172 | : stick ( joy# stick# - f: x y ) \ get stick position 173 | /ALLEGRO_JOYSTICK_STATE_STICK * swap joy[] 174 | ALLEGRO_JOYSTICK_STATE.sticks + dup sf@ cell+ sf@ ; 175 | : btn ( joy# button# - n# ) \ get button state 176 | cells swap joy[] ALLEGRO_JOYSTICK_STATE.buttons + @ ; 177 | : #joys ( - n ) al_get_num_joysticks ; 178 | : pollJoys ( - ) #joys for i >joyhandle i joy[] al_get_joystick_state loop ; 179 | \ ----------------------------------------- end joysticks ------------------------------------------ 180 | 181 | \ -------------------------------------------------------------------------------------------------- 182 | \ Graphics essentials; no-fixed-point version 183 | : transform: create here /transform allot al_identity_transform ; 184 | transform: (identity) 185 | 186 | \ integer stuff 187 | : bmpw ( bmp - n ) al_get_bitmap_width ; 188 | : bmph ( bmp - n ) al_get_bitmap_height ; 189 | : bmpwh ( bmp - w h ) dup bmpw swap bmph ; 190 | : hold> ( - ) 1 al_hold_bitmap_drawing r> call 0 al_hold_bitmap_drawing ; 191 | : loadbmp ( adr c - bmp ) zstring al_load_bitmap ; 192 | : savebmp ( bmp adr c - ) zstring swap al_save_bitmap 0= abort" Allegro: Error saving bitmap." ; 193 | : -bmp ( bmp - ) ?dup -exit al_destroy_bitmap ; 194 | 195 | create write-src ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ZERO , ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ZERO , 196 | create add-src ALLEGRO_ADD , ALLEGRO_ALPHA , ALLEGRO_ONE , ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ONE , 197 | create interp-src ALLEGRO_ADD , ALLEGRO_ALPHA , ALLEGRO_INVERSE_ALPHA , ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ONE , 198 | 199 | : blend ( blender - ) 200 | dup to currentblender 201 | @+ swap @+ swap @+ swap @+ swap @+ swap @ al_set_separate_blender ; 202 | : blend> ( blender - ) 203 | currentblender to oldblender blend r> call oldblender blend ; 204 | interp-src blend 205 | 206 | \ Pen 207 | : at ( x y - ) penx 2! ; 208 | : +at ( x y - ) penx 2+! ; 209 | : at@ ( - x y ) penx 2@ ; 210 | 211 | \ State 212 | define internal 213 | create states /ALLEGRO_STATE 16 * allot 214 | variable >state 215 | : (state) >state @ 15 and /ALLEGRO_STATE * states + ; 216 | using internal 217 | : +state ( - ) (state) ALLEGRO_STATE_TARGET_BITMAP 218 | ALLEGRO_STATE_DISPLAY or 219 | ALLEGRO_STATE_BLENDER or 220 | ALLEGRO_STATE_NEW_FILE_INTERFACE or 221 | ALLEGRO_STATE_TRANSFORM or 222 | ALLEGRO_STATE_PROJECTION_TRANSFORM or al_store_state 223 | 1 >state +! 224 | ; 225 | : -state ( - ) -1 >state +! (state) al_restore_state ; 226 | previous 227 | 228 | : fullscreen 229 | fs on 230 | [defined] dev [if] ALLEGRO_FULLSCREEN_WINDOW [else] ALLEGRO_FULLSCREEN [then] 231 | ALLEGRO_OPENGL or 232 | al_set_new_display_flags 233 | +display ; 234 | 235 | fullscreen 236 | 237 | \ -------------------------------------------------------------------------------------------------- 238 | include afkit/piston.f 239 | \ -------------------------------------------------------------------------------------------------- 240 | 241 | >host 242 | -------------------------------------------------------------------------------- /ramen/ide/ide.f: -------------------------------------------------------------------------------- 1 | \ SwiftForth only 2 | 3 | s" ramen/ide/data/consolab.ttf" 26 ALLEGRO_TTF_NO_KERNING font: consolas 4 | : keycode evt ALLEGRO_KEYBOARD_EVENT.keycode @ ; 5 | : unichar evt ALLEGRO_KEYBOARD_EVENT.unichar @ ; 6 | create margins 4 cells /allot 7 | : ?.catch ?dup if postpone [ .catch then ; 8 | 9 | define ideing 10 | include afkit/plat/win/clipb.f 11 | include ramen/ide/v2d.f 12 | 13 | 0 value outbuf 14 | 0 value >outbuf 15 | 16 | create cursor 6 cells /allot \ col, row, color (r,g,b,a) 17 | : colour 2 cells + ; 18 | variable scrolling scrolling on 19 | create replbuf #1024 /allot 20 | create cmdbuf #1024 /allot 21 | create history #1024 /allot 22 | create ch 0 c, 0 c, 23 | create attributes 24 | 1 , 1 , 1 , 1 , \ 0 white 25 | 0 , 0 , 0 , 1 , \ 1 black 26 | 0.3 , 1 , 0.3 , 1 , \ 2 green 27 | 1 , 1 , 0.3 , 1 , \ 3 light yellow 28 | 0 , 1 , 1 , 1 , \ 4 cyan 29 | 1.0 , 0 , 0.5 , 1 , \ 5 purple 30 | 1 , 1 , 1 , 1 , \ 0 white 31 | 1 , 1 , 1 , 1 , \ 0 white 32 | 1 , 1 , 1 , 1 , \ 0 white 33 | 1 , 1 , 1 , 1 , \ 0 white 34 | 1 , 1 , 1 , 1 , \ 0 white 35 | 1 , 1 , 1 , 1 , \ 0 white 36 | 1 , 1 , 1 , 1 , \ 0 white 37 | 1 , 1 , 1 , 1 , \ 0 white 38 | 1 , 1 , 1 , 1 , \ 0 white 39 | 1 , 1 , 1 , 1 , \ 0 white 40 | 1 , 1 , 1 , 1 , \ 0 white 41 | 1 , 1 , 1 , 1 , \ 0 white 42 | 1 , 1 , 1 , 1 , \ 0 white 43 | 1 , 1 , 1 , 1 , \ 0 white 44 | 1 , 1 , 1 , 1 , \ 0 white 45 | \ 0 value tempbmp 46 | :make repl? repl @ ; 47 | 0 value outbmp 48 | 49 | ( command buffer ) 50 | : recall history count cmdbuf place ; 51 | : store cmdbuf count dup if history place else 2drop then ; 52 | : typechar cmdbuf count + count! #1 cmdbuf count+! ; 53 | : rub cmdbuf count nip #1 - 0 max cmdbuf count! ; 54 | : paste clipb@ cmdbuf append ; 55 | : copy cmdbuf count clipb! ; 56 | 57 | ( init ) 58 | : /output 59 | 64 megs allocate throw to outbuf 60 | outbuf to >outbuf 61 | #2048 #2048 al_create_bitmap to outbmp 62 | ; \ outbmp al_clone_bitmap to tempbmp ; 63 | 64 | ( metrics ) 65 | consolas char A chrw constant fw 66 | consolas chrh constant fh 67 | \ : right-margin ( - n ) margins x2@ fw / displayw fw / min ; 68 | \ : bottom-margin ( - n ) margins y2@ fh / displayh 3 rows - fh / min ; 69 | : #cols ( - n ) displayw fw / pfloor 128 min ; 70 | : #rows ( - n ) displayh fh / 3 - pfloor ; 71 | 72 | ( cursor ) 73 | : ramen:get-xy ( - #col #row ) cursor xy@ 2i ; 74 | : ramen:at-xy ( #col #row - ) 2p cursor xy! ; 75 | : ramen:get-size ( - cols rows ) #cols #rows 2i ; 76 | 77 | ( utils ) 78 | : fillrect ( w h - ) write-src blend> rectf ; 79 | : clear ( w h bitmap - ) black 0 alpha onto> fillrect ; 80 | 81 | ( output ) 82 | : bufloc >outbuf cursor y@ #128 * + cursor x@ 1i + ; 83 | : scroll 84 | #128 +to >outbuf 85 | bufloc #128 erase 86 | ; 87 | : ramen:cr 88 | 0 cursor x! 89 | 1 cursor y+! 90 | scrolling @ -exit 91 | cursor y@ #rows >= if scroll -1 cursor y+! then 92 | ; 93 | : (emit) 94 | bufloc c! 95 | 1 cursor x+! 96 | cursor x@ #cols >= if ramen:cr then 97 | ; 98 | decimal 99 | \ : ?b output @ display <> if write-src else interp-src then ; 100 | \ : at> r> at@ 2>r call 2r> at ; 101 | : ramen:emit 102 | ( at> output @ onto> ?b blend> consolas fnt ! cursor colour 4@ rgba ) 103 | (emit) ; 104 | : ramen:type 105 | ( at> output @ onto> ?b blend> consolas fnt ! cursor colour 4@ rgba ) 106 | bounds do i c@ (emit) loop ; 107 | : ramen:?type dup if type else 2drop then ; 108 | fixed 109 | : ramen:attribute 1p 4 cells * attributes + cursor colour 4 imove ; 110 | 111 | : ramen:page 112 | >outbuf cursor y@ 1 + #128 * + to >outbuf 113 | 0 0 cursor xy! 114 | >outbuf #128 #rows * erase ; 115 | 116 | : zero 0 ; 117 | create ide-personality 118 | 4 cells , #19 , 0 , 0 , 119 | ' noop , \ INVOKE ( - ) 120 | ' noop , \ REVOKE ( - ) 121 | ' noop , \ /INPUT ( - ) 122 | ' ramen:emit , \ EMIT ( char - ) 123 | ' ramen:type , \ TYPE ( addr len - ) 124 | ' ramen:?type , \ ?TYPE ( addr len - ) 125 | ' ramen:cr , \ CR ( - ) 126 | ' ramen:page , \ PAGE ( - ) 127 | ' ramen:attribute , \ ATTRIBUTE ( n - ) 128 | ' zero , \ KEY ( - char ) \ not yet supported 129 | ' zero , \ KEY? ( - flag ) \ not yet supported 130 | ' zero , \ EKEY ( - echar ) \ not yet supported 131 | ' zero , \ EKEY? ( - flag ) \ not yet supported 132 | ' zero , \ AKEY ( - char ) \ not yet supported 133 | ' 2drop , \ PUSHTEXT ( addr len - ) \ not yet supported 134 | ' ramen:at-xy , \ AT-XY ( x y - ) 135 | ' ramen:get-xy , \ GET-XY ( - x y ) 136 | ' ramen:get-size , \ GET-SIZE ( - x y ) 137 | ' drop , \ ACCEPT ( addr u1 - u2) \ not yet supported 138 | 139 | ( command buffer stuff ) 140 | : cancel 0 cmdbuf ! ; 141 | : echo cursor colour 4@ #4 attribute cr cmdbuf count type space cursor colour 4! ; 142 | : interp cmdbuf count (evaluate) ; 143 | \ : ?errormsg errormsg ; 144 | \ ' ?errormsg is .catch 145 | : obey store echo ['] interp catch ?.catch 0 cmdbuf ! ; 146 | 147 | ( hotkey stuff ) 148 | : toggle dup @ not swap ! ; 149 | 150 | : (rld) cr ." Reloading... " s" rld" evaluate ; 151 | 152 | : special ( n - ) 153 | case 154 | [char] v of paste endof 155 | [char] c of copy endof 156 | endcase ; 157 | 158 | : pageup #rows -4 / pfloor #128 * +to >outbuf >outbuf outbuf max to >outbuf ; 159 | : pagedown #rows 4 / pfloor #128 * +to >outbuf ; 160 | 161 | : idekeys 162 | ( always ) 163 | 164 | \ etype ALLEGRO_EVENT_DISPLAY_RESIZE = 165 | \ etype FULLSCREEN_EVENT = or if /margins then 166 | 167 | etype ALLEGRO_EVENT_KEY_DOWN = if 168 | keycode #37 < ?exit 169 | keycode case 170 | of repl toggle endof 171 | of 172 | shift? if 173 | s" session.f" file-exists if 174 | s" session.f" included 175 | then 176 | else 177 | [defined] rld [if] ['] (rld) catch ?.catch [then] 178 | then 179 | endof 180 | 181 | endcase 182 | then 183 | 184 | 185 | ( only when REPL? is true ) 186 | repl? -exit 187 | etype ALLEGRO_EVENT_KEY_CHAR = if 188 | ctrl? if 189 | unichar special 190 | else 191 | alt? ?exit 192 | unichar #32 >= unichar #126 <= and if 193 | unichar typechar exit 194 | then 195 | then 196 | keycode case 197 | of recall endof 198 | of cancel endof 199 | of alt? ?exit obey endof 200 | of rub endof 201 | of pageup endof 202 | of pagedown endof 203 | endcase 204 | then 205 | ; 206 | 207 | ( rendering ) 208 | : draw-outbuf 209 | >outbuf 210 | consolas font> 211 | at@ 2>r 212 | #rows for 213 | dup #cols 1i #128 min print 214 | 0 fh +at 215 | #128 + 216 | loop 217 | drop 218 | 2r> at 219 | ; 220 | 221 | : ?... dup 16 > if dup 16 - else 0 then ; 222 | : .S2 ( ? - ? ) 223 | depth -exit 224 | #3 attribute 225 | ." ( " depth i. ." ) " 226 | DEPTH 0> IF DEPTH 1p ?... ?DO S0 @ I 1 + CELLS - @ 227 | base @ #16 = if h. else . then LOOP THEN 228 | DEPTH 0< ABORT" Underflow" 229 | FDEPTH ?DUP IF 230 | ." F: " 231 | 0 DO I' I - #1 - FPICK N. #1 +LOOP 232 | THEN ; 233 | 234 | : ?.errs 235 | showerr if ." SHOWERR " then 236 | steperr if ." STEPERR " then ; 237 | 238 | : +blinker repl? -exit now 16 and -exit s[ [char] _ +c ]s ; 239 | : .cmdbuf #0 attribute consolas fnt ! white cmdbuf count +blinker type ; 240 | : bar displayw displayh #rows fh * - dblue fillrect ; 241 | : ?trans repl? if 1 alpha else 0.8 alpha then ; 242 | : ?shad repl? if 1 alpha else 0.25 alpha then ; 243 | 244 | : (preren) 245 | outbmp onto> black 0 alpha backdrop white draw-outbuf 246 | ; 247 | : .output 248 | 0 0 at 249 | (preren) 250 | 2 2 +at black ?shad outbmp tblit 251 | -4 -4 +at black ?shad outbmp tblit 252 | 4 0 +at black ?shad outbmp tblit 253 | -4 4 +at black ?shad outbmp tblit 254 | 2 -2 +at white ?trans outbmp tblit 255 | ; 256 | : bottom 0 #rows fh * ; 257 | : .cmdline 258 | repl @ if bar then 259 | get-xy 2>r >outbuf >r 260 | replbuf to >outbuf 261 | replbuf #1024 erase 262 | 0 0 cursor xy! scrolling off 263 | ?.errs repl @ if 264 | .s2 265 | .cmdbuf 266 | then 267 | scrolling on 268 | white draw-outbuf 269 | r> to >outbuf 2r> at-xy 270 | \ output @ onto> noop \ fixes the lag bug... why though? 271 | ; 272 | 273 | \ -------------------------------------------------------------------------------------------------- 274 | \ bring it all together 275 | 276 | : /ide >host /output 1 1 1 1 cursor colour 4! ( /margins ) ; \ don't remove the >host; fixes a bug 277 | : /repl 278 | /s \ clear the stack 279 | repl on 280 | \ ['] >display is >host \ >host is redefined to take us to the display 281 | \ >host 282 | >display 283 | ide-personality open-personality 284 | ; 285 | : shade dgrey 0.5 alpha 0 0 at displaywh rectf white ; 286 | : ?rest 287 | source-id close-file drop 288 | [in-platform] sf [if] begin refill while interpret repeat [then] ; 289 | 290 | only forth definitions also ideing 291 | : ide:pageup pageup ; 292 | : ide:pagedown pagedown ; 293 | 294 | : ide-system idekeys ; 295 | : ide-overlay 0 0 at unmount repl @ if shade then .output bottom at .cmdline ; 296 | : rasa ['] ide-system is ?system ['] ide-overlay is ?overlay ; 297 | : -ide close-personality HWND btf ; 298 | : ide rasa /repl ['] ?rest catch ?.catch go -ide ; 299 | : /s S0 @ SP! ; 300 | : quit -ide cr quit ; 301 | : wipe 0 0 cursor xy! outbuf to >outbuf outbuf #128 #rows * erase ; 302 | 303 | /ide 304 | only forth definitions 305 | marker (empty) --------------------------------------------------------------------------------