Closed mitra42 closed 3 years ago
Doing this in the Eprom branch ... partially added a Romable16_16 class
Part of the JS backport should be looking for efficiency issues, especially using both Forth and JS stacks. For example fetch pops stuff off Forth stack, then passes as argument to Mfetch to m.fetchCell which passes the address to ramAddr for conversion and then passes to cellRamFetch. Some of these steps could be eliminated.
On Arduino its already simpler
fetch() { SPpush(Mfetch(SPpop())) }
CELLTYPE Mfetch(const CELLTYPE byteAddr) { return (byteAddr >= RAM0) ? cellRamFetch(RAMADDR(byteAddr)) : cellRomFetch(ROMADDR(byteAddr)) ; }
#define RAMADDR(x) ((x ^ RAM0) >> CELLSHIFT)
CELLTYPE cellRamFetch(const CELLTYPE cellAddr) { return ram[cellAddr]; };
But really that wants to be closer to
fetch() {
const CELLTYPE a = ram[SP];
ram[SP] = (a & RAM0) ? ram[(a ^ RAM0) >> CELLSHIFT] : rom[a]
}
Then Mfetch(a)
gets replaced in some cases with fetch()
if the arguments are anywhere near the stack or just with
Mfetch(a) { return (a & RAM0) ? ram[(a ^ RAM0) >> CELLSHIFT] : rom[a] }
Worth further thought that this last line might not be that different from the code actually output since a smart compiler probably optimises cellRamFetch (or I could use a #define)
Backport is done - but only for Cell=2 mem=16, would be good to add the others in the Rommable format and then remove the Mem versions.
Currently it only runs out the eprom branch, backporting is a little complex