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

bit struct types #13

Open
Lokathor opened this issue Oct 31, 2024 · 1 comment
Open

bit struct types #13

Lokathor opened this issue Oct 31, 2024 · 1 comment

Comments

@Lokathor
Copy link
Owner

Lokathor commented Oct 31, 2024

We need to somehow support structs where each bit controls a thing.

Example using the LCD Control:

0) BG & Window Enable / Priority
1) OBJ Enable
2) OBJ Large Size
3) BG Tilemap Higher
4) BG & Window Tiles Higher
5) Window Enabled
6) Window Tile Map Area Higher
7) LCD Enabled

Each bit controls one thing.

We need a syntax that lets the user make values of these types for loading into a register

a = // how to write the literal?
LCDC = a

and also a syntax that lets the user check or edit a value

a = LCDC
// how to check a particular bit?

Ideally users would be able to define their own types as well, but that's probably a longer term goal.

@Lokathor Lokathor changed the title lang: bit structs bit struct types Nov 11, 2024
@Lokathor
Copy link
Owner Author

Lokathor commented Nov 11, 2024

Current top idea:

// general form for accessing the `lcd_enabled` bit of the `LcdControl` type in the `a` register.
a.LcdControl.lcd_enabled

// assign `a` the value of `LcdControl` with `lcd_enabled` set (and no other bits set)
a = LcdControl { lcd_enabled }

// set or clear a specific bit
a.LcdControl.lcd_enabled = true
a.LcdControl.lcd_enabled = false

// branch on the bit being set
if a.LcdControl.lcd_enabled {
  foo()
}

// branch on the bit being clear
if not a.LcdControl.lcd_enabled {
  bar()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant