// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
leaq 0x91b(%rip), %rbx       # 0x24e9
leaq 0x4eb(%rip), %r12       # 0x20c0
leaq 0x914(%rip), %r14       # 0x24f0
movq 0x23fd(%rip), %r15      # 0x3fe0
xorl %r13d, %r13d
callq 0x11ca
movl %eax, %ebp
movq %rbx, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
movl %ebp, %eax
shrl $0xc, %eax
andl $0x3f, %eax
movsbl (%rax,%r12), %esi
movl %ebp, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movsbl (%rax,%r12), %edx
movl %ebp, %eax
andl $0x3f, %eax
movsbl (%rax,%r12), %ecx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1050
incl %r13d
cmpl $0x4, %r13d
jne 0x1c3d
movl $0xa, %edi
callq 0x1030
xorl %r13d, %r13d
btl $0x15, %ebp
jb 0x1c54
movq (%r15), %rdi
callq 0x1070
testl %eax, %eax
je 0x1be6
jmp 0x1e17
leaq 0x93f(%rip), %rdi       # 0x259a
callq 0x1040
callq 0x11ca
movl %eax, %ebp
movl %eax, %r14d
andl $0x3ffff, %r14d         # imm = 0x3FFFF
leaq 0x882(%rip), %rdi       # 0x24fa
movl $0x0, 0xc(%rsp)
movl %r14d, %esi
xorl %eax, %eax
callq 0x1050
callq 0x11ca
movl %eax, %ebx
movl %eax, %r13d
orl $0xfffe0000, %r13d      # imm = 0xFFFE0000
negl %r13d
leaq 0x861(%rip), %rdi       # 0x2506
movl %r13d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1050
xorl %r15d, %r15d
testl $0x38000, %ebp          # imm = 0x38000
jne 0x1df1
movl $0x0, 0xc(%rsp)
movl %r15d, 0x10(%rsp)
addl %r14d, %ebx
callq 0x11ca
andl $0x3ffff, %eax          # imm = 0x3FFFF
addl %eax, %ebx
leaq 0x873(%rip), %rdi       # 0x2557
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
incl %r13d
callq 0x11ca
movl %eax, %ebp
movl %eax, %r15d
andl $0x3ffff, %r15d         # imm = 0x3FFFF
addl %r15d, %ebx
leal 0x1(%r14), %eax
movl %eax, 0x14(%rsp)
leaq 0x84f(%rip), %rdi       # 0x2562
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1050
movl %r15d, %edi
callq 0x12e4
movl %ebp, %eax
shrl $0xc, %eax
andl $0x3f, %eax
movsbl (%rax,%r12), %esi
movl %ebp, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movsbl (%rax,%r12), %edx
andl $0x3f, %ebp
movsbl (%rbp,%r12), %ecx
leaq 0x81d(%rip), %rdi       # 0x256f
xorl %eax, %eax
callq 0x1050
movl $0xa, %edi
callq 0x1030
decl %r13d
movl 0x14(%rsp), %eax
movl %eax, %r14d
cmpl $0x1, %r13d
jg 0x1cf0
andl $0x3ffff, %ebx          # imm = 0x3FFFF
je 0x1d93
leaq 0x7f6(%rip), %rdi       # 0x257c
movl %ebx, %esi
xorl %eax, %eax
callq 0x1050
incl 0xc(%rsp)
movl 0x10(%rsp), %r15d
incl %r15d
callq 0x11ca
movl %eax, %ebp
movl %eax, %r14d
andl $0x3ffff, %r14d         # imm = 0x3FFFF
leaq 0x747(%rip), %rdi       # 0x24fa
movl %r14d, %esi
xorl %eax, %eax
callq 0x1050
callq 0x11ca
movl %eax, %ebx
movl %eax, %r13d
orl $0xfffe0000, %r13d      # imm = 0xFFFE0000
negl %r13d
leaq 0x72e(%rip), %rdi       # 0x2506
movl %r13d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1050
testl $0x38000, %ebp          # imm = 0x38000
je 0x1cc9
leaq 0x71f(%rip), %rdi       # 0x2517
movl %r14d, %esi
xorl %eax, %eax
callq 0x1050
leaq 0x731(%rip), %rdi       # 0x253a
movl %r15d, %esi
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x1050
xorl %edi, %edi
callq 0x1080