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


Forums > C64 Coding > Most efficient (in cycles) 25Hz music player
2020-07-27 13:27
Frostbyte

Registered: Aug 2003
Posts: 40
Most efficient (in cycles) 25Hz music player

Last night, just for funsies and obviously inspired by the 25Hz music compo, I began wondering what is the fastest way to skip playing every 2nd frame. I came up with this.

First in the music init, I also init a toggle counter on zeropage address $02 to 00:
lda #$00
sta $02

Then, in the music play IRQ, I do this:
....
lda #$ff // 2 cycles - set accu to FF
eor $02 // 3 cycles - XOR with toggle: accu becomes 00 if toggle is FF, FF if 00
sta $02 // 3 cycles - update toggle counter to either FF or 00
bne end_irq // 2 cycles - skip playing if counter is not 00
jsr music.play
end_irq:
....

Of course it'd be much more efficient to use this or some other code to skip the music IRQ completely every 2nd frame, but you guys get the point. :)

This was a beginner's 10 cycle approach to the problem. Any faster solutions?
 
... 10 posts hidden. Click here to view all posts....
 
2020-07-28 12:58
Stryyker

Registered: Dec 2001
Posts: 465
Or for you playing music each frame:

jsr $1003
lda $1003
eor #$2c
sta $1003

This assumes $1003 has a jmp. Basically toggle $1003 opcode between whatever it has a $60 to do a rts.
2020-07-28 13:56
Groepaz

Registered: Dec 2001
Posts: 9713
not that it saves anything over the solution provided in the first post :)
2020-07-28 14:47
Stryyker

Registered: Dec 2001
Posts: 465
If you want to save more cycles, 2 raster interrupts in the same page so you only need to do lda #<rasterirq2 sta $0314 or $fffe and lda #<raster1 sta $0314 or $fffe so you have 6 cycles changing at the expense of more memory use
2020-07-28 15:11
Copyfault

Registered: Dec 2001
Posts: 373
Yes, I had the feeling a RASTER IRQ was kinda set. But since the options for this had more or less been posted already, I just wanted to put up the timer-irq approach;)

At the end it's all for fun, and I'm happy that the 25Hz-Compo also sparked something for the coders (be it this discussion or some disco... aehh. funky releases :)=) )
2020-07-28 17:49
Oswald

Registered: Apr 2002
Posts: 4664
Quote: If you want to save more cycles, 2 raster interrupts in the same page so you only need to do lda #<rasterirq2 sta $0314 or $fffe and lda #<raster1 sta $0314 or $fffe so you have 6 cycles changing at the expense of more memory use

you should have read all the posts, the ultimate solution was found already.
2020-07-28 23:47
TWW

Registered: Jul 2009
Posts: 481
I'm also probably missing the point, but if it's cycles / frame, why is:

    jsr $1000
    lda $1000  // 4 cycles
    eor #$2c   // 2 cycles
    sta $1000  // 4 cycles


using more cycles than

    IRQ        // 7 cycles
    jsr $1003
    rti        // 7 cycles


or was it ment something like this (6,5 cycles):

    bit $dc0x
    bpl !+
        jsr $1003
!:


Considering the overhead on the IRQ method there is no memory saved.

If memory is no concern, you could easily make it make it 0 cycles (add more raster-IRQ chains). <- New ultimate solution?

What was the point here?
2020-07-29 15:06
Oswald

Registered: Apr 2002
Posts: 4664
bit $dc0x
bpl !+
jsr $1003
!:

you will also need a jmp !-
2020-07-29 15:57
TWW

Registered: Jul 2009
Posts: 481
Quote: bit $dc0x
bpl !+
jsr $1003
!:

you will also need a jmp !-


We are probably thinking about this differently?

I was thinking to set the timer so it is alternating between negative and positive each frame (so it skipps the call to the music routine every 2nd frame). i didn't do the math though and sure as hell didn't test it so it's out of my ass only.

Edit:

and IRQ chains = 0 cycles:

IRQ1
:Vsync
Play music
Do stuff
IRQ pointer => IRQ2

IRQ2
:Vsync
Do not play music
Do stuff
IRQ pointer => IRQ1
2020-08-07 12:27
Copyfault

Registered: Dec 2001
Posts: 373
Another idea if we assume RASTER IRQ as fixed component of the concept:
     lda #<msx_call
call:
     jsr msx_call*
     sta* call+1
and one has to ensure that the msx_call-routine offers a byte (not necessarily accu, hence the sta*) that is free to use in the msx_call-page; an RTS has to go there ofcourse.

Unfortunately, this is short on additional bytes, but since we're doing the JSR every frame (every other just used for skipping), it effectively increases the no. of cycles.


More elegant would be
call:
     jsr $20a9
     sta call
and taking the "bitter pill" to add an "LDA #$EA" to the end of the msx-call, which in turn must be located at $20a9.


Best in terms of additional cycles is to use a timer irq, impossible to get below when RASTER IRQ-only is a must;)
2020-08-08 13:05
Copyfault

Registered: Dec 2001
Posts: 373
Quote:
[...]More elegant would be
call:
     jsr $20a9
     sta call
and taking the "bitter pill" to add an "LDA #$EA" to the end of the msx-call, which in turn must be located at $20a9.[...]
Ah, silly me, ofcourse it's not necessary to tweak the music routine itself, just:
call:
     jsr $0c20
     lda #$a9
     sta call
There are some othter candidates for the hi-byte ($0c = NOP abs was chosen here), depending on the desired location of the music routine (relocation needed either way).
Previous - 1 | 2 - Next
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
rikib80
Black Beard/Abyss, A..
Mibri/ATL^MSL^PRX
sebalozlepsi
Jazzcat/Onslaught
Dano/Padua
Ze Smasher/F4CG
Guests online: 94
Top Demos
1 Christmas Megademo  (9.7)
2 Uncensored  (9.6)
3 Edge of Disgrace  (9.6)
4 Unboxed  (9.6)
5 Coma Light 13  (9.6)
6 Memento Mori  (9.6)
7 Unboxed [6581 edition]  (9.6)
8 Lunatico  (9.6)
9 Comaland 100%  (9.6)
10 The Shores of Reflec..  (9.5)
Top onefile Demos
1 To Norah  (9.8)
2 Copper Booze  (9.8)
3 Lovecats  (9.6)
4 The Sprite Demo  (9.6)
5 Elite Code Mechanics  (9.6)
6 Square Booze  (9.5)
7 Daah, Those Acid Pil..  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Hyperborea  (9.5)
Top Groups
1 Booze Design  (9.4)
2 Censor Design  (9.4)
3 Fossil  (9.4)
4 Oxyron  (9.3)
5 PriorArt  (9.3)
Top Logo Graphicians
1 Mermaid  (9.5)
2 Pal  (9.4)
3 Jailbird  (9.0)
4 Elko  (9.0)
5 Shine  (8.8)

Home - Disclaimer
Copyright © No Name 2001-2021
Page generated in: 0.046 sec.