| |
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. |
|
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Looks far better to me, just need to find some coding time now... =-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
What T.M.R. said + some inspiration.
I my releases I had looked for places where I could use UOCs, but only SAX (opcode $CB) helped. Still some look really potentially useful, such as DCM(DCP), RRA (for multiplication?), ASO(SLO) (for line drawing?), etc. |
| |
Kabuto Account closed
Registered: Sep 2004 Posts: 58 |
A good example of Unofficial Opcodes are ">= 5 sprites over FLI" effects, such as Demus Interruptus by Crest or Darwin by The Dreams |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Quote: What T.M.R. said + some inspiration.
I my releases I had looked for places where I could use UOCs, but only SAX (opcode $CB) helped. Still some look really potentially useful, such as DCM(DCP), RRA (for multiplication?), ASO(SLO) (for line drawing?), etc.
There's great use for many of them, so far just didn't use RRA and RLA as well as LAS and TAS. Even used them in all their adressing modes, some are really handy as they extend the indirect y index modes (LAX, SHA). Most used are LAX, SAX, SBX, DCP, ISC, ASR, ARR. |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Quoting Color BarI my releases I had looked for places where I could use UOCs, but only SAX (opcode $CB) helped. Still some look really potentially useful, such as DCM(DCP), RRA (for multiplication?), ASO(SLO) (for line drawing?), etc.
i'm using SAX and DCP right now, with some LAX use where i can just about justify it as an advantage as long as the loop isn't unrolled! =-)
(Please don't expect anything amazing... this is me we're talking about!) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quoting T.M.R... where i can just about justify it as an advantage as long as the loop isn't unrolled! =-)
It saves memory, isn't that enough justification? |
| |
Hein
Registered: Apr 2004 Posts: 954 |
Quote: Quoting Color BarI my releases I had looked for places where I could use UOCs, but only SAX (opcode $CB) helped. Still some look really potentially useful, such as DCM(DCP), RRA (for multiplication?), ASO(SLO) (for line drawing?), etc.
i'm using SAX and DCP right now, with some LAX use where i can just about justify it as an advantage as long as the loop isn't unrolled! =-)
(Please don't expect anything amazing... this is me we're talking about!)
Unrolling is for lamers anyway. |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
TMR:
I'm glad this update looks more convincing to you now. After this rules discussion before i feared i messed it up before it even started.
Now i have a better feeling... |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Quoting Monte CarlosTMR:
I'm glad this update looks more convincing to you now. After this rules discussion before i feared i messed it up before it even started.
Now i have a better feeling...
i'm just difficult, ask my Beloved... =-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quote: There's great use for many of them, so far just didn't use RRA and RLA as well as LAS and TAS. Even used them in all their adressing modes, some are really handy as they extend the indirect y index modes (LAX, SHA). Most used are LAX, SAX, SBX, DCP, ISC, ASR, ARR.
It looks like opcodes ASO ($0f), RLA ($2f), LSE ($4f), and RRA ($6f) may save you 2 cycles.
Suppose I want to do
ASL $xxxx
LDA $xxxx
That takes 10 cycles, but
LDA #$00
ASO $xxxx
takes only 8. Isn't that so?
(I am referring to http://codebase64.org/doku.php?id=base:extra_instructions_of_th..) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
SRE and SLO and others can take up to 8 cycles (indirect y indexed) and are thus not necessarily faster, also i have not come across any good use for an effect for the RRA and RLA opcodes so far, though they of course would save cycles if used properly.
lda #$00
slo $xxxx
can also be expressed as:
asl label+1
label lda #$00
|
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quoting Bitbreaker
lda #$00
slo $xxxx
can also be expressed as:
asl label+1
label lda #$00
Not always. |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
Thats what i tried recently:
ldx #60
fsprite lda #0
sta sprite+2,x
lda #$f0
sta sprite+1,x
lda #$ff
sta sprite+2,x
sbx #3 ; or axs #3
bpl fsprite
rts
----------------------------------
ldy # 24
ldx #0
setscreen:
lda #'*'
hi = *+2
sta screen,x
txa
sbx #$d8
bcc j
inc hi
j dey
bpl setscreen
rts
-------------------------------------
loop:
jsr waitretrace
lda #7
ldx $d016
sbx #$f9
stx $d016
jmp loop
--------------------------------------- |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Is there any concensus on the names given to the various extra instructions?
There are at least three references on codebase64:
http://codebase64.org/doku.php?id=base:extra_instructions_of_th..
http://unusedino.de/ec64/technical/aay/c64/ibmain.htm
http://www.oxyron.de/html/opcodes02.html
Which one is the most complete / commonly used?
A document by Groepaz was mentioned. Where can I find that?
I once used:
sta label+1
txa
label sbx #$00
To get X --> A and X-A --> A |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
just search for "no more secrets" and reveal:
No More Secrets
Think this and grahams reference are the most advanced docus. |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Thanks!
I constructed a 15 bit Maximum Length Sequence (MLS) generator, using RLA. This is what I have got now:
lda #seed1
sta zp1
lda #seed2
sta zp2
start:
clc
lda #$60 ;MSB of zp2 is output of the MLS, bits 6+5 are EORed (according to primitive polynomial for m=15)
rol zp1
rla zp2 ;actually the Carry flag contains the most recent output of the MLS at this point, while the MSB of zp2 is the output of the previous cycle.
beq start ; shift a zero bit in
;now we must distinguish between 01 or 10 versus 11 for bits 6 and 5 of A
eor #$60
beq start ; shift a zero bit in
sec ; shift a one bit in
jmp start+1
Reference for MLS: http://www.kempacoustics.com/thesis/node83.html
I don't know if this can be done more efficiently (probably). |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
Is this related to generation of random numbers which also are maximum length sequences or is this something on it's own? |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Yes, this is related. I dont know the details, but the reference explains more. I remembered something about random number generation with MLS, looked up the reference and saw a connection with RLA. |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
Interesting idea. I only know bout these eor randomizers. |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Nice! A optimization that comes to my mind at a chort glance:
eor #$60
beq start ; shift a zero bit in
sec ; shift a one bit in
jmp start+1
;isn't that the same as:
eor #$60
cmp #$01 ;sets carry on $20 $40 $60 and clears carry on $00
bne start+1 ;branch always
The lda #$60 + eor #$60 gives me the feeling that it can be optimized too, twice the same value :-D Also it would help to get a negated carry, hmm |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quote: Nice! A optimization that comes to my mind at a chort glance:
eor #$60
beq start ; shift a zero bit in
sec ; shift a one bit in
jmp start+1
;isn't that the same as:
eor #$60
cmp #$01 ;sets carry on $20 $40 $60 and clears carry on $00
bne start+1 ;branch always
The lda #$60 + eor #$60 gives me the feeling that it can be optimized too, twice the same value :-D Also it would help to get a negated carry, hmm
Yes, thanks for the optimization!
I'm studying Groepaz's document now to see if another UOC can be sneaked in advantageously :-) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Next try, and hope i don't spoil the fun, also: untested and just sketched in an editor :-D
lda #seed1
sta zp1
lda #seed2
start:
clc
ldx #$60
rol zp1
rol
sbx #$00 ;x = a & $60
beq start ;x = 0?
sbx #$60 ;$60-$60=0, $20 - $60=$c0 $40-$60=$e0
cpx #$01 ;clear carry on x = 0, else set
bne start+1
|
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Nice. The code after start: is 1 cycle faster, isn't it? But it does use the x-register as well.
For practical use of the MLS the code should probably be modified such that you can go through one update of it (as a subroutine?) and use the output elsewhere.
I don't want to give up too easily on RLA ;-) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
lda #seed1
sta zp1
lda #seed2
clc
start:
ldx #$60
rol zp1
rol
sbx #$e0 ;x = a & $60 - $e0 -> clc
bpl start
cpx #$40
;$20-$40 -> clc $40-$40 -> sec $60-$40 -> sec
bne start
Still untested, so i might be very wrong. Of course this method would not work well as a call, but i guess it was not the focus? :-D |
| |
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 :-( |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
lax blabla,x (y)
sbx #..
should emulate cpx,y or cpx,x |
| |
chatGPZ
Registered: Dec 2001 Posts: 11390 |
but since that destroys akku, you can just aswell use
txa
cmp bla,y
:) |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
yeah I wanted to keep A intact :) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
In the special case that 'bla' is on a page boundary (for example $1f00):
sty label+1
label:
cpx $1f00 |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
yup that would work, but probably also be slower or on par with what I wanted to optimize. |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Code optimization is hard ... |
| |
Oswald
Registered: Apr 2002 Posts: 5095 |
yeah, well often it is good to try to find a better solution instead of fucking the illegals :) |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
let's JAM |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
One potential use of SAX, SHA, SHX, and SHY could be in border graphics ($d020, $3fff, $39ff).
With something like
lda #value1
ldy #value2
ldx #value3
sta $d020 ;or $3fff or $39ff when the ECM bit is on
stx $d020
sty $d020
sta $d020
stx $d020
sty $d020
... ; repeat the above
the result will be columns of 4 characters wide, but only three different values are used. If you want to change a color with an lda #value4, for example, one column will become 6 characters wide. But with the mentioned UOCs you can change the color/value to create a column of only 5 characters wide (4 even with SAX), although the range of value4 may be very limited. |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Yays, i was the first entry! Now watch everyone else turn up and completely nuke mine! =-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Nice one! I like the border graphics ;-) |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Quoting Color BarNice one! I like the border graphics ;-)
i've been sitting on that main effect for a few weeks, it was the most interesting thing i could think of to do with the commands after reading through the docs. =-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
I would love to find a good application for some of the more obscure UOCs.
I am now trying to figure out if UOCs such as SLO and SRE can be useful in some kind of parallax scrolling effect.
For example a border sprite scroller where text is moved over fixed background sprite graphics. |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quote: I would love to find a good application for some of the more obscure UOCs.
I am now trying to figure out if UOCs such as SLO and SRE can be useful in some kind of parallax scrolling effect.
For example a border sprite scroller where text is moved over fixed background sprite graphics.
It looks like it works using RLA :-D
Furthermore, with suitably chosen MC sprite and background colors the scrolling may create an interesting color interlacing/mixing effect. |
| |
Monte Carlos
Registered: Jun 2004 Posts: 364 |
For ideas like this i started that compo!
Great! |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Not long before the deadline, i wonder who is waiting for the last minute before entering? =-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
There is the REU compo as well. A good opportunity to kill two birds with one stone. |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Hang on... the deadline's passed, did i accidentally feckin' win or something?! |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
I think so. But participating was more important than winning. :-) |
| |
T.M.R Account closed
Registered: Dec 2001 Posts: 749 |
Quoting Color BarI think so. But participating was more important than winning. :-)
i'm just worried about finishing the entry off on the Cosine website with a position really... honest! =-) |