jmp 	run


**** MKBS1TKT-README  


EXECBASE=	$04

DMACON=		$dff096

OpenLib=	-408
CloseLib=	-414

OpenDevice=	-444
CloseDevice=	-450

Open=		-30
Close=		-36

Write=		-48
Read=		-42

Lock=		-84
UnLock=		-90

CreateDir=	-120
CurrentDir=	-126
Delay=		-198

DoIo=		-456
FindTask=	-294
SetTaskPri=	-300

AddPort=	-354
RemPort=	-360

AllocMem=	-198
Freemem=	-210

run:

subq	#1,d0
beq	NoPars

SearchArgs:

cmp.b	#$20,(a0)+
bne	FoundArgs
dbra	d0,SearchArgs

FoundArgs:

move.b	-(a0),d0	; Compensate for the (a0)+
move.b	d0,FileName+2
move.b	d0,DirNameBS1+2
move.b	d0,DirNameTKT+2
move.b	d0,SDirNameTKT+2
sub.b	#'0',d0
move.b	d0,DriveNumber

NoPars:

move.l	EXECBASE,a6
lea	DosName,a1
jsr	OpenLib(a6)
beq	NoDosBase
move.l	d0,DosBase

move.l	DosBase,a6
move.l	#ConWindowName,d1
move.l	#1005,d2	; Modus OLD
jsr	Open(a6)
beq	NoConHandle
move.l	d0,ConHandle

;move.l	DosBase,a6
move.l	ConHandle,d1
move.l	#ConWindowText1,d2
move.l	#ConWindowText6End-ConWindowText1,d3
jsr	Write(a6)

LmbRmbTest:		; Left = ACTION, Right = NO-ACTION
btst	#10,$dff016
beq	CloseConsole
btst	#6,$bfe001
bne	LmbRmbTest

; ****** MakeSubDirBS1

move.l	DosBase,a6
move.l	#DirNameBS1,d1
jsr	CreateDir(a6)
beq	CloseConsole		; No Dir Created
move.l	d0,DirLockBS1

; ****** Write File in SubDir

;move.l	DosBase,a6
move.l	#FileName,d1
move.l	#1006,d2		; Mode_Write
jsr	Open(a6)
beq	CloseConsole
move.l	d0,FileHandle

;move.l	DosBase,a6
move.l	FileHandle,d1
move.l	#FileText,d2
move.l	#FileTextEnd-FileText,d3
jsr	Write(a6)
cmp.l	#-1,d0
beq	CloseFile		; Couldn't write text in file
move.b	#1,FileWrittenFlag	; File O.K.

CloseFile:
;move.l	DosBase,a6
move.l	FileHandle,d1
jsr	Close(a6)

;move.l	DosBase,a6
move.l	DirLockBS1,d1
jsr	UnLock(a6)

cmp.b	#1,FileWrittenFlag
bne 	CloseConsole

; ****** MakeSubDirTKT

;move.l	DosBase,a6
move.l	#DirNameTKT,d1
jsr	CreateDir(a6)
beq	CloseConsole		; No Dir Created
move.l	d0,DirLockTKT

;move.l	DosBase,a6
move.l	DirLockTKT,d1
jsr	UnLock(a6)

; ****** MakeSubdirTKTBS1

;move.l	DosBase,a6
move.l	#SDirNameTKT,d1
jsr	CreateDir(a6)
beq	CloseConsole		; No Dir Created
move.l	d0,SDirLockTKT

;move.l	DosBase,a6
move.l	SDirLockTKT,d1
jsr	UnLock(a6)


; ****** Get SectorNrs Of UserDirBlocks and FileHeaderBlock

move.l	#FileName,d3
jsr	GetSectorNr
cmp.l	#0,d4
beq	CloseConsole
move.l	d4,FileSectorNr

move.l	#DirNameBS1,d3
jsr	GetSectorNr
cmp.l	#0,d4
beq	CloseConsole
move.l	d4,BS1DirSectorNr

move.l	#DirNameTKT,d3
jsr	GetSectorNr
cmp.l	#0,d4
beq	CloseConsole
move.l	d4,TKTDirSectorNr

move.l	#SDirNameTKT,d3
jsr	GetSectorNr
cmp.l	#0,d4
beq	CloseConsole
move.l	d4,TKTBS1DirSectorNr

; ****** TrackDiskDevice

move.l	EXECBASE,a6
move.l	#512,d0				; 512 bytes in 1 sector
move.l	#$10002,d1			; CHIPCLEAR
jsr	AllocMem(a6)
beq	NoDiskBufferMem
move.l	d0,DiskBufferAddr

move.l	EXECBASE,a6
sub.l	a1,a1
jsr	FindTask(a6)
;move.l	d0,a1
move.l	d0,ReadReply+$10	;Set SigTask

;move.l	#80,d0
; a1 bevat pointer naar task
;jsr	SetTaskPri(a6)

lea 	ReadReply,a1
jsr	AddPort(a6)

lea	DiskIoReq,a1
clr.l	d0
move.b	DriveNumber,d0
clr.l	d1
lea	TrackDiskDevice,a0
move.l	EXECBASE,a6
jsr	OpenDevice(a6)
tst.l	d0
bne	NoTrackDiskDevice

; ****** Modify File

move.l	FileSectorNr,d0
move.w	#2,d5			; Read
jsr	ReadWriteSector		; d0= sectornr / d5= Command

move.l	DiskBufferAddr,a0
move.l	#$-1,324(a0)		; FileSize in bytes
ori.l	#$01,320(a0)		; ProtectionStatus	
move.l	FileSectorNr,496(a0)	; Next Block with same hash = ItSelf

jsr	CalcCheckSum	; Don't forget this !

move.l	FileSectorNr,d0
move.w	#3,d5		; Write
jsr	ReadWriteSector

; ****** Modify BS1SubDir

move.l	BS1DirSectorNr,d0
move.w	#2,d5			; Read
jsr	ReadWriteSector		; d0= sectornr / d5= Command

move.l	DiskBufferAddr,a0
ori.l	#$01,320(a0)		; ProtectionStatus	

jsr	CalcCheckSum	; Don't forget this !

move.l	BS1DirSectorNr,d0
move.w	#3,d5		; Write
jsr	ReadWriteSector

; ****** Modify TKTSubDir

move.l	TKTDirSectorNr,d0
move.w	#2,d5			; Read
jsr	ReadWriteSector		; d0= sectornr / d5= Command

move.l	DiskBufferAddr,a0
ori.l	#$01,320(a0)		; ProtectionStatus	

jsr	CalcCheckSum	; Don't forget this !

move.l	TKTDirSectorNr,d0
move.w	#3,d5		; Write
jsr	ReadWriteSector

; ****** Modify TKTBS1SubDir

move.l	TKTBS1DirSectorNr,d0
move.w	#2,d5			; Read
jsr	ReadWriteSector		; d0= sectornr / d5= Command

move.l	DiskBufferAddr,a0
ori.l	#$01,320(a0)		; ProtectionStatus	
move.l	TKTBS1DirSectorNr,496(a0)	; Next Block with same hash

jsr	CalcCheckSum	; Don't forget this !

move.l	TKTBS1DirSectorNr,d0
move.w	#3,d5		; Write
jsr	ReadWriteSector

; ******

move.l	DosBase,a6
move.l	#150,d1
jsr	Delay(a6)

jsr	DriveMotorOff

NoSectorNr:
move.l	EXECBASE,a6
lea	DiskIoReq,a1
jsr	CloseDevice(a6)

NoTrackDiskDevice:
move.l	EXECBASE,a6
lea	ReadReply,a1
jsr	RemPort(a6)

move.l	DiskBufferAddr,a1
move.l	#512,d0
jsr	FreeMem(a6)

NoDiskBufferMem:
CloseConsole:
move.l	DosBase,a6
move.l	ConHandle,d1
jsr	Close(a6)

NoConHandle:
move.l	EXECBASE,a6
move.l	DosBase,a1
jsr	CloseLib(a6)

NoDosBase:

clr.l	d0
rts
; ********* end of main *********
;
; ******
GetSectorNr:

; input  : d3 = pathname
; output : d4 = SectorNr of FileHeader of Dir
;             = 0 => ERROR NO LOCK FOUND

clr.l	d4

move.l	DosBase,a6
move.l	d3,d1
move.l	#-2,d2			; ACCESS_READ
jsr	Lock(a6)
beq	NoLock
move.l	d0,d1			; Copy the BPTR to D1

lsl.l	#2,d0			; Convert Lock BPTR to APTR
move.l	d0,a0
move.l	4(a0),d4		; Save SectorNr

;move.l	DosBase,a6
; BPTR_Lock already in D1
jsr	UnLock(a6)

NoLock: 
rts

; ******

ReadWriteSector:	

; input  : d0 = sectornr
;          d5 = command

lea	DiskIoReq,a1
move.l	#ReadReply,14(a1)
move.w	d5,28(a1)
move.l	DiskBufferAddr,40(a1)
move.l	#512,36(a1)	;1 sector = lenght
mulu	#512,d0
move.l	d0,44(a1)	; offset
move.l	d0,d2
jsr	DoIo(a6)
cmp.b	#0,31(a1)
beq	ReadWriteOK

move.l	DosBase,a6
move.l	ConHandle,d1
move.l	#ErrorText,d2
move.l	#ErrorTextEnd-ErrorText,d3
jsr	Write(a6)	

ReadWriteOK:
lea	DiskIoReq,a1
move.w	#4,28(a1)	; Update
move.l	EXECBASE,a6
jsr	DoIo(a6)

lea	DiskIoReq,a1
move.w	#5,28(a1)	; Clear
move.l	EXECBASE,a6
jsr	DoIo(a6)

rts

; ******

DriveMotorOff:
lea	DiskIoReq,a1
move.w	#9,28(a1)	;TD_MOTOR
move.l	#0,36(a1)	; Motor Off
move.l	EXECBASE,a6
jsr	DoIO(a6)
rts

; ******

CalcCheckSum:
move.l	DiskBufferAddr,a0
move.l	a0,a1
move.l	#$7f,d1
clr.l	d0
move.l	d0,20(a1)
CheckSumLoop:
sub.l	(a0)+,d0
dbf	d1,ChecksumLoop
move.l	d0,20(a1)	; Correct CheckSum value

rts

;
; ********* Constants

DosName:	dc.b	'dos.library',0
even
TrackDiskDevice: dc.b	'trackdisk.device',0
even
ConWindowName:	dc.b	'CON:0/0/640/200/*** MakeBS1_TKT_README *** Programmed by AMY PRODUCTIONS ***',0
even

; ****** LET OP ! De volgorde van de TextString Constanten
;        is belangrijk omwille van de eenmalige Write() !

ConWindowText1:	dc.b	$9b,"0;33;40m"
	dc.b	$9b,$32,$30,$68	; LF = LF + RT
	dc.b	$9b,"1;32;40m",'IF YOU WANT TO CREATE A SUBDIR CALLED :'
	dc.b	$9b,"0m",$a
ConWindowText1End:
even
DirNameBS1:	dc.b	'df1:        * BAMIGA SECTOR ONE * ',0
DirNameBS1End:
even
ConWindowText2:	dc.b	$a,$9b,"0;33;40m"
	dc.b	$9b,"1;32;40m",'WITH A PROTECTED FILE CALLED :'
	dc.b	$9b,"0m",$a
ConWindowText2End:
even
FileName:		; = DirNameBS1 + FileName
	dc.b	'df1:        * BAMIGA SECTOR ONE * /BS1-README',0
FileNameEnd:
even
ConWindowText3:	dc.b	$a,$9b,"0;33;40m"
	dc.b	$9b,"1;32;40m",'AND FILETEXT :'
	dc.b	$9b,"0m",$a
ConWindowText3End:
even
FileText:	dc.b	'BAMIGA SECTOR ONE :',$0a,$0a
		dc.b	$9b,"1;33;40m",'POSTBOX 163,',$0a
		dc.b	'B-2018 ANTWERP 14,',$0a
		dc.b	'BELGIUM [EUROPE].',$9b,"0m",$0a,$0a
		dc.b	'REMEMBER : DIAMONDS ARE FOREVER ...',$0a
FileTextEnd:
even
ConWindowText4:	dc.b	$a,$9b,"0;33;40m"
	dc.b	$9b,"1;32;40m",'AND A PROTECTED SUBDIR CALLED :'
	dc.b	$9b,"0m",$a
ConWindowText4End:
even
DirNameTKT:	dc.b	'df1:        *** THE KENT TEAM *** ',0
DirNameTKTEnd:
even
ConWindowText5:	dc.b	$a,$9b,"0;33;40m"
	dc.b	$9b,"1;32;40m",'WITH A PROTECTED SUBDIR CALLED :'
	dc.b	$9b,"0m",$a
ConWindowText5End:
even
SDirNameTKT:	dc.b	'df1:        *** THE KENT TEAM *** /'
		dc.b	'THERE IS NOTHING HERE (SORRY!)',0
SDirNameTKTEnd:
even
ConWindowText6:	dc.b	$a,$a,$a,$9b,"1;32;40m"
		dc.b	'[ PRESS LEFT MOUSEBUTTON TO CONTINU '
		dc.b	'OR RIGHT MOUSEBUTTON TO EXIT ]'
		dc.b	$9b,"0m",$0a,$9b,$32,$30,$6c ; LF = LF !
ConWindowText6End:
even
ErrorText:	dc.b	'Er is een fout gebeurt in ReadWriteSector subr.',0
ErrorTextEnd:
even

; ********** Variables

DosBase:	blk.l	1,0
ConHandle:	blk.l	1,0

DirLockBS1:	blk.l	1,0
DirLockTKT:	blk.l	1,0
SDirLockTKT:	blk.l	1,0
OldLock:	blk.l	1,0

FileHandle:	blk.l	1,0
FileWrittenFlag:	blk.b	1,0
even
FileSectorNr:	blk.l	1,0
BS1DirSectorNr:	blk.l	1,0
TKTDirSectorNr:	blk.l	1,0
TKTBS1DirSectorNr:	blk.l	1,0
DiskBufferAddr:	blk.l	1,0
ReadReply:	blk.l	8,0
DiskIoReq:
Message:	blk.b	20,0
Io:		blk.b	12,0
IoReq:		blk.b	16,0
even
DriveNumber:	blk.b	1,1
even
