.equ MEMTEST = 1
.equ MEMFILL = 1
.equ MMC_DEBUG = 0 /* Increase for more debugging */
+.equ MMC_DEBUG_RDW = 0
.equ DSKSEL_DEBUG = 0
.equ DISK_DEBUG = 0 /* 1 = BOOT/HOME debug, 2 = +R/W debug */
.equ HOSTRW_DEBUG = 0
.equ o_fat_clust_offset= 17
.equ o_fat_clust_ptr = 18
+.if SRAM_SIZE > 1024
+
+fat_last_fatsect: .byte 1
+ .equ o_fat_last_fatsect = 22
+
+fat_buf: .byte 512
+
+.endif
; ############################################################################
; Start of Code Segment
std y+o_fat_log_clust ,_255
std y+o_fat_log_clust+1,_255
std y+o_fat_last_dsk ,_255
+.if SRAM_SIZE > 1024
+ std y+o_fat_last_fatsect,_255
+.endif
+
ret
; ============================================================================
ldd xh,z+1
ldd yl,z+2
ldd yh,z+3
+ ldiw z,hostbuf
; Load first sector from Partition
rcall mmcReadSect
sbc yh,_0
; Load sector from Directory
+ ldiw z,hostbuf
lcall mmcReadSect
tst temp
breq fat_look_for_images
push xl
push xh
-; Create FAT Offset Value
+; Create FAT Offset Value
+
clr zh
mov zl,yl
lsl zl
rol zh
-; Get FAT Start
mov temp,yh
- lds xl,fat_ptr2fat
+
+.if SRAM_SIZE > 1024
+
+; Check, if required fat sector allready in buffer
+
+ lds temp2,fat_last_fatsect
+ sts fat_last_fatsect,temp
+ cp temp,temp2
+ breq fat_phys_1
+
+; Not in buffer, get fat sector
+
+ lds xl,fat_ptr2fat ;get FAT start
lds xh,fat_ptr2fat+1
lds yl,fat_ptr2fat+2
lds yh,fat_ptr2fat+3
-; Add Cluster offset within sector
- add xl,temp
+ add xl,temp ;add cluster offset within sector
+ adc xh,_0
+ adc yl,_0
+ adc yh,_0
+ push zl
+ push zh
+ ldiw z,fat_buf
+ lcall mmcReadSect
+ pop zh
+ pop zl
+
+fat_phys_1:
+ ldiw y,fat_buf
+ add zl,yl
+ adc zh,yh
+ ldd yl,z+0
+ ldd yh,z+1
+.else
+
+ lds xl,fat_ptr2fat ;get FAT start
+ lds xh,fat_ptr2fat+1
+ lds yl,fat_ptr2fat+2
+ lds yh,fat_ptr2fat+3
+ add xl,temp ;add cluster offset within sector
adc xh,_0
adc yl,_0
adc yh,_0
lcall mmcReadWord
-
+ movw y,z
+.endif
pop xh
pop xl
- movw y,z
; Check next logical Cluster
; ====================================================================
- .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
;Load first sector from MMC (boot sector)
ldiw y,0 ; Sector 0
movw x,y
+ ldiw z,hostbuf
lcall mmcReadSect
tst temp
breq mgr_check_bootsektor
.if MEMFILL
ldiw x,0
+ ldi temp,MEMFILL_VAL
ramfillw:
- ldi temp,MEMFILL_VAL
rcall dram_write_pp
brcc ramfillw
.endif
mmcReadWord:
-.if MMC_DEBUG > 1
+.if (MMC_DEBUG > 1) || (MMC_DEBUG_RDW > 0)
printnewline
printstring "mmcRdWord "
.endif
rjmp mmc_rwexit_error
mmc_rw_1:
- ldiw y,hostbuf ;aarrrgh
- sbrs temp3,MMC_RDWORD
- movw z,y
ldiw y,512
sbrs temp3,MMC_RDOP
rjmp mmc_wroper
out SPDR,_255
mov zh,temp
+.if MMC_DEBUG_RDW > 0
+ movw temp,z
+ lcall printhexw
+ printstring " "
+.endif
+
; discard the rest
mmc_rcvw_rl2: