; Filesystem functions for the Interaction with BIOS and Disks
;
; Copyright (C) 2010 Frank Zoll
+; Copyright (C) 2010,2011,2013 Leo C.
;
; This file is part of avrcpm.
;
; ====================================================================
- .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
-
- 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
+ std z+PTAB_SPT,yl
+ tst yh ;more then 256 sectors per track?
+ breq dpb_imgd_1 ;todo: support 16 bit sector numbers
dsk_imgprp_err:
printnewline
clr temp
ret
+dpb_imgd_1:
+ andi temp2,0x0f
+ swap temp2
+ std z+PTAB_BSH,temp2
+
+ andi temp,~dskType_MASK
+ ldd temp2,z+PTAB_TYPE
+ andi temp2,dskType_MASK
+ or temp,temp2
+ std z+PTAB_TYPE,temp
+
+ ori temp,255
+ ret
+
; ====================================================================
; Function:
; ====================================================================
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
; --------------------------------------------------------------------
; Description:
; ====================================================================
+
dsk_writehost:
- lds zl,hostdsk
- rcall dsk_getpartentry
- ld temp,z
- andi temp,dskType_MASK
-#if FAT16_SUPPORT
-; Is it a FAT16 Diskimage ?
- cpi temp,dskType_FAT
- brne PC+2
- rjmp fat_writehost
-#endif
+.if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
+ printnewline
+ printstring "Host write: "
+.else
+ printstring ", hst WR "
+.endif
+.endif
-; Is it a CP/M Partition ?
- cpi temp,dskType_CPM
- brne PC+2
- rjmp cpm_writehost
-; Disktype not supported -> Return
+ rcall dsk_hostparam
+ breq dsk_hstwr_err
+
+ ldiw z,hostbuf
+ rcall mmcWriteSect
+ tst temp
+ brne dsk_hstwr_err
+
+dsk_hstwr_ok:
+ sts erflag,_0
+ ret
+
+dsk_hstwr_err:
+ sts erflag,_255
ret
; ====================================================================
; --------------------------------------------------------------------
; Description:
; ====================================================================
+
dsk_readhost:
-#if 0
+.if HOSTRW_DEBUG
+.if DISK_DEBUG == 0
printnewline
- printstring "readhost"
- ldiw z,biosdrvtbl
- rcall dbg_hexdump_line
- adiw z,16
- rcall dbg_hexdump_line
-#endif
-
+ printstring "Host read: "
+.else
+ printstring ", hst RD "
+.endif
+.endif
+
+ rcall dsk_hostparam
+ breq dsk_hstrd_err
+
+ ldiw z,hostbuf
+ lcall mmcReadSect
+ tst temp
+ brne dsk_hstrd_err
+
+dsk_hstrd_ok:
+ sts erflag,_0
+ ret
+
+dsk_hstrd_err:
+ sts erflag,_255
+ ret
+
+; ====================================================================
+; Function: Does a Disk write operation
+; ====================================================================
+; Parameters
+; --------------------------------------------------------------------
+; Registers : none
+; Variables : [r] seekdsk Number of Disk to Read
+; [r] seeksec Sector to read
+; [r] seektrk Track to read
+; hostdsk = host disk #, (partition #)
+; hostlba = host block #, relative to partition start
+; Read/Write "hostsize" bytes to/from hostbuf
+; --------------------------------------------------------------------
+; Description:
+; ====================================================================
+
+dsk_hostparam:
+
lds zl,hostdsk
+
+.if HOSTRW_DEBUG
+ mov temp,zl
+ subi temp,-('A')
+ lcall uartputc
+.endif
rcall dsk_getpartentry
- ld temp,z
+ lds xl,hostlba ; get sector to access
+ lds xh,hostlba+1
+
+.if HOSTRW_DEBUG
+ printstring ": lba "
+ push r15
+ push r14
+ clr r14
+ clr r15
+ movw temp,x
+ lcall print_ultoa
+ pop r14
+ pop r15
+.endif
+
+ ldd _tmp0,z+PTAB_SIZE ; get disksize
+ ldd _tmp1,z+PTAB_SIZE+1
+
+ cp xl,_tmp0 ; check given sector against disksize
+ cpc xh,_tmp1
+ brcc dsk_hst_param_err
+
+ ldd temp,z+PTAB_TYPE
andi temp,dskType_MASK
#if FAT16_SUPPORT
; Is it a FAT16 Diskimage ?
cpi temp,dskType_FAT
- brne PC+2
- rjmp fat_readhost
+ brne dsk_hstpar_nofat
+ rcall fat_lba_to_phys
+ rjmp dsk_hstpar_gotit
+dsk_hstpar_nofat:
#endif
-
+#if CPMDSK_SUPPORT
; Is it a CP/M Partition ?
cpi temp,dskType_CPM
- brne PC+2
- rjmp cpm_readhost
-; Disktype not supported -> Return
+ brne dsk_hstpar_nocpm
+ lcall cpm_lba_to_phys
+ rjmp dsk_hstpar_gotit
+dsk_hstpar_nocpm:
+#endif
+; Disktype not supported
+ rjmp dsk_hst_param_err
+
+dsk_hstpar_gotit:
+
+.if HOSTRW_DEBUG
+ printstring ", abs "
+ push r15
+ push r14
+ push temp2
+ push temp
+ movw temp,x
+ movw r14,y
+ lcall print_ultoa
+ pop temp
+ pop temp2
+ pop r14
+ pop r15
+.endif
+
+ ori temp,255
ret
+dsk_hst_param_err:
+
+.if HOSTRW_DEBUG
+ printstring ", max: "
+ push r15
+ push r14
+ push temp2
+ push temp
+ movw temp,_tmp0
+ clr r14
+ clr r15
+ lcall print_ultoa
+ pop temp
+ pop temp2
+ pop r14
+ pop r15
+ printstring " "
+.endif
+
+ clr temp
+ ret
+; --------------------------------------------------------------------
; vim:set ts=8 noet nowrap