// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/build.c
// Function: drawtilescreen
int drawtilescreen(int pictopleft, int picbox)
{
	intptr_t vidpos, vidpos2;
	int i, j, wallnum, xdime, ydime, cnt, pinc;
	int dax, day, scaledown, xtiles, ytiles, tottiles;
	unsigned char *picptr;
	char snotbuf[80];

	xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles;

#if USE_POLYMOST && USE_OPENGL
	setpolymost2dview();	// JBF 20040205: set to 2d rendering
#endif

	pinc = ylookup[1];
	clearview(blackcol);
	for(cnt=0;cnt<(tottiles<<(gettilezoom<<1));cnt++)         //draw the 5*3 grid of tiles
	{
		wallnum = cnt+pictopleft;
		if (wallnum < localartlookupnum)
		{
			wallnum = localartlookup[wallnum];
			if ((tilesizx[wallnum] != 0) && (tilesizy[wallnum] != 0))
			{
				if (waloff[wallnum] == 0) loadtile(wallnum);
				picptr = (unsigned char *)(waloff[wallnum]);
				xdime = tilesizx[wallnum];
				ydime = tilesizy[wallnum];

				dax = ((cnt%(xtiles<<gettilezoom))<<(6-gettilezoom));
				day = ((cnt/(xtiles<<gettilezoom))<<(6-gettilezoom));
#if USE_POLYMOST && USE_OPENGL
				if (polymost_drawtilescreen(dax, day, wallnum, 64>>gettilezoom))
#endif
				{
					vidpos = ylookup[day]+dax+frameplace;
					if ((xdime <= (64>>gettilezoom)) && (ydime <= (64>>gettilezoom)))
					{
						for(i=0;i<xdime;i++)
						{
							vidpos2 = vidpos+i;
							for(j=0;j<ydime;j++)
							{
								*(unsigned char *)vidpos2 = *picptr++;
								vidpos2 += pinc;
							}
						}
					}
					else                          //if 1 dimension > 64
					{
						if (xdime > ydime)
							scaledown = ((xdime+(63>>gettilezoom))>>(6-gettilezoom));
						else
							scaledown = ((ydime+(63>>gettilezoom))>>(6-gettilezoom));

						for(i=0;i<xdime;i+=scaledown)
						{
							if (waloff[wallnum] == 0) loadtile(wallnum);
							picptr = (unsigned char *)(waloff[wallnum]) + ydime*i;
							vidpos2 = vidpos;
							for(j=0;j<ydime;j+=scaledown)
							{
								*(unsigned char *)vidpos2 = *picptr;
								picptr += scaledown;
								vidpos2 += pinc;
							}
							vidpos++;
						}
					}
				}
				if (localartlookupnum < MAXTILES)
				{
					dax = ((cnt%(xtiles<<gettilezoom))<<(6-gettilezoom));
					day = ((cnt/(xtiles<<gettilezoom))<<(6-gettilezoom));
					Bsprintf(snotbuf,"%d",localartfreq[cnt+pictopleft]);
					printext256(dax,day,whitecol,-1,snotbuf,1);
				}
			}
		}
	}

	cnt = picbox-pictopleft;    //draw open white box
	dax = ((cnt%(xtiles<<gettilezoom))<<(6-gettilezoom));
	day = ((cnt/(xtiles<<gettilezoom))<<(6-gettilezoom));

	i = (63>>gettilezoom);
	drawline256((dax  )<<12, (day  )<<12, (dax+i)<<12, (day  )<<12, whitecol);
	drawline256((dax+i)<<12, (day  )<<12, (dax+i)<<12, (day+i)<<12, whitecol);
	drawline256((dax+i)<<12, (day+i)<<12, (dax  )<<12, (day+i)<<12, whitecol);
	drawline256((dax  )<<12, (day+i)<<12, (dax  )<<12, (day  )<<12, whitecol);

	i = localartlookup[picbox];
	Bsprintf(snotbuf,"%d",i);
	printext256(0L,ydim-8,whitecol,-1,snotbuf,0);
	printext256(xdim-((int)strlen(names[i])<<3),ydim-8,whitecol,-1,names[i],0);

	Bsprintf(snotbuf,"%dx%d",tilesizx[i],tilesizy[i]);
	printext256(xdim>>2,ydim-8,whitecol,-1,snotbuf,0);

	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %esi, 0x4(%rsp)
movl %edi, %ebx
leaq 0x3ea205(%rip), %rax    # 0x400fec
movl (%rax), %ecx
sarl $0x6, %ecx
leaq 0x3ea1fd(%rip), %rax    # 0x400ff0
movl (%rax), %r14d
sarl $0x6, %r14d
movl %ecx, (%rsp)
imull %ecx, %r14d
callq 0x39c49
leaq 0x3f8e93(%rip), %rax    # 0x40fca0
movslq 0x4(%rax), %r12
movl 0x10ff35(%rip), %edi    # 0x126d4c
callq 0x38a4f
movl %ebx, 0x10(%rsp)
movslq %ebx, %rdx
leaq 0x11f786(%rip), %r13    # 0x1365b0
leaq 0x3f21ef(%rip), %r15    # 0x409020
leaq 0x37b4a8(%rip), %r8     # 0x3922e0
xorl %ebx, %ebx
movl %r14d, 0x14(%rsp)
movq %rdx, 0x18(%rsp)
movl 0x861be(%rip), %esi     # 0x9d008
leal (%rsi,%rsi), %ecx
movl %r14d, %eax
shll %cl, %eax
cltq
cmpq %rax, %rbx
jge 0x170c6
leaq (%rbx,%rdx), %rcx
movswq 0x123f47(%rip), %rax    # 0x13adb0
cmpq %rax, %rcx
jge 0x170be
movswq (%r13,%rcx,2), %r9
movzwl (%r15,%r9,2), %edi
testw %di, %di
je 0x170be
leaq 0x3e3953(%rip), %rax    # 0x3fa7e0
movzwl (%rax,%r9,2), %eax
testw %ax, %ax
je 0x170be
movq %rcx, 0x28(%rsp)
movq (%r8,%r9,8), %r14
testq %r14, %r14
movq %r9, 0x8(%rsp)
jne 0x16edd
movl %r9d, %edi
callq 0x2cc4a
movq 0x8(%rsp), %r9
leaq 0x37b41e(%rip), %rax    # 0x3922e0
movq (%rax,%r9,8), %r14
movzwl (%r15,%r9,2), %edi
leaq 0x3e390e(%rip), %rax    # 0x3fa7e0
movzwl (%rax,%r9,2), %eax
movl 0x8612b(%rip), %esi     # 0x9d008
movl %edi, %r13d
movl %eax, %r15d
movl (%rsp), %edi
movl %esi, %ecx
shll %cl, %edi
movq %rbx, 0x20(%rsp)
movl %ebx, %eax
cltd
idivl %edi
movl %eax, %ebp
movl %edx, %ebx
movb $0x6, %cl
subb %sil, %cl
shll %cl, %ebx
shll %cl, %ebp
pushq $0x40
popq %rax
movl %esi, %ecx
shrl %cl, %eax
movl %ebx, %edi
movl %ebp, %esi
movl %r9d, %edx
movl %eax, %ecx
callq 0x5329b
movq 0x8(%rsp), %rdi
testl %eax, %eax
leaq 0x37b3bc(%rip), %r8     # 0x3922e0
je 0x17022
movswl %r13w, %edx
movslq %ebp, %rax
leaq 0x3f8d68(%rip), %rcx    # 0x40fca0
movslq (%rcx,%rax,4), %rax
movslq %ebx, %rbx
addq %rax, %rbx
leaq 0x160167(%rip), %rax    # 0x1770b0
addq (%rax), %rbx
movswl %r15w, %ebp
movl 0x860b2(%rip), %ecx     # 0x9d008
pushq $0x40
popq %rax
shrl %cl, %eax
cmpl %edx, %eax
jl 0x16f9b
cmpl %ebp, %eax
jl 0x16f9b
testl %ebp, %ebp
movl $0x0, %eax
cmovlel %eax, %ebp
testl %edx, %edx
cmovlel %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rax
je 0x17022
leaq (%rbx,%rax), %rcx
movl %ebp, %esi
subl $0x1, %esi
jb 0x16f96
movb (%r14), %dil
incq %r14
movb %dil, (%rcx)
addq %r12, %rcx
jmp 0x16f83
incq %rax
jmp 0x16f74
pushq $0x3f
popq %rax
shrl %cl, %eax
cmpw %bp, %dx
movl %ebp, %esi
cmovgl %edx, %esi
addl %eax, %esi
movb $0x6, %al
subb %cl, %al
movl %eax, %ecx
sarl %cl, %esi
movslq %esi, %r14
movslq %edx, %r9
movslq %ebp, %r11
imulq %r14, %r11
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r9, 0x38(%rsp)
movq %r11, 0x30(%rsp)
cmpq %r9, %r15
jge 0x17022
movq (%r8,%rdi,8), %rax
testq %rax, %rax
jne 0x16ffc
callq 0x2cc4a
movq 0x30(%rsp), %r11
movq 0x38(%rsp), %r9
movq 0x8(%rsp), %rdi
leaq 0x37b2e8(%rip), %r8     # 0x3922e0
movq (%r8,%rdi,8), %rax
addq %r13, %rax
xorl %ecx, %ecx
movq %rbx, %rdx
cmpl %ebp, %ecx
jge 0x17017
movb (%rax,%rcx), %sil
movb %sil, (%rdx)
addq %r12, %rdx
addq %r14, %rcx
jmp 0x17004
incq %rbx
addq %r14, %r15
addq %r11, %r13
jmp 0x16fcf
cmpw $0x23ff, 0x123d85(%rip) # imm = 0x23FF
leaq 0x3f1fee(%rip), %r15    # 0x409020
leaq 0x11f577(%rip), %r13    # 0x1365b0
movl 0x14(%rsp), %r14d
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rax
jg 0x170be
movq %rax, %r8
movb 0x85fb0(%rip), %cl      # 0x9d008
movl (%rsp), %edi
shll %cl, %edi
movb $0x6, %sil
subb %cl, %sil
movl %ebx, %eax
cltd
idivl %edi
movl %eax, %ebx
movl %edx, %ebp
movl %esi, %ecx
shll %cl, %ebp
shll %cl, %ebx
leaq 0x11ad27(%rip), %rax    # 0x131da0
movswl (%rax,%r8,2), %edx
leaq 0x40(%rsp), %rdi
leaq 0x52cf3(%rip), %rsi     # 0x69d7d
xorl %eax, %eax
callq 0x6b00
movswl 0x10fcb0(%rip), %edx    # 0x126d48
movl %ebp, %edi
movl %ebx, %esi
movq 0x20(%rsp), %rbx
pushq $-0x1
popq %rcx
leaq 0x40(%rsp), %r8
pushq $0x1
popq %r9
callq 0x39aab
leaq 0x37b227(%rip), %r8     # 0x3922e0
movq 0x18(%rsp), %rdx
incq %rbx
jmp 0x16e44
movl 0x4(%rsp), %eax
movl %esi, %ecx
movl (%rsp), %edi
shll %cl, %edi
subl 0x10(%rsp), %eax
cltd
idivl %edi
movl %eax, %r12d
movb $0x6, %cl
subb %sil, %cl
shll %cl, %edx
shll %cl, %r12d
movl %esi, %ecx
pushq $0x3f
popq %r14
shrl %cl, %r14d
leal (%rdx,%r14), %ebx
movl %edx, %ebp
shll $0xc, %ebp
movl %r12d, %r15d
shll $0xc, %r15d
shll $0xc, %ebx
movzbl 0x10fc3f(%rip), %r8d    # 0x126d48
movl %ebp, %edi
movl %r15d, %esi
movl %ebx, %edx
movl %r15d, %ecx
callq 0x3973b
addl %r12d, %r14d
shll $0xc, %r14d
movzbl 0x10fc21(%rip), %r8d    # 0x126d48
movl %ebx, %edi
movl %r15d, %esi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x3973b
movzbl 0x10fc0a(%rip), %r8d    # 0x126d48
movl %ebx, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x3973b
movzbl 0x10fbf3(%rip), %r8d    # 0x126d48
movl %ebp, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x3973b
movslq 0x4(%rsp), %rax
movswq (%r13,%rax,2), %r14
leaq 0x52c07(%rip), %rsi     # 0x69d7d
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x6b00
leaq 0x3e9e61(%rip), %rbp    # 0x400ff0
movl (%rbp), %esi
addl $-0x8, %esi
movswl 0x10fbac(%rip), %edx    # 0x126d48
pushq $-0x1
popq %rcx
xorl %edi, %edi
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x39aab
leaq 0x3e9e39(%rip), %r13    # 0x400fec
movl (%r13), %r15d
imulq $0x19, %r14, %rax
leaq 0x123bfe(%rip), %r12    # 0x13adc0
addq %rax, %r12
movq %r12, %rdi
callq 0x6420
shll $0x3, %eax
subl %eax, %r15d
movl (%rbp), %esi
addl $-0x8, %esi
movswl 0x10fb68(%rip), %edx    # 0x126d48
movl %r15d, %edi
pushq $-0x1
popq %r15
movl %r15d, %ecx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x39aab
leaq 0x3f1e24(%rip), %rax    # 0x409020
movswl (%rax,%r14,2), %edx
leaq 0x3e35d8(%rip), %rax    # 0x3fa7e0
movswl (%rax,%r14,2), %ecx
leaq 0x52333(%rip), %rsi     # 0x69547
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6b00
movl (%r13), %edi
sarl $0x2, %edi
movl (%rbp), %esi
addl $-0x8, %esi
movswl 0x10fb16(%rip), %edx    # 0x126d48
movl %r15d, %ecx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x39aab
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq