Jump to content

Photo

how many CPU cycles in a scanline?


22 replies to this topic

#1 sanny OFFLINE  

sanny

    Chopper Commander

  • 198 posts
  • Location:Bavaria

Posted Thu Nov 9, 2017 6:48 AM

Hi,

 

I've got two questions, which might be related.

 

The Altirra manual in section 2.3 states that there are 114 CPU cycles per scan line.

I've written a test program which disables Antic, DMA, and everything. Then it changes the background color register while the screen is displayed.

This test program needs to consume 105 cycles per scan line, otherwise the display gets distorted.

 

This is my first question. Is the Altirra manual wrong, or where do I lose the 9 (114-105) cycles?

 

For the second question look at the attached screen shot.

I expected the vertical bars to be evenly spaced.

I'm doing this in the program

; this should give evenly spaced horizontal bars
; but somehow that's not the case !??
        CYCLES  33
        STX     COLBK   ; 4 cycles (37)
        STA     COLBK   ; 4 cycles (41)
        STX     COLBK   ; 4 cycles (45)
        STA     COLBK   ; 4 cycles (49)
        STX     COLBK   ; 4 cycles (53)
        STA     COLBK   ; 4 cycles (57)
        STX     COLBK   ; 4 cycles (61)
        STA     COLBK   ; 4 cycles (65)
        STX     COLBK   ; 4 cycles (69)
        STA     COLBK   ; 4 cycles (73)
        STX     COLBK   ; 4 cycles (77)
        STA     COLBK   ; 4 cycles (81)
        STX     COLBK   ; 4 cycles (85)
        STA     COLBK   ; 4 cycles (89)
        STX     COLBK   ; 4 cycles (93)
        STA     COLBK   ; 4 cycles (97)
        STX     COLBK   ; 4 cycles (101)
        STA     COLBK   ; 4 cycles (105) -> 105 cycles total

This is for one display line. The code is repeated a few times to get "bars".

On the right half of the screen this looks like expected. But on the left half, the bars are thicker and the space between them is also larger. Can someone explain this effect to me? Maybe my missing cycles are somehow consumed by these bigger bars and spaces btw. them.

 

Attached are a precompiled exe and the (cc65) source code.

 

regards,

chris

Attached Thumbnails

  • atari000.png

Attached Files



#2 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 12,763 posts
  • Location:United Kingdom

Posted Thu Nov 9, 2017 6:53 AM

DRAM refresh still happens even if you disable DMA, and that consumes 9 cycles most of the time. I'm guessing that'll explain the uneven bar spacing too.


Edited by flashjazzcat, Thu Nov 9, 2017 6:54 AM.


#3 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 619 posts
  • Location:US

Posted Thu Nov 9, 2017 11:06 AM

I second what flashjazzcat said. You can see all refresh and DMA cycles in Altirra by pressing Shift-F8. If you do that when DMA is completely disabled you see the following pattern:

 

refresh.png

 

Notice that the positions of the DRAM refresh cycles correspond to the area where your bars are distorted.

 

Maybe you could even out the bars by intermixing ST* ABS, ST* ABS,Y and STA (ZP),Y instructions to adjust the width by one or two cycles at opportune moments since those take 4, 5 and 6 cycles respectively. You could also get 7 cycles if you force a page boundary to be crossed.


Edited by Xuel, Thu Nov 9, 2017 11:07 AM.


#4 _The Doctor__ ONLINE  

_The Doctor__

    River Patroller

  • 2,669 posts
  • Location:10-0-11-00:02

Posted Thu Nov 9, 2017 11:14 AM

I think he wants to get as much out of each line as possible and wants to know how to get it all. so what is the answer 105 yes? and we are losing 9 instead of 8? why is there a difference pal/ntsc?    covering the bases here...


Edited by _The Doctor__, Thu Nov 9, 2017 11:15 AM.


#5 Xuel OFFLINE  

Xuel

    Dragonstomper

  • 619 posts
  • Location:US

Posted Thu Nov 9, 2017 11:28 AM

There's no difference in the number of cycles per line between PAL and NTSC. When DMA is disabled, DRAM refresh always consumes 9 cycles. The only time refresh takes fewer cycles is on "badlines" where some of the refresh cycles are blocked by character set index lookups depending on the width of the screen and the HSCROL status. See the timing diagrams in the Altirra Hardware Reference Manual for precise timings.



#6 Heaven/TQA OFFLINE  

Heaven/TQA

    Quadrunner

  • 10,359 posts
  • Location:Baden-Württemberg, Germany

Posted Thu Nov 9, 2017 1:34 PM

Interesting so the claim 114 cycles for code is wrong?

#7 emkay ONLINE  

emkay

    Quadrunner

  • 8,814 posts
  • What's up?
  • Location:Holy Grail ;)

Posted Thu Nov 9, 2017 3:32 PM

Interesting so the claim 114 cycles for code is wrong?


As I wrote in an other thread...

#8 sanny OFFLINE  

sanny

    Chopper Commander

  • Topic Starter
  • 198 posts
  • Location:Bavaria

Posted Thu Nov 9, 2017 4:53 PM

I think he wants to get as much out of each line as possible and wants to know how to get it all.

 

Yes, that was the reason for my question.

 

Thanks for you answers.

 

Now I know there's nothing wrong with my program and that there are only 105 cycles available per scan line.



#9 Stephen ONLINE  

Stephen

    Quadrunner

  • 6,513 posts
  • A8 Gear Head
  • Location:No longer in Crakron, Ohio

Posted Thu Nov 9, 2017 5:00 PM

Yes, that was the reason for my question.
 
Thanks for you answers.
 
Now I know there's nothing wrong with my program and that there are only 105 cycles available per scan line.

105Cycles.jpg

#10 _The Doctor__ ONLINE  

_The Doctor__

    River Patroller

  • 2,669 posts
  • Location:10-0-11-00:02

Posted Thu Nov 9, 2017 7:19 PM

ah but debates about what can be done with badlines or re working the the systems might surface  .....



#11 pirx OFFLINE  

pirx

    Moonsweeper

  • 377 posts
  • Location:Poland

Posted Fri Nov 10, 2017 3:23 AM

Now I know there's nothing wrong with my program and that there are only 105 cycles available per scan line.

 

apparently a scam line



#12 Rybags OFFLINE  

Rybags

    Quadrunner

  • 15,230 posts
  • Location:Australia

Posted Fri Nov 10, 2017 3:56 AM

There's 114.  A cycle is a cycle whether it's stolen or not.  The exact cycles lost will vary depending on graphics mode, if HScrolling going on etc.

 

 

This thread needs some hipster jokes...

 

brixton-stolen-bike-parts.jpg

 


Edited by Rybags, Fri Nov 10, 2017 3:58 AM.


#13 MrFish ONLINE  

MrFish

    River Patroller

  • 4,216 posts
  • Location:1010-1010

Posted Fri Nov 10, 2017 8:05 PM

There's 114.  A cycle is a cycle whether it's stolen or not.  The exact cycles lost will vary depending on graphics mode, if HScrolling going on etc.

 

 

This thread needs some hipster jokes...

 

brixton-stolen-bike-parts.jpg

 

 

Technically, no cycle was stolen here.



#14 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 12,763 posts
  • Location:United Kingdom

Posted Sat Nov 11, 2017 2:48 AM

Precisely. The cycle pictured is not stolen, but nor is it usable. We're talking about usable cycles, of which there appear to be 105 at most. :)



#15 Sheddy OFFLINE  

Sheddy

    Dragonstomper

  • 656 posts
  • Location:UK

Posted Sat Nov 11, 2017 3:36 AM

Never were truer words spoke. Nothing stolen, but you could get pumped up thinking you had the whole 114. Bit of a let down, but we just have to handle it.
Wheely a shame

..ok, not proud of that last one...

#16 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 12,763 posts
  • Location:United Kingdom

Posted Sat Nov 11, 2017 3:50 AM

Thanks for that rider.



#17 Sheddy OFFLINE  

Sheddy

    Dragonstomper

  • 656 posts
  • Location:UK

Posted Sat Nov 11, 2017 3:57 AM

I could go on, but I'm tired now

Edited by Sheddy, Sat Nov 11, 2017 4:01 AM.


#18 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • 1,252 posts
  • Location:Germany

Posted Sat Nov 11, 2017 4:01 AM

That brings up the question how to disable the refresh if static RAM is used (there are some memory extensions with SRAM) - not that "fragmenting the platform" is a good thing, just for the sake of it...?



#19 Rybags OFFLINE  

Rybags

    Quadrunner

  • 15,230 posts
  • Location:Australia

Posted Sat Nov 11, 2017 4:06 AM

Not a lot of point really, you'd end up with an incompatible system.

 

I suppose in doing it you'd get a "poor man's accelerated" machine with a blistering 9% or so performance increase.

The logic involved would simply be taking /REF and /HALT from Antic.  Whenever /REF is active, override /HALT to bring it high as seen by the CPU.

But the problem is you'd also need to isolate the address bus since Antic is outputting a row address for the refresh.

 

So the poor man's accelerator ends up being more complex/costly than a rich man's one.


Edited by Rybags, Sat Nov 11, 2017 4:06 AM.


#20 emkay ONLINE  

emkay

    Quadrunner

  • 8,814 posts
  • What's up?
  • Location:Holy Grail ;)

Posted Sat Nov 11, 2017 4:44 AM

There's 114.  A cycle is a cycle whether it's stolen or not.  The exact cycles lost will vary depending on graphics mode, if HScrolling going on etc.
 
 
This thread needs some hipster jokes...
 
brixton-stolen-bike-parts.jpg


This really looks like most cycles were stolen at a bad line.

#21 MrFish ONLINE  

MrFish

    River Patroller

  • 4,216 posts
  • Location:1010-1010

Posted Sat Nov 11, 2017 12:03 PM

Precisely. The cycle pictured is not stolen, but nor is it usable. We're talking about usable cycles, of which there appear to be 105 at most. :)

 

I understand what the discussion's about. My comment was meant to be humorous.



#22 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 12,763 posts
  • Location:United Kingdom

Posted Sat Nov 11, 2017 1:32 PM

 

I understand what the discussion's about. My comment was meant to be humorous.

 

I know dude... so was mine. :)



#23 emkay ONLINE  

emkay

    Quadrunner

  • 8,814 posts
  • What's up?
  • Location:Holy Grail ;)

Posted Sat Nov 11, 2017 3:17 PM

Saving CPU cycles ? Just let Antic do scrolling, shuffling Data around, let the screen shake ...




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users