+
+ xor a
+ ld (bootdsk),a
+ ld a,(dpb)
+ ld (bootspt),a
+
+ ld c,'I'-'A'
+ call seldsk
+ ld a,h
+ or l
+ jp z,boot1
+
+ ld de,10
+ add hl,de
+ ld e,(hl)
+ inc hl
+ ld d,(hl) ;de = dpb of first ram disk
+
+ ld hl,7
+ add hl,de
+ ld a,(hl) ;get drm
+ add 3 ;ToDo: this works only up to 252 dir entries
+ and 0fch
+ rrca ;4 dir entries per sector
+ rrca ;Number of sectors to init
+ push af
+
+ ld bc,6
+ add hl,bc
+ ld c,(hl) ;Start track (= # of reserved tracks)
+ push bc ;Save track
+
+; Check, if we have reserved tracks.
+ ld a,c
+ or a
+ jp z,boot0 ;Skip if not.
+
+; Save CPM to ram disk.
+
+ ld a,(de) ;sectors per track
+ ld (bootspt),a
+ ld a,'I'-'A'
+ ld (bootdsk),a
+ call home
+ ld b,nsects
+ ld c,0 ;track
+ ld d,1 ;sektor (0 based)
+ ld hl,ccp
+store1:
+ push bc
+ push de
+ push hl
+ ld c,d
+ ld b,0
+ call setsec
+ pop bc
+ push bc
+ call setdma
+ ld c,0
+ call write
+
+ pop hl
+ ld de,128
+ add hl,de
+ pop de
+ pop bc
+ dec b
+ jp z,boot0
+
+ inc d
+ ld a,(bootspt)
+ dec a
+ cp d ;if sector >= spt then change tracks
+ jp nc,store1
+
+ ld d,0
+ inc c
+ push bc
+ push de
+ push hl
+ ld b,0
+ call settrk
+ pop hl
+ pop de
+ pop bc
+ jp store1
+
+; Clear directory area of ram disk.
+
+boot0:
+ pop bc
+ call settrk
+ pop af
+ ld d,a ;d = # of sectors
+ ld e,0 ;e = sector
+ push de
+ ld hl,dirbuf ;Clear dirbuf
+ ld c,128
+ ld a,0E5h
+boot_cl:
+ ld (hl),a
+ inc hl
+ dec c
+ jp nz,boot_cl
+
+ ld bc,dirbuf
+ call setdma
+ pop de
+boot_cl2:
+ push de
+ ld c,e
+ ld b,0
+ call setsec
+ ld c,0
+ call write
+ pop de
+ inc e
+ dec d
+ jp nz,boot_cl2
+
+boot1: