From ee97876115c7e38fe29a2b3c0c34f6ec2f07ef8a Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Wed, 24 Sep 2025 00:40:56 +0200 Subject: [PATCH] Add a few toys --- Makefile | 6 +++++ add.asm | 11 +++++++++ call.asm | 35 +++++++++++++++++++++++++++++ copy.asm | 19 ++++++++++++++++ debug.asm | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dosdbt.asm | 25 +++++++++++++++++++++ format.asm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ hello.asm | 25 +++++++++++++++++++++ 8 files changed, 250 insertions(+) create mode 100644 add.asm create mode 100644 call.asm create mode 100644 copy.asm create mode 100644 debug.asm create mode 100644 dosdbt.asm create mode 100644 format.asm create mode 100644 hello.asm diff --git a/Makefile b/Makefile index 757ae34..b6f2a88 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,12 @@ binaries: ## Build all binaries docker build --build-arg TARGET=writefloppy.bin -o . --target=export . docker build --build-arg TARGET=crc16.bin -o . --target=export . docker build --build-arg TARGET=wozmon.bin -o . --target=export . + docker build --build-arg TARGET=hello.bin -o . --target=export . + docker build --build-arg TARGET=copy.bin -o . --target=export . + docker build --build-arg TARGET=call.bin -o . --target=export . + docker build --build-arg TARGET=debug.bin -o . --target=export . + docker build --build-arg TARGET=dosdbt.bin -o . --target=export . + docker build --build-arg TARGET=format.bin -o . --target=export . .PHONY: help diff --git a/add.asm b/add.asm new file mode 100644 index 0000000..8a94d1f --- /dev/null +++ b/add.asm @@ -0,0 +1,11 @@ +BITS 16 +CPU 8086 + +_start: + mov bp, sp + mov si, [bp+6] + mov ax, [si] + mov si, [bp+4] + mov dx, [si] + sub ax, dx + retf 4 diff --git a/call.asm b/call.asm new file mode 100644 index 0000000..f19d8ad --- /dev/null +++ b/call.asm @@ -0,0 +1,35 @@ +BITS 16 +CPU 8086 + +org 0x7300 + +PARAMS equ 0x7380 +; dw 0: target offset +; dw 2: target segment +; dw 4: number of params +; dw 6: param 0 +; ... + +_start: + push bx + push si + push di + push bp + mov si, PARAMS + mov bx, 0x6 + xor cx, cx +a1: + cmp cx, [es:si+4] + jge a2 + lea ax, [es:si+bx] + push ax + add bl, 2 + inc cl + jmp a1 +a2: + call far [es:si] + pop bp + pop di + pop si + pop bx + ret diff --git a/copy.asm b/copy.asm new file mode 100644 index 0000000..540752e --- /dev/null +++ b/copy.asm @@ -0,0 +1,19 @@ +BITS 16 +CPU 8086 + +main: + mov bp, sp + mov si, [bp+4] + mov cx, [si] + mov si, [bp+6] + mov di, [si] + mov si, [bp+8] + mov si, [si] + push ds + push es + pop ds + cld + rep movsw + pop ds + + retf 6 diff --git a/debug.asm b/debug.asm new file mode 100644 index 0000000..3d70e21 --- /dev/null +++ b/debug.asm @@ -0,0 +1,66 @@ +BITS 16 +CPU 8086 + +org 0x7000 + +_start: + jmp main + +hexdigits: + db "0123456789abcdef" + +putc: + push bx + push bp + mov ah, 0x0e + xor bh, bh + int 0x10 + pop bp + pop bx + ret + +printnibble: + push si + push bx + mov si, hexdigits + xor bh, bh + mov bl, al + and bl, 0xf + mov al, cs:[si+bx] + call putc + pop bx + pop si + ret + +printi8: + push bx + mov bl, al + mov cl, 4 + shr al, cl + call printnibble + mov al, bl + call printnibble + pop bx + ret + +printi16: + push bx + mov bx, ax + mov al, ah + call printi8 + mov al, bl + call printi8 + pop bx + ret + +main: + mov bp, sp + mov si, [bp+4] + mov si, [si] + mov ax, [si] + call printi16 + mov al, 0x0d + call putc + mov al, 0x0a + call putc + retf 2 diff --git a/dosdbt.asm b/dosdbt.asm new file mode 100644 index 0000000..b5e34f1 --- /dev/null +++ b/dosdbt.asm @@ -0,0 +1,25 @@ +BITS 16 +CPU 8086 + +diskpointer equ 0x1e*4 +dbtbase equ 0x100 + +_start: + jmp main + +main: + push ds + mov si, diskpointer + lds si, [si] + mov di, dbtbase + mov cx, 0x0a + cld + rep movsb + pop ds + mov al, 9 ; sectors per track + mov di, dbtbase + mov [di+4], al + mov di, diskpointer + mov [di], word dbtbase + mov [di+2], ds + retf diff --git a/format.asm b/format.asm new file mode 100644 index 0000000..6d41917 --- /dev/null +++ b/format.asm @@ -0,0 +1,63 @@ +BITS 16 +CPU 8086 + +buffer equ 0xe000 +sectors equ 9 + + +_start: + jmp main + +formattrack: + push bp + push bx + push di + mov bp, sp + push ax ; track + push cx ; head + + mov bx, buffer + xor cx, cx +l0: + cmp cl, sectors + jnl l1 + mov di, cx + and di, 0x0f ; max 15 sectors + shl di, 1 + shl di, 1 ; di = cl*4 + lea di, [bx+di] + mov al, [bp-2] ; track number + mov [di+0], al + mov al, [bp-4] ; head number + mov [di+1], al + mov al, cl ; sector number + inc al + mov [di+2], al + mov [di+3], byte 0x02 ; 512 bytes per sector + inc cl + jmp l0 + +l1: + mov ah, 0x05 ; format track + mov al, sectors + mov dl, 0 ; first drive + mov dh, [bp-4] ; head number + mov ch, [bp-2] ; track number + mov cl, 1 ; sector number (first sector?) + int 0x13 + add sp, 4 + pop di + pop bx + pop bp + ret + +main: + mov bp, sp + mov si, [bp+8] + mov ax, [si] + mov si, [bp+6] + mov cx, [si] + call formattrack + mov si, [bp+4] + mov [si], ax + retf 6 diff --git a/hello.asm b/hello.asm new file mode 100644 index 0000000..3d0f124 --- /dev/null +++ b/hello.asm @@ -0,0 +1,25 @@ +BITS 16 +CPU 8086 + +org 0x7200 + +_start: + jmp main + +hw: + db "Hello, world!", 0x0d, 0x0a, 0 + +main: + xor bx, bx + mov si, hw +printloop: + mov al, cs:[si] + test al, al + jz done + mov ah, 0x0e + int 0x10 + inc si + jmp printloop + +done: + retf