News for hackers. Stuff that matters.
Re:Why does the Commodore C128 perform poorly when running C... by ajross on Friday December 09, 2022 @03:12PM (#33925940)
The 65C816 is another device that I think gets too much play. It's a relatively straightforward extension of an 8 bit idea to 16 bits, with a few (but just a few) more registers and some address stretching trickery to get more than 64k of (fairly) easily addressible RAM.

Which is to say, the 65C816 did pretty much exactly what the 8086 had done, including a bunch of the same mistakes[1]. Which would have been fine if these were head-to-head competitors. But the 8086 shipped six years earlier!

[1] Though not quite 1:1. Intel had a 16 bit data bus from the start, but the WDC segmentation model was cleaner, etc...

Re:Why does the Commodore C128 perform poorly when running C... by renewedrebecca on Friday December 09, 2022 @07:29PM (#33928373)
Actually, the '816 segmentation model is worse than the 8086. For one thing, code can't overflow from one 64k bank to another. Once the PC goes past $FFFF, it rolls over to $0000 without changing the bank.

The only new registers are the code bank and data bank registers, and I think the code bank register can't even be directly set. You have to do a 24-bit JMP or JSR, and that automatically changes the bank.

The A/X/Y registers all get extended to 16-bits, but A can be addressed as 'A' and 'B', two 8-bit registers. A mode change is necessary for this.

It's a particularly hard CPU to generate code for. There's a commercial, free to use for private use C compiler, but most people use assembler.

Pointers are a pain in the butt... You have to use a direct page memory location to fake a 24-bit pointer. On the 8086, you could at least use the ES register to point anywhere without a DP access.

Re:Why does the Commodore C128 perform poorly when running C... by pcwalton on Friday December 09, 2022 @08:29PM (#33928831)
> Once the PC goes past $FFFF, it rolls over to $0000 without changing the bank.

I had forgotten about that! Yeah, that's horrendous.

> The only new registers are the code bank and data bank registers

There's the relocatable DP register, which you could use as a frame pointer (I've written code that does this). It's still quite awkward though.

> I think the code bank register can't even be directly set. You have to do a 24-bit JMP or JSR, and that automatically changes the bank.

To be fair that's how x86 works too, right? You have to do a far jump or far call to switch CS. (Also you could push addresses on the stack and do a far return on both 65816 and x86.)

> It's a particularly hard CPU to generate code for. There's a commercial, free to use for private use C compiler, but most people use assembler.

This is absolutely true. 6502 derivatives are almost uniquely hostile to C-like languages—witness all the failed attempts at porting LLVM to them—and the 65816 is no exception. I'm pretty sure that in an alternate world where 6502-based microcomputers had become dominant, the classic 6502 ISA would have quickly become relegated to some sort of legacy emulation mode, and the "normal" ISA would be nothing like it, unlike the relatively modest extensions that the 286 and 386 made to the 8086 ISA.

Re:Why does the Commodore C128 perform poorly when running C... by mikepavone on Friday December 09, 2022 @04:51PM (#33926825)
> but the WDC segmentation model was cleaner, etc...

Eh, I don't think this is generally true. Intel's decision to have the segments overlap so much was definitely very short-sighted, but the 8086 has a big advantage in having multiple segment registers with the ability to override which is used via an instruction prefix. This makes copying data between two pages straightforward on the 8086 whereas you need to constantly reload the databank register on the 65C816.

I think as a pure 16-bit design the 8086 is actually pretty good. It's not at all a forward-looking design though so it wasn't well suited to being the basis of the default PC architecture for decades to come.

Re:Why does the Commodore C128 perform poorly when running C... by pcwalton on Friday December 09, 2022 @08:36PM (#33928881)
> This makes copying data between two pages straightforward on the 8086 whereas you need to constantly reload the databank register on the 65C816.

Don't the MVN and MVP block transfer instructions let you specify separate data banks for the source and the destination?

(I agree that the 8086 was a superior design to the 65816 in most other ways.)

Re:Why does the Commodore C128 perform poorly when running C... by mikepavone on Friday December 09, 2022 @11:36PM (#33929891)
You're right. If all you want to do is literally copy bytes without any other processing then those instructions will handle it.