Timing of microcomputers

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
pikachu64
Posts: 6
Joined: Tue Feb 06, 2018 5:32 pm
Location: Upstate NY, USA

Timing of microcomputers

Post by pikachu64 » Thu Apr 11, 2019 7:00 am

I bought a book "The Z80 Microprocessor: Architecture, Interfacing, Programming , and Design" by Ramesh Gaonkar and am almost done reading it. A question I have regarding development of SNES, GB/GBC and early 8-bit microcomputers which I am trying to get into, is How do we know how much "work can be done" until a frame is drawn and work involving the memory-mapped video chip must be momentarily paused?

To take the Gameboy as an example that doesn't get into television details, is it that there are "X" T-states that are available before an interrupt fires signalling the beginning of the screen draw, and then "Y" more T-states until it is safe to touch video chip memory registers again?

Sorry for the very basic question, I have been reading Pandocs and Fullsnes, but coming from basic modern PC development I am unfamiliar with the fundamental operation of 8- and 16-bit computers and unable to comprehend the details of those documents. I was thinking I could begin with just trying to output some graphics and then move on to audio once I understand more.

tepples
Posts: 21973
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Timing of microcomputers

Post by tepples » Thu Apr 11, 2019 7:50 am

The Game Boy PPU takes 456 T-states per scanline. Of these, the background uses about 170 T-states (one for each dot, plus a few more to set up scrolling), and each sprite on the scanline uses about 9 T-states.[1] This totals anywhere from 170 to 291 T-states, the rest being considered horizontal blanking. Each frame has 144 scanlines, and there are 10 vertical blanking scanlines between one frame and the next, for a total of 154 scanlines or 70224 T-states per frame.

Have you been reading the original Pan Docs or the expanded Pan Docs that the gbdev community has been maintaining? The latter has a table of how long each "mode" lasts.


[1] These can vary based on the background's X scroll and each sprite's X position.

Nicole
Posts: 218
Joined: Sun Mar 27, 2016 7:56 pm

Re: Timing of microcomputers

Post by Nicole » Thu Apr 11, 2019 8:22 am

Generally the interrupt is at the end of the drawing period, not the beginning. The interrupt is at the start of V-blank, the period of time between frames where nothing is being drawn and video memory is safe to access.

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Timing of microcomputers

Post by koitsu » Thu Apr 11, 2019 1:48 pm

And to answer the question more directly: what you as a programmer end up caring about most of the time is "how many CPU cycles do I have available within this period of time (ex. VBlank)".

The answer is very rarely documented in official documentation, in my experience -- the info you usually get pertains purely to hardware, like "blah blah happens at some particular clock rate, which correlates with blah blah Hz".

Usually people have figured this out in numerous ways through reverse engineering and extensive tests (once able to run code on whatever the device is). Like for the NES/Famicom, I semi-recently demanded this be documented because it's super important.

pikachu64
Posts: 6
Joined: Tue Feb 06, 2018 5:32 pm
Location: Upstate NY, USA

Re: Timing of microcomputers

Post by pikachu64 » Sun Feb 23, 2020 6:59 pm

Thanks all for your responses

Oziphantom
Posts: 826
Joined: Tue Feb 07, 2017 2:03 am

Re: Timing of microcomputers

Post by Oziphantom » Mon Feb 24, 2020 12:26 am

unless you are doing "to the clock" critical timing based things, you basically don't try and count the thousands of clocks. You just write some code and check its Raster time. You tend to think more in lines rather than clocks when it comes to getting things done.

Post Reply