Skip to content

Structs Support #23

@Hawkbat

Description

@Hawkbat

ISSOtm's structs.asm is a thing of beauty, but I'd like to have some of that functionality in the base language as well.

Syntax Proposal:

  • StructIdentifier: STRUCT starts a struct declaration with the name StructIdentifier.
    • fieldIdentifier SB number defines a field with a size of number bytes; number is 1 if omitted.
    • fieldIdentifier SW number defines a field with a size of number * 2 bytes; number is 1 if omitted.
    • fieldIdentifier SL number defines a field with a size of number * 4 bytes; number is 1 if omitted.
  • fieldIdentifier SSTRUCT StructIdentifier defines a matching field for each field in the struct named StructIdentifier, prefixed with fieldIdentifier.
  • ENDS ends the current struct declaration.
  • DSTRUCT StructIdentifier defines a padded label for each field in the struct named StructIdentifier, as if with DS.
  • NEW StructIdentifier starts a struct instantiation of the struct named StructIdentifier. Fields can be specified in any order but will be emitted in the order defined in the struct. If any fields are omitted, their value will be undefined. For each field instantiation, fieldIdentifier must exactly match an existing field in the struct, and the total size of the arguments must not exceed the size of the field.
    • fieldIdentifier SB arg0, arg1, argN defines a label named fieldIdentifier and prefixed with the current label whose contents are equal to the provided arguments, as if they were passed to DB.
    • fieldIdentifier SW arg0, arg1, argN defines a label named fieldIdentifier and prefixed with the current label whose contents are equal to the provided arguments, as if they were passed to DW.
    • fieldIdentifier SL arg0, arg1, argN defines a label named fieldIdentifier and prefixed with the current label whose contents are equal to the provided arguments, as if they were passed to DL.
  • ENDN ends the current struct instantiation.
  • SIZEOF(StructIdentifier) returns the total size of the struct named StructIdentifier in bytes.

Example:

Character: STRUCT
name SB 8
xPosition SW
yPosition SW
spriteAddresses SW 4
somethingLong SL
ENDS

Section "RAM", wram0
wPlayerCharacter: DSTRUCT Character
; if we wanted to reserve the space but not define the field labels:
wPlayerBuffer: DS SIZEOF(Character)

Section "ROM", rom0
SlimeMonster: NEW Character
name SB "Slime", 0
spriteAddresses SW SlimeSprite0, SlimeSprite1, SlimeSprite2, SlimeSprite3
xPosition SB $F0, $40
yPosition SW $3A1F
ENDN

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions