// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw 0xa43(%rip), %ax        # 0x2013
movw %ax, -0x113(%rbp)
movb 0xa38(%rip), %al        # 0x2015
movb %al, -0x111(%rbp)
leaq 0xa50(%rip), %rdi       # 0x203a
movb $0x0, %al
callq 0x1080
cmpl $0x2, -0x8(%rbp)
jge 0x167c
movq 0x29f6(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xa46(%rip), %rsi       # 0x2059
movb $0x0, %al
callq 0x10e0
movq 0x29d7(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xa3f(%rip), %rsi       # 0x2071
movb $0x0, %al
callq 0x10e0
movq 0x29b8(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xa35(%rip), %rsi       # 0x2086
movb $0x0, %al
callq 0x10e0
movq 0x2999(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xa3a(%rip), %rsi       # 0x20a3
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a37
cmpl $0x2, -0x8(%rbp)
jle 0x16a4
movl $0x1, 0x2a84(%rip)      # 0x4110
movl $0x708, 0x2a32(%rip)    # imm = 0x708
leaq 0xa4b(%rip), %rdi       # 0x20e8
movb $0x0, %al
callq 0x1080
callq 0x1270
cmpl $0x0, %eax
jg 0x16d2
movq 0x2943(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xa35(%rip), %rsi       # 0x20f4
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a37
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1a1d
movq -0x10(%rbp), %rax
movl -0x124(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9fa(%rip), %rsi       # 0x2105
callq 0x1140
movq %rax, -0x130(%rbp)
cmpq $0x0, -0x130(%rbp)
jne 0x1745
movq 0x28d0(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x9d5(%rip), %rsi       # 0x2107
movb $0x0, %al
callq 0x10e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a37
jmp 0x1747
movq -0x130(%rbp), %rdi
callq 0x10f0
cmpl $0x0, %eax
jne 0x19fd
leaq -0x110(%rbp), %rdi
movq -0x130(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x10d0
leaq -0x110(%rbp), %rdi
leaq 0x996(%rip), %rsi       # 0x2118
movl $0x2, %edx
callq 0x1030
cmpl $0x0, %eax
jne 0x179d
movl $0x2, -0x11c(%rbp)
jmp 0x17d2
leaq -0x110(%rbp), %rdi
leaq 0x970(%rip), %rsi       # 0x211b
movl $0x3, %edx
callq 0x1030
cmpl $0x0, %eax
jne 0x17c6
movl $0x3, -0x11c(%rbp)
jmp 0x17d0
movl $0x0, -0x11c(%rbp)
jmp 0x17d2
movslq -0x11c(%rbp), %rax
leaq -0x110(%rbp), %rdi
addq %rax, %rdi
leaq 0x935(%rip), %rsi       # 0x211f
movl $0x7, %edx
callq 0x1030
cmpl $0x0, %eax
jne 0x18fb
cmpl $0x0, 0x290c(%rip)      # 0x4110
jne 0x181b
leaq -0x110(%rbp), %rsi
leaq 0x913(%rip), %rdi       # 0x2127
movb $0x0, %al
callq 0x1080
movl 0x28af(%rip), %edi      # 0x40d0
leaq -0x113(%rbp), %rsi
movl $0x3, %edx
callq 0x1040
movl -0x11c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %eax
movl -0x11c(%rbp), %ecx
addl $0x17, %ecx
cmpl %ecx, %eax
jge 0x18ef
movslq -0x118(%rbp), %rax
movsbl -0x110(%rbp,%rax), %edi
callq 0x1530
movl %eax, -0x120(%rbp)
cmpl $0x0, -0x120(%rbp)
jge 0x187d
jmp 0x18ef
movl -0x118(%rbp), %eax
addl $0x1, %eax
cltq
movsbl -0x110(%rbp,%rax), %edi
callq 0x1530
movb %al, -0x125(%rbp)
movsbl -0x125(%rbp), %eax
cmpl $0x0, %eax
jge 0x18a9
jmp 0x18ef
movl -0x120(%rbp), %eax
shll $0x4, %eax
movsbl %al, %ecx
movsbl -0x125(%rbp), %eax
addl %ecx, %eax
movb %al, -0x125(%rbp)
movl 0x2806(%rip), %edi      # 0x40d0
leaq -0x125(%rbp), %rsi
movl $0x1, %edx
callq 0x1040
movl -0x118(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x118(%rbp)
jmp 0x1841
movl $0x0, -0x11c(%rbp)
jmp 0x1971
movl -0x11c(%rbp), %eax
movl %eax, -0x118(%rbp)
cmpl $0xff, -0x118(%rbp)
jge 0x196f
movslq -0x118(%rbp), %rax
movsbl -0x110(%rbp,%rax), %eax
cmpl $0x22, %eax
je 0x193b
movslq -0x118(%rbp), %rax
movsbl -0x110(%rbp,%rax), %eax
cmpl $0x0, %eax
jne 0x193d
jmp 0x196f
movl 0x278d(%rip), %edi      # 0x40d0
movslq -0x118(%rbp), %rax
leaq -0x110(%rbp), %rsi
addq %rax, %rsi
movl $0x1, %edx
callq 0x1040
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x1907
jmp 0x1971
movl 0x2759(%rip), %edi      # 0x40d0
leaq 0x7b1(%rip), %rsi       # 0x212f
movl $0x2, %edx
callq 0x1040
callq 0x1400
movb %al, -0x125(%rbp)
cmpb $0x0, -0x125(%rbp)
je 0x19f8
callq 0x1160
movq (%rax), %rax
movsbl -0x125(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x19d1
movsbl -0x125(%rbp), %esi
leaq 0x768(%rip), %rdi       # 0x2132
movb $0x0, %al
callq 0x1080
movsbl -0x125(%rbp), %eax
cmpl $0xa, %eax
jne 0x19eb
leaq 0x74c(%rip), %rdi       # 0x2130
movb $0x0, %al
callq 0x1080
callq 0x1400
movb %al, -0x125(%rbp)
jmp 0x1993
jmp 0x1747
movq -0x130(%rbp), %rdi
callq 0x1050
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x16dc
leaq 0x711(%rip), %rdi       # 0x2135
movb $0x0, %al
callq 0x1080
callq 0x1500
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq