// File: /workspace/github_c_makefile_star2_O1/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, 0x59dcb1(%rip)    # 0x5f9a44
je 0x5bda4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x59d995(%rip), %rbx    # 0x5f9740
leaq 0x59dc92(%rip), %rsi    # 0x5f9a44
movl $0x1, %edi
callq *0xb8(%rbx)
cmpl $0x0, 0x59dc80(%rip)    # 0x5f9a44
je 0x5bd95
movl $0x10000, %edi          # imm = 0x10000
movl $0x4, %esi
callq 0x6930
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5bf5e
xorl %eax, %eax
leaq 0x479b4(%rip), %rsi     # 0xa37a0
movq %rax, %rdx
shlq $0x5, %rdx
leaq 0x35bf6(%rip), %rbx     # 0x919f0
leaq (%rbx,%rdx), %rdi
movq %rax, %r8
shlq $0x10, %r8
addq 0x8(%rsp), %r8
xorl %ecx, %ecx
movq %rax, 0x10(%rsp)
cmpq $0x2, %rax
sete %cl
movslq 0x10(%rbx,%rdx), %r9
movslq 0x18(%rbx,%rdx), %r10
addl $0x3, %ecx
movl 0xc(%rbx,%rdx), %r11d
addq (%rbx,%rdx), %r10
xorl %r15d, %r15d
testl %r11d, %r11d
jle 0x5bea4
movq %r15, %r12
imulq %r9, %r12
leal (,%r15,8), %edx
andl $0x700, %edx            # imm = 0x700
shll %cl, %edx
addq %r10, %r12
leaq (%r8,%rdx,4), %rdx
movl %r15d, %r13d
andl $0x1f, %r13d
shll $0x5, %r13d
addq %rdx, %r13
movl 0x8(%rdi), %ebp
xorl %r14d, %r14d
testl %ebp, %ebp
jle 0x5be95
movl $0x7, %ebx
subl 0x14(%rdi), %ebx
xorl %edx, %edx
movslq %ebx, %rax
movb (%rsi,%rax), %al
testb %al, (%r12,%r14)
je 0x5be8b
movl $0xffffffff, (%r13,%rdx,4) # imm = 0xFFFFFFFF
incq %rdx
decl %ebx
cmpq %rdx, %rbp
jne 0x5be76
addq $0x400, %r13            # imm = 0x400
incq %r14
cmpq %r11, %r14
jne 0x5be68
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0x5be31
movq 0x10(%rsp), %rax
incq %rax
cmpq $0x3, %rax
jne 0x5bdec
movl $0x84c0, %edi           # imm = 0x84C0
leaq 0x59d872(%rip), %rbx    # 0x5f9740
callq *0x140(%rbx)
movl 0x59db6a(%rip), %esi    # 0x5f9a44
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 $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c0
leaq 0x59dadf(%rip), %rsi    # 0x5f9a44
movl $0x1, %edi
callq *0xc0(%rbx)
movl $0x0, 0x59daca(%rip)    # 0x5f9a44
jmp 0x5bd95