// File: /workspace/github_cpp_makefile_star2_O3/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::save(Rnes::PpuState&)
void Ppu::save(PpuState &pb) {
  pb.set_cycle(cycle);
  pb.set_frame(frame);

  for (int i = 0; i < REG_COUNT; i++) {
    pb.add_regs(regs[i]);
  }

  for (int i = 0; i < spriteRamSize; i++) {
    PpuState_SpriteState *sprite = pb.add_spriteram();
    sprite->set_ycoordminus1(spriteRam[i].yCoordMinus1);
    sprite->set_tileindex(spriteRam[i].tileIndex);
    sprite->set_attr(spriteRam[i].attr);
    sprite->set_xcoord(spriteRam[i].xCoord);
  }

  pb.set_vramtoggle(vramToggle);
  pb.set_vramfinexscroll(vramFineXScroll);
  pb.set_vramcurrentaddr(vramCurrentAddr);
  pb.set_vramtempaddr(vramTempAddr);
  pb.set_vrammachineaddr(vramMachineAddr);
  pb.set_vramreadlatch(vramReadLatch);
  pb.set_scrollingmachinestate(scrollingMachineState);
  pb.set_xscrollorigin(xScrollOrigin);
  pb.set_yscrollorigin(yScrollOrigin);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq 0x18(%rdi), %rax
movq %rax, 0x40(%rsi)
movq %rdi, -0x30(%rbp)
movq 0x20(%rdi), %rax
orl $0x3, 0x10(%rsi)
movq %rax, 0x48(%rsi)
leaq 0x18(%rsi), %rax
movq %rax, -0x38(%rbp)
movl 0x18(%rsi), %r14d
xorl %r13d, %r13d
movq %rsi, -0x40(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x28(%rax,%r13), %r15d
leal 0x1(%r14), %r12d
cmpl 0x1c(%rbx), %r14d
jne 0x18071
movq -0x38(%rbp), %rdi
movl %r12d, %esi
callq 0xa670
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0xa530
movl %r14d, %ecx
movl %r15d, (%rax,%rcx,4)
movl %r12d, (%rbx)
incq %r13
movl %r12d, %r14d
cmpq $0x8, %r13
movq -0x40(%rbp), %rbx
jne 0x18051
leaq 0x28(%rbx), %r15
xorl %r12d, %r12d
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0x180be
movslq 0x30(%rbx), %rcx
movl (%rax), %esi
cmpl %esi, %ecx
jge 0x180c3
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x8(%rax,%rcx,8), %rax
jmp 0x180f8
movl 0x34(%rbx), %esi
jmp 0x180c8
cmpl 0x34(%rbx), %esi
jne 0x180d8
incl %esi
movq %r15, %rdi
callq 0xa960
movq 0x38(%rbx), %rax
movl (%rax), %esi
incl %esi
movl %esi, (%rax)
movq 0x28(%rbx), %rdi
callq 0x30a88
movq 0x38(%rbx), %rcx
movslq 0x30(%rbx), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x30(%rbx)
movq %rax, 0x8(%rcx,%rdx,8)
movq -0x30(%rbp), %rdx
movzbl 0x30(%rdx,%r12,4), %ecx
movl %ecx, 0x18(%rax)
movzbl 0x31(%rdx,%r12,4), %ecx
movl %ecx, 0x1c(%rax)
movzbl 0x32(%rdx,%r12,4), %ecx
movl %ecx, 0x20(%rax)
movzbl 0x33(%rdx,%r12,4), %ecx
orl $0xf, 0x10(%rax)
movl %ecx, 0x24(%rax)
incq %r12
cmpq $0x40, %r12
jne 0x1809e
movq -0x30(%rbp), %rsi
movl 0x130(%rsi), %eax
movl 0x10(%rbx), %ecx
movl %ecx, %edx
orl $0x4, %edx
movl %edx, 0x10(%rbx)
movl %eax, 0x50(%rbx)
movl 0x134(%rsi), %eax
movl %eax, 0x54(%rbx)
movzwl 0x138(%rsi), %eax
movl %eax, 0x58(%rbx)
movzwl 0x13a(%rsi), %eax
movl %eax, 0x5c(%rbx)
movzwl 0x13c(%rsi), %eax
movl %eax, 0x60(%rbx)
movzbl 0x13e(%rsi), %eax
movl %ecx, %edx
orl $0xfc, %edx
movl %edx, 0x10(%rbx)
movl %eax, 0x64(%rbx)
movl 0x140(%rsi), %eax
movl %eax, 0x68(%rbx)
movzbl 0x144(%rsi), %eax
movl %eax, 0x6c(%rbx)
movzbl 0x145(%rsi), %eax
orl $0x7fc, %ecx            # imm = 0x7FC
movl %ecx, 0x10(%rbx)
movl %eax, 0x70(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq