// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/src/bstub.c
// Function: ExtInit
int ExtInit(void)
{
	int i, rv = 0;
	unsigned char remapbuf[256];

	buildputs("Tekwar BUILD V1.2\n\n");

#if defined(DATADIR)
    {
        const char *datadir = DATADIR;
        if (datadir && datadir[0]) {
            addsearchpath(datadir);
        }
    }
#endif

     {
          char *supportdir = Bgetsupportdir(1);
          char *appdir = Bgetappdir();
          char dirpath[BMAX_PATH+1];

          // the OSX app bundle, or on Windows the directory where the EXE was launched
          if (appdir) {
               addsearchpath(appdir);
               free(appdir);
          }

          // the global support files directory
          if (supportdir) {
               Bsnprintf(dirpath, sizeof(dirpath), "%s/JFTekWar", supportdir);
               addsearchpath(dirpath);
               free(supportdir);
          }
     }

     // default behaviour is to write to the user profile directory, but
     // creating a 'user_profiles_disabled' file in the current working
     // directory where the game was launched makes the installation
     // "portable" by writing into the working directory
     if (access("user_profiles_disabled", F_OK) == 0) {
          char cwd[BMAX_PATH+1];
          if (getcwd(cwd, sizeof(cwd))) {
               addsearchpath(cwd);
          }
     } else {
          char *supportdir;
          char dirpath[BMAX_PATH+1];
          int asperr;

          if ((supportdir = Bgetsupportdir(0))) {
#if defined(_WIN32) || defined(__APPLE__)
               const char *confdir = "JFTekWar";
#else
               const char *confdir = ".jftekwar";
#endif
               Bsnprintf(dirpath, sizeof(dirpath), "%s/%s", supportdir, confdir);
               asperr = addsearchpath(dirpath);
               if (asperr == -2) {
                    if (Bmkdir(dirpath, S_IRWXU) == 0) {
                         asperr = addsearchpath(dirpath);
                    } else {
                         asperr = -1;
                    }
               }
               if (asperr == 0) {
                    chdir(dirpath);
               }
               free(supportdir);
          }
     }

	initgroupfile("stuff.dat");
	bpp = 8;
	if (loadsetup("build.cfg") < 0) buildputs("Configuration file not found, using defaults.\n"), rv = 1;
	memcpy((void *)buildkeys,(void *)keys,sizeof(buildkeys));   //Trick to make build use setup.dat keys
	if (option[4] > 0) option[4] = 0;
	if (initengine()) {
		wm_msgbox("Build Engine Initialisation Error",
				"There was a problem initialising the Build engine: %s", engineerrstr);
		return -1;
	}

		//You can load your own palette lookup tables here if you just
		//copy the right code!
	for(i=0;i<256;i++)
		remapbuf[i] = ((i+32)&255);  //remap colors for screwy palette sectors
	makepalookup(16,remapbuf,0,0,0,1);

	kensplayerheight = 34;
	zmode = 0;
	defaultspritecstat = 0;

    parallaxtype=2;
    parallaxyoffs=112;
    pskyoff[0]=0;   
    pskyoff[1]=1;   
    pskyoff[2]=2; 
    pskyoff[3]=3;   
    pskybits=2;     // 4 tiles
    memset(&recXT, 0, sizeof(struct spriteextension));
    recordXT=-1;

    ExtDeleteSprite = DeleteSprite;

	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd60, %rsp            # imm = 0xD60
movl $0x0, -0xc(%rbp)
leaq 0xa508b(%rip), %rdi     # 0xafc04
callq 0x4a720
leaq 0xa5093(%rip), %rax     # 0xafc18
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
je 0xabb1
movq -0x118(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xabb1
movq -0x118(%rbp), %rdi
callq 0x2f0b0
movl $0x1, %edi
callq 0x328a0
movq %rax, -0x120(%rbp)
callq 0x327e0
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0xabf0
movq -0x128(%rbp), %rdi
callq 0x2f0b0
movq -0x128(%rbp), %rdi
callq 0x61c0
cmpq $0x0, -0x120(%rbp)
je 0xac33
leaq -0x530(%rbp), %rdi
movq -0x120(%rbp), %rcx
movl $0x401, %esi            # imm = 0x401
leaq 0xa5024(%rip), %rdx     # 0xafc38
movb $0x0, %al
callq 0x6490
leaq -0x530(%rbp), %rdi
callq 0x2f0b0
movq -0x120(%rbp), %rdi
callq 0x61c0
leaq 0xa500a(%rip), %rdi     # 0xafc44
xorl %esi, %esi
callq 0x6150
cmpl $0x0, %eax
jne 0xac6e
leaq -0x940(%rbp), %rdi
movl $0x401, %esi            # imm = 0x401
callq 0x6390
cmpq $0x0, %rax
je 0xac69
leaq -0x940(%rbp), %rdi
callq 0x2f0b0
jmp 0xad30
xorl %edi, %edi
callq 0x328a0
movq %rax, -0x948(%rbp)
cmpq $0x0, %rax
je 0xad2e
leaq 0xa4fce(%rip), %rax     # 0xafc5b
movq %rax, -0xd60(%rbp)
leaq -0xd50(%rbp), %rdi
movq -0x948(%rbp), %rcx
movq -0xd60(%rbp), %r8
movl $0x401, %esi            # imm = 0x401
leaq 0xa4fb0(%rip), %rdx     # 0xafc65
movb $0x0, %al
callq 0x6490
leaq -0xd50(%rbp), %rdi
callq 0x2f0b0
movl %eax, -0xd54(%rbp)
cmpl $-0x2, -0xd54(%rbp)
jne 0xad0d
leaq -0xd50(%rbp), %rdi
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x6280
cmpl $0x0, %eax
jne 0xad01
leaq -0xd50(%rbp), %rdi
callq 0x2f0b0
movl %eax, -0xd54(%rbp)
jmp 0xad0b
movl $0xffffffff, -0xd54(%rbp) # imm = 0xFFFFFFFF
jmp 0xad0d
cmpl $0x0, -0xd54(%rbp)
jne 0xad22
leaq -0xd50(%rbp), %rdi
callq 0x6bd0
movq -0x948(%rbp), %rdi
callq 0x61c0
jmp 0xad30
leaq 0xa4f34(%rip), %rdi     # 0xafc6b
callq 0x2f720
leaq 0x1afec1(%rip), %rax    # 0x1bac04
movl $0x8, (%rax)
leaq 0xa4f25(%rip), %rdi     # 0xafc75
callq 0x2c390
cmpl $0x0, %eax
jge 0xad6d
leaq 0xa4f1e(%rip), %rdi     # 0xafc7f
callq 0x4a720
movl $0x1, -0xc(%rbp)
leaq 0xd51ac(%rip), %rdi     # 0xdff20
leaq 0xc48e5(%rip), %rsi     # 0xcf660
movl $0x50, %edx
callq 0x60c0
movzbl 0xc48c8(%rip), %eax     # 0xcf654
cmpl $0x0, %eax
jle 0xad98
movb $0x0, 0xc48bc(%rip)     # 0xcf654
callq 0x37e10
cmpl $0x0, %eax
je 0xadcd
leaq 0x1ea7d7(%rip), %rax    # 0x1f5580
movq (%rax), %rdx
leaq 0xa4efb(%rip), %rdi     # 0xafcae
leaq 0xa4f16(%rip), %rsi     # 0xafcd0
movb $0x0, %al
callq 0xa4450
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xaecf
movl $0x0, -0x8(%rbp)
cmpl $0x100, -0x8(%rbp)      # imm = 0x100
jge 0xae00
movl -0x8(%rbp), %eax
addl $0x20, %eax
andl $0xff, %eax
movb %al, %cl
movslq -0x8(%rbp), %rax
movb %cl, -0x110(%rbp,%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xadd4
leaq -0x110(%rbp), %rsi
movl $0x10, %edi
xorl %r8d, %r8d
movl $0x1, %r9d
movl %r8d, %edx
movl %r8d, %ecx
callq 0x57660
leaq 0xd516d(%rip), %rax     # 0xdff94
movl $0x22, (%rax)
leaq 0x15f24c(%rip), %rax    # 0x16a080
movl $0x0, (%rax)
leaq 0x15f243(%rip), %rax    # 0x16a084
movw $0x0, (%rax)
leaq 0x38f7d5(%rip), %rax    # 0x39a622
movb $0x2, (%rax)
leaq 0x38f7cd(%rip), %rax    # 0x39a624
movl $0x70, (%rax)
leaq 0x38f5bc(%rip), %rax    # 0x39a420
movw $0x0, (%rax)
leaq 0x38f5b0(%rip), %rax    # 0x39a420
movw $0x1, 0x2(%rax)
leaq 0x38f5a3(%rip), %rax    # 0x39a420
movw $0x2, 0x4(%rax)
leaq 0x38f596(%rip), %rax    # 0x39a420
movw $0x3, 0x6(%rax)
leaq 0x38f789(%rip), %rax    # 0x39a620
movw $0x2, (%rax)
leaq 0xd708d(%rip), %rdi     # 0xe1f30
xorl %esi, %esi
movl $0x22, %edx
callq 0x62d0
movw $0xffff, 0xc4800(%rip)  # imm = 0xFFFF
leaq 0x16ee41(%rip), %rax    # 0x179d00
leaq 0x1a(%rip), %rcx        # 0xaee0
movq %rcx, (%rax)
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd60, %rsp            # imm = 0xD60
popq %rbp
retq
nopl (%rax,%rax)