Struct maros/syntax and naming conventions

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
OrangyTang
Interested
Posts: 19
Joined: Tue Feb 23, 2016 4:45 pm

Struct maros/syntax and naming conventions

Post by OrangyTang » Thu Apr 26, 2018 9:04 am

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.

User avatar
TmEE co.(TM)
Very interested
Posts: 2296
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Struct maros/syntax and naming conventions

Post by TmEE co.(TM) » Thu Apr 26, 2018 6:17 pm

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.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

User avatar
Stef
Very interested
Posts: 2744
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Struct maros/syntax and naming conventions

Post by Stef » Fri Apr 27, 2018 7:08 am

I know several x86 assembler supporting structure but i'm not sure about 68k assembler (code warrior seems to support it).

OrangyTang
Interested
Posts: 19
Joined: Tue Feb 23, 2016 4:45 pm

Re: Struct maros/syntax and naming conventions

Post by OrangyTang » Fri Apr 27, 2018 1:00 pm

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

Mask of Destiny
Very interested
Posts: 563
Joined: Thu Nov 30, 2006 6:30 am

Re: Struct maros/syntax and naming conventions

Post by Mask of Destiny » Fri Apr 27, 2018 6:16 pm

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.

User avatar
Sik
Very interested
Posts: 682
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Struct maros/syntax and naming conventions

Post by Sik » Sun Apr 29, 2018 12:09 am

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.
Sik is pronounced as "seek", not as "sick".

User avatar
BigEvilCorporation
Very interested
Posts: 199
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: Struct maros/syntax and naming conventions

Post by BigEvilCorporation » Tue May 01, 2018 10:15 am

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.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests