Category : Miscellaneous Language Source Code
Archive   : BDISK10.ZIP
Filename : TRKFRM.ASM

 
Output of file : TRKFRM.ASM contained in archive : BDISK10.ZIP
DOSSEG
.MODEL medium

PUBLIC _TrkFrm

;========================================================
; Format a disk track. The usage is:
;
; push ;drive number
; push ;head (side) number
; push ;track number
; push ;number of sectors per track
; push ;number of bytes per sector
; call _TrkFrm ;format
;
; The values are not checked, except the number of
; sectors, which must be 0 > sectors >= MAXSEC. AX = 0
; if no errors, otherwise AH = 00 and AL = disk status
; if BIOS error, or AX = 0100 if invalid number of
; sectors.
;
; The stack is cleared on exit and all registers are
; preserved except AX.

MAXSEC EQU 64

.DATA?

TrkAdr Db (MAXSEC * 4) DUP (?)

TrkFrmStk STRUC
registers dw 7 DUP (?)
retaddr dw 2 DUP (?)
bytes dw ?
sectors dw ?
track dw ?
head dw ?
drive dw ?
TrkFrmStk ENDS

ASSUME ds:NOTHING, es:@DATA, ss:NOTHING

.CODE

EXTRN _SctrSz:far

_TrkFrm PROC
push bx
push cx
push dx
push di
push si
push bp
push es
mov bp, sp

mov cx, [bp].sectors ;get sector count
or cx, cx ;check if none
jz Trfr2
cmp cx, MAXSEC ;check if too many
ja Trfr2

;--- set the sector size byte

mov ax, [bp].bytes ;bytes per sector
call _SctrSz ;get sector size
mov byte ptr [bp].bytes, al ;save

;--- set up track address fields

mov ax, @DATA
mov es, ax ;set segment
lea di, TrkAdr ;track addresses
push di
sub ah, ah ;initial sector count
mov dh, byte ptr [bp].head ;get head number
mov dl, byte ptr [bp].track ;get track number

Trfr1: mov al, dl ;track number
stosb
mov al, dh ;head number
stosb
inc ah ;increment sector
mov al, ah ;sector number
stosb
mov al, byte ptr [bp].bytes ;bytes per sector
stosb
loop Trfr1

;--- format track

pop bx ;restore address list
mov ch, dl ;track number
mov dl, byte ptr [bp].drive ;drive number

push bp
push es
mov ah, 5 ;format function
int 13h ;execute
pop es
pop bp
jnc Trfr3 ;jump if okay

;--- error, reset disk and try again

push bp
push es
mov ah, 0 ;reset function
int 13h ;execute
pop es
pop bp

push bp
push es
mov ah, 5 ;format function
int 13h ;execute
pop es
pop bp
jnc Trfr3 ;jump if okay

;--- error formatting track

mov al, ah
sub ah, ah
jmp Trfr4

;--- illegal parameters or something

Trfr2: mov ax, 100h ;set first bit
jmp Trfr4

;--- track is formatted okay

Trfr3: sub ax, ax

Trfr4: pop es
pop bp
pop si
pop di
pop dx
pop cx
pop bx
ret 10
_TrkFrm ENDP

END


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : BDISK10.ZIP
Filename : TRKFRM.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/