// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x215e5
movq -0x8(%rbp), %rax
testb $0x1, 0x1110(%rax)
je 0x215e5
jmp 0x21604
leaq 0x3db1(%rip), %rdi      # 0x2539d
leaq 0x3c77(%rip), %rsi      # 0x2526a
movl $0x153, %edx            # imm = 0x153
leaq 0x3dfd(%rip), %rcx      # 0x253fc
callq 0x3180
movq -0x8(%rbp), %rax
movl 0x1118(%rax), %eax
movq %rax, -0x18(%rbp)
subq $0x3, %rax
ja 0x217c7
movq -0x18(%rbp), %rax
leaq 0x3019(%rip), %rcx      # 0x24640
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
addq $0x1158, %rdi           # imm = 0x1158
movl -0xc(%rbp), %esi
callq 0x30b0
jmp 0x217c7
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x18, %eax
ja 0x216df
movq -0x20(%rbp), %rax
leaq 0x30b0(%rip), %rcx      # 0x24718
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movzbl 0x111d(%rax), %ecx
orl $0x10, %ecx
movb %cl, 0x111d(%rax)
jmp 0x216f2
movq -0x8(%rbp), %rax
movzbl 0x111d(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x111d(%rax)
jmp 0x216f2
movq -0x8(%rbp), %rax
movzbl 0x111d(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x111d(%rax)
jmp 0x216f2
movq -0x8(%rbp), %rax
movzbl 0x111d(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x111d(%rax)
jmp 0x216f2
movq -0x8(%rbp), %rax
movzbl 0x111d(%rax), %ecx
orl $0x8, %ecx
movb %cl, 0x111d(%rax)
jmp 0x216f2
movq -0x8(%rbp), %rdi
addq $0x1158, %rdi           # imm = 0x1158
movl -0xc(%rbp), %esi
callq 0x30b0
jmp 0x217c7
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x18, %eax
ja 0x21749
movq -0x28(%rbp), %rax
leaq 0x2fa1(%rip), %rcx      # 0x246b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x35, -0xc(%rbp)
jmp 0x2174b
movl $0x31, -0xc(%rbp)
jmp 0x2174b
movl $0x32, -0xc(%rbp)
jmp 0x2174b
movl $0x33, -0xc(%rbp)
jmp 0x2174b
movl $0x34, -0xc(%rbp)
jmp 0x2174b
jmp 0x2174b
movq -0x8(%rbp), %rdi
addq $0x1158, %rdi           # imm = 0x1158
movl -0xc(%rbp), %esi
callq 0x30b0
jmp 0x217c7
movl -0xc(%rbp), %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x18, %eax
ja 0x217b2
movq -0x30(%rbp), %rax
leaq 0x2ed4(%rip), %rcx      # 0x24650
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x30, -0xc(%rbp)
jmp 0x217b4
movl $0x36, -0xc(%rbp)
jmp 0x217b4
movl $0x37, -0xc(%rbp)
jmp 0x217b4
movl $0x38, -0xc(%rbp)
jmp 0x217b4
movl $0x39, -0xc(%rbp)
jmp 0x217b4
jmp 0x217b4
movq -0x8(%rbp), %rdi
addq $0x1158, %rdi           # imm = 0x1158
movl -0xc(%rbp), %esi
callq 0x30b0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)