changeset 1902:d141618d38df

Can now be compiled to cobble CoCo or Dragon disks.
author afra
date Thu, 03 Nov 2005 01:36:10 +0000
parents 311bb8001b95
children cb9a9df15964
files level1/cmds/cobbler.asm
diffstat 1 files changed, 277 insertions(+), 178 deletions(-) [+]
line wrap: on
line diff
--- a/level1/cmds/cobbler.asm	Sat Oct 29 17:41:54 2005 +0000
+++ b/level1/cmds/cobbler.asm	Thu Nov 03 01:36:10 2005 +0000
@@ -11,6 +11,10 @@
 *
 *          2002/07/20  Boisy G. Pitre
 * Modified source to allow for OS-9 Level One and Level Two assembly.
+*
+*	   2005/11/03  P.Harvey-Smith.
+* Added the ability to assemble for either CoCo or Dragon.
+*
 
          nam   Cobbler
          ttl   Write OS9Boot to a disk
@@ -30,30 +34,31 @@
 
          mod   eom,name,tylg,atrv,start,size
 
-         org   0
-lsn0buff rmb   26
-newbpath rmb   1
-devpath  rmb   3
-u001E    rmb   2
-fullbnam rmb   20	this buffer hodls the entire name (i.e. /D0/OS9Boot)
-u0034    rmb   16
-u0044    rmb   7
-u004B    rmb   2
-u004D    rmb   1
-u004E    rmb   16
-pathopts rmb   20
-u0072    rmb   2
-u0074    rmb   10
-bffdbuf  rmb   16
-u008E    rmb   1
-u008F    rmb   7
-u0096    rmb   232
-bitmbuf  rmb   1024
-         IFGT  Level-1
-u057E    rmb   76
-u05CA    rmb   8316
-         ENDC
-size     equ   .
+		org   0
+lsn0buff 	rmb   26	Buffer to hold data from LSN0 of traget device
+newbpath 	rmb   1
+devpath  	rmb   3
+EndDevName    	rmb   2		pointer to last character of device name when moving to fullbnam
+fullbnam 	rmb   20	this buffer hodls the entire name (i.e. /D0/OS9Boot)
+u0034    	rmb   16
+BootBuf    	rmb   7		Area to read part of current boot area into, to check for boot stuff
+u004B    	rmb   2
+LSNBitmapByte	rmb   1		Saved byte from bitmap, of current LSN
+u004E    	rmb   16
+pathopts 	rmb   20
+u0072    	rmb   2
+u0074    	rmb   10
+bffdbuf  	rmb   16
+u008E    	rmb   1
+u008F    	rmb   7
+u0096    	rmb   232
+bitmbuf  	rmb   1024
+         
+		IFGT  Level-1
+u057E    	rmb   76
+u05CA    	rmb   8316
+		ENDC
+size     	equ   .
 
 name     fcs   /Cobbler/
          fcb   edition
@@ -74,10 +79,21 @@
          fcb   C$LF
          fcc   "Error - cannot gen to hard disk"
          fcb   C$CR
+	 
+	IFNE	DRAGON
+FileWarn fcb   C$LF
+         fcc   "Warning - not a Dragon "
+         fcb   C$LF
+         fcc   "disk."
+
+	ELSE
 FileWarn fcb   C$LF
          fcc   "Warning - file(s) present"
          fcb   C$LF
          fcc   "on track 34 - this track"
+
+	ENDC
+
          fcb   C$LF
          fcc   "not rewritten."
          fcb   C$CR
@@ -94,64 +110,76 @@
 RelNam   fcc   "Rel"
          fcb   $FF 
 
-start    clrb  
+DragonRootSec	equ	$12	Dragon root sector is always LSN 18
+
+start    clrb  				Check first char is a /
          lda   #PDELIM
          cmpa  ,x
          lbne  ShowHelp
-         os9   F$PrsNam 
-         lbcs  ShowHelp
-         lda   #PDELIM
+	 
+         os9   F$PrsNam 		Parse the name
+         lbcs  ShowHelp			Error : show help
+	 
+         lda   #PDELIM			Check that path has only one / e.g. '/d1'
          cmpa  ,y
-         lbeq  ShowHelp
-         leay  <fullbnam,u
+         lbeq  ShowHelp			yes : show help
+	 
+         leay  <fullbnam,u		Transfer name to our buffer
 L013C    sta   ,y+
          lda   ,x+
          decb  
          bpl   L013C
-         sty   <u001E
-         ldd   #PENTIR*256+C$SPAC
+	 
+         sty   <EndDevName		Save pointer to end of dev name
+         ldd   #PENTIR*256+C$SPAC	Store '@ ' at end of devname, for entire dev e.g. '/d1@ '
          std   ,y++
-         leax  <fullbnam,u
-         lda   #UPDAT.
-         os9   I$Open   
-         sta   <devpath
-         lbcs  ShowHelp
-         ldx   <u001E
-         leay  >BootName,pcr
-         lda   #PDELIM
-L0162    sta   ,x+
+         leax  <fullbnam,u		Point to devname
+         lda   #UPDAT.			Open for update
+         os9   I$Open   		
+         sta   <devpath			Save pathnumber
+         lbcs  ShowHelp			Error opening dev, show help + exit
+	 
+         ldx   <EndDevName		Get pointer to end of dev name
+         leay  >BootName,pcr		Get pointer to boot file name
+         lda   #PDELIM			Append path delimiter e.g. '/d1/'
+L0162    sta   ,x+			Append boot name to dev name e.g. '/d1/OS9Boot'
          lda   ,y+
          bpl   L0162
+	 
          pshs  u
          clra  
          clrb  
          tfr   d,x
          tfr   d,u
          lda   <devpath
-         os9   I$Seek   	seek to 0
+         os9   I$Seek   		seek to 0
          lbcs  Bye
          puls  u
-         leax  lsn0buff,u
-         ldy   #DD.DAT		$1A
+         leax  lsn0buff,u		Point to buffer
+         ldy   #DD.DAT			$1A
          lda   <devpath
-         os9   I$Read   	read LSN0
-         lbcs  Bye
-         ldd   <DD.BSZ		get size of bootfile currently
-         beq   L019F		branch if none
+         os9   I$Read   		read LSN0
+         lbcs  Bye			Error : exit
+	 
+         ldd   <DD.BSZ			get size of bootfile currently
+         beq   L019F			branch if none
+	 
          leax  <fullbnam,u
-         os9   I$Delete 	delete existing bootfile
-         clra  
+         os9   I$Delete 		delete existing bootfile
+         
+	 clra  
          clrb  
-         sta   <DD.BT
+         sta   <DD.BT			Init some of the LSN0 vars
          std   <DD.BT+1
          std   <DD.BSZ
-         lbsr  WriteLSN0
+         lbsr  WriteLSN0		Write back to disk
+	 
 L019F    lda   #WRITE.
          ldb   #READ.+WRITE.
          leax  <fullbnam,u
-         os9   I$Create 	create new bootfile
-         sta   <newbpath
-         lbcs  Bye		branch if error
+         os9   I$Create 		create new bootfile
+         sta   <newbpath		Save pathnumber
+         lbcs  Bye			branch if error
 
          IFGT  Level-1
 * OS-9 Level Two: Copy first 90 bytes of system direct page into our space
@@ -214,26 +242,28 @@
          ELSE
 
 * OS-9 Level One: Write out bootfile
-         ldd   >D.BTHI          get bootfile size
+         ldd   >D.BTHI          	get bootfile size
          subd  >D.BTLO
-         tfr   d,y              in D, tfr to Y
-         std   <DD.BSZ          save it
-         ldx   >D.BTLO          get pointer to boot in mem
+         tfr   d,y              	in D, tfr to Y
+         std   <DD.BSZ          	save it
+         ldx   >D.BTLO          	get pointer to boot in mem
          lda   <newbpath
-         os9   I$Write          write out boot to file
+         os9   I$Write          	write out boot to file
          lbcs  Bye
 
          ENDC
 
-         leax  <pathopts,u
-         clrb
+         leax  <pathopts,u		Point to option buffer
+         clrb				Read option section of Path descriptor
 *         ldb   #SS.Opt
-         lda   <newbpath
-         os9   I$GetStt 
-         lbcs  Bye
-         lda   <newbpath
+         lda   <newbpath		Get pathnumber of new bootfile
+         os9   I$GetStt 		Get options
+         lbcs  Bye			Error: exit
+	 
+         lda   <newbpath		Close bootfile
          os9   I$Close  
-         lbcs  ShowHelp
+         
+	 lbcs  ShowHelp
          pshs  u
          ldx   <pathopts+(PD.FD-PD.OPT),u
          lda   <pathopts+(PD.FD+2-PD.OPT),u
@@ -241,70 +271,97 @@
          clrb  
          tfr   d,u
          lda   <devpath
-         os9   I$Seek   	seek to os9boot file descriptor
+         os9   I$Seek   		seek to os9boot file descriptor
          puls  u
-         lbcs  Bye
-         leax  <bffdbuf,u
+         lbcs  Bye			Error: exit
+	 
+         leax  <bffdbuf,u		Point to buffer for filedes sector
          ldy   #256
-         os9   I$Read   	read in filedes sector
-         lbcs  Bye
-         ldd   >bffdbuf+(FD.SEG+FDSL.S+FDSL.B),u
-         lbne  IsFragd		branch if fragmented
-* Get and save bootfile's LSN
+         os9   I$Read   		read in filedes sector
+         lbcs  Bye			Error: exit
+         ldd   >bffdbuf+(FD.SEG+FDSL.S+FDSL.B),u	Test if fragmented
+         lbne  IsFragd			branch if fragmented
+	 
+* Get and save bootfile's LSN 
          ldb   >bffdbuf+(FD.SEG),u
          stb   <DD.BT
          ldd   >bffdbuf+(FD.SEG+1),u
          std   <DD.BT+1
-         lbsr  WriteLSN0
+         lbsr  WriteLSN0		Write bootfile loc to LSN0 on disk
+	 
          ldd   #$0001
          lbsr  Seek2LSN
+         leax  >bitmbuf,u		Point to bitmap buffer
+         ldy   <DD.MAP			Get block number of map
+         lda   <devpath			Get dev pathnumber
+         os9   I$Read   		read bitmap sector(s)
+         lbcs  Bye			Error: exit
+	 
+*
+* On the dragon, we do not need to test to see if the boot track has files on
+* as the boot area is on track 0 imediatly after the blockmap, and before 
+* the root directory, and therefore can never have files on it.
+* However, we do need to verify that this is a Dragon formatted disk,
+* we do this by checking that the root directory starts at LSN 18 (or greater).
+*
+	 ifne	DRAGON
+	 ldd	<DD.DIR+1		Get LSN of root dir
+	 cmpd	#DragonRootSec		Is this a dragon disk ?
+	 beq	RewriteBitmap		Yes : write boot
+	 lbra	TrkAlloc		No : error and exit.
+	 else
+	 
+         ldd   #(Bt.Track*256)+Bt.Sec	Get offset of boot track
+         ldy   #$0004			Check 4 csectors
+         lbsr  CheckAlloc
+         bcc   L0304			Not allocated, check rest
+	 
+         ldd   #(Bt.Track*256)+Bt.Sec	Get offset of boot track
+         lbsr  Seek2LSN
+         leax  <BootBuf,u		Point to buffer
+         ldy   #$0007			No of bytes to read
+         lda   <devpath			Get device path
+         os9   I$Read   		Do read
+         lbcs  Bye			Error : exit
+	 
+         leax  <BootBuf,u		Point to buffer
+         ldd   ,x			Load first 2 bytes into D
+         cmpa  #'O			Check for presense of 'OS'
+         lbne  TrkAlloc			No: Try and allocate track (CoCo)
+         cmpb  #'S
+         lbne  TrkAlloc			No: Try and allocate track (CoCo)
+	 
+         lda   $04,x			Check 5th byte is a NOP
+         cmpa  #$12
+         beq   L02F7			Yes: boot track already contains boot code
+	 
+         ldd   #(Bt.Track*256)+Bt.Sec+$0F
+         ldy   #$0003
+         lbsr  CheckAlloc
+         lbcs  TrkAlloc
+	 
+L02F7    clra  				Allocate boot track (CoCo)
+         ldb   <DD.TKS
+         tfr   d,y
+         ldd   #(Bt.Track*256)+Bt.Sec
+         lbsr  Allocate
+         bra   RewriteBitmap
+	 
+L0304    ldd   #(Bt.Track*256)+Bt.Sec+$04	Check to see if sectors 5..18 of boot track free
+         ldy   #$000E			Number of sectors
+         lbsr  CheckAlloc		Check them
+         lbcs  TrkAlloc			Carry set, sectors allocated, error & exit
+         bra   L02F7
+
+	ENDC
+
+RewriteBitmap    
+	ldd   #$0001
+         lbsr  Seek2LSN			Seek to bitmap sector on disk
          leax  >bitmbuf,u
          ldy   <DD.MAP
          lda   <devpath
-         os9   I$Read   	read bitmap sector(s)
-         lbcs  Bye
-         ldd   #Bt.Track*256+$00
-         ldy   #$0004
-         lbsr  L03A7
-         bcc   L0304
-         ldd   #Bt.Track*256+$00
-         lbsr  Seek2LSN
-         leax  <u0044,u
-         ldy   #$0007
-         lda   <devpath
-         os9   I$Read   
-         lbcs  Bye
-         leax  <u0044,u
-         ldd   ,x
-         cmpa  #'O
-         lbne  TrkAlloc
-         cmpb  #'S
-         lbne  TrkAlloc
-         lda   $04,x
-         cmpa  #$12
-         beq   L02F7
-         ldd   #Bt.Track*256+$0F
-         ldy   #$0003
-         lbsr  L03A7
-         lbcs  TrkAlloc
-L02F7    clra  
-         ldb   <DD.TKS
-         tfr   d,y
-         ldd   #Bt.Track*256+$00
-         lbsr  L03FD
-         bra   L0315
-L0304    ldd   #Bt.Track*256+$04
-         ldy   #$000E
-         lbsr  L03A7
-         lbcs  TrkAlloc
-         bra   L02F7
-
-L0315    ldd   #$0001
-         lbsr  Seek2LSN		Seek to bitmap sector on disk
-         leax  >bitmbuf,u
-         ldy   <DD.MAP
-         lda   <devpath
-         os9   I$Write  	write updated bitmap
+         os9   I$Write  		write updated bitmap
          lbcs  Bye
 
          IFGT  Level-1
@@ -314,10 +371,10 @@
          leax  >RelNam,pcr
          os9   F$Link   
          lbcs  NoRel
-         tfr   u,d		tfr module header to D
-         puls  u		get statics ptr
+         tfr   u,d			tfr module header to D
+         puls  u			get statics ptr
          subd  #$0006
-         std   <u004B,u		save pointer
+         std   <u004B,u			save pointer
          lda   #$E0
          anda  <u004B,u
          ora   #$1E
@@ -325,7 +382,7 @@
          subd  <u004B,u
          addd  #$0001
          tfr   d,y
-         ldd   #Bt.Track*256+$00
+         ldd   #(Bt.Track*256)+Bt.Sec
          lbsr  Seek2LSN
          lda   <devpath
          ldx   <u004B,u
@@ -333,20 +390,20 @@
          ELSE
 
 * OS-9 Level One: Write out data at $EF00
-         ldd   #Bt.Track*256+$00
+         ldd   #(Bt.Track*256)+Bt.Sec	Seek to boot track
          lbsr  Seek2LSN 
-         lda   <devpath
-         ldx   #Bt.Start
+         lda   <devpath			
+         ldx   #Bt.Start		Get boot start and size
          ldy   #Bt.Size
 
          ENDC
 
-         os9   I$Write  
-         lbcs  WriteBad
-         os9   I$Close  
-         lbcs  Bye
-         clrb  
-         lbra  Bye
+         os9   I$Write  		Write boot track
+         lbcs  WriteBad			Error 
+         os9   I$Close  		Close devpath
+         lbcs  Bye			Error : exit
+         clrb  				Flag no error
+         lbra  Bye			
 
 * Get absolute LSN
 * Returns in D
@@ -366,7 +423,9 @@
          rts   
 
 * Returns bit in bitmap corresponding to LSN in A
-L038C    pshs  y,b
+* X=bitmap buffer, on exit X points to bitmap byte of our LSN
+GetBitmapBit    
+	pshs  y,b
 * Divide D by 8
          lsra  
          rorb  
@@ -374,81 +433,114 @@
          rorb  
          lsra  
          rorb  
-         leax  d,x
+         leax  d,x		Point X at byte witin bitmap of our LSN ?
          puls  b
-         leay  <L03A1,pcr
-         andb  #$07
-         lda   b,y
-         puls  pc,y
+         leay  <BitTable,pcr	Point to bit table
+         andb  #$07		Make sure offset within table
+         lda   b,y		Get bit from table
+         puls  pc,y		Restore and return
+
+BitTable    fcb   $80,$40,$20,$10,$08,$04,$02,$01	Bitmap bit table
 
-L03A1    fcb   $80,$40,$20,$10,$08,$04,$02,$01
-
-L03A7    pshs  y,x,b,a
-         bsr   AbsLSN		go get absolute LSN
+*
+* CheckAlloc, check to see if a block of sectors is allocated.
+* 
+* Entry : A=track, B= sector, Y=number of sectors
+* Exit : Carry Set, sectors are already allocated. Carry clear, sectors are free.
+*
+CheckAlloc
+	pshs  y,x,b,a
+         bsr   AbsLSN		go get absolute LSN in D
          leax  >bitmbuf,u	point X to our bitmap buffer
-         bsr   L038C
-         sta   ,-s		save off
+         bsr   GetBitmapBit		
+         
+	 sta   ,-s		save off
          bmi   L03CB
-         lda   ,x
-         sta   <u004D
-L03BB    anda  ,s
-         bne   L03F7
-         leay  -$01,y
-         beq   L03F3
-         lda   <u004D
-         lsr   ,s
-         bcc   L03BB
-         leax  $01,x
-L03CB    lda   #$FF
+	 
+         lda   ,x		Get bitmap byte of our LSN
+         sta   <LSNBitmapByte	Save for later use
+L03BB    anda  ,s		Is our LSN allocated ?
+         bne   L03F7		Yes : flag error
+         
+	 leay  -$01,y		Decrement sector count		
+         beq   L03F3		All done : yes, exit
+         
+	 lda   <LSNBitmapByte	Get saved bitmap byte
+         lsr   ,s		Check next sector
+         bcc   L03BB		If carry, we need to fetch next byte from bitmap
+         
+	 leax  $01,x		Increment bitmap pointer
+L03CB    lda   #$FF		
          sta   ,s
          bra   L03DB
+	 
 L03D1    lda   ,x
          anda  ,s
          bne   L03F7
-         leax  $01,x
+         
+	 leax  $01,x
          leay  -$08,y
-L03DB    cmpy  #$0008
-         bhi   L03D1
+L03DB    cmpy  #$0008		Done a whole byte's worth of blocks ?
+         bhi   L03D1		Yes
          beq   L03ED
-         lda   ,s
-L03E5    lsra  
-         leay  -$01,y
-         bne   L03E5
-         coma  
+	 
+         lda   ,s		Fetch current bit 
+L03E5    lsra  			Process next sector
+         leay  -$01,y		decrement sector count
+         bne   L03E5		Any more : yes continue
+         
+	 coma  
          sta   ,s
 L03ED    lda   ,x
          anda  ,s
          bne   L03F7
-L03F3    andcc #^Carry
+	 
+L03F3    andcc #^Carry		
          bra   L03F9
-L03F7    orcc  #Carry
-L03F9    leas  $01,s
-         puls  pc,y,x,b,a
-L03FD    pshs  y,x,b,a
+	 
+L03F7    orcc  #Carry		Flag error ?
+L03F9    leas  $01,s		Drop saved byte	
+         puls  pc,y,x,b,a	Restore and return
+	 
+	 
+*
+* Allocate, allocate blocks in bitmap
+* Entry : A=track, B=sector, Y=block count.
+*
+	 
+Allocate    
+	 pshs  y,x,b,a
          lbsr  AbsLSN		get absolute LSN
-         leax  >bitmbuf,u
-         bsr   L038C
-         sta   ,-s
+         leax  >bitmbuf,u	Point to bitmap buffer
+         bsr   GetBitmapBit	Get bit corisponding to LSN
+	 
+         sta   ,-s		Save it
          bmi   L041C
+	 
          lda   ,x
 L040E    ora   ,s
          leay  -$01,y
          beq   L043A
+	 
          lsr   ,s
          bcc   L040E
+	 
          sta   ,x
          leax  $01,x
 L041C    lda   #$FF
          bra   L0426
+	 
 L0420    sta   ,x
          leax  $01,x
          leay  -$08,y
 L0426    cmpy  #$0008
          bhi   L0420
          beq   L043A
+	 
 L042E    lsra  
          leay  -$01,y
          bne   L042E
+	 
          coma  
          sta   ,s
          lda   ,x
@@ -457,6 +549,10 @@
          leas  $01,s
          puls  pc,y,x,b,a
 
+*
+* Seek To LSN, A=track, B=sector
+* 
+
 Seek2LSN pshs  u,y,x,b,a
          lbsr  AbsLSN
          pshs  a
@@ -479,7 +575,8 @@
          tfr   d,u
          lda   <devpath
          os9   I$Seek   	Seek to LSN0
-         puls  u		added for OS-9 Level One +BGP+
+         
+	 puls  u		added for OS-9 Level One +BGP+
          leax  lsn0buff,u	Point to our LSN buffer
          ldy   #DD.DAT
          lda   <devpath
@@ -494,7 +591,9 @@
          clrb
          bra   Bye
          ENDC
-L0477    pshs  b
+	 
+DisplayErrorAndExit    
+	pshs  b
          lda   #$02
          ldy   #256
          os9   I$WritLn 
@@ -504,19 +603,19 @@
 
 IsFragd  leax  >BootFrag,pcr
          clrb  
-         bra   L0477
+         bra   DisplayErrorAndExit
 
 WriteBad leax  >WritErr,pcr
          clrb  
-         bra   L0477
+         bra   DisplayErrorAndExit
 
 TrkAlloc leax  >FileWarn,pcr
          clrb  
-         bra   L0477
+         bra   DisplayErrorAndExit
 
          IFGT  Level-1
 NoRel    leax  >RelMsg,pcr
-         bra   L0477
+         bra   DisplayErrorAndExit
          ENDC
 
          emod