Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Practical way of detecting the video Hz on SMS

Reply to topic
Author Message
  • Joined: 29 Jan 2014
  • Posts: 92
  • Location: Brasilia, Brazil
Reply with quote
Practical way of detecting the video Hz on SMS
Post Posted: Sun Jan 20, 2019 9:43 pm
As I was researching a practical/solid way of detecting a SMS VDP connected to a MSX computer (Franky/PlaySoniq, for the vgmplay-msx project) I discovered a consistent register behavior on the SMS VDPs which can be useful for detecting the video frequency:

As you guys are aware of, the TMS9xxx VDPs (TMS9918/9928/9929/9118/9128/9129) have a function which allows it to synchronize with external video source for superimposing. The SMS VDP also have that feature, which is used on the SYSTEM E arcade board to make two SMS VDPs operate synchronized.

What I discovered is that when you have a single VDP you have no synchronization input for the extvideo mode. So the internal raster of the VDP will sit at a corner of screen without traversing. That makes the vertical counter stop at a fixed value, which is:

0xBA for 50Hz
0xD5 for 60Hz

By masking out the IRQ, setting extvideo on briefly, waiting a little while (for the counter to reach that value) and checking the vertical counter value you can tell what vertical frequency the VDP is set as.

Clearing extvideo makes the counter resume normal behavior.

This behavior was consistent on 315-5124 and 315-5246, I don't know if it works on newer chips. Also, I am assuming this doesn't work on the Game Gear.
  View user's profile Send private message
  • Joined: 24 Mar 2018
  • Posts: 4
Reply with quote
Post Posted: Sun Jan 20, 2019 10:34 pm
Some more findings;

0xBA corresponds to the sync start line of PAL 256x192 (-70)
0xD5 corresponds to the sync start line of NTSC 256x192 (-43)

So before testing for this you also need to set a 256x192 mode.

Additionally, after setting EXTVID, the v-counter either changed immediately or after 20 µs. I didn’t see any intermediate values, but either way, you gotta wait a bit for it to determine that it’s lost sync and reset the counter.
  View user's profile Send private message
  • Joined: 31 Oct 2007
  • Posts: 844
  • Location: Estonia, Rapla city
Reply with quote
Post Posted: Mon Jan 21, 2019 8:28 pm
That is an interesting way to check 50/60, very cool find !

Another option is to just count numbers throughout a frame, 50Hz will count higher compared to 60Hz.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Sep 2018
  • Posts: 50
Reply with quote
Post Posted: Tue Jan 22, 2019 2:35 am
What's the exact behaviour if EXTVID is on and there's no external video? Is it that the VDP halts before generating vertical sync, awaiting detection of an external sync, and resumes from where it is as soon as EXTVID is toggled back off?

If so then it should be possible to generate an interlaced array. Thinking extemporaneously, enable EXTVID for half a line, then disable it, then wait for the duration of vertical sync, then do the same for odd frames, and just enable it for an entire line then disable it and forget about it for evens.
  View user's profile Send private message Visit poster's website
  • Joined: 29 Jan 2014
  • Posts: 92
  • Location: Brasilia, Brazil
Reply with quote
Post Posted: Tue Jan 22, 2019 5:08 pm
TmEE wrote
That is an interesting way to check 50/60, very cool find !

Another option is to just count numbers throughout a frame, 50Hz will count higher compared to 60Hz.


We were looking for a consistent way of testing for the presence of a SMS VDP. The ports 88h/89h on MSX are used for an alternative V9938 VDP for a external MSX2 upgrade kit. (cartridge based) So an deterministic way of discerning the SMS VDP apart from a regular TMS9xxx or V9938 was necessary. What I was looking for with this was a way of using the presence of the SEGA VDP V counter as indicative of a Franky cartridge presence. Discovering that we can tell NTSC apart from PAL was actually a nice bonus on this.
  View user's profile Send private message
  • Joined: 24 Mar 2018
  • Posts: 4
Reply with quote
Post Posted: Fri Jan 25, 2019 1:54 pm
TomHarte wrote
What's the exact behaviour if EXTVID is on and there's no external video? Is it that the VDP halts before generating vertical sync, awaiting detection of an external sync, and resumes from where it is as soon as EXTVID is toggled back off?


Going by what I observed from the v-counter, when the sync is lost (near immediately), it resets to the start of the vertical sync and stays there. I reckon it stays because this reset just happens continuously as long as no sync is detected.

Once EXTVID is disabled it resumes. I presume it resumes immediately from right there at the start of vertical sync and not at some other place.
  View user's profile Send private message
  • Joined: 29 Jan 2014
  • Posts: 92
  • Location: Brasilia, Brazil
Reply with quote
Post Posted: Fri Jan 25, 2019 3:34 pm
Apparently, when on EXTVIDEO mode, the H-L pin (the pin which causes the H counter latch the raster position) becomes the sync input for the VDP. On the particular case of a MSX computer where the pin is left disconnected there is no chance of a mistake on the detection. That might be a different story on a actual Master System with a Light Phaser gun connected to. It would be interesting if we were to perform some testing with this later on.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!