Porting Sweet 16 (2004)
6502.org
6502.org
It reminds me a bit of the Apollo Guidance Computer (AGC) which also had a specialized decrement counter and loop instruction (CCS), presumably also just motivated by code size.
Similar to having SWEET16 to augment the 6502, the AGC also used a virtual machine/interpreter to gain additional code density.
https://en.wikipedia.org/wiki/Apollo_Guidance_Computer
https://borja.medium.com/a-glimpse-into-the-apollo-guidance-...
Memory and ROM space was so valuable back then, that I wonder if in retrospect he thought that was 300 bytes (size of SWEET16 interpreter) of ROM space wisely used ?!
That's another somewhat odd omission from SWEET16 - the only way it lets you combine 6502 assembler and SWEET16 code is via the pattern.
<6502 code>
jsr SWEET16 // switch to inline SWEET16 code
<SWEET16 code>
rtn // SWEET16 instruction to switch back to inline 6502 code
<6502 code>
You can't do the opposite - switch to 6502 code for part of a SWEET16 function, or have 6502 code call (vs switch to) a SWEET16 subroutine (or vice versa).
interestingly, this form of argument passing, where the arguments follow the call instruction, was the standard way to pass arguments on the pdp-8. though usually it was just, like, a fixed number of arguments, not an arbitrary-sized blob as in the sweet-16 case
it does seem like it would have been more convenient to orchestrate low-level 6502 subroutines by stringing them together with sweet-16 code than vice versa, but i guess the actual scripting language woz wrote for the apple 2 was integer basic
specialized loop instructions are pretty common actually
One of the things that had made the 6502 so successful, was its extensive use of ‘zero page’, or memory locations 0 to 255. With a very limited number of registers, the 6502 relied on the use of ‘zero page’ to access frequently used values. Access to these values was faster as only a single address byte was needed to specify the address. The 6809 enhanced the use of the zero page by adding a new 8-bit ‘Direct Page’ register which allowed the ‘zero page’ to be moved to anywhere in the 16-bit address space.”
From https://thechipletter.substack.com/p/motorolas-6809-the-best...
"It is a song by Billy Idol, but that's not what this article is about" (my addition)
RENUMBER from Programmer's Aid #1 seems to be the only mainstream thing that used it. Anyone know of anything else?
> BYTE: Isn’t Sweet-16 still used in Apple DOS and ProDOS editor/assemblers?
> WOZNIAK: Yes, it’s used in EDASM , mostly in the editor portion. Randy Wigginton wrote EDASM. He’s worked here since before we even had a company. Lately he’s written the Macintosh word processor – MacWrite. He’s done a lot for the company. and he’s used Sweet-16 in several things he’s done.
At least some 6502 assemblers included Sweet-16 opcodes, so I suspect many assembler programs included Sweet-16 in the parts where speed wasn't as pressing (simply because it was easy to invoke).
Not to mention his thinking out of the box and tool around the issue, trading space vs speed in some scenario.
Conceptually it is closed to dock as it provide an api call for some usage without a full blown vm.
The 6502 instruction set takes advantage of this by having additional instructions to load/store values to zero page as well as ones to load/store to generic 16 bit addresses. An instruction accessing zero page memory will be two bytes (op-code + one byte address), while an instruction accessing a generic address will be three bytes (op-code + two-byte address). The zero page access therefore takes less code space, and will run faster (even though the memory access speed is the same) since there are only 2 vs 3 instruction bytes to fetch.
Given the 10x speed overhead of the SWEET16 interpreter, it'd really not make much difference if it chose to use non-zero page locations for its 16 registers. It makes more difference in hand written code where you are optimizing for every byte of code space and cycle of instruction timing.
For the “not much difference” would it be intended because it is using space to trade of low speed. Given this page use less space and less speed, would it still be important.
As far as speed, given that the interpreter overhead of SWEET16 means it's about 10x slower than 6502 code, adding an extra clock cycle for non-ZP access would at worst make that 11x vs 10x. Would that really make a difference to the cases where it was useful? The trade off is that NOT using ZP for SWEET16 would give those 32 bytes of ZP (16 registered x 2 bytes) back to the developer.
However, It seems that SWEET16 was not much used, and I doubt that any change like this - where to place it's registers - would have made any difference to that. It's maybe interesting to consider would a different interpreted code (with different feature set from SWEET16) have been any more widely used?
Yes, you can consider ZP as a page of registers, but it's not like there was any choice - seeing as the 6502 basically had no registers (just A, X, Y) you had to have your program variables in memory, and ZP was faster/smaller that the alternative!
It's just a shortcut addressing mode.