// File: /workspace/github_c_makefile_star2_O0/armlabs[P]ssd1306_linux/ssd1306.c
// Function: ssd1306_oled_write_line
uint8_t ssd1306_oled_write_line(uint8_t size, char* ptr)
{
    uint16_t i = 0;
    uint16_t index = 0;
    uint8_t* font_table = 0;
    uint8_t font_table_width = 0;
    
    if (ptr == 0)
        return 1;
    
    if (size == SSD1306_FONT_SMALL) // 5x7
    {
        font_table = (uint8_t*)font5x7;
        font_table_width = 5;
    }
    else if (size == SSD1306_FONT_NORMAL) // 8x8
    {
        font_table = (uint8_t*)font8x8;
        font_table_width = 8;
    }
    else
        return 1;
    
    data_buf[i++] = SSD1306_DATA_CONTROL_BYTE;
    
    // font table range in ascii table is from 0x20(space) to 0x7e(~)
    while (ptr[index] != 0 && i <= 1024)
    {
        if ((ptr[index] < ' ') || (ptr[index] > '~'))
            return 1;

        uint8_t* font_ptr = &font_table[(ptr[index] - 0x20) * font_table_width];
        uint8_t j = 0;
        for (j = 0; j < font_table_width; j++)
        {
            data_buf[i++] = font_ptr[j];
            if (i > 1024)
                return 1;
        }
        // insert 1 col space for small font size)
        if (size == SSD1306_FONT_SMALL)
            data_buf[i++] = 0x00;
        index++;
    }
    
    return _i2c_write(data_buf, i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %dil, %al
movb %al, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
movw $0x0, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x402d4a
movb $0x1, -0x1(%rbp)
jmp 0x402ece
movzbl -0x2(%rbp), %eax
cmpl $0x0, %eax
jne 0x402d64
leaq 0xbb7c6(%rip), %rax     # 0x4be520
movq %rax, -0x20(%rbp)
movb $0x5, -0x21(%rbp)
jmp 0x402d89
movzbl -0x2(%rbp), %eax
cmpl $0x1, %eax
jne 0x402d7e
leaq 0xbb98c(%rip), %rax     # 0x4be700
movq %rax, -0x20(%rbp)
movb $0x8, -0x21(%rbp)
jmp 0x402d87
movb $0x1, -0x1(%rbp)
jmp 0x402ece
jmp 0x402d89
movw -0x12(%rbp), %ax
movw %ax, %cx
addw $0x1, %cx
movw %cx, -0x12(%rbp)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xef62c(%rip), %rax     # 0x4f23d0
movb $0x40, (%rax,%rcx)
movq -0x10(%rbp), %rax
movzwl -0x14(%rbp), %ecx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x32(%rbp)
je 0x402dcd
movzwl -0x12(%rbp), %eax
cmpl $0x400, %eax            # imm = 0x400
setle %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0x402dd9
jmp 0x402ebb
movq -0x10(%rbp), %rax
movzwl -0x14(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jl 0x402dfb
movq -0x10(%rbp), %rax
movzwl -0x14(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
jle 0x402e04
movb $0x1, -0x1(%rbp)
jmp 0x402ece
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl -0x14(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
subl $0x20, %ecx
movzbl -0x21(%rbp), %edx
imull %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
movb $0x0, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
movzbl -0x21(%rbp), %ecx
cmpl %ecx, %eax
jge 0x402e82
movq -0x30(%rbp), %rax
movzbl -0x31(%rbp), %ecx
movb (%rax,%rcx), %dl
movw -0x12(%rbp), %ax
movw %ax, %cx
addw $0x1, %cx
movw %cx, -0x12(%rbp)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xef56e(%rip), %rax     # 0x4f23d0
movb %dl, (%rax,%rcx)
movzwl -0x12(%rbp), %eax
cmpl $0x400, %eax            # imm = 0x400
jle 0x402e76
movb $0x1, -0x1(%rbp)
jmp 0x402ece
jmp 0x402e78
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x402e30
movzbl -0x2(%rbp), %eax
cmpl $0x0, %eax
jne 0x402eaa
movw -0x12(%rbp), %ax
movw %ax, %cx
addw $0x1, %cx
movw %cx, -0x12(%rbp)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xef52a(%rip), %rax     # 0x4f23d0
movb $0x0, (%rax,%rcx)
movw -0x14(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x14(%rbp)
jmp 0x402da8
leaq 0xef50e(%rip), %rdi     # 0x4f23d0
movswl -0x12(%rbp), %esi
callq 0x403280
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)