Jump to content

Significant change to VERA IRQLINE register


Wavicle
 Share

Recommended Posts

Hello Everyone,

I've another update on the VERA design, and this one is important if you are working with VERA interrupts. Please read if you write games, demos, or any program that uses line interrupts.

The IRQLINE register now has different read and write semantics. Writing the IRQLINE register (IRQLINE_L / $9F28 and IEN / $9F26 bit 7) still works the same, however reading the IRQLINE register now returns the new SCANLINE register. This is a 9 bit raster line counter that starts at 0 and counts up 511. It will sit at 511 for scan lines 511-524. 511-524 are "scan lines" that happen during VSYNC. In progressive scan mode, 479 is the last visible line.

In interlace mode, SCANLINE counts even numbers on even fields and odd numbers on odd fields. This means that bit 0 of the SCANLINE register reports nearly the same thing as bit 7 of the DC_VIDEO register.

There is one "trap" here that developers need to be on the lookout for here: it is not safe to set bits in the IEN register using a read-modify-write. Performing a code sequence such as LDA $9F26 / ORA $02 / STA $9F26 or using the W65C02 bit set/clear opcodes has a chance to flip the value of IRQLINE bit 8 depending on the line being drawn when that code executes. Any code writing the IEN register will need to know what the value of IRQLINE[8] should be because it is no longer accessible through the register interface.

This was discussed at some length on Discord and the feedback from those present was that the drawbacks from having to take a few extra steps when writing the IEN register was outweighed by the benefits to some types of software being able to poll for a particular line. If anyone feels that we reached the wrong conclusion, please make your case (constructively and with civility!) in this thread so that we know where to find it.

More details can be found in the PR implementing this change here: https://github.com/fvdhoef/vera-module/pull/21

Here is sample output from a demo program written by @MooingLemur that changes the background color every scanline.

WIN_20220921_11_52_18_Pro.jpg.b1ce872d0bde45c145279d55146466a4.jpg

  • Like 1
Link to comment
Share on other sites

On 9/23/2022 at 10:04 AM, Ed Minchau said:

So, we should poll IRQLINE(8) and then write to IEN?

The assumption is that if you are enabling interrupts, you already know what IRQLINE should be. You need to mask off bit 7 and set it to whatever it should be before writing it back out.

Link to comment
Share on other sites

Hello again, everyone. As we've had a chance to test this change out on more software, I think that I underestimated the impact of the "trap" above.

@ZeroByte suggested moving bit 8 of the SCANLINE from IEN[7] to IEN[6] which will re-enable read-modify-write operations to IEN. (E.g. you can enable a single interrupt by doing IEN |= 0x20 without knowing what bit 8 of the line IRQ should be).

Let me know of any problem/issue you see with this modification to the new (and as yet unsupported in the emulator) scanline feature.

  • Like 1
Link to comment
Share on other sites

On 9/28/2022 at 12:10 AM, Wavicle said:

moving bit 8 of the SCANLINE from IEN[7] to IEN[6] which will re-enable read-modify-write operations to IEN. (E.g. you can enable a single interrupt by doing IEN |= 0x20 without knowing what bit 8 of the line IRQ should be).

I like that a lot more 🖕.

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.

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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use