Category : BASIC Source Code
Archive   : QBCP.ZIP
Filename : QBFORMCP.BAS

 
Output of file : QBFORMCP.BAS contained in archive : QBCP.ZIP
'*****************************************************************************

'Copyright (c) 1988 Marcel Madonna

'QBFORMCP.BAS will reformat the last track on a DS/DD diskette. It assigns
'number 10 to the very last sector on the diskette (It's normally 9). This
'allows you to use the QBWARE routines to read HEAD 1, TRACK 39, SECTOR 12
'from your program as a means of providing rudimentary copy protection.

' You can improve on this routine by reading each cluster after it is
' formatted and marking the FAT if the cluster is bad. You can also
' mark the last sector on the disk as bad so DOS won't try to use it.
' CAUTION - MODIFYING THIS ROUTINE REQIURES SOME KNOWLEDGE OF FAT
' ENTRIES, THE DISK BASE TABLE AND THE BIOS PARAMETER BLOCK.
' UNINFORMED MODIFICATIONS CAN RESULT IN UNPREDICTABLE RESULTS!!!!!!!!

'
' ********************* N O T E *************************
'
'This program cannot be used from the DOS prompt without Microsoft
'QuickBasic V4.0 and a registered copy of QBWARE.
'
'To compile it, at the DOS prompt type:

' bc qbformcp;
' link /ex /noe qbformat,,,brun40 qbware;
' del qbformcp.obj
' del qbformcp.map

'To run it from the QuickBasic development environment, type:
'
' qb qbformcp /l qbware
' [Shift] + F5

'To execute just type "QBFORMCP" at the DOS prompt

'For Example:

' QBFORMCP

'will copy protect a diskette in drive A:

'*****************************************************************************

CLS

PRINT "Qbformcp - Version 1.0 (C) Copyright 1988 AJM Software"

Drive$ = "A" 'Use the A drive

LOCATE 3, 1
PRINT "We will now add copy protection to the diskette in Drive A"
PRINT "It must be a DS/DD 9-Sector 360K diskette."
PRINT "Do you wish to continue (Y/N)?"
X$ = ""
WHILE X$ = ""
X$ = INKEY$
WEND
IF X$ <> "Y" AND X$ <> "y" THEN
PRINT "Format aborted"
END
END IF

' Make sure that the Disk Base table is properly initialized
' Default to 360k DS/DD disk
' The following code should be needed only for AT type machines

DEF SEG = 0
OFFSET = PEEK(120 + 0) + (256 * PEEK(120 + 1))'Offset of DBT
SEGMENT = PEEK(120 + 2) + (256 * PEEK(120 + 3))'Segment of DBT
IF SEGMENT >= ABS(&HF000) THEN
PRINT "The Disk Base Table is in ROM and cannot be altered"
END
END IF

DEF SEG = SEGMENT
OLD.MAXSECT = PEEK(OFFSET + 4)
POKE (OFFSET + 4), &H9 'Indicate 9 sectors/track


Buffer$ = SPACE$(512) 'Initialize buffer area
MaxTrack% = 39 'Indicate 40 tracks (0-39)
Sectors% = 9 'Indicate 9 sectors/track
SectSize% = 2 'Indicate 512 bytes/sector
Rc% = 0 'Initialize return code

Track% = MaxTrack%
Text$ = SPACE$(Sectors% * 4)
Head% = 1
FOR Sect% = 1 TO Sectors%
MID$(Text$, 1 + ((Sect% - 1) * 4)) = CHR$(Track%) + CHR$(Head%) + CHR$(Sect%) + CHR$(SectSize%)
NEXT Sect%
MID$(Text$, 33) = CHR$(Track%) + CHR$(Head%) + CHR$(10) + CHR$(SectSize%)
LOCATE 7, 1
PRINT "...Formatting CYL "; Head%; " TRACK "; Track%
CALL BsDFmt(Text$, Drive$, Head%, Track%, Sectors%, Rc%)
IF Rc% <> 0 AND Rc% <> 6 THEN GOTO Error.Routine


' You can use the following code to check for bad clusters. It's slow, but
' it does work
'FOR Sector% = 1 TO Sectors%
' CALL BsdRead(Buffer$, Drive$, Head%, Track%, Sector%, Rc%)
' IF Rc% <> 0 THEN
' GOSUB Update.FAT
' END IF
'NEXT Sector%




MAXSECT$ = CHR$(OLD.MAXSECT)
POKE (OFFSET + 4), ASC(MAXSECT$) 'Restore the old value

PRINT
PRINT "...All done"
PRINT
PRINT "Remember that this program is intended to be used as a demo"
PRINT "only. No error checking was done so any bad clusters will"
PRINT "not be marked as bad in the FAT. This diskette is usable"
PRINT "in all other respects."
END


Write.Buffer:

CALL BsdWrit(Buffer$, Drive$, Head%, Track%, Sector%, Rc%)
IF Rc% <> 0 THEN GOTO Error.Routine
RETURN

Error.Routine:
' Rc% 1 - illegal command
' 2 - sector not found
' 3 - write protect error
' 4 - bad sector
' 6 - disk drive door opened (some 1.2M drives only)
' 8 - DMA failure
' 9 - DMA overrun
' 16 - bad CRC:parity check
' 32 - controller malfunction
' 64 - seek failure
' 128 - time out

IF Rc% = 1 THEN
PRINT "Illegal command issued"
ELSEIF Rc% = 2 THEN
PRINT "Sector not found"
ELSEIF Rc% = 3 THEN
PRINT "Write protect error"
ELSEIF Rc% = 4 THEN
PRINT "Bad sector found"
ELSEIF Rc% = 6 THEN
PRINT "Don't open the drive door during a format"
ELSEIF Rc% = 8 THEN
PRINT "DMA failure"
ELSEIF Rc% = 9 THEN
PRINT "DMA overrun"
ELSEIF Rc% = 16 THEN
PRINT "Bad CRC"
ELSEIF Rc% = 32 THEN
PRINT "Controller malfunction"
ELSEIF Rc% = 64 THEN
PRINT "Seek failure"
ELSEIF Rc% = 128 THEN
PRINT "Time-out"
PRINT "Make sure the drive door is closed"
ELSE
PRINT "Error "; Rc%
END IF

PRINT "Format halted " + TIME$
END

'
' You can update the FAT here if you want to make your diskette usable
' when it contains bad clusters.

Update.FAT:

LOCATE 22, 1
PRINT "Bad cluster found - do not use this diskette"
RETURN



  3 Responses to “Category : BASIC Source Code
Archive   : QBCP.ZIP
Filename : QBFORMCP.BAS

  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/