// File: /workspace/github_c_makefile_star2_O3/uobikiemukot[P]yaft/./ctrlseq/dcs.h
// Function: decdld_parse_header
void decdld_parse_header(struct terminal_t *term, char *start_buf)
{
	/*
	DECDLD format
		DCS Pfn; Pcn; Pe; Pcmw; Pss; Pt; Pcmh; Pcss; f Dscs Sxbp1 ; Sxbp2 ; .. .; Sxbpn ST
	parameters
		DCS : ESC (0x1B) 'P' (0x50) (DCS(8bit C1 code) is not supported)
		Pfn : fontset (ignored)
		Pcn : start char (0 means SPACE 0x20)
		Pe  : erase mode
				0: clear selectet charset
				1: clear only redefined glyph
				2: clear all drcs charset
		Pcmw: max cellwidth (force CELL_WEDTH defined in glyph.h)
		Pss : screen size (ignored)
		Pt  : defines the glyph as text or full cell or sixel (force full cell mode)
		      (TODO: implement sixel/text mode)
		Pcmh: max cellheight (force CELL_HEIGHT defined in glyph.h)
		Pcss: character set size (force: 96)
				0: 94 glyphs charset
				1: 96 glyphs charset
		f   : '{' (0x7B)
		Dscs: define character set
				Intermediate char: SPACE (0x20) to '/' (0x2F)
				final char       : '0' (0x30) to '~' (0x7E)
									but allow chars between '@' (0x40) and '~' (0x7E) for DRCSMMv1
									(ref: https://github.com/saitoha/drcsterm/blob/master/README.rst)
		Sxbp: see parse_decdld_sixel()
		ST  : ESC (0x1B) '\' (0x5C) or BEL (0x07)
	*/
	char *cp;
	int start_char, erase_mode, charset;
	struct parm_t parm;

	/* replace final char of DECDLD header by NUL '\0' */
	cp = strchr(start_buf, '{');
	*cp = '\0';

	logging(DEBUG, "decdld_parse_header()\nbuf:%s\n", start_buf);

	/* split header by semicolon ';' */
	reset_parm(&parm);
	parse_arg(start_buf, &parm, ';', isdigit);

	if (parm.argc != 8) /* DECDLD header must have 8 params */
		return;

	/* set params */
	start_char = dec2num(parm.argv[1]);
	erase_mode = dec2num(parm.argv[2]);

	/* parse Dscs */
	cp++; /* skip final char (NUL) of DECDLD header */
	while (SPACE <= *cp && *cp <= '/') /* skip intermediate char */
		cp++;

	if (0x40 <= *cp && *cp <= 0x7E) /* final char of Dscs must be between 0x40 to 0x7E (DRCSMMv1) */
		charset = *cp - 0x40;
	else
		charset = 0;

	logging(DEBUG, "charset(ku):0x%.2X start_char:%d erase_mode:%d\n",
		charset, start_char, erase_mode);

	/* reset previous glyph data */
	if (erase_mode < 0 || erase_mode > 2)
		erase_mode = 0;

	if (erase_mode == 2)      /* reset all drcs charset */
		memset(term->drcs, 0, sizeof(struct glyph_t) * DRCS_CHARS);
	else if (erase_mode == 0) /* reset selected drcs charset */
		memset(term->drcs + GLYPHS_PER_CHARSET * charset, 0, sizeof(struct glyph_t) * DRCS_CHARS);

	//if (term->drcs[charset] == NULL) /* always allocate 96 chars buffer */
		//term->drcs[charset] = ecalloc(GLYPH_PER_CHARSET, sizeof(struct glyph_t));

	decdld_parse_data(cp + 1, start_char, term->drcs + GLYPHS_PER_CHARSET * charset); /* skip final char */
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
movl $0x7b, %esi
callq 0x2100
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movups %xmm0, 0x20(%rsp)
movups %xmm0, 0x30(%rsp)
movups %xmm0, 0x40(%rsp)
movups %xmm0, 0x50(%rsp)
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x70(%rsp)
movups %xmm0, 0x80(%rsp)
testq %r15, %r15
je 0x6cb8
movq %rax, %r14
movq %r15, %rdi
callq 0x20d0
testq %rax, %rax
je 0x6cb8
xorl %ecx, %ecx
xorl %esi, %esi
xorl %edi, %edi
xorl %edx, %edx
movsbl (%r15), %r8d
leal -0x3a(%r8), %r9d
cmpl $-0xa, %r9d
jb 0x6bcc
movq %r15, %r9
jmp 0x6bcf
xorl %r9d, %r9d
testq %rdx, %rdx
cmoveq %r9, %rdx
cmpl $0x3b, %r8d
jne 0x6bfd
movb $0x0, (%r15)
cmpl $0xf, %edi
jle 0x6bea
xorl %r8d, %r8d
jmp 0x6bfb
movslq %edi, %rcx
movq %rdx, 0x10(%rsp,%rcx,8)
incl %edi
xorl %r8d, %r8d
movl %edi, %ecx
movl %edi, %esi
xorl %edx, %edx
cmpq $0x1, %rax
jne 0x6c2d
testq %rdx, %rdx
je 0x6c11
movl %esi, %edi
cmpl $0xf, %esi
jle 0x6c1f
jmp 0x6c2d
testb %r8b, %r8b
jne 0x6c29
movl %ecx, %esi
movl %ecx, %edi
cmpl $0xf, %ecx
jg 0x6c2d
movslq %esi, %rcx
movq %rdx, 0x10(%rsp,%rcx,8)
incl %ecx
movl %ecx, %esi
movl %ecx, %edi
incq %r15
decq %rax
jne 0x6bb9
cmpl $0x8, %ecx
jne 0x6cb8
movq 0x18(%rsp), %rdi
xorl %r12d, %r12d
movl $0x0, %r15d
testq %rdi, %rdi
je 0x6c5c
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d12
movq %rax, %r15
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6c75
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d12
movq %rax, %r12
incq %r14
movb (%r14), %al
movl %eax, %ecx
andb $-0x10, %cl
incq %r14
cmpb $0x20, %cl
je 0x6c78
leal -0x7f(%rax), %ecx
addb $-0x40, %al
xorl %edx, %edx
cmpb $-0x3f, %cl
movzbl %al, %eax
cmovbl %edx, %eax
movzbl %al, %r13d
cmpl $0x3, %r12d
cmovael %edx, %r12d
testl %r12d, %r12d
je 0x6cc9
cmpl $0x2, %r12d
jne 0x6ced
leaq 0x80488(%rbx), %rdi
jmp 0x6ce1
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl %r13d, %eax
shll $0x5, %eax
leal (%rax,%rax,2), %eax
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rax,8), %rdi
addq $0x80488, %rdi          # imm = 0x80488
movl $0x3b100, %edx          # imm = 0x3B100
xorl %esi, %esi
callq 0x2130
shll $0x5, %r13d
leal (%r13,%r13,2), %eax
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rax,8), %rdx
addq $0x80488, %rdx          # imm = 0x80488
movq %r14, %rdi
movl %r15d, %esi
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x6a25