I am filled with a mixture of pride and shame
Posted: Thu Sep 09, 2010 1:03 am
And this was the only place I could think of to ( confess | brag about ) what I have done. Here's my 2ROT primitive, which rotates the stack from ABC -> BCA. All values are four-byte doubles. The data stack is indexed by X and divided between several bytes of stackl and an equally sized stackh region. Top of stack is special gets its own 2-byte zero page storage.
Waddya think, sirs?
It should also be noted that stackl = $00 and stackh = $30. (I have about 18 more bytes available for stack but this makes it easier to debug in xpet), otherwise I'd have to begin with:
Waddya think, sirs?
Code: Select all
;--------------------------------------------------------------
;
; 2ROT ( hi3 lo3 hi2 lo2 hi1 lo1 -- hi2 lo2 hi1 lo1 hi3 lo3 )
;
tworotlfa .word $adde
.byt (tworot-*-1)|bit7
.asc "2RO","T"|bit7
tworot dex
lda tos+1
sta stackh,x
lda tos
sta stackl,x ; enclose TOS into the indexed split stack
lda #%001101
sta tos ; LSR-loop flags
lda #$ca ; dex
sta l057 ; unnecessary except in case of NMI (improbable on a PET)
l056 ldy 4,x ; pass through 4x
lda 2,x ; on each pass juggle three bytes
sta 4,x ; pass 1 = 0,stackl
lda 0,x ; pass 2 = 1,stackl
sta 2,x ; pass 3 = 0,stackh
sty 0,x ; pass 4 = 1,stackh
lda l057
eor #($e8^$ca) ; toggle dex <-> inx
sta l057
l057 dex
lsr tos
bcs l056
txa
eor #<(stackl^stackh)
tax
lsr tos
bcs l056
jmp pop
Code: Select all
tworot dex
lda tos+1
sta stackh,x
lda tos
sta stackl,x ; enclose TOS into the indexed split stack
stx tos+1
clc
txa
adc #<stackl
tax
and at the very end
ldx tos+1
jmp pop