// File: /workspace/github_c_makefile_star2_O2/leiradel[P]zx48k-libretro/src/zx.h
// Function: zx_joystick
void zx_joystick(zx_t* sys, uint8_t mask) {
    CHIPS_ASSERT(sys && sys->valid);
    if (sys->joystick_type == ZX_JOYSTICKTYPE_SINCLAIR_1) {
        if (mask & ZX_JOYSTICK_RIGHT) { kbd_key_down(&sys->kbd, '5'); }
        else                          { kbd_key_up(&sys->kbd, '5'); }
        if (mask & ZX_JOYSTICK_LEFT)  { kbd_key_down(&sys->kbd, '1'); }
        else                          { kbd_key_up(&sys->kbd, '1'); }
        if (mask & ZX_JOYSTICK_RIGHT) { kbd_key_down(&sys->kbd, '2'); }
        else                          { kbd_key_up(&sys->kbd, '2'); }
        if (mask & ZX_JOYSTICK_DOWN)  { kbd_key_down(&sys->kbd, '3'); }
        else                          { kbd_key_up(&sys->kbd, '3'); }
        if (mask & ZX_JOYSTICK_UP)    { kbd_key_down(&sys->kbd, '4'); }
        else                          { kbd_key_up(&sys->kbd, '4'); }
    }
    else if (sys->joystick_type == ZX_JOYSTICKTYPE_SINCLAIR_2) {
        if (mask & ZX_JOYSTICK_RIGHT) { kbd_key_down(&sys->kbd, '0'); }
        else                          { kbd_key_up(&sys->kbd, '0'); }
        if (mask & ZX_JOYSTICK_LEFT)  { kbd_key_down(&sys->kbd, '6'); }
        else                          { kbd_key_up(&sys->kbd, '6'); }
        if (mask & ZX_JOYSTICK_RIGHT) { kbd_key_down(&sys->kbd, '7'); }
        else                          { kbd_key_up(&sys->kbd, '7'); }
        if (mask & ZX_JOYSTICK_DOWN)  { kbd_key_down(&sys->kbd, '8'); }
        else                          { kbd_key_up(&sys->kbd, '8'); }
        if (mask & ZX_JOYSTICK_UP)    { kbd_key_down(&sys->kbd, '9'); }
        else                          { kbd_key_up(&sys->kbd, '9'); }
    }
    else {
        sys->joy_joymask = mask;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x1137a
movq %rdi, %rbx
cmpb $0x0, 0x1110(%rdi)
je 0x1137a
movl %esi, %r14d
movl 0x1118(%rbx), %eax
cmpl $0x3, %eax
je 0x11298
cmpl $0x2, %eax
jne 0x112b2
addq $0x1158, %rbx           # imm = 0x1158
pushq $0x35
popq %rsi
movq %rbx, %rdi
testb $0x1, %r14b
jne 0x112be
callq 0x3060
jmp 0x112c3
addq $0x1158, %rbx           # imm = 0x1158
pushq $0x30
popq %rsi
movq %rbx, %rdi
testb $0x1, %r14b
jne 0x1130f
callq 0x3060
jmp 0x11314
movb %r14b, 0x111e(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
callq 0x3070
pushq $0x31
popq %rsi
movq %rbx, %rdi
testb $0x2, %r14b
jne 0x112d6
callq 0x3060
jmp 0x112db
callq 0x3070
pushq $0x32
popq %rsi
movq %rbx, %rdi
testb $0x1, %r14b
jne 0x112ee
callq 0x3060
jmp 0x112f3
callq 0x3070
pushq $0x33
popq %rsi
movq %rbx, %rdi
testb $0x4, %r14b
jne 0x11306
callq 0x3060
jmp 0x1130b
callq 0x3070
pushq $0x34
jmp 0x1135e
callq 0x3070
pushq $0x36
popq %rsi
movq %rbx, %rdi
testb $0x2, %r14b
jne 0x11327
callq 0x3060
jmp 0x1132c
callq 0x3070
pushq $0x37
popq %rsi
movq %rbx, %rdi
testb $0x1, %r14b
jne 0x1133f
callq 0x3060
jmp 0x11344
callq 0x3070
pushq $0x38
popq %rsi
movq %rbx, %rdi
testb $0x4, %r14b
jne 0x11357
callq 0x3060
jmp 0x1135c
callq 0x3070
pushq $0x39
popq %rsi
movq %rbx, %rdi
testb $0x8, %r14b
jne 0x11371
popq %rbx
popq %r14
popq %rbp
jmp 0x3060
popq %rbx
popq %r14
popq %rbp
jmp 0x3070
leaq 0x2f1c(%rip), %rdi      # 0x1429d
leaq 0x2de2(%rip), %rsi      # 0x1416a
leaq 0x3009(%rip), %rcx      # 0x14398
movl $0x1b1, %edx            # imm = 0x1B1
callq 0x30d0