Page 1 of 1
Struct maros/syntax and naming conventions
Posted: Thu Apr 26, 2018 9:04 am
by OrangyTang
Another day, another stupid question
As I poke into the gameplay code of the disassembly, I'm finding more code like this:
Code: Select all
LEA $FFFFA400.w, A5 ; player 1 state struct
BSR.w updatePlayer
...
updatePlayer:
MOVE.w $C8(A5), D0 ; read current player weapon into D0
Where there's basically an object/struct at a fixed place in memory, it's loaded into an A4/5/6 register and then it accesses the struct members at fixed offsets. Other than just defining constants for the 'C8' offsets, is there a way to make this more readable? I kinda want a way of defining a struct and it's member names, and having the assembler generate the correct offsets.
Along similar lines I'm basically making up naming conventions as I go (like camel case for labels, upper case for constant, etc.) but are there any standard naming conventions for 68k / Megadrive code? What tricks do you like to use to make things more readable?
Thanks.
Re: Struct maros/syntax and naming conventions
Posted: Thu Apr 26, 2018 6:17 pm
by TmEE co.(TM)
I do stuff like that :
OffsetName EQU 124
MOVE.W OffsetName(A0), D0
EDIT: Exactly what you try to avoid... lol. I don't know of any better solution.
Re: Struct maros/syntax and naming conventions
Posted: Fri Apr 27, 2018 7:08 am
by Stef
I know several x86 assembler supporting structure but i'm not sure about 68k assembler (code warrior seems to support it).
Re: Struct maros/syntax and naming conventions
Posted: Fri Apr 27, 2018 1:00 pm
by OrangyTang
So I dug out the old manual for snasm68k, and I think the 'rs' and 'rsset' macros are what I need (see page 27) :
https://segaretro.org/images/0/04/SNASM ... Manual.pdf
However I can't actually figure ou the usage syntax atm. This works to define a struct, but actually using it always generates a syntax error
Code: Select all
rsreset
Player_WeaponId rs.w 0
Player_Health rs.w 0
Player_CharId rs.b 0
Re: Struct maros/syntax and naming conventions
Posted: Fri Apr 27, 2018 6:16 pm
by Mask of Destiny
You should put a non-zero number after the rs.b/rs.w/rs.l as that's the number of elements of that size you're allocating. Not sure if that's causing your syntax error, but you definitely won't get the right results with zero.
Re: Struct maros/syntax and naming conventions
Posted: Sun Apr 29, 2018 12:09 am
by Sik
Is the error on RSRESET? Try RSSET 0 instead if so. If you get errors on RS too, well... (and yeah, MOD is right, the number in RS should reflect how much of that size are you allocating, e.g. rs.w 1 if the value is a word)
Anyway yeah, I normally use RS for this stuff, but that's for my own homebrew where the format of the structure may change at any time and I don't want to have to sort out the offsets every time it changes. For a disassembly of a game I'd actually use EQU instead.
Re: Struct maros/syntax and naming conventions
Posted: Tue May 01, 2018 10:15 am
by BigEvilCorporation
Yeah RSRESET doesn't work for ASM68K and older versions of SNASM68K, stick to RSSET 0.
I go... a little overboard with struct usage :p
Code: Select all
rsset 0
;-----------------------------
IFND FINAL
Entity_DebugName rs.b entity_name_length ; Debug name string
ENDIF
;-----------------------------
Entity_TypeBits rs.l 1 ; Entity type bits
;-----------------------------
Entity_UpdateRoutine rs.l 1 ; Update subroutine address
Entity_RenderRoutine rs.l 1 ; Render subroutine address
Entity_SerialiseRoutine rs.l 1 ; Save/load subroutine address
;-----------------------------
LINKED_LIST_NODE EntityWorldGrid ; Next in world grid linked list
LINKED_LIST_NODE EntityUpdate ; Next in update linked list
LINKED_LIST_NODE EntityRender ; Next in render linked list
LINKED_LIST_NODE EntitySerialise ; Next in serialise linked list
;-----------------------------
Entity_WorldPosX rs.l 1 ; Position X (world space)
Entity_WorldPosY rs.l 1 ; Position Y (world space)
Entity_Width rs.w 1 ; Width (pixels)
Entity_Height rs.w 1 ; Height(pixels)
Entity_WorldGridIdxTL rs.w 1 ; World grid index (top-left corner)
Entity_WorldGridIdxBR rs.w 1 ; World grid index (bottom-right corner)
Entity_WorldGridFlags rs.b 1 ; Current state in update/render grid (EntityGridFlag_*)
Entity_WorldGridOrder rs.b 1 ; Order to insert into world grid, for removal/reinserting
Entity_Active rs.b 1 ; Active flag
;-----------------------------
RS_ALIGN
Entity_Struct_Size rs.b 0
...
rsset Entity_Struct_Size
;-----------------------------------
SpriteObj_SubSpriteDimArr rs.l 1 ; Multi-sprite subsprite dimentions bits array address
SpriteObj_SubSpriteOffArr rs.l 1 ; Subsprite position offsets array address
SpriteObj_TilesetAddr rs.l 1 ; Art tiles ROM address
SpriteObj_PaletteAddr rs.l 1 ; Palette ROM address
SpriteObj_VRAMAddr rs.w 1 ; Art tiles VRAM address
SpriteObj_DrawOffsetX rs.w 1 ; Sprite draw offset X (pixels)
SpriteObj_DrawOffsetY rs.w 1 ; Sprite draw offset Y (pixels)
SpriteObj_SizeTiles rs.w 1 ; Number of tiles
SpriteObj_TileID rs.w 1 ; First tile ID (VRAM)
SpriteObj_PaletteIdx rs.b 1 ; Palette ID
SpriteObj_Priority rs.b 1 ; Priority (0/1)
SpriteObj_NumSubSprites rs.b 1 ; Num sub-sprites
SpriteObj_FlippedX rs.b 1 ; Sprite flip X
SpriteObj_FlippedY rs.b 1 ; Sprite flip Y
SpriteObj_Visible rs.b 1 ; Is visible (hidden in sprite border if not)
SpriteObj_SpriteLinked rs.b 1 ; Is sprite linked (use as last frame visibility test)
SpriteObj_PaletteAutoLoad rs.b 1 ; Load palette if on screen and not loaded
;-----------------------------------
RS_ALIGN
SpriteObj_Struct_Size rs.b 0
;-----------------------------------
..and about another 5 derivatives of that - AnimObj, PhysicsObj, CharacterObj, PlayerObj, Nymn.