

******************************************************************
*
*       HARD DISK CONFIGURATION ROUTINE
*
*       Public Domain programmed by Francois Lionet 24/11/88
*
*       2 Rue Brobeil 60100 CREIL FRANCE
*
*       Assembled with seka
*
******************************************************************
*       This little routine can be very useful to
*       all hard disk owners. It allows you to select
*       up to three different configurations.
*       For example:
*       Config #1 could be Low-res with DEGAS oriented accessories.
*       Config #2 could be Mid-res with Disk accessories
*       Config #3 could be Monochrome plus accessories
******************************************************************
*       How does it works?
*       Put this routine in your AUTO folder.
*       [1] Create 3 folders named
*           CONFIG1, CONFIG2, CONFIG3 in the main directory
*
*       [2] Copy in each folder the DESKTOP for each 
*           configuration, and the accessories you want.
*
*       When you boot the computer (or press reset), the CONFIG.PRG
*       asks you to press keys 1,2 or 3. If you don't press a key
*       before 2 seconds, the program does nothing, and GEM Desktop
*       appears.
*       If you select one of the 3 configuration, the program first
*       erases all .ACC present in the main directory, and then copies
*       the contents of the CONFIGx folder. GEM then appears with the
*       selected desktop and set of accessories. Useful isn't it! 
*******************************************************************
*       Of course, you can easily change the number of 
*       configurations, and the messages! Bye!
*******************************************************************
even
        bra Debut

        blk.l 128,0
Pile:   dc.l 0

Dta:            blk.b 48,0
Longueur:       equ Dta+26
Repons:         dc.w 0
Handle:         dc.w 0

;---------------------------------> Welcome messages
Hello:          dc.b 27,"E",10,10,10
                dc.b "     You have 2 seconds to choose",13,10
                dc.b "          your configuration:",13,10
                dc.b 13,10
                dc.b "     (1) Lowres",13,10
                dc.b "     (2) Midres 1",13,10
                dc.b "     (3) Midres 2",13,10
                dc.b 13,10,0    
Efface:         dc.b "I kill: ",0
CopText:        dc.b "I copy: ",0
textErr:        dc.b 13,10
                dc.b "Disk error!",7,7,7,7,7
                dc.b 13,10,0
Defaut:         dc.b 13,10,7,7,7,7,7
                dc.b "         I don't change anything.",13,10,0
Text:           blk.b 40,0
Retour:         dc.b 13,10,0        

; Accessoiry killing
Acc:            dc.b "\*.ACC",0
PAcc:           dc.b "\"
PAcc1:          blk.b 16,0
; Copy path
PathD:          dc.b "\"
PathD1:         blk.b 16,0

even

; Origin folders
NbConfig:       equ 3
Table:          dc.l Path1,Load1,Load11
                dc.l Path2,Load2,Load21
                dc.l Path3,Load3,Load31
Path1:          dc.b "\CONFIG1\*.*",0
Load1:          dc.b "\CONFIG1\"
Load11:         blk.b 16,0
Path2:          dc.b "\CONFIG2\*.*",0
Load2:          dc.b "\CONFIG2\"
Load21:         blk.b 16,0
Path3:          dc.b "\CONFIG3\*.*",0
Load3:          dc.b "\CONFIG3\"
Load31:         blk.b 16,0
        
even

; The rest of the program is in french: find a dictionnary!

Debut:
;-----> Reservation memoire
        move.l sp,a5
        move.l #Pile,sp
        move.l 4(a5),a5
        move.l $c(a5),d0
        add.l $14(a5),d0
        add.l $1c(a5),d0
        add.l #$100,d0
        move.l d0,-(sp)
        move.l a5,-(sp)
        move.w #0,-(sp)
        move.w #$4a,-(sp)
        trap #1
        add.l #12,sp

;-----> Affiche le texte
        lea Hello,a0
        bsr Print
    
;-----> Attend une r‚ponse (1 seconde)
        move.w #100,d7
Wait:   move.w #37,-(sp)
        trap #14
        addq.l #2,sp
        move.w #2,-(sp)
        move.w #1,-(sp)
        trap #13
        addq.l #4,sp
        tst.w d0
        bne.s Wait1
        dbra d7,Wait
Rien:   lea Defaut,a0
        bsr Print
        bra FinPrg

; Une r‚ponse!
Wait1:  move.w #2,-(sp)
        move.w #2,-(sp)
        trap #13
        addq.l #4,sp
        and.w #$ff,d0
        sub.w #48,d0
        bmi Rien
        cmp.w #NbConfig,d0
        bhi Rien
        move.w d0,Repons
        bsr SetDta

;-----> Efface les .ACC 
        lea Acc,a0
        bsr SFirst
        bne PasAcc
EffAcc: lea PAcc1,a1            ;Recopie le nom
        bsr Recop
        lea Efface,a0           ;Efface XXXXXX
        bsr Print
        lea Text,a0
        bsr Print
        lea Retour,a0
        bsr Print
        lea PAcc,a0             ;Va effacer
        bsr UnLink
        bsr SNext
        beq.s EffAcc
        lea Retour,a0
        bsr Print
PasAcc:
;-----> Recopie le contenu du CONFIGX
        lea Table,a6
        move.w Repons,d0
        mulu #12,d0
        lea -12(a6,d0.w),a6
        move.l (a6),a0
        bsr SFirst
        bne FinPrg

Copie:  move.l 8(a6),a1         ;Copie le nom
        bsr Recop

        lea Coptext,a0
        bsr Print
        lea Text,a0
        bsr Print
        lea Retour,a0
        bsr Print

; Charge le fichier
        move.l 4(a6),a0         ;Ouvre
        bsr Open
        bsr Load                ;Charge (Ad ---> Longueur)
        bsr Close               ;Ferme
; Sauve le fichier
        lea PathD,a0
        bsr Create
        bsr Save
        bsr Close

; Un Autre?
        bsr SNext
        beq Copie        

;-----> Fin normale du programme
FinPrg: clr.w -(sp)
        trap #1

;-----> Erreur disque!
Erreur: lea TextErr,a0
        bsr Print
        bsr Close
        bra FinPrg

*****************************************************************

; Print
Print:  move.l a0,-(sp)
        move.w #$09,-(sp)
        trap #1
        addq.l #6,sp
        rts

; Recopie le nom en PathD / TextL / et (a1)
Recop:  lea Dta+30,a0
        lea PathD1,a2
        lea Text,a3
B1:     move.b (a0)+,d0
        move.b d0,(a1)+
        move.b d0,(a2)+
        move.b d0,(a3)+
        bne.s B1
        rts

; Set Dta
SetDta: pea dta
        move.w #$1a,-(sp)
        trap #1     
        addq.l #6,sp
        rts

; Unlink
UnLink: move.l a0,-(sp)
        move.w #$41,-(sp)
        trap #1
        addq.l #6,sp
        tst.w d0
        rts

; SFisrt
SFirst: clr.w -(sp)
        move.l a0,-(sp)
        move.w #$4e,-(sp)             ;SFIRST
        trap #1
        addq.l #8,sp
        tst.w d0
        rts

; SNext
SNext:  move.w #$4f,-(sp)
        trap #1
        addq.w #2,sp
        tst.w d0
        rts

; Create
Create: clr.w -(sp)
        move.l a0,-(sp)
        move.w #$3c,-(sp)
        trap #1   
        addq.l #8,sp
        move.w d0,Handle
        bmi Erreur
        rts

; Open
Open:   clr.w -(sp)
        move.l a0,-(sp)
        move.w #$3d,-(sp)
        trap #1                       ;OPEN
        addq.l #8,sp
        move.w d0,Handle
        bmi Erreur
        rts

; Load
Load:   pea Fin                       ;adresse de chargement
        move.l Longueur,-(sp)         ;taille du fichier
        move.w Handle,-(sp)
        move.w #$3f,-(sp)
        trap #1
        add.l #12,sp
        cmp.l Longueur,d0
        bne Erreur
        rts
        
; Save
Save:   pea Fin                       ;adresse de debut
        move.l Longueur,-(sp)         ;taille du fichier
        move.w Handle,-(sp)
        move.w #$40,-(sp)
        trap #1
        add.l #12,sp
        cmp.l Longueur,d0
        bne Erreur
        rts
 
; Close
Close:  move.w Handle,-(sp)
        move.w #$3e,-(sp)
        trap #1                       ;close
        addq.l #4,sp
        rts

        dc.l 0
Fin:    dc.l 0

