
; Program : MakeRes 1.0
; Date    : end of 1992
; Author  : G.Nikl
;
;   snail mail: Gunther Nikl
;               Hans-Beimler-Str 17
;               Parchim
;               O-2850
;
;        email: gnikl@informatik.uni-rostock.de

; MakeRes installs 'HackDisk' by Dan Babcock resident in ram
; This is done via KickMemPtr & KickMemList so it should work
; on all systems.Should be called as the first program in the
; STARTUP-SEQUENCE ( yes the STARTUP-SEQUENCE ) because of a
; reset we have to do to activate the new trackdisk.device !
; The RESET is done without any message with the official reset
; code by Commodore. The program checks first if hackdisk is
; installed. If so all work is already done. If not we try to
; load the device from disk ( please place hackdisk in DEVS: ).
; I wrote this tiny program because i had nothing to install
; hackdisk.device in my system (Fred Fish deleted the support
; utility hackdisk was supplied with).
;
;   Disclaimer
;   ~~~~~~~~~~~
;   The author cannot be held liable for the suitability or accuracy of
;   this the program.  Any damage directly or indirectly caused by the
;   use or misuse of this the program is the sole responsibility of the
;   user her/him self.

; This program and the source are public domain

_LVOSupervisor		equ	-30
_LVOAllocMem		equ	-198
_LVOFindName		equ	-276
_LVOCloseLibrary	equ	-414
_LVOOpenLibrary		equ	-552
_LVOSumKickData		equ	-612

_LVOLoadSeg		equ	-150
_LVODelay		equ	-198

KickMemPtr		equ	546
KickTagPtr		equ	550
KickCheckSum		equ	554

main		movea.l 4.w,a6			; ExecBase
		lea     350(a6),a0		; DevList
		lea     OldDevice(pc),a1	; TrackDisk
		jsr     _LVOFindName(a6)
		move.l	d0,a0
		move.l	a0,d0
		beq	nodos
		move.l	24(a0),a0		; IdString
		lea	NewDevice+5(pc),a1
		moveq	#7,d2
.check		moveq	#$5f,d0
		and.b	(a0)+,d0		; umwandeln in
		moveq	#$5f,d1
		and.b	(a1)+,d1		; Kleinbuchstaben
		cmp.b	d0,d1
		dbne	d2,.check		; weiter vergleichen
		beq	nodos			; installiert !
		lea     DosName(pc),a1
		moveq   #33,d0
		jsr     _LVOOpenLibrary(a6)	; DOS oeffen
		movea.l d0,a5
		move.l  a5,d0
		beq     nodos			; Fehler !
		lea     NewDevice(pc),a1
		move.l  a1,d1
		exg     a6,a5
		jsr     _LVOLoadSeg(a6)		; Device ueber DOS laden
		exg     a6,a5
		movea.l d0,a3
		move.l  a3,d0
		beq.s   nodev			; Fehler !
		adda.l  a3,a3
		adda.l  a3,a3
		move.l  -(a3),d3		; Hunkgroesse

; Eigentlich muessten nur 40 Bytes reserviert werden. Diese liegen dann aber
; im unguenstigten Fall in einem Bereich der beim Booten! durch ( nur? )
; KickStart 1.2 ueberschrieben wird. Dieser Fall kann eintreten ein, wenn die
; Startup-Sequence noch vor Ausfuehrung des ersten Befehls abgebrochen wird.
; Wird nun dieses Programm ausgefuehrt, so wird die KickMemList bei einer
; Groesse von 40 Bytes in diesem fraglichem Bereich abgelegt. Bevor alle in
; den KickMemList(s) belegt werden holt sich Exec Speicher, gibt diesen aber
; teilweise! wieder frei. Dh. man bekommt bei Ausfuehrung dieses Programmes
; unter Umstaenden schon genutzten Speicher !

		moveq   #56,d0
		moveq   #1,d1
		swap    d1
		jsr     _LVOAllocMem(a6)	; Speicher fuer
						; MemList & KickTag
		movea.l d0,a2
		lea     14(a2),a0
		moveq   #2,d2
		move.w  d2,(a0)+		; Anzahl Entries in MemList
		move.l  a2,(a0)+		; Adresse der MemList
		moveq   #40,d2
		move.l  d2,(a0)+		; Groesse der MemList
		move.l  a3,(a0)+		; Adresse des Devices
		move.l  d3,(a0)+		; Groesse des Devices
		addq.l  #8,a3			; richtige Adresse des
		move.l  a3,(a0)			; Devices eintragen
		move.l  KickTagPtr(a6),4(a0)	; alten KickTag retten
		beq.s   1$			; war nichts da
		bset    #31,4(a0)		; Fortsetzung kennzeichnen
1$		move.l  a0,KickTagPtr(a6)	; neuen KickTag eintragen
		move.l  KickMemPtr(a6),d0	; KickMem belegt ?
		beq.s   2$			; nein
		move.l  d0,(a2)			; Nachfolger
		movea.l d0,a0
		move.l  a2,4(a0)		; Vorgaenger
2$		move.l  a2,KickMemPtr(a6)	; neues KickMem eintragen
		jsr     _LVOSumKickData(a6)	; Checksumme berechnen
		move.l  d0,KickCheckSum(a6)	; eintragen
		exg     a6,a5
		moveq   #25,d1			: change to suit
		jsr     _LVODelay(a6)		; 1/2 Sekunde warten
		exg     a6,a5
		lea     $01000004,a4		; Computer neustarten
		suba.l  -$18(a4),a4
		movea.l (a4),a4
		subq.l  #2,a4
		lea     ResetCode(pc),a5
		jsr     _LVOSupervisor(a6)
		cnop    0,4
ResetCode	reset
		jmp    (a4)

nodev		movea.l a5,a1			; bei Fehler DOS schliessen
		jsr     _LVOCloseLibrary(a6)
nodos		moveq   #0,d0
		rts

DosName		dc.b	'dos.library',0
		even
OldDevice	dc.b    'trackdisk.device',0
		even
NewDevice	dc.b	'devs:hackdisk.device',0
		even


