'816 Forth Xmemory words

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
Post Reply
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

'816 Forth Xmemory words

Post by GARTHWILSON »

I'm getting some time to work on my long-neglected '816 Forth, and started considering the words for accessing the non-bank-0 locations. Because of Forth's code compactness, and in order to keep performance good, I've kept to a 16-bit Forth with all the actual Forth code running in bank 0, reserving the other banks primarily for data (large arrays, tables, etc.). So ! for example only stores a normal 16-bit cell at the address pointed to by the top 16-bit stack cell; but now I need another one where the address at the top will be a double number, and I need another name. Below, I propose just adding an X in front (for eXtended memory) but I would rather not come up with new non-standards if other such things already exist in common (or not-so-common) practice. Does anyone know?

The last two variations on CMOVE are for moving blocks of less than 64K from bank-0 memory to extended memory and vice-versa. Since these blocks will never overlap, there's no need for the "up" version. For simplicity, I suppose XCMOVE could just be used, but it will need a double-number address for even the bank-0 source or destination. XCMOVE and XCMOVE> will be able to move more than one bank at a time-- ie, in effect, there really will be no bank boundaries above bank 0.

The DO...LOOP and related words will also need to be able to handle a limit and index that are double numbers. Here I've just added a 2 in front of the name. Again, does anyone know if other more-standard names exist in Forth practice?

Code: Select all

normal    extended-memory (X)
words:    version and stack effect:

!         X!         ( n Xaddr -- )
C!        XC!        ( c Xaddr -- )
@         X@         ( Xaddr -- n )
C@        XC@        ( Xaddr -- c )
2@        X2@        ( Xaddr -- d )
2!        X2!        ( d Xaddr -- )
CMOVE     XCMOVE     ( from_Xaddr to_Xaddr count -- )
CMOVE>    XCMOVE>    ( from_Xaddr to_addr  count -- )
          CMOVE>X    ( from_addr  to_Xaddr count -- )
          X>CMOVE    ( from_Xaddr to_Xaddr count -- )
VARIABLE  XVARIABLE
ALLOT     XALLOT     ( d-count -- )
FILL      XFILL

DO        2DO        ( to_d  from_d -- )
?DO       2?DO       ( to_d  from_d -- )
I         2I         ( -- d )
J         2J         ( -- d )
LOOP      2LOOP
+LOOP     2+LOOP     (maybe only take 16-bit input?)
LEAVE     2LEAVE
UNLOOP    2UNLOOP
BOUNDS    2BOUNDS    ( Xaddr  d_count -- Xend_addr+1  Xbegin_addr )
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

PygmyForth for the PC used L! and L@ for "long" addresses variations. Also, if I/O is stored in a separate bank, then you could conceivably use P! and P@ (for Port Store/Fetch), which seems to be idiomatic as well.

As far as the other words, there are no standards so far as I can tell. If it's not defined in ANSI's definition (core or otherwise), it's not going to be standard anyway.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

Thanks for the note on Pygmy Forth.
Quote:
If it's not defined in ANSI's definition (core or otherwise), it's not going to be standard anyway.
I just ask because there are a lot of things that are not in ANS but are nevertheless in common Forth usage.
cas
Posts: 27
Joined: 21 May 2003
Location: Germany
Contact:

Post by cas »

VolksForth MS-DOS (a F83 Forth) defines

Code: Select all

l@ ( seg:addr -- n ) // long fetch

l!  (n seg:addr -- ) // long store

lc@ (seg:addr -- 8b ) // leng fetch char

lc! ( 8b seg:addr -- ) // long store char

lmove ( from.seg:addr to.seg:addr quan -- ) same as move, but for extended memory, 64K max in one move

ltype ( seg:addr len -- ) // same as type, but prints string from extended RAM

ldump (seg:addr quan -- ) // dump memory from extended RAM

lallocate ( #pages -- seg ff | avail.pages err# ) // allocate #pages in extended ram, leaves either highbytes of address of pages and true flag, or number of available pages and false flag/error code

lfree ( seg -- err# ) // frees memory reserved by lallocate

User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

Well, the '816 Forth still mostly been collecting dust, but I just finished the set of words for the 32-bit DO LOOP for the '02 which I've been wanting occasionally for things like operating off-board multimegabyte peripheral memory:

2BOUNDS
2DO and its internal, 2do
2?DO and its internal, 2?do
2LOOP and its internal, 2loop
2+LOOP and its internal, 2+loop which also uses a 32-bit incrementer
2I (I didn't bother to do a 2J .)
2LEAVE
2?LEAVE
2UNLOOP

Only the IMMEDIATE compiling words and 2BOUNDS are written as secondaries. The rest are all primitives for best performance. Wow does it ever take a lot of assembly-language instructions to do these on the '02! 2loop and 2+loop together take about 103 assembly-language instructions (not bytes), not including headers. I left the last four above without compiler security, so 2I 2LEAVE 2?LEAVE and 2UNLOOP there in capitals are the actual run-time words, not IMMEDIATE compile-only words that compile internals.

I might start another topic on designing a simple 32-bit 6502 with 32-bit data bus and registers. The objective would be considerably different from the 65GZ032 whose complexity seems to have kept it from ever being completed. It would have fewer addressing modes than the '816 because with a 32-bit data bus and registers, basically everything is in zero page (or direct page). In some ways it would be simpler than the 6502, but I do want a few of the things the '816 has that the '02 lacks, especially to facilitate relocatable code and multitasking. I was trying to get hold of Rob Finch since he has a dormant processor-design Yahoo forum but he seems to be incommunicado at the moment. [Edit, years later: He has surfaced, and is back here and even more active on the AnyCPU forum.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Post Reply