// File: /workspace/github_cpp_makefile_star2_O1/khedoros[P]khednes/mapper_003_cnrom.cpp
// Function: mapper_003::cycle_forward(unsigned int)
rom::ppu_change_t mapper_003::cycle_forward(unsigned int cycle) {
    unsigned int next_c = cycle + 1;
    if(ppu_queue.size() > 0) {
        next_c = ppu_queue.front().first;
    }
    rom::ppu_change_t changes;
    changes.val = 0;
    while(ppu_queue.size() > 0 && next_c < cycle) {
        rom_command_t comm = ppu_queue.front().second.first;
        int val = ppu_queue.front().second.second;
        switch(comm) {
        case lo_crom:
            changes.lo_crom = 1;
            chr_lo_offset = val;
            break;
        case hi_crom:
            changes.hi_crom = 1;
            chr_hi_offset = val;
            break;
        case set_horiz:
            changes.set_horiz = 1;
            cart->mirror_mode = HORIZ;
            break;
        case set_vert:
            changes.set_vert = 1;
            cart->mirror_mode = VERT;
            break;
        case set_4_scr:
            changes.set_4_scr = 1;
            cart->mirror_mode = FOUR_SCR;
            break;
        case set_bg:
            if(val == 0)
                changes.set_bg0 = 1;
            else
                changes.set_bg1 = 1;
            break;
        case set_spr:
            if(val == 0)
                changes.set_spr0 = 1;
            else
                changes.set_spr1 = 1;
            break;
        default:
            std::cout<<"Unknown command!"<<std::endl;
            break;
        }
        ppu_queue.pop_front();
        if(ppu_queue.size() > 0)
            next_c = ppu_queue.front().first;
    }
    return changes;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0x20(%rdi)
je 0x132fc
movq 0x10(%r14), %rax
movl 0x10(%rax), %ebp
jmp 0x132ff
leal 0x1(%rbx), %ebp
xorl %eax, %eax
cmpq $0x0, 0x20(%r14)
je 0x13432
cmpl %ebx, %ebp
jae 0x13432
xorl %r12d, %r12d
leaq 0x32ea(%rip), %r15      # 0x16608
movq 0x10(%r14), %rax
movl 0x14(%rax), %ecx
cmpq $0x6, %rcx
ja 0x13386
movl 0x18(%rax), %eax
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
orl $0x1, %r12d
movl %eax, 0x28(%r14)
jmp 0x133f9
orl $0x10, %r12d
movq 0x8(%r14), %rax
movl $0x2, 0x88(%rax)
jmp 0x133f9
orl $0x4, %r12d
movq 0x8(%r14), %rax
movl $0x1, 0x88(%rax)
jmp 0x133f9
orl $0x8, %r12d
movq 0x8(%r14), %rax
movl $0x0, 0x88(%rax)
jmp 0x133f9
movl $0x10, %edx
movq 0x8c1e(%rip), %r13      # 0x1bfb0
movq %r13, %rdi
leaq 0x3295(%rip), %rsi      # 0x16631
callq 0x4410
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4390
movsbl %al, %esi
movq %r13, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4290
jmp 0x133f9
orl $0x2, %r12d
movl %eax, 0x2c(%r14)
jmp 0x133f9
testl %eax, %eax
je 0x133ec
orl $0x40, %r12d
jmp 0x133f9
testl %eax, %eax
je 0x133f2
orl $0x100, %r12d           # imm = 0x100
jmp 0x133f9
orl $0x20, %r12d
jmp 0x133f9
orl $0x80, %r12d
movq 0x10(%r14), %r13
decq 0x20(%r14)
movq %r13, %rdi
callq 0x4590
movq %r13, %rdi
callq 0x4380
cmpq $0x0, 0x20(%r14)
je 0x1341f
movq 0x10(%r14), %rax
movl 0x10(%rax), %ebp
cmpq $0x0, 0x20(%r14)
je 0x1342e
cmpl %ebx, %ebp
jb 0x1331e
movzwl %r12w, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)