// File: ticky[P]ps2iconsys/src/ps2_iconsys.cpp
// Function: IconSys::DecodeTitle(unsigned char const*, char*)
void IconSys::DecodeTitle(unsigned char const * str_in, char* str_out)
{
	unsigned char t1, t2;

	for(int i=0; i<68; i+=2) {
		t1 = str_in[i];		//each S-JIS character consists of two bytes
		t2 = str_in[i+1];

		switch(t1) {
			case 0x00:
				if(t2 == 0x00) {
					str_out[i>>1] = '\0';
					return;
				} else {
					str_out[i>>1] = '?';
				}
				break;
			case 0x81:
				if(t2 == 0x40) {
					str_out[i>>1] = ' ';
				} else if(t2 == 0x46) {
					str_out[i>>1] = ':';
				} else if(t2 == 0x5E) {
					str_out[i>>1] = '/';
				} else if(t2 == 0x69) {
					str_out[i>>1] = '(';
				} else if(t2 == 0x6A) {
					str_out[i>>1] = ')';
				} else if(t2 == 0x6D) {
					str_out[i>>1] = '[';
				} else if(t2 == 0x6E) {
					str_out[i>>1] = ']';
				} else if(t2 == 0x6F) {
					str_out[i>>1] = '{';
				} else if(t2 == 0x70) {
					str_out[i>>1] = '}';
				} else {
					str_out[i>>1] = '?';
				}
				break;
			case 0x82:
				if((t2 >= 0x4f) && (t2 <= 0x7A)) {
					//digits (0-9), capital letters (A-Z)
					str_out[i>>1] = t2-31;
				} else if( (t2 >= 0x81) && (t2 <= 0x9B) ) {
					//lowercase letters (a-z)
					str_out[i>>1] = t2-32;
				} else if(t2 == 0x3F) {
					str_out[i>>1] = ' ';
				}  else {
					str_out[i>>1] = '?';
				}
				break;			
			default:
				str_out[i>>1] = '?';
				break;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x44, -0x18(%rbp)
jge 0x7bad
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rcx
movslq -0x18(%rbp), %rax
movb 0x1(%rax,%rcx), %al
movb %al, -0x12(%rbp)
movzbl -0x11(%rbp), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
je 0x79a6
jmp 0x7987
movl -0x1c(%rbp), %eax
subl $0x81, %eax
je 0x79d9
jmp 0x7993
movl -0x1c(%rbp), %eax
subl $0x82, %eax
je 0x7b00
jmp 0x7b8d
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x79c4
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x7bad
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x7b9d
movzbl -0x12(%rbp), %eax
cmpl $0x40, %eax
jne 0x79f7
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
jmp 0x7afb
movzbl -0x12(%rbp), %eax
cmpl $0x46, %eax
jne 0x7a15
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x3a, (%rax,%rcx)
jmp 0x7af9
movzbl -0x12(%rbp), %eax
cmpl $0x5e, %eax
jne 0x7a33
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x2f, (%rax,%rcx)
jmp 0x7af7
movzbl -0x12(%rbp), %eax
cmpl $0x69, %eax
jne 0x7a51
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x28, (%rax,%rcx)
jmp 0x7af5
movzbl -0x12(%rbp), %eax
cmpl $0x6a, %eax
jne 0x7a6f
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x29, (%rax,%rcx)
jmp 0x7af3
movzbl -0x12(%rbp), %eax
cmpl $0x6d, %eax
jne 0x7a8a
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x5b, (%rax,%rcx)
jmp 0x7af1
movzbl -0x12(%rbp), %eax
cmpl $0x6e, %eax
jne 0x7aa5
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x5d, (%rax,%rcx)
jmp 0x7aef
movzbl -0x12(%rbp), %eax
cmpl $0x6f, %eax
jne 0x7ac0
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x7b, (%rax,%rcx)
jmp 0x7aed
movzbl -0x12(%rbp), %eax
cmpl $0x70, %eax
jne 0x7adb
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x7d, (%rax,%rcx)
jmp 0x7aeb
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x7aed
jmp 0x7aef
jmp 0x7af1
jmp 0x7af3
jmp 0x7af5
jmp 0x7af7
jmp 0x7af9
jmp 0x7afb
jmp 0x7b9d
movzbl -0x12(%rbp), %eax
cmpl $0x4f, %eax
jl 0x7b2c
movzbl -0x12(%rbp), %eax
cmpl $0x7a, %eax
jg 0x7b2c
movzbl -0x12(%rbp), %eax
subl $0x1f, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x7b8b
movzbl -0x12(%rbp), %eax
cmpl $0x81, %eax
jl 0x7b5c
movzbl -0x12(%rbp), %eax
cmpl $0x9b, %eax
jg 0x7b5c
movzbl -0x12(%rbp), %eax
subl $0x20, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x7b89
movzbl -0x12(%rbp), %eax
cmpl $0x3f, %eax
jne 0x7b77
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
jmp 0x7b87
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x7b89
jmp 0x7b8b
jmp 0x7b9d
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x7b9f
movl -0x18(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x18(%rbp)
jmp 0x7953
popq %rbp
retq
nop