// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/sdlayer2.c
// Function: getvalidmodes
void getvalidmodes(void)
{
	static int defaultres[][2] = {
		{1920,1200},{1920,1080},{1600,1200},{1680,1050},{1600,900},{1400,1050},{1440,900},{1366,768},
		{1280,1024},{1280,960},{1280,800},{1280,720},{1152,864},{1024,768},{800,600},{640,480},
		{640,400},{512,384},{480,360},{400,300},{320,240},{320,200},{0,0}
	};
	SDL_DisplayMode desktop;
	int i, maxx=0, maxy=0;

	if (modeschecked) return;

	validmodecnt=0;

	if (SDL_GetNumVideoDisplays() < 1) {
		buildputs("No video displays available!\n");
		return;
	}

	debugprintf("Detecting video modes:\n");

#define ADDMODE(x,y,c,f) if (validmodecnt<MAXVALIDMODES) { \
	int mn; \
	for(mn=0;mn<validmodecnt;mn++) \
		if (validmode[mn].xdim==x && validmode[mn].ydim==y && \
			validmode[mn].bpp==c  && validmode[mn].fs==f) break; \
	if (mn==validmodecnt) { \
		validmode[validmodecnt].xdim=x; \
		validmode[validmodecnt].ydim=y; \
		validmode[validmodecnt].bpp=c; \
		validmode[validmodecnt].fs=f; \
		validmodecnt++; \
		debugprintf("  - %dx%d %d-bit %s\n", x, y, c, (f&1)?"fullscreen":"windowed"); \
	} \
}

#define CHECKL(w,h) if ((w < maxx) && (h < maxy))
#define CHECKLE(w,h) if ((w <= maxx) && (h <= maxy))

	SDL_GetDesktopDisplayMode(0, &desktop);
	maxx = desktop.w;
	maxy = desktop.h;

	// Fullscreen 8-bit modes: upsamples to the desktop mode
	for (i=0; defaultres[i][0]; i++)
		CHECKLE(defaultres[i][0],defaultres[i][1])
			ADDMODE(defaultres[i][0],defaultres[i][1],8,1)

#if USE_POLYMOST && USE_OPENGL
	// Fullscreen >8-bit modes
	if (!glunavailable) {
		SDL_DisplayMode mode;
		for (int j = SDL_GetNumDisplayModes(0) - 1; j >= 0; j--) {
			SDL_GetDisplayMode(0, j, &mode);
			if ((mode.w > MAXXDIM) || (mode.h > MAXYDIM)) continue;
			if (SDL_BITSPERPIXEL(mode.format) < 8) continue;
			ADDMODE(mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), 1)
		}
	}
#endif

	// Windowed 8-bit modes
	for (i=0; defaultres[i][0]; i++) {
		CHECKL(defaultres[i][0],defaultres[i][1]) {
			ADDMODE(defaultres[i][0], defaultres[i][1], 8, 0)
		}
	}

#if USE_POLYMOST && USE_OPENGL
	// Windowed >8-bit modes
	if (!glunavailable) {
		for (i=0; defaultres[i][0]; i++) {
			CHECKL(defaultres[i][0],defaultres[i][1]) {
				ADDMODE(defaultres[i][0], defaultres[i][1], SDL_BITSPERPIXEL(desktop.format), 0)
			}
		}
	}
#endif

#undef CHECK
#undef ADDMODE

	qsort((void*)validmode, validmodecnt, sizeof(struct validmode_t), (int(*)(const void*,const void*))sortmodes);

	modeschecked=1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpb $0x0, 0x660ba9(%rip)    # 0x6cf000
jne 0x6e7c8
leaq 0x2ef44c(%rip), %r15    # 0x35d8b0
movl $0x0, (%r15)
callq 0x6bb0
testl %eax, %eax
jle 0x6e7d7
xorl %r14d, %r14d
leaq 0x20(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x65c0
movl 0x4(%rbx), %ebp
movl 0x8(%rbx), %r12d
movl (%r15), %eax
leaq 0x10705(%rip), %rcx     # 0x7eba0
movl $0x780, %esi            # imm = 0x780
leaq 0x3cd9a9(%rip), %rbx    # 0x43be50
leaq 0x9(%rbx), %rdx
movq %rcx, %rdi
cmpl %ebp, %esi
jg 0x6e527
movl 0x4(%rdi), %edi
cmpl %r12d, %edi
setle %r8b
cmpl $0x100, %eax            # imm = 0x100
setl %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x6e527
testl %eax, %eax
jle 0x6e502
movl %eax, %r9d
movq %rdx, %r10
xorl %r8d, %r8d
cmpl %esi, -0x9(%r10)
jne 0x6e4f4
cmpl %edi, -0x5(%r10)
jne 0x6e4f4
cmpb $0x8, -0x1(%r10)
jne 0x6e4f4
cmpb $0x1, (%r10)
je 0x6e505
incq %r8
addq $0x10, %r10
cmpq %r8, %r9
jne 0x6e4db
jmp 0x6e50a
xorl %r8d, %r8d
cmpl %eax, %r8d
jne 0x6e527
movslq %eax, %r8
shlq $0x4, %r8
movl %esi, (%rbx,%r8)
movl %edi, 0x4(%rbx,%r8)
movw $0x108, 0x8(%rbx,%r8)   # imm = 0x108
incl %eax
movl %eax, (%r15)
leaq (%rcx,%r14,8), %rdi
addq $0x8, %rdi
incq %r14
movl (%rdi), %esi
cmpq $0x16, %r14
jne 0x6e4ae
leaq 0x10fba3(%rip), %r14    # 0x17e0e8
cmpl $0x0, (%r14)
jne 0x6e65b
xorl %edi, %edi
callq 0x6c50
testl %eax, %eax
jle 0x6e64a
movl %eax, %ebx
leaq 0x8(%rsp), %r14
leaq 0x3cd8e4(%rip), %rax    # 0x43be50
addq $0x9, %rax
movq %rax, (%rsp)
movl %ebx, %r13d
leal -0x1(%r13), %ebx
xorl %edi, %edi
movl %ebx, %esi
movq %r14, %rdx
callq 0x6730
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl $0xf01, %eax            # imm = 0xF01
setge %dl
cmpl $0x871, %ecx            # imm = 0x871
setge %sil
orb %dl, %sil
jne 0x6e640
movl 0x8(%rsp), %edx
testl $0xf800, %edx           # imm = 0xF800
setne %dil
movl (%r15), %esi
cmpl $0x100, %esi            # imm = 0x100
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x6e640
movl %esi, %edi
testl %edi, %edi
jle 0x6e608
movl %edx, %r9d
shrl $0x8, %r9d
movq (%rsp), %r10
xorl %r8d, %r8d
cmpl %eax, -0x9(%r10)
jne 0x6e5fa
cmpl %ecx, -0x5(%r10)
jne 0x6e5fa
cmpb %r9b, -0x1(%r10)
jne 0x6e5fa
cmpb $0x1, (%r10)
je 0x6e60b
incq %r8
addq $0x10, %r10
cmpq %r8, %rdi
jne 0x6e5e2
jmp 0x6e610
xorl %r8d, %r8d
cmpl %esi, %r8d
jne 0x6e640
movslq %esi, %rdi
shlq $0x4, %rdi
leaq 0x3cd832(%rip), %r8     # 0x43be50
movl %edx, %r9d
movq %r8, %rdx
movl %eax, (%r8,%rdi)
movl %ecx, 0x4(%r8,%rdi)
movl %r9d, %eax
movb %ah, 0x8(%rdx,%rdi)
movb $0x1, 0x9(%r8,%rdi)
leal 0x1(%rsi), %eax
movl %eax, (%r15)
cmpl $0x1, %r13d
jg 0x6e574
movl (%r15), %eax
leaq 0x3cd7fc(%rip), %rbx    # 0x43be50
leaq 0x10fa8d(%rip), %r14    # 0x17e0e8
leaq 0x1053e(%rip), %rcx     # 0x7eba0
movl $0x780, %edi            # imm = 0x780
xorl %edx, %edx
leaq 0x9(%rbx), %rsi
movq %rcx, %r8
cmpl %ebp, %edi
jge 0x6e6dd
movl 0x4(%r8), %r8d
cmpl %r12d, %r8d
jge 0x6e6dd
cmpl $0xff, %eax
jg 0x6e6dd
testl %eax, %eax
jle 0x6e6b8
movl %eax, %r10d
movq %rsi, %r11
xorl %r9d, %r9d
cmpl %edi, -0x9(%r11)
jne 0x6e6aa
cmpl %r8d, -0x5(%r11)
jne 0x6e6aa
cmpb $0x8, -0x1(%r11)
jne 0x6e6aa
cmpb $0x0, (%r11)
je 0x6e6bb
incq %r9
addq $0x10, %r11
cmpq %r9, %r10
jne 0x6e691
jmp 0x6e6c0
xorl %r9d, %r9d
cmpl %eax, %r9d
jne 0x6e6dd
movslq %eax, %r9
shlq $0x4, %r9
movl %edi, (%rbx,%r9)
movl %r8d, 0x4(%rbx,%r9)
movw $0x8, 0x8(%rbx,%r9)
incl %eax
movl %eax, (%r15)
leaq (%rcx,%rdx,8), %r8
addq $0x8, %r8
incq %rdx
movl (%r8), %edi
cmpq $0x16, %rdx
jne 0x6e670
cmpl $0x0, (%r14)
jne 0x6e7a6
movb 0x21(%rsp), %cl
leaq 0x10496(%rip), %rdx     # 0x7eba0
movl $0x780, %r8d            # imm = 0x780
xorl %esi, %esi
leaq 0x9(%rbx), %rdi
movq %rdx, %r9
cmpl %ebp, %r8d
jge 0x6e78e
movl 0x4(%r9), %r9d
cmpl %r12d, %r9d
jge 0x6e78e
cmpl $0xff, %eax
jg 0x6e78e
testl %eax, %eax
jle 0x6e75f
movl %eax, %r11d
movq %rdi, %rbx
xorl %r10d, %r10d
cmpl %r8d, -0x9(%rbx)
jne 0x6e751
cmpl %r9d, -0x5(%rbx)
jne 0x6e751
cmpb %cl, -0x1(%rbx)
jne 0x6e751
cmpb $0x0, (%rbx)
je 0x6e762
incq %r10
addq $0x10, %rbx
cmpq %r10, %r11
jne 0x6e73b
jmp 0x6e767
xorl %r10d, %r10d
cmpl %eax, %r10d
jne 0x6e78e
movslq %eax, %r10
shlq $0x4, %r10
leaq 0x3cd6db(%rip), %r11    # 0x43be50
movl %r8d, (%r11,%r10)
movl %r9d, 0x4(%r11,%r10)
movb %cl, 0x8(%r11,%r10)
movb $0x0, 0x9(%r11,%r10)
incl %eax
movl %eax, (%r15)
leaq (%rdx,%rsi,8), %r9
addq $0x8, %r9
incq %rsi
movl (%r9), %r8d
cmpq $0x16, %rsi
jne 0x6e719
movslq %eax, %rsi
leaq 0x3cd6a0(%rip), %rdi    # 0x43be50
leaq 0x3a(%rip), %rcx        # 0x6e7f1
movl $0x10, %edx
callq 0x6790
movb $0x1, 0x660838(%rip)    # 0x6cf000
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x101a4(%rip), %rdi     # 0x7e982
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32d18