// File: /workspace/github_c_makefile_star2_O1/minkcv[P]vm/machine/vm.c
// Function: handleDebugKey
void handleDebugKey(VM* vm, SDL_Keycode key)
{
    if (key == SDLK_F2)
    {
        // Continue
        vm->cpu.breakState = 0;
        vm->cpu.step = 0;
        printf("Resuming execution\n");
    }
    if (key == SDLK_F3)
    {
        // Break all
        vm->cpu.breakState = 1;
        printf("Entering break state\n");
    }
    if (key == SDLK_F4)
    {
        // Step
        vm->cpu.breakState = 0;
        vm->cpu.step = 1;
        printf("Stepping\n");
    }
    if (key == SDLK_F9)
    {
	print_cpu_state(&vm->cpu);
    }
    if (key == SDLK_F10)
    {
        // Dump memory segments 0 through 63 (inclusive)
        int segment;
        int offset;
        int rowLength = 16;
        for (segment = 0; segment < 64; segment++)
        {
            for (offset = 0; offset < 256; offset++)
            {
                if (offset % rowLength == 0)
                    printf("\n0x%02X.0x%02X: 0x", segment, offset);
                printf("%02X", vm->memory[segment][offset]);
            }
        }
        printf("\n");
    }
    if (key == SDLK_F11)
    {
        // Dump memory segments 64 through 127 (inclusive)
        int segment;
        int offset;
        int rowLength = 16;
        for (segment = 64; segment < 128; segment++)
        {
            for (offset = 0; offset < 256; offset++)
            {
                if (offset % rowLength == 0)
                    printf("\n0x%02X.0x%02X: 0x", segment, offset);
                printf("%02X", vm->memory[segment][offset]);
            }
        }
        printf("\n");
    }
    if (key == SDLK_F12)
    {
	// Disassemble next 16 instructions
        print_disasm_block(&vm->cpu);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leal -0x4000003b(%rsi), %eax
cmpl $0xa, %eax
ja 0x1b8f
leaq 0x1682(%rip), %rcx      # 0x30c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, 0x24(%rdi)
leaq 0x16c5(%rip), %rdi      # 0x3123
jmp 0x1bb3
movl $0x1, 0x24(%rdi)
leaq 0x16c5(%rip), %rdi      # 0x3136
jmp 0x1bb3
movq %rsi, -0x30(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x30(%rdi), %r14
leaq 0x166b(%rip), %r15      # 0x30f4
leaq 0x1677(%rip), %r12      # 0x3107
xorl %r13d, %r13d
xorl %ebx, %ebx
testb $0xf, %bl
jne 0x1aa9
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1040
movzbl (%r14,%rbx), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x1040
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x1a95
incq %r13
addq $0x100, %r14            # imm = 0x100
cmpq $0x40, %r13
jne 0x1a93
movl $0xa, %edi
callq 0x11a0
movq -0x30(%rbp), %rsi
cmpl $0x40000045, %esi       # imm = 0x40000045
movq -0x38(%rbp), %rdi
je 0x1b7c
cmpl $0x40000044, %esi       # imm = 0x40000044
jne 0x1b8f
movq %rsi, -0x30(%rbp)
movq %rdi, -0x38(%rbp)
leaq 0x4030(%rdi), %r14
movl $0x40, %r15d
leaq 0x15da(%rip), %r12      # 0x30f4
leaq 0x15e6(%rip), %r13      # 0x3107
xorl %ebx, %ebx
testb $0xf, %bl
jne 0x1b37
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1040
movzbl (%r14,%rbx), %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x1040
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x1b23
incq %r15
addq $0x100, %r14            # imm = 0x100
cmpq $0x80, %r15
jne 0x1b21
movl $0xa, %edi
callq 0x11a0
cmpl $0x40000045, -0x30(%rbp) # imm = 0x40000045
movq -0x38(%rbp), %rdi
jne 0x1b8f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29ce
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x24(%rdi)
leaq 0x1598(%rip), %rdi      # 0x314b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11d0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ac7
nopl (%rax)