// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
callq 0x2675
movq %rax, %rbx
movb (%rax), %bpl
cmpb $0x22, %bpl
jne 0x4f0d
movl 0xe82e(%rip), %r14d     # 0x13734
movl %r14d, 0xc(%rsp)
jmp 0x4f5d
leaq 0xc(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x37d5
movl (%r14), %r14d
cmpl $0x10000, %r14d         # imm = 0x10000
jae 0x5055
pushq $0x2c
popq %rsi
movq %rax, %rdi
callq 0x2f15
testq %rax, %rax
je 0x5068
incq %rax
pushq $0x22
popq %rsi
movq %rax, %rdi
callq 0x2f15
movq %rax, %rbx
testq %rax, %rax
je 0x5071
incq %rbx
xorl %esi, %esi
movzbl (%rbx,%rsi), %eax
testl %eax, %eax
je 0x4f74
cmpl $0x22, %eax
je 0x4f74
incq %rsi
jmp 0x4f62
movq %rbx, %rdi
callq 0x258f
movq %rax, %r15
movq 0x1fa8a(%rip), %rdi     # 0x24a10
testq %rdi, %rdi
je 0x4f9f
leaq 0x6932(%rip), %rsi      # 0xb8c4
movl %r14d, %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2210
callq 0x2d99
leaq 0x692d(%rip), %rsi      # 0xb8d8
movq %r15, %rdi
callq 0x22b0
movq %rax, %r15
leaq 0x691e(%rip), %rsi      # 0xb8db
movq %rax, %rdi
callq 0x2575
pushq $0x2
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2270
movq %r15, %rdi
callq 0x2220
movq %rax, %r12
movq %r15, %rdi
callq 0x2140
leal (%r14,%r12), %edx
cmpl $0x10001, %edx          # imm = 0x10001
jge 0x5042
cmpl $0x0, 0x1fa20(%rip)     # 0x24a18
jne 0x5015
movslq %r14d, %rax
leaq 0xec4c(%rip), %rdi      # 0x13c50
addq %rax, %rdi
movslq %r12d, %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x20d0
movq %r15, %rdi
callq 0x2100
cmpb $0x22, %bpl
jne 0x502a
addl %r12d, 0xe70a(%rip)     # 0x13734
movq %rbx, %rdi
callq 0x2110
addq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68a7(%rip), %rdi      # 0xb8f0
movl %r14d, %esi
xorl %eax, %eax
callq 0x2af7
jmp 0x507f
leaq 0x6845(%rip), %rdi      # 0xb8a1
movl %r14d, %esi
xorl %eax, %eax
callq 0x2af7
jmp 0x507f
leaq 0x66f8(%rip), %rdi      # 0xb767
jmp 0x5078
leaq 0x6747(%rip), %rdi      # 0xb7bf
xorl %eax, %eax
callq 0x2af7
pushq $0x1
popq %rdi
callq 0x22f0