Add a few toys

This commit is contained in:
2025-09-24 00:40:56 +02:00
parent 9daf8d7f97
commit ee97876115
8 changed files with 250 additions and 0 deletions

View File

@@ -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

11
add.asm Normal file
View File

@@ -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

35
call.asm Normal file
View File

@@ -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

19
copy.asm Normal file
View File

@@ -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

66
debug.asm Normal file
View File

@@ -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

25
dosdbt.asm Normal file
View File

@@ -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

63
format.asm Normal file
View File

@@ -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

25
hello.asm Normal file
View File

@@ -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