// File: /workspace/github_c_makefile_star2_O1/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 0xe033(%rip), %rax      # 0x175f0
cmpl $0xec, %edx
jg 0x95e9
cmpl $0xcb, %edx
je 0x9604
cmpl $0xdd, %edx
jne 0x9602
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %cl
leal 0x2(%rsi), %r12d
movb $0x58, %dl
jmp 0x961f
cmpl $0xfd, %edx
je 0x960d
cmpl $0xed, %edx
jne 0x9602
leaq 0xc7f0(%rip), %rax      # 0x15df0
jmp 0x960b
jmp 0x9655
leaq 0xbfe5(%rip), %rax      # 0x155f0
jmp 0x9633
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %cl
leal 0x2(%rsi), %r12d
movb $0x59, %dl
cmpb $-0x35, %cl
jne 0x964b
movb $0x3, %dil
leaq 0xd7c2(%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 0x9655
movb $0x2, %r14b
leaq 0xcf9b(%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 0x967c
cmpl $0x25, %edi
jne 0x968d
movl %r15d, %edi
jmp 0x9696
cmpl $0x5e, %edi
je 0x96c0
cmpl $0x40, %edi
je 0x96d4
cmpl $0x2a, %edi
jne 0x9696
jmp 0x96c0
testl %edi, %edi
je 0x96f5
cmpl $0x23, %edi
je 0x96a0
callq 0x925d
incq %r13
jmp 0x9668
addb $0x2, %r14b
movq -0x30(%rbp), %r12
movzbl 0x61(%r12,%rbx), %edi
callq 0x92aa
movzbl 0x60(%r12,%rbx), %edi
callq 0x92aa
jmp 0x9664
leal 0x1(%rbx), %r12d
movq -0x30(%rbp), %rax
movzbl 0x60(%rax,%rbx), %edi
callq 0x92aa
jmp 0x96ed
movq -0x30(%rbp), %rax
movsbl 0x60(%rax,%rbx), %eax
leal 0x1(%rbx), %r12d
addl %ebx, %eax
incl %eax
movzwl %ax, %edi
callq 0x92f4
incb %r14b
jmp 0x9660
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq