Post subject: layers and other variables in SMW
Joined: 6/14/2015
Posts: 19
I am trying to understand what the different ram addresses inSMW actually represent in the game. Yes I know, I should just play the game and figure it out and I did for most of them but there are still a few concepts that elude me. These are code samples from the evolve script for SMW. What are layers for and why are they needed?
local layer1x = memory.read_s16_le(0x1A);
local layer1y = memory.read_s16_le(0x1C);
What is screen position and why is that different than Mario position?
screenX = memory.readbyte(0x03AD)
screenY = memory.readbyte(0x03B8)
there are 12 sprite and status locations.what are they for?
function getSprites()
		local sprites = {}
		for slot=0,11 do
			local status = memory.readbyte(0x14C8+slot)
			if status ~= 0 then
				spritex = memory.readbyte(0xE4+slot) + memory.readbyte(0x14E0+slot)*256
				spritey = memory.readbyte(0xD8+slot) + memory.readbyte(0x14D4+slot)*256
				sprites[#sprites+1] = {["x"]=spritex, ["y"]=spritey}
			end
		end		
return sprites
What are extended sprites?
Joined: 2/3/2013
Posts: 320
Location: Germany
I assume you're referring to MarI/O? By now there's more than one of these scripts around (modified versions), so you should probably link to the exact one you're using (edit your post).
All syllogisms have three parts, therefore this is not a syllogism.
Amaraticando
It/Its
Editor, Player (157)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Hi. Your post is probably more suitable in the SMW thread. Furthermore, you have the following resources: SMW page WRAM map Glitch list
skypickle wrote:
What are layers for and why are they needed?
local layer1x = memory.read_s16_le(0x1A);
local layer1y = memory.read_s16_le(0x1C);
Those WRAM addresses are hardware mirrors. A SNES emulator usually has a hotkey or command to disable/enable the different layers of images. In BizHawk, you have (by default) to press 1, 2, 3 or 4 you must set the SNES hotkeys to see what each layer is.
skypickle wrote:
What is screen position and why is that different than Mario position?
screenX = memory.readbyte(0x03AD)
screenY = memory.readbyte(0x03B8)
In MarI/O, this is for Super Mario Bros.
skypickle wrote:
there are 12 sprite and status locations.what are they for? ?
In SMW, there're at most 12 sprites at once. I'm not talking about a sprite in a general sense, but the most animated enemies/items in the game. In this category, Mario itself is not a sprite, nor is the fireball. Use the utility script to learn more about them. The WRAM has a lot of 12 bytes blocks that keep track of the positions, speeds, status, timer, etc of the sprites.
skypickle wrote:
What are extended sprites?
A different set of objects. For instance, the fireball, Yoshi's flames and the hammers are extended sprites.
Joined: 6/14/2015
Posts: 19
Thank you Amaraticando. I was reading through your utility code and found many interesting things as I am still learning LUA. I will prob go off topic so please direct me to the correct forum as these are mostly programming questions. 1) why do you use a make_set function? You use it for ABNORMAL_HITBOX_SPRITES where you make a table with 4 entries of RAM addresses like so:
local ABNORMAL_HITBOX_SPRITES = make_set{0x62, 0x63, 0x6b, 0x6c}
This table is used once in line 1038 here:
  if SHOW_SPRITE_HITBOX and not ABNORMAL_HITBOX_SPRITES[number] then
Is it not simpler to just construct the table in the first place like so:
ABNORMAL_HITBOX_SPRITES = {[1]=0x62, [2]=0x63, [3]=0x6b,[4] = 0x6b,}
instead of first making a list then an iterator to create an array? 2) Why are variables declared as local in the top level? for example , local ABNORMAL_HITBOX_SPRITES and functions too for example
local Isloaded, Movie_mode, Readonly, Currentframe, Framecount, Lagcount, Rerecords, Islagged
These are at the 'top level' and not within any other function so I do not see how making them local changes their scope. 3) in the MAIN loop, why do you call bizhawk_screen_info()? This is just a setup function that gets screen boundaries. Should it not be called just once before the loop? 4) Why is the client.paint() function OUTSIDE the main loop? What does it do? 5) functions defined but not used - test_draw_pixels ? 6) thanks again
Amaraticando
It/Its
Editor, Player (157)
Joined: 1/10/2012
Posts: 673
Location: Brazil
skypickle wrote:
1) why do you use a make_set function?
This creates a table like this
ABNORMAL_HITBOX_SPRITES = {[0x62] = true, [0x63] = true, [0x6b] = true, [0x6b] = true}
Searching for a particular entry is faster than iterating through the table until some entry has the sprite number as a value.
2) Why are variables declared as local in the top level? for example , local ABNORMAL_HITBOX_SPRITES and functions too for example
The difference between globals and those locals is that another script can see the globals too. But we usually do it more for performance, since locals are slightly faster than globals. Beware that there's a maximum of 200 locals.
3) in the MAIN loop, why do you call bizhawk_screen_info()? This is just a setup function that gets screen boundaries. Should it not be called just once before the loop?
Because the screen can be modified by the player, when (s)he maximizes the screen. This is mostly based on the lsnes script, which can manipulate the lateral gaps. A possible improvement for BizHawk is using emu.yield() to keep track of the screen size even when the emulator is paused.
4) Why is the client.paint() function OUTSIDE the main loop? What does it do?
This one is my stupidity. Since there's no way to escape the loop, there's no point having code after it.
5) functions defined but not used - test_draw_pixels ?
Just a test function that I forgot to remove, because every emulator has a different coordinates convention.