// File: Jumperr-labs[P]at25sf081/AT25SF081.cpp
// Function: AT25SF081::AT25SF081()
AT25SF081::AT25SF081() :
        should_stop_(false),
        status_register1_(0),
        status_register2_(0) {
    int cs_pin_number = GetPinNumber("cs");
    int sck_pin_number = GetPinNumber("sck");
    int si_pin_number = GetPinNumber("si");
    int so_pin_number = GetPinNumber("so");
    wp_pin_number_ = GetPinNumber("wp");
    hold_pin_number_ = GetPinNumber("hold");

    SpiSlaveConfig spi_config = {
            .mosi_pin_number = si_pin_number,
            .miso_pin_number = so_pin_number,
            .ss_pin_number = cs_pin_number,
            .sclk_pin_number = sck_pin_number,
            .supported_spi_modes = SPI_MODE_0 | SPI_MODE_3,
            .max_frequency = MAX_FREQUENCY,
            .bit_order = MSB_FIRST
    };

    spi_slave_ = CreateSpiSlave(spi_config);
    MemReset();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0xd150
movq -0x140(%rbp), %rax
movq 0xa933(%rip), %rcx      # 0x18f80
addq $0x10, %rcx
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
addq $0x10, %rax
movq %rax, %rcx
addq $0x100000, %rcx         # imm = 0x100000
movq %rcx, -0x138(%rbp)
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq -0x138(%rbp), %rcx
movb $0x0, (%rax)
addq $0x1, %rax
cmpq %rcx, %rax
movq %rax, -0x130(%rbp)
jne 0xe678
movq -0x140(%rbp), %rax
movl $0x0, 0x100010(%rax)
movl $0x0, 0x100014(%rax)
movb $0x0, 0x100018(%rax)
movb $0x0, 0x100019(%rax)
movb $0x0, 0x10001a(%rax)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xe200
movq -0x148(%rbp), %rdx
leaq 0x5919(%rip), %rsi      # 0x14000
leaq -0x30(%rbp), %rdi
callq 0xe130
jmp 0xe6f2
leaq -0x30(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x14c(%rbp)
jmp 0xe703
leaq -0x30(%rbp), %rdi
callq 0xd520
leaq -0x31(%rbp), %rdi
callq 0xda90
movl -0x14c(%rbp), %eax
movl %eax, -0xc(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0xe200
movq -0x158(%rbp), %rdx
leaq 0x58c7(%rip), %rsi      # 0x14003
leaq -0x68(%rbp), %rdi
callq 0xe130
jmp 0xe747
leaq -0x68(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x15c(%rbp)
jmp 0xe758
leaq -0x68(%rbp), %rdi
callq 0xd520
leaq -0x69(%rbp), %rdi
callq 0xda90
movl -0x15c(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0xe200
movq -0x168(%rbp), %rdx
leaq 0x5873(%rip), %rsi      # 0x14007
leaq -0x90(%rbp), %rdi
callq 0xe130
jmp 0xe7a2
leaq -0x90(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x16c(%rbp)
jmp 0xe7b6
leaq -0x90(%rbp), %rdi
callq 0xd520
leaq -0x91(%rbp), %rdi
callq 0xda90
movl -0x16c(%rbp), %eax
movl %eax, -0x70(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0xe200
movq -0x178(%rbp), %rdx
leaq 0x5812(%rip), %rsi      # 0x1400a
leaq -0xb8(%rbp), %rdi
callq 0xe130
jmp 0xe806
leaq -0xb8(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x17c(%rbp)
jmp 0xe81a
leaq -0xb8(%rbp), %rdi
callq 0xd520
leaq -0xb9(%rbp), %rdi
callq 0xda90
movl -0x17c(%rbp), %eax
movl %eax, -0x98(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0xe200
movq -0x188(%rbp), %rdx
leaq 0x57ae(%rip), %rsi      # 0x1400d
leaq -0xe0(%rbp), %rdi
callq 0xe130
jmp 0xe86d
leaq -0xe0(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x18c(%rbp)
jmp 0xe881
movq -0x140(%rbp), %rax
movl -0x18c(%rbp), %ecx
movl %ecx, 0x100010(%rax)
leaq -0xe0(%rbp), %rdi
callq 0xd520
leaq -0xe1(%rbp), %rdi
callq 0xda90
leaq -0x109(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0xe200
movq -0x198(%rbp), %rdx
leaq 0x5743(%rip), %rsi      # 0x14010
leaq -0x108(%rbp), %rdi
callq 0xe130
jmp 0xe8db
leaq -0x108(%rbp), %rdi
callq 0xd3f0
movl %eax, -0x19c(%rbp)
jmp 0xe8ef
movq -0x140(%rbp), %rax
movl -0x19c(%rbp), %ecx
movl %ecx, 0x100014(%rax)
leaq -0x108(%rbp), %rdi
callq 0xd520
leaq -0x109(%rbp), %rdi
callq 0xda90
movl -0x70(%rbp), %eax
movl %eax, -0x128(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x124(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x120(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x11c(%rbp)
movl $0x9, -0x118(%rbp)
movl $0x632ea00, -0x114(%rbp) # imm = 0x632EA00
movl $0x0, -0x110(%rbp)
leaq -0x128(%rbp), %rdi
callq 0xe040
movq -0x140(%rbp), %rdi
movq %rax, 0x8(%rdi)
callq 0xdc10
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe9a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xd520
leaq -0x31(%rbp), %rdi
callq 0xda90
jmp 0xeab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe9d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xd520
leaq -0x69(%rbp), %rdi
callq 0xda90
jmp 0xeab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xea0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xd520
leaq -0x91(%rbp), %rdi
callq 0xda90
jmp 0xeab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xea43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xd520
leaq -0xb9(%rbp), %rdi
callq 0xda90
jmp 0xeab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xea77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0xd520
leaq -0xe1(%rbp), %rdi
callq 0xda90
jmp 0xeab7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xeaab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x108(%rbp), %rdi
callq 0xd520
leaq -0x109(%rbp), %rdi
callq 0xda90
movq -0x40(%rbp), %rdi
callq 0xe1f0