Language…
16 users online:  Anorakun, bandicoot, Dragul66, EliteBellic, Green Jerry, GrenCarret, h.carrell, Hammerer, hoangng,  K.T.B., MarsAmpere, ModernKiwi, NikSik1, QuinuS, RPG Hacker, Saela - Guests: 81 - Bots: 115
Users: 57,119 (2,260 active)
Latest user: Akayoki

What is an IRQ?

I looked it up on Wikipedia and don't understand how it works on smw. I heard that the layer 3 uses the irq line so that part of the layer 3 is on "mainscreen" (as in, in the foregroundmost), making the HUD always visible. This document didn't explain IRQ, it only explains the bits controlling it.
Give thanks to RPG hacker for working on Asar.
IRQ is an interrupt request. Imagine if you're a worker and suddenly you receive a call from your boss saying that you should eat lunch now. After you eat it, obviously you will come back to your job normally. That's how IRQ works.

In the programming and hardware world, IRQ has various usages, like updating the clock and polling your mouse and keyboard on your computer for example.

Usually IRQs are used when the CPU have to do something instantly, so it's interrupted and forced to run a code that is timing important.

In SNES, IRQ has usually just two purposes:

- Interrupt the CPU when the screen reaches certain position at drawing (either on a specific scanline (V count) or a horizontal position (H count) or both).

- Interrupt the CPU when a cart asks so (a SA-1 cart for example gives SA-1 CPU the power to send a IRQ to the SNES as well vice-versa).

In SMW, the first case is used to update the layer 3 registers and it's trigged just after the status bar is displayed on screen (position #$25). It's also used on mode 7 battles to change the screen mode mid-screen. Hence why you still can see the status bar on each boss, because the screen starts on mode 1 and after the status bar an IRQ changes to mode 7.

IRQs on SNES, as well HDMA, can be used to change any H-blank register, at whatever times you want. It's basically a manual HDMA, because obviously you don't need to waste two or three HDMA channels just to update the layer 3 registers at certain screen position and nothing more.

For SA-1 Pack, IRQs are also used for another purpose. Both SA-1 and SNES can invoke IRQs against each other and I use it to tell one of the CPUs to run a specific code. SA-1 for example can interrupt the SNES to run a specific code that SA-1 can't run like writing to WRAM.
GitHub - Twitter - YouTube - SnesLab Discord
Interrupts are extremely important in any modern computing. The CPU can't waste processing time polling if 5 billion things need to run something. Instead, other things poke the CPU and tell it to run things when they need it.

As mentioned, IRQs are interrupts that occur at set times during a frame on the SNES. SMW uses it to mess with layer 3 after it's done with the status bar.
I see it now, it runs the screen data from top to bottom on game mode. Anyway, how does the top layer 3 stays in front of everything, while other layer 3 stuff (like castle bricks and cave rocks) goes behind all things and scrolls not with the screen? When you say "irq time", does that mean each opcode per frame (as in within the main big processing loop)?
Give thanks to RPG hacker for working on Asar.
During the NMI (when the screen is being completely refreshed), the layer 3 is given priority over all other layers. During the IRQ, after the status bar has been drawn, layer 3 is given lower priority and a different x/y position.
The screen is drawn top->bottom, and IRQ is a routine usually called during a specific scanline. When IRQ is fired the CPU stops whatever it's doing and jumps to a location specified by the internal ROM header. As with all interrupts IRQ starts by preserving everything (PHP : REP #$30 : PHA : PHX : PHY : PHB) so that when it returns it won't crash. Usually the first thing you would do is wait for H-blank so you can access the PPU registers. During H-blank you have a small amount of time (cycles) to do whatever writes you need. If you need a lot of time you can extend H-blank into F-blank for a few scanlines, which is something a lot of splitscreen games do. With even a single scanline of F-blank you can do wonderful things such as updating tilemaps and palettes with DMA. For example you can update the status bar tilemap so you still get the full 512x512 BG3, though that does make the hack incompatible with ZSNES. Another thing to note is that you can't use scratch RAM in an IRQ routine since that might crash the game. And of course the routine ends with RTI.

allow shy guy emojis in post footers you cowards!
(I'm a dummy) What is a PPU registers, man, this sounds really confusing (thank god I remember that v and h blanks have to do with vertical and horizontal blanking (by the way what is a blank? Empty pixels that allow objects behind it visible?)). And what is a wait? Wait, as in how many opcodes, loops?
Give thanks to RPG hacker for working on Asar.
im sure you're familiar with regs.txt (considering your recent encounter with it). the PPU registers are those in the $21xx range. these addresses are the only ones that DMA can act upon via $43x1. they are called the PPU registers because they mainly, though not entirely, deal with matters related to screen rendering

a blank is when the electron gun of the television stops drawing stuff in order to move to a different part of the screen (either the beginning of the next scanline in the case of H-blank or the beginning of the first scanline in the case of V-blank. F-blank is nonstandard for it is software-initiated rather than routine, but in its case the electron gun is forced to stop drawing for as long as $2100's high bit is set, which, as well as its clearing, can occur at any point during rendering). in our age of emulation and digital displays, a blank is only a concept

a wait is a wait. usually accomplished by a loop or numerous opcodes, as you mentioned and as is usually done in standard code (aka after evoking the multiplication/division registers), though in the case of IRQ/NMI it can also be done by polling the H/V blank flags.

Originally posted by Von Fahrenheit
For example you can update the status bar tilemap so you still get the full 512x512 BG3, though that does make the hack incompatible with ZSNES.

as far as i'm aware, ZSNES has no major issues with that (besides possible mistimings, but that shouldn't hinder the effect)
Originally posted by Ladida
as far as i'm aware, ZSNES has no major issues with that (besides possible mistimings, but that shouldn't hinder the effect)


What I'm doing is I have a backup of BG3's top row of tiles in RAM, which I upload at every NMI, then I overwrite it with the status bar at IRQ (the status bar is at the bottom). If the top row is visible above the status bar ZSNES just uses the status bar tilemap for it. It seems to me that ZSNES just uses the current frame's most recent tilemap for the entire screen, which makes some sense. Updating the tilemap at IRQ works on both SNES9X and Higan, though.

But yes, the tilemap is updated, it's just that it overwrites whatever is above it.

allow shy guy emojis in post footers you cowards!
how strange. though my methods of full 512x512 L3 backgrounds were always via changing the layer 3 tilemap source rather than the actual tilemap, so i never encountered that issue
I notice that the bottom HUD (status bar) patch didn't mention "IRQ", but I heard that it mentions "game mode". Is it true that all it did is swaps the mode between IRQ and outside the IRQ (so that it runs "level" and then status bar)?
Give thanks to RPG hacker for working on Asar.
no

all that seems to do is reset the layer 3 position and upload to the bottom half of the screen. doesn't touch irq at all
Originally posted by Ladida
no

all that seems to do is reset the layer 3 position and upload to the bottom half of the screen. doesn't touch irq at all


Oh, I see now, so that's how the HUD doesn't scroll as of it was a layer 3 background, but how then how does it not impact the layer 3 background and only keeping the HUD?
Give thanks to RPG hacker for working on Asar.
Originally posted by GreenHammerBro
Oh, I see now, so that's how the HUD doesn't scroll as of it was a layer 3 background, but how then how does it not impact the layer 3 background and only keeping the HUD?


Originally posted by patch description
Layer 3 images won't be affected anymore since the status bar will be on top, if there's a layer 3 image in the level.


it will revert to the original status bar if there is a layer 3 image