Injecting custom code into the code loop

TokyoScarab

New member
Hi, I'm new to using NESMaker, but have a background in programming and do understand assembly. I'm finding parts of scripting in NESMaker just confusing and un-intuitive. I'd really love documentation on more aspects of scripting because when the standard scripts are making calls to pre-defined routines (macros) or variables, it's just really difficult to know what exactly is going on under the hood. After a bunch of digging around, I was able to find the macro folder in the program directory so I could know what all macros existed, the arguments they took, and what exactly they even did in the first place. I can't seem to say the same for pre-named variables. Closest I found was a file just sort of defining them all but not going into a lot of detail as to what they are used for. From what I could find in a related post asking for documentation from a year ago, the devs said they were still working on it (fair enough). So my actual question was more so how do you go about actually injecting your code into the actual code loop of the game without putting it in one of the pre-defined routines? It seems easy enough if you want something to happen on certain events (like a controller input), but what about putting something that runs a check on every code loop for example? I'm sorry if this has been asked before and I didn't catch it in my search. Hope you all can help me! :D
 

Mugi

Member
the lack of documentation at the moment is real, and basically the only way to figure things out is to dig into the engine and find things yourself.
it's taken me too a long series of going through the assemblies to find relevant things.

some easy scripts to help with stuff are for example predraw.asm which handles drawing of the sprite based weapon and sprite0 in the modules that are equipped with scroll.
the predraw runs once per frame and can easily be used for hooking up functionality that is required on a per-frame basis.

as far as macros goes, the buil-in script editor in NESMaker has a macro viewer that displays all the macros from the macro folder, along with their arguments. Majority of the macros are fairly well documented.
aside that, the mainasm.asm has includes to a couple files that give you a fairly good idea of how the game's mainloop is structured and in which order stuff like physics and collision are calculated.

the script settings tab under project -> project settings also gives out a fairly decent list of the scripts currently loaded into whatever module you are using.

what comes to the variables....... well *cough* good luck with that. the variables are literally ALL OVER THE ENGINE and it's a real mess, good luck figuring out what "testflagthing" is used for :p
 

dale_coop

Moderator
Staff member
100% agreed with Mugi.
About the script editor and the macros:

2019-09-18-09-16-03-NES-MAKER-4-1-5-Version-0x159-Unsaved-Project.png
 

TokyoScarab

New member
Yea, I had no idea the macro thing was even at the bottom of the defined scripts page. For some reason, every time I go to that page, the macro viewer area is as small as it can possibly be. I can resize the various areas in the workspace, but it I leave and come back, everything resets. That does help a bunch though. So what exactly is the difference between "Input scripts" and "Defined scripts"? From how I've seen them used, it seems the "Input scripts" are only used for various controller inputs. From messing around, I've noticed that the defined scripts have something to do with various AI and tile properties and that I can add scripts to this list, but how do you go about adding them to something?


UHfnFHn.png
 

dale_coop

Moderator
Staff member
Exactly, in “Input Scripts”, you’ll add all the scripts to be asssigned to your inputs buttons (from the “Input Editor”). you can edit them from here.

In “Defined Scripts”, you will have all the scripts assigned to the physics engine (collisions, actions,...). Scripts that you have assigned in the “Project Settings > Script Settings”, for each elements of the engine.
 

TokyoScarab

New member
This is all very helpful! Thanks! :D

I am looking through the defined scripts. Would it be accurate to assume that all the scripts in Defined Scripts and Input Scripts comprise all of the code that would be used in any game I make in NESMaker? Meaning that there would be nothing else being injected by NESMaker into the rom whenever you compile.


EDIT: After looking through the NESMaker files more, it seems that the MainASM.asm file contains the roadmap to everything.
 

Mugi

Member
the defined scripts is a large portion of the game, yes, but not all of it.
there is a number of files loaded into the project from gameenginedata/routines/basic/system/ folder (where the macros are too)
and there's a bunch of data, such as the ram variables etc in gameenginedata/gamedata/ and it's subfolders.
 
Top Bottom