// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/polymost.c
// Function: polymost_preparetext
static int polymost_preparetext(void)
{
	unsigned int *tbuf;

	if (texttexture) {
		return 0;
	}

	// construct a 256x256 rgba texture for the font glyph matrix.
	glfunc.glGenTextures(1,&texttexture);
	if (!texttexture) return -1;

	tbuf = (unsigned int *)Bcalloc(256*256, sizeof(unsigned int));
	if (!tbuf) {
		glfunc.glDeleteTextures(1,&texttexture);
		texttexture = 0;
		return -1;
	}

	// 8x8 - lines 0 to 63, 8 lines per row
	// 4x6 - lines 64 to 127, 8 lines per row
	// 8x14 - lines 128-255, 16 lines per row

	for (int fn = 0; fn < 3; fn++) {
		const struct textfontspec *f = &textfonts[fn];
		unsigned int *tptr = tbuf + 256*64*fn;
		int cellh = fn < 2 ? 8 : 16;

		for (int c = 0; c < 256; c++) {
			const unsigned char *letptr = &f->font[c * f->cellh + f->cellyoff];
			unsigned int *cptr = tptr + ((c/32) * 256 * cellh) + ((c%32)*8);

			for(int y = 0; y < f->charysiz; y++)
			{
				for(int x = 0; x < f->charxsiz; x++)
				{
					if (letptr[y] & pow2char[7 - x - f->cellxoff])
						cptr[x] = 0xffffffff;
				}
				cptr += 256;
			}
		}
	}

	glfunc.glActiveTexture(GL_TEXTURE0);
	glfunc.glBindTexture(GL_TEXTURE_2D, texttexture);
	glfunc.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)tbuf);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	free(tbuf);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x0, 0x59cb58(%rip)    # 0x5faa44
je 0x5defd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x59c83c(%rip), %rbx    # 0x5fa740
leaq 0x59cb39(%rip), %rsi    # 0x5faa44
movl $0x1, %edi
callq *0xb8(%rbx)
cmpl $0x0, 0x59cb27(%rip)    # 0x5faa44
je 0x5deee
movl $0x10000, %edi          # imm = 0x10000
movl $0x4, %esi
callq 0x6930
movq %rax, (%rsp)
testq %rax, %rax
je 0x5e0c0
xorl %edx, %edx
leaq 0x4685c(%rip), %rsi     # 0xa47a0
movq %rdx, %rax
shlq $0x5, %rax
leaq 0x34aee(%rip), %r9      # 0x92a40
leaq (%r9,%rax), %rdi
movq %rdx, %r8
shlq $0x10, %r8
addq (%rsp), %r8
xorl %ecx, %ecx
movq %rdx, 0x8(%rsp)
cmpq $0x2, %rdx
sete %cl
movslq 0x10(%r9,%rax), %rdx
movq %rdx, 0x10(%rsp)
movslq 0x18(%r9,%rax), %r10
addl $0x3, %ecx
movl 0xc(%r9,%rax), %r11d
addq (%r9,%rax), %r10
xorl %r15d, %r15d
testl %r11d, %r11d
jle 0x5e002
movq %r15, %r12
imulq 0x10(%rsp), %r12
leal (,%r15,8), %eax
andl $0x700, %eax            # imm = 0x700
shll %cl, %eax
addq %r10, %r12
leaq (%r8,%rax,4), %rax
movl %r15d, %r13d
andl $0x1f, %r13d
shll $0x5, %r13d
addq %rax, %r13
movl 0x8(%rdi), %ebp
xorl %r14d, %r14d
testl %ebp, %ebp
jle 0x5dff3
movb (%r12,%r14), %bl
movl $0x7, %edx
subl 0x14(%rdi), %edx
xorl %eax, %eax
movslq %edx, %r9
testb %bl, (%rsi,%r9)
je 0x5dfe9
movl $0xffffffff, (%r13,%rax,4) # imm = 0xFFFFFFFF
incq %rax
decl %edx
cmpq %rax, %rbp
jne 0x5dfd7
addq $0x400, %r13            # imm = 0x400
incq %r14
cmpq %r11, %r14
jne 0x5dfc5
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0x5df8d
movq 0x8(%rsp), %rdx
incq %rdx
cmpq $0x3, %rdx
jne 0x5df44
movl $0x84c0, %edi           # imm = 0x84C0
leaq 0x59c710(%rip), %rbx    # 0x5fa740
callq *0x140(%rbx)
movl 0x59ca08(%rip), %esi    # 0x5faa44
movl $0xde1, %edi            # imm = 0xDE1
callq *0xc8(%rbx)
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
movl $0x100, %ecx            # imm = 0x100
movl $0x100, %r8d            # imm = 0x100
xorl %r9d, %r9d
movq 0x8(%rsp), %r14
pushq %r14
pushq $0x1401                 # imm = 0x1401
pushq $0x1908                 # imm = 0x1908
callq *0xd0(%rbx)
addq $0x20, %rsp
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
callq *0xe8(%rbx)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
callq *0xe8(%rbx)
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c0
leaq 0x59c97d(%rip), %rsi    # 0x5faa44
movl $0x1, %edi
callq *0xc0(%rbx)
movl $0x0, 0x59c968(%rip)    # 0x5faa44
jmp 0x5deee