SweetCX16

All aspects of programming on the Commander X16.
BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

SweetCX16

Post by BruceMcF »


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

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

SweetCX16

Post by rje »


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

Ed Minchau
Posts: 508
Joined: Sat Jul 11, 2020 3:30 pm

SweetCX16

Post by Ed Minchau »


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.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

SweetCX16

Post by BruceMcF »


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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

SweetCX16

Post by rje »



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.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

SweetCX16

Post by BruceMcF »


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.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

SweetCX16

Post by BruceMcF »


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

 

 

 


 

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

SweetCX16

Post by rje »


Bruce, I'm going to check out your repo.  I just spent an evening porting in SWEET16 to the cc65 assembler, but I haven't tested it out.  I juggled the memory load address so that it loads at $0443 -- that makes sure the last 250 bytes begin right on $0500.

For your amusement.  https://github.com/bobbyjim/x16-sweet16

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

SweetCX16

Post by rje »


Wow, I just read your repo README, and I'm impressed.  Totally going to check out your implementation. 

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

SweetCX16

Post by rje »


SweetCX16.asm line 72 should be $0400, not $04000, yes?

Post Reply