// File: /workspace/github_c_makefile_star2_O1/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, %ebx
leaq 0xb80(%rip), %rdi       # 0x2118
callq 0x1050
cmpl $0x1, %ebx
jle 0x184c
cmpl $0x2, %ebx
je 0x15c5
movb $0x1, %al
movb %al, 0x2b6d(%rip)       # 0x4120
movb %al, 0x2b63(%rip)       # 0x411c
leaq 0xb76(%rip), %rdi       # 0x2136
callq 0x1050
callq 0x133c
testl %eax, %eax
jle 0x1858
cmpl $0x3, %ebx
movl $0x2, %eax
cmovgel %ebx, %eax
decl %eax
movq %rax, 0x18(%rsp)
leaq 0xf(%rsp), %rbp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movq 0x8(%rax,%r15,8), %rdi
leaq 0xaec(%rip), %rsi       # 0x20ee
callq 0x1150
testq %rax, %rax
je 0x185f
movq %rax, %r14
movq %r14, %rdi
callq 0x1100
testl %eax, %eax
jne 0x17f5
leaq 0x20(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x10e0
movl $0x2, %r12d
cmpw $0x223f, 0x20(%rsp)     # imm = 0x223F
je 0x1663
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), %r12d
movl %r12d, %r13d
leaq (%rsp,%r13), %rdi
addq $0x20, %rdi
movl $0x7, %edx
leaq 0xa8b(%rip), %rsi       # 0x2105
callq 0x1040
testl %eax, %eax
je 0x16c3
movzbl 0x20(%rsp,%r13), %eax
testl %eax, %eax
je 0x178c
cmpl $0x22, %eax
je 0x178c
leaq (%rsp,%r13), %rsi
addq $0x20, %rsi
movl 0x2a34(%rip), %edi      # 0x40dc
movl $0x1, %edx
callq 0x1060
incq %r13
cmpq $0xff, %r13
jne 0x1683
jmp 0x178c
cmpb $0x0, 0x2a56(%rip)      # 0x4120
jne 0x16df
leaq 0xa3a(%rip), %rdi       # 0x210d
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x10a0
movl 0x29f7(%rip), %edi      # 0x40dc
movl $0x3, %edx
leaq 0x93e(%rip), %rsi       # 0x202f
callq 0x1060
leal 0x17(%r12), %r13d
orl $0x8, %r12d
movsbl 0x20(%rsp,%r12), %eax
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x1712
addl $-0x30, %eax
jmp 0x172b
leal -0x61(%rax), %ecx
cmpb $0x5, %cl
ja 0x171f
addl $-0x57, %eax
jmp 0x172b
leal -0x41(%rax), %ecx
addl $-0x3c, %eax
cmpb $0x6, %cl
cmovael %ebx, %eax
testl %eax, %eax
js 0x178c
movzbl 0x21(%rsp,%r12), %ecx
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x1742
addl $-0x30, %ecx
jmp 0x175b
leal -0x61(%rcx), %edx
cmpb $0x5, %dl
ja 0x174f
addl $-0x57, %ecx
jmp 0x175b
leal -0x41(%rcx), %edx
addl $-0x3c, %ecx
cmpb $0x6, %dl
cmovael %ebx, %ecx
movb %cl, 0xf(%rsp)
testb %cl, %cl
js 0x178c
shll $0x4, %eax
addl %eax, %ecx
movb %cl, 0xf(%rsp)
movl 0x296a(%rip), %edi      # 0x40dc
movl $0x1, %edx
movq %rbp, %rsi
callq 0x1060
addq $0x3, %r12
cmpq %r13, %r12
jb 0x16ff
movl 0x294a(%rip), %edi      # 0x40dc
movl $0x2, %edx
leaq 0x977(%rip), %rsi       # 0x2115
callq 0x1060
callq 0x1479
movl %eax, %r13d
testb %al, %al
je 0x17eb
callq 0x1180
movq %rax, %r12
movq (%r12), %rax
movsbq %r13b, %rcx
testb $0x40, 0x1(%rax,%rcx,2)
je 0x17cf
movsbl %r13b, %edi
callq 0x1030
cmpb $0xa, %r13b
jne 0x17df
movl $0xa, %edi
callq 0x1030
callq 0x1479
movl %eax, %r13d
testb %al, %al
jne 0x17b7
movb %r13b, 0xf(%rsp)
jmp 0x1613
incq %r15
movq %r14, %rdi
callq 0x1070
cmpq 0x18(%rsp), %r15
jne 0x15f1
leaq 0x92f(%rip), %rdi       # 0x2141
callq 0x1050
movl 0x28bf(%rip), %edi      # 0x40dc
leaq 0x28bc(%rip), %rdx      # 0x40e0
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1130
movl 0x28a9(%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 0x1864
callq 0x11c2
jmp 0x1864
callq 0x11a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1838