Explanation Needed! Macro: TriggerScreen

Kanbei85

Member
For the purpose of trying to make BucketMouse's work on the Day/Night cycle functional, I have determined that an understanding of what exactly is going on with the TriggerScreen Macro must be had.

But so far nobody seems to understand what this code actually does:

MACRO TriggerScreen arg0
;; arg0 = screen to change, usually held in variable screenType
TXA
STA tempx
TYA
STA tempy

lda arg0 ;; this is the value of the screen to change.
AND #%00000111 ;; look at last bits to know what bit to check, 0-7
TAX
LDA ValToBitTable_inverse,x
STA temp2
lda arg0 ;; this is the value of the screen to change

LSR
LSR
LSR
;;; now we have the right *byte* out of the 32 needed for 256 screen bytes
TAY
LDA screenTriggers,y ;; now the rigth bit is loaded into the accum
ORA temp2

STA screenTriggers,y

LDX tempx
LDY tempy
ENDM

Somewhere up here, the screen is getting triggered in a way that stays persistent even if you reload the screen. If we understood how this worked, we might be able to get it to change a screen into night mode, or night triggered mode, at will as well.

This would give us a second and even a third triggered state for the screen, which could be highly useful. I have need of it already, because it could solve the problem that pickups don't stay gone after you collect them.
 

dale_coop

Moderator
Staff member
But so far nobody seems to understand what this code actually does
Joe explained in several videos (during the last 4 years) how Triggers work... here a recent one:
View: https://www.youtube.com/watch?v=bAOzs_A7o0k


But basically, there is a variable (screenTriggers) that stores all those screen that are triggered (you can set a trigger from the tool itself or by code)
A triggered screen is a different "state" for the screen. the Objects loaded/placed are not the same on a normal screen and on a triggered screen. Also, some tiles are removed on triggered screens (the doors, monster locks,...).

To "upgrade" that system, you could mix with the day/night state. By default, it's not really implemented in the code (piece of code are written, but a lot are missing or are disabled). That would make 4 states for each screens (day normal, day triggered, night normal, night triggered).

there are several topics on the subject on the forum...
for example: https://www.nesmakers.com/index.php?threads/4-5-9-how-to-activate-the-night-day-feature.7106/
 
Top Bottom