Jump to content
Sign in to follow this  
BruceMcF

SweetCX16

Recommended Posts

Just a note that my open source implementation of the venerable Sweet16 VM by Woz for the AppleII has a SweetCX16.asm version oriented to the GoldenRAM at $0400-$07FF.

All of my testing was of the C64 version assembled to the C64 $C000-$CFFF Golden Ram location, but if anyone wants to assemble it and run it in the CX16 emulator, I'd welcome feedback ... and bug reports, of course, in case my testing didn't cover as many edge cases as it should have done.

https://github.com/BruceMcF/Sweeter16

  • Like 2

Share this post


Link to post
Share on other sites

Ed Minchau apparently is working on a set of 16 bit "kernal" ops... I directed him to you on the Facebook page.

Edited by rje
  • Like 1

Share this post


Link to post
Share on other sites

Well, what I've come up with is 18 subroutines that handle 16 bit operations much like a Kernal call.  I have set it up so that any two consecutive bytes in zero page can be a 16 bit register.  So, for instance, to add the 16 bit value stored in 3C,3D to the 16 bit value stored in 1A,1B, the syntax would be:

LDX# 3C

LDY# 1A

CLC

JSR ADXY

This adds the values and returns the low byte in X and high byte in Y, and affects the Z,C,N, and V flags the same way that ADC does.

One can also use a sort of immediate mode. For instance, subtracting the hex value $4C1E from the 16 bit value stored in zero page addresses 4E,4F:

LDA# 4E

LDX# 1E

LDY# 4C

SEC

JSRA SBA#

Results stored in X= lo byte Y=high byte, and the Z,C,N, and V flags are affected the same way as with SBC.

 

These subroutines are stored in Golden RAM as part of my upcoming update to my CX16 assembly language editor, but if people want I can post it here too, it's only 350 bytes.

  • Like 2

Share this post


Link to post
Share on other sites

Yes, Sweet 16 was more intended to be used as a sequence of Sweet 16 operations for a set of things involving 16bit values. There's no particular reason they couldn't both be provided .... the 2page version can easily be assembled to any two available pages in Low RAM, including the top half of Golden RAM.

My focus has rather been on getting the first of the series of Forth's up an running ... this version has got a working Interpreter for calculations and just today I got the defining words to work, but it's still buggy, so maybe next week unless I get really lucky and can post the pre-alpha early this week.

Edited by BruceMcF
  • Like 1

Share this post


Link to post
Share on other sites
On 8/15/2020 at 5:40 PM, BruceMcF said:

Yes, Sweet 16 was more intended to be used as a sequence of Sweet 16 operations for a set of things involving 16bit values. There's no particular reason they couldn't both be provided .... the 2page version can easily be assembled to any two available pages in Low RAM, including the top half of Golden RAM.

My focus has rather been on getting the first of the series of Forth's up an running ... this version has got a working Interpreter for calculations and just today I got the defining words to work, but it's still buggy, so maybe next week unless I get really lucky and can post the pre-alpha early this week.

Ah Forth!  So please, can someone explain to me why I have such a resistance to the Forth language?  It seems to tick a lot of the boxes for a great 8-bit language.

Share this post


Link to post
Share on other sites

A lot has to do with getting a good introduction to the language. A lot of Forth implementers are better at talking to hardware than talking to people.

RPN takes getting used to, for people used to languages that say "do this with these things and this option", a language that just says " do this, now do this, now do this, ..." over and over again takes getting used to

Also, a lot of Forth source is badly laid out, trying to mimic the layout of a C family language instead of respecting what the language is actually doing.

Since my Forth is aligned with Standard Forth, I will include either a link to or PDF of the ANS Version of Starting Forth for people just getting started.

Share this post


Link to post
Share on other sites

One cute trick for 16 bit zeropage ops with a dedicated 16bit accumulator in (either zp or elsewhere) is (in Golden RAM)

DO16: STA OPLO : STA OPHI

REPEAT16: LDA D16ACC

OPLO: AND $00,X : STA D16ACC : LDA D16ACC+1

OPHI: AND $01,X : STA D16ACC : RTS

Where you put the address of the low byte in X and the zeropage X-indexed opcode in A and call DO16 ... does AND/ORA/EOR/LDA/STA and with proper setting or clearing of carry SBC and ADC. REPEAT16 when you are doing the same operation again. Only need to do a dedicated 16bit compare to get all 8 fundamental two-input ops.

19 bytes with ZP accumulator and routine in Golden RAM, 23 bytes with accumulator in golden RAM as well.

A second version with zp,X as the accumulator and zp

A second version with (zp),Y as the target address and you have quite a lot of flexibility in very little space.

And if a single accumulator feels a little restrictive:

EX16: LDY $00,X : LDA D16ACC : STY 16ACC : STA $00,X : LDY $01,X : LDA D16ACC+1 : STY D16ACC+1 : STA $01,X : RTS

~~~~~~~~~~~~~

16 bit CMP can be done ...

D16TMP: !byte 0

D16CMP: LDA $00,X : SEC : SBC D16ACC : STA D16TMP : LDA$01,X : SBC D16ACC+1 : BNE + : LDA D16TMP : BPL + : LDA #1

+ RTS

But maybe separate Less Than and Equal tests take about the same space:

D16LESS: LDA $00,X : SEC : SBC D16ACC : LDA $01,X : SBC D16ACC+1 : RTS

D16EQ: LDA $00,X : CMP D16ACC : BNE + : LDA $01,X : CMP D16ACC+1

+ RTS

 

 

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

Please review our Terms of Use