// File: /workspace/github_c_makefile_star2_O2/leiradel[P]zx48k-libretro/src/zx.h
// Function: zx_key_down
void zx_key_down(zx_t* sys, int key_code) {
    CHIPS_ASSERT(sys && sys->valid);
    switch (sys->joystick_type) {
        case ZX_JOYSTICKTYPE_NONE:
            kbd_key_down(&sys->kbd, key_code);
            break;
        case ZX_JOYSTICKTYPE_KEMPSTON:
            switch (key_code) {
                case 0x20:  sys->kbd_joymask |= ZX_JOYSTICK_BTN; break;
                case 0x08:  sys->kbd_joymask |= ZX_JOYSTICK_LEFT; break;
                case 0x09:  sys->kbd_joymask |= ZX_JOYSTICK_RIGHT; break;
                case 0x0A:  sys->kbd_joymask |= ZX_JOYSTICK_DOWN; break;
                case 0x0B:  sys->kbd_joymask |= ZX_JOYSTICK_UP; break;
                default:    kbd_key_down(&sys->kbd, key_code); break;
            }
            break;
        /* the Sinclair joystick ports work as normal keys */
        case ZX_JOYSTICKTYPE_SINCLAIR_1:
            switch (key_code) {
                case 0x20:  key_code = '5'; break;    /* fire */
                case 0x08:  key_code = '1'; break;    /* left */
                case 0x09:  key_code = '2'; break;    /* right */
                case 0x0A:  key_code = '3'; break;    /* down */
                case 0x0B:  key_code = '4'; break;    /* up */
                default: break;
            }
            kbd_key_down(&sys->kbd, key_code);
            break;
        case ZX_JOYSTICKTYPE_SINCLAIR_2:
            switch (key_code) {
                case 0x20:  key_code = '0'; break;    /* fire */
                case 0x08:  key_code = '6'; break;    /* left */
                case 0x09:  key_code = '7'; break;    /* right */
                case 0x0A:  key_code = '8'; break;    /* down */
                case 0x0B:  key_code = '9'; break;    /* up */
                default: break;
            }
            kbd_key_down(&sys->kbd, key_code);
            break;
    }
}

// Assembly:
testq %rdi, %rdi
je 0x110b1
cmpb $0x0, 0x1110(%rdi)
je 0x110b1
movl 0x1118(%rdi), %eax
cmpq $0x3, %rax
ja 0x1101e
leaq 0x268a(%rip), %rcx      # 0x13680
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leal -0x8(%rsi), %eax
cmpl $0x3, %eax
ja 0x11069
leaq 0x26a2(%rip), %rcx      # 0x136b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
orb $0x2, 0x111d(%rdi)
retq
leal -0x8(%rsi), %eax
cmpl $0x3, %eax
ja 0x11057
leaq 0x2672(%rip), %rcx      # 0x136a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x31
jmp 0x1109c
leal -0x8(%rsi), %eax
cmpl $0x3, %eax
ja 0x11060
leaq 0x2646(%rip), %rcx      # 0x13690
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x36
jmp 0x1109c
cmpl $0x20, %esi
jne 0x1109d
pushq $0x35
jmp 0x1109c
cmpl $0x20, %esi
jne 0x1109d
pushq $0x30
jmp 0x1109c
cmpl $0x20, %esi
jne 0x1109d
orb $0x10, 0x111d(%rdi)
retq
pushq $0x33
jmp 0x1109c
pushq $0x34
jmp 0x1109c
pushq $0x38
jmp 0x1109c
orb $0x4, 0x111d(%rdi)
retq
pushq $0x32
jmp 0x1109c
pushq $0x39
jmp 0x1109c
orb $0x8, 0x111d(%rdi)
retq
pushq $0x37
popq %rsi
addq $0x1158, %rdi           # imm = 0x1158
jmp 0x3070
orb $0x1, 0x111d(%rdi)
retq
pushq %rbp
movq %rsp, %rbp
leaq 0x31e1(%rip), %rdi      # 0x1429d
leaq 0x30a7(%rip), %rsi      # 0x1416a
leaq 0x3232(%rip), %rcx      # 0x142fc
movl $0x153, %edx            # imm = 0x153
callq 0x30d0