changeset 3122:35fb39e4b218

mc09: Store SD card drive offset in its own 2 bytes instead of trying to re-use two pre-assigned bytes. Tidy up comments in driver and in descriptors. Switch to use of hex offsets in makefile rather than decimal; more readable and more consistent.
author Neal Crook <foofoobedoo@gmail.com>
date Tue, 05 Jan 2016 21:55:34 +0000
parents 96f1d18ce8cf
children 039ddb7c8ad7
files level1/mc09/modules/makefile level1/modules/mc09sdc.asm level1/modules/mc09sdcdesc.asm
diffstat 3 files changed, 84 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/level1/mc09/modules/makefile	Mon Dec 05 17:34:33 2016 +0000
+++ b/level1/mc09/modules/makefile	Tue Jan 05 21:55:34 2016 +0000
@@ -188,25 +188,23 @@
 d2_80d.dd: rb1773desc.asm
 	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=2
 
-# OFFSET is the high 16 bits of the 24-bit block address
-# where the disk image starts on the SDcard. It must match
-# the value used in the create_sd_image script. Needs to be
-# expressed in DECIMAL here (at least, I don't know how to pass
-# it in and have it treated as hex)
+# SDOFFSET is the high 16 bits of the 24-bit block address at
+# which the disk image starts on the SDcard. It must match
+# the value used in the create_sd_image script.
 dds0_80d.dd: mc09sdcdesc.asm
-	$(AS) $< $(ASOUT)$@ $(AFLAGS) -DDNum=0 -DDD=1 -DOFFSET=640
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=0 -DSDOFFSET=0x0280 -DDD=1
 
 s0_80d.dd: mc09sdcdesc.asm
-	$(AS) $< $(ASOUT)$@ $(AFLAGS) -DDNum=0        -DOFFSET=640
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=0 -DSDOFFSET=0x0280
 
 s1_80d.dd: mc09sdcdesc.asm
-	$(AS) $< $(ASOUT)$@ $(AFLAGS) -DDNum=1        -DOFFSET=656
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=1 -DSDOFFSET=0x0290
 
 s2_80d.dd: mc09sdcdesc.asm
-	$(AS) $< $(ASOUT)$@ $(AFLAGS) -DDNum=2        -DOFFSET=672
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=2 -DSDOFFSET=0x02A0
 
 s3_80d.dd: mc09sdcdesc.asm
-	$(AS) $< $(ASOUT)$@ $(AFLAGS) -DDNum=3        -DOFFSET=688
+	$(AS) $< $(ASOUT)$@ $(AFLAGS) $(DSDD80) -DDNum=3 -DSDOFFSET=0x02B0
 
 # Serial ports for mc09
 term_mc6850_t0.dt: term_mc6850.asm
--- a/level1/modules/mc09sdc.asm	Mon Dec 05 17:34:33 2016 +0000
+++ b/level1/modules/mc09sdc.asm	Tue Jan 05 21:55:34 2016 +0000
@@ -35,10 +35,10 @@
 name     fcs   /mc09sd/
          fcb   edition
 
+
 * [NAC HACK 2015Sep04] probably ought to have timeouts on each of the
 * wait loops.
 
-
 * [NAC HACK 2015Sep04] based on tech ref and rb1773 we're supposed to
 * get the base address from the device data structure and then access all
 * the hw registers relative to that base address. rb1773 does it once and
@@ -60,7 +60,7 @@
 * Multicomp09 SDCC does not require any initialisation
 * [NAC HACK 2015Sep02] futures: new card detection and re-init when
 * the hardware supports it.
-* BUT the tech ref xplains there's other stuff we need to do.
+* BUT the tech ref xplains the other stuff we need to do.
 Init     equ   *
 
          ldd   #$FF*256+N.Drives  'invalid' value & # of drives
@@ -71,7 +71,7 @@
          decb                 done all drives yet?
          bne   Init1          no, init them all
 
-* unlike rb1773 we do not need a sector buffer (AFAIK) so we're done.
+* unlike rb1773 we do not need a sector buffer so we're done.
 
          clrb                 clear carry
          rts
@@ -116,24 +116,10 @@
 
 
 *******************************************************************
-* Term
-*
-* Entry:
-*    U  = address of device memory area
-*
-* Exit:
-*    CC = carry set on error
-*    B  = error code
+* Jump table for the public routines of this module. 3 bytes per
+* entry, so any bra must be padded with a NOP. Save a few bytes by
+* falling through to the last entry (Term).
 *
-* There is no memory allocated so nothing to do here, either. I almost
-* feel bad..
-Term     clrb
-         rts
-
-
-*******************************************************************
-* Jump table for the public routines of this module. 3 bytes per entry,
-* so any bra must be padded with a NOP.
 start    bra   Init
          nop
          bra   Read
@@ -144,8 +130,25 @@
          nop
          bra   SetStat
          nop
-         bra   Term
-         nop
+
+* FALL-THROUGH to the Term subroutine
+
+*******************************************************************
+* Term
+*
+* Entry:
+*    U  = address of device memory area
+*
+* Exit:
+*    CC = carry set on error
+*    B  = error code
+*
+* There is no memory allocated so nothing to do here, either. I
+* almost feel bad..
+*
+Term     clrb
+         rts
+
 
 *******************************************************************
 * Read
@@ -160,7 +163,7 @@
 *    CC = carry set on error
 *    B  = error code
 *
-* The SDcard base block for this disk is at Y+$2D
+* The SDcard base block for this disk is retrieved by LdSDAdrs.
 *
 Read     bsr   LdSDAdrs       set up address in controller
          ldx   PD.BUF,y       Get physical sector buffer ptr
@@ -227,8 +230,8 @@
 *    CC = carry set on error
 *    B  = error code
 *
-* [NAC HACK 2015Sep04] LdSDArs should take care of selecting the right offset
-* based on the drive that's selected.
+* The SDcard base block for this disk is retrieved by LdSDAdrs.
+*
 Write
          bsr   LdSDAdrs       set up address in controller
          ldx   PD.BUF,y       Get physical sector buffer ptr
@@ -269,14 +272,19 @@
 
 *******************************************************************
 * SET SDLBA2 SDLBA1 SDLBA0 FOR NEXT SD OPERATION
-* 1. The 16-bit value stored at $2D,Y is the upper 16 bits of the
-*    base block address of the disk image on the SDcard
+* 1. The device descriptor holds a value that is the upper 16 bits
+*    of the base block address of the disk image on the SDcard
 * 2. If this value is QQQQ, add QQQQ00 to {B,XH,XL} to form the
-*    value inot the hardware registers.
-* 2. Load lsn0cp with the number of bytes to be copied into the
+*    value into the hardware registers.
+* 3. Load lsn0cp with the number of bytes to be copied into the
 *    LSN0 buffer - if {B,XH,XL} == 0, this DD.SIZ. Otherwise,
-*    it is 0. Loaded for every operation, only used for Read.
+*    it is 0. Loaded for every operation, only *used* for Read.
 *
+* Entry:
+*    B  = MSB of LSN
+*    X  = LSB of LSN
+*    Y  = address of path descriptor
+*    U  = address of device memory area
 * Can destroy A, B, X, CC
 *
 * It is a constraint that the disk image is aligned so that the
@@ -285,7 +293,18 @@
 *
 * [NAC HACK 2015Sep04] hack! the hardware addresses should be
 * offsets from the base address stored in the device's data structure.
-LdSDAdrs clr   lsn0cp,u       default: copy nothing
+*
+* PD.DEV,Y is the device table pointer. From this, get the
+* descriptor pointer at V$DESC. From there, use the IT.xxx
+* offsets to get to data in the device descriptor. This is
+* long-winded because the value we need is outside of the area
+* that gets copied into the path descriptor.
+*
+LdSDAdrs pshs  y
+         ldy   PD.DEV,y       device table pointer
+         ldy   V$DESC,y       descriptor pointer
+
+         clr   lsn0cp,u       default: copy nothing
          pshs  b
 
          pshs  x              copy of X to pull off byte by byte
@@ -298,17 +317,16 @@
 notlsn0  tfr   x,d
          stb   SDLBA0         ls byte is done.
 
-         ldb   $2D,y          bits 23:16 of drive base
+         ldb   IT.SOFF1,y     bits 23:16 of drive base
 
-         adda  $2E,y          add bits 15:8 of drive base
+         adda  IT.SOFF2,y     add bits 15:8 of drive base
          sta   SDLBA1         middle byte is done
 
          adcb  #$00           add carry from middle byte
          addb  ,s+            add and drop stacked b
          stb   SDLBA2
-         rts
+         puls  y,pc
 
          emod
 eom      equ   *
          end
-
--- a/level1/modules/mc09sdcdesc.asm	Mon Dec 05 17:34:33 2016 +0000
+++ b/level1/modules/mc09sdcdesc.asm	Tue Jan 05 21:55:34 2016 +0000
@@ -8,6 +8,11 @@
 * ------------------------------------------------------------------
 *          2015/08/31  ncrook
 * Created from 1773 descriptor template
+*          2016/01/07  ncrook
+* Bill Nobel pointed out the impact of reusing the Interlv and SAS
+* bytes, so I have allocated 2 new bytes for SDOFFSET. Also, set the
+* track and sector count correctly because these are needed for
+* calculations by RBF during writes.
 
          nam   mc09sddesc
          ttl   Multicomp09 SDCC Device Descriptor Template
@@ -18,15 +23,11 @@
 atrv     set   ReEnt+rev
 rev      set   $00
 
-* [NAC HACK 2015Sep04] this data structure is described in the TechRef so
-* I assume it is Required. The DNum/Type are swapped in the TechRef (Type
-* is first) Error here or there?
+* All of these values can be provided on the build line in the Makefile
+* overriding the defaults below
          IFNDEF DNum
 DNum     set   0
          ENDC
-* [NAC HACK 2015Sep02] not sure whether the fact I'm emulating a floppy means
-* that I need all this stuff, eg for interacting with LSN0? Reconsider later
-* and maybe strip it all out
          IFNE  D35
 Type     set   TYP.CCF+TYP.3
          ELSE
@@ -62,6 +63,9 @@
          fcb   HW.Page    extended controller address
          fdb   $FFD8      physical controller (base) address
          fcb   initsize-*-1 initialization table size
+* In "The NitrOS-9 Technical Reference" describes this initialisation table.
+* The first byte is at offset IT.DTP from the start of the module but is copied
+* to PD.DTP in the path descriptor.
          fcb   DT.RBF     device type:0=scf,1=rbf,2=pipe,3=scf
          fcb   DNum       drive number
          fcb   Step       step rate
@@ -72,11 +76,19 @@
          fcb   Verify     verify disk writes:0=on
          fdb   SectTrk    # of sectors per track
          fdb   SectTrk0   # of sectors per track (track 0)
-         fdb   OFFSET     high 16 bits of 24-bit block address on
-*                         SDcard where this disk image starts.
-**nac removed but (for now) keep the entry the same size
-**nac         fcb   Interlv    sector interleave factor
-**nac         fcb   SAS        minimum size of sector allocation
+         fcb   Interlv    sector interleave factor
+         fcb   SAS        minimum size of sector allocation
+         fcb   0          IT.TFM
+         fdb   0          IT.Exten
+         fcb   0          IT.STOff
+* SDcard driver-specific additions to the device descriptor go
+* here. They do NOT get copied into the path descriptor; they
+* cannot because there is NO ROOM. The driver has to access these
+* values directly in the descriptor (see rbsuper/superdesc for how)
+
+* High 16 bits of the 24-bit SDcard block address corresponding
+* to the start of this disk image.
+         fdb   SDOFFSET
 initsize equ   *
 
          IFNE  DD