From 104d47e1a6f62c9f6418ba08ae74828766990c30 Mon Sep 17 00:00:00 2001 From: snow flurry Date: Mon, 15 Dec 2025 20:33:00 -0800 Subject: [PATCH] Initial commit --- README.md | 11 +++++++ dosbox.asm | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 README.md create mode 100644 dosbox.asm diff --git a/README.md b/README.md new file mode 100644 index 0000000..59aac44 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# DOS Tests + +Small COM programs to check quirks or functions of various DOSen to test which +type they might be. + +Information on compiling them is available in the contents of each file. + +## dosbox.asm + +Tests for a special opcode only implemented on DOSBox (to my knowledge!). More +info here: [https://datagirl.xyz/posts/dos_inside_the_box.html] diff --git a/dosbox.asm b/dosbox.asm new file mode 100644 index 0000000..b101340 --- /dev/null +++ b/dosbox.asm @@ -0,0 +1,91 @@ +org 100h +bits 16 + +section .text +jmp _start + +yesDosbox db "Yep, that is a DOSBox!",0dh,0ah,'$' +noDosbox db "Probably not a DOSBox.",0dh,0ah,'$' + +oldUDAddr dw 0 +oldUDSeg dw 0 + +isDosbox db 1 + +_catchUD: + push ax + push bx + + mov bx, sp + mov bx, WORD [ss:bx+4] + mov ax, bx + + mov bx, WORD [cs:bx] + and bh, 38h ; Keep only the opcode bits + cmp bx, 38feh ; little-endian FE 38 + je .notDosbox + ; uhh, we shouldn't end up here. clean up the IVT and IRET so the actual + ; #UD handler is called. + push es + xor ax, ax + mov es, ax + mov bx, [oldUDAddr] + mov [es:18h], bx + mov bx, [oldUDSeg] + mov [es:1ah], bx + pop es + jmp .catchDone + + .notDosbox: + ; Not DOSBox -- increment the IP and unset the flag + add ax, 4 + mov bx, sp + mov WORD [ss:bx+4], ax + mov [isDosbox], 0 + + .catchDone: + pop bx + pop ax + iret + +_start: + push es + ; store the old #UD... + xor ax, ax + mov es, ax + mov bx, [es:18h] + mov [oldUDAddr], bx + mov bx, [es:1ah] + mov [oldUDSeg], bx + ; ... and set the new #UD handler + mov bx, cs + mov [es:1ah], bx + mov bx, _catchUD + mov [es:18h], bx + pop es + + ; DOSBoxCB 0x0000 + db 0xfe, 0x38, 0x00, 0x00 + mov ax, [isDosbox] + cmp ax, 0 + jz .notDosbox + mov dx, yesDosbox + jmp .printAndQuit + .notDosbox: + mov dx, noDosbox + .printAndQuit: + mov ah, 09h + int 21h + + ; restore the old #UD handler + push es + xor ax, ax + mov es, ax + mov [es:1ah], oldUDSeg + mov [es:18h], oldUDAddr + pop ax + + ; and we're done! + mov ax, 4c00h + int 21h + hlt