Restarting the xForth journey

Chat about anything CX16 related that doesn't fit elsewhere
Post Reply
BruceRMcF
Posts: 259
Joined: Sat Jan 07, 2023 10:33 pm

Restarting the xForth journey

Post by BruceRMcF »

Well, on a previous version of this forum lived a "pre-Alpha" release of xForth, which was indeed live ... but still broken, as the critical "CREATE DOES>" pair of words did not work correctly.

The forum version of the source for that developing language implementation went into the same void where links to abandoned online image storage accounts go, and the laptop that it was most recently been moved onto proceeded to die.

However, I've restarted the project. Spurred by the tease of the CX16 GS prototype, I have simplified my target for the initial system, so that the reboot has gone faster -- in part because of experience in the original boot, but also because it did not have so far to travel.

The current development plan is:
  • xForth02, to have a 64KB memory map 65C02 version for the CX16, and also a closely aligned version NMOS6502 version for the C64.
  • xForth16, a 64KB memory bank 65816 version for the CX16, and
  • xForth1, a "Native Bank 1" 65816 version to provide close to a 64KB dictionary in Native Bank 1, plus support scaffolding and infrastructure in the 64KB address space
  • And maybe, if the spirit so moves me, an xForthH "Harvard" memory model Forth, with codespace in Native Bank 1 and dataspace in Native Bank 2.
The original xForth planned a "3 ring circus" of uses of HiRAM, with separated name headers eventually to live in HighRAM, additional executable Modules also to live in HighRAM, and HighRAM also available via the venerable Forth "BLOCK" system as virtual memory. The separated headers was to cram more functionality into Low RAM, by pulling the name information out of Low RAM.

But I've dropped that for the simplicity of mingled headers. It turns out, the implementation of executable Modules to execute from the HighRAM window is much easier to work out when the headers for the Modules are mixed in with the compiled (and/or assembled) code.

It's still a "two ring circus", with both BLOCKs and Modules using High RAM ... but since the classic Forth BLOCKs were designed to hold raw sectors from drives, with a tried and tested system of working in 1KB BLOCK Buffers, there is no interference between the two, because the access to the High RAM segments containing BLOCKs only occurs while executing the Forth word "BLOCK", and that use is already designed to stack the current High RAM segment before putting the desired one in place, and restoring it when finished. Indeed ... it has to be designed that way, because BLOCKs can hold source code, which can in turn contain calls to BLOCK.

So High RAM Modules and Blocks won't interfere with each other. I am only working on the Block system up front, but I've sketched out the Module system semantics elsewhere.

Anyway, I plunged back into sorting out my Forth inner interpreter, porting Brad Rodriguez's Camel Forth for the z80 primitives to 65C02 assembly, porting his Header macros into plain ACME pseudo-ops, and working through the small (but critical) adjustments between his Z80 inner interpreter and my 65C02 inner interpreter. I've made it through the process of using ACME as a spell checker until the source assembled, and am now grinding through the process of debugging in monitor to find the actual bugs preventing it from coming up ... the inner interpreter is working, the compiled code entry routine is working, and shortly the start up display should be working, and, fingers crossed, in another couple of days (or weeks, or months), I'll have the outer interpreter up and running so I will be able to test individual primitives on the command line, dramatically speeding up the debugging process.

This is part of my evening relaxation process in the Semester on those evenings where relaxation is an option, and the Semester is coming to an end. It's up in the air whether I will be finding time to work on it during the summer, but even if not, hopefully progress will be able to continue in the Fall ... so I wanted to lay a marker down that work on xForth has begin anew.
BruceRMcF
Posts: 259
Joined: Sat Jan 07, 2023 10:33 pm

Re: Restarting the xForth journey

Post by BruceRMcF »

I've said that I plan to have xForth02 for the CX16 and a closely aligned version of xForth02 for the C64.

How is that possible, when the CX16 xForth relies so heavily on High RAM?

It's possible by (1) accepting that it won't be identical (hence "closely aligned"), and (2) accepting that it will be slower.

The Modules and the Blocks can't be in the same place, because both Blocks and Modules will have to be loaded from mass storage, and while reading the High RAM segment, stacking it, putting a new High RAM segment in place, reading from or writing to a 1KB buffer in Low RAM, and then restoring the previous High RAM segment can be done quite quickly in the CX16 ...

... in the C64, that same 8KB chunk of a BLOCK image file is not some offset from a Block Image file that was loaded directly into High RAM ... it's a free standing BLOCK "chunk" file, from a BLOCK image file that has been split up into 8KB chunks. The user wants to leave that in place until it is necessary to replace it with another one to get to a different BLOCK in the BLOCK space. Otherwise the system will thrash badly.

So the C64 Modules are not 8KB at $A000-$BFFF, they are 4KB in the C64 Golden RAM at $C000-$CFFF. The RAM underneath the BASIC ROM is reserved for the 8KB "BLOCK Chunk" files. The base name of the Block image is stashed in the system data area, with the name of each Chunk being <<name>>.BL0 up as far as <<name>>.BLF, so that a Block image file can be split up into up to 16 "chunks". At 8KB per chunk, that is a maximum Block file size of 128KB. That means that a maximum size set of Block "chunks", plus a saved image of a compiled Forth system, can fit on a 1541 disk (or inside a 1541 disk image) ... but splitting up a maximum sized Block image file into chunks without clever 1541 tricks would require a 1571 or 1581 drive (or emulator with 1571 or 1581 image file).

To align the CX16 version of xForth02, its Block image files may be up to 128KB, and so they may occupy up to 16 consecutive HighRAM segments.

While Forth BLOCK files are likely most famous as the way that Forth source was edited, stored and loaded in the traditional 1970's / early 1980's Forth systems, Forth systems of the past half century have tended to rely on source edited and stored from existing system capabilities and loaded from the host system text files. xForth02 is intended to support this more modern approach as well, providing an INCLUDE" word which will allow a Forth source or script to be loaded from the host file system. So the focus of BLOCKs in xForth is not so much as a primitive, rudimentary (but very extensible) Integrated Development Environment, but rather as a means of breaking the 64KB limit for data access, giving the C64 version 128KB of extended data work and storage space and the CX16 version -- which can slot multiple files at 128KB boundaries of its virtual BLOCK space -- 256KB or more.

The BLOCK system is based on Block numbers, which are integers up to 15bit in size. The high bit of the location storing the block is reserved for a dirty bit to indicate that the contents of the buffer must be stored back in the original block "file" location (a 1KB range in a High RAM segment for the CX16) before using the buffer for a different block. With each Forth94/Forth2012 BLOCK being 1KB in size, that means the total space that can be addressed by one Block system in a 16bit Forth is 32MB:
  • The Block File space lives in High RAM, which is a maximum of 2MB. Given the system bank, and some HighRAM segments used for executable there are at most 15 128KB file slots -- 3 on a 512KB system -- so Block numbers from $0 to $77F ($780-$7FF is a "hole" in the block space numbering due to extended RAM reserved for other purposes).
  • Block numbers from 2048 ($800) through to 16,383 ($3FFF) are reserved for referring to ROM banks and cartridge "ROAM" spaces, with any further specification deferred pending more information on the "ROAM" allocation system in the CX16 GS (and I presume similar capabilities may be made available to Gen1 systems via an expansion slot card)
  • Block numbers from 16,384 ($4000) to 32,767 ($7FFF) are reserved for Native Banks 1-255 in the CX16GS.


While I doubt I will ever have either a C64 REU or a GeoRAM cartridge, the Forth BLOCK system can comfortably work with either, so the alignment of CX16 BLOCKs with the C64 hypothetically extends up to the Block File space, up to the amount of additional RAM installed ... and thanks to the massive range of equipment emulated by VICE, if I have the available time, I will be able to sort out how to make that work.
Post Reply