Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!rochester!pt.cs.cmu.edu!andrew.cmu.edu!mw22+ From: mw22+@andrew.cmu.edu (Michael Alan Wertheim) Newsgroups: comp.sys.apple Subject: Re: what is sweet 16? Message-ID: Date: 12 Apr 89 14:16:24 GMT References: <1568@husc6.harvard.edu>, <10183@polyslo.CalPoly.EDU> Organization: Class of '90, Carnegie Mellon, Pittsburgh, PA Lines: 133 In-Reply-To: <10183@polyslo.CalPoly.EDU> The following is based on an assembly listing of a Sweet-16 program. I have attempted to decipher the instruction set from the listing.... Unfortunately, I did all this at home and forgot to write down the entry point to Sweet-16. (It begins with $F6....) Also, there seem to be two different entry points to Sweet-16, and I'm not sure about the difference between the two. First of all, Sweet-16 was written by Woz in 1977. It is included in the 50-sector INTBASIC file. Sweet-16 is a 16-bit pseudo assembly language. Sweet-16 instructions can be written in-line with 6502 instructions. Sweet-16 gives you 16 16-bit registers, numbered 0 through 15. Register 0 is also Sweet-16's accumulator. Sweet-16 also maintains its own condition codes. I think Sweet-16 preserves the values of the A, X, and Y registers on entry and restores them on exit. For most Sweet-16 instructions: Each instruction is encoded in one byte. The first nibble of the byte specifies the instruction. The second nibble specifies which register is to be used. I have constructed the follwong table based on the Sweet-16 assembly that I have. Unfortunately, the Sweet-16 program that I am looking at (Woz's renumber utility for Integer Basic) only uses about 80% of the Sweet-16 instruction set, so the table is incomplete. Value of Example Encoding for What this first nibble instruction this example example does ======================================================================== 1 SET 3 $1234 13 12 34 Stores the value $1234 in reg 3 2 LD 3 23 Loads accumulator with value stored in reg 3 3 ST 7 37 Stores accumulator value into reg 7 4 LD @1 41 Loads accumulator with contents of memory word whose address is stored in reg 1 5 ST @2 52 Stores accumulator value into the memory word whose address is stored in reg 2 6 LDD @9 69 ? 7 STD @7 77 ? 8 Not used in the program I have 9 Not used in the program I have A ADD 8 A8 Adds value of reg 8 to accumulator and stores sum in accumulator B SUB 5 B5 Subtracts value of reg 5 from accumulator and stores difference in accumulator C POPD @3 C3 ? -- Woz's program has a few POPD instructions but no "PUSHD" instructions. D CPR 8 D8 Compares accumulator value with value in reg 8 E INR 9 E9 Increments reg 9 F DCR 9 F9 Decrements reg 9 If the first nibble of the instruction byte is 0, then the instruction is a branch instruction, which is sometimes a 2-byte instruction. The second nibble determines the type of branch. If needed, the an 8-bit signed offset is stored in the second byte of the instruction. Value of Example Encoding for What this second nibble instruction this example example does ======================================================================== 0 RTN 00 Signifies that the next instructions are 6502 instructions 1 Not used in the program I have 2 BNC label 02 10 Branches to label if carry bit is clear 3 BC label 03 10 Branches to label if carry bit is set 4 Not used in the program I have 5 BM label 05 10 ? 6 BZ label 06 10 Branches to label if zero bit is set 7 BNZ label 07 10 Branches to label if zero bit is clear 8 BMI label 08 10 Branches to label if minus bit is set 9 BNMI label 09 10 Branches to label if minus bit is clear A-F Not used in the program I have Example program: SW16 EQU $F6?? ; Sweet-16 entry point CROUT EQU $FDED ; Character out routine LDA #7 ; Load 7 (ascii bell value) into A JSR CROUT ; Ring the bell JSR SW16 ; Execute the following instructions ; as Sweet-16 instructions SET 1 1000 ; Load reg 1 with 1000 loop DCR 1 ; Decrement reg 1 BNZ loop ; If reg 1 isn't 0, loop back RTN ; Execute the following instructions ; as 6502 instructions JSR CROUT ; Ring the bell again (A is still 7) RTS