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

[Feature request] Get a charmap string corresponding to a given number #1606

Open
Rangi42 opened this issue Jan 9, 2025 · 4 comments
Open
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Milestone

Comments

@Rangi42
Copy link
Contributor

Rangi42 commented Jan 9, 2025

ASMotor has this feature as a :C format specifier in its interpolations. For example, "{65:C}" gives "A".

It's been occasionally asked-for in RGBASM over the years; I don't recall the specific use cases (most likely to do with metaprogramming or debugging), and it's not a critical feature, but there are times it would be "nice to have".

The main argument against it, I expect, is that there could be more than one charmap to the same value(s). I think any simple consistent tiebreaking logic would be fine in this case (give the first or last defined one, the least or greatest one in strcmp ordering... whatever's most natural to implement, it's an arbitrary choice). There could be an opt-in -Wambiguous-reverse-charmap warning for such cases.

This is slightly complicated by the fact that charmaps can now exist for multiple values, like charmap "A", 1, 2, 3. It would be consistent to allow converting 1, 2, 3 back into "A". I think the natural way to handle this would be a var-arg function.

  • REVCHAR(65)
  • MAPCHAR(1, 2, 3)
  • CHR(42) (Python-esque)
  • CHARSTR($C3, $A9)
  • ...the name could be bikeshedded
@Rangi42 Rangi42 added enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM labels Jan 9, 2025
@aaaaaa123456789
Copy link
Member

I'd say the best tie-breaking criteria would be to pick the last defined character, as it's both controllable by the user and friendly towards derived charmaps.

@Rangi42
Copy link
Contributor Author

Rangi42 commented Jan 10, 2025

Do you happen to recall any specific use cases for this feature? I think mine were for a quine and a Brainfuck interpreter, neither of which is exactly "standard GB dev". :P

@aaaaaa123456789
Copy link
Member

It's the first time I hear of it. But I'm sure something will eventually come up.

@Rangi42
Copy link
Contributor Author

Rangi42 commented Jan 10, 2025

A few discussions I found about this feature on Discord:

  • 2024-01-21: "Quick question, is there a way to convert a numeric macro argument to its string equivalent based on the current charmap? Couldn't find any function in the docs to do this"
    • "I ended up just creating a new charmap entry which is no big deal. Just that the constant is defined in a different file than I wished."
  • 2022-10-11: "how do you insert arbitrary byte values"
    • "if you're using modern rgbds, CHARLEN and CHARSUB will work"
  • 2021-07-01: "is there a macro which does int_to_chr() conversion?"
  • 2025-01-11: "I'm using No$GBA/BGB style debug log messages in a rom hack of Final Fantasy Adventure and would like to be able to log save file (and main character) names. That means taking values in the game's charmap and converting them to ASCII."

@Rangi42 Rangi42 modified the milestones: 0.9.1, 0.9.2 Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs rgbasm This affects RGBASM
Projects
None yet
Development

No branches or pull requests

2 participants