******************************************************************************* * dos.library.S Written by Readysoft. * Copyright 1992,1993,1994 RS. All rights reserved. 1992.02.23.-1994.05.18. * v1.0. ******************************************************************************* ******************************************************************************* * Macros ******************************************************************************* ;------------------------------------------------------------------------------ ; DosName Macro ;------------------------------------------------------------------------------ DOS.NAM MACRO DC.B 'dos.library',0 EVEN ENDM ******************************************************************************* * LIB Macro ******************************************************************************* DOS.LIB MACRO ******************************************************************************* * Constant Definitions ******************************************************************************* ;------------------------------------------------------------------------------ ; DeviceIdentifier Definitions ;------------------------------------------------------------------------------ dos_id_NIL EQU 0 dos_id_RAD EQU 1 dos_id_DF0 EQU 2 ;------------------------------------------------------------------------------ ; DiskInfoSector Structure (DIS) ;------------------------------------------------------------------------------ RSRESET dos_is_Label RS.B 28 Disk Label dos_is_Free RS.L 1 # of free bytes dos_is_NU RS.B 234 not used area dos_is_Map RS.B 246 Allocation Map dos_is_SizeOf RS.B 0 ;------------------------------------------------------------------------------ ; DirectoryEntry Structure ;------------------------------------------------------------------------------ RSRESET dos_de_FileName RS.B 28 FileName dos_de_Header RS.L 1 ptr to FHS dos_de_SizeOf RS.B 0 ;------------------------------------------------------------------------------ ; DirectorySector Structure (DIR) ;------------------------------------------------------------------------------ RSRESET dos_di_First RS.B 16*dos_de_SizeOf 16 entries / Sector dos_di_SizeOf RS.B 0 ;------------------------------------------------------------------------------ ; FileHeaderSector Structure (FHS) ;------------------------------------------------------------------------------ RSRESET dos_fh_FileName RS.B 28 FileName dos_fh_Length RS.L 1 dos_fh_NU RS.B 234 not used area dos_fh_Map RS.B 246 Allocation Map dos_fh_SizeOf RS.B 0 ;------------------------------------------------------------------------------ ; Error Codes ;------------------------------------------------------------------------------ dos_er_OK EQU $00000000 all right dos_er_Init EQU $00850000 unable to init dos_er_Device EQU $00850001 unknown device dos_er_DiskFull EQU $00850002 disk full dos_er_DirFull EQU $00850003 directory full dos_er_UnDef EQU $8085ffff undefined error ******************************************************************************* * Varibles ******************************************************************************* RSRESET dos_DISBuffer RS.B 512 DiskInfoSector buffer dos_FHSBuffer RS.B 512 FileHeaderSector buffer dos_DIRBuffer RS.B 512 DirectorySector buffer dos_DataBuffer RS.B 512 DataSector buffer dos_DirCacheDF0 RS.L 1 ptr to DF0 DirCache dos_DirStatDF0 RS.B 1 status of DF0 DirCache dos_NU RS.B 1 not used dos_VolName RS.L 1 dos_UnitNum RS.L 1 dos_Verify RS.L 1 dos_Address RS.L 1 dos_Length RS.L 1 dos_FileName RS.L 1 dos_FHS RS.L 1 dos_SizeOf RS.B 0 ******************************************************************************* * Routine Offsets ******************************************************************************* RSRESET RS.B -6 dos_Init RS.B -6 dos_Interrupt2 RS.B -6 dos_Format RS.B -6 dos_DiskInfo RS.B -6 dos_Load RS.B -6 dos_Save RS.B -6 dos_Read RS.B -6 dos_Write RS.B -6 dos_Delete RS.B -6 dos_FileInfo RS.B -6 ******************************************************************************* * Code ******************************************************************************* jmp dos.FileInfo jmp dos.Delete jmp dos.Write jmp dos.Read jmp dos.Save jmp dos.Load jmp dos.DiskInfo jmp dos.Format jmp dos.Interrupt2 jmp dos.Init dos.lib BLK.B dos_SizeOf,0 EVEN ;------------------------------------------------------------------------------ ; Init NoOp ;------------------------------------------------------------------------------ dos.Init movem.l d0/a0/a5,-(a7) lea dos.lib(pc),a5 move.l a5,a0 clear varible area move.w #dos_SizeOf-1,d0 .Clear clr.b (a0)+ dbf d0,.Clear ; move.l #12288,d0 init DF0 DirCache ; move.l #mem_ty_PublicC,d1 ; jsr mem.AllocMem ; tst.l d0 ; beq.s .Error ; move.l a0,dos_DirCacheDF0(a5) st dos_DirStatDF0(a5) status = invalid movem.l (a7)+,d0/a0/a5 rts .Error move.l #dos_er_Init,d0 jmp sys.FatalError ;------------------------------------------------------------------------------ ; Interrupt2 ;------------------------------------------------------------------------------ dos.Interrupt2 rts ;------------------------------------------------------------------------------ ; Format VolName,DevIdent,Verify,(a1,d1,d2) --> Error(d0) ;------------------------------------------------------------------------------ dos.Format movem.l d1/a1/a5,-(a7) lea dos.lib(pc),a5 cmpi.w #dos_id_DF0,d1 device DF0 ? beq.s .DF0 bra.s .DevErr device error .DF0 moveq #0,d1 unit 0 bsr dos.FormatTRD format with trackdisk .Exit movem.l (a7)+,d1/a1/a5 rts .DevErr move.l #dos_er_Device,d0 unknown device bra.s .Exit ;------------------------------------------------------------------------------ ; DiskInfo ;------------------------------------------------------------------------------ dos.DiskInfo rts ;------------------------------------------------------------------------------ ; Load Address,FileName,DevIdent(a0,a1,d1) --> Error(d0) ;------------------------------------------------------------------------------ dos.Load movem.l d1/a1/a5,-(a7) lea dos.lib(pc),a5 cmpi.w #dos_id_DF0,d1 device DF0 ? beq.s .DF0 bra.s .DevErr device error .DF0 moveq #0,d1 unit 0 bsr dos.LoadTRD load with trackdisk .Exit movem.l (a7)+,d1/a1/a5 rts .DevErr move.l #dos_er_Device,d0 unknown device bra.s .Exit ;------------------------------------------------------------------------------ ; Save Address,Length,FileName,DevIdent(a0,d0,a1,d1) --> Error(d0) ;------------------------------------------------------------------------------ dos.Save movem.l d1/a1/a5,-(a7) lea dos.lib(pc),a5 cmpi.w #dos_id_DF0,d1 device DF0 ? beq.s .DF0 bra.s .DevErr device error .DF0 moveq #0,d1 unit 0 bsr dos.SaveTRD save with trackdisk .Exit movem.l (a7)+,d1/a1/a5 rts .DevErr move.l #dos_er_Device,d0 unknown device bra.s .Exit ;------------------------------------------------------------------------------ ; Read ;------------------------------------------------------------------------------ dos.Read rts ;------------------------------------------------------------------------------ ; Write ;------------------------------------------------------------------------------ dos.Write rts ;------------------------------------------------------------------------------ ; Delete ;------------------------------------------------------------------------------ dos.Delete rts ;------------------------------------------------------------------------------ ; FileInfo ;------------------------------------------------------------------------------ dos.FileInfo rts ******************************************************************************* * Private Routines ******************************************************************************* ;------------------------------------------------------------------------------ ; FormatTRD VolName,UnitNum,Verify(a1,d1,d2) --> Error(d0) ;------------------------------------------------------------------------------ dos.FormatTRD movem.l d1-d2/a0-a2/a5,-(a7) lea dos.lib(pc),a5 move.l a1,dos_VolName(a5) store parameters move.l d1,dos_UnitNum(a5) move.l d2,dos_Verify(a5) jsr trd.Motor motor on tst.l d0 error ? bne.s .Exit jsr trd.Format format tst.l d0 error ? bne.s .Exit move.l dos_VolName(a5),a1 bsr dos.InitDIS init DiskInfoSector bsr dos.SaveDIS save DiskInfoSector tst.l d0 error ? bne .Exit bsr dos.InitDIR init Directory .Exit move.l d0,-(a7) store Error Code moveq #-1,d1 jsr trd.Motor motor off move.l (a7)+,d0 restore Error Code movem.l (a7)+,d1-d2/a0-a2/a5 rts ;------------------------------------------------------------------------------ ; LoadTRD Address,FileName,UnitNum(a0,a1,d1) --> Error(d0) ;------------------------------------------------------------------------------ dos.LoadTRD movem.l d1/a1,-(a7) lea dos.lib(pc),a5 move.l a0,dos_Address(a5) store parameters move.l d0,dos_Length(a5) move.l a1,dos_FileName(a5) move.l d1,dos_UnitNum(a5) move.l dos_UnitNum(a5),d1 motor on jsr trd.Motor bsr dos.LoadDIS load DiskInfoSector tst.l d0 error ? bne .Exit move.l dos_Length(a5),d0 init FileHeaderSector move.l dos_FileName(a5),a1 bsr dos.InitFHS tst.l d0 error ? bmi .DiskFull move.l dos_Length(a5),d7 save filedata move.l dos_Address(a5),a1 .Loop lea dos_DataBuffer(a5),a2 move.w #511,d6 .Copy move.b (a1)+,(a2)+ subq.l #1,d7 beq.s .EOF dbf d6,.Copy bra.s .Save .Clear clr.b (a2)+ .EOF dbf d6,.Clear .Save bsr dos.AllocSect allocates one sector tst.l d0 found ? bmi .DiskFull moveq #1,d1 lea dos_DataBuffer(a5),a0 jsr trd.WriteSector write one sector tst.l d0 error ? bne .Exit tst.l d7 next sector ? bne.s .Loop .OK tst.l d0 error ? bne .Exit bsr dos.InsertDir insert into directory tst.l d0 error ? bne .Exit bsr dos.SaveFHS save FileInfoSector tst.l d0 error ? bne .Exit bsr dos.SaveDIS save DiskInfoSector tst.l d0 error ? bne .Exit moveq #-1,d1 motor off jsr trd.Motor .Exit movem.l (a7)+,d1/a1 rts .DiskFull move.l #dos_er_DiskFull,d0 disk full bra.s .Exit ;------------------------------------------------------------------------------ ; SaveTRD Address,Length,FileName,UnitNum(a0,d0,a1,d1) --> Error(d0) ;------------------------------------------------------------------------------ dos.SaveTRD movem.l d1/a1,-(a7) lea dos.lib(pc),a5 move.l a0,dos_Address(a5) store parameters move.l d0,dos_Length(a5) move.l a1,dos_FileName(a5) move.l d1,dos_UnitNum(a5) move.l dos_UnitNum(a5),d1 motor on jsr trd.Motor bsr dos.LoadDIS load DiskInfoSector tst.l d0 error ? bne .Exit move.l dos_Length(a5),d0 init FileHeaderSector move.l dos_FileName(a5),a1 bsr dos.InitFHS tst.l d0 error ? bmi .DiskFull move.l dos_Length(a5),d7 save filedata move.l dos_Address(a5),a1 .Loop lea dos_DataBuffer(a5),a2 move.w #511,d6 .Copy move.b (a1)+,(a2)+ subq.l #1,d7 beq.s .EOF dbf d6,.Copy bra.s .Save .Clear clr.b (a2)+ .EOF dbf d6,.Clear .Save bsr dos.AllocSect allocates one sector tst.l d0 found ? bmi .DiskFull moveq #1,d1 lea dos_DataBuffer(a5),a0 jsr trd.WriteSector write one sector tst.l d0 error ? bne .Exit tst.l d7 next sector ? bne.s .Loop .OK tst.l d0 error ? bne .Exit bsr dos.InsertDir insert into directory tst.l d0 error ? bne .Exit bsr dos.SaveFHS save FileInfoSector tst.l d0 error ? bne .Exit bsr dos.SaveDIS save DiskInfoSector tst.l d0 error ? bne .Exit moveq #-1,d1 motor off jsr trd.Motor .Exit movem.l (a7)+,d1/a1 rts .DiskFull move.l #dos_er_DiskFull,d0 disk full bra.s .Exit ;------------------------------------------------------------------------------ ; InitFHS Length,FileName(d0,a1) --> Error(d0) ;------------------------------------------------------------------------------ dos.InitFHS movem.l d1/a0-a1/a5,-(a7) lea dos.lib(pc),a5 lea dos_FHSBuffer(a5),a0 clear Buffer move.w #127,d1 128*4 = 512 byte .ClrHB clr.l (a0)+ dbf d1,.ClrHB lea dos_FHSBuffer(a5),a0 insert FileLength move.l d0,dos_fh_Length(a0) lea dos_FHSBuffer(a5),a0 insert FileName lea dos_fh_FileName(a0),a0 .Name move.b (a1)+,(a0)+ tst.b (a1) bne.s .Name bsr dos.AllocSect allocates FHS move.l d0,dos_FHS(a5) movem.l (a7)+,d1/a0-a1/a5 rts ;------------------------------------------------------------------------------ ; SaveFHS NoOp --> Error(d0) ;------------------------------------------------------------------------------ dos.SaveFHS movem.l d1/a0/a5,-(a7) lea dos.lib(pc),a5 lea dos_FHSBuffer(a5),a0 save FileHeaderSector move.l dos_FHS(a5),d0 moveq #1,d1 jsr trd.WriteSector tst.l d0 error ? bne .Exit .Exit movem.l (a7)+,d1/a0/a5 rts ;------------------------------------------------------------------------------ ; LoadFHS ;------------------------------------------------------------------------------ dos.LoadFHS rts ;------------------------------------------------------------------------------ ; InitDIS VolName(a1) ;------------------------------------------------------------------------------ dos.InitDIS movem.l d0-d1/a0-a2/a5,-(a7) lea dos.lib(pc),a5 lea dos_DISBuffer(a5),a0 clear Buffer move.w #127,d1 128*4 = 512 byte .ClrHB clr.l (a0)+ dbf d1,.ClrHB lea dos_DISBuffer(a5),a0 init DiskInfoSector lea dos_is_Label(a0),a2 copy VolName .Copy move.b (a1)+,d0 beq.s .Copied move.b d0,(a2)+ bra.s .Copy .Copied clr.b (a2)+ move.l #$ffffff00,dos_is_Map(a0) 24 sectors (track0-1) movem.l (a7)+,d0-d1/a0-a2/a5 rts ;------------------------------------------------------------------------------ ; SaveDIS NoOp --> Error(d0) ;------------------------------------------------------------------------------ dos.SaveDIS movem.l d1/a0/a5,-(a7) lea dos.lib(pc),a5 lea dos_DISBuffer(a5),a0 read Sector 0 moveq #0,d0 moveq #1,d1 jsr trd.WriteSector tst.l d0 error ? bne .Exit .Exit movem.l (a7)+,d1/a0/a5 rts ;------------------------------------------------------------------------------ ; LoadDIS NoOp --> Error(d0) ;------------------------------------------------------------------------------ dos.LoadDIS movem.l d1/a0/a5,-(a7) lea dos.lib(pc),a5 lea dos_DISBuffer(a5),a0 read Sector 0 moveq #0,d0 moveq #1,d1 jsr trd.ReadSector movem.l (a7)+,d1/a0/a5 rts ;------------------------------------------------------------------------------ ; AllocSect NoOp --> FirstFreeSector(d0) ;------------------------------------------------------------------------------ dos.AllocSect movem.l d1-d2/a0-a1/a5,-(a7) lea dos.lib(pc),a5 lea dos_DISBuffer(a5),a0 lea dos_FHSBuffer(a5),a1 lea dos_is_Map(a0),a0 Allocation Map lea dos_fh_Map(a1),a1 moveq #0,d0 .Search move.l d0,d1 move.l d1,d2 lsr.l #3,d1 d1/8 = byte pointer and.l #7,d2 d2 = bit pointer eor.l #7,d2 btst d2,0(a0,d1.l) free sector ? beq.s .Found addq.l #1,d0 cmpi.w #1968,d0 bne.s .Search moveq #-1,d2 not found bra.s .Exit .Found bset d2,0(a0,d1.w) allocate bset d2,0(a1,d1.w) .Exit movem.l (a7)+,d1-d2/a0-a1/a5 rts ;------------------------------------------------------------------------------ ; InitDIR NoOp --> Error(d0) ;------------------------------------------------------------------------------ dos.InitDIR movem.l d1-d2/a0/a5,-(a7) lea dos.lib(pc),a5 lea dos_DIRBuffer(a5),a0 init DirectorySector moveq #127,d0 .Clear move.l #'DIR',(a0)+ dbf d0,.Clear lea dos_DIRBuffer(a5),a0 write DirectorySectors moveq #1,d1 moveq #1,d2 start at sector 1 .Write move.l d2,d0 jsr trd.WriteSector write DirectorySector tst.l d0 error ? bne.s .Exit addq.l #1,d2 next one cmpi.l #24,d2 368 files in 23 sectors bne.s .Write .Exit movem.l (a7)+,d1-d2/a0/a5 rts ;------------------------------------------------------------------------------ ; InsertDir NoOp --> Error(d0) ;------------------------------------------------------------------------------ dos.InsertDir movem.l d1-d3/a0-a2/a5,-(a7) lea dos.lib(pc),a5 moveq #1,d2 Sector 1 .Loop move.l d2,d0 moveq #1,d1 lea dos_DIRBuffer(a5),a0 jsr trd.ReadSector read a DirectorySector tst.l d0 error ? bne.s .Exit lea dos_DIRBuffer(a5),a0 moveq #15,d3 16 entries / Sector .Search tst.b dos_de_FileName(a0) empty ? beq.s .Found lea dos_de_SizeOf(a0),a0 next entry dbf d3,.Search addq.l #1,d2 next Sector cmpi.l #12,d2 last ? beq.s .DirFull directory full bra.s .Loop .Found move.l dos_FileName(a5),a1 insert FileName lea dos_de_FileName(a0),a2 .Name move.b (a1)+,d0 beq.s .NameOK move.b d0,(a2)+ bra.s .Name .NameOK clr.b (a2)+ move.l dos_FHS(a5),d0 insert FHS move.l d0,dos_de_Header(a0) move.l d2,d0 write DirectorySector moveq #1,d1 lea dos_DIRBuffer(a5),a0 jsr trd.WriteSector tst.l d0 error ? bne .Exit .Exit movem.l (a7)+,d1-d3/a0-a2/a5 rts .DirFull move.l #dos_er_DirFull,d0 directory full bra.s .Exit ******************************************************************************* * DataArea ******************************************************************************* DC.W -1 ENDM