I have started my journey into 65816 native mode programming. Doing things to work outside of the first 64K requires a lot of re-thinking. The 65816 also allows for greater flexibility.
Having a repository of useful code snipets would be useful. I'm probably trying to create code that many have already done. Does anyone have a good source of 65816 code snipets?
Also, Mike, could we add a place on 6502.org for these to be stored?
I am working on font generation using look-up tables and block move routines. I would be happy to share these once they are optimized and cleaned up.
Any thoughts or suggestions?
Daryl
65816 Native Mode Programming
There is also the 6502.org wiki that someone else had started. The nice thing about the wiki is you won't have to depend on Mike to put up a cookbook. See viewtopic.php?t=1224&highlight=wiki
That being said, yes, native mode is essentially a whole new CPU in terms of what now becomes possible. The largest intellectual barriers, I find, comes from the following:
1) ROM is expected to be at $00xxxx-$00FFFF, which seems silly. It would have made things MUCH easier had WDC moved the ROM to $FFxxxx-$FFFFFF, especially from an address decoding point of view! The Apple IIgs designers apparently felt so strongly about this that they engineered their chipset specifically to work around this issue. When _VP is asserted, the ROM (which normally sits in banks $FF and $E1) vectors are banked into bank zero. These vectors point into I/O space (which for Apple II compatibility, sits in bank zero anyway at $00C0xx), which then have hard-wired registers containing long-jumps into bank $E1.
In my Kestrel-2 design, I'm leaving the ROM in bank zero (RAM from $000000-$007FFF, ROM at $008000-$00FFFF, RAM again from $010000-$FEFFFF, and I/O from $FF0000-$FFFFFF), but am planning on an I/O control bit that will disable ROM and reveal the RAM beneath it (e.g., a Commodore-like "layering" approach).
2) Stack and direct page are hardwired to use bank zero.
3) Indirect jumps are also hardwired to be bank zero, BUT not indirect-indexed. E.g., JMP ($ABCD) will always fetch its vector from $00ABCD, while JMP ($ABCD,X) will use the current program bank. The latter is more powerful anyway, but, it's a gotcha you gotta be aware of.
1) ROM is expected to be at $00xxxx-$00FFFF, which seems silly. It would have made things MUCH easier had WDC moved the ROM to $FFxxxx-$FFFFFF, especially from an address decoding point of view! The Apple IIgs designers apparently felt so strongly about this that they engineered their chipset specifically to work around this issue. When _VP is asserted, the ROM (which normally sits in banks $FF and $E1) vectors are banked into bank zero. These vectors point into I/O space (which for Apple II compatibility, sits in bank zero anyway at $00C0xx), which then have hard-wired registers containing long-jumps into bank $E1.
In my Kestrel-2 design, I'm leaving the ROM in bank zero (RAM from $000000-$007FFF, ROM at $008000-$00FFFF, RAM again from $010000-$FEFFFF, and I/O from $FF0000-$FFFFFF), but am planning on an I/O control bit that will disable ROM and reveal the RAM beneath it (e.g., a Commodore-like "layering" approach).
2) Stack and direct page are hardwired to use bank zero.
3) Indirect jumps are also hardwired to be bank zero, BUT not indirect-indexed. E.g., JMP ($ABCD) will always fetch its vector from $00ABCD, while JMP ($ABCD,X) will use the current program bank. The latter is more powerful anyway, but, it's a gotcha you gotta be aware of.
kc5tja wrote:
There is also the 6502.org wiki that someone else had started. The nice thing about the wiki is you won't have to depend on Mike to put up a cookbook. See viewtopic.php?t=1224&highlight=wiki
dclxvi,
Can you add a 65816 Native Mode software section to your wiki? It would be better to keep it seperate from the 6502 code as the examples would not be cross compatible in most cases.
Daryl
Actually, if you have a membership on the wiki, you can edit it yourself. Here is the current source:
Just change that to:
or something along those lines. The part before the pipe is the webpage name on the wiki, and the part after the pipe is what we humans see on the website. If the two are the same, you can forego the pipe notation and just use [[[a-webpage-name]]] like that.
Code: Select all
++ Software Categories
* [[[software-math|Math]]]
++ Miscellaneous Software Articles
* [[[software-incdec|INC and DEC techniques]]]
* [[[software-delay|Delay routines]]]
Code: Select all
++ Software Categories
* [[[software-math|Math]]]
++ Software by Processor
* [[[software-6502|6502 Software]]]
* [[[software-65816|65816 Software]]]
++ Miscellaneous Software Articles
* [[[software-incdec|INC and DEC techniques]]]
* [[[software-delay|Delay routines]]]
kc5tja wrote:
There is also the 6502.org wiki that someone else had started.
8BIT wrote:
Does anyone have a good source of 65816 code snipets?
(snip)
I am working on font generation using look-up tables and block move routines.
(snip)
I am working on font generation using look-up tables and block move routines.
Other routines/techniques are:
1. m & x flag independence
2. Relative JSR and data
3. Parameter passing via the stack (it's not the only to do it, but it's available)
8BIT wrote:
Can you add a 65816 Native Mode software section to your wiki? It would be better to keep it seperate from the 6502 code as the examples would not be cross compatible in most cases.
Most 6502 code should be applicable to the 65816, so a "6502 specific" category is probably not necessary.
kc5tja wrote:
ROM is expected to be at $00xxxx-$00FFFF, which seems silly.
kc5tja wrote:
When _VP is asserted, the ROM (which normally sits in banks $FF and $E1) vectors are banked into bank zero. These vectors point into I/O space (which for Apple II compatibility, sits in bank zero anyway at $00C0xx), which then have hard-wired registers containing long-jumps into bank $E1.
kc5tja wrote:
Indirect jumps are also hardwired to be bank zero, BUT not indirect-indexed. E.g., JMP ($ABCD) will always fetch its vector from $00ABCD, while JMP ($ABCD,X) will use the current program bank.
kc5tja wrote:
The part before the pipe is the webpage name on the wiki, and the part after the pipe is what we humans see on the website.
dclxvi wrote:
kc5tja wrote:
ROM is expected to be at $00xxxx-$00FFFF, which seems silly.
In my (not yet published) 65816 design, I of course have to use bank $00 as boot area, but will remap that after initialization so I can have bank $00 with 64k RAM.
André
dclxvi wrote:
3. Parameter passing via the stack (it's not the only to do it, but it's available)
Quote:
Yes it does, but this is a ramification of the fact that RESET puts the 65816 in emulation mode, rather than native mode.
Quote:
It's able to figure out that [[[A Webpage Name]]] means the page a-webpage-name, but I like to explicitly state both the page name and what is displayed for clarity's sake.
kc5tja wrote:
I just wrote a book on this topic. It is live on the Wiki now.
Incidentally, I've added the memory move, and the relative JSR/data/etc., so Daryl, there will be a pop quiz on Monday. Please bring a #2 pencil.
kc5tja wrote:
Actually, that gives me a great idea -- use the CPU's E pin to 8 XOR gates covering A23-A16. That would work great. That forces bank 0 to be bank $FF when in emulation mode. That requires the ROM setup an image of the vectors in low RAM prior to engaging native mode, but it should work.
Anyway, we could probably fill a thread just on the 65816 vectors.
kc5tja wrote:
I don't because that requires me to constantly look up page names. This brings me back to good wiki style -- a page name should match its file name, unless circumstances require otherwise.
In practice... I started out by organizing the wiki as something of hierarchical table of contents, and for the most part it's the (sub)table of contents pages that contain links to other pages, and not the articles (including your book). The only place I can recall linking one article to another is the cube root article and that's because I didn't feel like explaining the algorithm
Again, one of the reasons I set up a wiki was to get opinions and inspire discussion. The nice thing is we can try different approaches to see the pros and cons. There's room for a variety of styles.
All IMO.
dclxvi wrote:
Incidentally, I've added the memory move, and the relative JSR/data/etc., so Daryl, there will be a pop quiz on Monday. Please bring a #2 pencil. 
I looked over your relative JSR/data/etc code. Interesting ideas if you want to easily use relocatable code.
Thanks for helping to get this idea rolling!!!!
Daryl
kc5tja wrote:
I just wrote a book on this topic. It is live on the Wiki now.
I added stuff to Daryl's memory fill article too. I know, I'm out of control!