// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/spgbld/func.cxx
// Function: load_ini(char*)
void load_ini(char *name)
{
	char t[256];
	char v[256];
	char v1[256];
	char v2[256];
	int a = 0;
	int b = 0;
	int nblk = 0;
	FILE* f = fopen(name, "r");

	if (!f)
		error(INI);

	while (!feof(f)) {
		*t = 0;
		fscanf(f, "%256[^ =\n\r\t]%*[ =]%256[^\n\r]%*c", t, v);

		if (!*t) {
			fscanf(f, "%*c");
			continue;
		}

		if (t[0] == ';')
			continue;

		strlwr(t);

		// description string
		if (!strcmp(t, STR(F_DESC))) {
			strncpy(hdr.desc, v, 32);
			printf("Description:\t%s\n", v);
			continue;
		}

		// stack address
		if (!strcmp(t, STR(F_SP))) {
			hdr.sp = (u16)num(v);
			printf("SP:\t\t#%04X\n", hdr.sp);
			continue;
		}

		// resident address
		if (!strcmp(t, STR(F_RES))) {
			hdr.resid = (u16)num(v);
			printf("Resident at:\t#%04X\n", hdr.resid);
			continue;
		}

		// pager address
		if (!strcmp(t, STR(F_PAGER))) {
			hdr.pager = (u16)num(v);

			if (hdr.pager)
				printf("Pager at:\t#%04X\n", hdr.pager);

			else
				printf("Pager:\t\tNot used\n");

			continue;
		}

		// start address
		if (!strcmp(t, STR(F_START))) {
			hdr.start = (u16)num(v);
			printf("Start:\t\t#%04X\n", hdr.start);
			continue;
		}

		// page3
		if (!strcmp(t, STR(F_PAGE3))) {
			hdr.page3 = (u8)num(v);
			printf("Page #C000:\t#%02X\n", hdr.page3);
			continue;
		}

		// clock
		if (!strcmp(t, STR(F_CLOCK))) {
			hdr.clk = (u8)num(v);
			printf("Clock:\t\t");

			switch (hdr.clk) {
			case 0: {
				printf("3.5");
				break;
			}

			case 1: {
				printf("7");
				break;
			}

			case 2: {
				printf("14");
				break;
			}

			case 3: {
				printf("14+");
				break;
			}
			}

			printf(" MHz\n");
			continue;
		}

		// INT
		if (!strcmp(t, STR(F_INT))) {
			hdr.ei = num(v);
			printf("Interrupts:\t");

			if (hdr.ei)
				printf("EI\n");

			else
				printf("DI\n");

			continue;
		}

		// block
		if (!strcmp(t, STR(F_BLK))) {
			int size;
			int offset = 0;
			sscanf(v, "%[^ ,\t]%*[ ,\t]%[^ ,\t]%*[ ,\t]%s", v1, v2, v);
			a = num(v1);
			b = num(v2);

			if (a & 0x1FF)
				error(ALGN);

			if ((a < 0xC000) || (a > 0xFE00))
				error(ADDR);

			a -= 0xC000;
			printf("Block:\t\tStart: #%04X  Page: #%02X  File: %s\n", a, b, v);
			struct stat st;
			stat(v, &st);
			size = st.st_size;

			if (size < 0) {
				printf("%s: ", v);
				error(FNFD);
			}

			if (size == 0) {
				printf("%s: ", v);
				error(ZERO);
			}

			while (size) {
				int curr_size = min(size, 0x4000 - a);
				strncpy(blk[nblk].fname, v, sizeof(blk[nblk].fname));
				hdr.blk[nblk].addr = a >> 9;
				hdr.blk[nblk].page = b++;
				blk[nblk].offset = offset;
				blk[nblk].size = curr_size;
				a = 0;
				offset += curr_size;
				size -= curr_size;

				if (++nblk == 256)
					goto end_of_ini;
			}

			continue;
		}

		// unknown tag
		printf("%s: ", t);
		error(UNK);
	}

end_of_ini:

	if (!nblk)
		error(0BLK);

	conf.n_blocks = nblk;
	hdr.num_blk = conf.n_blocks;
	hdr.blk[conf.n_blocks - 1].last = 1;
	fclose(f);
}

// Assembly:
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rdi, 0x4d0(%rsp)
movl $0x0, 0xcc(%rsp)
movl $0x0, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
movq 0x4d0(%rsp), %rdi
leaq 0x2709(%rip), %rsi      # 0x50e8
callq 0x21f0
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0x2a1d
leaq 0x2676(%rip), %rdi      # 0x5074
movb $0x0, %al
callq 0x2030
leaq 0x2633(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0x2, %edi
callq 0x2210
jmp 0x2a1f
movq 0xb8(%rsp), %rdi
callq 0x22a0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2a3d
jmp 0x319d
movb $0x0, 0x3d0(%rsp)
movq 0xb8(%rsp), %rdi
leaq 0x3d0(%rsp), %rdx
leaq 0x2d0(%rsp), %rcx
leaq 0x261c(%rip), %rsi      # 0x5080
movb $0x0, %al
callq 0x2310
cmpb $0x0, 0x3d0(%rsp)
jne 0x2a8d
movq 0xb8(%rsp), %rdi
leaq 0x2617(%rip), %rsi      # 0x509b
movb $0x0, %al
callq 0x2310
jmp 0x2a1f
movsbl 0x3d0(%rsp), %eax
cmpl $0x3b, %eax
jne 0x2a9c
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
callq 0x2450
leaq 0x3d0(%rsp), %rdi
leaq 0x25e7(%rip), %rsi      # 0x509f
callq 0x2250
cmpl $0x0, %eax
jne 0x2af6
leaq 0x2d0(%rsp), %rsi
leaq 0x46ff(%rip), %rdi      # 0x71d0
movl $0x20, %edx
callq 0x20c0
leaq 0x2d0(%rsp), %rsi
leaq 0x25ba(%rip), %rdi      # 0x50a4
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x25b0(%rip), %rsi      # 0x50b5
callq 0x2250
cmpl $0x0, %eax
jne 0x2b48
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movw %ax, %cx
leaq 0x46aa(%rip), %rax      # 0x71d0
movw %cx, 0x32(%rax)
leaq 0x469f(%rip), %rax      # 0x71d0
movzwl 0x32(%rax), %esi
leaq 0x257f(%rip), %rdi      # 0x50bb
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x2570(%rip), %rsi      # 0x50c7
callq 0x2250
cmpl $0x0, %eax
jne 0x2b9a
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movw %ax, %cx
leaq 0x4658(%rip), %rax      # 0x71d0
movw %cx, 0x38(%rax)
leaq 0x464d(%rip), %rax      # 0x71d0
movzwl 0x38(%rax), %esi
leaq 0x2542(%rip), %rdi      # 0x50d0
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x253b(%rip), %rsi      # 0x50e4
callq 0x2250
cmpl $0x0, %eax
jne 0x2c0a
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movw %ax, %cx
leaq 0x4606(%rip), %rax      # 0x71d0
movw %cx, 0x36(%rax)
leaq 0x45fb(%rip), %rax      # 0x71d0
cmpw $0x0, 0x36(%rax)
je 0x2bf7
leaq 0x45ed(%rip), %rax      # 0x71d0
movzwl 0x36(%rax), %esi
leaq 0x24fc(%rip), %rdi      # 0x50ea
movb $0x0, %al
callq 0x2030
jmp 0x2c05
leaq 0x24fd(%rip), %rdi      # 0x50fb
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x24f4(%rip), %rsi      # 0x510d
callq 0x2250
cmpl $0x0, %eax
jne 0x2c5c
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movw %ax, %cx
leaq 0x4596(%rip), %rax      # 0x71d0
movw %cx, 0x30(%rax)
leaq 0x458b(%rip), %rax      # 0x71d0
movzwl 0x30(%rax), %esi
leaq 0x24c3(%rip), %rdi      # 0x5113
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x24b7(%rip), %rsi      # 0x5122
callq 0x2250
cmpl $0x0, %eax
jne 0x2cac
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movb %al, %cl
leaq 0x4545(%rip), %rax      # 0x71d0
movb %cl, 0x34(%rax)
leaq 0x453b(%rip), %rax      # 0x71d0
movzbl 0x34(%rax), %esi
leaq 0x2488(%rip), %rdi      # 0x5128
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x2480(%rip), %rsi      # 0x513b
callq 0x2250
cmpl $0x0, %eax
jne 0x2d7b
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
movb %al, %dl
leaq 0x44f1(%rip), %rax      # 0x71d0
movq %rax, 0x8(%rsp)
movb 0x35(%rax), %cl
andb $0x3, %dl
andb $-0x4, %cl
orb %dl, %cl
movb %cl, 0x35(%rax)
leaq 0x2448(%rip), %rdi      # 0x5141
xorl %eax, %eax
callq 0x2030
movq 0x8(%rsp), %rax
movzbl 0x35(%rax), %eax
andl $0x3, %eax
movq %rax, 0x10(%rsp)
subb $0x3, %al
ja 0x2d68
movq 0x10(%rsp), %rax
leaq 0x22e3(%rip), %rcx      # 0x5004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2419(%rip), %rdi      # 0x514a
movb $0x0, %al
callq 0x2030
jmp 0x2d68
leaq 0x240d(%rip), %rdi      # 0x514e
movb $0x0, %al
callq 0x2030
jmp 0x2d68
leaq 0x23ff(%rip), %rdi      # 0x5150
movb $0x0, %al
callq 0x2030
jmp 0x2d68
leaq 0x23f2(%rip), %rdi      # 0x5153
movb $0x0, %al
callq 0x2030
leaq 0x23e8(%rip), %rdi      # 0x5157
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x23d3(%rip), %rsi      # 0x515d
callq 0x2250
cmpl $0x0, %eax
jne 0x2e03
leaq 0x2d0(%rsp), %rdi
callq 0x28e0
leaq 0x4428(%rip), %rcx      # 0x71d0
movb 0x35(%rcx), %cl
andb $0x1, %al
shlb $0x2, %al
andb $-0x5, %cl
orb %al, %cl
leaq 0x4414(%rip), %rax      # 0x71d0
movb %cl, 0x35(%rax)
leaq 0x239b(%rip), %rdi      # 0x5161
movb $0x0, %al
callq 0x2030
leaq 0x43fc(%rip), %rax      # 0x71d0
movb 0x35(%rax), %al
shrb $0x2, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2df0
leaq 0x2387(%rip), %rdi      # 0x516e
movb $0x0, %al
callq 0x2030
jmp 0x2dfe
leaq 0x237b(%rip), %rdi      # 0x5172
movb $0x0, %al
callq 0x2030
jmp 0x2a1f
leaq 0x3d0(%rsp), %rdi
leaq 0x2364(%rip), %rsi      # 0x5176
callq 0x2250
cmpl $0x0, %eax
jne 0x3161
movl $0x0, 0xb0(%rsp)
leaq 0x2d0(%rsp), %rdi
leaq 0x1d0(%rsp), %rdx
leaq 0xd0(%rsp), %rcx
leaq 0x2d0(%rsp), %r8
leaq 0x232a(%rip), %rsi      # 0x517c
movb $0x0, %al
callq 0x2180
leaq 0x1d0(%rsp), %rdi
callq 0x28e0
movl %eax, 0xcc(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x28e0
movl %eax, 0xc8(%rsp)
movl 0xcc(%rsp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
cmpl $0x0, %eax
je 0x2eb8
leaq 0x2302(%rip), %rdi      # 0x519b
movb $0x0, %al
callq 0x2030
leaq 0x2198(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0x4, %edi
callq 0x2210
cmpl $0xc000, 0xcc(%rsp) # imm = 0xC000
jl 0x2ed2
cmpl $0xfe00, 0xcc(%rsp) # imm = 0xFE00
jle 0x2ef8
leaq 0x22e7(%rip), %rdi      # 0x51c0
movb $0x0, %al
callq 0x2030
leaq 0x2158(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0xd, %edi
callq 0x2210
movl 0xcc(%rsp), %eax
subl $0xc000, %eax           # imm = 0xC000
movl %eax, 0xcc(%rsp)
movl 0xcc(%rsp), %esi
movl 0xc8(%rsp), %edx
leaq 0x2d0(%rsp), %rcx
leaq 0x22c2(%rip), %rdi      # 0x51ea
movb $0x0, %al
callq 0x2030
leaq 0x2d0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2160
movq 0x50(%rsp), %rax
movl %eax, 0xb4(%rsp)
cmpl $0x0, 0xb4(%rsp)
jge 0x2f93
leaq 0x2d0(%rsp), %rsi
leaq 0x22b1(%rip), %rdi      # 0x5217
movb $0x0, %al
callq 0x2030
leaq 0x22a8(%rip), %rdi      # 0x521c
movb $0x0, %al
callq 0x2030
leaq 0x20bd(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0x5, %edi
callq 0x2210
cmpl $0x0, 0xb4(%rsp)
jne 0x2fd9
leaq 0x2d0(%rsp), %rsi
leaq 0x226b(%rip), %rdi      # 0x5217
movb $0x0, %al
callq 0x2030
leaq 0x2272(%rip), %rdi      # 0x522c
movb $0x0, %al
callq 0x2030
leaq 0x2077(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0xa, %edi
callq 0x2210
jmp 0x2fdb
cmpl $0x0, 0xb4(%rsp)
je 0x315c
movl 0xb4(%rsp), %eax
movl $0x4000, %ecx           # imm = 0x4000
subl 0xcc(%rsp), %ecx
cmpl %ecx, %eax
jge 0x300d
movl 0xb4(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x301d
movl $0x4000, %eax           # imm = 0x4000
subl 0xcc(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x1c(%rsp)
movslq 0xc4(%rsp), %rax
leaq 0x459c(%rip), %rdi      # 0x75d0
imulq $0x4408, %rax, %rax     # imm = 0x4408
addq %rax, %rdi
leaq 0x2d0(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x20c0
movl 0xcc(%rsp), %eax
sarl $0x9, %eax
movb %al, %cl
movslq 0xc4(%rsp), %rdx
leaq 0x4165(%rip), %rax      # 0x71d0
addq $0x100, %rax            # imm = 0x100
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movzbl %cl, %ecx
movw %cx, %dx
movw (%rax), %cx
andw $0x1f, %dx
andw $-0x20, %cx
orw %dx, %cx
movw %cx, (%rax)
movl 0xc8(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc8(%rsp)
movb %al, %cl
movslq 0xc4(%rsp), %rdx
leaq 0x411d(%rip), %rax      # 0x71d0
addq $0x100, %rax            # imm = 0x100
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x2(%rax)
movl 0xb0(%rsp), %ecx
movslq 0xc4(%rsp), %rdx
leaq 0x44f7(%rip), %rax      # 0x75d0
imulq $0x4408, %rdx, %rdx     # imm = 0x4408
addq %rdx, %rax
movl %ecx, 0x400(%rax)
movl 0x1c(%rsp), %ecx
movslq 0xc4(%rsp), %rdx
leaq 0x44d4(%rip), %rax      # 0x75d0
imulq $0x4408, %rdx, %rdx     # imm = 0x4408
addq %rdx, %rax
movl %ecx, 0x404(%rax)
movl $0x0, 0xcc(%rsp)
movl 0x1c(%rsp), %eax
addl 0xb0(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl 0x1c(%rsp), %ecx
movl 0xb4(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xb4(%rsp)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
cmpl $0x100, %eax            # imm = 0x100
jne 0x3157
jmp 0x319f
jmp 0x2fdb
jmp 0x2a1f
leaq 0x3d0(%rsp), %rsi
leaq 0x20a7(%rip), %rdi      # 0x5217
movb $0x0, %al
callq 0x2030
leaq 0x20c2(%rip), %rdi      # 0x5240
movb $0x0, %al
callq 0x2030
leaq 0x1eb3(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0x3, %edi
callq 0x2210
jmp 0x319f
cmpl $0x0, 0xc4(%rsp)
jne 0x31cf
leaq 0x209d(%rip), %rdi      # 0x524d
movb $0x0, %al
callq 0x2030
leaq 0x1e81(%rip), %rdi      # 0x503f
movb $0x0, %al
callq 0x2030
movl $0x8, %edi
callq 0x2210
movl 0xc4(%rsp), %ecx
leaq 0x444bf3(%rip), %rax    # 0x447dd0
movl %ecx, 0x18(%rax)
leaq 0x444be9(%rip), %rax    # 0x447dd0
movl 0x18(%rax), %eax
movw %ax, %cx
leaq 0x3fdc(%rip), %rax      # 0x71d0
movw %cx, 0x3a(%rax)
leaq 0x444bd1(%rip), %rax    # 0x447dd0
movl 0x18(%rax), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x3fc1(%rip), %rax      # 0x71d0
addq $0x100, %rax            # imm = 0x100
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movw (%rax), %cx
andw $0xff7f, %cx            # imm = 0xFF7F
orw $0x80, %cx
movw %cx, (%rax)
movq 0xb8(%rsp), %rdi
callq 0x2190
addq $0x4d8, %rsp            # imm = 0x4D8
retq
nopw %cs:(%rax,%rax)