     1                                  ; ****************************************************************************
     2                                  ; rootdir.s - TRDOS 386 (TRDOS v2.0) TEST Program - display root dir address 
     3                                  ;	      ((Get Logical DOS Drive Description Table))
     4                                  ; ----------------------------------------------------------------------------
     5                                  ; 15/09/2020
     6                                  ;
     7                                  ; ****************************************************************************
     8                                  
     9                                  ; 14/07/2020
    10                                  ; 31/12/2017
    11                                  ; TRDOS 386 (v2.0) system calls
    12                                  _ver 	equ 0
    13                                  _exit 	equ 1
    14                                  _fork 	equ 2
    15                                  _read 	equ 3
    16                                  _write	equ 4
    17                                  _open	equ 5
    18                                  _close 	equ 6
    19                                  _wait 	equ 7
    20                                  _create	equ 8
    21                                  _rename	equ 9
    22                                  _delete	equ 10
    23                                  _exec	equ 11
    24                                  _chdir	equ 12
    25                                  _time 	equ 13
    26                                  _mkdir 	equ 14
    27                                  _chmod	equ 15
    28                                  _rmdir	equ 16
    29                                  _break	equ 17
    30                                  _drive	equ 18
    31                                  _seek	equ 19
    32                                  _tell 	equ 20
    33                                  _memory	equ 21
    34                                  _prompt	equ 22
    35                                  _path	equ 23
    36                                  _env	equ 24
    37                                  _stime	equ 25
    38                                  _quit	equ 26	
    39                                  _intr	equ 27
    40                                  _dir	equ 28
    41                                  _emt 	equ 29
    42                                  _ldrvt 	equ 30
    43                                  _video 	equ 31
    44                                  _audio	equ 32
    45                                  _timer	equ 33
    46                                  _sleep	equ 34
    47                                  _msg    equ 35
    48                                  _geterr	equ 36
    49                                  _fpstat	equ 37
    50                                  _pri	equ 38
    51                                  _rele	equ 39
    52                                  _fff	equ 40
    53                                  _fnf	equ 41
    54                                  _alloc	equ 42
    55                                  _dalloc equ 43
    56                                  _calbac equ 44
    57                                  _dma	equ 45	
    58                                  
    59                                  %macro sys 1-4
    60                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    61                                      ; 03/09/2015	
    62                                      ; 13/04/2015
    63                                      ; Retro UNIX 386 v1 system call.	
    64                                      %if %0 >= 2   
    65                                          mov ebx, %2
    66                                          %if %0 >= 3    
    67                                              mov ecx, %3
    68                                              %if %0 = 4
    69                                                 mov edx, %4   
    70                                              %endif
    71                                          %endif
    72                                      %endif
    73                                      mov eax, %1
    74                                      ;int 30h
    75                                      int 40h ; TRDOS 386 (TRDOS v2.0)	   
    76                                  %endmacro
    77                                  
    78                                  ; TRDOS 386 (and Retro UNIX 386 v1) system call format:
    79                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    80                                  
    81                                  ;========================================================================
    82                                  ; GET LOGICAL DRIVE DESCRIPTION TABLE
    83                                  ;========================================================================
    84                                  
    85                                  ; Logical DOS Disks
    86                                  LD_Name equ 0
    87                                  LD_DiskType equ 1
    88                                  LD_PhyDrvNo equ 2
    89                                  LD_FATType equ 3
    90                                  LD_FSType equ 4
    91                                  LD_LBAYes equ 5
    92                                  LD_BPB equ 6
    93                                  LD_FATBegin equ 96
    94                                  LD_ROOTBegin equ 100
    95                                  LD_DATABegin equ 104
    96                                  LD_StartSector equ 108
    97                                  LD_TotalSectors equ 112
    98                                  LD_FreeSectors equ 116
    99                                  LD_Clusters equ 120
   100                                  LD_PartitionEntry equ 124
   101                                  LD_DParamEntry equ 125
   102                                  LD_MediaChanged equ 126
   103                                  LD_CDirLevel equ 127
   104                                  LD_CurrentDirectory equ 128
   105                                  
   106                                  ;========================================================================
   107                                  ;------------------------------------------------------------------------
   108                                  
   109                                  [BITS 32] ; We need 32-bit instructions for protected mode
   110                                  
   111                                  [ORG 0] 
   112                                  
   113                                  START_CODE:
   114                                  	sys	_ldrvt, 2, ldrvtbuff  ; get logical dos drive table
    60                              <1> 
    61                              <1> 
    62                              <1> 
    63                              <1> 
    64                              <1>  %if %0 >= 2
    65 00000000 BB02000000          <1>  mov ebx, %2
    66                              <1>  %if %0 >= 3
    67 00000005 B9[42010000]        <1>  mov ecx, %3
    68                              <1>  %if %0 = 4
    69                              <1>  mov edx, %4
    70                              <1>  %endif
    71                              <1>  %endif
    72                              <1>  %endif
    73 0000000A B81E000000          <1>  mov eax, %1
    74                              <1> 
    75 0000000F CD40                <1>  int 40h
   115 00000011 0F8294000000            	jc 	error
   116                                  
   117 00000017 31DB                    	xor	ebx, ebx
   118 00000019 A1[A6010000]            	mov	eax, [ldrvtbuff+LD_ROOTBegin]
   119 0000001E B90A000000              	mov	ecx, 10
   120                                  div_repeat:
   121 00000023 31D2                    	xor	edx, edx
   122 00000025 F7F1                    	div	ecx
   123 00000027 80C230                  	add	dl, '0'
   124 0000002A 52                      	push	edx
   125 0000002B 43                      	inc	ebx
   126 0000002C 09C0                    	or	eax, eax
   127 0000002E 75F3                    	jnz	short div_repeat
   128 00000030 BF[15010000]            	mov	edi, number
   129                                  first_zero:
   130 00000035 58                      	pop	eax
   131 00000036 4B                      	dec	ebx
   132 00000037 7409                    	jz	short last_zero
   133 00000039 3C30                    	cmp	al, '0'
   134 0000003B 76F8                    	jna	short first_zero
   135                                  non_zero:
   136 0000003D AA                      	stosb	
   137 0000003E 58                      	pop	eax
   138 0000003F 4B                      	dec	ebx
   139 00000040 75FB                    	jnz	short non_zero	
   140                                  last_zero:
   141 00000042 AA                      	stosb
   142                                  	;sub	al, al
   143                                  	;stosb	
   144                                  
   145                                  p_rootdir_addr:
   146 00000043 BE[EF000000]            	mov 	esi, rootdir_msg
   147 00000048 E865000000              	call	print_msg
   148 0000004D BE[20010000]            	mov	esi, crlf
   149 00000052 E85B000000              	call 	print_msg
   150                                  	
   151 00000057 BE[42010000]            	mov	esi, ldrvtbuff
   152 0000005C 31C0                    	xor	eax, eax
   153 0000005E 66A3[82020000]          	mov	[zeroword], ax
   154                                  hexrow:
   155 00000064 B910000000              	mov	ecx, 16
   156 00000069 BF[42020000]            	mov	edi, hextable
   157                                  hexchar:
   158 0000006E AC                      	lodsb
   159 0000006F E852000000              	call	bintohex
   160 00000074 66AB                    	stosw
   161 00000076 66B86820                	mov	ax, 'h '
   162 0000007A 66AB                    	stosw
   163 0000007C E2F0                    	loop	hexchar
   164                                  
   165 0000007E 56                      	push	esi	
   166 0000007F 66BE[2001]              	mov	si, crlf
   167 00000083 E82A000000              	call 	print_msg
   168 00000088 66BE[4202]              	mov	si, hextable
   169 0000008C E821000000              	call 	print_msg
   170 00000091 5E                      	pop	esi
   171 00000092 81FE[42020000]          	cmp	esi, ldrvtbuff+256
   172 00000098 72CA                    	jb	short hexrow		
   173 0000009A BE[20010000]            	mov	esi, crlf
   174                                  p_msg:
   175 0000009F E80E000000              	call 	print_msg
   176                                  here:	
   177                                  	sys	_exit
    60                              <1> 
    61                              <1> 
    62                              <1> 
    63                              <1> 
    64                              <1>  %if %0 >= 2
    65                              <1>  mov ebx, %2
    66                              <1>  %if %0 >= 3
    67                              <1>  mov ecx, %3
    68                              <1>  %if %0 = 4
    69                              <1>  mov edx, %4
    70                              <1>  %endif
    71                              <1>  %endif
    72                              <1>  %endif
    73 000000A4 B801000000          <1>  mov eax, %1
    74                              <1> 
    75 000000A9 CD40                <1>  int 40h
   178                                  	; hlt
   179                                  	; jmp 	short here
   180                                  
   181                                  error:
   182 000000AB BE[23010000]            	mov 	esi, msg_err
   183 000000B0 EBED                    	jmp 	short p_msg
   184                                   
   185                                  print_msg:
   186                                  	sys 	_msg, esi, 255, 0Fh ; message with white color 
    60                              <1> 
    61                              <1> 
    62                              <1> 
    63                              <1> 
    64                              <1>  %if %0 >= 2
    65 000000B2 89F3                <1>  mov ebx, %2
    66                              <1>  %if %0 >= 3
    67 000000B4 B9FF000000          <1>  mov ecx, %3
    68                              <1>  %if %0 = 4
    69 000000B9 BA0F000000          <1>  mov edx, %4
    70                              <1>  %endif
    71                              <1>  %endif
    72                              <1>  %endif
    73 000000BE B823000000          <1>  mov eax, %1
    74                              <1> 
    75 000000C3 CD40                <1>  int 40h
   187                                  				    ; (max. 255 chars)
   188 000000C5 C3                      	retn
   189                                  
   190                                  ;------------------------------------------------------------------------
   191                                  
   192                                  bintohex:
   193                                  	; INPUT ->
   194                                  	; 	AL = byte (binary number)
   195                                  	; OUTPUT ->
   196                                  	;	AX = hexadecimal string
   197                                  	;
   198 000000C6 31DB                    	xor	ebx, ebx
   199 000000C8 88C3                    	mov	bl, al
   200 000000CA C0EB04                  	shr	bl, 4
   201 000000CD 8A9B[DF000000]          	mov	bl, [ebx+hexchrs] 	 	
   202 000000D3 86D8                    	xchg	bl, al
   203 000000D5 80E30F                  	and	bl, 0Fh
   204 000000D8 8AA3[DF000000]          	mov	ah, [ebx+hexchrs] 
   205 000000DE C3                      	retn
   206                                  
   207                                  hexchrs:
   208 000000DF 303132333435363738-     	db	'0123456789ABCDEF'
   208 000000E8 39414243444546     
   209                                  
   210                                  ;------------------------------------------------------------------------
   211                                  ;  root directory message
   212                                  ;------------------------------------------------------------------------
   213                                  
   214 000000EF 0D0A                    rootdir_msg:	db 0Dh, 0Ah
   215 000000F1 447269766520433A20      		db 'Drive C: '
   216 000000FA 0D0A                    		db 0Dh, 0Ah
   217 000000FC 526F6F742044697265-     		db 'Root Directory Address : '
   217 00000105 63746F727920416464-
   217 0000010E 72657373203A20     
   218                                  number:
   219 00000115 00<rep Bh>              		times 11 db 0
   220                                  crlf:
   221 00000120 0D0A00                  		db 0Dh, 0Ah, 0
   222                                  
   223                                  msg_err:
   224 00000123 0D0A                    		db 0Dh, 0Ah 
   225 00000125 4572726F7220212028-                     db 'Error ! (Drive not ready!)'
   225 0000012E 4472697665206E6F74-
   225 00000137 2072656164792129   
   226 0000013F 0D0A00                  		db 0Dh, 0Ah, 0
   227                                  
   228                                  ;------------------------------------------------------------------------
   229                                  ;  buffer & hex table
   230                                  ;------------------------------------------------------------------------
   231                                  
   232                                  bss_start:
   233                                  
   234                                  ABSOLUTE bss_start
   235                                  
   236 00000142 <res 100h>              ldrvtbuff: resb 256
   237 00000242 <res 40h>               hextable:  resb 64
   238 00000282 ????                    zeroword:  resw 1
   239                                  	   		
   240                                  bss_end:
