69 lines
1017 B
NASM
69 lines
1017 B
NASM
; First MCB block is always at 00540
|
|
mcb_first:
|
|
mov ax, 0x54
|
|
mov ds, ax
|
|
ret
|
|
|
|
mcb_init:
|
|
call mcb_first
|
|
mov dx, ds
|
|
inc dx
|
|
xor si, si
|
|
int 0x12
|
|
mov cl, 6
|
|
shl ax, cl
|
|
sub ax, dx
|
|
mov byte [si+0], 'Z'
|
|
mov word [si+1], 0
|
|
mov word [si+3], ax
|
|
mov dx, cs
|
|
call mcb_split
|
|
mov word [si+1], 8
|
|
ret
|
|
|
|
; split mcb block into two
|
|
; IN dx segment of second block
|
|
mcb_split:
|
|
call mcb_find
|
|
dec dx
|
|
; Calculate size of first block
|
|
; dx = dx - ds - 1
|
|
stc
|
|
mov ax, ds
|
|
sbb dx, ax
|
|
;
|
|
push dx
|
|
; swap old size with new size
|
|
xchg dx, [si+3]
|
|
; if current mcb is last, its not anymore
|
|
mov cl, 'M'
|
|
xchg cl, byte [si+0]
|
|
; advance DS to begin of first block
|
|
pop ax
|
|
mov ds, ax
|
|
stc
|
|
sbb dx, ax
|
|
; write MCB data
|
|
mov byte [si+0], cl
|
|
mov word [si+1], 0
|
|
mov word [si+3], dx
|
|
ret
|
|
|
|
; IN dx segment we look for
|
|
; OUT ds segment where mcb starts
|
|
mcb_find:
|
|
call mcb_first
|
|
xor si, si
|
|
.loop: stc
|
|
adc ax, [si+3]
|
|
cmp dx, ax
|
|
jc .found
|
|
cmp byte [si+0], 'Z'
|
|
jz .fail
|
|
mov ds, ax
|
|
jmp .loop
|
|
.fail: stc
|
|
ret
|
|
.found: clc
|
|
ret
|