Some of you might have read that the biggest bug (so far) with my Crude 65816 Emulator was that I had coded the routine for LDA Absolute Y Indexed wrong. It's instructive to look at that part of Tali Forth for the 6502 more closely, especially at lines 1321 and 1324 (some whitespace lines omitted):
Code:
1314 ldy #SP0
1315 stx TMPX
1317 _loop: ; ironically, we need the stack for this
1321 lda 0,y
1322 sta 2,x ; MSB first
1323 dey
1324 lda 0,y
1325 sta 1,x ; then LSB
This is part of the routine for ".S", the Forth command to print non-destructively what's on the Data Stack. I don't actually
remember coding this, but looking at the code, I'm pretty sure I know what I was thinking: I need the stack to print the stack (this calls "." (dot) to print the number), so I'll just use LDA Zero Page Y Indexed so I can preserve X as the Data Stack Pointer. Clever, huh?
Well, no. There is no such instruction, even on the 65c02. In fact, this is really LDA Absolute Indexed Y, which should have been written as
Code:
lda 0000,y
to make that clear. Which is also why I'm sure I was under the impression that there is such an instruction. It just happens to work by accident, no thanks to me.
So what's the big problem? It means that Tali Forth cannot currently run in a different bank of the 65816, because it assumes that Zero Page is in the first page of the program's bank. Loading the program into bank 01, for instance, setting DBR to 01 and then jumping to 01:e0000 will not work (there are other problems like the interrupt routines, but those are obvious). It's an example of why adapting 6502 programs to the 65816 is a pain unless they are cleanly coded. I'm going to have to figure out a different way to do this at some point.
As an aside, this is an example of why I have become disenchanted with the tradition assembler notation for the 6502/65816. The Ophis assembler has no way of knowing that I was trying to code some hypothetical "LDA Zero Page Y Indexed" mode and thinks I'm just too lazy to type three extra zeros for Absolute Y Indexed (which I wish I could claim were true, alas). In the "Typist's Notation" I've been using for my simple Forth assembler, this would have been (with operands switched around here for readability):
Code:
1314 ldy.# SP0
1315 stx.z TMPX
1317 -> loop \ ironically, we need the stack for this
1321 lda.zy 0
1322 sta.zx 2 ; MSB first
1323 dey
1324 lda.zy 0
1325 sta.zx 1 ; then LSB
Even while typing, the "lda.zy" would not have triggered the syntax highlighting rules I have set up in vim, warning me that something is wrong, and the assembler would have aborted because there is no such instruction.