// File: /workspace/github_cpp_makefile_star2_O3/mrlordkaj[P]i2cdevlib-pi/SSD1308/SSD1308.cpp
// Function: SSD1308::writeString(unsigned char, unsigned char, unsigned short, char const*)
void SSD1308::writeString(uint8_t row, uint8_t col, uint16_t len, const char * text)
{
  uint16_t index = 0;
  setPageAddress(row, MAX_PAGE);
  const uint8_t col_addr = FONT_WIDTH*col;
  setColumnAddress(col_addr, MAX_COL);

  while ((col+index) < CHARS && (index < len)) {
     // write first line, starting at given position
     writeChar(text[index++]);
  }

  // write remaining lines
  // write until the end of memory
  // then wrap around again from the top.
  if (index + 1 < len) {
    setPageAddress(row + 1, MAX_PAGE);
    setColumnAddress(0, MAX_COL);
    bool wrapEntireScreen = false;
    while (index + 1 < len) {
       writeChar(text[index++]);
       // if we've written the last character space on the screen, 
       // reset the page and column address so that it wraps around from the top again
       if (!wrapEntireScreen && (row*CHARS + col + index) > 127) {
         setPageAddress(0, MAX_PAGE);
         setColumnAddress(0, MAX_COL);
         wrapEntireScreen = true;
       }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
movl %ecx, %ebp
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, %r14
leaq 0xd(%rsp), %r13
movb $0x22, (%r13)
movb %bl, 0x1(%r13)
movb $0x7, 0x2(%r13)
movzbl (%rdi), %edi
movl $0x80, %esi
movl $0x3, %edx
movq %r13, %rcx
callq 0x1f150
leal (,%r15,8), %eax
movb $0x21, (%r13)
movb %al, 0x1(%r13)
movb $0x7f, 0x2(%r13)
movzbl (%r14), %edi
leaq 0xd(%rsp), %rcx
movl $0x80, %esi
movl $0x3, %edx
callq 0x1f150
cmpb $0x10, %r15b
setae %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
movzwl %bp, %eax
movq %rax, 0x10(%rsp)
jne 0x341ed
movq %rbx, 0x18(%rsp)
xorl %r12d, %r12d
leaq 0x2258(%rip), %rbx      # 0x363f0
movq 0x20(%rsp), %rax
movb (%rax,%r12), %al
addb $-0x20, %al
movzbl %al, %r13d
shll $0x3, %r13d
xorl %ebp, %ebp
movq %r13, %rax
addq %rbp, %rax
movzbl (%rbx,%rax), %edx
movzbl (%r14), %edi
movl $0x40, %esi
callq 0x1f5d0
incq %rbp
cmpq $0x8, %rbp
jne 0x341ad
incq %r12
cmpq 0x10(%rsp), %r12
jae 0x341e1
leal (%r12,%r15), %eax
cmpl $0x10, %eax
jb 0x34198
leal 0x1(%r12), %eax
movq 0x18(%rsp), %rbx
jmp 0x341f5
movl $0x1, %eax
xorl %r12d, %r12d
cmpl 0x10(%rsp), %eax
jae 0x34327
leal 0x1(%rbx), %eax
leaq 0xd(%rsp), %r13
movb $0x22, (%r13)
movb %al, 0x1(%r13)
movb $0x7, 0x2(%r13)
movzbl (%r14), %edi
movl $0x80, %esi
movl $0x3, %edx
movq %r13, %rcx
callq 0x1f150
movw $0x21, (%r13)
movb $0x7f, 0x2(%r13)
movzbl (%r14), %edi
leaq 0xd(%rsp), %rcx
movl $0x80, %esi
movl $0x3, %edx
callq 0x1f150
movzwl %r12w, %eax
incl %eax
cmpl 0x10(%rsp), %eax
jae 0x34327
movzbl %bl, %eax
shll $0x4, %eax
addl %r15d, %eax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0x2179(%rip), %r15      # 0x363f0
movzwl %r12w, %eax
movq 0x20(%rsp), %rcx
movb (%rcx,%rax), %al
addb $-0x20, %al
movzbl %al, %ebx
shll $0x3, %ebx
xorl %ebp, %ebp
leaq (%rbx,%rbp), %rax
movzbl (%r15,%rax), %edx
movzbl (%r14), %edi
movl $0x40, %esi
callq 0x1f5d0
incq %rbp
cmpq $0x8, %rbp
jne 0x3428d
incl %r12d
movzwl %r12w, %ebx
movb $0x1, %bpl
testb $0x1, %r13b
jne 0x34318
movq 0x18(%rsp), %rax
addl %ebx, %eax
cmpl $0x80, %eax
jb 0x34316
movw $0x22, 0xd(%rsp)
movb $0x7, 0xf(%rsp)
movzbl (%r14), %edi
movl $0x80, %esi
movl $0x3, %edx
leaq 0xd(%rsp), %r13
movq %r13, %rcx
callq 0x1f150
movw $0x21, 0xd(%rsp)
movb $0x7f, 0xf(%rsp)
movzbl (%r14), %edi
movl $0x80, %esi
movl $0x3, %edx
movq %r13, %rcx
callq 0x1f150
jmp 0x34318
xorl %ebp, %ebp
incl %ebx
movl %ebp, %r13d
cmpl 0x10(%rsp), %ebx
jb 0x34277
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq