EdouardBERGE / rasm

RASM powerful Z80 assembler
129 stars 16 forks source link

Suggestion: add an `opcode` function that returns the value of the given opcode #2

Closed rgiot closed 3 years ago

rgiot commented 4 years ago

The following sample file illustrates a simple example that works properly with by toy assembler: https://github.com/cpcsdk/rust.cpclib/blob/master/cpclib-asm/tests/opcode.asm and deserves to be available with rasm.

To add this function will allow people that write self-modifying code to not search by which value an opcode is supposed to be replaced:

 ld a, opcode(pop hl)
 ld (myroutine.regpop), a

instead of

OPCODE_POP_HL equ 0xe1
...
 ld a,  OPCODE_POP_HL
 ld (myroutine.regpop), a

I think such function should return a 32bit value in order to properly manage 4 bytes opcodes

EdouardBERGE commented 3 years ago

i think it's too messy in order to be friendly and convenient to use, mostly because opcode may have "any" size

cpcitor commented 3 years ago

I love the idea because it allows somehow more "readable"/"maintainable" code in theory. In practice because opcode can be more than one byte, I understand that it causes complexity and promise of maintainability of the assembler program itself weighs against. ¯\_(ツ)_/¯

What I would do as a user is have an independently generated, ready-to-use table of name-for-Z80-opcodes-that-fit-on-one-byte and use those names.

EdouardBERGE commented 3 years ago

anyone can propose some kind of "best includes for you" like "amstrad_firmware_calls.inc" or "opcodes_bytes.inc"

cpcitor commented 3 years ago

anyone can propose some kind of "best includes for you" like "amstrad_firmware_calls.inc" or "opcodes_bytes.inc"

Well, "anyone" can be me.

@rgiot, you will find on https://github.com/cpcitor/cpc-dev-tool-chain/blob/master/cpclib/cdtc/asminclude/cdtc/z80_syms_for_opcodes_first_byte.s a generated table.

It uses the sdasz80 syntax (because it is part of cpc-dev-tool-chain which existed before rasm), but it is very easy to change all .equ to EQU or whatever you want.

As you will see, it somehow does more than you expected, as it additionally provides names that ensure opcode meaning and visible hex value are always in sync.

"amstrad_firmware_calls.inc"

I might make something similar one day.

As a side effect of making a C-level wrapper to the firmware routines, some are in https://github.com/cpcitor/cpc-dev-tool-chain/blob/master/cpclib/cfwi/src/fw_nowrapperneeded.s

EdouardBERGE commented 3 years ago

thanks for the opcode file, i puted it in a "resources" folder