// File: /workspace/github_c_makefile_star2_O0/lecram[P]congif/term.c
// Function: escseq
static void
escseq(Term *term, uint8_t byte)
{
    uint8_t first, second;

    if (term->parlen) {
        first = *term->partial;
        second = byte;
    } else {
        first = byte;
        second = 0;
    }
    switch (first) {
    case 'c':
        reset(term);
        break;
    case 'D':
        CLEARWRAP;
        if (term->row == term->bot)
            scroll_down(term);
        else
            term->row++;
        break;
    case 'E':
        CLEARWRAP;
        if (term->row == term->bot) {
            scroll_down(term);
            term->col = 0;
        } else {
            term->row++;
        }
        break;
    case 'H':
        /* TODO: set tab stop at current column */
        logfmt("NYI: ESC Sequence H (HTS)\n");
        break;
    case 'M':
        if (term->row == term->top)
            scroll_up(term);
        else
            term->row--;
        break;
    case 'Z':
        /* Identify Terminal (DECID) */
        /* if we were a real terminal, we'd reply with "ESC [ ? 6 c" */
        /* since there is no application listening, we can ignore this */
        break;
    case '7':
        CLEARWRAP;
        save_misc(term);
        break;
    case '8':
        CLEARWRAP;
        load_misc(term);
        break;
    case '%':
        /* TODO: select charset */
        logfmt("NYI: ESC Sequence %% (character set selection)\n");
        switch(second)
        {
        case '8': /* Linux switch to UTF8 */
        case 'G': /* DOCS: Designate other coding system */
            term->mode &= ~M_ISOLAT1;
            if (term->cs_array[0] == CS_ISO)
                term->cs_array[0] = CS_BMP;
            if (term->cs_array[1] == CS_ISO)
                term->cs_array[1] = CS_BMP;
            break;
        case '@': /* DOCS, Standard return */
            term->mode |= M_ISOLAT1;
            if (term->cs_array[0] == CS_BMP)
                term->cs_array[0] = CS_ISO;
            if (term->cs_array[1] == CS_BMP)
                term->cs_array[1] = CS_ISO;
            break;
        }
        break;
    case '#':
        switch(second)
        {
        case '8':
            {
                int i, j;
                for (i = 0; i < term->rows; i++) {
                    for (j = 0; j < term->cols; j++) {
                        term->addr[i][j] = (Cell) {'E', def_attr, def_pair};
                    }
                }
            }
            break;
        default:
            /* TODO */
            logfmt("NYI: ESC Sequence # 3..6 DECDWL etc\n");
            break;
        }
        break;
    case '(':
        switch (second) {
        case 'B':
            term->cs_array[0] = (term->mode&M_ISOLAT1)?CS_ISO:CS_BMP;
            break;
        case '0':
            term->cs_array[0] = CS_VTG;
            break;
        case 'U':
            term->cs_array[0] = CS_437;
            break;
        case 'K':
            logfmt("UNS: user-defined mapping\n");
            term->cs_array[0] = (term->mode&M_ISOLAT1)?CS_ISO:CS_BMP;
            break;
        }
        break;
    case ')':
        switch (second) {
        case 'B':
            term->cs_array[1] = (term->mode&M_ISOLAT1)?CS_ISO:CS_BMP;
            break;
        case '0':
            term->cs_array[1] = CS_VTG;
            break;
        case 'U':
            term->cs_array[1] = CS_437;
            break;
        case 'K':
            logfmt("UNS: user-defined mapping\n");
            term->cs_array[1] = (term->mode&M_ISOLAT1)?CS_ISO:CS_BMP;
            break;
        }
        break;
    case '>':
        /* TODO: set numeric keypad mode */
        logfmt("NYI: ESC Sequence > (DECPNM)\n");
        break;
    case '=':
        /* TODO: set application keypad mode */
        logfmt("NYI: ESC Sequence = (DECPAM)\n");
        break;
    default:
        logfmt("UNS: ESC Sequence %c\n", first);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0x22fe
movq -0x8(%rbp), %rax
movb 0x6c(%rax), %al
movb %al, -0xa(%rbp)
movb -0x9(%rbp), %al
movb %al, -0xb(%rbp)
jmp 0x2308
movb -0x9(%rbp), %al
movb %al, -0xa(%rbp)
movb $0x0, -0xb(%rbp)
movzbl -0xa(%rbp), %eax
addl $-0x23, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x40, %eax
ja 0x272f
movq -0x20(%rbp), %rax
leaq 0x4d2b(%rip), %rcx      # 0x7054
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
callq 0x1880
jmp 0x2741
jmp 0x2342
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jl 0x2363
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x2365
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x2380
movq -0x8(%rbp), %rdi
callq 0x3670
jmp 0x238d
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x2741
jmp 0x2394
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jl 0x23b5
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x23b7
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x23dd
movq -0x8(%rbp), %rdi
callq 0x3670
movq -0x8(%rbp), %rax
movl $0x0, 0xc(%rax)
jmp 0x23ea
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x2741
leaq 0x51d9(%rip), %rdi      # 0x75cf
movb $0x0, %al
callq 0x2220
jmp 0x2741
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x241d
movq -0x8(%rbp), %rdi
callq 0x3870
jmp 0x242a
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x2741
jmp 0x2741
jmp 0x2436
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jl 0x2457
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x2459
movq -0x8(%rbp), %rdi
callq 0x35f0
jmp 0x2741
jmp 0x2469
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jl 0x248a
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x248c
movq -0x8(%rbp), %rdi
callq 0x3990
jmp 0x2741
leaq 0x5149(%rip), %rdi      # 0x75ea
xorl %eax, %eax
callq 0x2220
movzbl -0xb(%rbp), %eax
movl %eax, -0x24(%rbp)
subl $0x38, %eax
je 0x24ca
jmp 0x24b6
movl -0x24(%rbp), %eax
subl $0x40, %eax
je 0x2508
jmp 0x24c0
movl -0x24(%rbp), %eax
subl $0x47, %eax
jne 0x2546
jmp 0x24ca
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %ecx
andl $0xffffefff, %ecx       # imm = 0xFFFFEFFF
movw %cx, 0x18(%rax)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x24f1
movq -0x8(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x8(%rbp), %rax
cmpl $0x1, 0x34(%rax)
jne 0x2506
movq -0x8(%rbp), %rax
movl $0x0, 0x34(%rax)
jmp 0x2546
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movw %cx, 0x18(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x252f
movq -0x8(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x2544
movq -0x8(%rbp), %rax
movl $0x1, 0x34(%rax)
jmp 0x2546
jmp 0x2741
movb -0xb(%rbp), %al
subb $0x38, %al
jne 0x25c5
jmp 0x2554
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x25c3
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x25b6
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
movw $0x45, -0x18(%rbp)
movb 0xc25f(%rip), %dl       # 0xe7f8
movb %dl, -0x16(%rbp)
movb 0x80f0(%rip), %dl       # 0xa692
movb %dl, -0x15(%rbp)
movl -0x18(%rbp), %edx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x256d
jmp 0x25b8
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x255b
jmp 0x25d3
leaq 0x504e(%rip), %rdi      # 0x761a
movb $0x0, %al
callq 0x2220
jmp 0x2741
movzbl -0xb(%rbp), %eax
addl $-0x30, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x25, %eax
ja 0x2670
movq -0x30(%rbp), %rax
leaq 0x4bf7(%rip), %rcx      # 0x71f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %edx
andl $0x1000, %edx           # imm = 0x1000
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x2670
movq -0x8(%rbp), %rax
movl $0x2, 0x30(%rax)
jmp 0x2670
movq -0x8(%rbp), %rax
movl $0x3, 0x30(%rax)
jmp 0x2670
leaq 0x4ff8(%rip), %rdi      # 0x763f
movb $0x0, %al
callq 0x2220
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %edx
andl $0x1000, %edx           # imm = 0x1000
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x2741
movzbl -0xb(%rbp), %eax
addl $-0x30, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x25, %eax
ja 0x270d
movq -0x38(%rbp), %rax
leaq 0x4ac2(%rip), %rcx      # 0x7158
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %edx
andl $0x1000, %edx           # imm = 0x1000
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x34(%rax)
jmp 0x270d
movq -0x8(%rbp), %rax
movl $0x2, 0x34(%rax)
jmp 0x270d
movq -0x8(%rbp), %rax
movl $0x3, 0x34(%rax)
jmp 0x270d
leaq 0x4f5b(%rip), %rdi      # 0x763f
movb $0x0, %al
callq 0x2220
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %edx
andl $0x1000, %edx           # imm = 0x1000
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x34(%rax)
jmp 0x2741
leaq 0x4f44(%rip), %rdi      # 0x765a
movb $0x0, %al
callq 0x2220
jmp 0x2741
leaq 0x4f52(%rip), %rdi      # 0x7678
movb $0x0, %al
callq 0x2220
jmp 0x2741
movzbl -0xa(%rbp), %esi
leaq 0x4f5c(%rip), %rdi      # 0x7696
movb $0x0, %al
callq 0x2220
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)