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

Post Reply
User avatar
dale_coop
Posts: 5417
Joined: Fri Feb 16, 2018 7:05 am
Location: France

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

Post by dale_coop » Tue Jan 14, 2020 10:36 am

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:

Image

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: Select all

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: Select all

    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: Select all

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

Code: Select all

    LDA screenFlags
    AND #%00000010
etc...

For the "Screen Flag 6", it would be:

Code: Select all

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

Code: Select all

    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: Select all

    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.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
My son's game: KUBO 3
Post Reply