// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
cmpl $0x0, 0x59ff61(%rip)    # 0x5f3a44
je 0x53af4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x59fc45(%rip), %rax    # 0x5f3740
leaq 0x59ff42(%rip), %rsi    # 0x5f3a44
pushq $0x1
popq %rdi
callq *0xb8(%rax)
cmpl $0x0, 0x59ff32(%rip)    # 0x5f3a44
je 0x53ae5
pushq $0x4
popq %rsi
movl $0x10000, %edi          # imm = 0x10000
callq 0x6930
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x53cda
xorl %eax, %eax
pushq $0x7
popq %r10
leaq 0x49c64(%rip), %rdi     # 0x9d7a0
xorl %r8d, %r8d
cmpq $0x3, %r8
je 0x53c3e
movq %r8, %rdx
shlq $0x5, %rdx
leaq 0x37ec9(%rip), %rsi     # 0x8ba20
leaq (%rsi,%rdx), %r9
movq %r8, %rcx
shlq $0x10, %rcx
addq 0x8(%rsp), %rcx
movq %rcx, 0x20(%rsp)
xorl %ecx, %ecx
movq %r8, 0x10(%rsp)
cmpq $0x2, %r8
sete %cl
movslq 0x10(%rsi,%rdx), %r8
movq %r8, 0x18(%rsp)
addl $0x3, %ecx
movl 0xc(%rsi,%rdx), %r15d
testl %r15d, %r15d
cmovlel %eax, %r15d
movslq 0x18(%rsi,%rdx), %r12
addq (%rsi,%rdx), %r12
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0x53c31
movq %r14, %rbp
leal (,%r14,8), %edx
andl $0x700, %edx            # imm = 0x700
shll %cl, %edx
imulq 0x18(%rsp), %rbp
addq %r12, %rbp
movq 0x20(%rsp), %rsi
leaq (%rsi,%rdx,4), %rdx
movl %r14d, %r13d
andl $0x1f, %r13d
shll $0x5, %r13d
addq %rdx, %r13
xorl %ebx, %ebx
cmpq %r15, %rbx
je 0x53c29
movl 0x8(%r9), %edx
testl %edx, %edx
cmovlel %eax, %edx
movl %r10d, %r8d
xorl %r11d, %r11d
cmpq %r11, %rdx
je 0x53c1d
movl %r8d, %esi
subl 0x14(%r9), %esi
movslq %esi, %rsi
movb (%rdi,%rsi), %sil
testb %sil, (%rbp,%rbx)
je 0x53c15
orl $-0x1, (%r13,%r11,4)
incq %r11
decl %r8d
jmp 0x53bf5
addq $0x400, %r13            # imm = 0x400
incq %rbx
jmp 0x53be1
incq %r14
jmp 0x53b9f
movq 0x10(%rsp), %r8
incq %r8
jmp 0x53b3f
movl $0x84c0, %edi           # imm = 0x84C0
leaq 0x59faf6(%rip), %rbx    # 0x5f3740
callq *0x140(%rbx)
movl 0x59fdee(%rip), %esi    # 0x5f3a44
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 0x10(%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 $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c0
leaq 0x59fd63(%rip), %rsi    # 0x5f3a44
pushq $0x1
popq %rdi
leaq 0x59fa55(%rip), %rax    # 0x5f3740
callq *0xc0(%rax)
andl $0x0, 0x59fd4c(%rip)    # 0x5f3a44
jmp 0x53ae5