// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movl %esi, 0x14(%rsp)
movl %edi, 0x4(%rsp)
leaq 0x3ee841(%rip), %rax    # 0x406fec
movl (%rax), %r15d
sarl $0x6, %r15d
leaq 0x3ee837(%rip), %rax    # 0x406ff0
movl (%rax), %r12d
sarl $0x6, %r12d
imull %r15d, %r12d
callq 0x3c626
leaq 0x3fd4d0(%rip), %rax    # 0x415ca0
movslq 0x4(%rax), %rbp
movl 0x114572(%rip), %edi    # 0x12cd4c
callq 0x3b239
movl 0x8a823(%rip), %esi     # 0xa3008
leal (%rsi,%rsi), %ecx
movl %r12d, %eax
shll %cl, %eax
testl %eax, %eax
jle 0x18abf
movslq 0x4(%rsp), %r13
leaq 0x3f681f(%rip), %rbx    # 0x40f020
leaq 0x37fad8(%rip), %r8     # 0x3982e0
xorl %edx, %edx
movl %r15d, 0x1c(%rsp)
movl %r12d, 0x18(%rsp)
movq %r13, 0x28(%rsp)
leaq (%rdx,%r13), %rcx
movswq 0x12858b(%rip), %rax    # 0x140db0
cmpq %rax, %rcx
jge 0x18aa3
leaq 0x123d7b(%rip), %rax    # 0x13c5b0
movswq (%rax,%rcx,2), %r9
cmpw $0x0, (%rbx,%r9,2)
je 0x18aa3
leaq 0x3e7f93(%rip), %rax    # 0x4007e0
cmpw $0x0, (%rax,%r9,2)
je 0x18aa3
movq %rcx, 0x30(%rsp)
cmpq $0x0, (%r8,%r9,8)
movq %r9, 0x8(%rsp)
jne 0x18884
movl %r9d, %edi
movq %rdx, %r14
callq 0x2f106
movq 0x8(%rsp), %r9
movq %r14, %rdx
leaq 0x37fa5c(%rip), %r8     # 0x3982e0
movq (%r8,%r9,8), %r14
movb 0x8a779(%rip), %sil     # 0xa3008
movl %r15d, %edi
movl %esi, %ecx
shll %cl, %edi
movswl (%rbx,%r9,2), %r12d
leaq 0x3e7f3e(%rip), %rax    # 0x4007e0
movswl (%rax,%r9,2), %r15d
movq %rdx, 0x20(%rsp)
movl %edx, %eax
cltd
idivl %edi
movl %eax, %ebx
movl %edx, %r13d
movb $0x6, %cl
subb %sil, %cl
shll %cl, %r13d
shll %cl, %ebx
movl $0x40, %eax
movl %esi, %ecx
shrl %cl, %eax
movl %r13d, %edi
movl %ebx, %esi
movl %r9d, %edx
movl %eax, %ecx
callq 0x5b4d9
movq 0x8(%rsp), %rdi
leaq 0x37f9fc(%rip), %r8     # 0x3982e0
testl %eax, %eax
je 0x18a00
movslq %r12d, %r10
movslq %ebx, %rax
leaq 0x3fd3a7(%rip), %rcx    # 0x415ca0
movslq (%rcx,%rax,4), %rax
movslq %r13d, %rbx
addq %rax, %rbx
movl 0x8a6ff(%rip), %ecx     # 0xa3008
movl $0x40, %eax
shrl %cl, %eax
movslq %r15d, %r9
leaq 0x164796(%rip), %rdx    # 0x17d0b0
addq (%rdx), %rbx
cmpl %r10d, %eax
setl %dl
cmpl %r15d, %eax
setl %al
orb %dl, %al
je 0x189d0
movl $0x3f, %eax
shrl %cl, %eax
cmpw %r15w, %r12w
cmovlel %r15d, %r12d
addl %eax, %r12d
movb $0x6, %al
subb %cl, %al
movl %eax, %ecx
sarl %cl, %r12d
testw %r10w, %r10w
jle 0x18a00
movl %r12d, %r14d
movq %r9, %r11
imulq %r14, %r11
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r9, 0x48(%rsp)
movq %r10, 0x40(%rsp)
movq %r11, 0x38(%rsp)
cmpq $0x0, (%r8,%rdi,8)
jne 0x1899c
callq 0x2f106
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
movq 0x48(%rsp), %r9
movq 0x8(%rsp), %rdi
leaq 0x37f944(%rip), %r8     # 0x3982e0
testw %r9w, %r9w
jle 0x189c0
movq (%r8,%rdi,8), %rax
addq %r13, %rax
xorl %ecx, %ecx
movq %rbx, %rdx
movb (%rax,%rcx), %sil
movb %sil, (%rdx)
addq %rbp, %rdx
addq %r14, %rcx
cmpl %r15d, %ecx
jl 0x189ae
incq %rbx
addq %r14, %r12
addq %r11, %r13
cmpq %r10, %r12
jb 0x18975
jmp 0x18a00
testw %r10w, %r10w
jle 0x18a00
movl %r12d, %eax
xorl %ecx, %ecx
testw %r9w, %r9w
jle 0x189f8
leaq (%rbx,%rcx), %rdx
movl %r15d, %esi
movb (%r14), %dil
incq %r14
movb %dil, (%rdx)
addq %rbp, %rdx
decl %esi
jne 0x189e8
incq %rcx
cmpq %rax, %rcx
jne 0x189db
cmpw $0x23ff, 0x1283a7(%rip) # imm = 0x23FF
movl 0x1c(%rsp), %r15d
movl 0x18(%rsp), %r12d
movq 0x28(%rsp), %r13
leaq 0x3f6601(%rip), %rbx    # 0x40f020
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rax
jg 0x18aa3
movq %rax, %r8
movb 0x8a5d4(%rip), %cl      # 0xa3008
movl %r15d, %edi
shll %cl, %edi
movb $0x6, %sil
subb %cl, %sil
movl %edx, %eax
cltd
idivl %edi
movl %eax, %ebx
movl %edx, %r14d
movl %esi, %ecx
shll %cl, %r14d
shll %cl, %ebx
leaq 0x11f349(%rip), %rax    # 0x137da0
movswl (%rax,%r8,2), %edx
leaq 0x50(%rsp), %rdi
leaq 0x5b293(%rip), %rsi     # 0x73cfb
xorl %eax, %eax
callq 0x6b00
movswl 0x1142d2(%rip), %edx    # 0x12cd48
movl %r14d, %edi
movl %ebx, %esi
leaq 0x3f659e(%rip), %rbx    # 0x40f020
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %r8
movl $0x1, %r9d
callq 0x3c433
movq 0x20(%rsp), %rdx
leaq 0x37f83d(%rip), %r8     # 0x3982e0
movl 0x8a55f(%rip), %esi     # 0xa3008
leal (%rsi,%rsi), %ecx
movl %r12d, %eax
shll %cl, %eax
incq %rdx
cltq
cmpq %rax, %rdx
jl 0x18819
movl %esi, %ecx
shll %cl, %r15d
movl 0x14(%rsp), %r13d
movl %r13d, %eax
subl 0x4(%rsp), %eax
cltd
idivl %r15d
movl %eax, %r15d
movb $0x6, %cl
subb %sil, %cl
shll %cl, %edx
shll %cl, %r15d
movl $0x3f, %r14d
movl %esi, %ecx
shrl %cl, %r14d
leal (%rdx,%r14), %ebx
movl %edx, %ebp
shll $0xc, %ebp
movl %r15d, %r12d
shll $0xc, %r12d
shll $0xc, %ebx
movzbl 0x114241(%rip), %r8d    # 0x12cd48
movl %ebp, %edi
movl %r12d, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x3c09a
addl %r15d, %r14d
shll $0xc, %r14d
movzbl 0x114223(%rip), %r8d    # 0x12cd48
movl %ebx, %edi
movl %r12d, %esi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x3c09a
movzbl 0x11420c(%rip), %r8d    # 0x12cd48
movl %ebx, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x3c09a
movzbl 0x1141f5(%rip), %r8d    # 0x12cd48
movl %ebp, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x3c09a
movslq %r13d, %rax
leaq 0x123a44(%rip), %rcx    # 0x13c5b0
movswq (%rcx,%rax,2), %r14
leaq 0x5b183(%rip), %rsi     # 0x73cfb
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x6b00
leaq 0x3ee45f(%rip), %r13    # 0x406ff0
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x1141a9(%rip), %edx    # 0x12cd48
xorl %edi, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x3c433
leaq 0x3ee434(%rip), %r12    # 0x406fec
movl (%r12), %ebp
leaq (%r14,%r14,4), %rax
leaq (%rax,%rax,4), %rax
leaq 0x1281f5(%rip), %r15    # 0x140dc0
addq %rax, %r15
movq %r15, %rdi
callq 0x6420
shll $0x3, %eax
subl %eax, %ebp
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x11415f(%rip), %edx    # 0x12cd48
movl %ebp, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r15, %r8
xorl %r9d, %r9d
callq 0x3c433
leaq 0x3f641e(%rip), %rax    # 0x40f020
movswl (%rax,%r14,2), %edx
leaq 0x3e7bd2(%rip), %rax    # 0x4007e0
movswl (%rax,%r14,2), %ecx
leaq 0x5a8ab(%rip), %rsi     # 0x734c5
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6b00
movl (%r12), %edi
sarl $0x2, %edi
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x11410f(%rip), %edx    # 0x12cd48
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x3c433
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq