// File: jswaff[P]prophet3/src/drawboard.cpp
// Function: draw_board(position*)
void draw_board(position *p) {
    char text[100];

    for (int r=0;r<8;r++) {  // every rank
        strcpy(text,"");
        for (int f=0;f<8;f++) { // every file
            switch(p->piece[get_square((rank_t)r,(file_t)f)]) {
            case NO_PIECE: strcat(text,"- "); break;
            case PAWN: strcat(text,"P "); break;
            case -PAWN: strcat(text,"p "); break;
            case ROOK: strcat(text,"R "); break;
            case -ROOK: strcat(text,"r "); break;
            case BISHOP: strcat(text,"B "); break;
            case -BISHOP: strcat(text,"b "); break;
            case KNIGHT: strcat(text,"N "); break;
            case -KNIGHT: strcat(text,"n "); break;
            case QUEEN: strcat(text,"Q "); break;
            case -QUEEN: strcat(text,"q "); break;
            case KING: strcat(text,"K "); break;
            case -KING: strcat(text,"k "); break;
            }
        }

        // print the player to move
        if (r==RANK_6) {
            if (p->player==WHITE) {
                strcat(text,"   white to move");
            } else {
                strcat(text,"   black to move");
            }
        }

        // print the en passant square
        if (r==RANK_5) {
            if (p->ep_sq==NO_SQUARE) {
                strcat(text,"   no ep");
            } else {
                char buffer[3];
                sq_to_str(p->ep_sq,buffer);
                strcat(text,"   ep=");
                strcat(text,buffer);
            }
        }

        // print the castling rights on the fourth row
        if (r==RANK_4) {
            if (p->castling_rights) {
                strcat(text,"   castling=");
                if (can_castle_wk(p))
                    strcat(text,"K");
                if (can_castle_wq(p))
                    strcat(text,"Q");
                if (can_castle_bk(p))
                    strcat(text,"k");
                if (can_castle_bq(p))
                    strcat(text,"q");
            } else {
                strcat(text,"   no castling rights");
            }
        }

        strcat(text,"\n");
        print(text);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x8, -0x74(%rbp)
jge 0x67ea
leaq -0x70(%rbp), %rdi
leaq 0x321ee(%rip), %rsi     # 0x386f9
callq 0x2140
movl $0x0, -0x78(%rbp)
cmpl $0x8, -0x78(%rbp)
jge 0x6678
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x74(%rbp), %edi
movl -0x78(%rbp), %esi
callq 0x12130
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl $0x6, %eax
movl %eax, %ecx
movq %rcx, -0x88(%rbp)
subl $0xc, %eax
ja 0x6668
movq -0x88(%rbp), %rax
leaq 0x2f10c(%rip), %rcx     # 0x35674
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x70(%rbp), %rdi
leaq 0x32188(%rip), %rsi     # 0x38704
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f117(%rip), %rsi     # 0x356a8
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f105(%rip), %rsi     # 0x356ab
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0f3(%rip), %rsi     # 0x356ae
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0e1(%rip), %rsi     # 0x356b1
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0cf(%rip), %rsi     # 0x356b4
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0c0(%rip), %rsi     # 0x356b7
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0b1(%rip), %rsi     # 0x356ba
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f0a2(%rip), %rsi     # 0x356bd
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f093(%rip), %rsi     # 0x356c0
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f084(%rip), %rsi     # 0x356c3
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f075(%rip), %rsi     # 0x356c6
callq 0x22f0
jmp 0x6668
leaq -0x70(%rbp), %rdi
leaq 0x2f066(%rip), %rsi     # 0x356c9
callq 0x22f0
jmp 0x666a
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x6517
cmpl $0x2, -0x74(%rbp)
jne 0x66af
movq -0x8(%rbp), %rax
cmpl $0x1, 0x138(%rax)
jne 0x669d
leaq -0x70(%rbp), %rdi
leaq 0x2f036(%rip), %rsi     # 0x356cc
callq 0x22f0
jmp 0x66ad
leaq -0x70(%rbp), %rdi
leaq 0x2f035(%rip), %rsi     # 0x356dd
callq 0x22f0
jmp 0x66af
cmpl $0x3, -0x74(%rbp)
jne 0x6706
movq -0x8(%rbp), %rax
cmpl $0x40, 0x13c(%rax)
jne 0x66d4
leaq -0x70(%rbp), %rdi
leaq 0x2f021(%rip), %rsi     # 0x356ee
callq 0x22f0
jmp 0x6704
movq -0x8(%rbp), %rax
movl 0x13c(%rax), %edi
leaq -0x7b(%rbp), %rsi
callq 0x14220
leaq -0x70(%rbp), %rdi
leaq 0x2f005(%rip), %rsi     # 0x356f7
callq 0x22f0
leaq -0x70(%rbp), %rdi
leaq -0x7b(%rbp), %rsi
callq 0x22f0
jmp 0x6706
cmpl $0x4, -0x74(%rbp)
jne 0x67c1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x140(%rax)
je 0x67af
leaq -0x70(%rbp), %rdi
leaq 0x2efd2(%rip), %rsi     # 0x356fe
callq 0x22f0
movq -0x8(%rbp), %rdi
callq 0xf1e0
testb $0x1, %al
jne 0x6740
jmp 0x6750
leaq -0x70(%rbp), %rdi
leaq 0x3e12f(%rip), %rsi     # 0x4487a
callq 0x22f0
movq -0x8(%rbp), %rdi
callq 0xf200
testb $0x1, %al
jne 0x675f
jmp 0x676f
leaq -0x70(%rbp), %rdi
leaq 0x2efa1(%rip), %rsi     # 0x3570b
callq 0x22f0
movq -0x8(%rbp), %rdi
callq 0xf220
testb $0x1, %al
jne 0x677e
jmp 0x678e
leaq -0x70(%rbp), %rdi
leaq 0x32a38(%rip), %rsi     # 0x391c1
callq 0x22f0
movq -0x8(%rbp), %rdi
callq 0xf240
testb $0x1, %al
jne 0x679d
jmp 0x67ad
leaq -0x70(%rbp), %rdi
leaq 0x3e235(%rip), %rsi     # 0x449dd
callq 0x22f0
jmp 0x67bf
leaq -0x70(%rbp), %rdi
leaq 0x2ef53(%rip), %rsi     # 0x3570d
callq 0x22f0
jmp 0x67c1
leaq -0x70(%rbp), %rdi
leaq 0x300b9(%rip), %rsi     # 0x36885
callq 0x22f0
leaq -0x70(%rbp), %rdi
movb $0x0, %al
callq 0x8c60
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x64f6
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)