-
-
Notifications
You must be signed in to change notification settings - Fork 171
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] Use the bytes of an opcode in numeric expressions #823
Comments
This was discussed previously in Discord |
Here's a tentative implementation:
The main problem is how to handle the patches, though.
I think that this would require the lazy expression evaluator (#663) anyway, though we may want to design it with this in mind..? |
If we go with a |
That would be trivial with a dummy argument ( |
I think |
Doubt it, it's not very DRY, especially if some syntax regarding expressions is changed. (Shortcuts, or whatever.) I prefer the dummy argument solution. |
Examples using
|
LOAD
blocks exist for whole chunks of RAM code. However, self-modifying code usually needs more fine-grained control, writing and rewriting individual bytes, not just copying N bytes from ROM to RAM. Here's an example:And another:
rgbasm
can already encode instructions as bytes, so it would be convenient to have a syntax allowing those bytes as part of usual numeric expressions. A few ideas:<[ nop ]>
(inspired by HTML CDATA)'nop'
(not currently in use)OPCODE(nop)
(likeHIGH(bc)
orDEF(Symbol)
)(I think
OPCODE
would be clearest and fit in best with existingrgbasm
syntax; too much meaningful punctuation ends up like Perl.)Some tricky details:
rl h
acts likedb $CB, $14
; this could be pretty easily handled withHIGH
andLOW
, likeld a, LOW(OPCODE(rl h)) / ld [hli], a / ld [hl], HIGH(OPCODE(rl h))
. (Little-endian order to be consistent, sodw OPCODE(rl h)
would act like plainrl h
.) Three-byte ones would still be feasible, if less convenient: dodef op = OPCODE(ld hl, $abcd)
, then work withLOW(op)
($21),HIGH(op)
($cd), andop>>16
($ab).@
: e.g. jumping ahead 5 bytes without a label is done asjr (@ + 2) + 5
. Here,OPCODE(jr 5)
could evaluate to$0518
, orOPCODE(jr z, $ff)
to$ff28
(aka the notional "rst z, $38
"). Or just disallow the destination here, soOPCODE(jr) == $18
andOPCODE(jr z) == $28
.However this is done, it should reuse the parser's regular opcode handling, without needing two separate paths. I don't expect that to be a problem.
The text was updated successfully, but these errors were encountered: