From 60d7207fdc7d9ee59157630ffa05b394f7e0be73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 9 Jul 2021 01:06:08 +0300 Subject: [PATCH] Put EttinOS programs into git --- .gitignore | 1 + CC0 | 116 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 21 +++++++++ dec2hex.asm | 87 +++++++++++++++++++++++++++++++++++ echo.asm | 6 +++ hex2dec.asm | 101 +++++++++++++++++++++++++++++++++++++++++ old_rot13.disasm | 48 ++++++++++++++++++++ rot13.asm | 38 ++++++++++++++++ 8 files changed, 418 insertions(+) create mode 100644 .gitignore create mode 100644 CC0 create mode 100644 Makefile create mode 100644 dec2hex.asm create mode 100644 echo.asm create mode 100644 hex2dec.asm create mode 100644 old_rot13.disasm create mode 100644 rot13.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/CC0 b/CC0 new file mode 100644 index 0000000..670154e --- /dev/null +++ b/CC0 @@ -0,0 +1,116 @@ +CC0 1.0 Universal + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator and +subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for the +purpose of contributing to a commons of creative, cultural and scientific +works ("Commons") that the public can reliably and without fear of later +claims of infringement build upon, modify, incorporate in other works, reuse +and redistribute as freely as possible in any form whatsoever and for any +purposes, including without limitation commercial purposes. These owners may +contribute to the Commons to promote the ideal of a free culture and the +further production of creative, cultural and scientific works, or to gain +reputation or greater distribution for their Work in part through the use and +efforts of others. + +For these and/or other purposes and motivations, and without any expectation +of additional consideration or compensation, the person associating CC0 with a +Work (the "Affirmer"), to the extent that he or she is an owner of Copyright +and Related Rights in the Work, voluntarily elects to apply CC0 to the Work +and publicly distribute the Work under its terms, with knowledge of his or her +Copyright and Related Rights in the Work and the meaning and intended legal +effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not limited +to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, communicate, + and translate a Work; + + ii. moral rights retained by the original author(s) and/or performer(s); + + iii. publicity and privacy rights pertaining to a person's image or likeness + depicted in a Work; + + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + + v. rights protecting the extraction, dissemination, use and reuse of data in + a Work; + + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation thereof, + including any amended or successor version of such directive); and + + vii. other similar, equivalent or corresponding rights throughout the world + based on applicable law or treaty, and any national implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention of, +applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and +unconditionally waives, abandons, and surrenders all of Affirmer's Copyright +and Related Rights and associated claims and causes of action, whether now +known or unknown (including existing as well as future claims and causes of +action), in the Work (i) in all territories worldwide, (ii) for the maximum +duration provided by applicable law or treaty (including future time +extensions), (iii) in any current or future medium and for any number of +copies, and (iv) for any purpose whatsoever, including without limitation +commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes +the Waiver for the benefit of each member of the public at large and to the +detriment of Affirmer's heirs and successors, fully intending that such Waiver +shall not be subject to revocation, rescission, cancellation, termination, or +any other legal or equitable action to disrupt the quiet enjoyment of the Work +by the public as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason be +judged legally invalid or ineffective under applicable law, then the Waiver +shall be preserved to the maximum extent permitted taking into account +Affirmer's express Statement of Purpose. In addition, to the extent the Waiver +is so judged Affirmer hereby grants to each affected person a royalty-free, +non transferable, non sublicensable, non exclusive, irrevocable and +unconditional license to exercise Affirmer's Copyright and Related Rights in +the Work (i) in all territories worldwide, (ii) for the maximum duration +provided by applicable law or treaty (including future time extensions), (iii) +in any current or future medium and for any number of copies, and (iv) for any +purpose whatsoever, including without limitation commercial, advertising or +promotional purposes (the "License"). The License shall be deemed effective as +of the date CC0 was applied by Affirmer to the Work. Should any part of the +License for any reason be judged legally invalid or ineffective under +applicable law, such partial invalidity or ineffectiveness shall not +invalidate the remainder of the License, and in such case Affirmer hereby +affirms that he or she will not (i) exercise any of his or her remaining +Copyright and Related Rights in the Work or (ii) assert any associated claims +and causes of action with respect to the Work, in either case contrary to +Affirmer's express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + + b. Affirmer offers the Work as-is and makes no representations or warranties + of any kind concerning the Work, express, implied, statutory or otherwise, + including without limitation warranties of title, merchantability, fitness + for a particular purpose, non infringement, or the absence of latent or + other defects, accuracy, or the present or absence of errors, whether or not + discoverable, all to the greatest extent permissible under applicable law. + + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without limitation + any person's Copyright and Related Rights in the Work. Further, Affirmer + disclaims responsibility for obtaining any necessary consents, permissions + or other rights required for any use of the Work. + + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to this + CC0 or use of the Work. + +For more information, please see + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d8ed1c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +OLDBINS = echo.bin +BINS = dec2hex.bin hex2dec.bin echo.bin rot13.bin + +.SUFFIXES: +.SUFFIXES: .asm .bin + +most: $(BINS) + +all: $(BINS) $(OLDBINS) + +.asm.bin: + nasm -fbin -o $@ $< + +clean: + rm -f *.bin + +install: $(BINS) + @test -n "$(DISKIMG)" || { echo "DISKIMG not set, point at EttinOS disk image." >&2; exit 1; } + mcopy -o -i "$(DISKIMG)" $(BINS) :: + +.PHONY: all clean diff --git a/dec2hex.asm b/dec2hex.asm new file mode 100644 index 0000000..7217a30 --- /dev/null +++ b/dec2hex.asm @@ -0,0 +1,87 @@ +cpu 8086 +org 0x3000 + +xor dx, dx + +cmp byte [si], 0 +jne atoi + +mov ah, 2 +mov si, overflow_msg +int 0x21 +int 0x20 + +atoi: + lodsb + + cmp al, 0 + je .end + + cmp al, '0' + jl .notdigit + + cmp al, '9' + jg .notdigit + + xor ah, ah + sub al, '0' + mov cx, ax + + mov ax, dx + mul word [ten] + test dx, dx + jnz .overflow + + mov dx, ax + add dx, cx + jc .overflow + + jmp atoi + + .notdigit: + mov byte [char_slot], al + mov si, notdigit_msg + mov ah, 2 + int 0x21 + int 0x20 + + .overflow: + mov si, overflow_msg + mov ah, 2 + int 0x21 + int 0x20 + + .end: + +std +mov di, hexstring+3 +xor bh, bh +mov cx, 4 +itoh: + mov bl, 0xf + and bl, dl + mov al, [hexdigits + bx] + stosb + + shr dx, 1 + shr dx, 1 + shr dx, 1 + shr dx, 1 + + loop itoh + +cld + +mov si, hexstring +mov ah, 2 +int 0x21 +int 0x20 + +notdigit_msg db "Not a digit '" +char_slot db 0, "'", 0 +overflow_msg db "Value must be in range 0 to 65535", 0 + +hexstring db "xxxx", 0 + +hexdigits db "0123456789abcdef" +ten dw 10 diff --git a/echo.asm b/echo.asm new file mode 100644 index 0000000..4b03226 --- /dev/null +++ b/echo.asm @@ -0,0 +1,6 @@ +org 0x3000 + +mov ah, 2 +int 0x21 + +int 0x20 diff --git a/hex2dec.asm b/hex2dec.asm new file mode 100644 index 0000000..b2e6fa0 --- /dev/null +++ b/hex2dec.asm @@ -0,0 +1,101 @@ +cpu 8086 +org 0x3000 + +xor dx, dx + +cmp byte [si], 0 +jne htoi + +mov ah, 2 +mov si, overflow_msg +int 0x21 +int 0x20 + +htoi: + lodsb + + cmp al, 0 + je .end + + .digit09: + cmp al, '0' + jl .notdigit + + cmp al, '9' + jg .digitcapital + + sub al, '0' + jmp .digit + + .digitcapital: + cmp al, 'A' + jl .notdigit + + cmp al, 'F' + jg .digitminuscule + + sub al, 'A' - 10 + jmp .digit + + .digitminuscule: + cmp al, 'a' + jl .notdigit + + cmp al, 'f' + jg .notdigit + + sub al, 'a' - 10 + jmp .digit + + .digit: + xor ah, ah + + test dx, 0xf000 + jnz .overflow + + shl dx, 1 + shl dx, 1 + shl dx, 1 + shl dx, 1 + or dx, ax + + jmp htoi + + .notdigit: + mov byte [char_slot], al + mov si, notdigit_msg + mov ah, 2 + int 0x21 + int 0x20 + + .overflow: + mov si, overflow_msg + mov ah, 2 + int 0x21 + int 0x20 + + .end: + +mov si, decimalstring + 5 +mov ax, dx +itoa: + dec si + xor dx, dx + div word [ten] + add dl, '0' + mov byte [si], dl + + test ax, ax + jnz itoa + +mov ah, 2 +int 0x21 +int 0x20 + +notdigit_msg db "Not a digit '" +char_slot db 0, "'", 0 +overflow_msg db "Value must be in range 0 to ffff", 0 + +decimalstring db "xxxxx", 0 + +ten dw 10 diff --git a/old_rot13.disasm b/old_rot13.disasm new file mode 100644 index 0000000..85d929a --- /dev/null +++ b/old_rot13.disasm @@ -0,0 +1,48 @@ +; Recreation from disassembly, changing org 0x2000 to 0x3000 should produce +; a binary runnable on current (as of 2021-07-09) EttinOS +cpu 8086 +org 0x2000 + +mov ah, 3 +mov al, 255 +mov di, buffer +int 0x21 + +mov bx, buffer + +rotloop: + cmp byte [bx], 0 + jz .end + + cmp byte [bx], 'A' + jl .next + cmp byte [bx], 'M' + jle .inc + cmp byte [bx], 'Z' + jle .dec + + cmp byte [bx], 'a' + jl .next + cmp byte [bx], 'm' + jle .inc + cmp byte [bx], 'z' + jle .dec + + .next: + inc bx + jmp short rotloop + + .inc: + add byte [bx], 13 + jmp short .next + .dec: + sub byte [bx], 13 + jmp short .next + .end: + +mov ah, 2 +mov si, buffer +int 0x21 +int 0x20 + +buffer: diff --git a/rot13.asm b/rot13.asm new file mode 100644 index 0000000..daabf11 --- /dev/null +++ b/rot13.asm @@ -0,0 +1,38 @@ +cpu 8086 +org 0x3000 + +mov bx, si + +rotloop: + cmp byte [bx], 0 + jz .end + + cmp byte [bx], 'A' + jl .next + cmp byte [bx], 'M' + jle .inc + cmp byte [bx], 'Z' + jle .dec + + cmp byte [bx], 'a' + jl .next + cmp byte [bx], 'm' + jle .inc + cmp byte [bx], 'z' + jle .dec + + .next: + inc bx + jmp short rotloop + + .inc: + add byte [bx], 13 + jmp short .next + .dec: + sub byte [bx], 13 + jmp short .next + .end: + +mov ah, 2 +int 0x21 +int 0x20