// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movl %ecx, %ebp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r14
leaq 0x5(%rsp), %r13
movb $0x22, (%r13)
movb %r15b, 0x1(%r13)
movb $0x7, 0x2(%r13)
movzbl (%rdi), %edi
movl $0x80, %esi
movl $0x3, %edx
movq %r13, %rcx
callq 0x1f150
leal (,%rbx,8), %eax
movb $0x21, (%r13)
movb %al, 0x1(%r13)
movb $0x7f, 0x2(%r13)
movzbl (%r14), %edi
leaq 0x5(%rsp), %rcx
movl $0x80, %esi
movl $0x3, %edx
callq 0x1f150
movq %rbx, 0x8(%rsp)
cmpb $0x10, %bl
setae %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
movzwl %bp, %eax
movq %rax, 0x18(%rsp)
jne 0x342ba
movq %r15, 0x20(%rsp)
xorl %r12d, %r12d
leaq 0x218f(%rip), %rbx      # 0x363f0
movq 0x10(%rsp), %rbp
movb (%rbp,%r12), %al
addb $-0x20, %al
movzbl %al, %r13d
shll $0x3, %r13d
xorl %r15d, %r15d
leaq (%r15,%r13), %rax
movzbl (%rbx,%rax), %edx
movzbl (%r14), %edi
movl $0x40, %esi
callq 0x1f5d0
incq %r15
cmpq $0x8, %r15
jne 0x34278
incq %r12
cmpq 0x18(%rsp), %r12
jae 0x342ae
movq 0x8(%rsp), %rax
addl %r12d, %eax
cmpl $0x10, %eax
jb 0x34266
leal 0x1(%r12), %eax
movq 0x20(%rsp), %r15
jmp 0x342c7
movl $0x1, %eax
xorl %r12d, %r12d
movq 0x10(%rsp), %rbp
cmpl 0x18(%rsp), %eax
jae 0x34408
leal 0x1(%r15), %eax
leaq 0x5(%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 0x5(%rsp), %rcx
movl $0x80, %esi
movl $0x3, %edx
callq 0x1f150
movzwl %r12w, %eax
incl %eax
cmpl 0x18(%rsp), %eax
jae 0x34408
movzbl %r15b, %eax
shll $0x4, %eax
addl 0x8(%rsp), %eax
movl %eax, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x209f(%rip), %r15      # 0x363f0
movzwl %r12w, %r13d
movb (%rbp,%r13), %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 0x34364
incl %r12d
testb $0x1, 0x8(%rsp)
je 0x34395
movq 0x10(%rsp), %rbp
jmp 0x343f9
movzwl %r12w, %eax
addl 0x20(%rsp), %eax
cmpl $0x80, %eax
movq 0x10(%rsp), %rbp
jb 0x343f9
movw $0x22, 0x5(%rsp)
movb $0x7, 0x7(%rsp)
movzbl (%r14), %edi
movl $0x80, %esi
movl $0x3, %edx
leaq 0x5(%rsp), %rbx
movq %rbx, %rcx
callq 0x1f150
movw $0x21, 0x5(%rsp)
movb $0x7f, 0x7(%rsp)
movzbl (%r14), %edi
movl $0x80, %esi
movl $0x3, %edx
movq %rbx, %rcx
callq 0x1f150
movb $0x1, %al
movq %rax, 0x8(%rsp)
addl $0x2, %r13d
cmpl 0x18(%rsp), %r13d
jb 0x34351
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop