MASM - macro variable?

This is my first question here, and I hope you can help me! I am currently working on a GameBoy emulator and I want to write it to MASM, for processing CPU instructions I want to create an array with variables in order to facilitate my access.

Here is an example I want to achieve:

assume esi:ptr CPU_CORE
REGISTER_A equ (([esi].registers.AF AND 0F0h) SAR 3h)
REGISTER_B equ (([esi].registers.BC AND 0F0h) SAR 3h)
REGISTER_C equ (([esi].registers.BC AND 0Fh))
PARAM_TABLE [Type?] REGISTER_A
            [Type?] REGISTER_B
            [Type?] REGISTER_C
assume esi:ptr NOTHING

and if I want to get the value from PARAM_TABLE, it should work as follows:

lea esi, PARAM_TABLE
mov ecx, 1h ; just as example for accessing REGISTER_B
mov eax, [esi+ecx*[TYPE?]]
;EAX now contains the value from the hi-byte of the BC register, so: (([esi].registers.BC AND 0F0h) SAR 3h)

So basically my idea is to create variables like REGISTER_A to make access easier. I hope you understand me. Maybe this can be done with macros?

+4
source share
1 answer

, , . , , :

REGISTER_A equ [esi+CPU_CORE.registers.A]

:

mov eax, REGISTER_A ;EAX will now contain the value of the register A.

, ( , .)

REGISTER_A equ CPU_CORE.registers.A

, PARAM, :

PARAM struct
  pointer DWORD  ? ;Register pointer
  flags   BYTE   ? ;BIT 0: Content Flag, BIT 1: 8 or 16 bit
  desc    DWORD  ? ;Description of the parameter
PARAM ends

LD R, R. :

PARAM_LIST_R    PARAM       <CPU_CORE.registers.B, 0, _stro('B')>
                PARAM       <CPU_CORE.registers._C, 0, _stro('C')>
                PARAM       <CPU_CORE.registers.D, 0, _stro('D')>
                PARAM       <CPU_CORE.registers.E, 0, _stro('E')>
                PARAM       <CPU_CORE.registers.H, 0, _stro('H')>
                PARAM       <CPU_CORE.registers.L, 0, _stro('L')>
                PARAM       <CPU_CORE.registers.H, 1, _stro('(HL)')>
                PARAM       <CPU_CORE.registers.A, 0, _stro('A')>

LoadParam       proc        cpu_core:DWORD, param:DWORD
    LOCAL value:DWORD
    pushad
    mov esi, cpu_core
    mov edi, param
    assume esi:ptr CPU_CORE
    assume edi:ptr PARAM
    add esi, [edi].pointer
    movzx ebx, [edi].flags
    bt ebx, 0
    test ebx, ebx
    jnc @NO_CONTENT
    movzx edx, word ptr ds:[esi]
    ;-- ADDING CPU_READ FUNCTION --;
    jmp @DONE
@NO_CONTENT:
    bt ebx, 1
    jc @GET16Bit
    movzx eax, byte ptr ds:[esi]
    jmp @DONE
@GET16Bit:
    movzx eax, word ptr ds:[esi]
@DONE:
    mov value, eax
    assume esi:ptr NOTHING
    assume edi:ptr NOTHING
    popad
    mov eax, value
    ret
LoadParam endp

CPU_CORE ESI PARAM EDI, PARAM CPU_CORE. , BIT 0 , CPU ( : (HL)), , . BIT 1 , , 16- (BC, DE, HL) 8- (B, C, D, E, H, L, A).

, , . - , , , , " " .

, : "" "z80 decoding" google.

+2

All Articles