	opt l-
	
	incdir "df1:include/"
	include "exec/exec_lib.i"
	include "exec/macros.i"
	include "devices/trackdisk.i"
	include "libraries/dos_lib.i"
	include "libraries/dos.i"
	include "exec/memory.i"
	include "intuition/intuition_lib.i"
	include "intuition/intuition.i"
	include "graphics/graphics_lib.i"
	
	lea grafname,a1
	moveq #0,d0
	CALLEXEC OpenLibrary
	move.l d0,_GfxBase
	
	lea dosname,a1
	moveq #0,d0
	CALLEXEC OpenLibrary
	move.l d0,_DOSBase
	
	lea intname,a1
	moveq #0,d0
	CALLEXEC OpenLibrary
	move.l d0,_IntuitionBase

	CALLDOS Output
	move.l d0,d1
	move.l #frase,d2
	move.l #lun,d3
	CALLDOS Write
LetsGo	btst #6,$BFE001
	bne.s LetsGo
	CALLINT OpenWorkBench
	move.l d0,a0
	move.l sc_FirstWindow(a0),a1
	move.l a1,Finestra
	move.l wd_FirstRequest(a1),a0
	cmpa.l #0,a0
	beq CanceFines
	CALLINT EndRequest
CanceFines
	move.l Finestra,a4
	move.l wd_NextWindow(a4),a0
	cmpa.l #0,a0
	beq Avanti
	CALLINT CloseWindow
Avanti	move.l a4,a0
	CALLINT CloseWindow
	clr.l d0
	CALLGRAF FreeSprite
	CALLINT CloseWorkBench
	move.l _IntuitionBase,a1
	CALLEXEC CloseLibrary
	move.l _GfxBase,a1
	CALLEXEC CloseLibrary
	move.l _DOSBase,a1
	CALLEXEC CloseLibrary
	bsr Inizializza
	
	
	move.l #1024,d0
	move.l #MEMF_CHIP!MEMF_CLEAR,d1
	CALLEXEC AllocMem
	move.l d0,buffer
	
	move.l ioExtReq,a1
	move.l #1,IO_LENGTH(a1)
	move #TD_MOTOR,IO_COMMAND(a1)
	CALLEXEC DoIO
	
	move.l ioExtReq,a1
	clr.l IO_OFFSET(a1)
	move.l #2,d0
	lsl.l #8,d0
	lsl.l #1,d0
	move.l d0,IO_LENGTH(a1)
	move.l buffer,IO_DATA(a1)
	move #CMD_READ,IO_COMMAND(a1)

	CALLEXEC DoIO	; legge blocchi 0,1
	
	move.l buffer,a0
	add.l #12,a0	; Saltare le 3 long
	move.l ioExtReq,a1
	clr.b IO_FLAGS(a1)
	move.l $4,a6
	move #CMD_READ,IO_COMMAND(a1)
	jsr (a0)
	rts

Inizializza
	CREATEPORT nomeporta,#0
	
	CREATEEXTIO

	lea devname,a0
	clr.l d0
	move.l ioExtReq,a1
	clr.l d1
	CALLEXEC OpenDevice
	rts


nomeporta	dc.b 'Trackdisk.message',0
	cnop 0,2
devname	dc.b 'trackdisk.device',0
	cnop 0,2	
buffer	dc.l 0
intname	INTNAME
grafname	GRAFNAME
dosname	dc.b 'dos.library',0
	cnop 0,2
frase	dc.b 'Please insert the disk to launch and press the LEFT mouse button.',10
	dc.b '(Do not care about the Requester,if present:it will be AUTOMATICALLY closed)',0
lun	equ *-frase
_IntuitionBase	ds.l 1
Finestra	ds.l 1
_DOSBase	ds.l 1
_GfxBase	ds.l 1
