[4.1] Prevent a script from being executed when a Screen Flag is set (NESmaker ASM)

dale_coop

Moderator
Staff member
A small example of how to prevent a input script from being executed when a Screen Flag is set (for example, when the "Hide Hud" flag... or the custom "Cutscene" flag... is ticked).

Here's the Screen Infos dialog:

2020-01-14-10-34-51-Screen-Details.png


The Screen Flags are indexed from 0 to 7 (from bottom to top)
NESmaker uses a variable named "screenFlags". Each bit of that variable corresponds to a screen flag state... can be "1" (ON) or "0" (OFF):

Code:
screenFlags
76543210
|||||||+------screen flag 0
||||||+-------screen flag 1
|||||+--------screen flag 2
||||+---------screen flag 3
|||+----------screen flag 4
||+-----------screen flag 5
|+------------screen flag 6
+-------------screen flag 7


If you want to check the state of "Screen Flag 0", the code would be something like that:
Code:
    LDA screenFlags
    AND #%00000001
(we load the variable and isolate the bit we want to check, here the #0 one... then, we will be able to test the result of that operation)

So... for the "Screen Flag 1", it would be:
Code:
    LDA screenFlags
    AND #%00000010

For the "Screen Flag 2", it would be:
Code:
    LDA screenFlags
    AND #%00000010

etc...

For the "Screen Flag 6", it would be:
Code:
    LDA screenFlags
    AND #%01000000

And for the "Screen Flag 7", it would be:
Code:
    LDA screenFlags
    AND #%10000000


Now, let's say, for example, you want the StartMovingPlayerLeft input script to not execute when the "Screen Flag 1" is set (ticked "ON").
You would just modify the "StartMovingPlayerLeft.asm" script, adding that code at the begining the script:
Code:
    LDA screenFlags	;; we check the screen flags
    AND #%00000010	;; the screen flag 1
    BEQ +		;; if not set, jump to the "+" label
    RTS			;; else, if set, stop the execution of that script
    +
    ;; from here, the rest of the script...

This code can be used to check any screen flag (just move the bit to the one you want to check) and in any/every script you need.
 
Top Bottom