ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

A Pico Z-machine

Fri Jul 23, 2021 5:18 am

I've finished a rough port of the bocfel Z-code interpreter for the Pico. To avoid confusion, I have decided to call it pocfel. According to the dog developer the p indicates that Fido's upside down windowing system has been used rather than GLK to display the text. From my point of view the letter p does not look like an upside down b.

Games are saved using a 0.5MB LittleFS partition located at 1MB while the Z-code binary is loaded as a separate uf2 image starting at 1.5MB in flash.

The most recent version is currently available at the link

https://fractal.math.unr.edu/~ejolson/p ... urrent.tgz

Please read the file 01PICO.txt to learn how to build and use the program. I've tested pocfel with a number of games and it seems to work.

Note that I tried to disable all code that stores history, undo and debugging information in RAM as this quickly exhausts the Pico's memory; however, it's possible that I missed something. Please let me know of any instabilities that cause the interpreter to crash by posting feedback here. Other bug reports are also welcome.
Last edited by ejolson on Fri Jul 23, 2021 5:53 am, edited 4 times in total.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Fri Jul 23, 2021 5:41 am

Work leading up to the version of the bocfel interpreter available for download from the link in the previous post is described in

viewtopic.php?f=144&t=315050

A large number of Z-code binaries are available for download at

https://ifdb.org/search?searchfor=forma ... ne%2fBlorb

The original source for bocfel is

https://cspiegel.github.io/bocfel/

hippy
Posts: 10530
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: A Pico Z-machine

Fri Jul 23, 2021 11:15 am

ejolson wrote:
Fri Jul 23, 2021 5:18 am
Please read the file 01PICO.txt to learn how to build and use the program. I've tested pocfel with a number of games and it seems to work.
Worked for me. Thanks.

I got a couple of certificate related errors when I tried a simple 'wget' for your '.tgz' using your download URL but right-click and save from Chromium worked.

Code: Select all

ERROR: The certificate of 'fractal.math.unr.edu' is not trusted.
ERROR: The certificate of 'fractal.math.unr.edu' doesn't have a known issuer.
One edit of CMakeLists.txt to point it to where my Pico SDK was and it sailed through the build. Grunk is looking for his pig :D

It looks like a two-parter; 'pocfel.uf2' loads to the start of Flash where it looks for 'story.uf2' loaded elsewhere in Flash. It would be possible to merge the two to create a single '.uf2'. That might be useful for sharing single, ready-built, ready-to-go, '.uf2' files.

Other options might include allowing multiple stories. But I may be getting ahead of things here. The great thing is you have the foundation for whatever might come next. I can understand the priority being to look for any bugs in the port so I'll help Grunk find his pig and see what happens.

Using 'minicom' the first time the formatting was a little off for me. I was seeing -

Code: Select all

>
Outside                                     Score:
My cursor under the 'O' of the colour inverted line, so it gets over-typed. If I typed "look" I end up with an inverted "lookide ... score:' scrolled up the page.

It was better with GtkTerm, the inverted line stayed at the bottom, but I noticed the right-hand side was truncated, no actual score value and similar line truncation with "help". Probably the inversion not covering the full width, leaving black text on a black background.

Trying now, after a re-plug, it's fine in 'minicom', I can even read I have a score of zero. So there might be some issues relating to ANSI escape sequences or initialisation which needs investigating.

I am sure I confused things by swapping between terminals, accidentally having multiple /dev/ttyACM0 open, because, when I switched to a prompt I had run 'minicom' on ...

Code: Select all

>
Huh?

>

*** PANIC ***

Out of memo
It might be worth changing Product and Manufacturer in the USB descriptors to show it's running 'pocfel', and perhaps which story. That won't show with 'lsusb' but will show in 'dmesg'.

All-in; I'm very impressed, would recommend anyone else interested in text-based adventuring to take it for a spin. I have porting my own 'cavern' game from long ago to a Pi on my To Do list. I might have to take a look at Z-code.

hippy
Posts: 10530
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: A Pico Z-machine

Fri Jul 23, 2021 11:30 am

A couple of interactions which could perhaps be improved -

Code: Select all

>save
Enter filename for save game: 
[Warning: unable to open save file]
Oops, that not work.

Code: Select all

>save
Enter filename for save game: fred
OK.
>/dir
               ./               ../             fred  
>/ls
[No saves available]
And definitely some sort of memory leak or overflow somewhere-

Code: Select all

>put out fire pants
Grunk huff and puff at pants, but it not good enough. Pants still on fire.

>stamp on pants
Grunk not know what that mean.

>jump

*** PANIC ***

Out of memo
I have had a couple of hangs .I'm guessing an OOM issue too severe to report it.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Fri Jul 23, 2021 2:59 pm

hippy wrote:
Fri Jul 23, 2021 11:30 am
A couple of interactions which could perhaps be improved -

Code: Select all

>save
Enter filename for save game: 
[Warning: unable to open save file]
Oops, that not work.

Code: Select all

>save
Enter filename for save game: fred
OK.
>/dir
               ./               ../             fred  
>/ls
[No saves available]
And definitely some sort of memory leak or overflow somewhere-

Code: Select all

>put out fire pants
Grunk huff and puff at pants, but it not good enough. Pants still on fire.

>stamp on pants
Grunk not know what that mean.

>jump

*** PANIC ***

Out of memo
I have had a couple of hangs .I'm guessing an OOM issue too severe to report it.
Yikes, it looks like the memory is in much shorter supply after I added LittleFS. There was enough memory to find the pig before that. Maybe I set the cache on the filesystem too large. I'll check that.

Thanks for testing. Sorry you could not get the pig yet.

In response to other observations, I've used only minicom and xterm for testing. The ANSI terminal emulator needs to know how to select a scroll region, and read the cursor position. Also, the game needs to be restarted if you change the window size as window size change events are not propagated through the serial links.

There was an existing way to save state to memory via /push, /ls and /pop in the original interpreter. I think I'll take those out as there is clearly not enough RAM.

I left in a one level /undo command, but it is again taking too much. I'll take that out.

I'll post back when a new version of ready.

Again thanks for testing this. Did you compile on Windows or a Raspberry Pi?

lurk101
Posts: 884
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Pico Z-machine

Fri Jul 23, 2021 3:44 pm

ejolson wrote:
Fri Jul 23, 2021 2:59 pm
Yikes, it looks like the memory is in much shorter supply after I added LittleFS. There was enough memory to find the pig before that. Maybe I set the cache on the filesystem too large. I'll check that.

Code: Select all

    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);
    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0);
    LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0);
Those are the only restrictions on cache size. You can make it very small. There's no point in having a large cache with LFS on Pico. Reads are fast and inexpensive (memcpy from XIP mapped flash space).

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Fri Jul 23, 2021 4:18 pm

lurk101 wrote:
Fri Jul 23, 2021 3:44 pm
ejolson wrote:
Fri Jul 23, 2021 2:59 pm
Yikes, it looks like the memory is in much shorter supply after I added LittleFS. There was enough memory to find the pig before that. Maybe I set the cache on the filesystem too large. I'll check that.

Code: Select all

    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);
    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0);
    LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0);
Those are the only restrictions on cache size. You can make it very small. There's no point in having a large cache with LFS on Pico. Reads are fast and inexpensive (memcpy from XIP mapped flash space).
It seems I'd set cache_size to prog_size, so that should be enough. I wonder what lookahead_size does?

lurk101
Posts: 884
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Pico Z-machine

Fri Jul 23, 2021 4:35 pm

ejolson wrote:
Fri Jul 23, 2021 4:18 pm
lurk101 wrote:
Fri Jul 23, 2021 3:44 pm
ejolson wrote:
Fri Jul 23, 2021 2:59 pm
Yikes, it looks like the memory is in much shorter supply after I added LittleFS. There was enough memory to find the pig before that. Maybe I set the cache on the filesystem too large. I'll check that.

Code: Select all

    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);
    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0);
    LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0);
Those are the only restrictions on cache size. You can make it very small. There's no point in having a large cache with LFS on Pico. Reads are fast and inexpensive (memcpy from XIP mapped flash space).
It seems I'd set cache_size to prog_size, so that should be enough. I wonder what lookahead_size does?
No luck there either, it doesn't use much space.

hippy
Posts: 10530
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: A Pico Z-machine

Fri Jul 23, 2021 4:45 pm

ejolson wrote:
Fri Jul 23, 2021 2:59 pm
Again thanks for testing this. Did you compile on Windows or a Raspberry Pi?
No problem. My First Year entertainment was pulling all-nighters playing the original Colossal Cave Adventure on a DECsystem-10 to a Derek & Clive soundtrack. I've still got my hand-drawn map on fan-fold somewhere. I have always had a passion, but more for the design and compiler implementation side rather than adventuring.

This is all being done on my Pi.

Please don't put yourself under undue pressure for my sake. I am impressed it works so well, will enjoy taking a stroll through the files as much as testing.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Fri Jul 23, 2021 4:46 pm

lurk101 wrote:
Fri Jul 23, 2021 4:35 pm
ejolson wrote:
Fri Jul 23, 2021 4:18 pm
lurk101 wrote:
Fri Jul 23, 2021 3:44 pm

Code: Select all

    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);
    LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0);
    LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0);
Those are the only restrictions on cache size. You can make it very small. There's no point in having a large cache with LFS on Pico. Reads are fast and inexpensive (memcpy from XIP mapped flash space).
It seems I'd set cache_size to prog_size, so that should be enough. I wonder what lookahead_size does?
No luck there either, it doesn't use much space.
I guess I need to track malloc. Given my previous experience with atexit, maybe it is worth asking whether free actually frees memory or simply returns success as if it did. Does anyone know what kind of allocator is used and how to check how much free memory is left in the heap?

stevend
Posts: 398
Joined: Fri Oct 11, 2013 12:28 pm

Re: A Pico Z-machine

Fri Jul 23, 2021 5:04 pm

ejolson wrote:
Fri Jul 23, 2021 4:18 pm
I wonder what lookahead_size does?
It's a packed bitmap of block usage, starting from some arbitrary (possibly current) block number. No point in allocating more bits than storage blocks, at the most. It's purpose is to speed up allocation of new blocks; once all blocks in the bitmap have been allocated, a scan is done to find some more.

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 867
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: A Pico Z-machine

Fri Jul 23, 2021 5:43 pm

guess I need to track malloc. Given my previous experience with atexit, maybe it is worth asking whether free actually frees memory or simply returns success as if it did. Does anyone know what kind of allocator is used and how to check how much free memory is left in the heap?
malloc/free come from the standard (newlib) C library (which provides no method to determine free space) and yes free does something.
atexit is fairly fringe functionality for a microcontroller app.

lurk101
Posts: 884
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Pico Z-machine

Fri Jul 23, 2021 7:08 pm

There is a heap declared in assembler source file crt0.S. Have you tried setting the CMAKE_ASM_FLAGS cmake variable?

Code: Select all

set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DPICO_HEAP_SIZE=...")
It defaults to 0x800. Not sure if that's the space used by the newlib malloc though.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Fri Jul 23, 2021 7:53 pm

stevend wrote:
Fri Jul 23, 2021 5:04 pm
ejolson wrote:
Fri Jul 23, 2021 4:18 pm
I wonder what lookahead_size does?
It's a packed bitmap of block usage, starting from some arbitrary (possibly current) block number. No point in allocating more bits than storage blocks, at the most. It's purpose is to speed up allocation of new blocks; once all blocks in the bitmap have been allocated, a scan is done to find some more.
Working under the assumption that LittleFS has been checked for memory leaks, I instrumented the rest of the bocfel code base. Even after setting the -u 0 flag to disable all undo functionality, it appears the program makes four malloc calls one realloc and three calls to free each turn [Edit: I was confused here--it doesn't]. From what I can tell the first malloc leaks 56 bytes of memory each turn while the other calls allocate and then deallocate a total of around 100KB each turn.

On it's own, I'm not worried about the memory leak, but it may interact with the larger allocations to cause fragmentation. In my opinion, the program should not create save states at each turn after I've turned off the undo feature.
Last edited by ejolson on Sat Jul 24, 2021 11:57 pm, edited 3 times in total.

lurk101
Posts: 884
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Pico Z-machine

Fri Jul 23, 2021 7:55 pm

lurk101 wrote:
Fri Jul 23, 2021 7:08 pm
There is a heap declared in assembler source file crt0.S. Have you tried setting the CMAKE_ASM_FLAGS cmake variable?

Code: Select all

set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DPICO_HEAP_SIZE=...")
It defaults to 0x800. Not sure if that's the space used by the newlib malloc though.
Sorry, no. That doesn't seem to make a difference. I can malloc 200K with the default setting.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Sat Jul 24, 2021 12:21 am

lurk101 wrote:
Fri Jul 23, 2021 7:55 pm
lurk101 wrote:
Fri Jul 23, 2021 7:08 pm
There is a heap declared in assembler source file crt0.S. Have you tried setting the CMAKE_ASM_FLAGS cmake variable?

Code: Select all

set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DPICO_HEAP_SIZE=...")
It defaults to 0x800. Not sure if that's the space used by the newlib malloc though.
Sorry, no. That doesn't seem to make a difference. I can malloc 200K with the default setting.
It's good to know one can allocate that much memory. After a little experimentation, I realized that the undo flag was set to 1 on my debug build. After setting it back to 0 the cycle of malloc and free each turn went away. I also cut the call stack from 1024 nested functions to 512 which saves another 24K of RAM just in case.

Now the astonishing Wumpus 2000

https://ifdb.org/viewgame?id=bsqx3xdl6epc52cu

seems even to run on the Pico Z-machine.

Code: Select all

Pocfel version 11 running...                                                    
                                                                                
                                                                                
Would you like to restore a saved game? >no                                     
                                                                                
Some people love exploring caves, and some people get a sick thrill out of      
falling. But you're not one of them.                                            
                                                                                
Since childhood you've had a fear of heights, depths, and quick trips in        
between; those dreams about endless drops into bottomless pits still haunt you, 
especially when you've had a bit to drink. You were also one of those kids who  
was CONVINCED that the boogeyman lurked under the basement steps, down there in 
the cold and clammy darkness. Nope, you are definitely NOT a fan of these two   
exotic pleasures of falling and darkness, which is why you're not thrilled      
about being thrown into a deep, forbidding shaft. If the fall lasts long enough 
maybe you'll get a chance to ponder what's at the bottom of it all, and what    
you left behind on the surface...                                               
                                                                                
Press any key to continue >                                                     
                                                                                
To be fair you HAVE plumbed these depths, though not in a very heroic way.      
You've done research and talked to people, mainly. When you devoted last week's 
editorial to exposing the shady dealings of New Jersey public officials, you    
thought you'd be given a promotion. Maybe the newspaper chain would bump you up 
to some big city assignment, get you away from the little Morristown rag you'd  
been working on for seven years.                                                
                                                                                
Apparently, the one thing you DIDN'T find out in your research was that those   
public officials OWN the newspaper chain, and that they're even more ruthless   
and immoral than you'd thought. Now, after being dragged out of bed and dumped  
into the pit itself, it looks like that promotion is a long way off.            
                                                                                
Press any key to continue >                                                     
                                                                                
But what IS in this pit? You've read facts about it in geological surveys.      
You've heard all the local folklore about the mythical creatures lurking down   
there -- the Wumpus was probably the most colourful monster of the bunch -- and 
you know for a fact that the city's been dumping toxic waste into it for years. 
Leave it to a bunch of suburban fat-cats to arrange a billion-dollar            
waste-disposal contract, and then just hire some local thugs to dump the stuff  
into a hole under Morristown. Could that toxic junk be leaking into the city's  
water supply? Lots of people are speculating, but nobody has had the courage to 
actually go DOWN there to check it out.                                         
                                                                                
Press any key to continue >                                                     
                                                                                
Well, looks like you've been reluctantly nominated. If you survive the fall,    
you might get a chance to solve these mysteries...and maybe win a Pulitzer      
Prize to boot! You've been falling for a long time, and it's almost time to     
land...for better or for worse.                                                 
                                                                                
And hey, maybe that Wumpus thing is really friendly?                            
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
Wumpus 2000                                                                     
The Virulent Labyrinth Of Yob-Shuggoth                                          
Copyright 2004 by Muffy St. Bernard.                                            
                                                                                
! Type 'help' for tips, hints and special features !                            
                                                                                
Release 1 / Serial number 041119 / Inform v6.21 Library 6/10                    
                                                                                
A vast, textured, watery chamber                                                
You are in room #20, a vast chamber with textured, orange, fungus-spotted       
walls. Some of the fungus has been scraped off the wall, but it is slowly       
growing back. The roof of the chamber is too high for you to see. Stalagmites   
rise out of the floor, reaching for the roof of the cave.                       
                                                                                
Exit 1 twists toward an unexplored room.                                        
Exit 2 moves toward an unexplored room.                                         
Exit 3 slowly descends toward an unexplored room.                               
Exit 4 rises very slightly toward an unexplored room.                           
                                                                                
A strong wind rushes from exit 3 to exit 1.                                     
A gush of water bursts from exit 4, through the room, and into exit 3.          
                                                                                
There is an empty canteen here.                                                 
High above your head is the shaft you fell out of.                              
                                                                                
It appears that this skeleton on the ground has broken your fall.               
                                                                                
A scrap of paper is lying next to the skeleton.                                 
                                                                                
You can also see a Transmat Popper and two food pellets here.                   
It's hot in here!                                                               
The deafening sound of a waterfall roars through the chamber.                   
                                                                                
>take canteen                                                                   
Taken.

>take popper
Taken.

>take food
Taken.

>i
You are carrying:
  a food pellet
  a Transmat Popper
  an empty canteen
  a Glow Bar

You are carrying 11 lbs of stuff (27% of your current capacity). It's all worth
about $695.

>                                                                          
Note that it takes some time for the "Press any key to continue" messages in the prologue at the beginning of the game to appear, presumably because the program is generating a random graph on which to play the game. Unfortunately, there doesn't appear to be any chance it will be a dodecahedron.

Woohoo! I've updated the Pocfel source code to version 11 in the link provided by the first post.

lurk101
Posts: 884
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: A Pico Z-machine

Sat Jul 24, 2021 2:46 am

I won't be creating any wood encased Pico game sticks anytime soon so I'd like to get this working on serial.
So..

Code: Select all

ztouf2 game.z8 game.uf2 0x10180000
Just creates a binary blob to be flashed at 0x10180000? Or, is there anything about the uf2 format I need to consider? I've removed the USB dependencies from the build.

Do you have a Github account? This would sit well there, become forkable and a great addition.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Sat Jul 24, 2021 3:19 am

lurk101 wrote:
Sat Jul 24, 2021 2:46 am
I won't be creating any wood encased Pico game sticks anytime soon so I'd like to get this working on serial.
So..

Code: Select all

ztouf2 game.z8 game.uf2 0x10180000
Just creates a binary blob to be flashed at 0x10180000? Or, is there anything about the uf2 format I need to consider? I've removed the USB dependencies from the build.
Irritatingly ztouf2 places the Z-code binary at 0x10180004 with a 4 byte header at 0x10180000 that contains a little-endian 32-bit number indicating the size of the original file. It also puts 22 bytes of zero padding at the end, due to some comments in zterp.c about the Z-code instruction decoder running off the end. I think Z-code itself is big endian, but the interpreter takes care of that. More information is contained in ztouf2.c about the memory layout.

It looks like Pocfel version 11 is pretty stable (at least compared to the previous version). If you want to patch the version you already have, just change "-u","1" to "-u","0" in zterp.c.

Here is a test where Grunk has caught the pig and is on the way out.

Code: Select all

>n

Windy Cave
Wow, this just like real cave! It have big pointy rock that stick down from up
high, and it have big pointy rock that stick up from ground, and it even have
dark and twisty tunnel that go north!

There lots of wind that come from north. Must be tunnel that go to other place.
Wind smell like fresh air, so maybe tunnel go outside.

Secret door in south wall not look so secret from here. Door still open right
now.

Pig reach over to ball. Then pig lick it. Huh. Weird pig.

>score
Grunk have 6 out of 7 so far.

>i
Grunk have:
  ball (that make light)
  pants (Grunk wearing them)
  pig (not happy)

Little wind blow through.

>
Probably it's best not to use the /ps command to save a game state in RAM. I haven't fully checked whether the file-based /save and /restore are completely stable, but hopefully. Note that most games also have an in-game save command (without the leading slash) and that the two save formats are intentionally incompatible. One therefore has to be consistent and use /restore with /save or alternatively restore with save.

Unfortunately, I missed a point.

Code: Select all

    ***  Grunk bring pig back to farm  ***


Grunk have 6 out of 7 that time.

Time for Grunk to RESTART or RESTORE a saved story or UNDO what Grunk just do
or tell FULL score or look at MENU (with different silly thing Grunk can try
doing and hint for last point) or just QUIT?
> quit
 Farm                                                             Score: 6      
                                                                                
Pocfel exited with code 0...rebooting...                           
                                  
Pocfel version 11 running...



Pig lost! Boss say that it Grunk fault. Say Grunk forget about closing gate.    
Maybe boss right. Grunk not remember forgetting, but maybe Grunk just forget.   
Boss say Grunk go find pig, bring it back. Him say, if Grunk not bring back     
pig, not bring back Grunk either. Grunk like working at pig farm, so now Grunk  
need find pig.                                                                                                   
I guess playing one more time is needed. This time I'll test the /save command.

ejolson
Posts: 8034
Joined: Tue Mar 18, 2014 11:47 am

Re: A Pico Z-machine

Sat Jul 24, 2021 9:01 pm

hippy wrote:
Fri Jul 23, 2021 11:15 am
All-in; I'm very impressed, would recommend anyone else interested in text-based adventuring to take it for a spin. I have porting my own 'cavern' game from long ago to a Pi on my To Do list. I might have to take a look at Z-code.
While there is a C compiler that generates Z code, it seems the most popular language is Inform version 6. I was reading the language manual yesterday and it seems well written.

https://www.ifarchive.org/if-archive/in ... nual_4.pdf

see also

https://www.inform-fiction.org/manual/

Rather than trying to catch another pig, I searched the archive and found
    dogout.jpg
    dogout.jpg (37.08 KiB) Viewed 1004 times
    https://ifdb.org/viewgame?id=8cfrh2p2imthsgss

    I right clicked to download the story file and then typed

    Code: Select all

    $ ztouf2 "Take the Dog Out.zblorb" 
    Extracting Take the Dog Out.zblorb...
    /x/hapa/ejolson/bin/ztouf2: line 29: cd: too many arguments
    ../Take the Dog Out.zblorb: No such file or directory
    Couldn't find any Z code!
    
    A few changes later version 12 of Pocfel produced

    Code: Select all

    $ ztouf2 "Take the Dog Out.zblorb" 
    Extracting Take the Dog Out.zblorb...
    Successfully captured 2 resources!
    /x/hapa/ejolson/bin/ztouf2.bin 0.z ../Take the Dog Out_0.uf2 0x10180000
    Wrote 1617 blocks to ../Take the Dog Out_0.uf2
    
    It seems natural to blame the dog developer for this one. Doing so, however, ignores the fact that other people put spaces in their file names as well.

    After updating the link in the first post to this thread with the updated version, I inserted the Pico-based USB Z-machine dongle while pressing BOOTSEL and as root typed

    Code: Select all

    # dmesg | tail -n1
    [2349518.802976] sd 2:0:0:0: [sdb] Attached SCSI removable disk
    # mount /dev/sdb1 /mnt
    # cp "Take the Dog Out_0.uf2" /mnt
    # umount /mnt
    # minicom -w -b 115200 -o -D /dev/ttyACM0
    Pocfel version 11 running...
    
    "Who let the dogs out?"
               -Baha Men
    "Who will let the dog out?"
               -Your girlfriend
     
    It's 9:00 am, and the dog needs to go out.
    
    Take the Dog Out
    A Short Constitutional by Ell
    Release 2 / Serial number 210404 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) 
    
    Living Room
    Your living room is a mish-mash of design styles, known as "how broke
    twentysomethings decorate." A bookshelf, a couch, a coffee table, and a
    makeshift TV stand pretty much sum up the essentials present here. 
     
    There are some other rooms and stuff which you don't have time to hang out in
    right now because you need to get Muffins' fluffy butt out the front door to
    the south.
    
    Your dog awaits your attention here.
    >
    
    Woohoo! Hopefully Fido will like this one better than Lost Pig.
    Last edited by ejolson on Sat Jul 24, 2021 9:42 pm, edited 1 time in total.

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sat Jul 24, 2021 9:39 pm

    ejolson wrote:
    Sat Jul 24, 2021 9:01 pm
    Woohoo! Hopefully Fido will like this one better than the pig.
    This time I thoroughly tested the /save and /restore features. No crashes.

    My final score was

    Code: Select all

    You did it. Against all expectations, you made it out of the house by eighteen
    minutes to ten. You and Muffins trot happily to the park, eager to begin the
    daily watering ritual.
    
        *** You are a champion! ***
    
    In that game you scored 28 out of a possible 30, in 43 turns.
    
    I wonder how to get the missing 2 points.

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sun Jul 25, 2021 4:42 am

    ejolson wrote:
    Sat Jul 24, 2021 9:01 pm
    hippy wrote:
    Fri Jul 23, 2021 11:15 am
    All-in; I'm very impressed, would recommend anyone else interested in text-based adventuring to take it for a spin. I have porting my own 'cavern' game from long ago to a Pi on my To Do list. I might have to take a look at Z-code.
    While there is a C compiler that generates Z code, it seems the most popular language is Inform version 6.
    Building the Inform 6 Z-code compiler on a Pi 4B under Raspberry Pi OS was remarkably simple compared to the effort of getting the Z-machine running on a Pico. I typed

    Code: Select all

    $ wget https://github.com/DavidKinder/Inform6/archive/refs/tags/v6.35.tar.gz
    $ tar zxf v6.35.tar.gz
    $ cd Inform6-6.35
    $ time gcc -O3 -DLINUX -o inform *.c
    
    real    0m33.888s
    user    0m32.025s
    sys 0m1.741s
    
    and had a working compiler in less than a minute. I felt quite refreshed that neither cmake, make, ninja nor any other build tools were needed to compile those 38 thousand lines of code.

    The runtime library was even easier and installed with

    Code: Select all

    $ git clone https://gitlab.com/DavidGriffith/inform6lib.git
    
    Now I have to figure out how to compile hello world for the Z-machine.

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sun Jul 25, 2021 4:55 am

    ejolson wrote:
    Sun Jul 25, 2021 4:42 am
    Now I have to figure out how to compile hello world for the Z-machine.
    Hello world was easier than expected as I didn't even need the runtime. Under Fido's supervision I simply created a file called hello.inf containing the lines

    Code: Select all

    ! "Hello world" example program
    [ Main;
      print "Bark bark woof bark howl.^";
    ];
    
    and then typed

    Code: Select all

    $ ./inform hello.inf 
    $ ls -l hello*
    -rw-r--r-- 1 ejolson users   81 Jul 24 21:51 hello.inf
    -rw-r--r-- 1 ejolson users 1536 Jul 24 21:51 hello.z5
    
    A quick check with the Linux version of pocfel obtained

    Code: Select all

    $ pocfel hello.z5
    Pocfel version 12 running...
    
    Bark bark woof bark howl.
    
    Pocfel exited with code 0.
    
    I wonder how difficult it would be to write a Z-code program that computes really big Fibonacci numbers?

    viewtopic.php?f=31&t=308988

    see also

    viewtopic.php?t=227343

    and

    viewtopic.php?t=240287

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sun Jul 25, 2021 5:59 pm

    ejolson wrote:
    Sun Jul 25, 2021 4:55 am
    I wonder how difficult it would be to write a Z-code program that computes really big Fibonacci numbers?
    I now have a working version of vbccz which compiles C code into Z code. Unfortunately, the development platform had to be moved to 64-bit because vbccz doesn't work on 32-bit Raspberry Pi OS.

    https://github.com/Quuxplusone/Advent/issues/3

    Even after that vbccz only builds correctly when using clang and not with gcc. Therefore, a small change needs to be made to vbcc/Makefile which reads

    Code: Select all

    CC = clang -std=c9x -g -DHAVE_AOS4
    
    After this change I obtain a working compiler on 64-bit x86 as well as the testing release of 64-bit Raspberry Pi OS. It's possible the HAVE_AOS4 define is responsible for the weirdness, but I left that alone since things already worked.

    I smell a wumpus. Could it now be easy to port Ken's historic C code?

    viewtopic.php?t=287943

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sun Jul 25, 2021 8:04 pm

    ejolson wrote:
    Sun Jul 25, 2021 5:59 pm
    I smell a wumpus. Could it now be easy to port Ken's historic C code?

    viewtopic.php?t=287943
    After a slight setback, the file wumpus.c now reads as

    Code: Select all

    #include <stdio.h>
    
    int main(){
        printf("Bark bark woof bark howl.\n");
    }
    
    Minor changes to the adventure Makefile and support routines then lead to

    Code: Select all

    $ make
    vc +z -c99 -O1 -DZ_MACHINE -DSAVE_AND_RESTORE -Iz-machine/include -c z-machine/cstubs.c -o z-machine/cstubs.s -module-name=libc
    vc +z -c99 -O1 -DZ_MACHINE -DSAVE_AND_RESTORE -Iz-machine/include -c wumpus.c -o z-machine/wumpus.s -module-name=wumpus
    cd z-machine ; inform -v8 -ew~S~X~D \$MAX_ARRAYS=700 \$MAX_ZCODE_SIZE=38000 \$MAX_STATIC_DATA=48000 Main.inf ../wumpus.z8
    Inform 6.35 for Linux (22nd May 2021)
    Compiled with 21 suppressed warnings
    $ pocfel wumpus.z8 
    Pocfel version 12 running...
    
    Bark bark woof bark howl.
    
    Pocfel exited with code 0.
    
    With the C compiler now running, what could go wrong? I wonder where the support library for 32-bit integer arithmetic went. Maybe it's time to let Fido out of the kennel.

    viewtopic.php?p=1893113#p1893113
    Last edited by ejolson on Sun Jul 25, 2021 11:45 pm, edited 1 time in total.

    ejolson
    Posts: 8034
    Joined: Tue Mar 18, 2014 11:47 am

    Re: A Pico Z-machine

    Sun Jul 25, 2021 10:09 pm

    ejolson wrote:
    Sun Jul 25, 2021 8:04 pm
    With the C compiler now running, what could go wrong?
    After only a few changes, I managed to compile wump.c from the historic 7th edition of Unix using vbccz for the Pico Z-machine. Pretty much the only thing I did was replace advent.c from Arthur's repository with wumpus.c. The resulting Z-code binary is

    https://fractal.math.unr.edu/~ejolson/p ... /wumpus.z8

    which runs on the Linux Pocfel as

    Code: Select all

    $ pocfel wumpus.z8 
    Pocfel version 12 running...
    
    Instructions? (y-n) n
    You are in room 11
    Bats nearby
    There are tunnels to 16 17 18
    Move or shoot (m-s) m
    which room? 16
    You are in room 16
    Bats nearby
    There are tunnels to 1 11 20
    Move or shoot (m-s) m
    which room? 1
    You are in room 1
    I smell a wumpus
    I feel a draft
    There are tunnels to 4 13 16
    Move or shoot (m-s) m
    which room? 13
    You are in room 13
    You fell into a pit
    Another game? (y-n) n
    
    Pocfel exited with code 0.
    
    The same binary can be flashed and run with Pocfel on the Pico using ztouf2. How exciting is that? I find it amazing nobody has created a Z-code version of this classic wumpus hunting game before.

    Return to “General”