// File: /workspace/github_c_makefile_star2_O0/Edilbert[P]BS9/bs9.c
// Function: ParseLoadData
char *ParseLoadData(char *p)
{
   int Start,Size,Advance;
   char *Filename,*EndPtr;
   FILE *lp;

   p = SkipSpace(p);

   Advance = 1;
   if (*p == '\"') Start = pc;
   else
   {
      Advance = 0;
      p = EvalOperand(p,&Start,0);

      if (Start < 0 || Start > 0xffff)
      {
         ErrorMsg("Illegal start address for LOAD %d\n",Start);
         exit(1);
      }
      p = NeedChar(p,',');
      if (!p)
      {
         ErrorMsg("Missing ',' after start address\n");
         exit(1);
      }
      p = NeedChar(p+1,'"');
      if (!p)
      {
         ErrorMsg("Missing quote for filename\n");
         exit(1);
      }
   }
   EndPtr = ++p;
   while (*EndPtr != '\0' && *EndPtr != '"') ++EndPtr;
   Filename = (char *)StrNDup(p, EndPtr - p);
   if (df) fprintf(df,"Loading %4.4x <%s>\n",Start,Filename);
   PrintLine();
   lp = fopen(Filename,"rb");
   AssertFileOp(lp,"Could not LOAD <%s>\n");
   fseek(lp,0,SEEK_END);
   Size = ftell(lp);
   rewind(lp);
   if (Start + Size > 0x10000)
   {
      ErrorMsg("LOADING %4.4x to %4.4x violates 64K size\n",
         Start,Start+Size);
      exit(1);
   }

   if (!Pass) fread(ROM+Start,Size,1,lp);
   fclose(lp);
   if (Advance) pc += Size;
   p += strlen(p);
   return p;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0x2830
movq %rax, 0x30(%rsp)
movl $0x1, 0x24(%rsp)
movq 0x30(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x73ec
movl 0x10331(%rip), %eax     # 0x17714
movl %eax, 0x2c(%rsp)
jmp 0x74a5
movl $0x0, 0x24(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
xorl %edx, %edx
callq 0x4740
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x2c(%rsp)
jl 0x741b
cmpl $0xffff, 0x2c(%rsp)     # imm = 0xFFFF
jle 0x7437
movl 0x2c(%rsp), %esi
leaq 0x93e8(%rip), %rdi      # 0x1080e
movb $0x0, %al
callq 0x3150
movl $0x1, %edi
callq 0x22b0
movq 0x30(%rsp), %rdi
movl $0x2c, %esi
callq 0x36a0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x746b
leaq 0x927a(%rip), %rdi      # 0x106d4
movb $0x0, %al
callq 0x3150
movl $0x1, %edi
callq 0x22b0
movq 0x30(%rsp), %rdi
addq $0x1, %rdi
movl $0x22, %esi
callq 0x36a0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x74a3
leaq 0x929a(%rip), %rdi      # 0x1072c
movb $0x0, %al
callq 0x3150
movl $0x1, %edi
callq 0x22b0
jmp 0x74a5
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x7(%rsp)
je 0x74dd
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x74e7
jmp 0x74f7
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x74b8
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rcx, %rax
movl %eax, %esi
callq 0x26b0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x214d3(%rip)     # 0x289f0
je 0x753d
movq 0x214ca(%rip), %rdi     # 0x289f0
movl 0x2c(%rsp), %edx
movq 0x18(%rsp), %rcx
leaq 0x92fb(%rip), %rsi      # 0x10831
movb $0x0, %al
callq 0x21e0
callq 0x34c0
movq 0x18(%rsp), %rdi
leaq 0x92f7(%rip), %rsi      # 0x10845
callq 0x2270
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x92e4(%rip), %rsi      # 0x10848
callq 0x2670
movq 0x8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x2230
movq 0x8(%rsp), %rdi
callq 0x21f0
movl %eax, 0x28(%rsp)
movq 0x8(%rsp), %rdi
callq 0x2120
movl 0x2c(%rsp), %eax
addl 0x28(%rsp), %eax
cmpl $0x10000, %eax          # imm = 0x10000
jle 0x75c7
movl 0x2c(%rsp), %esi
movl 0x2c(%rsp), %edx
addl 0x28(%rsp), %edx
leaq 0x92a7(%rip), %rdi      # 0x1085d
movb $0x0, %al
callq 0x3150
movl $0x1, %edi
callq 0x22b0
cmpl $0x0, 0x2142a(%rip)     # 0x289f8
jne 0x75f3
movslq 0x2c(%rsp), %rax
leaq 0x10654(%rip), %rdi     # 0x17c30
addq %rax, %rdi
movslq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rcx
movl $0x1, %edx
callq 0x20b0
movq 0x8(%rsp), %rdi
callq 0x20e0
cmpl $0x0, 0x24(%rsp)
je 0x7614
movl 0x28(%rsp), %eax
addl 0x10106(%rip), %eax     # 0x17714
movl %eax, 0x10100(%rip)     # 0x17714
movq 0x30(%rsp), %rdi
callq 0x20f0
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)