// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movl %edi, %ebx
leaq 0xc36(%rip), %rdi       # 0x2118
callq 0x1050
cmpl $0x1, %ebx
jle 0x1721
cmpl $0x2, %ebx
je 0x150f
movb $0x1, %al
movb %al, 0x2c2b(%rip)       # 0x4128
movb %al, 0x2c21(%rip)       # 0x4124
leaq 0xc2c(%rip), %rdi       # 0x2136
callq 0x1050
callq 0x129c
testl %eax, %eax
jle 0x1777
decl %ebx
pushq $0x1
popq %r15
pushq $0xa
popq %rbp
xorl %ecx, %ecx
movq %rbx, 0x10(%rsp)
cmpq %rbx, %rcx
je 0x16fc
movq 0x8(%rsp), %rax
movq 0x8(%rax,%rcx,8), %rdi
leaq 0xba8(%rip), %rsi       # 0x20ee
movq %rcx, %r14
callq 0x1160
testq %rax, %rax
je 0x178a
movq %rax, %rbx
incq %r14
movq %r14, 0x18(%rsp)
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x16e5
leaq 0x20(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x10e0
cmpw $0x223f, 0x20(%rsp)     # imm = 0x223F
pushq $0x2
popq %rax
je 0x15ae
leaq 0x20(%rsp), %rdi
leaq 0xb65(%rip), %rsi       # 0x2101
pushq $0x3
popq %rdx
callq 0x1120
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal (%rcx,%rcx,2), %eax
movl %eax, %r12d
leaq (%rsp,%r12), %rdi
addq $0x20, %rdi
leaq 0xb45(%rip), %rsi       # 0x2105
pushq $0x7
popq %rdx
callq 0x1040
testl %eax, %eax
je 0x160b
cmpq $0xff, %r12
je 0x168f
movzbl 0x20(%rsp,%r12), %eax
testl %eax, %eax
je 0x168f
cmpl $0x22, %eax
je 0x168f
leaq (%rsp,%r12), %rsi
addq $0x20, %rsi
movl 0x2ae6(%rip), %edi      # 0x40e4
movq %r15, %rdx
callq 0x1060
incq %r12
jmp 0x15cc
cmpb $0x0, 0x2b16(%rip)      # 0x4128
jne 0x1627
leaq 0xaf2(%rip), %rdi       # 0x210d
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x10a0
movl 0x2ab7(%rip), %edi      # 0x40e4
leaq 0x9fb(%rip), %rsi       # 0x202f
pushq $0x3
popq %rdx
callq 0x1060
leal 0x17(%r12), %r14d
orq $0x8, %r12
cmpq %r14, %r12
jae 0x168f
movsbl 0x20(%rsp,%r12), %edi
callq 0x1497
testl %eax, %eax
js 0x168f
movl %eax, %r13d
movsbl 0x21(%rsp,%r12), %edi
callq 0x1497
testb %al, %al
js 0x168f
shll $0x4, %r13d
addl %r13d, %eax
movb %al, 0x7(%rsp)
movl 0x2a68(%rip), %edi      # 0x40e4
leaq 0x7(%rsp), %rsi
movq %r15, %rdx
callq 0x1060
addq $0x3, %r12
jmp 0x1645
movl 0x2a4f(%rip), %edi      # 0x40e4
leaq 0xa79(%rip), %rsi       # 0x2115
pushq $0x2
popq %rdx
callq 0x1060
callq 0x13d8
testb %al, %al
je 0x16db
movl %eax, %r13d
callq 0x1190
movq (%rax), %rax
movsbq %r13b, %rcx
testb $0x40, 0x1(%rax,%rcx,2)
je 0x16cc
movsbl %r13b, %edi
callq 0x1030
cmpb $0xa, %r13b
jne 0x16a4
movl %ebp, %edi
callq 0x1030
jmp 0x16a4
movb $0x0, 0x7(%rsp)
jmp 0x1562
movq %rbx, %rdi
callq 0x1070
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rcx
jmp 0x152c
leaq 0xa3e(%rip), %rdi       # 0x2141
callq 0x1050
callq 0x1476
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28d0(%rip), %rbx      # 0x3ff8
movq (%rbx), %rdi
movq 0x8(%rsp), %r14
movq (%r14), %rdx
leaq 0x914(%rip), %rsi       # 0x204e
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rdi
movq (%r14), %rdx
leaq 0x918(%rip), %rsi       # 0x2066
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rdi
movq (%r14), %rdx
leaq 0x919(%rip), %rsi       # 0x207b
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rcx
leaq 0x925(%rip), %rdi       # 0x2098
pushq $0x44
jmp 0x179d
movq 0x287a(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0x955(%rip), %rdi       # 0x20dd
jmp 0x179b
movq 0x2867(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0x955(%rip), %rdi       # 0x20f0
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
pushq $-0x1
popq %rax
jmp 0x170f