Category : Modula II Source Code
Archive   : FIOASM.ZIP
Filename : FIOASM.A

 
Output of file : FIOASM.A contained in archive : FIOASM.ZIP
module FioAsm

(*
File input-output routines for JPI Modula-2
by Carl Neiburger
169 N. 25th St.
San Jose, Calif. 95116

CompuServe No. 72336,2257

These routines are intended to replace low-level routines in JPI's FIO.MOD.
FioAsm's routines are optimized through assembly language.
*)

segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public @path: org 65

public @ToPath: (* on entry, ds:si are string to copy *)
push es; push di (* and cx is length *)
cmp cx, 64 (* is string too long? *)
jb ToPath1
mov cx, 64 (* then truncate *)
ToPath1:
push cs
pop es
mov di,@path
xor al,al (* search for 0 *)
repne
movsb (* move it *)
push cs
pop ds
mov dx,@path
mov byte [di],0 (* add zero *)
ToPath2:
pop di; pop es
ret near 0

segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public @IOR: dw 0

public @SetIorBool :
jnc SetOK
mov cs:[@IOR],ax
xor ax, ax
ret near 0
SetOK:
mov word cs:[@IOR],0
mov ax, 1
ret near 0

public FioAsm$IOresult:
mov ax, cs:[@IOR]
mov word cs:[@IOR],0
ret far 0

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR
extrn @ToPath

public FioAsm$Create : CrNamLen = 10; CrNamSeg = 8; CrNamOfs = 6;
push bp; mov bp,sp
push ds; push si
lds si, [bp][CrNamOfs]
mov cx, [bp][CrNamLen]
call near @ToPath
mov ah, 3CH (* create file *)
xor cx, cx (* no attribute *)
int 21H
jnc CrRet (* handle is in ax *)
mov cs:[@IOR],ax (* error is in ax *)
xor ax,ax
not ax (* return MAX(CARDINAL) *)
CrRet:
pop si; pop ds
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR
extrn @ToPath

public FioAsm$Open : OpNamLen = 12; OpNamSeg = 10; OpNamOfs = 8; OpType = 6;
push bp; mov bp,sp
push ds; push si
lds si, [bp][OpNamOfs]
mov cx, [bp][OpNamLen]
call near @ToPath
mov ah, 3DH (* open file *)
mov al, [bp][OpType]
int 21H
jnc OpRet (* handle is in ax *)
mov cs:[@IOR],ax (* error is in ax *)
xor ax,ax
not ax (* return MAX(CARDINAL) *)
OpRet:
pop si; pop ds
pop bp; ret far 8

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool

public FioAsm$Close : ClFile = 6;
push bp; mov bp,sp
mov bx, [bp][ClFile]
mov ah, 3EH (* close file *)
int 21H
call near @SetIorBool
pop bp; ret far 2

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool

public FioAsm$Truncate : TrFile = 6;
push bp; mov bp,sp
mov bx, [bp][TrFile]
mov ah, 40H (* write *)
xor cx, cx
int 21H
call near @SetIorBool
pop bp; ret far 2

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$Read : ReFile = 14; ReBufLen = 12;
ReBufSeg = 10; ReBufOfs = 8; ReCount = 6;
push bp; mov bp,sp
push ds;
lds dx, [bp][ReBufOfs]
mov cx, [bp][ReCount]
mov bx, [bp][ReFile]
mov ah, 3FH (* read file *)
int 21H
jnc ReRet (* bytes read are ax *)
mov cs:[@IOR],ax (* error is in ax *)
xor ax,ax (* if error, return zero *)
ReRet:
pop ds
pop bp; ret far 10

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$Write : WrFile = 14; WrBufLen = 12;
WrBufSeg = 10; WrBufOfs = 8; WrCount = 6;
push bp; mov bp,sp
push ds;
lds dx, [bp][WrBufOfs]
mov cx, [bp][WrCount]
mov bx, [bp][WrFile]
mov ah, 40H (* write file *)
int 21H
jnc WrRet (* bytes written are in ax *)
mov cs:[@IOR],ax (* error is in ax *)
xor ax,ax (* if error, return zero *)
WrRet:
pop ds
pop bp; ret far 10

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool
extrn @ToPath

public FioAsm$Rename : OldLen = 16; OldSeg = 14; OldOfs = 12;
NewLen = 10; NewSeg = 8; NewOfs = 6;
push bp; mov bp,sp
push ds; push si; push es; push di;
lds si,[bp][NewOfs]
mov cx,[bp][NewLen]
xor ax, ax
push ax (* zero to terminate string *)
sub sp,cx (* make room for string *)
push ss
pop es
mov di,sp
rep
movsb (* move it *)
mov di,sp (* point back to string start *)
lds si, [bp][OldOfs]
mov cx, [bp][OldLen]
call near @ToPath (* point ds:dx to old name *)
mov ah, 56H (* rename *)
int 21H
add sp,[bp][NewLen] (* restore stack pointer *)
pop si (* and zero at end *)
call near @SetIorBool
pop di; pop es; pop si; pop ds
pop bp; ret far 12

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$GetDrive:
mov ah, 19H (* get drive *)
int 21H
inc al (* bump A up to 1, etc *)
ret far 0

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn FioAsm$GetDrive

public FioAsm$Drives:
call far FioAsm$GetDrive
dec al (* A = 0 in this case *)
mov dl, al
mov ah, 0EH (* number of drives *)
int 21H
ret far 0

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn FioAsm$Drives
extrn @SetIorBool

public FioAsm$SetDrive:
push bp; mov bp,sp
call far FioAsm$Drives (* how many are there? *)
mov dl, [bp][6]
cmp al,dl (* does requested drive exist? *)
jl SDerr (* if so, forget it *)
mov ah, 0EH (* set drive *)
dec dl
int 21H
clc
jmp SDret
SDerr:
mov ax,15
stc
SDret:
call near @SetIorBool
pop bp
ret far 2

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$SetVerify: SVon = 6
push bp; mov bp,sp
xor dl, dl
mov al, [bp][SVon]
mov ah, 2EH (* number of drives *)
int 21H
pop bp
ret far 2

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$VerifyIsOn:
mov ah, 54H (* number of drives *)
int 21H
ret far 0

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool
extrn @ToPath

public FioAsm$SetFileAttribute : Attr = 12; FNLen = 10; FNSeg = 8; FNOfs = 6;
push bp; mov bp,sp
push ds; push si
lds si, [bp][FNOfs]
mov cx, [bp][FNLen]
call near @ToPath
mov cx, [bp][Attr]
mov ax, 4301H
int 21H
call near @SetIorBool
pop si; pop ds
pop bp; ret far 8

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR
extrn @ToPath

public FioAsm$GetFileAttribute : FNLen = 10; FNSeg = 8; FNOfs = 6;
push bp; mov bp,sp
push ds; push si
lds si, [bp][FNOfs]
mov cx, [bp][FNLen]
call near @ToPath
mov ax, 4300H
int 21H
jnc GAtOK
mov cs:[@IOR],ax (* error is in ax *)
mov ax, 40H (* attribute = ioerror *)
jmp GAtRet
GAtOK:
mov ax, cx (* return attributes *)
GAtRet:
pop si; pop ds
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$FileTime : Fi = 6;
push bp; mov bp,sp
mov bx, [bp][Fi]
mov ax, 5700H
int 21H
jnc TimeOK
xor ax, ax (* we goofed; no time *)
xor dx, dx

mov cs:[@IOR],ax (* error is in ax *)
jmp TimeRet
TimeOK:
mov ax, cx (* return low byte in ax; high is in dx already *)
TimeRet:
pop bp; ret far 2

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool

public FioAsm$SetFileTime : Fi = 10; HiTime = 8; LoTime = 6;
push bp; mov bp,sp
mov ax, 5701H
mov bx, [bp][Fi]
mov cx, [bp][LoTime]
mov dx, [bp][HiTime]
int 21H
call near @SetIorBool
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$DecodeFileTime : PackedDate = 12; PackedTime = 10;
DTSeg = 8; DTOfs = 6;
DYear = 0; DMonth = 2; DDay = 4; DHours = 6; DMins = 8; DSecs = 10;
push bp; mov bp,sp
push ds; push di
lds di, [bp][DTOfs]
mov ax, [bp][PackedDate]
push ax
and ax, 1FH
mov [di][DDay], ax
pop ax
mov cx, 5
shr ax, cx
push ax
and ax, 0FH
mov [di][DMonth], ax
pop ax
mov cx, 4
shr ax, cx
add ax, 1980
mov [di][DYear], ax

mov ax, [bp][PackedTime]
push ax
and ax, 1FH
shl ax, 1
mov [di][DSecs], ax
pop ax
mov cx, 5
shr ax, cx
push ax
and ax, 3FH
mov [di][DMins], ax
pop ax
mov cx, 6
shr ax, cx
mov [di][DHours], ax
pop di; pop ds
pop bp; ret far 8

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$EncodeFileTime :
Year = 6; Month = 8; Day = 10; Hours = 12; Mins = 14; Secs = 16;
push bp; mov bp,sp
mov ax, [bp][Year]
sub ax, 1980
mov cx, 4
shl ax, cx
add al, [bp][Month]
mov cx, 5
shl ax, cx
add al, [bp][Day]
mov dx, ax
mov ax, [bp][Hours]
mov cx, 6
shl ax, cx
add al, [bp][Mins]
mov cx, 5
shl ax, cx
mov bx, ax
mov ax, [bp][Secs]
shr ax, 1
add ax, bx
pop bp; ret far 12

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$GetDir : GDrive = 12; GDLen = 10; GDSeg = 8; GDOfs = 6;
push bp; mov bp,sp
push ds; push si;
lds si, [bp][GDOfs]
mov dl, [bp][GDrive]
mov ah, 47H (* getdir *)
int 21H
jnc GDRet
mov byte [si], 0 (* set string = 0C *)
GDRet:
pop si; pop ds
pop bp; ret far 8

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @SetIorBool
extrn @ToPath

public FioAsm$Erase :
mov ah, 41H (* erase file *)
jmp Act

public FioAsm$RmDir :
mov ah, 3AH (* rmDir *)
jmp Act

public FioAsm$MkDir :
mov ah, 39H (* mkDir *)
jmp Act

public FioAsm$ChDir :
mov ah, 3BH (* chDir *)

Act: ActLen = 10; ActNamSeg = 8; ActNamOfs = 6;
push bp; mov bp,sp
push ds; push si
lds si, [bp][ActNamOfs]
mov cx, [bp][ActLen]
call near @ToPath
int 21H
call near @SetIorBool
pop si; pop ds
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$Seek : SeekFile = 14; SeekHi = 12; SeekLo = 10;
SeekOKSeg = 8; SeekOKOfs = 6
push bp; mov bp,sp
push ds; push di;
lds di, [bp][SeekOKOfs]
mov dx, [bp][SeekLo]
mov cx, [bp][SeekHi]
mov bx, [bp][SeekFile]
mov ax, 4200H (* seek absolute *)
int 21H
jnc SeekGood
mov cs:[@IOR],ax (* error is in ax *)
mov byte [di],0 (* OK false *)
jmp SeekRet
SeekGood:
mov byte [di],1
SeekRet:
pop di; pop ds
pop bp; ret far 10

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$SeekRel : SeekFile = 14; SeekHi = 12; SeekLo = 10;
SeekOKSeg = 8; SeekOKOfs = 6
push bp; mov bp,sp
push ds; push di;
lds di, [bp][SeekOKOfs]
mov dx, [bp][SeekLo]
mov cx, [bp][SeekHi]
mov bx, [bp][SeekFile]
mov ax, 4201H (* seek relativee *)
int 21H
jnc SeekRelGood
mov cs:[@IOR],ax (* error is in ax *)
mov byte [di],0 (* OK false *)
jmp SeekRelRet
SeekRelGood:
mov byte [di],1
SeekRelRet:
pop di; pop ds
pop bp; ret far 10

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$GetPos : GetFile = 10; GetOKSeg = 8; GetOKOfs = 6
push bp; mov bp,sp
push ds; push di;
lds di, [bp][GetOKOfs]
xor dx,dx (* no offset *)
xor cx,cx
mov bx, [bp][GetFile]
mov ax, 4201H (* seek relative *)
int 21H
jnc GetGood
mov cs:[@IOR],ax (* error is in ax *)
mov byte [di],0 (* OK false *)
jmp GetRet
GetGood:
mov byte [di],1
GetRet:
pop di; pop ds
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$SeekEOF : SEOFFile = 10; SEOFokSeg = 8; SEOFokOfs = 6
push bp; mov bp,sp
push ds; push di;
lds di, [bp][SEOFokOfs]
xor dx,dx
xor cx,cx
mov bx, [bp][SEOFFile]
mov ax, 4202H (* seek EOF *)
int 21H
jnc SEOFgood
mov cs:[@IOR],ax (* error is in ax *)
mov byte [di],0 (* OK false *)
jmp SEOFRet
SEOFgood:
mov byte [di],1
SEOFRet:
pop di; pop ds
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @IOR

public FioAsm$EOF : EOFFile = 10; EOFokSeg = 8; EOFokOfs = 6
push bp; mov bp,sp
push ds; push di;
lds di, [bp][EOFokOfs]
mov bx, [bp][EOFFile]
mov ax, 4406H (* device status, input *)
int 21H
jnc EOFgood
mov cs:[@IOR],ax (* error is in ax *)
mov ax,1 (* set TRUE, just in case *)
mov byte ds:[di],0 (* OK false *)
jmp EofRet
EOFgood:
not al (* reverse TRUE, FALSE *)
and ax,1 (* reset all but last bit *)
mov byte ds:[di],1 (* OK true *)
EofRet:
pop di; pop ds;
pop bp; ret far 6

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

extrn @ToPath

public FioAsm$ReadFirstEntry : R1Len = 16; R1Seg = 14; R1Ofs = 12;
R1Attr = 10; D1Seg = 8; D1Ofs = 6;
push bp; mov bp,sp
push ds; push es; push di; push si
lds dx, [bp][D1Ofs]
mov ah, 1AH (* set DTA to D *)
int 21H
mov cx,[bp][R1Len] (* get buffer length *)
lds si,[bp][R1Ofs]
call near @ToPath
mov ah, 4EH (* read first *)
mov cx, [bp][R1Attr]
int 21H
jnc R1OK
xor ax,ax (* false *)
jmp R1Ret
R1OK:
mov ax, 1
R1Ret:
pop si; pop di; pop es; pop ds
pop bp; ret far 12

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$ReadNextEntry : D2Seg = 8; D2Ofs = 6;
push bp; mov bp,sp
push ds;
lds dx, [bp][D2Ofs]
mov ah, 1AH (* set DTA to D *)
int 21H
mov ah, 4FH (* read next *)
int 21H
jnc R2OK
xor ax,ax (* false *)
jmp R2Ret
R2OK:
mov ax, 1
R2Ret:
pop ds
pop bp; ret far 4

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$SetDTA: DTASeg = 8; DTAOfs = 6;
push bp; mov bp,sp
push ds;
lds dx, [bp][DTAOfs]
mov ah, 1AH (* set DTA to D *)
int 21H
pop ds
pop bp; ret far 4

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$GetDTA:
push bp; mov bp,sp
push ds; push es
mov ah, 2FH
int 21H
mov dx,es
mov ax, bx
pop es; pop ds
pop bp; ret far 0

section ; segment C_CODE(CODE,28H); group G_CODE(C_CODE); select C_CODE

public FioAsm$DiskFree: dr = 10; BPCseg = 8; BPCofs = 6;
push bp; mov bp,sp
push ds; push si;
lds si,[bp][BPCofs]
mov dl, [bp][dr] (* load drive *)
mov ah, 36H (* get disk data *)
int 21H
cmp ax, 0FFFFH
jne OKdr
xor ax, ax
OKdr:
mul cx
mov [si],ax
mul bx
pop si; pop ds
pop bp; ret far 6

end


  3 Responses to “Category : Modula II Source Code
Archive   : FIOASM.ZIP
Filename : FIOASM.A

  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/