vCPU from ROM (or chained SYS functions)

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
User avatar
DavidHK
Posts: 31
Joined: 25 Aug 2019, 12:59

vCPU from ROM (or chained SYS functions)

Post by DavidHK »

I stumbled over this issue on Github for running vCPU programs directly from ROM: https://github.com/kervinck/gigatron-rom/issues/83

I was pondering about it a while now and I've had questions as to how to handle the program counter and such. One solution might be to add another interpreter, but I was looking for other solutions.

One idea I had was to build chained application specific SYS functions. You would need an assembler that enforces that each block of native code takes a constant amount of cycles (so only very special jump instructions would be allowed). Each of such fixed blocks would be an application specific SYS function and they can chain to the next one by putting its address in the "sysFn" variable. In theory this should only require the RAM for the single syscall instruction. To be able to call "normal" SYS functions a bit more RAM would be needed, maybe something like this in vCPU assembler code (9 bytes if I counted correctly):

Code: Select all

SYS [external fn time]
LDWI [next chain fn address]
STW $22 ; set "sysFn"
SYS [next chained time]
This vCPU code would be modified each time a regular SYS function is called.

This would not allow directly using existing vCPU code, but I am not sure that is possible anyway as the memory map would be completely different between RAM and ROM.

But so far these are just wild thoughts that I wanted to pin down publicly, not something I intend to use very soon.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: vCPU from ROM (or chained SYS functions)

Post by marcelk »

I haven't figured it out yet either. A good application for such a capability will be to host the set of functions for SDC/MMC card loading: for it to load GT1 files anywhere in RAM without true restrictions. On the other hand, with 64K or 128K RAM, this may not be much of an issue. In 32K such a loader tends to get in the way.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: vCPU from ROM (or chained SYS functions)

Post by marcelk »

DavidHK wrote: One idea I had was to build chained application specific SYS functions. You would need an assembler that enforces that each block of native code takes a constant amount of cycles (so only very special jump instructions would be allowed). Each of such fixed blocks would be an application specific SYS function and they can chain to the next one by putting its address in the "sysFn" variable.
But so far these are just wild thoughts that I wanted to pin down publicly, not something I intend to use very soon.
I just realise I have subconsciously applied this idea in shortening the vReset routine at $01f0 so I can have some variable space in that area... Not so long ago this function got shortened to:

Code: Select all

LDI SYS_Reset_88
STW sysFn
SYS 88
SYS_Reset_88 (an internal SYS function) then does some reset work, stuffs SYS_Exec_88 into sysFn and provides an argument, reverts vPC and returns to have the same SYS instruction executed again:

Code: Select all

SYS_Reset_88:
              ...
              006c 00ad  ld   $ad         ;SYS_Exec_88
              006d c222  st   [$22]       ;sysFn
              006e 00b7  ld   $b7         ;<Reset.gt1 from EPROM
              006f c224  st   [$24]       ;sysArg+0
              0070 00c1  ld   $c1         ;>Reset.gt1 from EPROM
              0071 c225  st   [$25]       ;sysArg+1
              0072 0116  ld   [$16]       ;Force second SYS call
              0073 a002  suba $02
              0074 c216  st   [$16]       ;vPC
               ...
Coincidence? Probably not...

.
One solution might be to add another interpreter, but I was looking for other solutions.
But so far these are just wild thoughts that I wanted to pin down publicly, not something I intend to use very soon.
I was just watching this great presentation on a 16-bit system called AcheronVM for the 6502. It's tempting to see this as inspiration for a "better" vCPU...

https://www.youtube.com/watch?v=zdJnz6-d060

.
Attachments
Screenshot 2019-11-10 at 20.37.42.jpg
Screenshot 2019-11-10 at 20.37.42.jpg (561.61 KiB) Viewed 3267 times
User avatar
DavidHK
Posts: 31
Joined: 25 Aug 2019, 12:59

Re: vCPU from ROM (or chained SYS functions)

Post by DavidHK »

marcelk wrote: 10 Nov 2019, 19:49 SYS_Reset_88 (an internal SYS function) then does some reset work, stuffs SYS_Exec_88 into sysFn and provides an argument, reverts vPC and returns to have the same SYS instruction executed again:
Ah, yes, that is basically what I was thinking of. (And with branches where each path gets a different sysFn for continuation.)
marcelk wrote: 10 Nov 2019, 19:49 I was just watching this great presentation on a 16-bit system called AcheronVM for the 6502. It's tempting to see this as inspiration for a "better" vCPU...
That sounds like a really great design, maybe I should start up some 6502 emulator and play with it myself.
Post Reply