// File: /workspace/github_c_makefile_star2_O2/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, 0x180414(%rip)   # 0x1b1a28
jne 0x317d1
movl 0x3e084c(%rip), %ebp    # 0x411e6c
movl 0x3e084a(%rip), %eax    # 0x411e70
leaq 0x3e0853(%rip), %rbx    # 0x411e80
cmpl %eax, %ebp
je 0x316b6
movslq %ebp, %rcx
imulq $0x28, %rcx, %r10
movzbl 0x13(%r10,%rbx), %ecx
testl %ecx, %ecx
je 0x316a9
cmpl %ecx, 0x3ea834(%rip)    # 0x41be80
jl 0x316a9
addq %rbx, %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), %r14d
movl 0x18(%r10), %r15d
movl 0x1c(%r10), %r12d
movl 0x20(%r10), %r13d
movl 0x24(%r10), %r10d
subq $0x8, %rsp
pushq %r10
pushq %r13
pushq %r12
pushq %r15
pushq %r14
pushq %r11
pushq %rax
callq 0x31846
addq $0x40, %rsp
movl 0x3e07c7(%rip), %eax    # 0x411e70
incl %ebp
andl $0x3ff, %ebp            # imm = 0x3FF
jmp 0x3162d
callq 0x43e86
callq 0x47532
movb 0x3ea7be(%rip), %al     # 0x41be84
testb %al, %al
je 0x316db
movsbl %al, %esi
xorl %edi, %edi
callq 0x322ad
movb $0x0, 0x3ea7a9(%rip)    # 0x41be84
callq 0x63720
callq 0x4711b
movl 0x6c0a1(%rip), %eax     # 0x9d78c
cmpl 0x6c09f(%rip), %eax     # 0x9d790
je 0x316ff
pushq $0x4
popq %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0x31279
movl 0x3e0766(%rip), %r14d   # 0x411e6c
movl 0x3e0764(%rip), %eax    # 0x411e70
cmpl %eax, %r14d
je 0x317d1
movslq %r14d, %rcx
imulq $0x28, %rcx, %rcx
leaq (%rbx,%rcx), %r15
movb 0x13(%rcx,%rbx), %cl
cmpb $-0x7e, %cl
jb 0x31790
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
movq %rax, (%rsp)
movzbl 0x12(%r15), %r10d
movl 0x14(%r15), %r11d
movl 0x18(%r15), %r12d
movl 0x1c(%r15), %r13d
movl 0x20(%r15), %ebp
movq %rbx, %rax
movl 0x24(%r15), %ebx
subq $0x8, %rsp
pushq %rbx
movq %rax, %rbx
pushq %rbp
pushq %r13
pushq %r12
pushq %r11
pushq %r10
pushq 0x38(%rsp)
callq 0x31846
addq $0x40, %rsp
movl 0x3e06e4(%rip), %eax    # 0x411e70
movb 0x13(%r15), %cl
testb $0x7f, %cl
je 0x317a4
cmpl $0x7e, 0x3ea6e4(%rip)   # 0x41be80
jg 0x317a4
decb %cl
movb %cl, 0x13(%r15)
testb $0x7f, %cl
jne 0x317c2
cmpl 0x3e06bc(%rip), %r14d   # 0x411e6c
jne 0x317c2
leal 0x1(%r14), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movl %ecx, 0x3e06aa(%rip)    # 0x411e6c
incl %r14d
andl $0x3ff, %r14d           # imm = 0x3FF
jmp 0x3170c
callq 0x9fd2
movl 0x373d0c(%rip), %eax    # 0x3a54e8
movl 0x3ea6a6(%rip), %ecx    # 0x41be88
leal 0x8(%rcx), %edx
cmpl %edx, %eax
setl %dl
cmpl %ecx, %eax
setge %cl
testb %dl, %cl
jne 0x317fe
movl %eax, 0x3ea68f(%rip)    # 0x41be88
callq 0x1d488
leaq 0x67b89b(%rip), %r14    # 0x6ad0a0
movl (%r14), %eax
leaq 0x67b895(%rip), %rbx    # 0x6ad0a4
movl %eax, (%rbx)
callq 0x62cd4
movl %eax, (%r14)
movl %eax, %ecx
subl (%rbx), %ecx
cmpl $0x2711, %ecx           # imm = 0x2711
jb 0x31827
movl %eax, (%rbx)
movl $0x1, 0x6bf57(%rip)     # 0x9d788
incl 0x3ea655(%rip)          # 0x41be8c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq