// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
leaq 0x1acb(%rip), %rsi      # 0x40e7
callq 0x2130
testq %rax, %rax
je 0x2b69
movq %rax, %r15
movq %rax, %rdi
callq 0x21e0
movl $0x0, 0x4(%rsp)
testl %eax, %eax
je 0x268d
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
je 0x2b8d
leaq 0x44470c(%rip), %rax    # 0x446d60
movl %ecx, 0x18(%rax)
leaq 0x3b02(%rip), %rax      # 0x6160
movw %cx, 0x3a(%rax)
decl %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
orb $-0x80, 0x100(%rax,%rcx)
movq %r15, %rdi
callq 0x2100
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21(%rsp), %r14
leaq 0x19e6(%rip), %r12      # 0x407f
leaq 0x20(%rsp), %r13
leaq 0x120(%rsp), %rbp
movl $0x0, 0x4(%rsp)
movb $0x0, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2230
movzbl 0x20(%rsp), %eax
testl %eax, %eax
je 0x26f5
cmpl $0x3b, %eax
je 0x28e9
movb 0x20(%rsp), %al
movq %r14, %rbx
testb %al, %al
je 0x270b
movsbl %al, %edi
callq 0x21b0
movb %al, -0x1(%rbx)
movb (%rbx), %al
incq %rbx
jmp 0x26df
movq %r15, %rdi
leaq 0x199b(%rip), %rsi      # 0x409a
xorl %eax, %eax
callq 0x2230
jmp 0x28e9
movl 0x20(%rsp), %eax
movl $0x63736564, %ecx       # imm = 0x63736564
xorl %ecx, %eax
movzbl 0x24(%rsp), %ecx
orl %eax, %ecx
je 0x281b
movl 0x20(%rsp), %eax
movl $0x63617473, %ecx       # imm = 0x63617473
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
je 0x2845
movq 0x20(%rsp), %rax
movabsq $0x746e656469736572, %rcx # imm = 0x746E656469736572
xorq %rcx, %rax
movzbl 0x28(%rsp), %ecx
orq %rax, %rcx
je 0x2864
movl 0x20(%rsp), %eax
movl $0x65676170, %ecx       # imm = 0x65676170
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x72, %ecx
orl %eax, %ecx
je 0x2883
movl 0x20(%rsp), %eax
movl $0x72617473, %ecx       # imm = 0x72617473
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x74, %ecx
orl %eax, %ecx
je 0x28a7
movl 0x20(%rsp), %eax
movl $0x65676170, %ecx       # imm = 0x65676170
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x33, %ecx
orl %eax, %ecx
je 0x28c6
movl 0x20(%rsp), %eax
movl $0x636f6c63, %ecx       # imm = 0x636F6C63
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
je 0x290a
cmpl $0x746e69, 0x20(%rsp)   # imm = 0x746E69
jne 0x2957
movq %rbp, %rdi
callq 0x25cb
leaq 0x3979(%rip), %rbx      # 0x6160
movb 0x35(%rbx), %cl
shlb $0x2, %al
andb $0x4, %al
andb $-0x5, %cl
orb %al, %cl
movb %cl, 0x35(%rbx)
leaq 0x1944(%rip), %rdi      # 0x4142
xorl %eax, %eax
callq 0x2030
testb $0x4, 0x35(%rbx)
jne 0x2b2c
leaq 0x1b81(%rip), %rdi      # 0x4397
jmp 0x2b5f
movl $0x20, %edx
leaq 0x3939(%rip), %rdi      # 0x6160
movq %rbp, %rsi
callq 0x2060
leaq 0x186d(%rip), %rdi      # 0x40a3
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2030
jmp 0x28e9
movq %rbp, %rdi
callq 0x25cb
leaq 0x390c(%rip), %rcx      # 0x6160
movw %ax, 0x32(%rcx)
movzwl %ax, %esi
leaq 0x1858(%rip), %rdi      # 0x40ba
jmp 0x28e2
movq %rbp, %rdi
callq 0x25cb
leaq 0x38ed(%rip), %rcx      # 0x6160
movw %ax, 0x38(%rcx)
movzwl %ax, %esi
leaq 0x184e(%rip), %rdi      # 0x40cf
jmp 0x28e2
movq %rbp, %rdi
callq 0x25cb
leaq 0x38ce(%rip), %rcx      # 0x6160
movw %ax, 0x36(%rcx)
testw %ax, %ax
je 0x28fe
movzwl %ax, %esi
leaq 0x1844(%rip), %rdi      # 0x40e9
jmp 0x28e2
movq %rbp, %rdi
callq 0x25cb
leaq 0x38aa(%rip), %rcx      # 0x6160
movw %ax, 0x30(%rcx)
movzwl %ax, %esi
leaq 0x183c(%rip), %rdi      # 0x4100
jmp 0x28e2
movq %rbp, %rdi
callq 0x25cb
leaq 0x388b(%rip), %rcx      # 0x6160
movb %al, 0x34(%rcx)
movzbl %al, %esi
leaq 0x1833(%rip), %rdi      # 0x4115
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x21e0
testl %eax, %eax
je 0x26ae
jmp 0x2641
leaq 0x1a7c(%rip), %rdi      # 0x4381
jmp 0x2b5f
movq %rbp, %rdi
callq 0x25cb
leaq 0x3847(%rip), %rbx      # 0x6160
movb 0x35(%rbx), %cl
andb $0x3, %al
andb $-0x4, %cl
orb %al, %cl
movb %cl, 0x35(%rbx)
leaq 0x1801(%rip), %rdi      # 0x412e
xorl %eax, %eax
callq 0x2030
movzbl 0x35(%rbx), %eax
andl $0x3, %eax
leaq 0x16c2(%rip), %rcx      # 0x4004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x17e5(%rip), %rdi      # 0x4137
jmp 0x2b45
movl 0x20(%rsp), %eax
movl $0x636f6c62, %ecx       # imm = 0x636F6C62
xorl %ecx, %eax
movzwl 0x24(%rsp), %ecx
xorl $0x6b, %ecx
orl %eax, %ecx
jne 0x2bb1
movq %rbp, %rdi
leaq 0x17d9(%rip), %rsi      # 0x4155
leaq 0x3b0(%rsp), %rbx
movq %rbx, %rdx
leaq 0x2b0(%rsp), %r12
movq %r12, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x20f0
movq %rbx, %rdi
callq 0x25cb
movq %rax, %r14
movq %r12, %rdi
callq 0x25cb
testl $0x1ff, %r14d           # imm = 0x1FF
jne 0x2be8
movq %rax, %r12
movq %r14, %rax
addq $-0xfe01, %rax          # imm = 0xFFFF01FF
cmpq $-0x3e02, %rax          # imm = 0xC1FE
jbe 0x2c80
leal -0xc000(%r14), %ebp
leaq 0x17e1(%rip), %rdi      # 0x41c3
movl %ebp, %esi
movl %r12d, %edx
leaq 0x120(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
leaq 0x220(%rsp), %rsi
callq 0x20c0
movl 0x250(%rsp), %eax
testl %eax, %eax
js 0x2c46
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movl 0x4(%rsp), %esi
je 0x2c0c
movslq %esi, %rdi
imulq $0x4408, %rdi, %r14     # imm = 0x4408
addq 0x35a3(%rip), %r14      # 0x5fe0
leaq (%rdi,%rdi,2), %rcx
leaq 0x3718(%rip), %rdx      # 0x6160
leaq (%rdx,%rcx), %r15
addq $0x100, %r15            # imm = 0x100
incq %rdi
xorl %ebx, %ebx
movl %eax, %r13d
testl %eax, %eax
movl %esi, 0x4(%rsp)
je 0x2b00
movl $0x4000, %r12d          # imm = 0x4000
subl %ebp, %r12d
cmpl %r12d, %r13d
cmovll %r13d, %r12d
movl $0x400, %edx            # imm = 0x400
movq %rdi, 0x18(%rsp)
movq %r14, %rdi
leaq 0x120(%rsp), %rsi
callq 0x2060
movl 0x4(%rsp), %esi
shrl $0x9, %ebp
movzwl (%r15), %eax
andl $0x1f, %ebp
andl $-0x20, %eax
orl %ebp, %eax
movw %ax, (%r15)
movq 0x8(%rsp), %rdx
movb %dl, 0x2(%r15)
movl %ebx, 0x400(%r14)
movl %r12d, 0x404(%r14)
addl %r12d, %ebx
movl %r13d, %eax
subl %r12d, %eax
incl %esi
addq $0x4408, %r14           # imm = 0x4408
addq $0x3, %r15
movq 0x18(%rsp), %rdi
movq %rdi, %rcx
incq %rcx
incb %dl
movq %rdx, 0x8(%rsp)
xorl %ebp, %ebp
cmpl $0x100, %edi            # imm = 0x100
movq %rcx, %rdi
jne 0x2a58
movl $0x100, 0x4(%rsp)       # imm = 0x100
testl %r13d, %r13d
movq 0x10(%rsp), %r15
leaq 0x21(%rsp), %r14
leaq 0x156b(%rip), %r12      # 0x407f
leaq 0x20(%rsp), %r13
leaq 0x120(%rsp), %rbp
je 0x28e9
jmp 0x2641
leaq 0x1867(%rip), %rdi      # 0x439a
jmp 0x2b5f
leaq 0x15ff(%rip), %rdi      # 0x413b
jmp 0x2b45
leaq 0x15f9(%rip), %rdi      # 0x413e
xorl %eax, %eax
callq 0x2030
jmp 0x2b58
movl $0x37, %edi
callq 0x2180
leaq 0x1833(%rip), %rdi      # 0x4392
callq 0x21d0
jmp 0x28e9
leaq 0x1503(%rip), %rdi      # 0x4073
xorl %eax, %eax
callq 0x2030
leaq 0x1752(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x2, %edi
callq 0x2150
leaq 0x1692(%rip), %rdi      # 0x4226
xorl %eax, %eax
callq 0x2030
leaq 0x172e(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x8, %edi
callq 0x2150
leaq 0x1638(%rip), %rdi      # 0x41f0
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x164e(%rip), %rdi      # 0x4219
xorl %eax, %eax
callq 0x2030
leaq 0x16f7(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x3, %edi
callq 0x2150
leaq 0x1585(%rip), %rdi      # 0x4174
xorl %eax, %eax
callq 0x2030
leaq 0x16d3(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x4, %edi
callq 0x2150
leaq 0x15dd(%rip), %rdi      # 0x41f0
leaq 0x120(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x15dc(%rip), %rdi      # 0x4205
xorl %eax, %eax
callq 0x2030
leaq 0x1699(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0xa, %edi
callq 0x2150
leaq 0x15a3(%rip), %rdi      # 0x41f0
leaq 0x120(%rsp), %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x1592(%rip), %rdi      # 0x41f5
xorl %eax, %eax
callq 0x2030
leaq 0x165f(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0x5, %edi
callq 0x2150
leaq 0x1512(%rip), %rdi      # 0x4199
xorl %eax, %eax
callq 0x2030
leaq 0x163b(%rip), %rdi      # 0x42d0
callq 0x21d0
movl $0xd, %edi
callq 0x2150