Jump to content
IGNORED

Two questions about the PIA


rafaelmessias

Recommended Posts

Hello everyone!

 

I'm writing a 2600 emulator (for no reason at all, just a personal challenge) and while reading about how the PIA works, I was left with two questions (so far; a million more will surely come in time):

 

1. What is the initial state of the timer? Is it supposed to be counting down even before anything is written to 0x294-0x297?

One of the roms I'm using to test my code is reading from 0x284 before setting the timer, so I'm wondering what's the expected behavior. Using the (absolutely fantastic) Stella debugger the behavior I see is that 0x284 gets a random value when the game starts, and is counting down as if a 1024 clocks interval was set. Is this really how it should work?

 

2. If one writes again to an interval address before the timer reaches 0 will it just reset without a problem and start counting down from the new value (with the new interval)?

 

I'd really appreciate any help. Thank you for your time!

Link to comment
Share on other sites

It definitely counts down initially. Else all games which do not set the timer before checking it for the 1st time, would stall. And the initial value is random, it is frequently used to initialize random number generation.

 

Don't now about the initial clock interval. I would have guessed(!) 1 clock.

Link to comment
Share on other sites

I made a simple test rom to check the timer at startup and display the results.
The screen looks like this:
post-10599-0-14408100-1473276096_thumb.png
The 'I' indicates that the 'timer flag' (bit 7) is set in the interrupt flag register (TIMINT).
The following two digits are the timer value (INTIM register) at startup (in hex)
On the right there's the time interval (1T,8T,64T or 1024T).

I only tried this on one console (a PAL light sixer).
In my tests the timer is almost always set to 1024T (like in Stella) and the "timer flag" is set (While it's cleared in Stella). The actual value seems to be random.
If I run the test shortly after having played a game cartridge, though, the timer is almost always set to 64T (which is the value most used in 2600 games as it's similar to the scanline duration). If I leave the console powered off for a few seconds more and try again, it gets back to 1024T

The testrom need to be the executed at power-on, so if you use an Harmony, you must flash it in single game mode. If you launch it from the menu, the results are influenced by the menu software itself (I always get "I 05 64T", in that case). For the same reasons you cannot use a supercharger, cuttle cart or other flahcarts with a menu.
timer_test.zip

  • Like 4
Link to comment
Share on other sites

Nice, guys, thank you for the explanations!

 

I was about to ask a third question (about how can we unambiguously know if the value on INTIM is before or after the timer has reached 0) but alex_79 mentioned the TIMINT flag, which I had never heard of, and a bit of searching through the forum got me to a really nice explanation from SeaGtGruff (http://atariage.com/forums/topic/133686-please-explain-riot-timmers/?p=1617207).

 

It's interesting that the Stella Programmer's Guide (which I've been using so far as reference for the PIA) never even mentions TIMINT or the 0x285 address.

 

Anyway, off I go to write a bit more code!

Link to comment
Share on other sites

Yeah, TIMINT isn't mentioned in the Stella Programmer's Guide but you can find info in the 6532 datasheet.

Btw, "INTIM" and "TIMINT" aren't the most descriptive names, I never remember which is which without looking at the docs...

I tested the rom in a few more consoles and I can mostly confirm my previous results:
- the increment seem to be always set to 1024T (unless you just played a game and swap it with the testrom leaving the console unpowered for a very short time)
- the actual timer value is random
- the interrupt flag is also random: while in the light sixer I tested yesterday it seemed always set, this isn't true for the other consoles I tried.

Here is a fixed testrom if anyone is interested. The old one could incorrectly detect the increment for low initial values, if the timer decremented to 0 before the increment calculation routine started.
Now it should work correctly for any value between $01 and $FF.
If the initial INTIM value is $00 the increment isn't displayed as there's no reliable way to calculate it in that case. The INTIM value and interrupt flag is always displayed.
timer_test_v2.zip

Edited by alex_79
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...