// File: /workspace/github_c_makefile_star2_O1/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, 0x183f3a(%rip)   # 0x1b7a28
jne 0x33ca2
movl 0x3e4372(%rip), %ebx    # 0x417e6c
cmpl 0x3e4370(%rip), %ebx    # 0x417e70
je 0x33b8b
leaq 0x3e4373(%rip), %r14    # 0x417e80
movslq %ebx, %rax
leaq (%rax,%rax,4), %rax
movzbl 0x13(%r14,%rax,8), %ecx
testl %ecx, %ecx
je 0x33b7b
cmpl %ecx, 0x3ee35c(%rip)    # 0x421e80
jl 0x33b7b
leaq (%r14,%rax,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 0x33d17
addq $0x40, %rsp
incl %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
cmpl 0x3e42e7(%rip), %ebx    # 0x417e70
jne 0x33b0d
callq 0x4a4cd
callq 0x4e8b5
movb 0x3ee2e9(%rip), %al     # 0x421e84
testb %al, %al
je 0x33bb0
movsbl %al, %esi
xorl %edi, %edi
callq 0x34728
movb $0x0, 0x3ee2d4(%rip)    # 0x421e84
callq 0x6d200
callq 0x4e483
movl 0x6fbcc(%rip), %eax     # 0xa378c
cmpl 0x6fbca(%rip), %eax     # 0xa3790
je 0x33bd6
xorl %edi, %edi
xorl %esi, %esi
movl $0x4, %edx
callq 0x33747
movl 0x3e4290(%rip), %ebx    # 0x417e6c
cmpl 0x3e428e(%rip), %ebx    # 0x417e70
je 0x33ca2
leaq 0x3e4291(%rip), %rcx    # 0x417e80
movslq %ebx, %rax
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r15
cmpb $-0x7e, 0x13(%r15)
jb 0x33c59
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 0x33d17
leaq 0x3e422b(%rip), %rcx    # 0x417e80
addq $0x40, %rsp
movb 0x13(%r15), %al
testb $0x7f, %al
je 0x33c70
cmpl $0x7e, 0x3ee218(%rip)   # 0x421e80
jg 0x33c70
decb %al
movb %al, 0x13(%r15)
testb $0x7f, 0x13(%r15)
jne 0x33c8e
movl 0x3e41ef(%rip), %eax    # 0x417e6c
cmpl %eax, %ebx
jne 0x33c8e
incl %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, 0x3e41de(%rip)    # 0x417e6c
incl %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
cmpl 0x3e41d4(%rip), %ebx    # 0x417e70
jne 0x33bef
callq 0xab51
movl 0x37783b(%rip), %eax    # 0x3ab4e8
movl 0x3ee1d5(%rip), %ecx    # 0x421e88
leal 0x8(%rcx), %edx
cmpl %edx, %eax
setl %dl
cmpl %ecx, %eax
setge %cl
testb %dl, %cl
jne 0x33ccf
movl %eax, 0x3ee1be(%rip)    # 0x421e88
callq 0x1f68a
leaq 0x67f3da(%rip), %r14    # 0x6b30b0
movl (%r14), %eax
leaq 0x67f3d4(%rip), %rbx    # 0x6b30b4
movl %eax, (%rbx)
callq 0x6c6fa
movl %eax, (%r14)
movl %eax, %ecx
subl (%rbx), %ecx
cmpl $0x2711, %ecx           # imm = 0x2711
jb 0x33cf8
movl %eax, (%rbx)
movl $0x1, 0x6fa86(%rip)     # 0xa3788
incl 0x3ee184(%rip)          # 0x421e8c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq