; ====================================================================
- .dseg
-tmpdpb: .byte 16
-
- .cseg
str_CPM_Disk:
.db 10,"<CPM_Disk>",0
#endif
-; Copy the dpb data from flash memory, pointed to by Z, to temp ram.
-
-dpb_copy_p:
- push yh
- push yl
- ldi temp2,16
- ldiw y,tmpdpb
-cpydpb_pl:
- lpm temp,z+
- st y+,temp
- dec temp2
- brne cpydpb_pl
- pop yl
- pop yh
- ret
-
-; Copy the dpb data, pointed to by Z to temp ram.
-
-dpb_copy:
- st y+,temp
- ldi temp2,15
-cpydpb_l:
- ld temp,z+
- st y+,temp
- dec temp2
- brne cpydpb_l
- ret
-
; ====================================================================
; Function: get drive table entry pointer for drive # in temp
lcall strncmp_p
brne dsk_tyze_not
- ldiw z,hostbuf+32
- ldiw y,tmpdpb
+ ldiw z,hostbuf+31
+ clt ;dpb in RAM
ldi temp,1 ;1 sector header size
- rcall dpb_copy
+ st z,temp
ori temp,0xff
ret
dec temp2
brne dsk_tmyz80_loop
+ ldiw z,dpbdat_myz80*2
+ set
ori temp,0xff
ret
brne dsk_tsimhd_loop
dsk_tsimhd_found:
+ ldiw z,dpbdat_simhd*2
+ set
ori temp,0xff
ret
; Test for simhd format.
rcall dsk_tst_simhd
- ldiw z,dpbdat_simhd*2
- brne dsk_imgt_fixed
+ brne dsk_imgt_done
; Test for MyZ80 format.
rcall dsk_tst_myz80
- ldiw z,dpbdat_myz80*2
- brne dsk_imgt_fixed
+ brne dsk_imgt_done
; No special image found. Use avrcpm.
ldiw z,dpbdat_avrcpm*2
-
-dsk_imgt_fixed:
- rcall dpb_copy_p
+ set
ori temp,0xff
+
dsk_imgt_done:
ret
rcall dsk_format_get
breq dpb_imgd_err ;no known format detected
-;
+dpb_imgd_0:
+ brtc dpb_imgd_variable
+dpb_imgd_fixed:
+ lpm temp, z+ ;image header
+ lpm yl,z+ ;low(SPT)
+ lpm yh,z+ ;high(SPT)
+ lpm temp2,z+ ;BSH
+ rjmp dpb_imgd_common
+
+dpb_imgd_variable:
+ ld temp, z+ ;image header
+ ld yl,z+ ;low(SPT)
+ ld yh,z+ ;high(SPT)
+ ld temp2,z+ ;BSH
+
+dpb_imgd_common:
mov zl,temp3
rcall dsk_getpartentry ;get partition entry
- ldiw y,tmpdpb
-
-; std y+12,_0 ;Test: set check size to 0
-; std y+13,_0
+ std z+PTAB_SPT,yl
+ tst yh ;more then 256 sectors per track?
+ brne dsk_imgprp_err ;todo: support 16 bit sector numbers
+
+ andi temp2,0x0f
+ swap temp2
+ std z+PTAB_BSH,temp2
- ldd temp,y+0
andi temp,~dskType_MASK
ldd temp2,z+PTAB_TYPE
andi temp2,dskType_MASK
or temp,temp2
std z+PTAB_TYPE,temp
- ldd temp,y+1
- std z+PTAB_SPT,temp
- ldd temp,y+2
- tst temp ;more then 256 sectors per track?
- brne dsk_imgprp_err ;todo: support 16 bit sector numbers
- ldd temp2,y+3
- andi temp2,0x0f
- swap temp2
- std z+PTAB_BSH,temp2
-
+
ori temp,255
ret
breq dpb_di_err_p1
movw x,temp
- ldiw z,tmpdpb+1 ;skip sector offset byte
+ adiw z,1 ;skip sector offset byte
+ push temp3
+ ldi temp3,15
dpb_dicpl:
- ld temp,z+
+ brtc PC+2 ;
+ lpm temp,z+
+ brts PC+2 ;
+ ld temp,z+
rcall dram_write_pp
- cpi zl,low(tmpdpb + 16)
+ dec temp3
brne dpb_dicpl
+ pop temp3
sbiw x,15
+ sbiw z,15
movw temp,x
movw x,y
adiw x,10
rcall dram_writew_pp ;DPB
-
+
+ brtc dpb_dicks_variable
+dpb_dicks_fixed:
+ adiw z,5
+ lpm _tmp0,z+ ;dsm
+ lpm _tmp1,z+
+ adiw z,11-5-2
+ lpm temp,z+ ;cks
+ lpm temp2,z+
+ rjmp dpb_dicks_common
+dpb_dicks_variable:
+ ldd _tmp0,z+5 ;dsm
+ ldd _tmp1,z+5+1
+ ldd temp,z+11 ;cks
+ ldd temp2,z+11+1
+
; get mem for dir check vector
- lds temp,tmpdpb+12 ;cks
- lds temp2,tmpdpb+12+1
+dpb_dicks_common:
cp temp,_0
cpc temp2,_0
breq dpb_dicks0
; get mem for alloc vector
- lds temp,tmpdpb+6 ;dsm
- lds temp2,tmpdpb+6+1
+ movw temp,_tmp0
subi temp, low (-8)
sbci temp2,high(-8)
lsr temp2
dsk_writehost:
.if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
+ printnewline
+ printstring "Host write: "
+.else
printstring ", hst WR "
+.endif
.endif
rcall dsk_hostparam
breq dsk_hstwr_err
+ ldiw z,hostbuf
rcall mmcWriteSect
tst temp
brne dsk_hstwr_err
dsk_readhost:
.if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
+ printnewline
+ printstring "Host read: "
+.else
printstring ", hst RD "
+.endif
.endif
rcall dsk_hostparam
breq dsk_hstrd_err
+ ldiw z,hostbuf
rcall mmcReadSect
tst temp
brne dsk_hstrd_err