;   This is FastFlop, which speeds up your Atari ST's floppy disks
;   Copyright (C) 1989  by Robert Fischer
;
;	This program costs no money; you can redistribute it and/or modify it
;	under the terms of the Lynxware General License as published by Robert
;	Fischer; either version 1, or (at your option) any later version. 
;
;   This program is distributed in the hope that it will be useful,
;   but WITHOUT ANY WARRANTY; without even the implied warranty of
;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;   Lynxware General License for more details.
;
;   You should have received a copy of the Lynxware General License
;   along with this program; if not, write to the author.
;
;   To contact the author, call or write:
;       Robert Fischer
;       80 Killdeer Road
;       Hamden, CT    06517
;       (203) 288-9599
;		E-mail: fischer-robert@cs.yale.edu

.extern _oxbios_p
.extern _flopwr_vec		; address of flopwr routine
.extern _floprd_vec

* These are AL support routines for FastFlop
* Assemble with MADMAC
*----------------------------------------------------------
* Fastcpy -- copy unaligned 512 byte blocks
*----------------------------------------------------------
_fastcpy::
        move.l      4(sp), a0
        move.l      8(sp), a1
        move.w      #63, d0

fast1:  move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        move.b      (a0)+, (a1)+
        dbra        d0, fast1
        rts

; ************ A patch to go2track

*------ Floppy state variables in DSB:
recal       =   $ff00
dcurtrack   =   0
dseekrt     =   dcurtrack+2
dsbsiz      =   dseekrt+2


*---------- Addresses which must be relocated
flopcmds    = $17340001
ctrack      = $1702
;dcurtrack  = $1703

*---------- Patch to change the way that go2track works
_go2tr_patch::
        move.w  ctrack(a5), d7
        cmp     dcurtrack(a1), d7 ; already on correct track?
        bne     go2ver        ; (no) verify
        move.w  #$10, d6      ; (yes) use "seek w/o verify"
go2ver:
        jsr     flopcmds
        bne     go2trr
        move.w  ctrack(a5), dcurtrack(a1)
        and.b   #$18, d7
go2trr:     rts

*---------- The other patch, to call critic() correctly from change()
_change_patch::
        move.w  d0,-(sp)
        move.w  #-17,-(sp)
        bsr.s   _critic
_cpatch_jmp::
        jmp     $DDDDDDDD   ; <-- To be relocated, jump back to RAM code

*----------------------------------------------------------
* Critical Error Handler
*----------------------------------------------------------
etv_critic  =   $404
_critic::   move.l  etv_critic,-(sp)
_critich:   moveq   #-1, d0
            rts

; ----------------------------------------------------------
; Stuff to replace the Xbios Floprd and Flopwr handler
; Replace the X-Bios trap handler
; ----------------------------------------------------------
; THIS DOESN'T WORK AND IS NOT NEEDED!  THAT'S WHY IT'S COMMENTED OUT!!!

_nxbios::
;	move.l	saveptr, a1			; Allocate save-area storage
;	sub.l	#10, a1
;	move.l	a1, saveptr
;
;	move.w	(sp)+, d0
;	move.w	d0, 8(a1)			; Save SR
;	move.l	(sp)+, 4(a1)		; Save Return Address
;	move.l	a7, (a1)			; Save stack ptr
;
;							; SR in d0
;	btst	#13, d0			; Test SR, to switch to correct stack
;	bne.s	.b_supr
;	move.l	usp, a7			; Put on user stack instead
;.b_supr:
;
;	tst.w	10(sp)			; Test device number
;	beq.s	.good_dev		; Pass on if wrong drive
;	cmp.w	#1, 10(sp)
;	bne.s	.pass_on
;.good_dev:
;
;	cmp.w	#9, (sp)			; Check for flopwr
;	beq.s	.l3
;	cmp.w	#8, (sp)			; Check for floprd
;	beq.s	.l3
;
;.pass_on:
;	move.l	(a1), a7				; Restore old stack ptr
;	move.l	4(a1), -(sp)			; Restore Ret. addr and SR
;	move.w	8(a1), -(sp)
;	add.l	#10, a1
;	move.l	a1, saveptr
;
;	move.l	_oxbios_p, -(sp)		; do old Xbios.
;	rts
;
;.l3:
;	sub.l	#36, a1				; 40 bytes used minus stuff used for a7
;	move.l	a1, saveptr
;
;	movem.l	d3-d7/a3-a7, (a1)	; Save C registers
;
;	move.w	(sp)+, d0			; Pop Function number
;	cmp.w	#8, d0				; Check for floprd
;	beq.s	.lfloprd
;
;.lflopwr:
;	move.l	_flopwr_vec, a1
;	bra.s	.do_it
;.lfloprd:
;	move.l	_floprd_vec, a1
;
;.do_it:
;	jsr		(a1)
;
;	move.l	saveptr, a1				; Restore back to system stack, exit
;	movem.l	(a1)+, d3-d7/a3-a7
;	move.l	(a1)+, -(sp)
;	move.w	(a1)+, -(sp)
;	move.l	a1, saveptr				; Restore save pointer
;	rte
;
;	.bss
;save_satrt:	ds.b	460				; Every call uses 46 bytes
;save_end:
;
;	.data
;saveptr: dc.l save_end
