| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
Event id #2417 : First CSDb "Unintended OpCode coding challenge"
So here it is. The First CSDb "Unintended OpCode coding challenge" starts over.
First CSDb "Unintended OpCode Coding Challenge"
Please give some feedback about your interest in this compo.
For those who have been part of the discussion
http://csdb.dk/forums/?roomid=12&topicid=112819#112927
please let me know if you are in better agreement with the reworked rules than before.
However, there will not be a rule change anymore. |
|
... 44 posts hidden. Click here to view all posts.... |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
I am not sure I understand this version. X&A may contain $00, $20, $40, or $60, flags in SBX are set like CMP, so the BPL start never happens??
Focus? There wasn't any focus ... I was just looking for a nice application for opcodes like SLO, SRE, RLA, RRA :-D |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Umm, i guess it should be bmi if i get it right, but flags are set perfectly well by sbx, so no problem.
The values i have noted are the input and resulting values. We need to focus on $00, $20, $40, $60 (00,01,10,11) by subtracting $e0 we manage to receive a negative result only upon $60 as input value, so we can branch out beforehand here as we would end up with a wrong carry in the following code. What remains are $00 - $e0, $20 - $e0 and $40 - $e0 as further results. so for 00 we have $20, for case 01 we have $40 and for case 10 we have $60 as result in X. If we now do a cpx we end up to have the carry cleared for case 00 and set for case 01 and case 10, right? After that we branch always. However i just notice that we should better do a cpx #$3f to fullfill the branch always :-D
lda #seed1
sta zp1
lda #seed2
clc
start:
ldx #$60
rol zp1
rol
sbx #$e0 ;x = a & $60 - $e0 -> clc
bmi start
cpx #$3f
;$20-$40 -> clc $40-$40 -> sec $60-$40 -> sec
bne start
|
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
That is even more efficient. Cool!
From this and other examples such as the ones posted by Monte Carlos I get the impression that SBX is a pretty useful UOC. |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
anything to emulate cpx ,y or cpy ,x ? |
| |
algorithm
Registered: May 2002 Posts: 705 |
@Oswald, maybe something like the below?
stx loc+1
loc cpy #$00
with code in zero page, would use 5 cycles.
No single illegal/legal opcode for the above :-( |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
I mean cpx abs,y or vice versa, they seem so obvious to have still not implemented.
damn you chuck ;) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
If you want it comfortable, switch to Java. |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
If you want to make it a subroutine, is this a good idea?
start: lda zp2
clc
ldx #$60
rol zp1
rol zp2
sbx #$00
lda $c000,x
sta start+2
rts
Where $c000, $c020, $c040, and $c060 contain $18,$38,$38,$18, respectively (opcode clc=$18, sec=$38).
First call: jsr init
Subsequent calls: jsr start
With RLA:
start:
clc
lda #$60
rol zp1
rla zp2
tax
lda $c000,x
sta start
rts
But I can imagine you want to call it for example 8 times in a row to generate an entire byte in which case the overhead of storing the state of the MLS generator can be much reduced. |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
Quote: If you want it comfortable, switch to Java.
|
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quoting Color BarIf you want to make it a subroutine, is this a good idea?
start: lda zp2
clc
ldx #$60
rol zp1
rol zp2
sbx #$00
lda $c000,x
sta start+2
rts
Where $c000, $c020, $c040, and $c060 contain $18,$38,$38,$18, respectively (opcode clc=$18, sec=$38).
[/code]
Faster is:
init: lda #seed1
sta zp1
start: lda #seed2
clc ; or sec depending on how you want to initialize
rol zp1
rol
sta start+1
tax
lda $c000,x
sta start+2
rts
This requires a look up table with $18,$38 values for any value of A after the rol. This has the advantage that it is easier to generalize to other MLS orders, where you may have to EOR more than two bits. No UOC required :-( |
Previous - 1 | 2 | 3 | 4 | 5 | 6 - Next |