     1                                  ; ****************************************************************************
     2                                  ; df0.s (df8086.s) - print free blocks - by Erdogan Tan - 30/06/2022
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Retro UNIX 8086 v1 - file system (disk free blocks info) utility 
     5                                  ;
     6                                  ; [ Last Modification: 30/06/2022 ]
     7                                  
     8                                  ; Derived from unix v2 '/bin/df' (PDP-11 assembly) source code 
     9                                  ;
    10                                  ; ****************************************************************************
    11                                  ; [ svntree-20081216.tar.gz - bin/df (archive date: 21-11-1972) ]
    12                                  
    13                                  ; Assembler: NASM v2.15
    14                                  ; ((nasm df1.s -l df1.txt -o df1 -Z error.txt))
    15                                  
    16                                  ; UNIX v1 system calls
    17                                  _rele 	equ 0
    18                                  _exit 	equ 1
    19                                  _fork 	equ 2
    20                                  _read 	equ 3
    21                                  _write	equ 4
    22                                  _open	equ 5
    23                                  _close 	equ 6
    24                                  _wait 	equ 7
    25                                  _creat 	equ 8
    26                                  _link 	equ 9
    27                                  _unlink	equ 10
    28                                  _exec	equ 11
    29                                  _chdir	equ 12
    30                                  _time 	equ 13
    31                                  _mkdir 	equ 14
    32                                  _chmod	equ 15
    33                                  _chown	equ 16
    34                                  _break	equ 17
    35                                  _stat	equ 18
    36                                  _seek	equ 19
    37                                  _tell 	equ 20
    38                                  _mount	equ 21
    39                                  _umount	equ 22
    40                                  _setuid	equ 23
    41                                  _getuid	equ 24
    42                                  _stime	equ 25
    43                                  _quit	equ 26	
    44                                  _intr	equ 27
    45                                  _fstat	equ 28
    46                                  _emt 	equ 29
    47                                  _mdate 	equ 30
    48                                  _stty 	equ 31
    49                                  _gtty	equ 32
    50                                  _ilgins	equ 33
    51                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    52                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    53                                  _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
    54                                  ; 12/01/2022 - Retro UNIX 386 v1.2
    55                                  ; Retro UNIX 386 v2 system calls
    56                                  _setgid	equ 37
    57                                  _getgid	equ 38
    58                                  _sysver	equ 39 ; (get) Retro Unix 386 version
    59                                  
    60                                  ;;;
    61                                  ESCKey equ 1Bh
    62                                  EnterKey equ 0Dh
    63                                  
    64                                  %macro sys 1-4
    65                                      ; Retro UNIX 8086 v1 system call.
    66                                      %if %0 >= 2   
    67                                          mov bx, %2
    68                                          %if %0 >= 3
    69                                              mov cx, %3
    70                                              %if %0 >= 4
    71                                                 mov dx, %4
    72                                              %endif
    73                                          %endif
    74                                      %endif
    75                                      mov ax, %1
    76                                      int 20h
    77                                  %endmacro
    78                                  
    79                                  ; Retro UNIX 8086 v1 system call format:
    80                                  ; sys systemcall (ax) <arg1 (bx)>, <arg2 (cx)>, <arg3 (dx)>kj
    81                                  
    82                                  ;-----------------------------------------------------------------
    83                                  ;  code
    84                                  ;-----------------------------------------------------------------
    85                                  
    86                                  [BITS 16] ; 16-bit intructions (for x86 real mode)
    87                                  
    88                                  [ORG 0] 
    89                                  
    90                                  START_CODE:
    91                                  	; 30/06/2022
    92 00000000 59                      	pop	cx ; cx = number of arguments
    93                                  	;
    94 00000001 58                      	pop	ax ; ax = argument 0 = executable file name
    95                                  	;
    96                                  	;dec	cx
    97 00000002 FEC9                    	dec	cl
    98 00000004 7E39                    	jng	short df_0
    99                                  
   100 00000006 5E                      	pop	si
   101                                  
   102 00000007 AD                      	lodsw	
   103                                  
   104 00000008 3D6664                  	cmp	ax, 'fd'
   105 0000000B 7506                    	jne	short df_2
   106 0000000D 803C00                  	cmp	byte [si], 0
   107 00000010 763B                    	jna	short df_1
   108 00000012 AD                      	lodsw
   109                                  df_2:
   110 00000013 3C30                    	cmp	al, '0'
   111 00000015 7236                    	jb	short df_1
   112 00000017 3C31                    	cmp	al, '1'
   113 00000019 7732                    	ja	short df_1
   114 0000001B 08E4                    	or	ah, ah
   115 0000001D 752E                    	jnz	short df_1
   116 0000001F A2[3A02]                	mov	[fdname+7], al
   117                                  
   118                                  	sys	_open, fdname, 0 ; open /dev/fd? for read
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000022 BB[3302]            <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000025 B90000              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000028 B80500              <1>  mov ax, %1
    76 0000002B CD20                <1>  int 20h
   119 0000002D 7333                    	jnc	short df_3
   120                                  
   121                                  df_err:
   122                                  	sys	_write, 1, error_msg, size_emsg
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 0000002F BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000032 B9[A002]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 00000035 BA0B00              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000038 B80400              <1>  mov ax, %1
    76 0000003B CD20                <1>  int 20h
   123 0000003D EB1C                    	jmp	short hang ; terminate
   124                                  	
   125                                  df_0:
   126                                  	; print usage message on stdout
   127                                  	sys	_write, 1, program_msg, size_pmsg
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 0000003F BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000042 B9[B601]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 00000045 BA3D00              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000048 B80400              <1>  mov ax, %1
    76 0000004B CD20                <1>  int 20h
   128                                  	;sys	_msg, program_msg, size_pmsg, 0Fh 
   129                                  df_1:
   130                                  	sys	_write, 1, usage_msg, size_umsg
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 0000004D BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000050 B9[F401]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 00000053 BA3E00              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000056 B80400              <1>  mov ax, %1
    76 00000059 CD20                <1>  int 20h
   131                                  
   132                                  hang:
   133                                  	sys	_exit
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000005B B80100              <1>  mov ax, %1
    76 0000005E CD20                <1>  int 20h
   134 00000060 EBF9                    	jmp	short hang
   135                                  
   136                                  df_3:
   137 00000062 A3[C002]                	mov	[fdfnum], ax
   138                                  
   139                                  	sys	_read, ax, bsbuffer, 512
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000065 89C3                <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000067 B9[C202]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 0000006A BA0002              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000006D B80300              <1>  mov ax, %1
    76 00000070 CD20                <1>  int 20h
   140 00000072 721E                    	jc	short df_4
   141                                  
   142                                  	; check Retro UNIX signature on boot sector
   143 00000074 813E[C402]5255          	cmp	word [bsFSystemID], 'RU'
   144 0000007A 7516                    	jne	short df_4
   145 0000007C 813E[C602]4653          	cmp	word [bsFSystemID+2], 'FS'
   146 00000082 750E                    	jne	short df_4
   147                                  	;cmp	word [bsfdsign], 'fd'	
   148                                  	;jne	short df_4
   149                                  
   150                                  	sys	_read, [fdfnum], sbbuffer
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000084 8B1E[C002]          <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000088 B9[C204]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000008B B80300              <1>  mov ax, %1
    76 0000008E CD20                <1>  int 20h
   151 00000090 7307                    	jnc	short df_5
   152                                  
   153                                  df_4:
   154                                  	;sys	_close, [fdfnum]
   155                                  	sys	_close
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000092 B80600              <1>  mov ax, %1
    76 00000095 CD20                <1>  int 20h
   156 00000097 EB96                    	jmp	df_err
   157                                  
   158                                  df_5:
   159                                  	; write volume serial number (as hex string)
   160 00000099 BE[C802]                	mov	si, bsVolSerial
   161 0000009C BF[C206]                	mov	di, volserialstr
   162 0000009F B102                    	mov	cl, 2
   163 000000A1 88CD                    	mov	ch, cl ; 2
   164                                  df_6:
   165 000000A3 AC                      	lodsb
   166 000000A4 88C3                    	mov	bl, al
   167 000000A6 80E30F                  	and	bl, 0Fh
   168 000000A9 8AA7[AC02]              	mov	ah, [bx+hexchrs]
   169 000000AD C0E804                  	shr	al, 4
   170 000000B0 88C3                    	mov	bl, al
   171 000000B2 8A87[AC02]              	mov	al, [bx+hexchrs]
   172 000000B6 50                      	push	ax
   173 000000B7 FEC9                    	dec	cl
   174 000000B9 75E8                    	jnz	short df_6
   175 000000BB FECD                    	dec	ch
   176 000000BD 7404                    	jz	short df_7
   177 000000BF B102                    	mov	cl, 2
   178 000000C1 EBE0                    	jmp	short df_6
   179                                  df_7:
   180 000000C3 58                      	pop	ax
   181 000000C4 AB                      	stosw
   182 000000C5 58                      	pop	ax
   183 000000C6 AB                      	stosw
   184 000000C7 B02D                    	mov	al, '-'
   185 000000C9 AA                      	stosb
   186 000000CA 58                      	pop	ax
   187 000000CB AB                      	stosw
   188 000000CC 58                      	pop	ax
   189 000000CD AB                      	stosw
   190                                  	
   191 000000CE B068                    	mov	al, 'h'
   192 000000D0 AA                      	stosb
   193                                  
   194 000000D1 B80D0A                  	mov	ax, 0A0Dh ; CRLF
   195 000000D4 AB                      	stosw
   196                                  	
   197                                  	;xor	al, al
   198                                  	;stosb
   199                                  	
   200                                  	sys	_write, 1, nextline, 2
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 000000D5 BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 000000D8 B9[3002]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 000000DB BA0200              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 000000DE B80400              <1>  mov ax, %1
    76 000000E1 CD20                <1>  int 20h
   201                                  
   202 000000E3 B9[3302]                	mov	cx, fdname	
   203 000000E6 B208                    	mov	dl, 8
   204                                  	sys	_write
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 000000E8 B80400              <1>  mov ax, %1
    76 000000EB CD20                <1>  int 20h
   205                                  
   206                                  	;sys	_msg, fdname, 8, 0Fh
   207                                  
   208                                  	;mov	cx, volserialhdr
   209                                  	;mov	dl, size_vsnhdr
   210                                  	;sys	_write
   211                                  
   212                                  	sys	_write, 1, volserialhdr, size_vsnhdr
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 000000ED BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 000000F0 B9[3C02]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 000000F3 BA1B00              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 000000F6 B80400              <1>  mov ax, %1
    76 000000F9 CD20                <1>  int 20h
   213                                  	
   214 000000FB B9[C206]                	mov	cx, volserialstr
   215 000000FE B20C                    	mov	dl, 12 ; xxxx-xxxxh, CR, LF
   216                                  	sys	_write
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000100 B80400              <1>  mov ax, %1
    76 00000103 CD20                <1>  int 20h
   217                                  
   218                                  df_8:	
   219                                  	sys	_close, [fdfnum]
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000105 8B1E[C002]          <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000109 B80600              <1>  mov ax, %1
    76 0000010C CD20                <1>  int 20h
   220                                  	;	
   221                                  
   222 0000010E BE[C404]                	mov	si, freeb
   223 00000111 8B1E[C204]              	mov	bx, [nfree]
   224 00000115 29FF                    	sub	di, di
   225 00000117 31C9                    	xor	cx, cx
   226                                  	;xor	dx, dx
   227 00000119 28D2                    	sub	dl, dl
   228 0000011B 53                      	push	bx
   229                                  df_9:
   230 0000011C AC                      	lodsb
   231 0000011D B108                    	mov	cl, 8	
   232                                  df_10:
   233 0000011F D0E8                    	shr	al, 1
   234 00000121 7310                    	jnc	short df_11
   235 00000123 42                      	inc	dx
   236 00000124 09FF                    	or	di, di
   237 00000126 750B                    	jnz	short df_11
   238                                  	; save first free block number
   239 00000128 89F7                    	mov	di, si
   240 0000012A 81EF[C404]              	sub	di, freeb
   241 0000012E C1E703                  	shl	di, 3 ; * 8
   242 00000131 29CF                    	sub	di, cx
   243                                  df_11:		
   244 00000133 E2EA                    	loop	df_10
   245 00000135 4B                      	dec	bx
   246 00000136 75E4                    	jnz	short df_9
   247                                  
   248 00000138 58                      	pop	ax
   249 00000139 57                      	push	di ; first free block
   250 0000013A 52                      	push	dx ; free blocks
   251                                  
   252 0000013B C1E003                  	shl	ax, 3  ; number of blocks (volume size)
   253                                  
   254 0000013E E85000                  	call	decimal_number
   255                                  	; si = start of decimal number string
   256                                  	; di = byte count of decimal number string
   257                                  
   258                                  	sys	_write, 1, volszhdr, size_volsz
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000141 BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 00000144 B9[5802]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 00000147 BA1700              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000014A B80400              <1>  mov ax, %1
    76 0000014D CD20                <1>  int 20h
   259                                  
   260                                  	;sys	_write, 1, si, di
   261                                  		
   262 0000014F 89F1                    	mov	cx, si
   263 00000151 89FA                    	mov	dx, di
   264                                  	sys	_write
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000153 B80400              <1>  mov ax, %1
    76 00000156 CD20                <1>  int 20h
   265                                  
   266 00000158 58                      	pop	ax ; free blocks
   267                                  	
   268 00000159 E83500                  	call	decimal_number
   269                                  
   270                                  	sys	_write, 1, fblkshdr, size_fblks
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 0000015C BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 0000015F B9[7002]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 00000162 BA1700              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000165 B80400              <1>  mov ax, %1
    76 00000168 CD20                <1>  int 20h
   271                                  
   272                                  	;sys	_write, 1, si, di
   273                                  
   274 0000016A 89F1                    	mov	cx, si
   275 0000016C 89FA                    	mov	dx, di
   276                                  	sys	_write
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000016E B80400              <1>  mov ax, %1
    76 00000171 CD20                <1>  int 20h
   277                                  
   278 00000173 58                      	pop	ax ; first free block
   279                                  	
   280 00000174 E81A00                  	call	decimal_number
   281                                  
   282                                  	sys	_write, 1, ffblkhdr, size_ffblk
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000177 BB0100              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69 0000017A B9[8802]            <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71 0000017D BA1700              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000180 B80400              <1>  mov ax, %1
    76 00000183 CD20                <1>  int 20h
   283                                  
   284                                  	;sys	_write, 1, si, di
   285                                  
   286 00000185 89F1                    	mov	cx, si
   287 00000187 89FA                    	mov	dx, di
   288                                  	sys	_write
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov bx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov cx, %3
    70                              <1>  %if %0 >= 4
    71                              <1>  mov dx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000189 B80400              <1>  mov ax, %1
    76 0000018C CD20                <1>  int 20h
   289                                  
   290                                  	;;sys	_write, 1, nextline, 2
   291                                  	;mov	cx, nextline
   292                                  	;mov	dl, 2
   293                                  	;sys	_write 	
   294                                  
   295 0000018E E9CAFE                  	jmp	hang  ; terminate 
   296                                  
   297                                  ; ----------------------------------------------------------------
   298                                  
   299                                  decimal_number:
   300                                  	; ax = binary number
   301                                  	
   302 00000191 29C9                    	sub	cx, cx
   303                                  
   304 00000193 BE[D006]                	mov	si, num_str
   305 00000196 89F7                    	mov	di, si
   306                                  
   307 00000198 51                      	push	cx ; 0
   308                                  
   309 00000199 B10A                    	mov	cl, 10
   310                                  dn_1:
   311 0000019B 29D2                    	sub	dx, dx
   312 0000019D F7F1                    	div	cx
   313 0000019F 80C230                  	add	dl, '0'
   314 000001A2 52                      	push	dx
   315 000001A3 21C0                    	and	ax, ax
   316 000001A5 75F4                    	jnz	short dn_1
   317                                  dn_2:
   318 000001A7 58                      	pop	ax
   319 000001A8 21C0                    	and	ax, ax
   320 000001AA 7403                    	jz	short dn_3
   321 000001AC AA                      	stosb
   322 000001AD EBF8                    	jmp	short dn_2
   323                                  dn_3:
   324 000001AF B80D0A                  	mov	ax, 0A0Dh  ; CRLF
   325 000001B2 AB                      	stosw
   326                                  	
   327 000001B3 29F7                    	sub	di, si
   328 000001B5 C3                      	retn		
   329                                  
   330                                  ;-----------------------------------------------------------------
   331                                  ;  data - initialized data
   332                                  ;-----------------------------------------------------------------
   333                                  
   334                                  program_msg:
   335 000001B6 0D0A                    	db  0Dh, 0Ah
   336 000001B8 526574726F20554E49-     	db  'Retro UNIX 8086 v1 DF Utility by Erdogan TAN - 30/06/2022'
   336 000001C1 582038303836207631-
   336 000001CA 204446205574696C69-
   336 000001D3 747920627920457264-
   336 000001DC 6F67616E2054414E20-
   336 000001E5 2D2033302F30362F32-
   336 000001EE 303232             
   337 000001F1 0D0A00                  	db  0Dh, 0Ah, 0
   338                                  usage_msg:
   339 000001F4 0D0A                    	db  0Dh, 0Ah
   340 000001F6 55736167653A206466-     	db  'Usage: df <disk>'
   340 000001FF 203C6469736B3E     
   341 00000206 0D0A                    	db  0Dh, 0Ah
   342 00000208 0D0A                    	db  0Dh, 0Ah
   343 0000020A 4469736B204E616D65-     	db  'Disk Names: fd0, fd1, 0 (fd0), 1 (fd1)'
   343 00000213 733A206664302C2066-
   343 0000021C 64312C203020286664-
   343 00000225 30292C203120286664-
   343 0000022E 3129               
   344                                  	;db  0Dh, 0Ah
   345                                  nextline:
   346 00000230 0D0A00                  	db  0Dh, 0Ah, 0
   347                                  
   348                                  size_pmsg equ usage_msg-(program_msg+1)
   349                                  
   350                                  fdname:
   351 00000233 2F6465762F66647800      	db "/dev/fdx", 0
   352                                  
   353                                  size_umsg equ fdname-(usage_msg+1)
   354                                  
   355                                  volserialhdr:
   356 0000023C 0D0A                    	db 0Dh, 0Ah
   357 0000023E 0D0A                    	db 0Dh, 0Ah
   358 00000240 566F6C756D65205365-     	db "Volume Serial Number : " 
   358 00000249 7269616C204E756D62-
   358 00000252 6572203A20         
   359 00000257 00                      	db 0
   360                                  
   361                                  size_vsnhdr equ volszhdr-(volserialhdr+1) 
   362                                  
   363                                  volszhdr:
   364                                  	;;db 0Dh, 0Ah
   365                                  	;db 0Dh, 0Ah
   366 00000258 566F6C756D65205369-     	db "Volume Size          : "
   366 00000261 7A6520202020202020-
   366 0000026A 2020203A20         
   367 0000026F 00                      	db 0
   368                                  
   369                                  size_volsz equ fblkshdr-(volszhdr+1) 
   370                                    
   371                                  fblkshdr:
   372                                  	;;db 0Dh, 0Ah
   373                                  	;db 0Dh, 0Ah
   374 00000270 4672656520426C6F63-     	db "Free Blocks          : "
   374 00000279 6B7320202020202020-
   374 00000282 2020203A20         
   375 00000287 00                      	db 0
   376                                  
   377                                  size_fblks equ ffblkhdr-(fblkshdr+1) 
   378                                    
   379                                  ffblkhdr:
   380                                  	;;db 0Dh, 0Ah
   381                                  	;db 0Dh, 0Ah
   382 00000288 466972737420467265-     	db "First Free Block     : "
   382 00000291 6520426C6F636B2020-
   382 0000029A 2020203A20         
   383 0000029F 00                      	db 0
   384                                  
   385                                  size_ffblk equ error_msg-(ffblkhdr+1) 
   386                                  
   387                                  error_msg:
   388 000002A0 0D0A                    	db 0Dh, 0Ah	
   389 000002A2 4572726F722021          	db "Error !"
   390 000002A9 0D0A00                   	db 0Dh, 0Ah, 0  
   391                                  
   392                                  hexchrs:
   393 000002AC 303132333435363738-     	db '0123456789ABCDEF', 0
   393 000002B5 3941424344454600   
   394                                  
   395                                  size_emsg equ hexchrs-(error_msg+1)
   396                                  
   397                                  ;-----------------------------------------------------------------
   398                                  ;  bss - uninitialized data
   399                                  ;-----------------------------------------------------------------	
   400                                  
   401 000002BD 90<rep 3h>              align 4
   402                                  
   403                                  bss_start:
   404                                  
   405                                  ABSOLUTE bss_start
   406                                  
   407                                  fdfnum:
   408 000002C0 ????                    	resw 1
   409                                  
   410                                  bsbuffer:
   411 000002C2 <res 200h>              	resb 512
   412                                  
   413                                  bsFSystemID equ bsbuffer+2
   414                                  bsVolSerial equ bsbuffer+6
   415                                  ;bsfdsign   equ bsbuffer+10
   416                                  
   417                                  sbbuffer:
   418 000004C2 <res 200h>              	resb 512
   419                                  
   420                                  nfree equ sbbuffer
   421                                  freeb equ sbbuffer+2
   422                                  
   423                                  volserialstr:
   424 000006C2 <res Eh>                	resb 14  ; xxxx-xxxxh, CRLF, 0
   425                                  
   426                                  num_str:
   427 000006D0 <res Ch>                	resb 12
   428                                  
   429                                  bss_end:
   430                                  
   431                                  ;-----------------------------------------------------------------
   432                                  ; 30/06/2022
   433                                  ;-----------------------------------------------------------------
   434                                  ; Original UNIX v2 - df (disk free blocks info) source code
   435                                  ;-----------------------------------------------------------------
   436                                  ; [ svntree-20081216.tar.gz - bin/df (archive date: 21-11-1972) ]
   437                                  
   438                                  ;/ df -- find free space
   439                                  ;
   440                                  ;	cmp	(sp)+,$1
   441                                  ;	bgt	1f
   442                                  ;	mov	$rf0,0f
   443                                  ;	jsr	pc,df
   444                                  ;	mov	$1,r0
   445                                  ;	sys	write; plus; 1
   446                                  ;	mov	$rk1,0f
   447                                  ;	jsr	pc,df
   448                                  ;	mov	$1,r0
   449                                  ;	sys	write; plus; 1
   450                                  ;	mov	$rk2,0f
   451                                  ;	jsr	pc,df
   452                                  ;	mov	$1,r0
   453                                  ;	sys	write; plus; 1
   454                                  ;	mov	$rk3,0f
   455                                  ;	jsr	pc,df
   456                                  ;	mov	$1,r0
   457                                  ;2:
   458                                  ;	mov	$1,r0
   459                                  ;	sys	write; nl; 1
   460                                  ;	sys	exit
   461                                  ;
   462                                  ;1:
   463                                  ;	tst	(sp)+
   464                                  ;	mov	(sp)+,0f
   465                                  ;	jsr	pc,df
   466                                  ;	br	2b
   467                                  ;
   468                                  ;df:
   469                                  ;	clr	r3
   470                                  ;	sys	36.
   471                                  ;	sys	open; 0:..; 0
   472                                  ;	bes	9f
   473                                  ;	sys	read; nfree; 1024.
   474                                  ;	mov	$freeb,r1
   475                                  ;	mov	nfree,r2
   476                                  ;	asr	r2
   477                                  ;1:
   478                                  ;	mov	$16.,r4
   479                                  ;	mov	(r1)+,r5
   480                                  ;2:
   481                                  ;	rol	r5
   482                                  ;	adc	r3
   483                                  ;	dec	r4
   484                                  ;	bne	2b
   485                                  ;	dec	r2
   486                                  ;	bgt	1b
   487                                  ;9:
   488                                  ;	clr	r2
   489                                  ;	dvd	$10.,r2
   490                                  ;	mov	r3,-(sp)
   491                                  ;	mov	r2,r3
   492                                  ;	beq	2f
   493                                  ;	jsr	pc,9b
   494                                  ;2:
   495                                  ;	movb	(sp)+,ch
   496                                  ;	add	$'0,ch
   497                                  ;	mov	$1,r0
   498                                  ;	sys	write; ch; 1
   499                                  ;	rts	pc
   500                                  ;
   501                                  ;rf0:	</dev/rf0\0>
   502                                  ;rk0:	</dev/rk0\0>
   503                                  ;rk1:	</dev/rk1\0>
   504                                  ;rk2:	</dev/rk2\0>
   505                                  ;rk3:	</dev/rk3\0>
   506                                  ;plus:	<+>
   507                                  ;nl:	<\n>
   508                                  ;	.even
   509                                  ;
   510                                  ;	.bss
   511                                  ;ch:	.=.+2
   512                                  ;nfree:	.=.+2
   513                                  ;freeb:	.=.+1022.
