// File: /workspace/github_c_makefile_star2_O2/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, 0x6652fd(%rip)    # 0x6c8000
jne 0x62fbb
leaq 0x2f3ba0(%rip), %rax    # 0x3568b0
andl $0x0, (%rax)
callq 0x6bb0
testl %eax, %eax
jle 0x62ee0
xorl %r14d, %r14d
leaq 0x20(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x65c0
movl 0x4(%rbx), %ebp
movl 0x8(%rbx), %r12d
leaq 0x2f3b70(%rip), %rbx    # 0x3568b0
movl (%rbx), %eax
leaq 0x10cb7(%rip), %r13     # 0x73a00
leaq 0x3d2100(%rip), %r15    # 0x434e50
leaq 0x9(%r15), %rcx
cmpq $0x16, %r14
je 0x62de7
movl (%r13,%r14,8), %edx
cmpl %ebp, %edx
jg 0x62ddf
movl 0x4(%r13,%r14,8), %esi
cmpl %r12d, %esi
setle %dil
cmpl $0x100, %eax            # imm = 0x100
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x62ddf
testl %eax, %eax
movl $0x0, %edi
cmovgl %eax, %edi
movq %rcx, %r9
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0x62dbf
cmpl %edx, -0x9(%r9)
jne 0x62db3
cmpl %esi, -0x5(%r9)
jne 0x62db3
cmpb $0x8, -0x1(%r9)
jne 0x62db3
cmpb $0x1, (%r9)
je 0x62dbc
incq %r8
addq $0x10, %r9
jmp 0x62d95
movl %r8d, %edi
cmpl %eax, %edi
jne 0x62ddf
movslq %eax, %rdi
shlq $0x4, %rdi
movl %edx, (%r15,%rdi)
movl %esi, 0x4(%r15,%rdi)
movw $0x108, 0x8(%r15,%rdi)  # imm = 0x108
incl %eax
movl %eax, (%rbx)
incq %r14
jmp 0x62d54
leaq 0x1142fa(%rip), %r11    # 0x1770e8
cmpl $0x0, (%r11)
jne 0x62f0a
xorl %edi, %edi
callq 0x6c50
movl %eax, %ebx
leaq 0x8(%rsp), %r14
leaq 0x9(%r15), %rax
movq %rax, (%rsp)
testl %ebx, %ebx
jle 0x62efa
decl %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 0x62e0e
movl 0x8(%rsp), %edx
testw $0xf800, %dx            # imm = 0xF800
setne %dil
leaq 0x2f3a59(%rip), %rsi    # 0x3568b0
movl (%rsi), %esi
cmpl $0x100, %esi            # imm = 0x100
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x62e0e
movslq %esi, %rdi
shrl $0x8, %edx
testl %esi, %esi
movl $0x0, %r8d
cmovgl %esi, %r8d
movq (%rsp), %r10
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x62eae
cmpl %eax, -0x9(%r10)
jne 0x62ea2
cmpl %ecx, -0x5(%r10)
jne 0x62ea2
cmpb %dl, -0x1(%r10)
jne 0x62ea2
cmpb $0x1, (%r10)
je 0x62eab
incq %r9
addq $0x10, %r10
jmp 0x62e85
movl %r9d, %r8d
cmpl %esi, %r8d
jne 0x62e0e
shlq $0x4, %rdi
movl %eax, (%r15,%rdi)
movl %ecx, 0x4(%r15,%rdi)
movb %dl, 0x8(%r15,%rdi)
movb $0x1, 0x9(%r15,%rdi)
leal 0x1(%rsi), %eax
leaq 0x2f39d7(%rip), %rcx    # 0x3568b0
movl %eax, (%rcx)
jmp 0x62e0e
leaq 0x108fb(%rip), %rdi     # 0x737e2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30c8d
leaq 0x2f39af(%rip), %rbx    # 0x3568b0
movl (%rbx), %eax
leaq 0x1141de(%rip), %r11    # 0x1770e8
xorl %ecx, %ecx
leaq 0x9(%r15), %rdx
cmpq $0x16, %rcx
je 0x62f95
movl (%r13,%rcx,8), %esi
cmpl %ebp, %esi
jge 0x62f8d
movl 0x4(%r13,%rcx,8), %edi
cmpl %r12d, %edi
jge 0x62f8d
cmpl $0xff, %eax
jg 0x62f8d
testl %eax, %eax
movl $0x0, %r8d
cmovgl %eax, %r8d
movq %rdx, %r10
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x62f6c
cmpl %esi, -0x9(%r10)
jne 0x62f60
cmpl %edi, -0x5(%r10)
jne 0x62f60
cmpb $0x8, -0x1(%r10)
jne 0x62f60
cmpb $0x0, (%r10)
je 0x62f69
incq %r9
addq $0x10, %r10
jmp 0x62f42
movl %r9d, %r8d
cmpl %eax, %r8d
jne 0x62f8d
movslq %eax, %r8
shlq $0x4, %r8
movl %esi, (%r15,%r8)
movl %edi, 0x4(%r15,%r8)
movw $0x8, 0x8(%r15,%r8)
incl %eax
movl %eax, (%rbx)
incq %rcx
jmp 0x62f10
cmpl $0x0, (%r11)
je 0x62fca
movslq %eax, %rsi
leaq 0x3d1eab(%rip), %rdi    # 0x434e50
leaq 0xaf(%rip), %rcx        # 0x6305b
pushq $0x10
popq %rdx
callq 0x6790
movb $0x1, 0x665045(%rip)    # 0x6c8000
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0x21(%rsp), %cl
xorl %edx, %edx
leaq 0x9(%r15), %rsi
cmpq $0x16, %rdx
je 0x62f9b
movl (%r13,%rdx,8), %edi
cmpl %ebp, %edi
jge 0x63053
movl 0x4(%r13,%rdx,8), %r8d
cmpl %r12d, %r8d
jge 0x63053
cmpl $0xff, %eax
jg 0x63053
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
movq %rsi, %r11
xorl %r10d, %r10d
cmpq %r10, %r9
je 0x6302f
cmpl %edi, -0x9(%r11)
jne 0x63023
cmpl %r8d, -0x5(%r11)
jne 0x63023
cmpb %cl, -0x1(%r11)
jne 0x63023
cmpb $0x0, (%r11)
je 0x6302c
incq %r10
addq $0x10, %r11
jmp 0x63006
movl %r10d, %r9d
cmpl %eax, %r9d
jne 0x63053
movslq %eax, %r9
shlq $0x4, %r9
movl %edi, (%r15,%r9)
movl %r8d, 0x4(%r15,%r9)
movb %cl, 0x8(%r15,%r9)
movb $0x0, 0x9(%r15,%r9)
incl %eax
movl %eax, (%rbx)
incq %rdx
jmp 0x62fd4