// File: /workspace/github_c_makefile_star2_O3/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, 0x2c(%rsp)
movl %edi, %ebx
leaq 0x3ef84c(%rip), %rax    # 0x407fec
movl (%rax), %r12d
sarl $0x6, %r12d
leaq 0x3ef842(%rip), %rax    # 0x407ff0
movl (%rax), %ebp
sarl $0x6, %ebp
imull %r12d, %ebp
callq 0x3da9c
leaq 0x3fe4dd(%rip), %rax    # 0x416ca0
movslq 0x4(%rax), %r15
movl 0x11557f(%rip), %edi    # 0x12dd4c
callq 0x3c4ff
movl 0x8b830(%rip), %esi     # 0xa4008
leal (%rsi,%rsi), %ecx
movl %ebp, %eax
shll %cl, %eax
testl %eax, %eax
movl %ebx, 0x28(%rsp)
jle 0x18af9
movslq %ebx, %rdi
movzwl 0x1295bb(%rip), %eax    # 0x141db0
leaq 0x124db4(%rip), %r8     # 0x13d5b0
leaq 0x3f781d(%rip), %rbx    # 0x410020
leaq 0x3e8fd6(%rip), %r14    # 0x4017e0
leaq 0x380acf(%rip), %r9     # 0x3992e0
xorl %r13d, %r13d
movl %r12d, 0x14(%rsp)
movl %ebp, 0x10(%rsp)
movq %rdi, 0x30(%rsp)
leaq (%rdi,%r13), %rdx
movswq %ax, %rcx
cmpq %rcx, %rdx
jge 0x18ae3
movswq (%r8,%rdx,2), %r10
movzwl (%rbx,%r10,2), %r11d
testw %r11w, %r11w
je 0x18ae3
movzwl (%r14,%r10,2), %ecx
testw %cx, %cx
je 0x18ae3
movq %rdx, 0x40(%rsp)
movq (%r9,%r10,8), %rbp
testq %rbp, %rbp
movq %r10, 0x20(%rsp)
jne 0x18890
movl %r10d, %edi
callq 0x2fc7e
movq 0x20(%rsp), %r10
leaq 0x380a64(%rip), %rax    # 0x3992e0
movq (%rax,%r10,8), %rbp
movzwl (%rbx,%r10,2), %r11d
movzwl (%r14,%r10,2), %ecx
movl 0x8b778(%rip), %esi     # 0xa4008
movw %r11w, 0x18(%rsp)
movw %cx, 0xe(%rsp)
movl %r12d, %edi
movl %esi, %ecx
shll %cl, %edi
movq %r13, 0x38(%rsp)
movl %r13d, %eax
cltd
idivl %edi
movl %eax, %ebx
movl %edx, %r14d
movb $0x6, %cl
subb %sil, %cl
shll %cl, %r14d
shll %cl, %ebx
movl $0x40, %eax
movl %esi, %ecx
shrl %cl, %eax
movl %r14d, %edi
movl %ebx, %esi
movl %r10d, %edx
movl %eax, %ecx
callq 0x5d64b
movq 0x20(%rsp), %rdi
movzwl 0xe(%rsp), %r8d
testl %eax, %eax
leaq 0x3809f8(%rip), %r9     # 0x3992e0
je 0x18a02
movzwl 0x18(%rsp), %r10d
movswl %r10w, %edx
movslq %ebx, %rax
leaq 0x3fe39e(%rip), %rcx    # 0x416ca0
movslq (%rcx,%rax,4), %rax
movslq %r14d, %rbx
addq %rax, %rbx
leaq 0x16579d(%rip), %rax    # 0x17e0b0
addq (%rax), %rbx
movswl %r8w, %r14d
movl 0x8b6e8(%rip), %ecx     # 0xa4008
movl $0x40, %eax
shrl %cl, %eax
cmpl %edx, %eax
jl 0x18969
cmpl %r14d, %eax
jl 0x18969
testw %r10w, %r10w
jle 0x18a02
movl %edx, %eax
xorl %ecx, %ecx
testw %r8w, %r8w
jle 0x1895c
leaq (%rbx,%rcx), %rdx
movl %r14d, %esi
movb (%rbp), %dil
incq %rbp
movb %dil, (%rdx)
addq %r15, %rdx
decl %esi
jne 0x1894b
incq %rcx
cmpq %rax, %rcx
jne 0x1893e
jmp 0x18a02
movl $0x3f, %eax
shrl %cl, %eax
cmpw %r8w, %r10w
movl %r14d, %esi
cmovgl %edx, %esi
addl %eax, %esi
movb $0x6, %al
subb %cl, %al
movl %eax, %ecx
sarl %cl, %esi
testw %r10w, %r10w
jle 0x18a02
movl %esi, %ebp
movslq %r14d, %r10
movslq %edx, %r11
imulq %rbp, %r10
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r10, 0x18(%rsp)
movq %r11, 0x48(%rsp)
movq (%r9,%rdi,8), %rax
testq %rax, %rax
jne 0x189d4
callq 0x2fc7e
movq 0x48(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %rdi
movzwl 0xe(%rsp), %r8d
leaq 0x380910(%rip), %r9     # 0x3992e0
movq (%r9,%rdi,8), %rax
testw %r8w, %r8w
jle 0x189f4
addq %r13, %rax
xorl %ecx, %ecx
movq %rbx, %rdx
movb (%rax,%rcx), %sil
movb %sil, (%rdx)
addq %r15, %rdx
addq %rbp, %rcx
cmpl %r14d, %ecx
jl 0x189e2
incq %rbx
addq %rbp, %r12
addq %r10, %r13
cmpq %r11, %r12
jb 0x189a6
movswl 0x1293a7(%rip), %eax    # 0x141db0
movl 0x8b5f9(%rip), %esi     # 0xa4008
cmpl $0x23ff, %eax           # imm = 0x23FF
jg 0x18abb
movl 0x14(%rsp), %r12d
movl %r12d, %edi
movl %esi, %ecx
shll %cl, %edi
movq 0x38(%rsp), %rbp
movl %ebp, %eax
cltd
idivl %edi
movl %eax, %ebx
movl %edx, %r14d
movb $0x6, %cl
subb %sil, %cl
shll %cl, %r14d
shll %cl, %ebx
leaq 0x12035a(%rip), %rax    # 0x138da0
movq 0x40(%rsp), %rcx
movswl (%rax,%rcx,2), %edx
leaq 0x50(%rsp), %r13
movq %r13, %rdi
leaq 0x5c3df(%rip), %rsi     # 0x74e3d
xorl %eax, %eax
callq 0x6b00
movswl 0x1152dc(%rip), %edx    # 0x12dd48
movl %r14d, %edi
movl %ebx, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r13, %r8
movq %rbp, %r13
movl $0x1, %r9d
callq 0x3d8b3
leaq 0x380852(%rip), %r9     # 0x3992e0
movzwl 0x12931b(%rip), %eax    # 0x141db0
movl 0x8b56d(%rip), %esi     # 0xa4008
movl 0x10(%rsp), %ebp
movq 0x30(%rsp), %rdi
leaq 0x124b05(%rip), %r8     # 0x13d5b0
leaq 0x3f756e(%rip), %rbx    # 0x410020
leaq 0x3e8d27(%rip), %r14    # 0x4017e0
jmp 0x18ae3
movl 0x14(%rsp), %r12d
movl 0x10(%rsp), %ebp
movq 0x30(%rsp), %rdi
leaq 0x124ae0(%rip), %r8     # 0x13d5b0
leaq 0x3f7549(%rip), %rbx    # 0x410020
leaq 0x3e8d02(%rip), %r14    # 0x4017e0
movq 0x38(%rsp), %r13
leal (%rsi,%rsi), %ecx
movl %ebp, %edx
shll %cl, %edx
incq %r13
movslq %edx, %rcx
cmpq %rcx, %r13
jl 0x18822
movl %esi, %ecx
shll %cl, %r12d
movl 0x2c(%rsp), %r13d
movl %r13d, %eax
subl 0x28(%rsp), %eax
cltd
idivl %r12d
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 0x115207(%rip), %r8d    # 0x12dd48
movl %ebp, %edi
movl %r12d, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x3d51a
addl %r15d, %r14d
shll $0xc, %r14d
movzbl 0x1151e9(%rip), %r8d    # 0x12dd48
movl %ebx, %edi
movl %r12d, %esi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x3d51a
movzbl 0x1151d2(%rip), %r8d    # 0x12dd48
movl %ebx, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x3d51a
movzbl 0x1151bb(%rip), %r8d    # 0x12dd48
movl %ebp, %edi
movl %r14d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x3d51a
movslq %r13d, %rax
leaq 0x124a0a(%rip), %rcx    # 0x13d5b0
movswq (%rcx,%rax,2), %r14
leaq 0x5c28b(%rip), %rsi     # 0x74e3d
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x6b00
leaq 0x3ef425(%rip), %r13    # 0x407ff0
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x11516f(%rip), %edx    # 0x12dd48
xorl %edi, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x3d8b3
leaq 0x3ef3fa(%rip), %r12    # 0x407fec
movl (%r12), %ebp
leaq (%r14,%r14,4), %rax
leaq (%rax,%rax,4), %rax
leaq 0x1291bb(%rip), %r15    # 0x141dc0
addq %rax, %r15
movq %r15, %rdi
callq 0x6420
shll $0x3, %eax
subl %eax, %ebp
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x115125(%rip), %edx    # 0x12dd48
movl %ebp, %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r15, %r8
xorl %r9d, %r9d
callq 0x3d8b3
leaq 0x3f73e4(%rip), %rax    # 0x410020
movswl (%rax,%r14,2), %edx
leaq 0x3e8b98(%rip), %rax    # 0x4017e0
movswl (%rax,%r14,2), %ecx
leaq 0x5b9b3(%rip), %rsi     # 0x74607
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6b00
movl (%r12), %edi
sarl $0x2, %edi
movl (%r13), %esi
addl $-0x8, %esi
movswl 0x1150d5(%rip), %edx    # 0x12dd48
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x3d8b3
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq