// File: /workspace/github_c_makefile_star2_O1/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, 0x6618e7(%rip)    # 0x6ce010
jne 0x6cac1
leaq 0x2f017a(%rip), %r15    # 0x35c8b0
movl $0x0, (%r15)
callq 0x6bb0
testl %eax, %eax
jle 0x6cad0
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 0x10f93(%rip), %rcx     # 0x7d700
movl $0x780, %esi            # imm = 0x780
leaq 0x3ce6d7(%rip), %rbx    # 0x43ae50
leaq 0x9(%rbx), %rdx
movq %rcx, %rdi
cmpl %ebp, %esi
jg 0x6c7fc
movl 0x4(%rdi), %edi
cmpl %r12d, %edi
setle %r8b
cmpl $0x100, %eax            # imm = 0x100
setl %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x6c7fc
testl %eax, %eax
jle 0x6c7d7
movl %eax, %r9d
movq %rdx, %r10
xorl %r8d, %r8d
cmpl %esi, -0x9(%r10)
jne 0x6c7c6
cmpl %edi, -0x5(%r10)
jne 0x6c7c6
cmpb $0x8, -0x1(%r10)
jne 0x6c7c6
cmpb $0x1, (%r10)
je 0x6c7da
incq %r8
addq $0x10, %r10
cmpq %r8, %r9
jne 0x6c7ad
movl %r9d, %r8d
jmp 0x6c7da
xorl %r8d, %r8d
cmpl %eax, %r8d
jne 0x6c7fc
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 0x6c780
leaq 0x1108ce(%rip), %r14    # 0x17d0e8
cmpl $0x0, (%r14)
jne 0x6c92a
xorl %edi, %edi
callq 0x6c50
testl %eax, %eax
jle 0x6c91c
movl %eax, %ebx
leaq 0x8(%rsp), %r14
leaq 0x3ce60f(%rip), %rax    # 0x43ae50
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 0x6c912
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 0x6c912
movl %esi, %edi
testl %esi, %esi
jle 0x6c8e0
movl %edx, %r9d
shrl $0x8, %r9d
movq (%rsp), %r10
xorl %r8d, %r8d
cmpl %eax, -0x9(%r10)
jne 0x6c8cf
cmpl %ecx, -0x5(%r10)
jne 0x6c8cf
cmpb %r9b, -0x1(%r10)
jne 0x6c8cf
cmpb $0x1, (%r10)
je 0x6c8e3
incq %r8
addq $0x10, %r10
cmpq %r8, %rdi
jne 0x6c8b7
movl %edi, %r8d
jmp 0x6c8e3
xorl %r8d, %r8d
cmpl %edi, %r8d
jne 0x6c912
movslq %esi, %rdi
shlq $0x4, %rdi
leaq 0x3ce55a(%rip), %r8     # 0x43ae50
movl %eax, (%r8,%rdi)
movq %r8, %rax
movl %ecx, 0x4(%r8,%rdi)
movb %dh, 0x8(%rax,%rdi)
movb $0x1, 0x9(%r8,%rdi)
leal 0x1(%rsi), %eax
movl %eax, (%r15)
cmpl $0x1, %r13d
jg 0x6c849
leaq 0x3ce52d(%rip), %rbx    # 0x43ae50
leaq 0x1107be(%rip), %r14    # 0x17d0e8
movl (%r15), %eax
leaq 0x10dcc(%rip), %rcx     # 0x7d700
movl $0x780, %edi            # imm = 0x780
xorl %edx, %edx
leaq 0x9(%rbx), %rsi
movq %rcx, %r8
cmpl %ebp, %edi
jge 0x6c9bf
movl 0x4(%r8), %r8d
cmpl %r12d, %r8d
setl %r9b
cmpl $0x100, %eax            # imm = 0x100
setl %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x6c9bf
testl %eax, %eax
jle 0x6c99a
movl %eax, %r10d
movq %rsi, %r11
xorl %r9d, %r9d
cmpl %edi, -0x9(%r11)
jne 0x6c989
cmpl %r8d, -0x5(%r11)
jne 0x6c989
cmpb $0x8, -0x1(%r11)
jne 0x6c989
cmpb $0x0, (%r11)
je 0x6c99d
incq %r9
addq $0x10, %r11
cmpq %r9, %r10
jne 0x6c970
movl %r10d, %r9d
jmp 0x6c99d
xorl %r9d, %r9d
cmpl %eax, %r9d
jne 0x6c9bf
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 0x6c942
cmpl $0x0, (%r14)
jne 0x6ca9f
movl (%r15), %eax
movb 0x21(%rsp), %cl
leaq 0x10d11(%rip), %rdx     # 0x7d700
movl $0x780, %r8d            # imm = 0x780
xorl %esi, %esi
leaq 0x9(%rbx), %rdi
movq %rdx, %r9
cmpl %ebp, %r8d
jge 0x6ca87
movl 0x4(%r9), %r9d
cmpl %r12d, %r9d
setl %r10b
cmpl $0x100, %eax            # imm = 0x100
setl %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x6ca87
testl %eax, %eax
jle 0x6ca5f
movl %eax, %r11d
movq %rdi, %rbx
xorl %r10d, %r10d
cmpl %r8d, -0x9(%rbx)
jne 0x6ca47
cmpl %r9d, -0x5(%rbx)
jne 0x6ca47
cmpb %cl, -0x1(%rbx)
jne 0x6ca47
cmpb $0x0, (%rbx)
je 0x6ca56
incq %r10
addq $0x10, %rbx
cmpq %r10, %r11
jne 0x6ca31
movl %r11d, %r10d
leaq 0x3ce3f3(%rip), %rbx    # 0x43ae50
jmp 0x6ca62
xorl %r10d, %r10d
cmpl %eax, %r10d
jne 0x6ca87
movslq %eax, %r10
shlq $0x4, %r10
movl %r8d, (%rbx,%r10)
movl %r9d, 0x4(%rbx,%r10)
movb %cl, 0x8(%rbx,%r10)
movb $0x0, 0x9(%rbx,%r10)
incl %eax
movl %eax, (%r15)
leaq (%rdx,%rsi,8), %r9
addq $0x8, %r9
incq %rsi
movl (%r9), %r8d
cmpq $0x16, %rsi
jne 0x6c9fe
movslq (%r15), %rsi
leaq 0x3ce3a7(%rip), %rdi    # 0x43ae50
leaq 0x3a(%rip), %rcx        # 0x6caea
movl $0x10, %edx
callq 0x6790
movb $0x1, 0x66154f(%rip)    # 0x6ce010
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10a0b(%rip), %rdi     # 0x7d4e2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32200