// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/extracters/ckabstape/ckabstape.c
// Function: main
int main(int argc, char **argv)
{
	int totalblks = 0;
	int badblks = 0;
	unsigned int currentwd = 0;
	int bytecnt = 0;	
	int col = 0;
	int framecount;
	unsigned int cksum;
	unsigned int adr;

        (void) argc;
        (void) argv;

	/*
	 *  read 3 chars and pack them in a word 
	 */
        do {
	     currentwd = readframe();
	     printf("%010o ", currentwd);
	     printf("%c %c %c ",sixbit((currentwd & 0770000) >>12),
                                 sixbit((currentwd & 007700) >>6),
			         sixbit(currentwd & 077) );
	     col++;
	     if(col == 4){
	      printf("\n");
	      col = 0;
	     }
	     if(currentwd & 00010000000) {
	      printf("\n loader end ----\n");
	     /*
	      * start looking for binary data frames
	      */
	      while(1){
	     /*
	      * frames start at the first 0x80 punched
	      * (check is in readframe..)
	      */

                  adr = readframe() & 0777777;		/*staring adr */
	       cksum = adr;
	       printf("ADR: %010o\n", adr);

	       framecount = readframe() & 0777777;	/* word count */
	       cksum += framecount;
	       framecount = -(0xfffe0000 | framecount); /* sign extend */
	       printf("CNT: %010o (%d)\n", framecount, framecount);

	       if((adr & 0700000) != 0){
	        printf("FRAMECOUNT == 0 START ADR == %06o\n", adr);
		printf("TOTAL BLKS %d TOTAL ERRS %d\n", totalblks, badblks);
	        exit(0);
	       }

	       currentwd = readframe() & 0777777;		/* checksum */
	       cksum += currentwd;
	       printf("CKS: %06o\n", currentwd);
	       /*
		* read all the data words
	        */
	       while(framecount > 0){
	 	currentwd = readframe();
	        cksum += currentwd & 0777777;
		printf("%05o: %06o  ",adr++, currentwd & 0777777);
		disasm(currentwd & 0777777);
	        printf("   ; %c%c%c ",sixbit((currentwd & 0770000) >>12),
                                 sixbit((currentwd & 007700) >>6),
                                 sixbit(currentwd & 077) );
 		printf("\n");
		framecount--;
	       }

	       if(cksum&0777777){
	        printf("****BAD CKSUM**** %06o\n",cksum&0777777);
	        badblks++;
	       }

	       totalblks++;
	      }
	     }
        } while(!feof(stdin));

	if(bytecnt > 0){
	 printf("%d chrs left\n", bytecnt);
	}

        exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xaa9(%rip), %rbx       # 0x24e9
leaq 0xaa9(%rip), %r14       # 0x24f0
pushq $0xa
popq %r15
movq 0x258e(%rip), %r13      # 0x3fe0
xorl %ebp, %ebp
callq 0x11c9
movl %eax, %r12d
movq %rbx, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
movl %r12d, %eax
shrl $0xc, %eax
andl $0x3f, %eax
leaq 0x648(%rip), %rcx       # 0x20c0
movsbl (%rax,%rcx), %esi
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movsbl (%rax,%rcx), %edx
movl %r12d, %eax
andl $0x3f, %eax
movsbl (%rax,%rcx), %ecx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1050
incl %ebp
cmpl $0x4, %ebp
jne 0x1aae
movl %r15d, %edi
callq 0x1030
xorl %ebp, %ebp
btl $0x15, %r12d
jb 0x1ac7
movq (%r13), %rdi
callq 0x1070
testl %eax, %eax
je 0x1a54
jmp 0x1c2a
leaq 0xacc(%rip), %rdi       # 0x259a
callq 0x1040
movl $0x0, (%rsp)
xorl %r14d, %r14d
callq 0x11c9
movl %eax, %r13d
movl %eax, %ebp
andl $0x3ffff, %ebp          # imm = 0x3FFFF
leaq 0xa06(%rip), %rdi       # 0x24fa
movl %ebp, %esi
xorl %eax, %eax
callq 0x1050
callq 0x11c9
movl %eax, %ebx
movl %eax, %r12d
orl $0xfffe0000, %r12d      # imm = 0xFFFE0000
negl %r12d
leaq 0x9ee(%rip), %rdi       # 0x2506
movl %r12d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1050
testl $0x38000, %r13d         # imm = 0x38000
jne 0x1c06
movl %r14d, 0x4(%rsp)
addl %ebp, %ebx
callq 0x11c9
andl $0x3ffff, %eax          # imm = 0x3FFFF
addl %eax, %ebx
leaq 0xa0b(%rip), %rdi       # 0x2557
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
testl %r12d, %r12d
jle 0x1bde
callq 0x11c9
movl %eax, %r13d
movl %eax, %r14d
andl $0x3ffff, %r14d         # imm = 0x3FFFF
addl %r14d, %ebx
leal 0x1(%rbp), %r15d
leaq 0x9e4(%rip), %rdi       # 0x2562
movl %ebp, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x1050
movl %r14d, %edi
callq 0x12ac
movl %r13d, %eax
shrl $0xc, %eax
andl $0x3f, %eax
leaq 0x51e(%rip), %rcx       # 0x20c0
movsbl (%rax,%rcx), %esi
movl %r13d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movsbl (%rax,%rcx), %edx
andl $0x3f, %r13d
movsbl (%r13,%rcx), %ecx
leaq 0x9ab(%rip), %rdi       # 0x256f
xorl %eax, %eax
callq 0x1050
pushq $0xa
popq %rdi
callq 0x1030
decl %r12d
movl %r15d, %ebp
jmp 0x1b55
andl $0x3ffff, %ebx          # imm = 0x3FFFF
movl 0x4(%rsp), %r14d
je 0x1bfe
leaq 0x98a(%rip), %rdi       # 0x257c
movl %ebx, %esi
xorl %eax, %eax
callq 0x1050
incl (%rsp)
incl %r14d
jmp 0x1add
leaq 0x90a(%rip), %rdi       # 0x2517
movl %ebp, %esi
xorl %eax, %eax
callq 0x1050
leaq 0x91d(%rip), %rdi       # 0x253a
movl %r14d, %esi
movl (%rsp), %edx
xorl %eax, %eax
callq 0x1050
xorl %edi, %edi
callq 0x1080