[comp.sys.apple] Sweet16

rdlanctot@instr.okanagan.bc.ca (Ryan Lanctot) (04/09/89)

There was an article by Woz quite some time ago (+10 yrs) in a back issue of
BYTE where he describes Sweet 16, et al.  I'll look up the date and get back
later.

Ryan Lanctot
<rdlanctot@instr.okanagan.bc.ca>

dseah@wpi.wpi.edu (David I Seah) (04/28/89)

This is kind of old stuff, but I ran across the issue of Byte that had the
Apple II system description by Steve Wozniak:

00	1	Return to 6502 mode
01	2	Branch Always
02	2	Branch no Carry
03	2	Branch on Carry
04	2	Branch on Positive
05	2	Branch on Negative
06	2	Branch if equal
07	2	Branch not equal
08	2	Branch on negative 1
09	2	Branch not negative 1
0A	1	Break to Monitor
0B-0F   1	No operation
1R	3	R<-2 byte constant (load register immediate)
2R	1	ACC<-R
3R	1	ACC->R
4R	1	ACC<-@R, R<-R+1
5R	1	ACC->@R, R<-R+1
6R	1	ACC<-@R double
7R	1	ACC->@R double
8R	1	R<-R-1, ACC<-@R (pop)
9R	1	R<-R-1, ACC->@R
AR	1	ACC<-@R(pop) double
BR	1	compare ACC to R
CR	1	ACC<-ACC+R
DR	1	ACC<-ACC-R
ER	1	R<-R+1
FR	1	R<-R-1

notes
1. All braches are followed by a 1 byte relative displacement.  Works
identically to 6502 branches.
2. Only ADD,SUB, and COMPARE can set carry
3. Notation:
     R = a 16 bit "Register" operand designation, one of 16 labelled 0 to 15
	 (decimal), 0 to F (hexidecimal)
     ACC = register operand R0
     @R = indicrect reference, using the register R as the pointer
     <-, -> = assignment of values
4. Length of instructions: Branches are always two bytes: opcodes followed by
relative displacement.  Load register immediate (1R) is three bytes: the
hexadecimal opcode 10 to 1F followed by the 2 byte literal value of a 16 bit
number.  All other instructions are one byte in length.

And from that issue of Byte (Apr 1977, I think)...some words from the Woz
himself.  Retyped without permission.

The Story of Sweet Sixteen
  While writing Apple BASIC, I ran into the problem of manipulating the 16 bit
pointer data and its arithmetic in an 8 bit machine.
  My solution to this problem of handling 16 bit data, notably pointers, with
an 8 bit microprocessor was to implement a non-existent 16 bit processor in
software, interpreter fashion, which I refer to as SWEET16.
  SWEET16 contains sixteen internal 16 bit registers, actually the first 32
bytes in main memory, labelled R0 through R15.  R0 is defined as the
accumulator, R15 as the program counter, and R14 as a status register.  R13
stores the result of all COMPARE operations for branch testing.  The user
acceses SWEET16 with a subroutine call to hexadecimal address F689.  Bytes
stored after the subroutine call are thereafter interpreted and executed by
SWEET16.  One of SWEET16's commands returns the user back to 6502 mode, even
restoring the original register contents.
  Implemented in only 300 bytes of code, SWEET16 has a very simple instruction
set tailored to operations such as memory moves and stack manipulation.  ost
opcodes are only one byte long, but since she runs approximately ten times
slower than equivalent 6502 code, SWEET16 should be employed only when code is
at a premium or execution is not.  As an example of her usefulness, I have
estimated that about 1K byte could be weeded out of my 5K byte Apple-II BASIC
interpreter with no observable performance degradation by selectively applying
SWEET16. []

huang@husc4.HARVARD.EDU (Howard Huang) (03/07/90)

Scott Alfter writes:
>...I have never figured out what Sweet-16 does;
>it's supposed to be a 16-bit processor emulator or something like that.)

Sweet-16 is Steve Wozniak's 16-bit processor emulator.  It was designed
way back when the Apple II was designed.  It used the first 32 (?) bytes
of zero page memory as a set of sixteen 16-bit registers.  Real hacker
stuff.

There was an article in Byte magazine about Sweet-16, and I think the
same article was reprinted with the original Merlin (Southwestern Data
Systems) documentation.

----------------------------------------------------------------------------
Howard C. Huang                        Internet:  huang@husc4.harvard.edu
Sophomore Computer Science Major       Bitnet:    huang@husc4.BITNET
Mather House 426, Harvard College      UUCP:      huang@husc4.UUCP (I think)
Cambridge, MA 02138                    Apple II:  ftp husc6.harvard.edu

ccasts2@prism.gatech.EDU (Sheldon Simms) (03/13/90)

A few of you who requested Sweet16 intros (specifically logon names: quack
and geary), When I save your mail message I was unaware that the file
system was full, so I lost the addresses to send to. If you could request
again, I would appreciate it. Also, anyone else who didn't see the first
message, If you are interested in Sweet 16 but have no documentation, I
have an intro and a description that I would be happy to send you.

Sheldon Simms
ccasts2@prism.gatech.edu