Hi guys, I started working on a 6502 graphing calculator a few years ago and I have been thinking about it again lately. I had an ATF1508 setup working at the time, so I can work on a little more complicated memory map. What would you think about this kind of set up?
RAM: 512k
ROM: 2k
0000 - 00FF = banked zero-page
0100 - 01FF = banked stack
0200 - 03FF = scratch memory (unbanked)
0400 - 7FFF = banked lower window for data
8000 - F7FF = banked upper window for data/program
F800 - FFFF = ROM (unbanked)
My idea was to have independent 3 bit counter chips for the zero page and stack so I would have 8 of each in the 512k RAM. For a lot of tasks I know I can just reuse counters and scratch variables in the zero page, but if I want a few hundred bytes to work with in a function or I run out of zero page, I can advance to a new one when I call a new function. Each function can also have its own temporary stack if needed. The downside is that functions that use a new zero page won't have access to the old zero page, so I would have to push any values I need onto the stack first and then copy them back off after I advanced to the new zero page. I know that would be slow, so I would only use a new zero page for functions where I really need the extra memory and can take the speed hit.
I would like to use an SD card to hold the firmware, so the ROM would just need to load that into the appropriate RAM banks, which shouldn't take up much space. Either the CPLD or two buffer chips would control the upper 4 bits of the 512k of RAM to give me two 32k windows (minus the few kb listed above.) I would put any bank switching code in the ROM. Jumping to code in another bank would work by pushing the return and destination banks and addresses onto a stack in the scratch area (which is not banked), then jumping to a function in the ROM that changes the bank and jumps to that address. If there is room, I could also put code in ROM to copy data between banks by setting the one window to the destination range and the other to the source range. If there is not enough room in ROM and I have to run the copy code from the upper window, I could advance to a new zero page, fill it up from the source bank then switch to the destination bank and empty the zero page, which would reduce the amount of time I spend switching banks. I would only run code from the upper bank since jump addresses would have to be reassigned to run the same code from the lower window (unless I only use indirect jumps, which seems like a bad idea.)
I know jumping to another bank to execute code then jumping back complicates things but I do think I will need to be able to do that. Some of the nicer calculators can solve symbolically, so doing "solve(2x=y,x)" returns "x=y/2" rather than just complaining that it can't find y. I think that kind of functionality, for example, should be available at any time to any program running, but I don't think that kind of solver, along with a GUI, graphing, trig tables, and a simple BASIC-like programming language could fit into 32k (but let me know if you disagree). I also thought it would be a good idea to map the LCD into the zero page since there will be a lot of data to dump to it.
The other idea I had was somehow getting debug information out of the calculator over serial to be able to single step the processor and see what it is doing every cycle. If there is room, I thought about putting some kind of 32-bit wide memory with a counter on there that would record the data bus, address lines, and some control signals every cycle. Then, in debug mode the interrupt would be called every single instruction. The CPLD would monitor the interrupt line and stop the counter when the interrupt was called. The interrupt code would read the data from the 32-bit memory and send it out over serial, so you could see the address and data lines for the last few cycles. Another way might be to divide the clock by 8 and store that information in the main RAM instead but only pulse the 6502 every eighth cycle. That would lower the max speed of the system though I think.
What do you guys think? Please tell your suggestions (other than switch to a 65816
)