Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structs Support #23

Open
Hawkbat opened this issue Feb 24, 2019 · 0 comments
Open

Structs Support #23

Hawkbat opened this issue Feb 24, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@Hawkbat
Copy link
Owner

Hawkbat commented Feb 24, 2019

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
@Hawkbat Hawkbat added the enhancement New feature or request label Feb 24, 2019
@Hawkbat Hawkbat changed the title FUTURE: Structs Support Structs Support Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant