// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: nextpage
void nextpage(void)
{
	int i;
	permfifotype *per;

	//char snotbuf[32];
	//j = 0; k = 0;
	//for(i=0;i<4096;i++)
	//   if (waloff[i] != 0)
	//   {
	//      sprintf(snotbuf,"%ld-%ld",i,tilesizx[i]*tilesizy[i]);
	//      printext256((j>>5)*40+32,(j&31)*6,walock[i]>>3,-1,snotbuf,1);
	//      k += tilesizx[i]*tilesizy[i];
	//      j++;
	//   }
	//sprintf(snotbuf,"Total: %ld",k);
	//printext256((j>>5)*40+32,(j&31)*6,31,-1,snotbuf,1);

	switch(qsetmode)
	{
		case 200:
			for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
			{
				per = &permfifo[i];
				if ((per->pagesleft > 0) && (per->pagesleft <= numpages))
					dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum,
							per->dashade,per->dapalnum,per->dastat,
							per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid);
			}

			OSD_Draw();
#if USE_POLYMOST
			polymost_nextpage();
#endif

			if (captureatnextpage) {
				screencapture(NULL, captureatnextpage);
				captureatnextpage = 0;
			}

			showframe();
#if USE_POLYMOST && USE_OPENGL
			polymost_aftershowframe();
#endif
			if (usegammabrightness!=ousegammabrightness) setbrightness(0,NULL,4);

			/*
			if (ratelimit > 0) {
				int delaytime;
				unsigned int thisticks, thist;

				ratelimitlast[ ratelimitn++ & 31 ] = thist = getusecticks();
				delaytime = 0;
				if (ratelimitn >= 32) {
					for (i=1;i<32;i++) delaytime += ratelimitlast[i] - ratelimitlast[i-1];
					delaytime = (1000000/ratelimit) - (delaytime/31);
				}
#ifdef _WIN32
				while (delaytime > 0) {
					Sleep(1);
					thisticks = getusecticks();
					delaytime -= (thisticks - thist);
					thist = thisticks;
				}
#endif
			}
			*/

			for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
			{
				per = &permfifo[i];
				if (per->pagesleft >= 130)
					dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum,
										per->dashade,per->dapalnum,per->dastat,
										per->cx1,per->cy1,per->cx2,per->cy2,per->uniqid);

				if ((per->pagesleft&127) && (numpages < 127)) per->pagesleft--;
				if (((per->pagesleft&127) == 0) && (i == permtail))
					permtail = ((permtail+1)&(MAXPERMS-1));
			}
			break;

		case 480:
			break;
	}
	faketimerhandler();

	if ((totalclock >= lastageclock+8) || (totalclock < lastageclock))
		{ lastageclock = totalclock; agecache(); }

#if USE_POLYMOST && USE_OPENGL
	omdtims = mdtims; mdtims = getticks();
	if (((unsigned int)(mdtims-omdtims)) > 10000) omdtims = mdtims;
#endif

	beforedrawrooms = 1;
	numframes++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0xc8, 0x183de8(%rip)   # 0x1b8a28
jne 0x34e01
movl 0x3e4220(%rip), %ebx    # 0x418e6c
movl 0x3e421e(%rip), %eax    # 0x418e70
cmpl %eax, %ebx
je 0x34ced
movl 0x3ee220(%rip), %ecx    # 0x422e80
leaq 0x3e4219(%rip), %r14    # 0x418e80
movslq %ebx, %rdx
leaq (%rdx,%rdx,4), %rdx
movzbl 0x13(%r14,%rdx,8), %esi
testl %esi, %esi
je 0x34cdd
cmpl %esi, %ecx
jl 0x34cdd
leaq (%r14,%rdx,8), %r10
movl (%r10), %edi
movl 0x4(%r10), %esi
movl 0x8(%r10), %edx
movswl 0xc(%r10), %ecx
movswl 0xe(%r10), %r8d
movsbl 0x10(%r10), %r9d
movzbl 0x11(%r10), %eax
movzbl 0x12(%r10), %r11d
movl 0x14(%r10), %r15d
movl 0x18(%r10), %r12d
movl 0x1c(%r10), %r13d
movl 0x20(%r10), %ebp
movl 0x24(%r10), %r10d
subq $0x8, %rsp
pushq %r10
pushq %rbp
pushq %r13
pushq %r12
pushq %r15
pushq %r11
pushq %rax
callq 0x34e76
addq $0x40, %rsp
movl 0x3ee1a9(%rip), %ecx    # 0x422e80
movl 0x3e4193(%rip), %eax    # 0x418e70
incl %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
cmpl %eax, %ebx
jne 0x34c67
callq 0x4c991
callq 0x51016
movb 0x3ee187(%rip), %al     # 0x422e84
testb %al, %al
je 0x34d12
movsbl %al, %esi
xorl %edi, %edi
callq 0x35957
movb $0x0, 0x3ee172(%rip)    # 0x422e84
callq 0x6efcd
callq 0x50be5
movl 0x6fa6a(%rip), %eax     # 0xa478c
cmpl 0x6fa68(%rip), %eax     # 0xa4790
je 0x34d38
xorl %edi, %edi
xorl %esi, %esi
movl $0x4, %edx
callq 0x348a4
movl 0x3e412e(%rip), %ebx    # 0x418e6c
cmpl 0x3e412c(%rip), %ebx    # 0x418e70
je 0x34e01
leaq 0x3e412f(%rip), %rcx    # 0x418e80
movslq %ebx, %rax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r15
movb 0x13(%r15), %al
cmpb $-0x7e, %al
jb 0x34dc0
movl (%r15), %edi
movl 0x4(%r15), %esi
movl 0x8(%r15), %edx
movswl 0xc(%r15), %ecx
movswl 0xe(%r15), %r8d
movsbl 0x10(%r15), %r9d
movzbl 0x11(%r15), %eax
movzbl 0x12(%r15), %r10d
movl 0x14(%r15), %r11d
movl 0x18(%r15), %r12d
movl 0x1c(%r15), %r13d
movl 0x20(%r15), %ebp
movl 0x24(%r15), %r14d
subq $0x8, %rsp
pushq %r14
pushq %rbp
pushq %r13
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0x34e76
leaq 0x3e40c8(%rip), %rcx    # 0x418e80
addq $0x40, %rsp
movb 0x13(%r15), %al
testb $0x7f, %al
je 0x34dd3
cmpl $0x7e, 0x3ee0b5(%rip)   # 0x422e80
jg 0x34dd3
decb %al
movb %al, 0x13(%r15)
testb $0x7f, %al
jne 0x34ded
cmpl 0x3e408f(%rip), %ebx    # 0x418e6c
jne 0x34ded
leal 0x1(%rbx), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, 0x3e407f(%rip)    # 0x418e6c
incl %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
cmpl 0x3e4075(%rip), %ebx    # 0x418e70
jne 0x34d51
callq 0xacd7
movl 0x3776dc(%rip), %eax    # 0x3ac4e8
movl 0x3ee076(%rip), %ecx    # 0x422e88
leal 0x8(%rcx), %edx
cmpl %edx, %eax
setl %dl
cmpl %ecx, %eax
setge %cl
testb %dl, %cl
jne 0x34e2e
movl %eax, 0x3ee05f(%rip)    # 0x422e88
callq 0x1fb7c
leaq 0x67f26b(%rip), %r14    # 0x6b40a0
movl (%r14), %eax
leaq 0x67f265(%rip), %rbx    # 0x6b40a4
movl %eax, (%rbx)
callq 0x6e428
movl %eax, (%r14)
movl %eax, %ecx
subl (%rbx), %ecx
cmpl $0x2711, %ecx           # imm = 0x2711
jb 0x34e57
movl %eax, (%rbx)
movl $0x1, 0x6f927(%rip)     # 0xa4788
incl 0x3ee025(%rip)          # 0x422e8c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq