// File: /workspace/github_c_makefile_star2_O3/algodesigner[P]z80/z80.c
// Function: disasm
uint8_t disasm(z80 *cpu, uint16_t pos) {
    const char *txt;
    char jr;
    uint8_t ch = _RamRead(pos);
    uint8_t count = 1;
    uint8_t C;

    switch (ch) {
    case 0xCB: ++pos; txt = MnemonicsCB[_RamRead(pos++)]; count++; break;
    case 0xED: ++pos; txt = MnemonicsED[_RamRead(pos++)]; count++; break;
    case 0xDD: ++pos; C = 'X';
        if (_RamRead(pos) != 0xCB) {
            txt = MnemonicsXX[_RamRead(pos++)]; ++count;
        } else {
            ++pos; txt = MnemonicsXCB[_RamRead(pos++)]; count += 2;
        }
        break;
    case 0xFD: ++pos; C = 'Y';
        if (_RamRead(pos) != 0xCB) {
            txt = MnemonicsXX[_RamRead(pos++)]; ++count;
        } else {
            ++pos; txt = MnemonicsXCB[_RamRead(pos++)]; count += 2;
        }
        break;
    default:   txt = Mnemonics[_RamRead(pos++)];
    }
    while (*txt != 0) {
        switch (*txt) {
        case '*':
            txt += 2;
            ++count;
            _puthex8(_RamRead(pos++));
            break;
        case '^':
            txt += 2;
            ++count;
            _puthex8(_RamRead(pos++));
            break;
        case '#':
            txt += 2;
            count += 2;
            _puthex8(_RamRead(pos + 1));
            _puthex8(_RamRead(pos));
            break;
        case '@':
            txt += 2;
            ++count;
            jr = _RamRead(pos++);
            _puthex16(pos + jr);
            break;
        case '%':
            _putch(C);
            ++txt;
            break;
        default:
            _putch(*txt);
            ++txt;
        }
    }

    return(count);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %eax
movq %rdi, -0x30(%rbp)
movb 0x60(%rdi,%rax), %cl
movl %esi, %r12d
incl %r12d
movzbl %cl, %edx
movb $0x2, %dil
movw $0x2, %r8w
movb $0x1, %r14b
leaq 0xe035(%rip), %rax      # 0x175f0
cmpl $0xec, %edx
jg 0x95e7
cmpl $0xcb, %edx
je 0x9602
cmpl $0xdd, %edx
jne 0x9600
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %cl
leal 0x2(%rsi), %r12d
movb $0x58, %dl
jmp 0x961d
cmpl $0xfd, %edx
je 0x960b
cmpl $0xed, %edx
jne 0x9600
leaq 0xc7f2(%rip), %rax      # 0x15df0
jmp 0x9609
jmp 0x9653
leaq 0xbfe7(%rip), %rax      # 0x155f0
jmp 0x9631
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %cl
leal 0x2(%rsi), %r12d
movb $0x59, %dl
cmpb $-0x35, %cl
jne 0x9649
movb $0x3, %dil
leaq 0xd7c4(%rip), %rax      # 0x16df0
movw $0x3, %r8w
movzwl %r12w, %ecx
movzwl %r8w, %r12d
addl %esi, %r12d
movq -0x30(%rbp), %rsi
movb 0x60(%rsi,%rcx), %cl
movl %edi, %r14d
jmp 0x9653
movb $0x2, %r14b
leaq 0xcf9d(%rip), %rax      # 0x165f0
movzbl %cl, %ecx
movq (%rax,%rcx,8), %r13
movzbl %dl, %r15d
movzwl %r12w, %ebx
addq $0x2, %r13
movzbl -0x2(%r13), %edi
cmpl $0x29, %edi
jg 0x967a
cmpl $0x25, %edi
jne 0x968b
movl %r15d, %edi
jmp 0x9694
cmpl $0x5e, %edi
je 0x96be
cmpl $0x40, %edi
je 0x96d2
cmpl $0x2a, %edi
jne 0x9694
jmp 0x96be
testl %edi, %edi
je 0x96f3
cmpl $0x23, %edi
je 0x969e
callq 0x925d
incq %r13
jmp 0x9666
addb $0x2, %r14b
movq -0x30(%rbp), %r12
movzbl 0x61(%r12,%rbx), %edi
callq 0x92aa
movzbl 0x60(%r12,%rbx), %edi
callq 0x92aa
jmp 0x9662
leal 0x1(%rbx), %r12d
movq -0x30(%rbp), %rax
movzbl 0x60(%rax,%rbx), %edi
callq 0x92aa
jmp 0x96eb
movq -0x30(%rbp), %rax
movsbl 0x60(%rax,%rbx), %eax
leal 0x1(%rbx), %r12d
addl %ebx, %eax
incl %eax
movzwl %ax, %edi
callq 0x92ff
incb %r14b
jmp 0x965e
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq