diff --git a/xscii.asm b/xscii.asm new file mode 100644 index 0000000..f6ee997 --- /dev/null +++ b/xscii.asm @@ -0,0 +1,233 @@ +EFFECT_NORMAL = '0' +EFFECT_BOLD = '1' +EFFECT_ITALIC = '3' +EFFECT_UNDERLINE = '4' +EFFECT_BLINK = '5' +EFFECT_REVERSE = '7' +COLOUR_GREY = '0' +COLOUR_RED = '1' +COLOUR_GREEN = '2' +COLOUR_YELLOW = '3' +COLOUR_BLUE = '4' +COLOUR_PINK = '5' +COLOUR_CYAN = '6' +COLOUR_WHITE = '7' + +macro output_number number, base, offset, character, colour, effect { + call output_bar + mov rbx, colour + mov rbp, effect + call output_colour + mov rbx, number + mov rbp, base + call offset_base + mov rbx, offset + sub rbx, [output_length] + mov rbp, character + call output_align + call output_base + call output_cancel +} + +format ELF64 executable 3 + +segment readable executable + +entry $ + main_loop: + output_number [character_index], 2, 8, align_zero, COLOUR_WHITE, EFFECT_NORMAL + output_number [character_index], 8, 4, align_zero, COLOUR_CYAN, EFFECT_NORMAL + output_number [character_index], 10, 4, align_space, COLOUR_CYAN, EFFECT_ITALIC + output_number [character_index], 16, 3, align_space, COLOUR_CYAN, EFFECT_BOLD + + call output_bar + mov rbx, COLOUR_BLUE + mov rbp, EFFECT_BOLD + call output_colour + mov rbx, [character_index] + call output_code + call output_cancel + + call output_bar + mov rbx, COLOUR_PINK + mov rbp, EFFECT_NORMAL + call output_colour + mov rbx, [character_index] + call output_name + call output_cancel + + mov rax, [character_index] + and rax, 1 + ;~mov rbx, 2 + ;~div rbx + ;~cmp rdx, 0 + cmp rax, 0 + je skip_line + mov rbx, align_line + mov rbp, 1 + call output_string + skip_line: + + inc [character_index] + cmp [character_index], 128 + jne main_loop + + mov rdi, 0 + mov rax, 60 + syscall + +output_string: + mov rax, 1 + mov rdi, 1 + mov rsi, rbx; string + mov rdx, rbp; length + syscall + ret + +output_colour: + mov [output_colour_format + 5], bl; effect + mov [output_colour_format + 2], bpl; colour + mov rbx, output_colour_format + mov rbp, 7 + call output_string + ret + +output_cancel: + mov rbx, output_colour_cancel + mov rbp, 4 + call output_string + ret + +output_align: + mov r15, rbx; count + mov r14, rbp; align + loop_statement: + mov rbx, r14 + mov rbp, 1 + call output_string + dec r15 + cmp r15, 0 + jne loop_statement + ret + +output_bar: + mov rbx, COLOUR_GREY + mov rbp, EFFECT_BOLD + call output_colour + mov rbx, align_bar + mov rbp, 3 + call output_string + call output_cancel + ret + +offset_base: + mov ax, bx + ;~mov [output_length], 0 + number_loop_statement: + div bpl + mov [output_quotient], al; code / base + mov [output_remainder], ah; code % base + mov r14, output_format + add r14, [output_length] + mov r15, output_cypher + add r15b, [output_remainder] + mov r13b, BYTE [r15] + mov BYTE [r14], r13b + xor rax, rax + mov al, [output_quotient] + inc [output_length] + cmp [output_quotient], 0 + jne number_loop_statement + ret + +output_base: + output_loop_statement: + mov rbx, output_format + add rbx, [output_length] + dec rbx + mov rbp, 1 + call output_string + dec [output_length] + cmp [output_length], 0 + jne output_loop_statement + ret + +output_code: + mov rax, rbx + mov rbx, 3 + mul rbx + mov rbx, code_list + add rbx, rax + mov rbp, 3 + call output_string + ret + +output_name: + mov rax, rbx + mov rbx, 24 + mul rbx + mov rbx, name_list + add rbx, rax + mov rbp, 24 + call output_string + ret + +segment readable writable + +character_index dq 0 + +align_zero db '0' +align_line db 10 +align_space db ' ' +align_bar db ' | ' + +output_cypher db '0123456789ABCDEF' +output_format db ' ' +output_length dq 0 +output_quotient db 0 +output_remainder db 0 + +output_colour_format db 27, '[ ;3 m' +output_colour_cancel db 27, '[0m' + +code_list db 'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS ', 'HT ', 'LF ', 'VT ', 'FF ', 'CR ', 'SO ', 'SI ', \ + 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM ', 'SUB', 'ESC', 'FS ', 'GS ', 'RS ', 'US ', \ + ' ', '! ', '" ', '# ', '$ ', '% ', '& ',39,' ','( ', ') ', '* ', '+ ', ', ', '- ', '. ', '/ ', \ + '0 ', '1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ', ': ', '; ', '< ', '= ', '> ', '? ', \ + '@ ', 'A ', 'B ', 'C ', 'D ', 'E ', 'F ', 'G ', 'H ', 'I ', 'J ', 'K ', 'L ', 'M ', 'N ', 'O ', \ + 'P ', 'Q ', 'R ', 'S ', 'T ', 'U ', 'V ', 'W ', 'X ', 'Y ', 'Z ', '[ ', '\ ', '] ', '^ ', '_ ', \ + '` ', 'a ', 'b ', 'c ', 'd ', 'e ', 'f ', 'g ', 'h ', 'i ', 'j ', 'k ', 'l ', 'm ', 'n ', 'o ', \ + 'p ', 'q ', 'r ', 's ', 't ', 'u ', 'v ', 'w ', 'x ', 'y ', 'z ', '{ ', '| ', '} ', '~ ', 'DEL' + +name_list db 'Null ', 'Start of heading ', 'Start of text ', 'End of text ', \ + 'End of transmission ', 'Enquiry ', 'Acknowledge ', 'Bell ', \ + 'Backspace ', 'Horizontal tab ', 'Line feed ', 'Vertical tab ', \ + 'Form feed ', 'Carriage return ', 'Shift out ', 'Shift in ', \ + 'Data link escape ', 'Device control 1 ', 'Device control 2 ', 'Device control 3 ', \ + 'Device control 4 ', 'Negative acknowledge ', 'Synchronous idle ', 'End transmission block ', \ + 'Cancel ', 'End of medium ', 'Substitute ', 'Escape ', \ + 'File separator ', 'Group separator ', 'Record separator ', 'Unit separator ', \ + 'Space ', 'Exclamation mark ', 'Speech mark ', 'Number sign ', \ + 'Dollar sign ', 'Percent ', 'Ampersand ', 'Quote ', \ + 'Open parenthesis ', 'Close parenthesis ', 'Asterisk ', 'Plus ', \ + 'Comma ', 'Minus ', 'Period ', 'Slash ', \ + 'Zero ', 'One ', 'Two ', 'Three ', \ + 'Four ', 'Five ', 'Six ', 'Seven ', \ + 'Eight ', 'Nine ', 'Colon ', 'Semicolon ', \ + 'Open angled bracket ', 'Equal ', 'Close angled bracket ', 'Question mark ', \ + 'At sign ', 'Uppercase A ', 'Uppercase B ', 'Uppercase C ', \ + 'Uppercase D ', 'Uppercase E ', 'Uppercase F ', 'Uppercase G ', \ + 'Uppercase H ', 'Uppercase I ', 'Uppercase J ', 'Uppercase K ', \ + 'Uppercase L ', 'Uppercase M ', 'Uppercase N ', 'Uppercase O ', \ + 'Uppercase P ', 'Uppercase Q ', 'Uppercase R ', 'Uppercase S ', \ + 'Uppercase T ', 'Uppercase U ', 'Uppercase V ', 'Uppercase W ', \ + 'Uppercase X ', 'Uppercase Y ', 'Uppercase Z ', 'Opening bracket ', \ + 'Backslash ', 'Closing bracket ', 'Caret ', 'Underscore ', \ + 'Grave ', 'Lowercase a ', 'Lowercase b ', 'Lowercase c ', \ + 'Lowercase d ', 'Lowercase e ', 'Lowercase f ', 'Lowercase g ', \ + 'Lowercase h ', 'Lowercase i ', 'Lowercase j ', 'Lowercase k ', \ + 'Lowercase l ', 'Lowercase m ', 'Lowercase n ', 'Lowercase o ', \ + 'Lowercase p ', 'Lowercase q ', 'Lowercase r ', 'Lowercase s ', \ + 'Lowercase t ', 'Lowercase u ', 'Lowercase v ', 'Lowercase w ', \ + 'Lowercase x ', 'Lowercase y ', 'Lowercase z ', 'Opening brace ', \ + 'Vertical bar ', 'Closing brace ', 'Tilde ', 'Delete '