\
  Un exploreur de disque simple
                                \
Package Form

Uses IO

Sub Screen(Mode as Int)
Enter
  Ax=Mode
  InLine(&HCD,&H10)
Leave

Def NbCol as Int
Enter
  AX=&H0f00
  InLine(&HCD,&H10)
  Result=AX/&H100
Leave

Sub ClearLine(Li as Int)
Var
   I as Int
Enter
  Locate Li,1
  For I=1 To NbCol() Do PutCar ' ';
  Locate Li,1
Leave

Sub LCNPrintS(L,C,Color as Int; Str as ^Int, Len as Int)
Var
   Scr as ^Int
   ScrPtr,StrPtr as ^Array[0..1] Of Int
Enter
  ScrPtr=Pointer(@Scr)
  ScrPtr^[0]=(L-1)*NbCol()*2+(C-1)*2
  ScrPtr^[1]=&HB800
  StrPtr=Pointer(@Str)
  While Len<>0 Do
    CX=Str^
  \ XOR CH,CH \
    InLine(&H30,&HED)
    Scr^=Color*&H100+CX
    ScrPtr^[0]=ScrPtr^[0]+2
    StrPtr^[0]=StrPtr^[0]+1
    Len=Len-1
  Wend
Leave

Var
   LARGEUR,HAUTEUR as Int
   UNIT as Int

Sub PrintSector(L0,C0 as Int; Buf as Pointer)
Var
   L as Int
   IP as ^Int
Enter
\ buf=(byte_ptr)min_ofs((void*)buf); \
  IP=Pointer(@Buf)
  For L=0 To HAUTEUR-1 Do
    LCNPrintS(L0+L,C0,7,Buf,LARGEUR)
    IP^=IP^+LARGEUR
  Next
Leave

Def ResetSket(Unit as Int) as Int
Enter
  AX=0
  DX=Unit
  InLine(&HCD,&H13)
  BX=AX
\ LAHF \
  InLine(&H9F)
\ MOV AL,AH \
  InLine(&H88,&HE0)
\ XOR AH,AH \
  InLine(&H30,&HE4)
\ AND AL,1 \
  InLine(&H24,&H01)
  If AX<>0 Then Result=BX/&H100 Else Result=0;
Leave

Def ReadSket(Unit,Face,Piste,Sector,NSect as Int; Buf as Pointer) as Int
Enter
  CX=Piste*256+Sector
  DX=Face*256+Unit
  AX=&H0200+NSect
\ buf=min_ofs(buf); * WARN * \
\ LES BX,[BP+0E] \
  InLine(&HC4,&H5E,&H0E)
  InLine(&HCD,&H13)
  BX=AX
\ LAHF \
  InLine(&H9F)
\ MOV AL,AH \
  InLine(&H88,&HE0)
\ XOR AH,AH \
  InLine(&H30,&HE4)
\ AND AL,1 \
  InLine(&H24,&H01)
  If AX<>0 Then Result=BX/&H100 Else Result=0;
Leave

Sub ReadAndPrintSectorSket(Face,Piste,Sector as Int; Buf as Pointer)
Var
   Resu as Int
Enter
  Resu=ResetSket(UNIT)
  If Resu<>0 Then Locate 2,1:PrintS "Couille reset_sket ":PrintX Resu
  Else
    Resu=ReadSket(UNIT,Face,Piste,Sector,1,Buf)
    If Resu<>0 Then Resu=ReadSket(UNIT,Face,Piste,Sector,1,Buf);
    If Resu<>0 Then Locate(2,1):PrintS("Couille read_sket "):PrintX(Resu)
    Else
      ClearLine(2):PrintSector(5,19,Buf);
  End
Leave

Sub Cassos
Enter
  InLine(&HB4,&H4C,&HCD,&H21)
Leave

Var
   SIZ_BUF,Face,Piste,Sector,I,Resu as Int
   Buf as Array [1..256] Of Int
   Touche as Int
   Fini as Byte
Enter
  LARGEUR=32:HAUTEUR=16
  UNIT=0
  SIZ_BUF=512
  Face=0:Piste=0:Sector=1
  For I=1 To SIZ_BUF/2 Do Buf[I]=&H0303;
  Screen(3)
  Locate(25,1)
  PrintS("Disk explorer ver 1.00. ")
  PrintS("Copyright (C) LezourdsManSoft, november 1993.")

  ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)

  Fini=0:While Fini=0
  Do
    ClearLine(1)
    PrintS("Face="):PrintX(Face)
    PrintS(", Piste="):PrintX(Piste)
    PrintS(", Sector="):PrintX(Sector)
    Touche=GetCar()
    If Touche=27 Then
      SetCRTMode 1:PrintS("Bye"):Fini=1
    Else
    If Touche='+' Then
      Sector=Sector+1
      If Sector=16 Then
        If Face=0 Then Face=1:Sector=1
        Else
          Piste=Piste+1
          If Piste=80 Then Piste=0:Sector=1:Face=0
          Else
            Sector=1:Face=0;
        End;

      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    Else
    If Touche='-' Then
      Sector=Sector-1
      If Sector=0 Then
        If Face=1 Then Face=0:Sector=15
        Else
          Piste=Piste-1
          If Piste=&hffff Then Piste=79:Sector=15:Face=1
          Else
            Sector=1:Face=1;
        End;

      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    Else
    If Touche='p' Then
      Piste=Piste-1:If Piste=&hffff Then Piste=79;
      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    Else
    If Touche='P' Then
      Piste=Piste+1:If Piste=80 Then Piste=0;
      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    Else
    If Touche='f' Or Touche='F' Then
      Face=1-Face
      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    Else
    If Touche='u' Or Touche='U' Then
      UNIT=1-UNIT
      ReadAndPrintSectorSket(Face,Piste,Sector,@Buf)
    End;
  Wend
Leave

\
  case 'n':
    resu=reset_sket(0);
    if (resu) { gotoxy(1,2),cprintf("couille reset_sket %x",resu);break; }
    else
      gotoxy(1,2),clreol();
    resu=start_format_sket();
    if (resu) { gotoxy(1,2),cprintf("couille start_format_sket %x",resu);break; }
    else
      gotoxy(1,2),clreol();
    resu=format_sket(0,face,piste);
    if (resu) { gotoxy(1,2),cprintf("couille format_sket %x",resu);break; }
    else
      gotoxy(1,2),clreol();
    read_and_print_sector_sket(face,piste,sector,buf);
  break;
  default: break;
                  \