Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > CSDb Entries > Event id #2417 : First CSDb "Unintended OpCode coding challenge"
2015-10-11 07:18
Monte Carlos

Registered: Jun 2004
Posts: 351
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.
2015-10-12 14:32
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Looks far better to me, just need to find some coding time now... =-)
2015-10-12 15:40
Rastah Bar

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.
2015-10-12 18:22
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
2015-10-12 19:23
Bitbreaker

Registered: Oct 2002
Posts: 501
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.
2015-10-13 08:24
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Quoting Color Bar
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.


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!)
2015-10-13 10:33
Rastah Bar

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?
2015-10-13 16:45
Hein

Registered: Apr 2004
Posts: 933
Quote: Quoting Color Bar
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.


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.
2015-10-13 19:14
Monte Carlos

Registered: Jun 2004
Posts: 351
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...
2015-10-14 07:35
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Quoting Monte Carlos
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...


i'm just difficult, ask my Beloved... =-)
2015-10-14 09:05
Rastah Bar

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..)
2015-10-14 14:29
Bitbreaker

Registered: Oct 2002
Posts: 501
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
2015-10-15 12:01
Rastah Bar

Registered: Oct 2012
Posts: 336
Quoting Bitbreaker


         lda #$00
         slo $xxxx

can also be expressed as:

         asl label+1
label    lda #$00


Not always.
2015-10-17 10:38
Monte Carlos

Registered: Jun 2004
Posts: 351
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
---------------------------------------
2015-10-18 09:58
Rastah Bar

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
2015-10-18 10:03
Monte Carlos

Registered: Jun 2004
Posts: 351
just search for "no more secrets" and reveal:

No More Secrets

Think this and grahams reference are the most advanced docus.
2015-10-18 20:52
Rastah Bar

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).
2015-10-19 16:04
Monte Carlos

Registered: Jun 2004
Posts: 351
Is this related to generation of random numbers which also are maximum length sequences or is this something on it's own?
2015-10-19 16:31
Rastah Bar

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.
2015-10-19 19:02
Monte Carlos

Registered: Jun 2004
Posts: 351
Interesting idea. I only know bout these eor randomizers.
2015-10-19 19:15
Bitbreaker

Registered: Oct 2002
Posts: 501
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
2015-10-19 19:25
Rastah Bar

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 :-)
2015-10-19 19:50
Bitbreaker

Registered: Oct 2002
Posts: 501
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
2015-10-19 20:23
Rastah Bar

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 ;-)
2015-10-20 06:49
Bitbreaker

Registered: Oct 2002
Posts: 501
        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
2015-10-20 08:14
Rastah Bar

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
2015-10-20 08:51
Bitbreaker

Registered: Oct 2002
Posts: 501
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
2015-10-20 11:03
Rastah Bar

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.
2015-10-20 12:49
Oswald

Registered: Apr 2002
Posts: 5034
anything to emulate cpx ,y or cpy ,x ?
2015-10-20 15:52
algorithm

Registered: May 2002
Posts: 702
@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 :-(
2015-10-20 21:24
Oswald

Registered: Apr 2002
Posts: 5034
I mean cpx abs,y or vice versa, they seem so obvious to have still not implemented.

damn you chuck ;)
2015-10-21 06:36
Bitbreaker

Registered: Oct 2002
Posts: 501
If you want it comfortable, switch to Java.
2015-10-21 13:44
Rastah Bar

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.
2015-10-21 16:29
Oswald

Registered: Apr 2002
Posts: 5034
Quote: If you want it comfortable, switch to Java.

2015-10-22 09:30
Rastah Bar

Registered: Oct 2012
Posts: 336
Quoting Color Bar
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).

[/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 :-(
2015-10-25 12:50
Monte Carlos

Registered: Jun 2004
Posts: 351
lax blabla,x (y)
sbx #..

should emulate cpx,y or cpx,x
2015-10-25 16:19
chatGPZ

Registered: Dec 2001
Posts: 11164
but since that destroys akku, you can just aswell use
txa
cmp bla,y 

:)
2015-10-25 21:17
Oswald

Registered: Apr 2002
Posts: 5034
yeah I wanted to keep A intact :)
2015-10-25 21:31
Rastah Bar

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
2015-10-25 21:49
Oswald

Registered: Apr 2002
Posts: 5034
yup that would work, but probably also be slower or on par with what I wanted to optimize.
2015-10-26 18:34
Rastah Bar

Registered: Oct 2012
Posts: 336
Code optimization is hard ...
2015-10-26 21:35
Oswald

Registered: Apr 2002
Posts: 5034
yeah, well often it is good to try to find a better solution instead of fucking the illegals :)
2015-10-27 20:32
Monte Carlos

Registered: Jun 2004
Posts: 351
let's JAM
2015-10-29 09:31
Rastah Bar

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.
2015-10-31 15:22
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! =-)
2015-10-31 18:41
Rastah Bar

Registered: Oct 2012
Posts: 336
Nice one! I like the border graphics ;-)
2015-10-31 23:36
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Quoting Color Bar
Nice 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. =-)
2015-11-01 08:45
Rastah Bar

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.
2015-11-03 15:28
Rastah Bar

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.
2015-11-04 21:15
Monte Carlos

Registered: Jun 2004
Posts: 351
For ideas like this i started that compo!
Great!
2015-12-28 16:03
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? =-)
2015-12-28 18:43
Rastah Bar

Registered: Oct 2012
Posts: 336
There is the REU compo as well. A good opportunity to kill two birds with one stone.
2016-01-02 00:01
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Hang on... the deadline's passed, did i accidentally feckin' win or something?!
2016-01-02 10:34
Rastah Bar

Registered: Oct 2012
Posts: 336
I think so. But participating was more important than winning. :-)
2016-01-02 17:07
T.M.R
Account closed

Registered: Dec 2001
Posts: 749
Quoting Color Bar
I 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! =-)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
csabanw
bugjam
Twilight/Excess/Arcade
master_hacker
ΛΛdZ
goerp/F4CG/HF
psych
Zeus
Guests online: 82
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Aliens in Wonderland  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Birth of a Flower  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Offence  (9.3)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Veto  (9.6)
3 Facet  (9.6)
4 The Sarge  (9.6)
5 Carrion  (9.5)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.14 sec.