שתשת                                        
; Projekt Multi-Execute

; Beschreibung: Das Programm soll Programme solange ausfuehren , wie Files
;               im angegebenen Pfad sind.D.h. wenn z.b. 5 Bilder im Pics:
;               sind,und das Programm die Funktion SHOWINHALTDIR nicht
;               supportet,dann soll mit MULTI-EXECUTE das dir gelesen
;               und das Programm solange mit einem neuen Namen aufgerufen
;               werden,wie Files im Dir sind.
;
; Syntax:       ME DIR: PROGRAMM + Optionen


Include "sys:coder/LVO3.0/dos_lib.i"
Include "sys:coder/LVO3.0/Exec_lib.i"

EXECBASE=4
ACCESS_READ=-2

    SUBQ #1,d0
    ANDI.L #$0000FFFF,D0
    move.l D0,LAENGE
    MOVE.L A0,ADRESSE
    TST.L D0
    BEQ.W ENDE2
	Move.l ExecBase,a6
	Move.l #DOSNAME,a1
	Move.l #0,d0
	JSR OPENLIBRARY(a6)
	Move.l D0,DOSBASE
    TST.L D0
    BEQ.B ENDE
    JSR COPYNAMES
	Move.l DOSBase,a6
	Move.l #DIRNAME,d1
	Move.l #ACCESS_READ,d2
	JSR LOCK(a6)
	Move.l D0,DIRLOCK
    TST.L DIRLOCK
    BEQ.B ENDE
    JSR DOIT
ENDE:
    TST.L DIRLOCK
    BEQ.B ENDE1
	Move.l DOSBase,a6
	Move.l DIRLOCK,d1
	JSR UNLOCK(a6)
ENDE1:
    TST.L DOSBASE
    BEQ.B ENDE2
	Move.l ExecBase,a6
	Move.l DOSBASE,a1
	JSR CLOSELIBRARY(a6)
ENDE2:
    RTS

COPYNAMES:
    MOVE.L LAENGE,D5
    MOVE.L ADRESSE,A5
    MOVE.L #DIRNAME,A0

.LABEL1:   
    SUB.L #1,D5
    MOVE.B (A5)+,D0
    CMPI.B #$20,D0
    BEQ.B .LABEL2
    MOVE.B D0,(A0)+
    BRA .LABEL1
.LABEL2:
    MOVE.L #0,(A0)
    MOVE.L A5,ADRESSE
    MOVE.L D5,LAENGE
    RTS    

DOIT:
	Move.l DOSBase,a6
	Move.l DIRLOCK,d1
	Move.l #FILEINFOBLOCK,d2
	JSR EXAMINE(a6)
    TST.L D0
    BEQ.B Doit2
    LEA FILEINFOBLOCK,A0
    LEA 4(A0),A0
    MOVE.L (A0),D0
    CMPI.L #0,D0
    BLT.B ISN_FILE
DOIT1:
	Move.l DIRLOCK,d1
	Move.l #FILEINFOBLOCK,d2
	JSR EXNEXT(a6)
    TST.L D0
    BEQ.B DOIT2
    LEA FILEINFOBLOCK,A0
    LEA 4(A0),A0
    MOVE.L (A0),D0
    CMPI.L #0,D0
    BLT.B ISN_FILE
    BRA.B DOIT1
Doit2:
    RTS

ISN_FILE:
    LEA EXECUTEPUFFER,A2
    MOVE.L ADRESSE,A5
    MOVE.L LAENGE,D5
    LEA FILEINFOBLOCK,A0
    LEA 8(A0),A0
ISN_FILE_L3:    
    SUB.L #1,D5
    MOVE.B (A5)+,D0
    CMPI.B #`%`,D0
    BEQ.B PROZENT
ISN_FILE_L1:    
    MOVE.B D0,(A2)+
ISN_FILE_L2:    
    CMPI.L #0,D5
    BNE.B ISN_FILE_L3
    MOVE.B #$00,(A2)
	Move.l #EXECUTEPUFFER,d1
	Move.l #0,d2
	Move.l #0,d3
	JSR EXECUTE(a6)
    BRA.B DOIT1

PROZENT:
    MOVE.B (A5),D1
    CMPI.B #`F`,D1
    BEQ.B .LABEL1
    CMPI.B #`f`,D1
    BEQ.B .LABEL1
    CMPI.B #`N`,D1
    BEQ.B .LABEL10
    CMPI.B #`n`,D1
    BEQ.B .LABEL10
    BRA.B ISN_FILE_L1
.LABEL1:
    MOVE.B (A5)+,D0
    SUB.L #1,D5
    MOVE.L #DIRNAME,A1
    LEA FILEINFOBLOCK,A0
    LEA 8(A0),A0
.LABEL4:
    MOVE.B (A1)+,D0
    CMPI.B #$00,D0
    BEQ.B .LABEL2
    MOVE.B D0,(A2)+
    BRA.B .LABEL4
.LABEL2:
    MOVE.B (A0)+,D0
    CMPI.B #$00,D0
    BEQ.B .LABEL3
    MOVE.B D0,(A2)+
    BRA.B .LABEL2
.LABEL3:
    BRA.B ISN_FILE_L2

.LABEL10:
    MOVE.B (A5)+,D0
    SUB.L #1,D5
    MOVE.L #DIRNAME,A1
    LEA FILEINFOBLOCK,A0
    LEA 8(A0),A0
.LABEL11:
    MOVE.B (A0)+,D0
    CMPI.B #$00,D0
    BEQ.B .LABEL12
    MOVE.B D0,(A2)+
    BRA.B .LABEL11
.LABEL12:
    BRA.W ISN_FILE_L2

EVEN
DOSNAME:        DC.B `dos.library`,0


EVEN
DIRLOCK:        DC.L 0
DOSBASE:        DC.L 0
ADRESSE:        DC.L 0
LAENGE:         DC.L 0

CNOP 0,4
FILEINFOBLOCK: BLK.B 260,0

EVEN
DIRNAME:       	BLK.B 1024,0
EXECUTEPUFFER:  BLK.B 1024,0


