.equ BOOTWAIT = 1
.equ PORT_DEBUG = 0
.equ DISK_DEBUG = 0
+.equ HOSTRW_DEBUG= 0
.equ MEMFILL_CB = 1
.equ STACK_DBG = 0
.equ PRINT_PC = 0
boot_again:
ldi yh,0
ldi yl,0
- ldi xh,0
- ldi xl,0
+ movw x,y
rcall mmcReadSect
;Test, if it has a valid MBR
ldi temp4,0xAA
cpi temp,0x55
cpc temp2,temp4
+ ldi opl,0 ;opl holds number of found disks (paritions)
breq boot_part
;No MBR, no partition table ...
- ldi opl,1
- sts ndisks,opl
+ inc opl ;pretend we have one.
rjmp boot_ipl
;Search Partition Table for CP/M partitions
boot_part:
ldi zl,low(hostbuf+510-64)
ldi zh,high(hostbuf+510-64)
- ldi yl,low(hostdstart)
- ldi yh,high(hostdstart)
- ldi opl,0
+ ldi yl,low(hostparttbl)
+ ldi yh,high(hostparttbl)
ldi oph,high(hostbuf+510)
boot_ploop:
ldd temp,z+PART_TYPE
cpi temp,PARTID
brne boot_nextp
+; Found a CP/M partition
+
ldd temp,z+PART_START
st y+,temp
ldd temp2,z+PART_START+1
rcall printstr
.db ", size: ",0,0
ldd temp,z+PART_SIZE
+ st y+,temp
ldd temp2,z+PART_SIZE+1
+ st y+,temp2
ldd temp3,z+PART_SIZE+2
+ st y+,temp3
ldd temp4,z+PART_SIZE+3
+ st y+,temp4
lsr temp4
ror temp3
ror temp2
.db "KB.",13,0,0
inc opl
- cpi temp2,MAXDISKS
+ cpi opl,MAXDISKS
breq boot_pend
boot_nextp:
adiw zl,16
brsh boot_pend
rjmp boot_ploop
boot_pend:
- sts ndisks,opl
; Read first sector of first CP/M partition
- lds xl,hostdstart
- lds xh,hostdstart+1
- lds yl,hostdstart+2
- lds yh,hostdstart+3
+ lds xl,hostparttbl
+ lds xh,hostparttbl+1
+ lds yl,hostparttbl+2
+ lds yh,hostparttbl+3
rcall mmcReadSect
boot_ipl:
- lds opl,ndisks
+ sts ndisks,opl
tst opl
brne boot_ipl2
rcall printstr
brsh noprintpc
rcall printstr
- .db "PC=",0
+ .db 13,"PC=",0
mov temp,z_pch
rcall printhex
mov temp,z_pcl
rcall printhex
- ldi temp,10
- rcall uartputc
+ ldi temp,' '
+; ldi temp,10
+; rcall uartputc
noprintpc:
.endif
seektrk: .byte 2 ;seek track number
seeksec: .byte 1 ;seek sector number
+hostparttbl: .byte 8*MAXDISKS ; host partition table (start sector, sector count)
hostdsk: .byte 1 ;host disk number
hostlba: .byte 3 ;host sector number (relative to partition start)
-hostdstart: .byte 4*MAXDISKS ; host disks start sector (partition)
unacnt: .byte 1 ;unalloc rec cnt
unadsk: .byte 1 ;last unalloc disk
cpi temp2,15
breq dskDiskCheck
+ cpi temp2,22
+ breq dskErrorRet
cpi temp2,TIMER_MSECS
brlo pr_noclock
brlt PC+2
ldi temp,0xff ;error return
ret
+
+dsk_dchend:
+ ldi temp,0
+ ret
+
+dskErrorRet:
+ lds temp,erflag
+ ret
dskDiskSel:
sts seekdsk,temp
ret
dskDoIt:
+.if DISK_DEBUG
+ push temp
+ sbrc temp,READ_FUNC
+ rjmp dskdbgr
+ sbrc temp,WRITE_FUNC
+ rjmp dskdbgw
+ rjmp dskdbge
+
+dskdbgr:
+ rcall printstr
+ .db 13,"Disk read: ",0
+ rjmp dskdbg1
+dskdbgw:
+ rcall printstr
+ .db 13,"Disk write: ",0
+dskdbg1:
+ lds temp,seekdsk
+ subi temp,-('A')
+ rcall uartputc
+ rcall printstr
+ .db ": track ",0,0
+ lds temp,seektrk+1
+ rcall printhex
+ lds temp,seektrk
+ rcall printhex
+ rcall printstr
+ .db " sector ",0,0
+ lds temp,seeksec
+ rcall printhex
+ rcall printstr
+ .db " dma-addr ",0,0
+ lds temp,dmaadr+1
+ rcall printhex
+ lds temp,dmaadr
+ rcall printhex
+ pop temp
+ push temp
+ sbrs temp,WRITE_FUNC
+ rjmp dskdbge
+ rcall printstr
+ .db " wrtype ",0,0
+ andi temp,3
+ rcall printhex
+dskdbge:
+ pop temp
+.endif
;See what has to be done.
sbrc temp,READ_FUNC
rjmp dsk_read
dsk_read:
-.if 0
- rcall timer_quit
- rcall printstr
- .db " In",0
-.endif
+ sbi flags,readop ;read operation
+ ;RAM disk?
+ lds temp2,seekdsk
+; cpi temp2,RAMDISKNR
+; brlt PC+2
+; rjmp rdskDoIt
-.if DISK_DEBUG
- push temp
- rcall printstr
- .db 13,0
- rcall printstr
- .db "Disk read: track ",0
- lds temp,seektrk+1
- rcall printhex
- lds temp,seektrk
- rcall printhex
- rcall printstr
- .db " sector ",0,0
- lds temp,seeksec
- rcall printhex
- rcall printstr
- .db " dma-addr ",0,0
- lds temp,dmaadr+1
- rcall printhex
- lds temp,dmaadr
- rcall printhex
-; rcall printstr
-; .db ".",13,0,0
- pop temp
-.endif
sts unacnt,_0
- sbi flags,readop ;read operation
sbi flags,rsflag ;must read data
ldi temp,WRUAL ;write type
sts wrtype,temp ;treat as unalloc
dsk_write:
;write the selected CP/M sector
- andi temp,WRTMSK
- sts wrtype,temp ;save write type
cbi flags,readop ;not a read operation
-.if DISK_DEBUG
- push temp
- rcall printstr
- .db 13,0
- rcall printstr
- .db "Disk write: track ",0,0
- lds temp,seektrk+1
- rcall printhex
- lds temp,seektrk
- rcall printhex
- rcall printstr
- .db " sector ",0,0
- lds temp,seeksec
- rcall printhex
- rcall printstr
- .db " dma-addr ",0,0
- lds temp,dmaadr+1
- rcall printhex
- lds temp,dmaadr
- rcall printhex
- rcall printstr
- .db " wrtype ",0,0
- lds temp,wrtype
- rcall printhex
-; rcall printstr
-; .db ".",13,0,0
- pop temp
-.endif
+ ;RAM disk?
+ lds temp2,seekdsk
+; cpi temp2,RAMDISKNR
+; brlt PC+2
+; rjmp rdskDoIt
+ andi temp,WRTMSK
+ sts wrtype,temp ;save write type
cpi temp,WRUAL ;write unallocated?
brne dsk_chkuna ;check for unalloc
dsk_rwoper:
;enter here to perform the read/write
+.if DISK_DEBUG
+ rcall printstr
+ .db ", flags: ",0
+ in temp,flags
+ rcall printhex
+.endif
sts erflag,_0 ;no errors (yet)
;Convert track/sector to an LBA address (in 128byte blocks)
add xl,r0 ;
adc xh,r1 ;
mul temp4,temp ;
- add xh,r0 ;xh:xl := sec + trk * SectorsPerTrack
+ add xh,r0 ;yl:xh:xl := sec + trk * SectorsPerTrack
adc yl,r1 ;
clr _0
;Convert from CP/M LBA blocks to host LBA blocks
ldi temp,SECSHF
dsk_sh1:
- lsr xh
+ lsr yl
+ ror xh
ror xl
- ror yl
dec temp
brne dsk_sh1
;yl:xh:xl = host block to seek
; active host sector?
- sbis flags,hostact ;host active?
+ in _tmp,flags ;host active flag
+ sbi flags,hostact ;always becomes 1
+ sbrs _tmp,hostact ;was it already?
rjmp dsk_filhst ;fill host if not
; host buffer active, same as seek buffer?
;
dsk_nomatch:
;proper disk, but not correct sector
- sbic flags,hostwrt ;host written?
+ sbis flags,hostwrt ;host written?
+ rjmp dsk_filhst
+ push xl
+ push xh
+ push yl
rcall dsk_writehost ;clear host buff
+ pop yl
+ pop xh
+ pop xl
dsk_filhst:
;may have to fill the host buffer
cbi flags,hostwrt ;no pending write
dsk_match:
- sbi flags,hostact ;host buffer active now
;copy data to or from buffer
ldi zl,low(hostbuf)
mul temp2,temp
add zl,r0 ;offset in hostbuf
adc zh,r1
-.if DISK_DEBUG
+.if 0 ; DISK_DEBUG
push r0
push r1
clr _0
lds temp,wrtype ;write type
cpi temp,WRDIR ;to directory?
breq dsk_wdir
- lds temp,erflag
-.if 0
- rcall timer_quit
- rcall printstr
- .db " Out",0
-.endif
ret ;no further processing
dsk_wdir:
; clear host buffer for directory write
dsk_wdir1:
rcall dsk_writehost ;clear host buff
cbi flags,hostwrt ;buffer written
- lds temp,erflag
ret
-
-;*****************************************************
-;* WRITEhost performs the physical write to *
-;* the host disk, READhost reads the physical *
-;* disk. *
;*****************************************************
-dsk_writehost:
- ;hostdsk = host disk #, hostlba = host block #.
- ;Write "hostsize" bytes from hostbuf and return
- ;error flag in erflag.
- ;Return erflag non-zero if error
+; hostdsk = host disk #, (partition #)
+; hostlba = host block #, relative to partition start
+; Read/Write "hostsize" bytes to/from hostbuf
- push yh
- push yl
- push xh
- push xl
- ldi zl,low(hostdstart)
- ldi zh,high(hostdstart)
+
+dsk_hostparam:
+ ldi zl,low(hostparttbl)
+ ldi zh,high(hostparttbl)
lds temp,hostdsk
- lsl temp
- lsl temp
- add zl,temp
- adc zh,_0
+.if HOSTRW_DEBUG
+ push temp
+ subi temp,-('A')
+ rcall uartputc
+ rcall printstr
+ .db ": ",0,0
+ pop temp
+.endif
+
+ lsl temp
+ lsl temp
+ lsl temp
+ add zl,temp
+ adc zh,_0
+
+ lds temp,hostlba
+ lds temp2,hostlba+1
+ lds temp3,hostlba+2
+
+.if HOSTRW_DEBUG
+ rcall printstr
+ .db "lba: ",0
+ clr temp4
+ rcall print_ultoa
+.endif
+
+ ldd xl,z+4
+ ldd xh,z+5
+ ldd yl,z+6
+
+ cp temp,xl
+ cpc temp2,xh
+ cpc temp3,yl
+ brcs dsk_hp1
+
+.if HOSTRW_DEBUG
+ rcall printstr
+ .db ", max: ",0
+ push temp4
+ push temp3
+ push temp2
+ push temp
+ movw temp,x
+ mov temp3,yl
+ clr temp4
+ rcall print_ultoa
+ pop temp
+ pop temp2
+ pop temp3
+ pop temp4
+ rcall printstr
+ .db " ",0
+.endif
+ clr temp
+ ret
+
+dsk_hp1:
ldd xl,z+0
ldd xh,z+1
ldd yl,z+2
ldd yh,z+3
- lds temp,hostlba
+
add xl,temp
- lds temp,hostlba+1
- adc xh,temp
- lds temp,hostlba+2
- adc zl,temp
+ adc xh,temp2
+ adc zl,temp3
adc zh,_0
+.if HOSTRW_DEBUG
+ rcall printstr
+ .db ", abs:",0,0
+ push temp4
+ push temp3
+ push temp2
+ push temp
+ movw temp,x
+ movw temp3,y
+ rcall print_ultoa
+ pop temp
+ pop temp2
+ pop temp3
+ pop temp4
+ rcall printstr
+ .db " ",0
+.endif
+ ori temp,255
+dsk_hpex:
+ ret
+
+;*****************************************************
+;* WRITEhost performs the physical write to *
+;* the host disk, READhost reads the physical *
+;* disk. *
+;*****************************************************
+
+dsk_writehost:
+.if HOSTRW_DEBUG
+ rcall printstr
+ .db 13,"host write ",0,0
+.endif
+ rcall dsk_hostparam
+ brne dsk_wr1
+ ldi temp,255
+ sts erflag,temp
+ ret
+
+dsk_wr1:
rcall mmcWriteSect
- pop xl
- pop xh
- pop yl
- pop yh
sts erflag,_0
ret
dsk_readhost:
- ;hostdsk = host disk #, hostlba = host block #.
- ;Read "hostsiz" bytes into hostbuf and return
- ;error flag in erflag.
-
- push yh
- push yl
- push xh
- push xl
- ldi zl,low(hostdstart)
- ldi zh,high(hostdstart)
- lds temp,hostdsk
- lsl temp
- lsl temp
- add zl,temp
- adc zh,_0
-
- ldd xl,z+0
- ldd xh,z+1
- ldd yl,z+2
- ldd yh,z+3
- lds temp,hostlba
- add xl,temp
- lds temp,hostlba+1
- adc xh,temp
- lds temp,hostlba+2
- adc zl,temp
- adc zh,_0
+.if HOSTRW_DEBUG
+ rcall printstr
+ .db 13,"host read ",0,0
+.endif
+ rcall dsk_hostparam
+ brne dsk_rd1
+ ldi temp,255
+ sts erflag,temp
+ ret
+
+dsk_rd1:
rcall mmcReadSect
- pop xl
- pop xh
- pop yl
- pop yh
sts erflag,_0
ret
; ****************************************************************************
; refresh interupt; exec 2 cbr cycles
-refrint:
- ;4 CAS RAS
+refrint: ;4
+
+ sbis P_RAS,ram_ras ;2
+ reti
+ ; CAS RAS
cbi P_CAS,ram_cas ;2 1| 1|
; 1| 1|
cbi P_RAS,ram_ras ;2 |0 1|
push yh
push yl
push z_flags
+ push temp4
+ push temp3
+ push temp2
+ push temp
clr yl ;yl = stack level
dec yl
brne ultoa6
+ pop temp
+ pop temp2
+ pop temp3
+ pop temp4
pop z_flags
pop yl
pop yh
push yh
push yl
push temp
- in r29,sph
- in r28,spl
+ in yh,sph
+ in yl,spl
ldd zl,y+7
ldd zh,y+6
uartgetc:
lds temp,rxcount ; Number of characters in buffer
tst temp
- breq uartgetc
+ breq uartgetc ;Wait for char
push zh
push zl