// File: /workspace/github_c_makefile_star2_O2/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)
movzbl 0x60(%rdi,%rax), %edx
movl %esi, %r12d
incl %r12d
movb $0x2, %r14b
movw $0x2, %di
cmpl $0xcb, %edx
je 0x9602
cmpl $0xdd, %edx
je 0x95be
cmpl $0xfd, %edx
je 0x95d2
cmpl $0xed, %edx
jne 0x961e
leaq 0xc834(%rip), %rcx      # 0x15df0
jmp 0x9609
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %dl
leal 0x2(%rsi), %r12d
movb $0x58, %al
jmp 0x95e4
movzwl %r12w, %eax
movq -0x30(%rbp), %rcx
movb 0x60(%rcx,%rax), %dl
leal 0x2(%rsi), %r12d
movb $0x59, %al
cmpb $-0x35, %dl
jne 0x95f9
movb $0x3, %r14b
leaq 0xd7fd(%rip), %rcx      # 0x16df0
movw $0x3, %di
jmp 0x9609
leaq 0xcff0(%rip), %rcx      # 0x165f0
jmp 0x9628
leaq 0xbfe7(%rip), %rcx      # 0x155f0
movzwl %r12w, %edx
movzwl %di, %r12d
addl %esi, %r12d
movq -0x30(%rbp), %rsi
movb 0x60(%rsi,%rdx), %dl
jmp 0x9628
movb $0x1, %r14b
leaq 0xdfc8(%rip), %rcx      # 0x175f0
movzbl %dl, %edx
movq (%rcx,%rdx,8), %r13
movzbl %al, %r15d
movzwl %r12w, %ebx
addq $0x2, %r13
movzbl -0x2(%r13), %eax
cmpl $0x25, %eax
je 0x9662
testl %eax, %eax
je 0x96c4
cmpl $0x23, %eax
je 0x966f
cmpl $0x5e, %eax
je 0x968f
cmpl $0x40, %eax
je 0x96a3
cmpl $0x2a, %eax
je 0x968f
movzbl %al, %edi
jmp 0x9665
movl %r15d, %edi
callq 0x925b
incq %r13
jmp 0x963b
addb $0x2, %r14b
movq -0x30(%rbp), %r12
movzbl 0x61(%r12,%rbx), %edi
callq 0x929d
movzbl 0x60(%r12,%rbx), %edi
callq 0x929d
jmp 0x9637
leal 0x1(%rbx), %r12d
movq -0x30(%rbp), %rax
movzbl 0x60(%rax,%rbx), %edi
callq 0x929d
jmp 0x96bc
movq -0x30(%rbp), %rax
movsbl 0x60(%rax,%rbx), %eax
leal 0x1(%rbx), %r12d
addl %ebx, %eax
incl %eax
movzwl %ax, %edi
callq 0x92eb
incb %r14b
jmp 0x9633
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq