// File: /workspace/github_c_makefile_star2_O3/bokunimowakaru[P]petit15term/petitPanCake.c
// Function: main
int main(int argc,char **argv){
	char s[256];									 // 文字データ用
	char PC_LINE[]={0x80,0x08,0x01};
	int i,j,k,loop;
	char c; 										// 文字入力用の文字変数
	FILE *fp;
	
	printf("petitPanCake for Raspberry Pi\n");
	if( argc < 2){
		fprintf(stderr,"Usage : %s input_files\n",argv[0]);
		fprintf(stderr,"        %s fuji.txt\n",argv[0]);
		fprintf(stderr,"        %s pc_movie/pc*.txt\n",argv[0]);
		fprintf(stderr,"PanCake用コマンドのファイルを入力してください。\n");
		return -1;
	}
	if( argc > 2){
		MOVIE=1; TXL_WAIT=1800;
		printf("MOVIE mode\n");
	}
	if(open_serial_port() <= 0){
		fprintf(stderr,"UART OPEN ERROR\n");
		return -1;
	}
	for(loop=0;loop < (argc-1);loop++){
		fp=fopen(argv[loop+1],"r");
		if(fp==0){
			fprintf(stderr,"FILE OPEN ERROR\n");
			return -1;
		}
		
		while(feof(fp)==0){
			fgets(s,256,fp);
			// printf("%s",s);
			if(strncmp(s,"?\"",2)==0) j=2;
			else if(strncmp(s,"? \"",3)==0) j=3;
			else j=0;
			if(strncmp(&s[j],"PC LINE",7)==0){
				if(!MOVIE) printf("(BIN)%s",s);
				write(ComFd, PC_LINE, 3);
				for(i=j+8;i<j+23;i+=3){
					k=ahex2i(s[i]); if( k<0 ) break;
					c=(char)ahex2i(s[i+1]); if( c<0 ) break;
					c+=(char)(k<<4);
					write(ComFd, &c, 1);
				//	usleep(TX_WAIT);
				}
				j=0;
			}else for(i=j;i<255;i++){
				if(s[i]=='\"' || s[i]=='\0' ) break;
				write(ComFd, &s[i], 1);
			//	usleep(TX_WAIT);
			}
			write(ComFd, "\r\n", 2);
			c=read_serial_port();
			while(c){
				if( isprint(c) ) printf("%c",c);	// 表示可能な文字の時に表示する
				if( c=='\n' ) printf("\n");
				c=read_serial_port();				// シリアルからデータを受信
			}
		}
		fclose(fp);
	}
	printf("DONE\n");
	close_serial_port();
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, 0x10(%rsp)
movl %edi, %r13d
leaq 0xb7c(%rip), %rdi       # 0x2118
callq 0x1050
cmpl $0x1, %r13d
jle 0x1844
cmpl $0x2, %r13d
je 0x15cb
movb $0x1, %al
movb %al, 0x2b67(%rip)       # 0x4120
movb %al, 0x2b5d(%rip)       # 0x411c
leaq 0xb70(%rip), %rdi       # 0x2136
callq 0x1050
callq 0x133c
testl %eax, %eax
jle 0x1850
decl %r13d
leaq 0x20(%rsp), %r12
leaq 0xf(%rsp), %r15
xorl %r14d, %r14d
movq %r13, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r14,8), %rdi
leaq 0xaf0(%rip), %rsi       # 0x20ee
callq 0x1150
testq %rax, %rax
je 0x1857
movq %rax, %rbx
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x17ea
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x10e0
movl $0x2, %eax
cmpw $0x223f, 0x20(%rsp)     # imm = 0x223F
je 0x165b
movl 0x20(%rsp), %eax
movl $0x203f, %ecx           # imm = 0x203F
xorl %ecx, %eax
movzbl 0x22(%rsp), %ecx
xorl $0x22, %ecx
xorl %edx, %edx
orw %ax, %cx
sete %dl
leal (%rdx,%rdx,2), %eax
movl %eax, %r13d
leaq (%rsp,%r13), %rdi
addq $0x20, %rdi
movl $0x7, %edx
leaq 0xa93(%rip), %rsi       # 0x2105
callq 0x1040
testl %eax, %eax
je 0x16bb
movzbl 0x20(%rsp,%r13), %eax
testl %eax, %eax
je 0x1781
cmpl $0x22, %eax
je 0x1781
leaq (%rsp,%r13), %rsi
addq $0x20, %rsi
movl 0x2a3c(%rip), %edi      # 0x40dc
movl $0x1, %edx
callq 0x1060
incq %r13
cmpq $0xff, %r13
jne 0x167b
jmp 0x1781
cmpb $0x0, 0x2a5e(%rip)      # 0x4120
jne 0x16d5
leaq 0xa42(%rip), %rdi       # 0x210d
movq %r12, %rsi
xorl %eax, %eax
callq 0x10a0
movl 0x2a01(%rip), %edi      # 0x40dc
movl $0x3, %edx
leaq 0x948(%rip), %rsi       # 0x202f
callq 0x1060
leal 0x17(%r13), %ebp
orq $0x8, %r13
movsbl 0x20(%rsp,%r13), %eax
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x1707
addl $-0x30, %eax
jmp 0x171f
leal -0x61(%rax), %ecx
cmpb $0x5, %cl
ja 0x1714
addl $-0x57, %eax
jmp 0x171f
leal -0x41(%rax), %ecx
cmpb $0x5, %cl
ja 0x1781
addl $-0x3c, %eax
testl %eax, %eax
js 0x1781
movzbl 0x21(%rsp,%r13), %ecx
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x1736
addl $-0x30, %ecx
jmp 0x1754
leal -0x61(%rcx), %edx
cmpb $0x5, %dl
ja 0x1743
addl $-0x57, %ecx
jmp 0x1754
leal -0x41(%rcx), %edx
addl $-0x3c, %ecx
cmpb $0x6, %dl
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovael %edx, %ecx
testb %cl, %cl
js 0x1781
shll $0x4, %eax
addl %eax, %ecx
movb %cl, 0xf(%rsp)
movl 0x2975(%rip), %edi      # 0x40dc
movl $0x1, %edx
movq %r15, %rsi
callq 0x1060
addq $0x3, %r13
cmpq %rbp, %r13
jb 0x16f4
movl 0x2955(%rip), %edi      # 0x40dc
movl $0x2, %edx
leaq 0x982(%rip), %rsi       # 0x2115
callq 0x1060
callq 0x1475
testb %al, %al
je 0x17e0
movl %eax, %r13d
callq 0x1180
movq %rax, %rbp
movq (%rbp), %rax
movsbq %r13b, %rcx
testb $0x40, 0x1(%rax,%rcx,2)
je 0x17c4
movsbl %r13b, %edi
callq 0x1030
cmpb $0xa, %r13b
jne 0x17d4
movl $0xa, %edi
callq 0x1030
callq 0x1475
movl %eax, %r13d
testb %al, %al
jne 0x17ac
movb $0x0, 0xf(%rsp)
jmp 0x160f
incq %r14
movq %rbx, %rdi
callq 0x1070
movq 0x18(%rsp), %r13
cmpq %r13, %r14
jne 0x15ed
leaq 0x937(%rip), %rdi       # 0x2141
callq 0x1050
movl 0x28c7(%rip), %edi      # 0x40dc
leaq 0x28c4(%rip), %rdx      # 0x40e0
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1130
movl 0x28b1(%rip), %edi      # 0x40dc
callq 0x10c0
movl %ebx, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x11de
jmp 0x185c
callq 0x11c2
jmp 0x185c
callq 0x11a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1830