Dvs Δημοσ. 27 Οκτωβρίου 2001 Δημοσ. 27 Οκτωβρίου 2001 mipos exei kaneis diskoles askiseis se pascal? (etsi gia exaskisi :>> )
Dvs Δημοσ. 27 Οκτωβρίου 2001 Μέλος Δημοσ. 27 Οκτωβρίου 2001 dokimases tin askisi pou eixan balei stin olympiada pliroforikis me tis lexeis pou diavazontan to idio anapoda; kaly askisi alla eukoli... --> tin exo kanei se vb (exo kanei kai tou deuterou girou)<BR> eukoles apla theloun xrono.<P>(i pascal einai malakia - teleios xazi glossa [giati na vazeis (begin -end)? se kourazei!)<P>koita kai to mail sou<P>cu
sh4dow Δημοσ. 27 Οκτωβρίου 2001 Δημοσ. 27 Οκτωβρίου 2001 O logos gia ton opoio exei begin kai end einai gia na dilosei apo pou xekinaei<BR>to programma i mia function kai procedure.<P>px:<P><BLOCKQUOTE><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><HR><pre><BR>procedure CallIt;<BR> function Calculate(x, y: Integer): Boolean;<BR> const<BR> w: Integer = 3;<BR> var<BR> p: Integer;<BR> begin<BR> p:= x + y;<BR> if (p-x)<0 then result:= True else result:= False;<BR> end;<P>var<BR> a, b, c: Integer<BR>begin<BR> writeln('Dose 3 arithmous');<BR> readln(a, b, c); {den xero ean to grafo sosta}<BR> if Calculate(a, then<BR> writeln(c + 3) else<BR> writeln(c + 4);<BR>end;<BR></pre><HR></BLOCKQUOTE><P>to parapano einai mia procedure pou mono auti blepei tin function Calculate<BR>(den eimai 100% sigouros alla nomizo oti ean baleis kai mia alli exo apo tin<BR>procedure me to idio onoma, tha kalesei prota tin esoteriki). tora ean bariese<BR>na grafeis begin end einai allo thema, kai prepei na koitaxeis na breis kapoion<BR>editor pou tha mporeis na baleis kapoio key shortcut gia na petaei mesa begin<BR>end. alla sinithos auto den einai problima giati oi programmatistes grafoun kai<BR>ligo grigora tha elega. allios tha po i pascal den einai c/c++ .<P><BR>ps: exeis dei function:<P><BLOCKQUOTE><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><HR><pre><BR>function LongMul(X, Y: Integer): Longint;<BR>asm<BR> MOV EAX,X<BR> IMUL Y<BR>end;<BR></pre><HR></BLOCKQUOTE><P>grapse ton kodika se asm gia na min grafeis begin end <P>is this stupid?<BR><BLOCKQUOTE><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><HR><pre><BR>{$R-,S-,I-,B-,F-,O+}<P>{---------------------------------------------------------<BR> BIOS disk I/O routines for floppy drives. Supports DOS<BR> real mode, DOS protected mode, and Windows. Requires<BR> TP6, TPW, or BP7.<P> All functions are for floppy disks only; no hard drives.<P> See the individual types and functions in the interface of<BR> this unit for more information. See the FMT.PAS sample<BR> program for an example of formatting disks.<P> For status code definitions, see the implementation of<BR> function GetStatusStr.<P> ---------------------------------------------------------<BR> Based on a unit provided by Henning Jorgensen of Denmark.<BR> Modified and cleaned up by TurboPower Software for pmode<BR> and Windows operation.<P> TurboPower Software<BR> P.O. Box 49009<BR> Colorado Springs, CO 80949-9009<P> CompuServe: 76004,2611<P> Version 1.0 10/25/93<BR> Version 1.1 10/29/93<BR> fix a dumb bug in the MediaArray check<BR> ---------------------------------------------------------}<P>unit BDisk;<BR> {-BIOS disk I/O routines for floppy drives}<P>interface<P>const<BR> MaxRetries : Byte = 3; {Number of automatic retries for<BR> read, write, verify, format}<P>type<BR> DriveNumber = 0..7; {Acceptable floppy drive numbers}<BR> {Generally, 0 = A, 1 = B}<P> DriveType = 0..4; {Floppy drive or disk types}<BR> {0 = unknown or error<BR> 1 = 360K<BR> 2 = 1.2M<BR> 3 = 720K<BR> 4 = 1.44M}<P> VolumeStr = String[11]; {String for volume labels}<P> FormatAbortFunc = {Prototype for format abort func}<BR> function (Track : Byte; {Track number being formatted, 0..MaxTrack}<BR> MaxTrack : Byte; {Maximum track number for this format}<BR> Kind : Byte {0 = format beginning}<BR> {1 = formatting Track}<BR> {2 = verifying Track}<BR> {3 = writing boot and FAT}<BR> {4 = format ending, Track = format status}<BR> ) : Boolean; {Return True to abort format}<P><BR>procedure ResetDrive(Drive : DriveNumber);<BR> {-Reset drive system (function $00). Call after any other<BR> disk function fails}<P><BR>function GetDiskStatus : Byte;<BR> {-Get status of last int $13 operation (function $01)}<P><BR>function GetStatusStr(ErrNum : Byte) : String;<BR> {-Return message string for any of the status codes used by<BR> this unit.}<P><BR>function GetDriveType(Drive : DriveNumber) : DriveType;<BR> {-Get drive type (function $08). Note that this returns the<BR> type of the *drive*, not the type of the diskette in it.<BR> GetDriveType returns 0 for an invalid drive.}<P><BR>function AllocBuffer(var P : Pointer; Size : Word) : Boolean;<BR> {-Allocate a buffer useable in real and protected mode.<BR> Buffers passed to ReadSectors and WriteSectors in pmode<BR> *MUST* be allocated by using this function. AllocBuffer returns<BR> False if sufficient memory is not available. P is also set to<BR> nil in that case.}<P><BR>procedure FreeBuffer(P : Pointer; Size : Word);<BR> {-Free buffer allocated by AllocBuffer. Size must match the<BR> size originally passed to AllocBuffer. FreeBuffer does<BR> nothing if P is nil.}<P><BR>function ReadSectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte;<BR> var Buffer) : Byte;<BR> {-Read absolute disk sectors (function $02). Track, Side,<BR> and SSect specify the location of the first sector to<BR> read. NSect is the number of sectors to read. Buffer<BR> must be large enough to hold these sectors. ReadSectors<BR> returns a status code, 0 for success.}<P><BR>function WriteSectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte;<BR> var Buffer) : Byte;<BR> {-Write absolute disk sectors (function $03). Track, Side,<BR> and SSect specify the location of the first sector to<BR> write. NSect is the number of sectors to write. Buffer<BR> must contain all the data to write. WriteSectors<BR> returns a status code, 0 for success.}<P><BR>function VerifySectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte) : Byte;<BR> {-Verify absolute disk sectors (function $04). This<BR> tests a computed CRC with the CRC stored along with the<BR> sector. Track, Side, and SSect specify the location of<BR> the first sector to verify. NSect is the number of<BR> sectors to verify. VerifySectors returns a status code,<BR> 0 for success. Don't call VerifySectors on PC/XTs and<BR> PC/ATs with a BIOS from 1985. It will overwrite the<BR> stack.}<P><BR>function FormatDisk(Drive : DriveNumber; DType : DriveType;<BR> Verify : Boolean; MaxBadSects : Byte;<BR> VLabel : VolumeStr;<BR> FAF : FormatAbortFunc) : Byte;<BR> {-Format drive that contains a disk of type DType. If Verify<BR> is True, each track is verified after it is formatted.<BR> MaxBadSects specifies the number of sectors that can be<BR> bad before the format is halted. If VLabel is not an<BR> empty string, FormatDisk puts the BIOS-level volume<BR> label onto the diskette. It does *not* add a DOS-level<BR> volume label. FAF is a user function hook that can be<BR> used to display status during the format, and to abort<BR> the format if the user so chooses. Parameters passed to<BR> this function are described in FormatAbortFunc above.<BR> FormatDisk also writes a boot sector and empty File<BR> Allocation Tables for the disk. FormatDisk returns a<BR> status code, 0 for success.}<P><BR>function EmptyAbortFunc(Track : Byte; MaxTrack : Byte; Kind : Byte) : Boolean;<BR> {-Do-nothing abort function for FormatDisk}<P> {========================================================================}<P>implementation<P>uses<BR>{$IFDEF DPMI}<BR> WinApi,<BR> Dos;<BR> {$DEFINE pmode}<BR>{$ELSE}<BR>{$IFDEF Windows}<BR> WinApi,<BR> WinDos;<BR> {$DEFINE pmode}<BR>{$ELSE}<BR> Dos;<BR> {$UNDEF pmode}<BR>{$ENDIF}<BR>{$ENDIF}<P>{$IFDEF Windows}<BR>type<BR> Registers = TRegisters;<BR> DateTime = TDateTime;<BR>{$ENDIF}<P>type<BR> DiskRec =<BR> record<BR> SSZ : Byte; {Sector size}<BR> SPT : Byte; {Sectors/track}<BR> TPD : Byte; {Tracks/disk}<BR> SPF : Byte; {Sectors/FAT}<BR> DSC : Byte; {Directory sectors}<BR> FID : Byte; {Format id for FAT}<BR> BRD : array[0..13] of Byte; {Variable boot record data}<BR> end;<BR> DiskRecs = array[1..4] of DiskRec;<BR> SectorArray = array[0..511] of Byte;<P>const<BR> DData: DiskRecs = {BRD starts at offset 13 of FAT}<BR>((SSZ: $02; SPT: $09; TPD: $27; SPF: $02; DSC: $07; FID: $FD; {5.25" - 360K}<BR> BRD: ($02, $01, $00, $02, $70, $00, $D0, $02, $FD, $02, $00, $09, $00, $02)),<BR> (SSZ: $02; SPT: $0F; TPD: $4F; SPF: $07; DSC: $0E; FID: $F9; {5.25" - 1.2M}<BR> BRD: ($01, $01, $00, $02, $E0, $00, $60, $09, $F9, $07, $00, $0F, $00, $02)),<BR> (SSZ: $02; SPT: $09; TPD: $4F; SPF: $03; DSC: $07; FID: $F9; {3.50" - 720K}<BR> BRD: ($02, $01, $00, $02, $70, $00, $A0, $05, $F9, $03, $00, $09, $00, $02)),<BR> (SSZ: $02; SPT: $12; TPD: $4F; SPF: $09; DSC: $0E; FID: $F0; {3.50" - 1.44M}<BR> BRD: ($01, $01, $00, $02, $E0, $00, $40, $0B, $F0, $09, $00, $12, $00, $02)));<P> BootRecord : SectorArray = {Standard boot program}<BR> ($EB, $34, $90, $41, $4D, $53, $54, $20, $33, $2E, $30, $00, $02, $01, $01,<BR> $00, $02, $E0, $00, $40, $0B, $F0, $09, $00,<BR> $12, $00, $02, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00,<BR> $00, $00, $00, $00, $00, $00, $00, $00, $12,<BR> $00, $00, $00, $00, $01, $00, $FA, $33, $C0, $8E, $D0, $BC, $00, $7C, $16,<BR> $07, $BB, $78, $00, $36, $C5, $37, $1E, $56,<BR> $16, $53, $BF, $2B, $7C, $B9, $0B, $00, $FC, $AC, $26, $80, $3D, $00, $74,<BR> $03, $26, $8A, $05, $AA, $8A, $C4, $E2, $F1,<BR> $06, $1F, $89, $47, $02, $C7, $07, $2B, $7C, $FB, $CD, $13, $72, $67, $A0,<BR> $10, $7C, $98, $F7, $26, $16, $7C, $03, $06,<BR> $1C, $7C, $03, $06, $0E, $7C, $A3, $3F, $7C, $A3, $37, $7C, $B8, $20, $00,<BR> $F7, $26, $11, $7C, $8B, $1E, $0B, $7C, $03,<BR> $C3, $48, $F7, $F3, $01, $06, $37, $7C, $BB, $00, $05, $A1, $3F, $7C, $E8,<BR> $9F, $00, $B8, $01, $02, $E8, $B3, $00, $72,<BR> $19, $8B, $FB, $B9, $0B, $00, $BE, $D6, $7D, $F3, $A6, $75, $0D, $8D, $7F,<BR> $20, $BE, $E1, $7D, $B9, $0B, $00, $F3, $A6,<BR> $74, $18, $BE, $77, $7D, $E8, $6A, $00, $32, $E4, $CD, $16, $5E, $1F, $8F,<BR> $04, $8F, $44, $02, $CD, $19, $BE, $C0, $7D,<BR> $EB, $EB, $A1, $1C, $05, $33, $D2, $F7, $36, $0B, $7C, $FE, $C0, $A2, $3C,<BR> $7C, $A1, $37, $7C, $A3, $3D, $7C, $BB, $00,<BR> $07, $A1, $37, $7C, $E8, $49, $00, $A1, $18, $7C, $2A, $06, $3B, $7C, $40,<BR> $38, $06, $3C, $7C, $73, $03, $A0, $3C, $7C,<BR> $50, $E8, $4E, $00, $58, $72, $C6, $28, $06, $3C, $7C, $74, $0C, $01, $06,<BR> $37, $7C, $F7, $26, $0B, $7C, $03, $D8, $EB,<BR> $D0, $8A, $2E, $15, $7C, $8A, $16, $FD, $7D, $8B, $1E, $3D, $7C, $EA, $00,<BR> $00, $70, $00, $AC, $0A, $C0, $74, $22, $B4,<BR> $0E, $BB, $07, $00, $CD, $10, $EB, $F2, $33, $D2, $F7, $36, $18, $7C, $FE,<BR> $C2, $88, $16, $3B, $7C, $33, $D2, $F7, $36,<BR> $1A, $7C, $88, $16, $2A, $7C, $A3, $39, $7C, $C3, $B4, $02, $8B, $16, $39,<BR> $7C, $B1, $06, $D2, $E6, $0A, $36, $3B, $7C,<BR> $8B, $CA, $86, $E9, $8A, $16, $FD, $7D, $8A, $36, $2A, $7C, $CD, $13, $C3,<BR> $0D, $0A, $4E, $6F, $6E, $2D, $53, $79, $73,<BR> $74, $65, $6D, $20, $64, $69, $73, $6B, $20, $6F, $72, $20, $64, $69, $73,<BR> $6B, $20, $65, $72, $72, $6F, $72, $0D, $0A,<BR> $52, $65, $70, $6C, $61, $63, $65, $20, $61, $6E, $64, $20, $73, $74, $72,<BR> $69, $6B, $65, $20, $61, $6E, $79, $20, $6B,<BR> $65, $79, $20, $77, $68, $65, $6E, $20, $72, $65, $61, $64, $79, $0D, $0A,<BR> $00, $0D, $0A, $44, $69, $73, $6B, $20, $42,<BR> $6F, $6F, $74, $20, $66, $61, $69, $6C, $75, $72, $65, $0D, $0A, $00, $49,<BR> $4F, $20, $20, $20, $20, $20, $20, $53, $59,<BR> $53, $4D, $53, $44, $4F, $53, $20, $20, $20, $53, $59, $53, $00, $00, $00,<BR> $00, $00, $00, $00, $00, $00, $00, $00, $00,<BR> $00, $00, $00, $00, $00, $00, $55, $AA);<P> MediaArray : array[DriveType, 1..2] of Byte =<BR> (($00, $00), {Unknown disk}<BR> ($01, $02), {360K disk}<BR> ($00, $03), {1.2M disk}<BR> ($00, $04), {720K disk}<BR> ($00, $04)); {1.44M disk}<P>{$IFDEF pmode}<BR>type<BR> DPMIRegisters =<BR> record<BR> DI : LongInt;<BR> SI : LongInt;<BR> BP : LongInt;<BR> Reserved : LongInt;<BR> BX : LongInt;<BR> DX : LongInt;<BR> CX : LongInt;<BR> AX : LongInt;<BR> Flags : Word;<BR> ES : Word;<BR> DS : Word;<BR> FS : Word;<BR> GS : Word;<BR> IP : Word;<BR> CS : Word;<BR> SP : Word;<BR> SS : Word;<BR> end;<P> function GetRealSelector(RealPtr : Pointer; Limit : Word) : Word;<BR> {-Set up a selector to point to RealPtr memory}<BR> type<BR> OS =<BR> record<BR> O, S : Word;<BR> end;<BR> var<BR> Status : Word;<BR> Selector : Word;<BR> Base : LongInt;<BR> begin<BR> GetRealSelector := 0;<BR> Selector := AllocSelector(0);<BR> if Selector = 0 then<BR> Exit;<BR> {Assure a read/write selector}<BR> Status := ChangeSelector(CSeg, Selector);<BR> Base := (LongInt(OS(RealPtr).S) shl 4)+LongInt(OS(RealPtr).O);<BR> if SetSelectorBase(Selector, Base) = 0 then begin<BR> Selector := FreeSelector(Selector);<BR> Exit;<BR> end;<BR> Status := SetSelectorLimit(Selector, Limit);<BR> GetRealSelector := Selector;<BR> end;<P> procedure GetRealIntVec(IntNo : Byte; var Vector : Pointer); Assembler;<BR> asm<BR> mov ax,0200h<BR> mov bl,IntNo<BR> int 31h<BR> les di,Vector<BR> mov word ptr es:[di],dx<BR> mov word ptr es:[di+2],cx<BR> end;<P> function RealIntr(IntNo : Byte; var Regs : DPMIRegisters) : Word; Assembler;<BR> asm<BR> xor bx,bx<BR> mov bl,IntNo<BR> xor cx,cx {StackWords = 0}<BR> les di,Regs<BR> mov ax,0300h<BR> int 31h<BR> jc @@ExitPoint<BR> xor ax,ax<BR> @@ExitPoint:<BR> end;<BR>{$ENDIF}<P> procedure Int13Call(var Regs : Registers);<BR> {-Call int $13 for real or protected mode}<BR>{$IFDEF pmode}<BR> var<BR> Base : LongInt;<BR> DRegs : DPMIRegisters;<BR>{$ENDIF}<BR> begin<BR>{$IFDEF pmode}<BR> {This pmode code is valid only for the AH values used in this unit}<BR> FillChar(DRegs, SizeOf(DPMIRegisters), 0);<BR> DRegs.AX := Regs.AX;<BR> DRegs.BX := Regs.BX;<BR> DRegs.CX := Regs.CX;<BR> DRegs.DX := Regs.DX;<BR> case Regs.AH of<BR> 2, 3, 5 :<BR> {Calls that use ES as a buffer segment}<BR> begin<BR> Base := GetSelectorBase(Regs.ES);<BR> if (Base <= 0) or (Base > $FFFF0) then begin<BR> Regs.Flags := 1;<BR> Regs.AX := 1;<BR> Exit;<BR> end;<BR> DRegs.ES := Base shr 4;<BR> end;<BR> end;<BR> if RealIntr($13, DRegs) <> 0 then begin<BR> Regs.Flags := 1;<BR> Regs.AX := 1;<BR> end else begin<BR> Regs.Flags := DRegs.Flags;<BR> Regs.AX := DRegs.AX;<BR> Regs.BX := DRegs.BX; {BX is returned by GetDriveType function only}<BR> end;<P>{$ELSE}<BR> Intr($13, Regs);<BR>{$ENDIF}<BR> end;<P> function GetDriveType(Drive : DriveNumber) : DriveType;<BR> var<BR> Regs : Registers;<BR> begin<BR> Regs.AH := $08;<BR> Regs.DL := Drive;<BR> Int13Call(Regs);<BR> if Regs.AH = 0 then<BR> GetDriveType := Regs.BL<BR> else<BR> GetDriveType := 0;<BR> end;<P> function GetDiskStatus : Byte;<BR> var<BR> Regs : Registers;<BR> begin<BR> Regs.AH := $01;<BR> Int13Call(Regs);<BR> GetDiskStatus := Regs.AL;<BR> end;<P> function GetStatusStr(ErrNum : Byte) : String;<BR> var<BR> NumStr : string[3];<BR> begin<BR> case ErrNum of<BR> {Following codes are defined by the floppy BIOS}<BR> $00 : GetStatusStr := '';<BR> $01 : GetStatusStr := 'Invalid command';<BR> $02 : GetStatusStr := 'Address mark not found';<BR> $03 : GetStatusStr := 'Disk write protected';<BR> $04 : GetStatusStr := 'Sector not found';<BR> $06 : GetStatusStr := 'Floppy disk removed';<BR> $08 : GetStatusStr := 'DMA overrun';<BR> $09 : GetStatusStr := 'DMA crossed 64KB boundary';<BR> $0C : GetStatusStr := 'Media type not found';<BR> $10 : GetStatusStr := 'Uncorrectable CRC error';<BR> $20 : GetStatusStr := 'Controller failed';<BR> $40 : GetStatusStr := 'Seek failed';<BR> $80 : GetStatusStr := 'Disk timed out';<P> {Following codes are added by this unit}<BR> $FA : GetStatusStr := 'Format aborted';<BR> $FB : GetStatusStr := 'Invalid media type';<BR> $FC : GetStatusStr := 'Too many bad sectors';<BR> $FD : GetStatusStr := 'Disk bad';<BR> $FE : GetStatusStr := 'Invalid drive or type';<BR> $FF : GetStatusStr := 'Insufficient memory';<BR> else<BR> Str(ErrNum, NumStr);<BR> GetStatusStr := 'Unknown error '+NumStr;<BR> end;<BR> end;<P> procedure ResetDrive(Drive : DriveNumber);<BR> var<BR> Regs : Registers;<BR> begin<BR> Regs.AH := $00;<BR> Regs.DL := Drive;<BR> Int13Call(Regs);<BR> end;<P> function AllocBuffer(var P : Pointer; Size : Word) : Boolean;<BR> var<BR> L : LongInt;<BR> begin<BR>{$IFDEF pmode}<BR> L := GlobalDosAlloc(Size);<BR> if L <> 0 then begin<BR> P := Ptr(Word(L and $FFFF), 0);<BR> AllocBuffer := True;<BR> end else begin<BR> P := nil;<BR> AllocBuffer := False<BR> end;<BR>{$ELSE}<BR> if MaxAvail >= Size then begin<BR> GetMem(P, Size);<BR> AllocBuffer := True;<BR> end else begin<BR> P := nil;<BR> AllocBuffer := False;<BR> end;<BR>{$ENDIF}<BR> end;<P> procedure FreeBuffer(P : Pointer; Size : Word);<BR> begin<BR> if P = nil then<BR> Exit;<BR>{$IFDEF pmode}<BR> Size := GlobalDosFree(LongInt(P) shr 16);<BR>{$ELSE}<BR> FreeMem(P, Size);<BR>{$ENDIF}<BR> end;<P> function CheckParms(DType : DriveType; Drive : DriveNumber) : Boolean;<BR> {-Make sure drive and type are within range}<BR> begin<BR> CheckParms := False;<BR> if (DType < 1) or (DType > 4) then<BR> Exit;<BR> if (Drive > 7) then<BR> Exit;<BR> CheckParms := True;<BR> end;<P> function SubfSectors(SubFunc : Byte;<BR> Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte;<BR> var Buffer) : Byte;<BR> {-Code shared by ReadSectors, WriteSectors, VerifySectors, FormatTrack}<BR> var<BR> Tries : Byte;<BR> Done : Boolean;<BR> Regs : Registers;<BR> begin<BR> Tries := 1;<BR> Done := False;<BR> repeat<BR> Regs.AH := SubFunc;<BR> Regs.AL := NSect;<BR> Regs.CH := Track;<BR> Regs.CL := SSect;<BR> Regs.DH := Side;<BR> Regs.DL := Drive;<BR> Regs.ES := Seg(Buffer);<BR> Regs.BX := Ofs(Buffer);<BR> Int13Call(Regs);<P> if Regs.AH <> 0 then begin<BR> ResetDrive(Drive);<BR> Inc(Tries);<BR> if Tries > MaxRetries then<BR> Done := True;<BR> end else<BR> Done := True;<BR> until Done;<P> SubfSectors := Regs.AH;<BR> end;<P> function ReadSectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte;<BR> var Buffer) : Byte;<BR> begin<BR> ReadSectors := SubfSectors($02, Drive, Track, Side, SSect, NSect, Buffer);<BR> end;<P> function WriteSectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte;<BR> var Buffer) : Byte;<BR> begin<BR> WriteSectors := SubfSectors($03, Drive, Track, Side, SSect, NSect, Buffer);<BR> end;<P> function VerifySectors(Drive : DriveNumber;<BR> Track, Side, SSect, NSect : Byte) : Byte;<BR> var<BR> Dummy : Byte;<BR> begin<BR> VerifySectors := SubfSectors($04, Drive, Track, Side, SSect, NSect, Dummy);<BR> end;<P> function SetDriveTable(DType : DriveType) : Boolean;<BR> {-Set drive table parameters for formatting}<BR> var<BR> P : Pointer;<BR> DBSeg : Word;<BR> DBOfs : Word;<BR> begin<BR> SetDriveTable := False;<P>{$IFDEF pmode}<BR> GetRealIntVec($1E, P);<BR> DBSeg := GetRealSelector(P, $FFFF);<BR> if DBSeg = 0 then<BR> Exit;<BR> DBOfs := 0;<BR>{$ELSE}<BR> GetIntVec($1E, P);<BR> DBSeg := LongInt(P) shr 16;<BR> DBOfs := LongInt(P) and $FFFF;<BR>{$ENDIF}<P> {Set gap length for formatting}<BR> case DType of<BR> 1 : Mem[DBSeg:DBOfs+7] := $50; {360K}<BR> 2 : Mem[DBSeg:DBOfs+7] := $54; {1.2M}<BR> 3,<BR> 4 : Mem[DBSeg:DBOfs+7] := $6C; {720K or 1.44M}<BR> end;<P> {Set max sectors/track}<BR> Mem[DBSeg:DBOfs+4] := DData[DType].SPT;<P>{$IFDEF pmode}<BR> DBSeg := FreeSelector(DBSeg);<BR>{$ENDIF}<P> SetDriveTable := True;<BR> end;<P> function GetMachineID : Byte;<BR> {-Return machine ID code}<BR>{$IFDEF pmode}<BR> var<BR> SegFFFF : Word;<BR>{$ENDIF}<BR> begin<BR>{$IFDEF pmode}<BR> SegFFFF := GetRealSelector(Ptr($FFFF, $0000), $FFFF);<BR> if SegFFFF = 0 then<BR> GetMachineID := 0<BR> else begin<BR> GetMachineID := Mem[segFFFF:$000E];<BR> SegFFFF := FreeSelector(SegFFFF);<BR> end;<BR>{$ELSE}<BR> GetMachineID := Mem[$FFFF:$000E];<BR>{$ENDIF}<BR> end;<P> function IsATMachine : Boolean;<BR> {-Return True if AT or better machine}<BR> begin<BR> IsATMachine := False;<BR> if Lo(DosVersion) >= 3 then<BR> case GetMachineId of<BR> $FC, $F8 : {AT or PS/2}<BR> IsATMachine := True;<BR> end;<BR> end;<P> function GetChangeLineType(Drive : DriveNumber; var CLT : Byte) : Byte;<BR> {-Return change line type of drive}<BR> var<BR> Regs : Registers;<BR> begin<BR> Regs.AH := $15;<BR> Regs.DL := Drive;<BR> Int13Call(Regs);<BR> if (Regs.Flags and FCarry) <> 0 then begin<BR> GetChangeLineType := Regs.AH;<BR> CLT := 0;<BR> end else begin<BR> GetChangeLineType := 0;<BR> CLT := Regs.AH;<BR> end;<BR> end;<P> function SetFloppyType(Drive : DriveNumber; FType : Byte) : Byte;<BR> {-Set floppy type for formatting}<BR> var<BR> Tries : Byte;<BR> Done : Boolean;<BR> Regs : Registers;<BR> begin<BR> Tries := 1;<BR> Done := False;<BR> repeat<BR> Regs.AH := $17;<BR> Regs.AL := FType;<BR> Regs.DL := Drive;<BR> Int13Call(Regs);<BR> if Regs.AH <> 0 then begin<BR> ResetDrive(Drive);<BR> Inc(Tries);<BR> if Tries > MaxRetries then<BR> Done := True;<BR> end else<BR> Done := True;<BR> until Done;<P> SetFloppyType := Regs.AH;<BR> end;<P> function SetMediaType(Drive : DriveType; TPD : Byte; SPT : Byte) : Byte;<BR> {-Set media type for formatting}<BR> var<BR> Regs : Registers;<BR> begin<BR> Regs.AH := $18;<BR> Regs.DL := Drive;<BR> Regs.CH := TPD;<BR> Regs.CL := SPT;<BR> Int13Call(Regs);<BR> SetMediaType := Regs.AH;<BR> end;<P> function FormatDisk(Drive : DriveNumber; DType : DriveType;<BR> Verify : Boolean; MaxBadSects : Byte;<BR> VLabel : VolumeStr;<BR> FAF : FormatAbortFunc) : Byte;<BR> label<BR> ExitPoint;<BR> type<BR> CHRNRec =<BR> record<BR> CTrack : Byte; {Track 0..?}<BR> CSide : Byte; {Side 0..1}<BR> CSect : Byte; {Sector 1..?}<BR> CSize : Byte; {Size 0..?}<BR> end;<BR> CHRNArray = array[1..18] of CHRNRec;<BR> FATArray = array[0..4607] of Byte;<BR> var<BR> Tries : Byte;<BR> Track : Byte;<BR> Side : Byte;<BR> Sector : Byte;<BR> RWritten : Byte;<BR> RTotal : Byte;<BR> FatNum : Byte;<BR> BadSects : Byte;<BR> ChangeLine : Byte;<BR> DiskType : Byte;<BR> Status : Byte;<BR> Done : Boolean;<BR> Trash : Word;<BR> DT : DateTime;<BR> VDate : LongInt;<BR> Regs : Registers;<BR> BootPtr : ^SectorArray;<BR> CHRN : ^CHRNArray;<BR> FATs : ^FATArray;<P> procedure MarkBadSector(Track, Side, Sector : Byte);<BR> const<BR> BadMark = $FF7; {Bad cluster mark}<BR> var<BR> CNum : Integer; {Cluster number}<BR> FOfs : Word; {Offset into fat for this cluster}<BR> FVal : Word; {FAT value for this cluster}<BR> OFVal : Word; {Old FAT value for this cluster}<BR> begin<BR> CNum := (((((Track*2)+Side)*DData[DType].SPT)+Sector-RTotal-2) div<BR> DData[DType].BRD[0])+2;<BR> if CNum > 1 then begin<BR> {Sector is in data space}<BR> FOfs := (CNum*3) div 2;<BR> Move(FATs^[FOfs], FVal, 2);<BR> if Odd(CNum) then<BR> OFVal := (FVal and (BadMark shl 4))<BR> else<BR> OFVal := (FVal and BadMark);<BR> if OFVal = 0 then begin<BR> {Not already marked bad, mark it}<BR> if Odd(CNum) then<BR> FVal := (FVal or (BadMark shl 4))<BR> else<BR> FVal := (FVal or BadMark);<BR> Move(FVal, FATs^[FOfs], 2);<BR> {Add to bad sector count}<BR> Inc(BadSects, DData[DType].BRD[0]);<BR> end;<BR> end;<BR> end;<P> begin<BR> {Validate parameters. Can't do anything unless these are reasonable}<BR> if not CheckParms(DType, Drive) then<BR> Exit;<P> {Initialize buffer pointers in case of failure}<BR> FATs := nil;<BR> CHRN := nil;<BR> BootPtr := nil;<P> {Status proc: starting format}<BR> if FAF(0, DData[DType].TPD, 0) then begin<BR> Status := $FA;<BR> goto ExitPoint;<BR> end;<P> {Error code for invalid drive or media type}<BR> Status := $FE;<P> case GetDriveType(Drive) of<BR> 1 : {360K drive formats only 360K disks}<BR> if DType <> 1 then<BR> goto ExitPoint;<BR> 2 : {1.2M drive formats 360K or 1.2M disk}<BR> if DType > 2 then<BR> goto ExitPoint;<BR> 3 : {720K drive formats only 720K disks}<BR> if DType <> 3 then<BR> goto ExitPoint;<BR> 4 : {1.44M drive formats 720K or 1.44M disks}<BR> if Dtype < 3 then<BR> goto ExitPoint;<BR> else<BR> goto ExitPoint;<BR> end;<P> {Error code for out-of-memory or DPMI error}<BR> Status := $FF;<P> {Allocate buffers}<BR> if not AllocBuffer(Pointer(FATs), SizeOf(FATArray)) then<BR> goto ExitPoint;<BR> if not AllocBuffer(Pointer(CHRN), SizeOf(CHRNArray)) then<BR> goto ExitPoint;<BR> if not AllocBuffer(Pointer(BootPtr), SizeOf(BootRecord)) then<BR> goto ExitPoint;<P> {Initialize boot record}<BR> Move(BootRecord, BootPtr^, SizeOf(BootRecord));<BR> Move(DData[DType].BRD, BootPtr^[13], 14);<P> {Initialize the FAT table}<BR> FillChar(FATs^, SizeOf(FATArray), 0);<BR> FATs^[0] := DData[DType].FID;<BR> FATs^[1] := $FF;<BR> FATs^[2] := $FF;<P> {Set drive table parameters by patching drive table in memory}<BR> if not SetDriveTable(DType) then<BR> goto ExitPoint;<P> {On AT class machines, set format parameters via BIOS}<BR> if IsATMachine then begin<BR> {Get change line type: 1 -> 360K drive, 2 -> 1.2M or 3.5" drive}<BR> Status := GetChangeLineType(Drive, ChangeLine);<BR> if Status <> 0 then<BR> goto ExitPoint;<BR> if (ChangeLine < 1) or (ChangeLine > 2) then begin<BR> Status := 1;<BR> goto ExitPoint;<BR> end;<P> {Determine floppy type for SetFloppyType call}<BR> DiskType := MediaArray[DType, ChangeLine];<BR> if DiskType = 0 then begin<BR> Status := $FB;<BR> goto ExitPoint;<BR> end;<P> {Set floppy type for drive}<BR> Status := SetFloppyType(Drive, DiskType);<BR> if Status <> 0 then<BR> goto ExitPoint;<P> {Set media type for format}<BR> Status := SetMediaType(Drive, DData[DType].TPD, DData[DType].SPT);<BR> if Status <> 0 then<BR> goto ExitPoint;<BR> end;<P> {Format each sector}<BR> ResetDrive(Drive);<BR> BadSects := 0;<P> for Track := 0 to DData[DType].TPD do begin<BR> {Status proc: formatting track}<BR> if FAF(Track, DData[DType].TPD, 1) then begin<BR> Status := $FA;<BR> goto ExitPoint;<BR> end;<P> for Side := 0 to 1 do begin<BR> {Initialize CHRN for this sector}<BR> for Sector := 1 to DData[DType].SPT do<BR> with CHRN^[sector] do begin<BR> CTrack := Track;<BR> CSide := Side;<BR> CSect := Sector;<BR> CSize := DData[DType].SSZ;<BR> end;<P> {Format this sector, with retries}<BR> Status := SubfSectors($05, Drive, Track, Side,<BR> 1, DData[DType].SPT, CHRN^);<BR> if Status <> 0 then<BR> goto ExitPoint;<BR> end;<P> if Verify then begin<BR> {Status proc: verifying track}<BR> if FAF(Track, DData[DType].TPD, 2) then begin<BR> Status := $FA;<BR> goto ExitPoint;<BR> end;<P> for Side := 0 to 1 do<BR> {Verify the entire track}<BR> if VerifySectors(Drive, Track, Side,<BR> 1, DData[DType].SPT) <> 0 then begin<BR> if Track = 0 then begin<BR> {Disk bad}<BR> Status := $FD;<BR> goto ExitPoint;<BR> end;<P> for Sector := 1 to DData[DType].SPT do<BR> if VerifySectors(Drive, Track, Side,<BR> Sector, 1) <> 0 then begin<BR> MarkBadSector(Track, Side, Sector);<BR> if BadSects > MaxBadSects then begin<BR> Status := $FC;<BR> goto ExitPoint;<BR> end;<BR> end;<BR> end;<BR> end;<BR> end;<P> {Status proc: writing boot and FAT}<BR> if FAF(0, DData[DType].TPD, 3) then begin<BR> Status := $FA;<BR> goto ExitPoint;<BR> end;<P> {Write boot record}<BR> Status := WriteSectors(Drive, 0, 0, 1, 1, BootPtr^);<BR> if Status <> 0 then begin<BR> Status := $FD;<BR> goto ExitPoint;<BR> end;<P> {Write FATs and volume label}<BR> Track := 0;<BR> Side := 0;<BR> Sector := 2;<BR> FatNum := 0;<BR> RTotal := (2*DData[DType].SPF)+DData[DType].DSC;<BR> for RWritten := 0 to RTotal-1 do begin<BR> if Sector > DData[DType].SPT then begin<BR> Sector := 1;<BR> Inc(Side);<BR> end;<P> if RWritten < (2*DData[DType].SPF) then begin<BR> if FatNum > DData[DType].SPF-1 then<BR> FatNum := 0;<BR> end else begin<BR> FillChar(FATs^, 512, 0);<BR> if ((VLabel <> '') and (RWritten = 2*DData[DType].SPF)) then begin<BR> {Put in volume label}<BR> for Trash := 1 to Length(VLabel) do<BR> VLabel[Trash] := Upcase(VLabel[Trash]);<BR> while Length(VLabel) < 11 do<BR> VLabel := VLabel+' ';<BR> Move(VLabel[1], FATs^, 11);<BR> FATs^[11] := 8;<BR> GetDate(DT.Year, DT.Month, DT.Day, Trash);<BR> GetTime(DT.Hour, DT.Min, DT.Sec, Trash);<BR> PackTime(DT, VDate);<BR> Move(VDate, FATs^[22], 4);<BR> end;<BR> FatNum := 0;<BR> end;<P> if WriteSectors(Drive, Track, Side,<BR> Sector, 1, FATs^[FatNum*512]) <> 0 then begin<BR> Status := $FD;<BR> goto ExitPoint;<BR> end;<P> Inc(Sector);<BR> Inc(FatNum);<BR> end;<P> {Success}<BR> Status := 0;<P>ExitPoint:<BR> FreeBuffer(BootPtr, SizeOf(BootRecord));<BR> FreeBuffer(CHRN, SizeOf(CHRNArray));<BR> FreeBuffer(FATs, SizeOf(FATArray));<P> {Status proc: ending format}<BR> Done := FAF(Status, DData[DType].TPD, 4);<BR> FormatDisk := Status;<BR> end;<P> function EmptyAbortFunc(Track, MaxTrack : Byte; Kind : Byte) : Boolean;<BR> begin<BR> EmptyAbortFunc := False;<BR> end;<P>end.<P>{ ------------------------------- DEMO PROGRAM -------------------- }<BR>{ ------------------------------- CUT HERE ---------------------}<P>{$R-,S-,I-}<P>program Fmt;<BR> {-Simple formatting program to demonstate DISKB unit}<P>uses<BR>{$IFDEF Windows}<BR> WinCrt,<BR>{$ENDIF}<BR> BDisk;<P>const<BR> ESC = #27;<BR> CR = #13;<P>type<BR> CharSet = set of Char;<P>var<BR> DLet : Char;<BR> DTyp : Char;<BR> Verf : Char;<BR> GLet : Char;<BR> DNum : Byte;<BR> Status : Byte;<BR> VStr : VolumeStr;<P>const<BR> DriveTypeName : array[DriveType] of string[5] =<BR> ('other', '360K', '1.2M', '720K', '1.44M');<P>{$IFNDEF Windows}<BR> function ReadKey : Char; assembler;<BR> {-Low budget readkey routine}<BR> asm<BR> xor ah,ah<BR> int 16h<BR> end;<BR>{$ENDIF}<P> function GetKey(Prompt : String; OKSet : CharSet) : Char;<BR> {-Get and return a key in the OKSet}<BR> var<BR> Ch : Char;<BR> begin<BR> Write(Prompt);<BR> repeat<BR> Ch := Upcase(ReadKey);<BR> if Ch = ESC then begin<BR> WriteLn;<BR> Halt;<BR> end;<BR> until (Ch in OKSet);<BR> if Ch <> CR then<BR> Write(Ch);<BR> WriteLn;<BR> GetKey := Ch;<BR> end;<P> function AbortFunc(Track, MaxTrack : Byte; Kind : Byte) : Boolean; far;<BR> {-Display formatting status. Could check for abort here too}<BR> begin<BR> case Kind of<BR> 0 : {Format beginning}<BR> Write('Formatting ');<BR> 1 : {Formatting track}<BR> Write(^H^H^H^H, ((Track*100) div MaxTrack):3, '%');<BR> 2 : {Verifying track}<BR> Write(^H, 'V');<BR> 3 : {Writing boot and FAT}<BR> Write(^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H, 'Writing boot and FAT');<BR> 4 : {Format ending}<BR> begin<BR> Write(^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H);<BR> {Track returns final status code in this case}<BR> if Track = 0 then<BR> WriteLn('Formatted successfully')<BR> else<BR> WriteLn('Format failed: ', GetStatusStr(Track));<BR> end;<BR> end;<BR> AbortFunc := False;<BR> end;<P>begin<BR> WriteLn('Floppy Formatter: <Esc> to exit');<P> {Get formatting parameters}<BR> DLet := GetKey('Drive to format? (A or : ', ['A'..'B']);<BR> DTyp := GetKey('Disk type? (1=360K, 2=1.2M, 3=720K, 4=1.44M): ', ['1'..'4']);<BR> Verf := GetKey('Verify? (Y or N) ', ['N', 'Y']);<BR> Write('Volume label? ');<BR> ReadLn(VStr);<BR> GLet := GetKey('Insert disk and press <Enter> ', [#13]);<P> {Compute drive number}<BR> DNum := Byte(DLet)-Byte('A');<P> WriteLn('Drive type is ', DriveTypeName[GetDriveType(DNum)]);<P> Status := FormatDisk(DNum, {drive number}<BR> Byte(DTyp)-Byte('0'), {format type}<BR> (Verf = 'Y'), {verify?}<BR> 10, {max bad sectors}<BR> VStr, {volume label}<BR> AbortFunc); {abort function}<BR> {AbortFunc reports the status}<BR>end.<BR></pre><HR></BLOCKQUOTE>
Dvs Δημοσ. 28 Οκτωβρίου 2001 Μέλος Δημοσ. 28 Οκτωβρίου 2001 O logos gia ton opoio exei begin kai end einai gia na dilosei apo pou xekinaei<BR>to programma i mia function kai procedure. --> to xero ://<BR>apla einai xazo na vazeis begin afou PANTA einai kato apo tin vasiki domi! (as evazes tou laxiston mono end (opos stin gwbasic i stin vb pou vazeis end if) <P><BR>to programma tou deuterou girou to exeis kaneis?<p>[ 27-10-2001: Message edited by: Dvs ]
sh4dow Δημοσ. 28 Οκτωβρίου 2001 Δημοσ. 28 Οκτωβρίου 2001 se pascal ola einai eukola <P>dokimases tin askisi pou eixan balei stin olympiada pliroforikis me tis lexeis pou diavazontan to idio anapoda; kaly askisi alla eukoli...<P>dokimase na ftiaxeis aples askiseis monos soy kai meta na tis lyseis me pascal, alla oxi mono me mia lysi :? poly kalo auto gia na exaskitheis se optimization kodika...<P>allo na kaneis einai na dexete kapoies times kai meta na ftiaxnei grafikes parastaseis.. kalo gia game development.<P>hmmm pare ena arxeio, kai xekina na prostheteis kathe byte tou arxeio me to epomeno (edo prepei na pareis ton xaraktira kai na ton metatrepseis se hex i dec ktl). ligo diskoli auti :L<P>bres mathimatikes askiseis pou exoun problimata noisis (diladi prepei na skefteis ligo prin kaneis praxeis) kai epilise ta se pascal.<P>auta kai alla polla.<P>ps: cpm
sh4dow Δημοσ. 28 Οκτωβρίου 2001 Δημοσ. 28 Οκτωβρίου 2001 to programma tou deuterou gyrou den xero pio einai to proto to eixa dei stin selida tous pou ithele na to steileis se disketa (tipota win3.1 tha eixan
Dvs Δημοσ. 28 Οκτωβρίου 2001 Μέλος Δημοσ. 28 Οκτωβρίου 2001 tha to skanaro kai tah to anevaso akpou an to deis (ama to theleise)<BR>plaka eixe to deutero. (8h mou pire na to skefto kai na to grapso!)
Επισκέπτης Δημοσ. 29 Οκτωβρίου 2001 Δημοσ. 29 Οκτωβρίου 2001 To programma pou panta prospa8ousa na ftia3w me opoia glwssa programmatismou ma8aina htan o thlefwnikos katalogos. Einai ena programma pou en oligois ta periexei ola! For, while, if, switch, arrays, files, sorting klp klp. Dokimase na to ftia3eis 8a sou parei arketo xrono alla sto telos 8a exeis mia syllogh apo programmata thlefwnikou katalogou apo mia seira apo glwsses <P>Filika<BR>Dionisos
Dvs Δημοσ. 29 Οκτωβρίου 2001 Μέλος Δημοσ. 29 Οκτωβρίου 2001 to exo kanei se vb kai pragmatika vothise arketa. alla se pascal mallon tha trelatheis! (thelo kati mikro kai periektioko (=diskolo?) - oxi eukolo kai terastio)
bandito Δημοσ. 2 Νοεμβρίου 2001 Δημοσ. 2 Νοεμβρίου 2001 1) Routines find, insert, remove se b-dendra <BR>2) An sou dothei ena odiko diktio me gnostes apostaseis apo poli se poli na ftia3eis mia routina, pou tha pairnei san parametrous tin afetiria kai ton termatismo, kai tha vriskei ton sintomotero dromo.<BR>An endiaferesai gia akoma pio diskola provlimata, ta 3analeme.
Dvs Δημοσ. 2 Νοεμβρίου 2001 Μέλος Δημοσ. 2 Νοεμβρίου 2001 to 2o to exo kanei :><BR>den thelei pano apo 8 ores <BR>to 1o to exigas ligo ?
bandito Δημοσ. 2 Νοεμβρίου 2001 Δημοσ. 2 Νοεμβρίου 2001 ta B-dendra, kai ta parakladia tous, einai apo tis pio simantikes domes ston programmatismo (indexes se databases mia simantiki tous efarmogi). Einai ligo diskolo na sou e3igisw edw ti einai ena B-dendro, alla an psa3eis se kapoio vivlio (mporw na sou proteinw an thes) tha deis, oti analoga me tin efarmogi oi routines find, insert, remove den einai eukoles (sinithos pantws gia na veltistopoihsoun tin poliplokotita, allazoyn tin domi). <BR>Episis, simasia den exei mono na liseis to provlima , alla na vreis kai tin veltisti lisi (kai fisika na apodei3eis oti einai auti).
Dvs Δημοσ. 3 Νοεμβρίου 2001 Μέλος Δημοσ. 3 Νοεμβρίου 2001 an einai i veltisti lisi giati na tin apodeixo kiolas? <P> siga min paro vivlio gia pascal - ama itan gia c ,vb i assembly nai allios..... vrika 2 programmatakia na kano gia tin ora - thx (ama exeis kana site pls pesto)
bandito Δημοσ. 3 Νοεμβρίου 2001 Δημοσ. 3 Νοεμβρίου 2001 Pou to 3ereis oti einai h veltisti? Auto einai zhthma theorias algoritmwn, kai oxi kapoias sigkekrimenis glossas. Auti einai h pragmatiki proklisi ston programmatismo, kai oxi na matheis kapoia glossa. p.x Twra programmatizw se C ena DSP (epe3ergasti tis texas) kai exw stin diathesi mou 32k grigoris mnimis, sin oti o epe3ergastis trexei mono sta 100MHz. Ekei na deis poy akoma kai mia prosthesi ligoteri einai veltistopoihsh. Gia paradeigma, oloi mporoun na ftia3oun ena algorithmo ta3inomosis, alla enw oi diadiki anazitisi exei poliplokotita O(n^2) enw o quicksort exei O(nlogn) poy einai poli kaliteros.
Dvs Δημοσ. 5 Νοεμβρίου 2001 Μέλος Δημοσ. 5 Νοεμβρίου 2001 simfono!<BR>vriskeis tin veltisi kai tin efarmozeis. giati an to apodeixeis?
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.