6502 redundant, missed, and suggested features
Re: 6502 redundant, missed, and suggested features
Probably they didn't feel like adding too much detail to the text, when the description below shows exactly what's happening.
Or, the designers intended to use the PC, and get a full 16 bit increment for free, but ran into some problems and switched to ALU increment late in the design process.
Or, the designers intended to use the PC, and get a full 16 bit increment for free, but ran into some problems and switched to ALU increment late in the design process.
Re: 6502 redundant, missed, and suggested features
My suspicion is that by the time that manual was written, some knowledge was lost.
The usual use case for JMP(abs) is surely a single JMP to indirect a vector. It's unlikely that the vector will be placed at the end of a page, so almost everyone will be unaware of the bug.
Edit: I see that indirect threaded code could possibly hit this, if it didn't take care.
The usual use case for JMP(abs) is surely a single JMP to indirect a vector. It's unlikely that the vector will be placed at the end of a page, so almost everyone will be unaware of the bug.
Edit: I see that indirect threaded code could possibly hit this, if it didn't take care.
Re: 6502 redundant, missed, and suggested features
Just for historical interest, I had a look to see what's the earliest mention of this bug, and the earliest I found is a note by Heinz J Schilling in 6502 User Notes newsletter, issue 15, June 1979.
http://archive.6502.org/publications/65 ... df#page=24
http://www.classiccmp.org/cini/pdf/KIM% ... df#page=24
It would be interesting to hear of an earlier mention.
Edit: I see that Bob Sander-Cederlof's newletter "Apple Assembly Lines" trumpets this bug note in the first issue, October 1980. I'm thinking therefore that it would not already be common knowledge.
(Again, a confusion between the address bus and program counter!)
Edit: downthread, BDD notes that Leventhal's 1979 book describes the misbehaviour, and it looks like the book was finalised no earlier than April 1979.
http://archive.6502.org/publications/65 ... df#page=24
http://www.classiccmp.org/cini/pdf/KIM% ... df#page=24
It would be interesting to hear of an earlier mention.
Edit: I see that Bob Sander-Cederlof's newletter "Apple Assembly Lines" trumpets this bug note in the first issue, October 1980. I'm thinking therefore that it would not already be common knowledge.
Quote:
There is an error in the JUMP INDIRECT instruction of ALL 6500 family CPU chips, no matter where they were made. This means the error is present in ALL APPLES. This fatal error occurs only when the low byte of the indirect pointer location happens to be $FF, as in JMP ($08FF). Normally, the processor should fetch the low-order address byte from location $08FF, increment the program counter to $0900, and then fetch the high-order address byte from $0900. Instead, the high-order byte of the program counter never gets incremented! The high-order address byte gets loaded from $0800 instead of $0900! For this reason, your program should NEVER include an instruction of the type JMP ($xxFF).
Edit: downthread, BDD notes that Leventhal's 1979 book describes the misbehaviour, and it looks like the book was finalised no earlier than April 1979.
Last edited by BigEd on Fri Aug 26, 2016 6:40 am, edited 2 times in total.
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 6502 redundant, missed, and suggested features
litwr wrote:
BigDumbDinosaur wrote:
If using the 65C02 or 65C816, there is the JMP (<addr>,X) instruction, which requires no preparation of any jump vectors. You use it with a table containing 16 bit addresses in little endian order. The following code does the work:
Quote:
GARTHWILSON wrote:
JMP (<addr>) is not a ZP instruction.
Most of the discussion of the JMP (<addr>,X) bug has been focused on using a table, which requires a jury-rigged operation on the NMOS anyway, unlike the CMOS. Whether using a table or not, you shouldn't have to put assembler directives before the address to prevent the page boundary straddling or add another byte at the beginning of the next page. It should just work, and on the CMOS, it does.
Quote:
Almost all of its additional instructions have very little importance. They may make codes slightly faster and smaller but in the completely tiny scale. I can estimate less than 2% smaller size and less than 1% faster speed.
Quote:
I want only BIT #imm and DEA, INA of its instructions. Even the useful BIT #imm can't set N and V flags.
Sometimes 65c02 is even slower than 6502.
The major evil of CMOS 6502 is the occupation of the valuable opcodes by these unimportant instructions. This had halted the natural development of 6502. 65816 and even 4510 had to follow this heavy and bad inheritance.
Instead of these "occupants" maybe placed much more powerful instructions: 16 bit arithmetic, POP XY, PUSH XY, work with two (or more) segment registers (it might give short and fast operations with 20 or 24 address bus and the relocation of codes), 16-bit accumulator, maybe another 16 bit accumulator, etc.
Quote:
I have also to note that we have tens of thousands (or even more) ML programs for NMOS 6502.
BigEd wrote:
Just for historical interest, I had a look to see what's the earliest mention of this bug, and the earliest I found is a note by Heinz J Schilling in 6502 User Notes newsletter, issue 15, June 1979.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: 6502 redundant, missed, and suggested features
For some time I've thought about a 65c02 upgrade board for the C64.
Someday, I will. It will break a lot of software, but for my purposes, I won't be too concerned.
If I get time this winter, I'd like to put a 65c02 in a PET and see what the consequences are. Unfortunately most of the PET software I have already doesn't work, so I might not find out.
I did have possession of a couple Apple //es that were dealer "enhanced." I don't have any recollection who the dealer was, but apparently they had forged ROMs. Visually they looked just like Apple ROMs should look, but they must have relied on the 65c02. Several times over the years I put known good NMOS 6502s in them and they both failed to boot. Unfortunately I think I sold both of those machines in recent years.
Someday, I will. It will break a lot of software, but for my purposes, I won't be too concerned.
If I get time this winter, I'd like to put a 65c02 in a PET and see what the consequences are. Unfortunately most of the PET software I have already doesn't work, so I might not find out.
I did have possession of a couple Apple //es that were dealer "enhanced." I don't have any recollection who the dealer was, but apparently they had forged ROMs. Visually they looked just like Apple ROMs should look, but they must have relied on the 65c02. Several times over the years I put known good NMOS 6502s in them and they both failed to boot. Unfortunately I think I sold both of those machines in recent years.
Re: 6502 redundant, missed, and suggested features
KC9UDX wrote:
I did have possession of a couple Apple //es that were dealer "enhanced." I don't have any recollection who the dealer was, but apparently they had forged ROMs. Visually they looked just like Apple ROMs should look, but they must have relied on the 65c02. Several times over the years I put known good NMOS 6502s in them and they both failed to boot. Unfortunately I think I sold both of those machines in recent years.
See https://en.wikipedia.org/wiki/Apple_IIe#Enhanced_IIe.
Re: 6502 redundant, missed, and suggested features
rwiker wrote:
KC9UDX wrote:
I did have possession of a couple Apple //es that were dealer "enhanced." I don't have any recollection who the dealer was, but apparently they had forged ROMs. Visually they looked just like Apple ROMs should look, but they must have relied on the 65c02. Several times over the years I put known good NMOS 6502s in them and they both failed to boot. Unfortunately I think I sold both of those machines in recent years.
See https://en.wikipedia.org/wiki/Apple_IIe#Enhanced_IIe.
If you have an Enhanced //e, you can take the 65c02 out and put in a 6502, and it will run all day long. Except for the two that I had, and maybe others, but I've not heard of anyone else with this situation.
At least this is what has been reported to me by other owners who were perplexed when I told them that the Enhanced ROM requires a 65c02.
Re: 6502 redundant, missed, and suggested features
GARTHWILSON wrote:
It can be used with the index registers in 8-bit mode as well. The Eyes & Liechty programming manual specifically shows it in both 8- and 16-bit mode, on page 382 of my old paper copy. (The .pdf that was distributed until early last year didn't have the same page numbers.)
Code: Select all
lda #index ;zero-based routine index
asl a ;double it
tax ;now absolute index
jmp (table,x) ;goto routine
BigEd wrote:
I see that it's inconvenient to have to account for the difference between the 02 and the C02. But, I think it may still be possible to use a 257 byte table which will suit both CPUs?
Code: Select all
ldx divisor
jmp (divjmp,X)
GARTHWILSON wrote:
The '816 has most of these, plus instructions and addressing modes that are totally impractical to do on the '02 at all. (Keeping with the topic title), PEA for example is a three-byte instruction that pushes a two-byte literal (its operand), which is typically an address but it can also be data, onto the stack, without affecting the processor registers. One use of it is to pass data to a subroutine. For a 6502 to synthesize it requires six instructions, and more if you need to save A. It's a similar story for PEI. PER requires 18 6502 instructions to synthesize (and more if you need to save A), 11 of those being in a subroutine. BRL (Branch Relative Long) and a four-byte (two-instruction) BSR (Branch to SubRoutine, or Branch, Saving Return address) with a 16-bit relative address are valuable, especially in relocatable code. So are the extra stack-addressing modes and the 16-bit stack pointer permitting much heavier use of the hardware stack for passing lots of parameters, as in C or recursive functions that may run the '02 out of stack space. Many features of the '816 make it far more suitable for multitasking.
GARTHWILSON wrote:
BigEd wrote:
Just for historical interest, I had a look to see what's the earliest mention of this bug, and the earliest I found is a note by Heinz J Schilling in 6502 User Notes newsletter, issue 15, June 1979.
Re: 6502 redundant, missed, and suggested features
litwr wrote:
IMHO LSR4 instruction would be worth to mention too. 6502 requres 4 LSR to get the higher nibble. The lower nibble can be get by AND #15. So what's the purpose of SWN (swap nibbles)? It is better to have z80 RLD which allows to make fast 4-bit shift of the sequence of bytes.
For example 4bit*4bit math (x*y):
Code: Select all
TXA
AND #$0F
ORA ShiftLtoH,Y
TAX
LDA MultTable,XWithout the shift table:
Code: Select all
TXA
ASL
ASL
ASL
ASL
STA $zp1
TYA
AND #$0F
ORA $zp1
TAX
LDA MultTable,X-
White Flame
- Posts: 704
- Joined: 24 Jul 2012
Re: 6502 redundant, missed, and suggested features
BigEd wrote:
I see that it's inconvenient to have to account for the difference between the 02 and the C02. But, I think it may still be possible to use a 257 byte table which will suit both CPUs?
Re: 6502 redundant, missed, and suggested features
Klaus2m5 wrote:
However, it is bold to tie the assumption of a bug in the 65c02 to the very special case that you are talking about. It is like calling the missing undocumented opcodes in the 65C02 a bug. I am sure, that there are much more coders having been bitten by the lack of the carry into the upper byte of the indirect address, than there are coders facing the same problem as you.
GARTHWILSON wrote:
If everything has to be pulled down to the weakest version, what's the sense in making any improvements?? If you're writing software for something like the venerable C64, using C64 kernel entry points and hardware, then by all means, avoid the extra CMOS instructions and addressing modes. It makes total sense. There never was an NMOS 6510 anyway. But for new builds, there's no sense in using the NMOS, and I will never go back to it.
kakemoms wrote:
26 cycles. One 256 byte table. If you had a swap function you could shave off 6 cycles, but it would still be faster with the extra table.
White Flame wrote:
Depending on how crucial speed is, I would put the compatibility into the code, not into the data structure. If the index is always odd, then a simple DEX brings it back into 0-254 range with even numbers and there's no page overflow.
Re: 6502 redundant, missed, and suggested features
Nobody ever complained, because everyone was aware of the behaviour, and acted accordingly.
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: 6502 redundant, missed, and suggested features
litwr wrote:
IMHO The problem of JMP (xxFF) is completely contrived and artificial.
Methinks you are beating a dead horse.
Quote:
GARTHWILSON wrote:
If everything has to be pulled down to the weakest version, what's the sense in making any improvements?? If you're writing software for something like the venerable C64, using C64 kernel entry points and hardware, then by all means, avoid the extra CMOS instructions and addressing modes. It makes total sense. There never was an NMOS 6510 anyway. But for new builds, there's no sense in using the NMOS, and I will never go back to it.
x86? We ain't got no x86. We don't NEED no stinking x86!
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: 6502 redundant, missed, and suggested features
litwr wrote:
My point is in fact that the writers of this enormously big amount of software never complained about JMP (xxFF).
Quote:
Another my point that the advancement from NMOS 6502 to CMOS was very tiny and it has even several back steps (the creation of JMP (xxFF)
Quote:
the occupation of valuable opcode space by the unimportant instructions,
Quote:
slow down the redundant BCD mode,
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: 6502 redundant, missed, and suggested features
litwr wrote:
Could you show any practical example which shows the situation in reverse?
When creating a mixed data structure like this it's desirable to freely allocate space exactly as needed. But if you allocate space exactly as needed then occasionally a destination value will straddle a page boundary. With NMOS 6502 this is a dangerous anomaly.
In the bad old days folks were forced to check for this condition every time before allocating space for a destination value. If the next available space happened to be at $xxFF then remedial action was required, such as sticking an extra, unused byte into the structure -- ie, wasting the byte at $xxFF -- to ensure proper alignment. Does that sound messy? It was!
Now we have the 'C02, and no anomalies. JMP (abs) just works.
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html