

macro dispatch arg {  ; begins procedure instructions
  common
    local ..caselist, ..caseaddr, ..casesize

    case@size equ ..casesize
    case@list equ ..caselist
    case@addr equ ..caseaddr

    macro oncase idname \{
      \local ..offset

      store byte $3d at ..caseaddr               ; cmp eax, dword imm    ; 5 bytes
      store dword idname at ..caseaddr+1
      ..caseaddr = ..caseaddr + 5
      ..offset = $ - ..caseaddr - 2

      store word $840f at ..caseaddr             ; je dword offset       ; 6 bytes
      store dword ..offset - 4 at ..caseaddr+2
      ..caseaddr = ..caseaddr + 6
    \}


    mov  eax, arg

    ..caselist:
    ..caseaddr = $

    rb ..casesize
}


macro enddispatch {
  case@size = case@addr - case@list
  restore case@size, case@addr, case@list
  purge oncase
}



