Thanks for your reply BDD. Yes I tried to account for the LS vs HC situation I have - I am making use of the limited components I have in my possession. The updated schematic is on the first post..
However, I spotted the error after getting my brain properly in to gear. The effect of the memory banking is that when the CPU A15 line goes high accessing RAM, inverse of PB4 and PB5 values are used to map to A15 and A16 of RAM. In short, PB4 and PB5 select which 32K chunk of RAM is enabled. On power up, PB4 and PB5 are high using pull ups and the VIA initialisation code.
So, this is the truth table (A15 is CPU, PBx is port B bits, 16' and 15' are the RAM lines, 32K is the bank number).
Code:
A15 PB5 PB4 16' 15' 32K
0 X X 1 1 3
1 0 0 1 1 3
1 0 1 1 0 2
1 1 0 0 1 1
1 1 1 0 0 0
What I forgot (or was too stupid to think through) was that PB4 and PB5 being zero forces the use of Bank 3, which is the same bank when A15 is not being selected. Thus I was actually overwriting the same 32K bank that is used for zero page, stack etc.
So slightly embarassed that I didn't figure out the flaw in my programming sooner, but the conclusion is that I now have a fully working memory map with the following features:
- 128K RAM accessed through 4 banks of 32K
- 64K ROM accessed through 4 banks of 16K
- Write to ROM area results in write to shadow RAM (whichever 32K bank is enabled)
- ROM can be disabled for full read and write access to 63K RAM space (continuous from 0x0800-0xffff : 62K)
- Smaller IO area of 1K (previously I had a 4K IO window)
Works stable at 5.36Mhz. I might be able to go higher, but won't be able to try as I am using a 21.4Mhz master clock divided by two to 10.7Mhz for the TMS9918 video chip, and divided by two again for the 5.36Mhz CPU clock.
I now have so much space, especially compared to the 16K ROM, now I will be able to extend the BIOS, Interpreter and File System to be much more sophisticated such as:
- Updating dflat to include floating point, plus extra high resolution drawing commands and ways to use the banked RAM
- Updating the File System to have a proper command line and remove 8.3 and single root folder restriction
- Updating the BIOS, possibly a basic windowing system.
Well, that will keep my project going for many, many more months!