10 PRINT
 : PRINT "PIP - VER 5.01 7May2010"

20 "Start 
21 CLEAR 0 
 : X = FRE(0) - 1500
 : IF (X < 0) THEN 
      CLEAR 600 
   ELSE 
      IF (X > 32000) THEN
         CLEAR 32000 
      ELSE 
         CLEAR X

30 DIM T2(15)
 : FOR (Y = 0) TO 15
 :     T2(Y) = -1
 : NEXT Y
 : PRINT "*";
 : LINE INPUT B$
40 IF (B$ = "") THEN 
      CLEAR 200
 :    END 'End Program

50 IF (LEN(B$) > 3) THEN 
      C$ = RIGHT$(B$, LEN(B$) - 3)  
   ELSE 
      C$ = B$

60 B$ = LEFT$(B$, 3)

70 IF (B$ = "DAT") THEN GOTO 680

80 IF (B$ = "COP") THEN GOTO 870

90 IF (B$ = "LIS") THEN GOTO 800

100 IF (B$ = "CNV") THEN GOTO 1040

110 IF (B$ = "DIR") THEN
       F = -1
  :    GOTO 270

120 IF (B$ = "SRT") THEN
       F = 0
  :    DIM A$(255)
  :    GOTO 270

130 IF (B$ <>"INI") THEN 
       PRINT "ERR"
  :    GOTO 20 'Start program again

140 'INI
141 GOSUB 760

150 A$ = STRING$(137, 0)
  : MID$(A$, 136, 1) = CHR$(255)

160 FOR (T = 6) TO 76
170     FOR (S = 0) TO 31
180         MID$(A$, 1, 2) = CHR$(T) + CHR$((S * 17) AND 31)
190         GOSUB 600
  :         DSKO$ A$, S
200 NEXT S, T

210 T = 70
  : GOSUB 600 'DIRECTORY TRACK
220 A$ = CHR$(70) + CHR$(0) + CHR$(0) + CHR$(128) + CHR$(127) + CHR$(0)
230 A$ = A$ + CHR$(0) + CHR$(255) + STRING$(127, 0) + CHR$(255)
240 DSKO$ A$, 0
250 PRINT
  : PRINT "DONE"
260 GOTO 20 'Start program again

270 'DIR (F = -1) or SRT (F = 0)

271 GOSUB 760
  : T = 70
  : GOSUB 600
290 PRINT
300 PRINT "DIRECTORY DISK"; A
310 PRINT
  : I = 0
320 FOR (S = 0) TO 31
330     A$ = DSKI$(17 * S AND 31)
340     A$ = LEFT$(A$, 135)
350     A$ = RIGHT$(A$, 128)
360     FOR (T = 0) TO 7
370         B$ = LEFT$(A$, (T + 1) * 16)
380         B$ = RIGHT$(B$, 16)
390         N$ = LEFT$(B$, 8)
400         B$ = RIGHT$(B$, 8)
410         X = ASC(B$)
  :         B$ = RIGHT$(B$, 7)
  :         Y = ASC(B$)
420         B$ = RIGHT$(B$, 6)
  :         Z = ASC(B$)
430         IF (ASC(N$) = 0) THEN GOTO 470
440         IF (ASC(N$) = 255) GOTO THEN 490
450         R$ = "S"
  :         IF (Z <> 2) THEN R$ = "R"
460         IF (F) THEN 
                   PRINT N$; "  "; R$; "  "; X; "  "; Y 
            ELSE 
                   A$(I) = N$ + "  " + R$ + "  " + STR$(X) + "  
" + STR$(Y)
  :                I = I + 1
470          NEXT T
480 NEXT S

490 IF ((F0 OR (I = 0)) THEN 
       PRINT
  :    GOTO 20 'Start program again

500 IF (I = 1) THEN GOTO 560
510 SW = 0
520 FOR (J = 0) TO (I - 2)
530     IF (A$(J) > A$(J + 1)) THEN 
           SWAP A$(J), A$(J + 1)
  :        SW = -1
540 NEXT J

550 IF (SW) THEN GOTO 510

560 FOR (J = 0) TO (I - 1)
570         PRINT A$(J)
580 NEXT J

590 PRINT
  : GOTO 20 'Start program again

600 IF (T2(A) <> - 1) THEN GOTO 640

610 IF ((INP(8) AND 64)) = 0) THEN 
       T2(A) = 0
  :    GOTO 640

620 WAIT 8, 2, 2
  : OUT 9, 2

630 GOTO 610

640 IF (T2(A) = T) THEN 
       RETURN

650 D = 1
  : IF (T2(A) >T) THEN D = 2
660 WAIT 8, 2 , 2
  : OUT 9, D
  : T2(A) = T2(A) - 2 * (D - 1.5)
670 GOTO 640

680 'DAT
681 INPUT "TRACK"; T
  : IF (T < 0) THEN
       GOTO 20
    ELSE 
       INPUT "SECTOR"; S

690 GOSUB 760
  : GOSUB 600

700 A$ = DSKI$(S)
  : FOR (I = 0) TO (LEN(A$) - 1)
710     T1$ = OCT$(ASC(RIGHT$(A$, LEN(A$) - I)))
720     T2$ = LEFT$("  000", 5 - LEN(T1$)) + T1$
  :     PRINT T2$;
730     IF ((I MOD 8) = 7) THEN PRINT

740 NEXT I
  : PRINT

750 GOTO 680

760 A = VAL(C$)

770 IF ((A<0) OR (A>15)) THEN
       PRINT "ERR"
  :    GOTO 20 'Start program again

780 OUT 8, 128
  : OUT 8, A

790 RETURN

800 'LIS
801 GOSUB 760
810 C$ = RIGHT$(C$, LEN(C$) - 1 + (A>9))
  : IF (ASC(C$) <> &O54) THEN
       PRINT "ERR"
  :    GOTO 20 'Start program again

820 C$ = RIGHT$(C$, (LEN(C$)  - 1))

830 OPEN "I", 1, C$, A
840 IF EOF(1) THEN
       CLOSE 1
  :    OTO 20 'Start program again

850 LINEINPUT #1, A$
860 PRINT A$
  : GOTO 840

870 'COP
871 GOSUB 760
  : B = A

880 C$ = RIGHT$(C$, LEN(C$) - 1 + (A > 9))
  : IF (ASC(C$) <> &O54) THEN 
       PRINT "ERR"
  :    GOTO 20 'Start program again

890 C$ = RIGHT$(C$, LEN(C$) - 1)
  : GOSUB 760
  : C = A

900 PRINT "FROM "; B; " TO "; C;
910 INPUT A$
  : IF (ASC(A$) <> ASC("Y")) THEN GOTO 20

920 FOR (T=0) TO 76
930     OUT 8, 128
  :     OUT 8, C
940     A = C
  :     GOSUB 600
  :     OUT 8, 128
  :     OUT 8, B
  :     A = B
  :     GOSUB 600
950     FOR (S=0) TO 31
960         OUT 8,128
  :         OUT 8, B
  :         B$=DSKI$(S)
970         F$ = DSKI$(S)
  :         IF (F$ <> B$) THEN
               PRINT "REREAD"
  :            GOTO 960

980         OUT 8, 128
  :         OUT 8, C
990         DSKO$ B$, S
  :         C$ = DSKI$(S)
  :         IF (C$ <> B$) THEN 
               PRINT "REWRITE"
  :            GOTO 950

1000    NEXT S
1010 NEXT T

1020 PRINT "DONE"
1030 GOTO 20 'Start program again

1040 'CNV
1041 GOSUB 760   'ENABLE DISK

1050 FOR (T = 6) TO 76
1060     GOSUB 600   'POSITION TO TRACK T

1070     FOR (S = 0) TO 31
1080         A$ = DSKI$(S)
   :         IF (ASC(MID$(A$, 3, 1)) <> 0) THEN GOTO 1120
1090         IF MID$(A$, 136, 1) = CHR$(255) THEN GOTO 1120
1100         MID$(A$, 136, 1) = CHR$(255)
1110         DSKO$ A$, S
1120     NEXT S
1130 NEXT T
   : GOTO 20 'Start program again