     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 14/04/2016
     5                                  ; ----------------------------------------------------------------------------
     6                                  ; Beginning: 04/01/2016
     7                                  ; ----------------------------------------------------------------------------
     8                                  ; Assembler: NASM version 2.11 (trdos386.s)
     9                                  ; ----------------------------------------------------------------------------
    10                                  ; Turkish Rational DOS
    11                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    12                                  ;
    13                                  ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
    14                                  ; unix386.s (03/01/2016)
    15                                  ;
    16                                  ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
    17                                  ; TRDOS2.ASM (09/11/2011)
    18                                  ; 
    19                                  ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
    20                                  ; ****************************************************************************
    21                                  
    22                                  KLOAD	equ 10000h ; Kernel loading address
    23                                  	; NOTE: Retro UNIX 8086 v1 /boot code loads kernel at 1000h:0000h 
    24                                  KCODE	equ 08h	; Code segment descriptor (ring 0)
    25                                  KDATA	equ 10h	; Data segment descriptor (ring 0)
    26                                  ; 19/03/2015
    27                                  UCODE	equ 1Bh ; 18h + 3h  (ring 3)
    28                                  UDATA	equ 23h ; 20h + 3h  (ring 3)
    29                                  ; 24/03/2015
    30                                  TSS	equ 28h	; Task state segment descriptor (ring 0)
    31                                  ; 19/03/2015
    32                                  CORE	equ 400000h  ; Start of USER's virtual/linear address space 
    33                                  		     ; (at the end of the 1st 4MB)
    34                                  ECORE	equ 0FFC00000h ; End of USER's virtual address space (4GB - 4MB)
    35                                  		     ; ULIMIT = (ECORE/4096) - 1 = 0FFBFFh (in GDT)
    36                                  
    37                                  ; 27/12/2013
    38                                  KEND    equ KLOAD + 65536 ; (28/12/2013) (end of kernel space)
    39                                  
    40                                  ; IBM PC/AT BIOS ----- 10/06/85 (postequ.inc)
    41                                  ;--------- CMOS TABLE LOCATION ADDRESS'S -------------------------------------
    42                                  CMOS_SECONDS	EQU	00H		; SECONDS (BCD)
    43                                  CMOS_SEC_ALARM	EQU	01H		; SECONDS ALARM (BCD)
    44                                  CMOS_MINUTES	EQU	02H		; MINUTES (BCD)
    45                                  CMOS_MIN_ALARM	EQU	03H		; MINUTES ALARM (BCD) 	
    46                                  CMOS_HOURS	EQU	04H		; HOURS (BCD
    47                                  CMOS_HR_ALARM	EQU	005H		; HOURS ALARM   (BCD)
    48                                  CMOS_DAY_WEEK	EQU	06H		; DAY OF THE WEEK  (BCD)
    49                                  CMOS_DAY_MONTH	EQU	07H		; DAY OF THE MONTH (BCD) 
    50                                  CMOS_MONTH	EQU	08H		; MONTH (BCD)
    51                                  CMOS_YEAR	EQU	09H		; YEAR (TWO DIGITS) (BCD)
    52                                  CMOS_CENTURY	EQU	32H		; DATE CENTURY BYTE (BCD)
    53                                  CMOS_REG_A	EQU	0AH		; STATUS REGISTER A
    54                                  CMOS_REG_B	EQU	00BH		; STATUS REGISTER B  ALARM
    55                                  CMOS_REG_C	EQU	00CH		; STATUS REGISTER C  FLAGS
    56                                  CMOS_REG_D	EQU	0DH		; STATUS REGISTER D  BATTERY
    57                                  CMOS_SHUT_DOWN	EQU	0FH		; SHUTDOWN STATUS COMMAND BYTE
    58                                  ;----------------------------------------
    59                                  ;	CMOS EQUATES FOR THIS SYSTEM	;
    60                                  ;-----------------------------------------------------------------------------
    61                                  CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
    62                                  CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
    63                                  NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
    64                                  					; HIGH BIT OF CMOS LOCATION ADDRESS
    65                                  
    66                                  ; Memory Allocation Table Address
    67                                  ; 05/11/2014
    68                                  ; 31/10/2014
    69                                  MEM_ALLOC_TBL	equ	100000h		; Memory Allocation Table at the end of
    70                                  					; the 1st 1 MB memory space.
    71                                  					; (This address must be aligned
    72                                  					;  on 128 KB boundary, if it will be
    73                                  					;  changed later.)
    74                                  					; ((lower 17 bits of 32 bit M.A.T.
    75                                  					;   address must be ZERO)).
    76                                  					; ((((Reason: 32 bit allocation 
    77                                  					;     instructions, dword steps)))
    78                                  					; (((byte >> 12 --> page >> 5)))  
    79                                  ;04/11/2014	
    80                                  PDE_A_PRESENT	equ	1		; Present flag for PDE
    81                                  PDE_A_WRITE	equ 	2		; Writable (write permission) flag
    82                                  PDE_A_USER	equ	4		; User (non-system/kernel) page flag
    83                                  ;
    84                                  PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
    85                                  PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
    86                                  PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
    87                                  PTE_A_ACCESS    equ	32		; Accessed flag (bit 5) ; 09/03/2015
    88                                  
    89                                  ; 17/02/2015 (unix386.s)
    90                                  ; 10/12/2014 - 30/12/2014 (0B000h -> 9000h) (dsectrm2.s)
    91                                  DPT_SEGM equ 09000h  ; FDPT segment (EDD v1.1, EDD v3)
    92                                  ;
    93                                  HD0_DPT	 equ 0	    ; Disk parameter table address for hd0
    94                                  HD1_DPT	 equ 32	    ; Disk parameter table address for hd1
    95                                  HD2_DPT	 equ 64	    ; Disk parameter table address for hd2
    96                                  HD3_DPT	 equ 96	    ; Disk parameter table address for hd3
    97                                  
    98                                  
    99                                  ; FDPT (Phoenix, Enhanced Disk Drive Specification v1.1, v3.0)
   100                                  ;      (HDPT: Programmer's Guide to the AMIBIOS, 1993)
   101                                  ;
   102                                  FDPT_CYLS	equ 0 ; 1 word, number of cylinders
   103                                  FDPT_HDS	equ 2 ; 1 byte, number of heads
   104                                  FDPT_TT		equ 3 ; 1 byte, A0h = translated FDPT with logical values
   105                                  		      ; otherwise it is standard FDPT with physical values 	
   106                                  FDPT_PCMP	equ 5 ; 1 word, starting write precompensation cylinder
   107                                  		      ; (obsolete for IDE/ATA drives)
   108                                  FDPT_CB		equ 8 ; 1 byte, drive control byte
   109                                  			; Bits 7-6 : Enable or disable retries (00h = enable)
   110                                  			; Bit 5	: 1 = Defect map is located at last cyl. + 1
   111                                  			; Bit 4 : Reserved. Always 0
   112                                  			; Bit 3 : Set to 1 if more than 8 heads
   113                                  			; Bit 2-0 : Reserved. Alsways 0
   114                                  FDPT_LZ		equ 12 ; 1 word, landing zone (obsolete for IDE/ATA drives)
   115                                  FDPT_SPT	equ 14 ; 1 byte, sectors per track
   116                                  
   117                                  ; Floppy Drive Parameters Table (Programmer's Guide to the AMIBIOS, 1993)
   118                                  ; (11 bytes long) will be used by diskette handler/bios
   119                                  ; which is derived from IBM PC-AT BIOS (DISKETTE.ASM, 21/04/1986).
   120                                  
   121                                  ; 01/02/2016
   122                                  Logical_DOSDisks equ 90000h + 100h ; 26*256 = 6656 bytes
   123                                  Directory_Buffer equ 80000h ; max = 64K Bytes
   124                                  FAT_Buffer	 equ 91C00h ; 1536 bytes (3 sectors)
   125                                  ; 15/02/2016
   126                                  Cluster_Buffer	 equ 70000h ; max = 64K Bytes ; buffer for file read & write
   127                                  ; 11/04/2016
   128                                  Env_Page:	 equ 93000h ; 512 bytes (4096 bytes)
   129                                  Env_Page_Size	 equ 512    ; (4096 bytes)				 	  		 	  
   130                                  
   131                                  [BITS 16]       ; We need 16-bit intructions for Real mode
   132                                  
   133                                  [ORG 0] 
   134                                  	; 12/11/2014
   135                                  	; Save boot drive number (that is default root drive)
   136 00000000 8816[4ABF]              	mov	[boot_drv], dl ; physical drv number
   137                                  
   138                                  	; Determine installed memory
   139                                  	; 31/10/2014
   140                                  	;
   141 00000004 B801E8                  	mov	ax, 0E801h ; Get memory size 
   142 00000007 CD15                    	int	15h	   ; for large configurations
   143 00000009 7308                    	jnc	short chk_ms
   144 0000000B B488                    	mov	ah, 88h    ; Get extended memory size 
   145 0000000D CD15                    	int	15h
   146                                  	;	   
   147                                  	;mov	al, 17h	; Extended memory (1K blocks) low byte
   148                                  	;out	70h, al ; select CMOS register
   149                                  	;in	al, 71h ; read data (1 byte)
   150                                  	;mov	cl, al
   151                                  	;mov	al, 18h ; Extended memory (1K blocks) high byte
   152                                  	;out	70h, al ; select CMOS register
   153                                  	;in	al, 71h ; read data (1 byte)
   154                                  	;mov	ch, al
   155                                   	;      
   156 0000000F 89C1                    	mov	cx, ax
   157 00000011 31D2                    	xor	dx, dx
   158                                  chk_ms:
   159 00000013 890E[D4C1]              	mov	[mem_1m_1k], cx
   160 00000017 8916[D6C1]              	mov	[mem_16m_64k], dx
   161                                  	; 05/11/2014
   162                                  	;and	dx, dx
   163                                  	;jz	short L2
   164 0000001B 81F90004                        cmp     cx, 1024
   165 0000001F 7315                    	jnb	short L0
   166                                  		 ; insufficient memory_error	
   167                                  		 ; Minimum 2 MB memory is needed... 
   168                                  	; 05/11/2014
   169                                  	; (real mode error printing)
   170 00000021 FB                      	sti
   171 00000022 BE[63C0]                	mov	si, msg_out_of_memory
   172 00000025 BB0700                  	mov	bx, 7
   173 00000028 B40E                    	mov	ah, 0Eh	; write tty
   174                                  oom_1:
   175 0000002A AC                      	lodsb
   176 0000002B 08C0                    	or	al, al
   177 0000002D 7404                    	jz	short oom_2
   178 0000002F CD10                    	int	10h
   179 00000031 EBF7                    	jmp	short oom_1
   180                                  oom_2:
   181 00000033 F4                              hlt
   182 00000034 EBFD                    	jmp	short oom_2
   183                                  
   184                                  L0:
   185                                  %include 'diskinit.s' ; 07/03/2015
   186                              <1> ; ****************************************************************************
   187                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskinit.s
   188                              <1> ; ----------------------------------------------------------------------------
   189                              <1> ; Last Update: 04/02/2016
   190                              <1> ; ----------------------------------------------------------------------------
   191                              <1> ; Beginning: 24/01/2016
   192                              <1> ; ----------------------------------------------------------------------------
   193                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
   194                              <1> ; ----------------------------------------------------------------------------
   195                              <1> ; Turkish Rational DOS
   196                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
   197                              <1> ;
   198                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
   199                              <1> ; diskinit.inc (10/07/2015)
   200                              <1> ;
   201                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
   202                              <1> ; ****************************************************************************
   203                              <1> 
   204                              <1> ; Retro UNIX 386 v1 Kernel - DISKINIT.INC
   205                              <1> ; Last Modification: 10/07/2015
   206                              <1> 
   207                              <1> ; DISK I/O SYSTEM INITIALIZATION - Erdogan Tan (Retro UNIX 386 v1 project)
   208                              <1> 
   209                              <1> ; ///////// DISK I/O SYSTEM STRUCTURE INITIALIZATION ///////////////
   210                              <1> 
   211                              <1> 	; 10/12/2014 - 02/02/2015 - dsectrm2.s
   212                              <1> ;L0:
   213                              <1> 	; 12/11/2014 (Retro UNIX 386 v1 - beginning)
   214                              <1> 	; Detecting disk drives... (by help of ROM-BIOS)
   215 00000036 BA7F00              <1> 	mov	dx, 7Fh
   216                              <1> L1:	
   217 00000039 FEC2                <1> 	inc	dl
   218 0000003B B441                <1> 	mov	ah, 41h ; Check extensions present
   219                              <1> 			; Phoenix EDD v1.1 - EDD v3
   220 0000003D BBAA55              <1> 	mov	bx, 55AAh
   221 00000040 CD13                <1> 	int 	13h
   222 00000042 721A                <1> 	jc	short L2
   223                              <1> 
   224 00000044 81FB55AA            <1> 	cmp	bx, 0AA55h
   225 00000048 7514                <1> 	jne	short L2
   226 0000004A FE06[4DBF]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
   227 0000004E 8816[4CBF]          <1>         mov     [last_drv], dl  ; last hard disk number
   228 00000052 BB[D0BE]            <1> 	mov	bx, hd0_type - 80h
   229 00000055 01D3                <1> 	add	bx, dx	 
   230 00000057 880F                <1> 	mov	[bx], cl ; Interface support bit map in CX
   231                              <1> 			 ; Bit 0 - 1, Fixed disk access subset ready
   232                              <1> 			 ; Bit 1 - 1, Drv locking and ejecting ready
   233                              <1> 			 ; Bit 2 - 1, Enhanced Disk Drive Support
   234                              <1>                          ;            (EDD) ready (DPTE ready)
   235                              <1> 			 ; Bit 3 - 1, 64bit extensions are present
   236                              <1>                          ;            (EDD-3)
   237                              <1> 			 ; Bit 4 to 15 - 0, Reserved
   238 00000059 80FA83              <1> 	cmp	dl, 83h	 ; drive number < 83h
   239 0000005C 72DB                <1> 	jb	short L1
   240                              <1> L2:
   241                              <1> 	; 23/11/2014
   242                              <1> 	; 19/11/2014
   243 0000005E 30D2                <1> 	xor	dl, dl  ; 0
   244                              <1> 	; 04/02/2016 (esi -> si)
   245 00000060 BE[4EBF]            <1> 	mov	si, fd0_type
   246                              <1> L3:
   247                              <1> 	; 14/01/2015
   248 00000063 8816[4BBF]          <1> 	mov	[drv], dl
   249                              <1> 	;
   250 00000067 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   251 00000069 CD13                <1> 	int	13h	
   252 0000006B 7210                <1> 	jc	short L4
   253                              <1> 		; BL = drive type (for floppy drives)
   254                              <1> 		; DL = number of floppy drives
   255                              <1> 		;		
   256                              <1> 		; ES:DI = Address of DPT from BIOS
   257                              <1> 		;
   258 0000006D 881C                <1> 	mov	[si], bl ;  Drive type
   259                              <1> 			; 4 = 1.44 MB, 80 track, 3 1/2"
   260                              <1> 	; 14/01/2015
   261 0000006F E8A202              <1> 	call	set_disk_parms
   262                              <1> 	; 10/12/2014
   263 00000072 81FE[4EBF]          <1> 	cmp	si, fd0_type
   264 00000076 7705                <1> 	ja	short L4
   265 00000078 46                  <1> 	inc	si ; fd1_type
   266 00000079 B201                <1> 	mov	dl, 1
   267 0000007B EBE6                <1> 	jmp	short L3
   268                              <1> L4:
   269                              <1> 	; Older BIOS (INT 13h, AH = 48h is not available)
   270 0000007D B27F                <1> 	mov	dl, 7Fh
   271                              <1> 	; 24/12/2014 (Temporary)
   272 0000007F 803E[4DBF]00        <1> 	cmp	byte [hdc], 0 ; EDD present or not ?	
   273 00000084 0F879000            <1>         ja      L10       ; yes, all fixed disk operations
   274                              <1> 			  ; will be performed according to
   275                              <1> 			  ; present EDD specification
   276                              <1> L6:
   277 00000088 FEC2                <1> 	inc 	dl
   278 0000008A 8816[4BBF]          <1>         mov     [drv], dl
   279 0000008E 8816[4CBF]          <1>         mov     [last_drv], dl ; 14/01/2015
   280 00000092 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   281 00000094 CD13                <1> 	int	13h	; (conventional function)
   282 00000096 0F828201            <1>         jc      L13	; fixed disk drive not ready
   283 0000009A 8816[4DBF]          <1>         mov     [hdc], dl ; number of drives
   284                              <1> 	;; 14/01/2013
   285                              <1> 	;;push	cx
   286 0000009E E87302              <1> 	call	set_disk_parms
   287                              <1> 	;;pop	cx
   288                              <1> 	;
   289                              <1> 	;;and	cl, 3Fh	 ; sectors per track (bits 0-6)
   290 000000A1 8A16[4BBF]          <1>         mov     dl, [drv]
   291 000000A5 BB0401              <1> 	mov	bx, 65*4 ; hd0 parameters table (INT 41h)	
   292 000000A8 80FA80              <1> 	cmp	dl, 80h
   293 000000AB 7603                <1> 	jna	short L7
   294 000000AD 83C314              <1> 	add	bx, 5*4	 ; hd1 parameters table (INT 46h)
   295                              <1> L7:	
   296 000000B0 31C0                <1> 	xor	ax, ax
   297 000000B2 8ED8                <1> 	mov	ds, ax
   298 000000B4 8B37                <1>         mov     si, [bx]
   299 000000B6 8B4702              <1>         mov     ax, [bx+2] 
   300 000000B9 8ED8                <1> 	mov	ds, ax
   301 000000BB 3A4C0E              <1>         cmp     cl, [si+FDPT_SPT] ; sectors per track 
   302 000000BE 0F855601            <1>         jne     L12 ; invalid FDPT
   303 000000C2 BF0000              <1> 	mov	di, HD0_DPT
   304 000000C5 80FA80              <1> 	cmp	dl, 80h
   305 000000C8 7603                <1> 	jna	short L8
   306 000000CA BF2000              <1> 	mov	di, HD1_DPT 
   307                              <1> L8:
   308                              <1> 	; 30/12/2014
   309 000000CD B80090              <1> 	mov	ax, DPT_SEGM
   310 000000D0 8EC0                <1> 	mov	es, ax
   311                              <1> 	; 24/12/2014
   312 000000D2 B90800              <1> 	mov	cx, 8
   313 000000D5 F3A5                <1> 	rep	movsw  ; copy 16 bytes to the kernel's DPT location
   314 000000D7 8CC8                <1> 	mov	ax, cs
   315 000000D9 8ED8                <1> 	mov	ds, ax
   316                              <1> 	; 02/02/2015
   317 000000DB 8A0E[4BBF]          <1>         mov     cl, [drv]
   318 000000DF 88CB                <1> 	mov	bl, cl
   319 000000E1 B8F001              <1> 	mov	ax, 1F0h
   320 000000E4 80E301              <1> 	and	bl, 1
   321 000000E7 7406                <1> 	jz	short L9
   322 000000E9 C0E304              <1> 	shl	bl, 4
   323 000000EC 2D8000              <1> 	sub	ax, 1F0h-170h
   324                              <1> L9:
   325 000000EF AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   326 000000F0 050602              <1> 	add	ax, 206h
   327 000000F3 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   328 000000F4 88D8                <1> 	mov	al, bl
   329 000000F6 04A0                <1> 	add	al, 0A0h
   330 000000F8 AA                  <1> 	stosb	; Device/Head Register upper nibble
   331                              <1> 	;
   332 000000F9 FE06[4BBF]          <1> 	inc	byte [drv]
   333 000000FD BB[D0BE]            <1> 	mov	bx, hd0_type - 80h
   334 00000100 01CB                <1> 	add	bx, cx
   335 00000102 800F80              <1>         or      byte [bx], 80h  ; present sign (when lower nibble is 0)
   336 00000105 A0[4DBF]            <1> 	mov	al, [hdc]
   337 00000108 FEC8                <1> 	dec	al
   338 0000010A 0F840E01            <1>         jz      L13
   339 0000010E 80FA80              <1> 	cmp	dl, 80h
   340 00000111 0F8673FF            <1>         jna     L6
   341 00000115 E90401              <1>         jmp     L13
   342                              <1> L10:
   343 00000118 FEC2                <1> 	inc 	dl
   344                              <1> 	; 25/12/2014
   345 0000011A 8816[4BBF]          <1> 	mov	[drv], dl
   346 0000011E B408                <1> 	mov 	ah, 08h ; Return drive parameters
   347 00000120 CD13                <1> 	int	13h	; (conventional function)
   348 00000122 0F82F600            <1>         jc      L13
   349                              <1> 	; 14/01/2015
   350 00000126 8A16[4BBF]          <1> 	mov	dl, [drv]
   351 0000012A 52                  <1> 	push	dx
   352 0000012B 51                  <1> 	push	cx
   353 0000012C E8E501              <1> 	call	set_disk_parms
   354 0000012F 59                  <1> 	pop	cx
   355 00000130 5A                  <1> 	pop	dx
   356                              <1> 	; 04/02/2016 (esi -> si)
   357 00000131 BE[B0E1]            <1> 	mov	si, _end ; 30 byte temporary buffer address 	
   358                              <1> 			 ; at the '_end' of kernel.
   359 00000134 C7041E00            <1> 	mov	word [si], 30
   360 00000138 B448                <1> 	mov	ah, 48h	 ; Get drive parameters (EDD function)
   361 0000013A CD13                <1> 	int	13h
   362 0000013C 0F82DC00            <1>         jc      L13
   363                              <1> 	; 04/02/2016 (ebx -> bx)
   364                              <1> 	; 14/01/2015
   365 00000140 29DB                <1> 	sub	bx, bx
   366 00000142 88D3                <1> 	mov	bl, dl
   367 00000144 80EB80              <1> 	sub	bl, 80h
   368 00000147 81C3[50BF]          <1> 	add	bx, hd0_type
   369 0000014B 8A07                <1> 	mov 	al, [bx]
   370 0000014D 0C80                <1> 	or	al, 80h
   371 0000014F 8807                <1> 	mov 	[bx], al	
   372 00000151 81EB[4EBF]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   373 00000155 81C3[9ABF]          <1> 	add	bx, drv.status
   374 00000159 8807                <1> 	mov	[bx], al
   375                              <1> 	; 04/02/2016 (eax -> ax)
   376 0000015B 8B4410              <1> 	mov	ax, [si+16]
   377 0000015E 854412              <1> 	test	ax, [si+18]
   378 00000161 7412                <1> 	jz	short L10_A0h 
   379                              <1> 			; 'CHS only' disks on EDD system 
   380                              <1> 			;  are reported with ZERO disk size
   381 00000163 81EB[9ABF]          <1> 	sub	bx, drv.status
   382 00000167 C1E302              <1> 	shl	bx, 2
   383 0000016A 81C3[7EBF]          <1> 	add	bx, drv.size ; disk size (in sectors)
   384 0000016E 8907                <1> 	mov	[bx], ax
   385 00000170 8B4412              <1> 	mov	ax, [si+18]
   386 00000173 8907                <1> 	mov	[bx], ax
   387                              <1> 
   388                              <1> L10_A0h: ; Jump here to fix a ZERO (LBA) disk size problem 
   389                              <1> 	 ; for CHS disks (28/02/2015)
   390                              <1> 	; 30/12/2014
   391 00000175 BF0000              <1> 	mov	di, HD0_DPT
   392 00000178 88D0                <1> 	mov	al, dl
   393 0000017A 83E003              <1> 	and 	ax, 3
   394 0000017D C0E005              <1> 	shl	al, 5 ; *32
   395 00000180 01C7                <1> 	add 	di, ax
   396 00000182 B80090              <1> 	mov	ax, DPT_SEGM
   397 00000185 8EC0                <1> 	mov	es, ax
   398                              <1> 	;
   399 00000187 88E8                <1> 	mov	al, ch	; max. cylinder number (bits 0-7)
   400 00000189 88CC                <1> 	mov	ah, cl	
   401 0000018B C0EC06              <1> 	shr	ah, 6	; max. cylinder number (bits 8-9)
   402 0000018E 40                  <1>  	inc	ax	; logical cylinders (limit 1024)
   403 0000018F AB                  <1> 	stosw		
   404 00000190 88F0                <1> 	mov	al, dh	; max. head number
   405 00000192 FEC0                <1> 	inc	al
   406 00000194 AA                  <1> 	stosb		; logical heads (limits 256)
   407 00000195 B0A0                <1> 	mov	al, 0A0h ; Indicates translated table
   408 00000197 AA                  <1> 	stosb
   409 00000198 8A440C              <1> 	mov	al, [si+12]
   410 0000019B AA                  <1> 	stosb		 ; physical sectors per track
   411 0000019C 31C0                <1>  	xor	ax, ax
   412                              <1> 	;dec	ax	 ; 02/01/2015 
   413 0000019E AB                  <1> 	stosw		 ; precompensation (obsolete)
   414                              <1> 	;xor	al, al	 ; 02/01/2015	
   415 0000019F AA                  <1> 	stosb		 ; reserved
   416 000001A0 B008                <1> 	mov	al, 8	 ; drive control byte
   417                              <1> 		         ; (do not disable retries, 
   418                              <1> 			 ; more than 8 heads)
   419 000001A2 AA                  <1> 	stosb
   420 000001A3 8B4404              <1> 	mov	ax, [si+4]
   421 000001A6 AB                  <1> 	stosw		 ; physical number of cylinders	
   422                              <1> 	;push	ax	 ; 02/01/2015
   423 000001A7 8A4408              <1> 	mov	al, [si+8]
   424 000001AA AA                  <1> 	stosb		 ; physical num. of heads (limit 16)
   425 000001AB 29C0                <1> 	sub 	ax, ax
   426                              <1> 	;pop	ax	 ; 02/01/2015	
   427 000001AD AB                  <1> 	stosw		 ; landing zone (obsolete)
   428 000001AE 88C8                <1> 	mov	al, cl	 ; logical sectors per track (limit 63)
   429 000001B0 243F                <1> 	and 	al, 3Fh	
   430 000001B2 AA                  <1> 	stosb
   431                              <1> 	;sub	al, al	 ; checksum
   432                              <1> 	;stosb
   433                              <1> 	;
   434 000001B3 83C61A              <1> 	add	si, 26   ; (BIOS) DPTE address pointer
   435 000001B6 AD                  <1> 	lodsw
   436 000001B7 50                  <1> 	push	ax	 ; (BIOS) DPTE offset
   437 000001B8 AD                  <1> 	lodsw
   438 000001B9 50                  <1> 	push	ax	 ; (BIOS) DPTE segment
   439                              <1> 	;
   440                              <1> 	; checksum calculation
   441 000001BA 89FE                <1> 	mov	si, di
   442 000001BC 06                  <1> 	push	es
   443 000001BD 1F                  <1> 	pop	ds
   444                              <1> 	;mov	cx, 16
   445 000001BE B90F00              <1> 	mov 	cx, 15
   446 000001C1 29CE                <1> 	sub	si, cx
   447 000001C3 30E4                <1> 	xor	ah, ah
   448                              <1> 	;del	cl
   449                              <1> L11:		
   450 000001C5 AC                  <1> 	lodsb
   451 000001C6 00C4                <1> 	add	ah, al
   452 000001C8 E2FB                <1> 	loop	L11
   453                              <1> 	;
   454 000001CA 88E0                <1> 	mov	al, ah
   455 000001CC F6D8                <1> 	neg	al	; -x+x = 0
   456 000001CE AA                  <1> 	stosb		; put checksum in byte 15 of the tbl
   457                              <1> 	;
   458 000001CF 1F                  <1> 	pop	ds	; (BIOS) DPTE segment
   459 000001D0 5E                  <1> 	pop	si	; (BIOS) DPTE offset	
   460                              <1> 	;
   461                              <1> 	; 23/02/2015
   462 000001D1 57                  <1> 	push	di
   463                              <1> 	; ES:DI points to DPTE (FDPTE) location
   464                              <1> 	;mov	cx, 8
   465 000001D2 B108                <1> 	mov	cl, 8
   466 000001D4 F3A5                <1> 	rep	movsw	
   467                              <1> 	;
   468                              <1> 	; 23/02/2015
   469                              <1> 	; (P)ATA drive and LBA validation
   470                              <1> 	; (invalidating SATA drives and setting
   471                              <1> 	; CHS type I/O for old type fixed disks)
   472 000001D6 5B                  <1> 	pop	bx
   473 000001D7 8CC8                <1> 	mov	ax, cs
   474 000001D9 8ED8                <1> 	mov	ds, ax
   475 000001DB 268B07              <1> 	mov	ax, [es:bx]
   476 000001DE 3DF001              <1> 	cmp	ax, 1F0h
   477 000001E1 7418                <1> 	je	short L11a
   478 000001E3 3D7001              <1> 	cmp	ax, 170h
   479 000001E6 7413                <1> 	je	short L11a
   480                              <1> 	; invalidation 
   481                              <1> 	; (because base port address is not 1F0h or 170h)
   482 000001E8 30FF                <1> 	xor	bh, bh
   483 000001EA 88D3                <1> 	mov	bl, dl
   484 000001EC 80EB80              <1> 	sub	bl, 80h
   485 000001EF C687[50BF]00        <1> 	mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   486 000001F4 808F[9CBF]F0        <1>         or      byte [bx+drv.status+2], 0F0h ; (failure sign)
   487 000001F9 EB14                <1> 	jmp	short L11b
   488                              <1> L11a:	
   489                              <1> 	; LBA validation
   490 000001FB 268A4704            <1> 	mov	al, [es:bx+4] ; Head register upper nibble
   491 000001FF A840                <1> 	test	al, 40h ; LBA bit (bit 6)
   492 00000201 750C                <1> 	jnz	short L11b ; LBA type I/O is OK! (E0h or F0h)
   493                              <1> 	; force CHS type I/O for this drive (A0h or B0h)
   494 00000203 28FF                <1> 	sub	bh, bh
   495 00000205 88D3                <1> 	mov	bl, dl
   496 00000207 80EB80              <1> 	sub	bl, 80h ; 26/02/2015
   497 0000020A 80A7[9CBF]FE        <1>         and     byte [bx+drv.status+2], 0FEh ; clear bit 0
   498                              <1> 				; bit 0 = LBA ready bit
   499                              <1> 	; 'diskio' procedure will check this bit !
   500                              <1> L11b:
   501 0000020F 3A16[4CBF]          <1> 	cmp	dl, [last_drv] ; 25/12/2014
   502 00000213 7307                <1>         jnb     short L13
   503 00000215 E900FF              <1>         jmp     L10
   504                              <1> L12:
   505                              <1> 	; Restore data registers
   506 00000218 8CC8                <1> 	mov	ax, cs
   507 0000021A 8ED8                <1> 	mov	ds, ax	
   508                              <1> L13:
   509                              <1> 	; 13/12/2014
   510 0000021C 0E                  <1> 	push	cs
   511 0000021D 07                  <1> 	pop	es
   512                              <1> L14:
   513 0000021E B411                <1> 	mov 	ah, 11h
   514 00000220 CD16                <1> 	int 	16h
   515 00000222 7406                <1> 	jz 	short L15 ; no keys in keyboard buffer
   516 00000224 B010                <1> 	mov	al, 10h
   517 00000226 CD16                <1> 	int 	16h
   518 00000228 EBF4                <1> 	jmp 	short L14
   519                              <1> L15:
   520                              <1> ; //////
   521                              <1> 	; 24/11/2014
   522                              <1> 	; 19/11/2014
   523                              <1> 	; 14/11/2014
   524                              <1> 	; Temporary code for disk searching code check
   525                              <1> 	;
   526                              <1> 	; This code will show existing (usable) drives and also
   527                              <1> 	; will show EDD interface support status for hard disks		
   528                              <1> 	; (If status bit 7 is 1, Identify Device info is ready,
   529                              <1> 	; no need to get it again in protected mode...) 
   530                              <1> 	;	
   531                              <1> 	; 13/11/2014
   532 0000022A BB0700              <1> 	mov	bx, 7
   533 0000022D B40E                <1> 	mov	ah, 0Eh
   534 0000022F A0[4EBF]            <1> 	mov	al, [fd0_type]
   535 00000232 20C0                <1> 	and	al, al
   536 00000234 743D                <1> 	jz	short L15a
   537 00000236 88C2                <1> 	mov	dl, al
   538 00000238 B046                <1> 	mov	al, 'F'
   539 0000023A CD10                <1> 	int 	10h
   540 0000023C B044                <1> 	mov	al, 'D'
   541 0000023E CD10                <1> 	int 	10h
   542 00000240 B030                <1> 	mov	al, '0'
   543 00000242 CD10                <1> 	int 	10h
   544 00000244 B020                <1> 	mov	al, ' '
   545 00000246 CD10                <1> 	int	10h
   546 00000248 E8B200              <1> 	call	L15c
   547 0000024B B020                <1> 	mov	al, ' '
   548 0000024D CD10                <1> 	int	10h
   549                              <1> 	;
   550 0000024F A0[4FBF]            <1> 	mov	al, [fd1_type]
   551 00000252 20C0                <1> 	and	al, al
   552 00000254 741D                <1> 	jz	short L15a
   553 00000256 88C2                <1> 	mov	dl, al
   554 00000258 B046                <1> 	mov	al, 'F'
   555 0000025A CD10                <1> 	int 	10h
   556 0000025C B044                <1> 	mov	al, 'D'
   557 0000025E CD10                <1> 	int 	10h
   558 00000260 B031                <1> 	mov	al, '1'
   559 00000262 CD10                <1> 	int 	10h
   560 00000264 B020                <1> 	mov	al, ' '
   561 00000266 CD10                <1> 	int	10h
   562 00000268 E89200              <1> 	call	L15c
   563 0000026B B020                <1> 	mov	al, ' '
   564 0000026D CD10                <1> 	int	10h
   565 0000026F B020                <1> 	mov	al, ' '
   566 00000271 CD10                <1> 	int	10h
   567                              <1> L15a:
   568 00000273 A0[50BF]            <1> 	mov	al, [hd0_type]
   569 00000276 20C0                <1> 	and	al, al
   570 00000278 7479                <1> 	jz	short L15b
   571 0000027A 88C2                <1> 	mov	dl, al
   572 0000027C B048                <1> 	mov	al, 'H'
   573 0000027E CD10                <1> 	int 	10h
   574 00000280 B044                <1> 	mov	al, 'D'
   575 00000282 CD10                <1> 	int 	10h
   576 00000284 B030                <1> 	mov	al, '0'
   577 00000286 CD10                <1> 	int 	10h
   578 00000288 B020                <1> 	mov	al, ' '
   579 0000028A CD10                <1> 	int 	10h
   580 0000028C E86E00              <1> 	call	L15c
   581 0000028F B020                <1> 	mov	al, ' '
   582 00000291 CD10                <1> 	int	10h
   583                              <1> 	;
   584 00000293 A0[51BF]            <1> 	mov	al, [hd1_type]
   585 00000296 20C0                <1> 	and	al, al
   586 00000298 7459                <1> 	jz	short L15b
   587 0000029A 88C2                <1> 	mov	dl, al
   588 0000029C B048                <1> 	mov	al, 'H'
   589 0000029E CD10                <1> 	int 	10h
   590 000002A0 B044                <1> 	mov	al, 'D'
   591 000002A2 CD10                <1> 	int 	10h
   592 000002A4 B031                <1> 	mov	al, '1'
   593 000002A6 CD10                <1> 	int 	10h
   594 000002A8 B020                <1> 	mov	al, ' '
   595 000002AA CD10                <1> 	int 	10h
   596 000002AC E84E00              <1> 	call	L15c
   597 000002AF B020                <1> 	mov	al, ' '
   598 000002B1 CD10                <1> 	int	10h
   599                              <1> 	;
   600 000002B3 A0[52BF]            <1> 	mov	al, [hd2_type]
   601 000002B6 20C0                <1> 	and	al, al
   602 000002B8 7439                <1> 	jz	short L15b
   603 000002BA 88C2                <1> 	mov	dl, al
   604 000002BC B048                <1> 	mov	al, 'H'
   605 000002BE CD10                <1> 	int 	10h
   606 000002C0 B044                <1> 	mov	al, 'D'
   607 000002C2 CD10                <1> 	int 	10h
   608 000002C4 B032                <1> 	mov	al, '2'
   609 000002C6 CD10                <1> 	int 	10h
   610 000002C8 B020                <1> 	mov	al, ' '
   611 000002CA CD10                <1> 	int 	10h
   612 000002CC E82E00              <1> 	call	L15c
   613 000002CF B020                <1> 	mov	al, ' '
   614 000002D1 CD10                <1> 	int	10h
   615                              <1> 	;
   616 000002D3 A0[53BF]            <1> 	mov	al, [hd3_type]
   617 000002D6 20C0                <1> 	and	al, al
   618 000002D8 7419                <1> 	jz	short L15b
   619 000002DA 88C2                <1> 	mov	dl, al
   620 000002DC B048                <1> 	mov	al, 'H'
   621 000002DE CD10                <1> 	int 	10h
   622 000002E0 B044                <1> 	mov	al, 'D'
   623 000002E2 CD10                <1> 	int 	10h
   624 000002E4 B033                <1> 	mov	al, '3'
   625 000002E6 CD10                <1> 	int 	10h
   626 000002E8 B020                <1> 	mov	al, ' '
   627 000002EA CD10                <1> 	int 	10h
   628 000002EC E80E00              <1> 	call	L15c
   629 000002EF B020                <1> 	mov	al, ' '
   630 000002F1 CD10                <1> 	int	10h
   631                              <1> 	;
   632                              <1> L15b:
   633 000002F3 B00D                <1> 	mov	al, 0Dh
   634 000002F5 CD10                <1> 	int 	10h	
   635 000002F7 B00A                <1> 	mov	al, 0Ah
   636 000002F9 CD10                <1> 	int 	10h
   637                              <1> 	;;xor	ah, ah
   638                              <1> 	;;int 	16h	
   639                              <1> 	;
   640 000002FB EB77                <1>         jmp     L16  ; jmp short L16
   641                              <1>         ;
   642                              <1> L15c:
   643 000002FD 88D6                <1> 	mov	dh, dl
   644 000002FF C0EE04              <1> 	shr	dh, 4
   645 00000302 80C630              <1> 	add	dh, 30h
   646 00000305 80E20F              <1> 	and	dl, 15
   647 00000308 80C230              <1> 	add	dl, 30h
   648 0000030B 88F0                <1> 	mov	al, dh
   649 0000030D CD10                <1> 	int	10h
   650 0000030F 88D0                <1> 	mov	al, dl
   651 00000311 CD10                <1> 	int	10h
   652 00000313 C3                  <1> 	retn
   653                              <1> 	;
   654                              <1> 	; end of temporary code for disk searching code check
   655                              <1> 
   656                              <1> ; //////
   657                              <1> 
   658                              <1> set_disk_parms:
   659                              <1> 	; 04/02/2016 (ebx -> bx)
   660                              <1> 	; 10/07/2015
   661                              <1> 	; 14/01/2015
   662                              <1> 	;push	bx
   663 00000314 28FF                <1> 	sub	bh, bh
   664 00000316 8A1E[4BBF]          <1> 	mov	bl, [drv]
   665 0000031A 80FB80              <1> 	cmp	bl, 80h
   666 0000031D 7203                <1> 	jb	short sdp0
   667 0000031F 80EB7E              <1> 	sub	bl, 7Eh
   668                              <1> sdp0:	
   669 00000322 81C3[9ABF]          <1> 	add	bx, drv.status
   670 00000326 C60780              <1>   	mov	byte [bx], 80h ; 'Present' flag
   671                              <1> 	;
   672 00000329 88E8                <1> 	mov	al, ch ; last cylinder (bits 0-7)
   673 0000032B 88CC                <1> 	mov	ah, cl ; 
   674 0000032D C0EC06              <1> 	shr	ah, 6  ; last cylinder (bits 8-9)
   675 00000330 81EB[9ABF]          <1> 	sub	bx, drv.status
   676 00000334 D0E3                <1> 	shl	bl, 1
   677 00000336 81C3[54BF]          <1> 	add	bx, drv.cylinders
   678 0000033A 40                  <1> 	inc	ax  ; convert max. cyl number to cyl count		
   679 0000033B 8907                <1> 	mov	[bx], ax
   680 0000033D 50                  <1> 	push	ax ; ** cylinders
   681 0000033E 81EB[54BF]          <1> 	sub	bx, drv.cylinders
   682 00000342 81C3[62BF]          <1> 	add	bx, drv.heads
   683 00000346 30E4                <1> 	xor	ah, ah
   684 00000348 88F0                <1> 	mov	al, dh ; heads
   685 0000034A 40                  <1> 	inc	ax
   686 0000034B 8907                <1> 	mov	[bx], ax
   687 0000034D 81EB[62BF]          <1>         sub     bx, drv.heads
   688 00000351 81C3[70BF]          <1>         add     bx, drv.spt
   689 00000355 30ED                <1> 	xor	ch, ch
   690 00000357 80E13F              <1> 	and	cl, 3Fh	; sectors (bits 0-6)
   691 0000035A 890F                <1> 	mov	[bx], cx
   692 0000035C 81EB[70BF]          <1>         sub     bx, drv.spt
   693 00000360 D1E3                <1> 	shl	bx, 1
   694 00000362 81C3[7EBF]          <1> 	add	bx, drv.size ; disk size (in sectors)
   695                              <1> 	; LBA size = cylinders * heads * secpertrack
   696 00000366 F7E1                <1> 	mul	cx 
   697 00000368 89C2                <1> 	mov	dx, ax	; heads*spt					
   698 0000036A 58                  <1> 	pop	ax ; ** cylinders
   699 0000036B 48                  <1> 	dec	ax ; 1 cylinder reserved (!?)
   700 0000036C F7E2                <1> 	mul	dx ; cylinders * (heads*spt)		
   701 0000036E 8907                <1> 	mov	[bx], ax
   702 00000370 895702              <1> 	mov	[bx+2], dx
   703                              <1> 	;
   704                              <1> 	;pop	bx
   705 00000373 C3                  <1> 	retn
   706                              <1> 
   707                              <1> ;align 2
   708                              <1> 
   709                              <1> ;cylinders :  dw 0, 0, 0, 0, 0, 0
   710                              <1> ;heads	  :  dw 0, 0, 0, 0, 0, 0
   711                              <1> ;spt	  :  dw 0, 0, 0, 0, 0, 0
   712                              <1> ;disk_size :  dd 0, 0, 0, 0, 0, 0
   713                              <1> 
   714                              <1> ;last_drv:
   715                              <1> ;	db  0
   716                              <1> ;drv_status:
   717                              <1> ;	db  0,0,0,0,0,0
   718                              <1> ;	db 0
   719                              <1> 
   720                              <1> 
   721                              <1> ; End Of DISK I/O SYSTEM STRUCTURE INITIALIZATION /// 06/02/2015
   722                              <1> 
   723                              <1> L16:
   724                                  
   725                                  	; 10/11/2014
   726 00000374 FA                           	cli	; Disable interrupts (clear interrupt flag)
   727                                  		; Reset Interrupt MASK Registers (Master&Slave)
   728                                  	;mov	al, 0FFh	; mask off all interrupts
   729                                  	;out	21h, al		; on master PIC (8259)
   730                                  	;jmp 	$+2  ; (delay)
   731                                  	;out	0A1h, al	; on slave PIC (8259)
   732                                  	;
   733                                  	; Disable NMI 
   734 00000375 B080                    	mov   	al, 80h 
   735 00000377 E670                    	out   	70h, al		; set bit 7 to 1 for disabling NMI
   736                                  	;23/02/2015
   737 00000379 90                      	nop			;
   738                                  	;in	al, 71h		; read in 71h just after writing out to 70h
   739                                  				; for preventing unknown state (!?)
   740                                  	;
   741                                   	; 20/08/2014
   742                                  	; Moving the kernel 64 KB back (to physical address 0)
   743                                  	; DS = CS = 1000h
   744                                  	; 05/11/2014
   745 0000037A 31C0                    	xor	ax, ax
   746 0000037C 8EC0                    	mov	es, ax ; ES = 0
   747                                  	;
   748 0000037E B90040                  	mov	cx, (KEND - KLOAD)/4
   749 00000381 31F6                    	xor	si, si
   750 00000383 31FF                    	xor	di, di
   751 00000385 F366A5                  	rep	movsd
   752                                  	;
   753 00000388 06                      	push	es ; 0
   754 00000389 68[8D03]                	push	L17
   755 0000038C CB                      	retf
   756                                  	;
   757                                  L17:
   758                                  	; Turn off the floppy drive motor
   759 0000038D BAF203                          mov     dx, 3F2h
   760 00000390 EE                              out     dx, al ; 0 ; 31/12/2013
   761                                  
   762                                  	; Enable access to memory above one megabyte
   763                                  L18:
   764 00000391 E464                    	in	al, 64h
   765 00000393 A802                    	test	al, 2
   766 00000395 75FA                            jnz     short L18
   767 00000397 B0D1                    	mov	al, 0D1h	; Write output port
   768 00000399 E664                    	out	64h, al
   769                                  L19:
   770 0000039B E464                    	in	al, 64h
   771 0000039D A802                    	test	al, 2
   772 0000039F 75FA                            jnz     short L19
   773 000003A1 B0DF                    	mov	al, 0DFh	; Enable A20 line
   774 000003A3 E660                    	out	60h, al
   775                                  ;L20:
   776                                  	;
   777                                  	; Load global descriptor table register
   778                                  
   779                                          ;mov     ax, cs
   780                                          ;mov     ds, ax
   781                                  
   782 000003A5 2E0F0116[60BC]                  lgdt    [cs:gdtd]
   783                                  
   784 000003AB 0F20C0                          mov     eax, cr0
   785                                  	; or 	eax, 1
   786 000003AE 40                      	inc     ax
   787 000003AF 0F22C0                  	mov     cr0, eax
   788                                  
   789                                  	; Jump to 32 bit code
   790                                  	
   791 000003B2 66                      	db 66h 			; Prefix for 32-bit
   792 000003B3 EA                      	db 0EAh 		; Opcode for far jump
   793 000003B4 [BA030000]              	dd StartPM 		; Offset to start, 32-bit
   794                                  				; (1000h:StartPM = StartPM + 10000h)
   795 000003B8 0800                    	dw KCODE		; This is the selector for CODE32_DESCRIPTOR,
   796                                  				; assuming that StartPM resides in code32
   797                                  
   798                                  [BITS 32] 
   799                                  
   800                                  StartPM:
   801                                  	; Kernel Base Address = 0 ; 30/12/2013
   802 000003BA 66B81000                	mov ax, KDATA           ; Save data segment identifier
   803 000003BE 8ED8                            mov ds, ax              ; Move a valid data segment into DS register
   804 000003C0 8EC0                           	mov es, ax              ; Move data segment into ES register
   805 000003C2 8EE0                           	mov fs, ax              ; Move data segment into FS register
   806 000003C4 8EE8                          	mov gs, ax              ; Move data segment into GS register
   807 000003C6 8ED0                            mov ss, ax              ; Move data segment into SS register
   808 000003C8 BC00000900                      mov esp, 90000h         ; Move the stack pointer to 090000h
   809                                  
   810                                  clear_bss: ; Clear uninitialized data area
   811                                  	; 11/03/2015
   812 000003CD 31C0                    	xor  eax, eax ; 0
   813 000003CF B9E8070000              	mov  ecx, (bss_end - bss_start)/4
   814                                  	;shr  ecx, 2 ; bss section is already aligned for double words
   815 000003D4 BF[10C20000]            	mov  edi, bss_start	
   816 000003D9 F3AB                    	rep  stosd  		
   817                                  
   818                                  memory_init:
   819                                  	; Initialize memory allocation table and page tables
   820                                  	; 16/11/2014
   821                                  	; 15/11/2014
   822                                  	; 07/11/2014
   823                                  	; 06/11/2014
   824                                  	; 05/11/2014
   825                                  	; 04/11/2014
   826                                  	; 31/10/2014 (Retro UNIX 386 v1 - Beginning) 
   827                                  	;
   828                                  ;	xor	eax, eax
   829                                  ;	xor 	ecx, ecx
   830 000003DB B108                    	mov	cl, 8
   831 000003DD BF00001000              	mov	edi, MEM_ALLOC_TBL	
   832 000003E2 F3AB                    	rep	stosd		   ; clear Memory Allocation Table
   833                                  				   ; for the first 1 MB memory
   834                                  	;
   835 000003E4 668B0D[D4C10000]        	mov	cx, [mem_1m_1k]	   ; Number of contiguous KB between
   836                                  				   ; 1 and 16 MB, max. 3C00h = 15 MB.
   837 000003EB 66C1E902                	shr	cx, 2		   ; convert 1 KB count to 4 KB count
   838 000003EF 890D[80C40000]          	mov	[free_pages], ecx
   839 000003F5 668B15[D6C10000]        	mov	dx, [mem_16m_64k]  ; Number of contiguous 64 KB blocks
   840                                  				   ; between 16 MB and 4 GB.	
   841 000003FC 6609D2                  	or	dx, dx
   842 000003FF 7413                    	jz	short mi_0
   843                                  	;
   844 00000401 6689D0                  	mov	ax, dx
   845 00000404 C1E004                  	shl	eax, 4		   ; 64 KB -> 4 KB (page count)
   846 00000407 0105[80C40000]          	add	[free_pages], eax
   847 0000040D 0500100000              	add	eax, 4096	   ; 16 MB = 4096 pages
   848 00000412 EB07                    	jmp	short mi_1
   849                                  mi_0:
   850 00000414 6689C8                  	mov	ax, cx
   851 00000417 66050001                	add	ax, 256		   ; add 256 pages for the first 1 MB		 
   852                                  mi_1:
   853 0000041B A3[7CC40000]            	mov	[memory_size], eax ; Total available memory in pages
   854                                  				   ; 1 alloc. tbl. bit = 1 memory page
   855                                  				   ; 32 allocation bits = 32 mem. pages   
   856                                  	;
   857 00000420 05FF7F0000              	add	eax, 32767	   ; 32768 memory pages per 1 M.A.T. page 	
   858 00000425 C1E80F                  	shr	eax, 15		   ; ((32768 * x) + y) pages (y < 32768)
   859                                  				   ;  --> x + 1 M.A.T. pages, if y > 0
   860                                  				   ;  --> x M.A.T. pages, if y = 0
   861 00000428 66A3[90C40000]          	mov	[mat_size], ax	   ; Memory Alloc. Table Size in pages		
   862 0000042E C1E00C                  	shl	eax, 12		   ; 1 M.A.T. page = 4096 bytes
   863                                  	;			   ; Max. 32 M.A.T. pages (4 GB memory)
   864 00000431 89C3                    	mov	ebx, eax	   ; M.A.T. size in bytes
   865                                  	; Set/Calculate Kernel's Page Directory Address
   866 00000433 81C300001000            	add	ebx, MEM_ALLOC_TBL
   867 00000439 891D[78C40000]          	mov	[k_page_dir], ebx  ; Kernel's Page Directory address
   868                                  				   ; just after the last M.A.T. page
   869                                  	;
   870 0000043F 83E804                  	sub	eax, 4		   ; convert M.A.T. size to offset value
   871 00000442 A3[88C40000]            	mov	[last_page], eax   ; last page ofset in the M.A.T.
   872                                  	;			   ; (allocation status search must be 
   873                                  				   ; stopped after here)	
   874 00000447 31C0                    	xor	eax, eax
   875 00000449 48                      	dec	eax		   ; FFFFFFFFh (set all bits to 1)	
   876 0000044A 6651                    	push	cx
   877 0000044C C1E905                  	shr	ecx, 5		   ; convert 1 - 16 MB page count to 
   878                                  				   ; count of 32 allocation bits
   879 0000044F F3AB                    	rep	stosd
   880 00000451 6659                    	pop	cx
   881 00000453 40                      	inc	eax		   ; 0	
   882 00000454 80E11F                  	and	cl, 31		   ; remain bits
   883 00000457 7412                    	jz	short mi_4
   884 00000459 8907                    	mov	[edi], eax	   ; reset	
   885                                  mi_2:
   886 0000045B 0FAB07                  	bts	[edi], eax	   ; 06/11/2014		
   887 0000045E FEC9                    	dec	cl
   888 00000460 7404                    	jz	short mi_3
   889 00000462 FEC0                    	inc	al
   890 00000464 EBF5                    	jmp	short mi_2
   891                                  mi_3:
   892 00000466 28C0                    	sub	al, al	   	   ; 0
   893 00000468 83C704                  	add	edi, 4		   ; 15/11/2014
   894                                  mi_4:
   895 0000046B 6609D2                  	or	dx, dx		  ; check 16M to 4G memory space	
   896 0000046E 7421                    	jz	short mi_6	  ; max. 16 MB memory, no more...
   897                                  	;	
   898 00000470 B900021000              	mov	ecx, MEM_ALLOC_TBL + 512 ; End of first 16 MB memory
   899                                  	;	
   900 00000475 29F9                    	sub	ecx, edi	  ; displacement (to end of 16 MB)
   901 00000477 7406                    	jz	short mi_5	  ; jump if EDI points to 
   902                                  				  ;         end of first 16 MB	
   903 00000479 D1E9                    	shr	ecx, 1		  ; convert to dword count
   904 0000047B D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   905 0000047D F3AB                    	rep 	stosd		  ; reset all bits for reserved pages
   906                                  				  ; (memory hole under 16 MB)
   907                                  mi_5:
   908 0000047F 6689D1                  	mov	cx, dx		  ; count of 64 KB memory blocks
   909 00000482 D1E9                    	shr	ecx, 1		  ; 1 alloc. dword per 128 KB memory
   910 00000484 9C                      	pushf			  ; 16/11/2014		
   911 00000485 48                      	dec	eax		  ; FFFFFFFFh (set all bits to 1)
   912 00000486 F3AB                    	rep	stosd
   913 00000488 40                      	inc	eax		  ; 0
   914 00000489 9D                      	popf			  ; 16/11/2014
   915 0000048A 7305                    	jnc	short mi_6
   916 0000048C 6648                    	dec	ax		  ; eax = 0000FFFFh
   917 0000048E AB                      	stosd
   918 0000048F 6640                    	inc	ax		  ; 0		
   919                                  mi_6:
   920 00000491 39DF                    	cmp	edi, ebx	  ; check if EDI points to 	
   921 00000493 730A                    	jnb	short mi_7	  ; end of memory allocation table
   922                                  	;			  ; (>= MEM_ALLOC_TBL + 4906) 
   923 00000495 89D9                    	mov	ecx, ebx	  ; end of memory allocation table
   924 00000497 29F9                    	sub	ecx, edi	  ; convert displacement/offset
   925 00000499 D1E9                    	shr	ecx, 1		  ; to dword count 	 		
   926 0000049B D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   927 0000049D F3AB                    	rep 	stosd		  ; reset all remain M.A.T. bits
   928                                  mi_7:
   929                                  	; Reset M.A.T. bits in M.A.T. (allocate M.A.T. pages)
   930 0000049F BA00001000              	mov	edx, MEM_ALLOC_TBL
   931                                  	;sub	ebx, edx	  ; Mem. Alloc. Tbl. size in bytes
   932                                  	;shr	ebx, 12		  ; Mem. Alloc. Tbl. size in pages	
   933 000004A4 668B0D[90C40000]        	mov	cx, [mat_size]	  ; Mem. Alloc. Tbl. size in pages
   934 000004AB 89D7                    	mov	edi, edx
   935 000004AD C1EF0F                  	shr	edi, 15		  ; convert M.A.T. address to
   936                                  				  ; byte offset in M.A.T.
   937                                  				  ; (1 M.A.T. byte points to 
   938                                  				  ;	      32768 bytes)
   939                                  				  ; Note: MEM_ALLOC_TBL address 
   940                                  				  ; must be aligned on 128 KB 
   941                                  				  ; boundary!
   942 000004B0 01D7                    	add	edi, edx	  ; points to M.A.T.'s itself	
   943                                  	; eax = 0
   944 000004B2 290D[80C40000]          	sub	[free_pages], ecx ; 07/11/2014
   945                                  mi_8:
   946 000004B8 0FB307                  	btr	[edi], eax	  ; clear bit 0 to bit x (1 to 31)
   947                                  	;dec	bl
   948 000004BB FEC9                    	dec	cl
   949 000004BD 7404                    	jz	short mi_9
   950 000004BF FEC0                    	inc	al
   951 000004C1 EBF5                    	jmp	short mi_8
   952                                  mi_9:
   953                                  	;
   954                                  	; Reset Kernel's Page Dir. and Page Table bits in M.A.T.
   955                                  	;		(allocate pages for system page tables)
   956                                  
   957                                  	; edx = MEM_ALLOC_TBL
   958 000004C3 8B0D[7CC40000]          	mov	ecx, [memory_size] ; memory size in pages (PTEs)
   959 000004C9 81C1FF030000            	add	ecx, 1023	 ; round up (1024 PTEs per table)	 	
   960 000004CF C1E90A                  	shr	ecx, 10		 ; convert memory page count to 
   961                                  				 ; page table count (PDE count)
   962                                  	;
   963 000004D2 51                      	push	ecx		 ; (**) PDE count (<= 1024)
   964                                  	;
   965 000004D3 41                      	inc	ecx		 ; +1 for kernel page directory	
   966                                  	;
   967 000004D4 290D[80C40000]          	sub	[free_pages], ecx ; 07/11/2014
   968                                  	;
   969 000004DA 8B35[78C40000]          	mov	esi, [k_page_dir] ; Kernel's Page Directory address
   970 000004E0 C1EE0C                  	shr	esi, 12		 ; convert to page number
   971                                  mi_10:
   972 000004E3 89F0                    	mov	eax, esi	 ; allocation bit offset		 
   973 000004E5 89C3                    	mov	ebx, eax
   974 000004E7 C1EB03                  	shr	ebx, 3		 ; convert to alloc. byte offset
   975 000004EA 80E3FC                  	and	bl,  0FCh	 ; clear bit 0 and bit 1
   976                                  				 ;   to align on dword boundary
   977 000004ED 83E01F                  	and	eax, 31		 ; set allocation bit position 
   978                                  				 ;  (bit 0 to bit 31)
   979                                  	;
   980 000004F0 01D3                    	add	ebx, edx	 ; offset in M.A.T. + M.A.T. address 
   981                                  	;
   982 000004F2 0FB303                  	btr 	[ebx], eax	 ; reset relevant bit (0 to 31)
   983                                  	;
   984 000004F5 46                      	inc	esi		 ; next page table
   985 000004F6 E2EB                    	loop	mi_10		 ; allocate next kernel page table 
   986                                  				 ; (ecx = page table count + 1)		
   987                                  	;
   988 000004F8 59                      	pop	ecx		 ; (**) PDE count (= pg. tbl. count)
   989                                  	;
   990                                  	; Initialize Kernel Page Directory and Kernel Page Tables
   991                                  	;
   992                                  	; Initialize Kernel's Page Directory
   993 000004F9 8B3D[78C40000]          	mov	edi, [k_page_dir]
   994 000004FF 89F8                    	mov	eax, edi
   995 00000501 0C03                    	or	al, PDE_A_PRESENT + PDE_A_WRITE
   996                                  		     	      ; supervisor + read&write + present
   997 00000503 89CA                    	mov	edx, ecx 	; (**) PDE count (= pg. tbl. count)	
   998                                  mi_11:
   999 00000505 0500100000              	add	eax, 4096	; Add page size (PGSZ)
  1000                                  			        ; EAX points to next page table
  1001 0000050A AB                      	stosd
  1002 0000050B E2F8                    	loop	mi_11
  1003 0000050D 29C0                    	sub	eax, eax	; Empty PDE
  1004 0000050F 66B90004                	mov	cx, 1024	; Entry count (PGSZ/4)
  1005 00000513 29D1                    	sub	ecx, edx
  1006 00000515 7402                    	jz	short mi_12
  1007 00000517 F3AB                    	rep	stosd 		; clear remain (empty) PDEs
  1008                                  	;
  1009                                  	; Initialization of Kernel's Page Directory is OK, here.
  1010                                  mi_12:
  1011                                  	; Initialize Kernel's Page Tables
  1012                                  	;
  1013                                  	; (EDI points to address of page table 0)
  1014                                  	; eax = 0
  1015 00000519 8B0D[7CC40000]          	mov	ecx, [memory_size] ; memory size in pages
  1016 0000051F 89CA                    	mov	edx, ecx	; (***)
  1017 00000521 B003                    	mov	al, PTE_A_PRESENT + PTE_A_WRITE
  1018                                  			     ; supervisor + read&write + present 	
  1019                                  mi_13:
  1020 00000523 AB                      	stosd
  1021 00000524 0500100000              	add	eax, 4096	
  1022 00000529 E2F8                    	loop	mi_13	
  1023 0000052B 6681E2FF03              	and	dx, 1023	; (***)
  1024 00000530 740B                    	jz	short mi_14
  1025 00000532 66B90004                	mov	cx, 1024	
  1026 00000536 6629D1                  	sub	cx, dx		; from dx (<= 1023) to 1024
  1027 00000539 31C0                    	xor	eax, eax
  1028 0000053B F3AB                    	rep	stosd		; clear remain (empty) PTEs 
  1029                                  				; of the last page table
  1030                                  mi_14:
  1031                                  	;  Initialization of Kernel's Page Tables is OK, here.
  1032                                  	;
  1033 0000053D 89F8                    	mov	eax, edi	; end of the last page table page
  1034                                  			        ; (beginging of user space pages)
  1035 0000053F C1E80F                  	shr	eax, 15		; convert to M.A.T. byte offset
  1036 00000542 24FC                    	and	al, 0FCh	; clear bit 0 and bit 1 for
  1037                                  				; aligning on dword boundary	
  1038                                  	 
  1039 00000544 A3[8CC40000]            	mov	[first_page], eax
  1040 00000549 A3[84C40000]            	mov	[next_page], eax ; The first free page pointer
  1041                                  				 ; for user programs
  1042                                  				 ; (Offset in Mem. Alloc. Tbl.)	
  1043                                  	;
  1044                                  	; Linear/FLAT (1 to 1) memory paging for the kernel is OK, here.
  1045                                  	;
  1046                                  	
  1047                                  	; Enable paging
  1048                                  	;
  1049 0000054E A1[78C40000]                    mov     eax, [k_page_dir]
  1050 00000553 0F22D8                  	mov	cr3, eax
  1051 00000556 0F20C0                  	mov	eax, cr0
  1052 00000559 0D00000080              	or	eax, 80000000h	; set paging bit (bit 31)
  1053 0000055E 0F22C0                  	mov	cr0, eax
  1054                                          ;jmp    KCODE:StartPMP
  1055                                  
  1056 00000561 EA                      	db 0EAh 		; Opcode for far jump
  1057 00000562 [68050000]                      dd StartPMP		; 32 bit offset
  1058 00000566 0800                    	dw KCODE		; kernel code segment descriptor
  1059                                  
  1060                                  
  1061                                  StartPMP:
  1062                                  	; 06/11//2014
  1063                                  	; Clear video page 0
  1064                                  	;
  1065                                  	; Temporary Code
  1066                                  	;
  1067 00000568 B9E8030000              	mov	ecx, 80*25/2
  1068 0000056D BF00800B00              	mov	edi, 0B8000h
  1069                                  	; 30/01/2016
  1070                                  	;xor	eax, eax	; black background, black fore color
  1071 00000572 B800070007              	mov	eax, 07000700h  ; black background, light gray fore color
  1072 00000577 F3AB                    	rep	stosd
  1073                                  	
  1074                                  	; 19/08/2014
  1075                                  	; Kernel Base Address = 0
  1076                                  	; It is mapped to (physically) 0 in the page table.
  1077                                  	; So, here is exactly 'StartPMP' address.
  1078                                  
  1079                                   	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
  1080 00000579 BE[D8C10000]            	mov	esi, starting_msg
  1081                                  	;; 14/08/2015 (kernel version message will appear
  1082                                  	;;	       when protected mode and paging is enabled)
  1083 0000057E BF00800B00              	mov	edi, 0B8000h ; 27/08/2014
  1084 00000583 B40A                    	mov	ah, 0Ah ; Black background, light green forecolor
  1085                                  	; 20/08/2014
  1086 00000585 E87D010000              	call	printk
  1087                                  
  1088                                  	; 'UNIX v7/x86' source code by Robert Nordier (1999)
  1089                                  	; // Set IRQ offsets
  1090                                  	;
  1091                                  	;  Linux (v0.12) source code by Linus Torvalds (1991)
  1092                                  	;
  1093                                  					;; ICW1
  1094 0000058A B011                    	mov	al, 11h			; Initialization sequence
  1095 0000058C E620                    	out	20h, al			; 	8259A-1
  1096                                  	; jmp 	$+2
  1097 0000058E E6A0                    	out	0A0h, al		; 	8259A-2
  1098                                  					;; ICW2
  1099 00000590 B020                    	mov	al, 20h			; Start of hardware ints (20h)
  1100 00000592 E621                    	out	21h, al			;	for 8259A-1
  1101                                  	; jmp 	$+2
  1102 00000594 B028                    	mov	al, 28h			; Start of hardware ints (28h)
  1103 00000596 E6A1                    	out	0A1h, al		; 	for 8259A-2
  1104                                  					;
  1105 00000598 B004                    	mov	al, 04h			;; ICW3
  1106 0000059A E621                    	out	21h, al			; 	IRQ2 of 8259A-1 (master)
  1107                                  	; jmp 	$+2
  1108 0000059C B002                    	mov	al, 02h			; 	is 8259A-2 (slave)
  1109 0000059E E6A1                    	out	0A1h, al		;
  1110                                  					;; ICW4
  1111 000005A0 B001                    	mov	al, 01h	 		;
  1112 000005A2 E621                    	out	21h, al			; 	8086 mode, normal EOI	
  1113                                  	; jmp 	$+2
  1114 000005A4 E6A1                    	out	0A1h, al		;	for both chips.
  1115                                  
  1116                                  	;mov	al, 0FFh	; mask off all interrupts for now
  1117                                  	;out	21h, al
  1118                                  	;; jmp 	$+2
  1119                                  	;out	0A1h, al
  1120                                  
  1121                                  	; 02/04/2015
  1122                                  	; 26/03/2015 System call (INT 30h) modification
  1123                                  	;  DPL = 3 (Interrupt service routine can be called from user mode)			
  1124                                  	;
  1125                                  	;; Linux (v0.12) source code by Linus Torvalds (1991)
  1126                                  	;  setup_idt:
  1127                                  	;
  1128                                          ;; 16/02/2015
  1129                                  	;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
  1130                                  	; 21/08/2014 (timer_int)
  1131 000005A6 BE[6CBC0000]            	mov	esi, ilist
  1132 000005AB 8D3D[10C20000]          	lea	edi, [idt]
  1133                                  	; 26/03/2015
  1134 000005B1 B930000000              	mov	ecx, 48		; 48 hardware interrupts (INT 0 to INT 2Fh)
  1135                                  	; 02/04/2015
  1136 000005B6 BB00000800              	mov	ebx,  80000h
  1137                                  rp_sidt1:
  1138 000005BB AD                      	lodsd
  1139 000005BC 89C2                    	mov	edx, eax
  1140 000005BE 66BA008E                	mov	dx, 8E00h
  1141 000005C2 6689C3                  	mov	bx, ax
  1142 000005C5 89D8                    	mov	eax, ebx	; /* selector = 0x0008 = cs */
  1143                                         			        ; /* interrupt gate - dpl=0, present */
  1144 000005C7 AB                      	stosd	; selector & offset bits 0-15 	
  1145 000005C8 89D0                    	mov	eax, edx
  1146 000005CA AB                      	stosd	; attributes & offset bits 16-23
  1147 000005CB E2EE                    	loop	rp_sidt1
  1148 000005CD B110                    	mov	cl, 16        ; 16 software interrupts (INT 30h to INT 3Fh)
  1149                                  rp_sidt2:
  1150 000005CF AD                      	lodsd
  1151 000005D0 21C0                    	and	eax, eax
  1152 000005D2 7413                    	jz	short rp_sidt3
  1153 000005D4 89C2                    	mov	edx, eax
  1154 000005D6 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
  1155 000005DA 6689C3                  	mov	bx, ax
  1156 000005DD 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
  1157 000005DF AB                      	stosd
  1158 000005E0 89D0                    	mov	eax, edx
  1159 000005E2 AB                      	stosd
  1160 000005E3 E2EA                    	loop	rp_sidt2
  1161 000005E5 EB16                    	jmp	short sidt_OK
  1162                                  rp_sidt3:
  1163 000005E7 B8[310A0000]            	mov	eax, ignore_int
  1164 000005EC 89C2                    	mov	edx, eax
  1165 000005EE 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
  1166 000005F2 6689C3                  	mov	bx, ax
  1167 000005F5 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
  1168                                  rp_sidt4:
  1169 000005F7 AB                      	stosd
  1170 000005F8 92                      	xchg	eax, edx
  1171 000005F9 AB                      	stosd
  1172 000005FA 92                      	xchg	edx, eax
  1173 000005FB E2FA                    	loop	rp_sidt4
  1174                                  sidt_OK: 
  1175 000005FD 0F011D[66BC0000]        	lidt 	[idtd]
  1176                                  	;
  1177                                  	; TSS descriptor setup ; 24/03/2015
  1178 00000604 B8[10C40000]            	mov	eax, task_state_segment
  1179 00000609 66A3[5ABC0000]          	mov	[gdt_tss0], ax
  1180 0000060F C1C010                  	rol	eax, 16
  1181 00000612 A2[5CBC0000]            	mov	[gdt_tss1], al
  1182 00000617 8825[5FBC0000]          	mov	[gdt_tss2], ah
  1183 0000061D 66C705[76C40000]68-     	mov	word [tss.IOPB], tss_end - task_state_segment
  1184 00000625 00                 
  1185                                  		; 
  1186                                  		; IO Map Base address (When this address points
  1187                                  		; to end of the TSS, CPU does not use IO port 
  1188                                  		; permission bit map for RING 3 IO permissions, 
  1189                                  		; access to any IO ports in ring 3 will be forbidden.)
  1190                                   		;
  1191                                  	;mov	[tss.esp0], esp ; TSS offset 4
  1192                                  	;mov	word [tss.ss0], KDATA ; TSS offset 8 (SS)
  1193 00000626 66B82800                   	mov	ax, TSS  ; It is needed when an interrupt 
  1194                                  			 ; occurs (or a system call -software INT- is requested)
  1195                                  			 ; while cpu running in ring 3 (in user mode).				
  1196                                  			 ; (Kernel stack pointer and segment will be loaded
  1197                                  			 ; from offset 4 and 8 of the TSS, by the CPU.)	 
  1198 0000062A 0F00D8                  	ltr	ax  ; Load task register
  1199                                  	;
  1200                                  esp0_set0:
  1201                                  	; 30/07/2015
  1202 0000062D 8B0D[7CC40000]          	mov 	ecx, [memory_size] ; memory size in pages
  1203 00000633 C1E10C                  	shl 	ecx, 12 ; convert page count to byte count
  1204 00000636 81F900004000            	cmp	ecx, CORE ; beginning of user's memory space (400000h)
  1205                                  			  ; (kernel mode virtual address)
  1206 0000063C 7605                    	jna	short esp0_set1
  1207                                  	;
  1208                                  	; If available memory > CORE (end of the 1st 4 MB)
  1209                                  	; set stack pointer to CORE
  1210                                  	;(Because, PDE 0 is reserved for kernel space in user's page directory)
  1211                                  	;(PDE 0 points to page table of the 1st 4 MB virtual address space)
  1212 0000063E B900004000              	mov	ecx, CORE
  1213                                  esp0_set1:
  1214 00000643 89CC                    	mov	esp, ecx ; top of kernel stack (**tss.esp0**)
  1215                                  esp0_set_ok:
  1216                                  	; 30/07/2015 (**tss.esp0**) 
  1217 00000645 8925[14C40000]          	mov	[tss.esp0], esp
  1218 0000064B 66C705[18C40000]10-             mov     word [tss.ss0], KDATA
  1219 00000653 00                 
  1220                                  	; 14/08/2015
  1221                                  	; 10/11/2014 (Retro UNIX 386 v1 - Erdogan Tan)
  1222                                  	;
  1223                                  	;cli	; Disable interrupts (for CPU)
  1224                                  	;    (CPU will not handle hardware interrupts, except NMI!)
  1225                                  	;
  1226 00000654 30C0                    	xor	al, al		; Enable all hardware interrupts!
  1227 00000656 E621                    	out	21h, al		; (IBM PC-AT compatibility)
  1228 00000658 EB00                    	jmp 	$+2		; (All conventional PC-AT hardware
  1229 0000065A E6A1                    	out	0A1h, al	;  interrupts will be in use.)	
  1230                                  				; (Even if related hardware component
  1231                                  				;  does not exist!)
  1232                                  	; Enable NMI 
  1233 0000065C B07F                    	mov	al, 7Fh		; Clear bit 7 to enable NMI (again)
  1234 0000065E E670                    	out  	70h, al
  1235                                  	; 23/02/2015
  1236 00000660 90                      	nop
  1237 00000661 E471                    	in	al, 71h		; read in 71h just after writing out to 70h
  1238                                  				; for preventing unknown state (!?)
  1239                                  	;
  1240                                  	; Only a NMI can occur here... (Before a 'STI' instruction)
  1241                                  	;
  1242                                  	; 02/09/2014
  1243 00000663 6631DB                  	xor	bx, bx
  1244 00000666 66BA0002                	mov	dx, 0200h	; Row 2, column 0  ; 07/03/2015
  1245 0000066A E8DC110000              	call	_set_cpos	; 24/01/2016
  1246                                  	;
  1247                                  	; 06/11/2014
  1248 0000066F E8BD120000              	call	memory_info
  1249                                  	; 14/08/2015
  1250                                  	;call getch ; 28/02/2015
  1251                                  drv_init:
  1252 00000674 FB                      	sti	; Enable Interrupts 
  1253                                  	; 06/02/2015
  1254 00000675 8B15[50BF0000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
  1255 0000067B 668B1D[4EBF0000]        	mov	bx, [fd0_type] ; fd0, fd1
  1256                                  	; 22/02/2015
  1257 00000682 6621DB                  	and	bx, bx
  1258 00000685 751B                    	jnz	short di1
  1259                                  	;
  1260 00000687 09D2                    	or 	edx, edx
  1261 00000689 7529                    	jnz	short di2
  1262                                  	;
  1263                                  setup_error:
  1264 0000068B BE[9FC00000]            	mov 	esi, setup_error_msg
  1265                                  psem:	
  1266 00000690 AC                      	lodsb
  1267 00000691 08C0                    	or	al, al
  1268                                  	;jz	short haltx ; 22/02/2015
  1269 00000693 7426                    	jz	short di3
  1270 00000695 56                      	push	esi
  1271 00000696 31DB                    	xor	ebx, ebx ; 0
  1272                                  			; Video page 0 (bl=0)
  1273 00000698 B407                    	mov	ah, 07h ; Black background, 
  1274                                  			; light gray forecolor
  1275 0000069A E818110000              	call	WRITE_TTY
  1276 0000069F 5E                      	pop	esi
  1277 000006A0 EBEE                    	jmp	short psem
  1278                                  
  1279                                  di1:
  1280                                  	; supress 'jmp short T6'
  1281                                  	;  (activate fdc motor control code)
  1282 000006A2 66C705[88070000]90-     	mov	word [T5], 9090h ; nop
  1283 000006AA 90                 
  1284                                  	;
  1285                                  	;mov	ax, int_0Eh	; IRQ 6 handler
  1286                                  	;mov	di, 0Eh*4	; IRQ 6 vector
  1287                                  	;stosw
  1288                                  	;mov 	ax, cs
  1289                                  	;stosw
  1290                                  	;; 16/02/2015
  1291                                          ;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
  1292                                  	;
  1293 000006AB E8DF210000              	CALL	DSKETTE_SETUP	; Initialize Floppy Disks
  1294                                  	;
  1295 000006B0 09D2                    	or	edx, edx
  1296 000006B2 7407                            jz      short di3
  1297                                  di2:
  1298 000006B4 E81B220000              	call   	DISK_SETUP	; Initialize Fixed Disks
  1299 000006B9 72D0                            jc      short setup_error
  1300                                  di3:
  1301 000006BB E845120000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
  1302                                  	;
  1303 000006C0 E8C5B40000              	call	display_disks ; 07/03/2015  (Temporary)
  1304                                  ;haltx:
  1305                                  	; 14/08/2015
  1306                                  	;call	getch ; 22/02/2015
  1307                                  	;sti	; Enable interrupts (for CPU)
  1308                                  ;	; 29/01/2016
  1309                                  ;	sub	ah, ah ;  read time count
  1310                                  ;	call	int1Ah
  1311                                  ;	mov	edx, ecx ; 18.2 * seconds
  1312                                  ;md_info_msg_wait1:
  1313                                  ;	; 29/01/2016
  1314                                  ;	mov	ah, 1
  1315                                  ;	call	int16h
  1316                                  ;	jz	short md_info_msg_wait2
  1317                                  ;	xor	ah, ah ; 0
  1318                                  ;       call    int16h
  1319                                  ;	jmp 	short md_info_msg_ok
  1320                                  ;md_info_msg_wait2:
  1321                                  ;	sub	ah, ah  ; read time count
  1322                                  ;	call	int1Ah
  1323                                  ;	cmp	edx, ecx ; ; 18.2 * seconds
  1324                                  ;	jna	short md_info_msg_wait3
  1325                                  ;	xchg 	edx, ecx	
  1326                                  ;md_info_msg_wait3:
  1327                                  ;	sub	ecx, edx
  1328                                  ;	cmp	ecx, 127 ; 7 seconds (18.2 * 7)
  1329                                  ;	jb	short md_info_msg_wait1		
  1330                                  ;md_info_msg_ok:
  1331                                  	; 30/06/2015
  1332 000006C5 E846370000              	call	sys_init
  1333                                  	;
  1334                                  	;jmp 	cpu_reset ; 22/02/2015
  1335                                  hang:  
  1336                                  	; 23/02/2015
  1337                                  	;sti			; Enable interrupts
  1338 000006CA F4                      	hlt
  1339                                  	;
  1340                                  	;nop
  1341                                  	;; 03/12/2014
  1342                                  	;; 28/08/2014
  1343                                  	;mov	ah, 11h
  1344                                  	;call	getc
  1345                                  	;jz      _c8
  1346                                  	;
  1347                                  	; 23/02/2015
  1348                                  	; 06/02/2015
  1349                                  	; 07/09/2014
  1350 000006CB 31DB                    	xor	ebx, ebx
  1351 000006CD 8A1D[A8C40000]          	mov	bl, [ptty]	; active_page
  1352 000006D3 89DE                    	mov	esi, ebx
  1353 000006D5 66D1E6                  	shl 	si, 1
  1354 000006D8 81C6[AAC40000]          	add	esi, ttychr
  1355 000006DE 668B06                  	mov	ax, [esi]
  1356 000006E1 6621C0                  	and	ax, ax
  1357                                  	;jz	short _c8
  1358 000006E4 74E4                    	jz	short hang
  1359 000006E6 66C7060000              	mov	word [esi], 0
  1360 000006EB 80FB03                  	cmp	bl, 3		; Video page 3
  1361                                  	;jb	short _c8
  1362 000006EE 72DA                    	jb	short hang
  1363                                  	;	
  1364                                  	; 02/09/2014
  1365 000006F0 B40E                    	mov	ah, 0Eh		; Yellow character 
  1366                                  				; on black background
  1367                                  	; 07/09/2014
  1368                                  nxtl:
  1369 000006F2 6653                    	push	bx
  1370                                  	;
  1371                                  	;xor	bx, bx		; bl = 0 (video page 0)
  1372                                  				; bh = 0 (video mode)
  1373                                  				; Retro UNIX 386 v1 - Video Mode 0
  1374                                  				; (PC/AT Video Mode 3 - 80x25 Alpha.)
  1375 000006F4 6650                    	push	ax
  1376 000006F6 E8BC100000              	call 	WRITE_TTY
  1377 000006FB 6658                    	pop	ax
  1378 000006FD 665B                    	pop	bx ; 07/09/2014
  1379 000006FF 3C0D                    	cmp	al, 0Dh		; carriage return (enter)
  1380                                  	;jne	short _c8
  1381 00000701 75C7                    	jne	short hang
  1382 00000703 B00A                    	mov	al, 0Ah		; next line
  1383 00000705 EBEB                    	jmp	short nxtl
  1384                                  	
  1385                                  ;_c8:
  1386                                  ;	; 25/08/2014
  1387                                  ;	cli				; Disable interrupts
  1388                                  ;	mov	al, [scounter + 1]
  1389                                  ;	and	al, al
  1390                                  ;	jnz	hang
  1391                                  ;	call	rtc_p
  1392                                  ;	jmp     hang
  1393                                  
  1394                                  
  1395                                  	; 27/08/2014
  1396                                  	; 20/08/2014
  1397                                  printk:
  1398                                          ;mov    edi, [scr_row]
  1399                                  pkl:
  1400 00000707 AC                      	lodsb
  1401 00000708 08C0                    	or 	al, al
  1402 0000070A 7404                    	jz	short pkr
  1403 0000070C 66AB                    	stosw
  1404 0000070E EBF7                    	jmp	short pkl
  1405                                  pkr:
  1406 00000710 C3                      	retn
  1407                                  
  1408                                  ; 25/07/2015
  1409                                  ; 14/05/2015 (multi tasking -time sharing- 'clock', x_timer)
  1410                                  ; 17/02/2015
  1411                                  ; 06/02/2015 (unix386.s)
  1412                                  ; 11/12/2014 - 22/12/2014 (dsectrm2.s) 
  1413                                  ;
  1414                                  ; IBM PC-XT Model 286 Source Code - BIOS2.ASM (06/10/85)
  1415                                  ;
  1416                                  ;-- HARDWARE INT  08 H - ( IRQ LEVEL 0 ) ---------------------------------------
  1417                                  ;	THIS ROUTINE HANDLES THE TIMER INTERRUPT FROM FROM CHANNEL 0 OF        :
  1418                                  ;	THE 8254 TIMER.  INPUT FREQUENCY IS 1.19318 MHZ AND THE DIVISOR        :
  1419                                  ;	IS 65536, RESULTING IN APPROXIMATELY 18.2 INTERRUPTS EVERY SECOND.     :
  1420                                  ;									       :
  1421                                  ;	THE INTERRUPT HANDLER MAINTAINS A COUNT (40:6C) OF INTERRUPTS SINCE    :
  1422                                  ;	POWER ON TIME, WHICH MAY BE USED TO ESTABLISH TIME OF DAY.	       :
  1423                                  ;	THE INTERRUPT HANDLER ALSO DECREMENTS THE MOTOR CONTROL COUNT (40:40)  :
  1424                                  ;	OF THE DISKETTE, AND WHEN IT EXPIRES, WILL TURN OFF THE 	       :
  1425                                  ;	DISKETTE MOTOR(s), AND RESET THE MOTOR RUNNING FLAGS.		       :
  1426                                  ;	THE INTERRUPT HANDLER WILL ALSO INVOKE A USER ROUTINE THROUGH	       :
  1427                                  ;	INTERRUPT 1CH AT EVERY TIME TICK.  THE USER MUST CODE A 	       :
  1428                                  ;	ROUTINE AND PLACE THE CORRECT ADDRESS IN THE VECTOR TABLE.	       :
  1429                                  ;-------------------------------------------------------------------------------
  1430                                  ;
  1431                                  
  1432                                  timer_int:	; IRQ 0
  1433                                  ;int_08h:	; Timer
  1434                                  	; 14/10/2015
  1435                                  	; Here, we are simulating system call entry (for task switch)
  1436                                  	; (If multitasking is enabled, 
  1437                                  	; 'clock' procedure may jump to 'sysrelease')
  1438 00000711 1E                      	push	ds
  1439 00000712 06                      	push	es
  1440 00000713 0FA0                    	push	fs
  1441 00000715 0FA8                    	push	gs
  1442 00000717 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  1443 00000718 66B91000                	mov     cx, KDATA
  1444 0000071C 8ED9                            mov     ds, cx
  1445 0000071E 8EC1                            mov     es, cx
  1446 00000720 8EE1                            mov     fs, cx
  1447 00000722 8EE9                            mov     gs, cx
  1448                                  	;
  1449 00000724 0F20D9                  	mov	ecx, cr3
  1450 00000727 890D[C6070000]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  1451                                  	;
  1452 0000072D 3B0D[78C40000]          	cmp 	ecx, [k_page_dir]
  1453 00000733 741F                    	je	short T3
  1454                                  	;
  1455                                  	; timer interrupt has been occurred while OS is in user mode
  1456 00000735 A3[D8D40000]            	mov 	[u.r0], eax
  1457 0000073A 89E1                    	mov	ecx, esp
  1458 0000073C 83C130                  	add	ecx, ESPACE ; 4 * 12 (stack frame)	
  1459 0000073F 890D[D0D40000]          	mov	[u.sp], ecx ; kernel stack pointer at the start of interrupt
  1460 00000745 8925[D4D40000]          	mov	[u.usp], esp ; kernel stack points to user's registers   
  1461                                  	;
  1462 0000074B 8B0D[78C40000]          	mov	ecx, [k_page_dir]
  1463 00000751 0F22D9                  	mov	cr3, ecx
  1464                                  T3:
  1465 00000754 FB                      	sti				; INTERRUPTS BACK ON
  1466 00000755 66FF05[FCC40000]        	INC	word [TIMER_LOW]	; INCREMENT TIME
  1467 0000075C 7507                    	JNZ	short T4		; GO TO TEST_DAY
  1468 0000075E 66FF05[FEC40000]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
  1469                                  T4:					; TEST_DAY
  1470 00000765 66833D[FEC40000]18      	CMP	word [TIMER_HIGH],018H	; TEST FOR COUNT EQUALING 24 HOURS
  1471 0000076D 7519                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1472 0000076F 66813D[FCC40000]B0-     	CMP	word [TIMER_LOW],0B0H
  1473 00000777 00                 
  1474 00000778 750E                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1475                                  
  1476                                  ;-----	TIMER HAS GONE 24 HOURS
  1477                                  	;;SUB	AX,AX
  1478                                  	;MOV	[TIMER_HIGH],AX
  1479                                  	;MOV	[TIMER_LOW],AX
  1480 0000077A 29C0                    	sub	eax, eax
  1481 0000077C A3[FCC40000]            	mov	[TIMER_LH], eax
  1482                                  	;	
  1483 00000781 C605[00C50000]01        	MOV	byte [TIMER_OFL],1
  1484                                  
  1485                                  ;-----	TEST FOR DISKETTE TIME OUT
  1486                                  
  1487                                  T5:
  1488                                  	; 23/12/2014
  1489 00000788 EB1D                    	jmp	short T6		; will be replaced with nop, nop
  1490                                  					; (9090h) if a floppy disk
  1491                                  					; is detected.
  1492                                  	;mov	al,[CS:MOTOR_COUNT]
  1493 0000078A A0[03C50000]            	mov	al, [MOTOR_COUNT]
  1494 0000078F FEC8                    	dec	al
  1495                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
  1496 00000791 A2[03C50000]            	mov	[MOTOR_COUNT], al
  1497                                  	;mov	[ORG_MOTOR_COUNT], al
  1498 00000796 750F                    	JNZ	short T6		; RETURN IF COUNT NOT OUT
  1499 00000798 B0F0                    	mov 	al,0F0h
  1500                                  	;AND	[CS:MOTOR_STATUS],al 	; TURN OFF MOTOR RUNNING BITS
  1501 0000079A 2005[02C50000]          	and	[MOTOR_STATUS], al
  1502                                  	;and	[ORG_MOTOR_STATUS], al
  1503 000007A0 B00C                    	MOV	AL,0CH			; bit 3 = enable IRQ & DMA, 
  1504                                  					; bit 2 = enable controller
  1505                                  					;	1 = normal operation
  1506                                  					;	0 = reset	
  1507                                  					; bit 0, 1 = drive select
  1508                                  					; bit 4-7 = motor running bits 
  1509 000007A2 66BAF203                	MOV	DX,03F2H		; FDC CTL PORT
  1510 000007A6 EE                      	OUT	DX,AL			; TURN OFF THE MOTOR
  1511                                  T6:	
  1512                                  	;inc	word [CS:wait_count]	; 22/12/2014 (byte -> word)
  1513                                  					; TIMER TICK INTERRUPT
  1514                                  	;;inc	word [wait_count] ;;27/02/2015
  1515                                  	;INT	1CH			; TRANSFER CONTROL TO A USER ROUTINE
  1516                                  	;;;;cli
  1517                                  	;call 	u_timer			; TRANSFER CONTROL TO A USER ROUTINE
  1518 000007A7 FF15[C2070000]          	call	[x_timer] ; 14/05/2015
  1519                                  T7:
  1520                                  	; 14/10/2015
  1521 000007AD B020                    	MOV	AL,EOI			; GET END OF INTERRUPT MASK
  1522 000007AF FA                      	CLI				; DISABLE INTERRUPTS TILL STACK CLEARED
  1523 000007B0 E620                    	OUT	INTA00,AL		; END OF INTERRUPT TO 8259 - 1	
  1524                                  	;
  1525 000007B2 A1[C6070000]            	mov 	eax, [cr3reg] 		; previous value/content of cr3 register
  1526 000007B7 0F22D8                   	mov	cr3, eax  ; restore cr3 register content
  1527                                  	;
  1528 000007BA 61                      	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
  1529                                  	;
  1530 000007BB 0FA9                    	pop	gs
  1531 000007BD 0FA1                    	pop	fs
  1532 000007BF 07                      	pop	es
  1533 000007C0 1F                      	pop	ds
  1534 000007C1 CF                      	iretd	; return from interrupt
  1535                                  
  1536                                  
  1537                                  ; ////////////////
  1538                                  
  1539                                  ; 14/05/2015 - Multi tasking 'clock' procedure (sys emt)
  1540                                  x_timer:
  1541 000007C2 [CA070000]              	dd 	u_timer			; 14/05/2015
  1542                                  	;dd	clock
  1543                                  
  1544                                  ; 14/10/2015
  1545 000007C6 00000000                cr3reg: dd 0
  1546                                  
  1547                                  	; 06/02/2015
  1548                                  	; 07/09/2014
  1549                                  	; 21/08/2014
  1550                                  u_timer:
  1551                                  ;timer_int:	; IRQ 0
  1552                                  	; 06/02/2015
  1553                                  	;push	eax
  1554                                  	;push	edx
  1555                                  	;push	ecx
  1556                                  	;push	ebx
  1557                                  	;push	ds
  1558                                  	;push	es
  1559                                  	;mov	eax, KDATA
  1560                                  	;mov	ds, ax
  1561                                  	;mov	es, ax
  1562 000007CA FF05[BEC40000]          	inc	dword [tcount]
  1563 000007D0 BB[EDBF0000]            	mov	ebx, tcountstr + 4
  1564 000007D5 66A1[BEC40000]          	mov	ax, [tcount]
  1565 000007DB B90A000000              	mov	ecx, 10
  1566                                  rp_divtcnt:
  1567 000007E0 31D2                    	xor	edx, edx
  1568 000007E2 F7F1                    	div	ecx
  1569 000007E4 80C230                  	add	dl, 30h
  1570 000007E7 8813                    	mov	[ebx], dl
  1571 000007E9 6609C0                  	or	ax, ax
  1572 000007EC 7403                    	jz	short print_lzero
  1573 000007EE 4B                      	dec	ebx
  1574 000007EF EBEF                    	jmp	short rp_divtcnt
  1575                                  print_lzero:
  1576 000007F1 81FB[E9BF0000]          	cmp	ebx, tcountstr
  1577 000007F7 7606                    	jna	short print_tcount
  1578 000007F9 4B                      	dec	ebx
  1579 000007FA C60330                   	mov	byte [ebx], 30h
  1580 000007FD EBF2                    	jmp	short print_lzero
  1581                                  print_tcount:
  1582 000007FF 56                      	push	esi
  1583 00000800 57                      	push	edi
  1584 00000801 BE[C5BF0000]            	mov	esi, timer_msg ; Timer interrupt message
  1585                                  	; 07/09/2014
  1586 00000806 66BB0100                	mov	bx, 1		; Video page 1
  1587                                  ptmsg:
  1588 0000080A AC                      	lodsb
  1589 0000080B 08C0                    	or	al, al
  1590 0000080D 740F                    	jz	short ptmsg_ok
  1591 0000080F 56                      	push	esi
  1592 00000810 6653                    	push	bx
  1593 00000812 B42F                            mov     ah,  2Fh ; Green background, white forecolor
  1594 00000814 E89E0F0000              	call 	WRITE_TTY
  1595 00000819 665B                    	pop	bx
  1596 0000081B 5E                      	pop	esi
  1597 0000081C EBEC                    	jmp	short ptmsg
  1598                                  	;; 27/08/2014
  1599                                  	;mov     edi, 0B8000h + 0A0h ; Row 1
  1600                                  	;call	printk
  1601                                  	;
  1602                                  ptmsg_ok:
  1603                                  	; 07/09/2014
  1604 0000081E 6631D2                  	xor	dx, dx		; column 0, row 0
  1605 00000821 E825100000              	call	_set_cpos	; set cursor position to 0,0 
  1606                                  	; 23/02/2015
  1607                                  	; 25/08/2014
  1608                                  	;mov	ebx, scounter		; (seconds counter)
  1609                                  	;dec	byte [ebx+1]		; (for reading real time clock)
  1610                                  ;	dec	byte [scounter+1]
  1611                                  ;;	jns	short timer_eoi		; 0 -> 0FFh ?
  1612                                  ;	jns	short u_timer_retn
  1613                                  	; 26/02/2015
  1614                                  ;	call	rtc_p
  1615                                  ;	mov	ebx, scounter		; (seconds counter)
  1616                                  ;	mov	byte [ebx+1], 18	; (18.2 timer ticks per second)
  1617                                  ;	dec 	byte [ebx]		; 19+18+18+18+18 (5)	
  1618                                  ;	jnz	short timer_eoi		; (109 timer ticks in 5 seconds)
  1619                                  ;	jnz	short u_timer_retn ; 06/02/2015
  1620                                  ;	mov	byte [ebx], 5
  1621                                  ;	inc	byte [ebx+1] ; 19
  1622                                  ;;timer_eoi:
  1623                                  ;;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1624                                  ;;	out	20h, al	; 8259 PORT
  1625                                  	;
  1626                                  ;u_timer_retn:  ; 06/02/2015
  1627 00000826 5F                      	pop	edi
  1628 00000827 5E                      	pop	esi
  1629                                  	;pop	es
  1630                                  	;pop	ds
  1631                                  	;pop	ebx
  1632                                  	;pop	ecx
  1633                                  	;pop	edx
  1634                                  	;pop	eax
  1635                                  	;iret
  1636 00000828 C3                      	retn	; 06/02/2015
  1637                                  
  1638                                  	; 28/08/2014
  1639                                  irq0:
  1640 00000829 6A00                            push 	dword 0
  1641 0000082B EB48                    	jmp	short which_irq
  1642                                  irq1:
  1643 0000082D 6A01                            push 	dword 1
  1644 0000082F EB44                    	jmp	short which_irq
  1645                                  irq2:
  1646 00000831 6A02                            push 	dword 2
  1647 00000833 EB40                    	jmp	short which_irq
  1648                                  irq3:
  1649                                  	; 20/11/2015
  1650                                  	; 24/10/2015
  1651 00000835 2EFF15[EFB40000]        	call	dword [cs:com2_irq3]
  1652 0000083C 6A03                    	push 	dword 3
  1653 0000083E EB35                    	jmp	short which_irq
  1654                                  irq4:
  1655                                  	; 20/11/2015
  1656                                  	; 24/10/2015
  1657 00000840 2EFF15[EBB40000]        	call	dword [cs:com1_irq4]
  1658 00000847 6A04                            push 	dword 4
  1659 00000849 EB2A                    	jmp	short which_irq
  1660                                  irq5:
  1661 0000084B 6A05                            push 	dword 5
  1662 0000084D EB26                    	jmp	short which_irq
  1663                                  irq6:
  1664 0000084F 6A06                            push 	dword 6
  1665 00000851 EB22                    	jmp	short which_irq
  1666                                  irq7:
  1667 00000853 6A07                            push 	dword 7
  1668 00000855 EB1E                    	jmp	short which_irq
  1669                                  irq8:
  1670 00000857 6A08                            push 	dword 8
  1671 00000859 EB1A                    	jmp	short which_irq
  1672                                  irq9:
  1673 0000085B 6A09                            push 	dword 9
  1674 0000085D EB16                    	jmp	short which_irq
  1675                                  irq10:
  1676 0000085F 6A0A                            push 	dword 10
  1677 00000861 EB12                    	jmp	short which_irq
  1678                                  irq11:
  1679 00000863 6A0B                            push 	dword 11
  1680 00000865 EB0E                    	jmp	short which_irq
  1681                                  irq12:
  1682 00000867 6A0C                            push 	dword 12
  1683 00000869 EB0A                    	jmp	short which_irq
  1684                                  irq13:
  1685 0000086B 6A0D                            push 	dword 13
  1686 0000086D EB06                    	jmp	short which_irq
  1687                                  irq14:
  1688 0000086F 6A0E                            push 	dword 14
  1689 00000871 EB02                    	jmp	short which_irq
  1690                                  irq15:
  1691 00000873 6A0F                            push 	dword 15
  1692                                  	;jmp	short which_irq
  1693                                  
  1694                                  	; 19/10/2015
  1695                                  	; 29/08/2014
  1696                                  	; 21/08/2014
  1697                                  which_irq:
  1698 00000875 870424                  	xchg	eax, [esp]  ; 28/08/2014
  1699 00000878 53                      	push	ebx
  1700 00000879 56                      	push	esi
  1701 0000087A 57                      	push	edi
  1702 0000087B 1E                      	push 	ds
  1703 0000087C 06                      	push 	es
  1704                                  	;
  1705 0000087D 88C3                    	mov	bl, al
  1706                                  	;
  1707 0000087F B810000000              	mov	eax, KDATA
  1708 00000884 8ED8                    	mov	ds, ax
  1709 00000886 8EC0                    	mov	es, ax
  1710                                  	; 19/10/2015
  1711 00000888 FC                      	cld
  1712                                          ; 27/08/2014
  1713 00000889 8105[A8BF0000]A000-             add     dword [scr_row], 0A0h
  1714 00000891 0000               
  1715                                  	;
  1716 00000893 B417                    	mov	ah, 17h	; blue (1) background, 
  1717                                  			; light gray (7) forecolor
  1718 00000895 8B3D[A8BF0000]                  mov     edi, [scr_row]
  1719 0000089B B049                    	mov	al, 'I'
  1720 0000089D 66AB                    	stosw
  1721 0000089F B052                    	mov	al, 'R'
  1722 000008A1 66AB                    	stosw
  1723 000008A3 B051                    	mov	al, 'Q'
  1724 000008A5 66AB                    	stosw
  1725 000008A7 B020                    	mov	al, ' '
  1726 000008A9 66AB                    	stosw
  1727 000008AB 88D8                    	mov	al, bl
  1728 000008AD 3C0A                    	cmp	al, 10
  1729 000008AF 7208                    	jb	short iix
  1730 000008B1 B031                    	mov	al, '1'
  1731 000008B3 66AB                    	stosw
  1732 000008B5 88D8                    	mov	al, bl
  1733 000008B7 2C0A                    	sub	al, 10
  1734                                  iix:
  1735 000008B9 0430                    	add	al, '0'
  1736 000008BB 66AB                    	stosw
  1737 000008BD B020                    	mov	al, ' '
  1738 000008BF 66AB                    	stosw
  1739 000008C1 B021                    	mov	al, '!'
  1740 000008C3 66AB                    	stosw
  1741 000008C5 B020                    	mov	al, ' '
  1742 000008C7 66AB                    	stosw
  1743                                  	; 23/02/2015
  1744 000008C9 80FB07                  	cmp	bl, 7 ; check for IRQ 8 to IRQ 15 
  1745 000008CC 0F868D010000            	jna	iiret
  1746 000008D2 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1747 000008D4 E6A0                    	out	0A0h, al ; the 2nd 8259
  1748 000008D6 E984010000              	jmp     iiret
  1749                                  	;
  1750                                  	; 22/08/2014
  1751                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1752                                  	;out	20h, al	; 8259 PORT
  1753                                  	;
  1754                                  	;pop	es
  1755                                  	;pop	ds
  1756                                  	;pop	edi
  1757                                  	;pop	esi
  1758                                  	;pop	ebx
  1759                                  	;pop 	eax
  1760                                  	;iret
  1761                                  
  1762                                  	; 02/04/2015
  1763                                  	; 25/08/2014
  1764                                  exc0:
  1765 000008DB 6A00                            push 	dword 0
  1766 000008DD E990000000                      jmp     cpu_except
  1767                                  exc1:
  1768 000008E2 6A01                            push 	dword 1
  1769 000008E4 E989000000                      jmp     cpu_except
  1770                                  exc2:
  1771 000008E9 6A02                            push 	dword 2
  1772 000008EB E982000000                      jmp     cpu_except
  1773                                  exc3:
  1774 000008F0 6A03                            push 	dword 3
  1775 000008F2 EB7E                            jmp     cpu_except
  1776                                  exc4:
  1777 000008F4 6A04                            push 	dword 4
  1778 000008F6 EB7A                            jmp     cpu_except
  1779                                  exc5:
  1780 000008F8 6A05                            push 	dword 5
  1781 000008FA EB76                            jmp     cpu_except
  1782                                  exc6:
  1783 000008FC 6A06                            push 	dword 6
  1784 000008FE EB72                            jmp     cpu_except
  1785                                  exc7:
  1786 00000900 6A07                            push 	dword 7
  1787 00000902 EB6E                            jmp     cpu_except
  1788                                  exc8:
  1789                                  	; [esp] = Error code
  1790 00000904 6A08                            push 	dword 8
  1791 00000906 EB5C                            jmp     cpu_except_en
  1792                                  exc9:
  1793 00000908 6A09                            push 	dword 9
  1794 0000090A EB66                            jmp     cpu_except
  1795                                  exc10:
  1796                                  	; [esp] = Error code
  1797 0000090C 6A0A                            push 	dword 10
  1798 0000090E EB54                            jmp     cpu_except_en
  1799                                  exc11:
  1800                                  	; [esp] = Error code
  1801 00000910 6A0B                            push 	dword 11
  1802 00000912 EB50                            jmp     cpu_except_en
  1803                                  exc12:
  1804                                  	; [esp] = Error code
  1805 00000914 6A0C                            push 	dword 12
  1806 00000916 EB4C                            jmp     cpu_except_en
  1807                                  exc13:
  1808                                  	; [esp] = Error code
  1809 00000918 6A0D                            push 	dword 13
  1810 0000091A EB48                            jmp     cpu_except_en
  1811                                  exc14:
  1812                                  	; [esp] = Error code
  1813 0000091C 6A0E                            push 	dword 14
  1814 0000091E EB44                    	jmp	short cpu_except_en
  1815                                  exc15:
  1816 00000920 6A0F                            push 	dword 15
  1817 00000922 EB4E                            jmp     cpu_except
  1818                                  exc16:
  1819 00000924 6A10                            push 	dword 16
  1820 00000926 EB4A                            jmp     cpu_except
  1821                                  exc17:
  1822                                  	; [esp] = Error code
  1823 00000928 6A11                            push 	dword 17
  1824 0000092A EB38                    	jmp	short cpu_except_en
  1825                                  exc18:
  1826 0000092C 6A12                            push 	dword 18
  1827 0000092E EB42                    	jmp	short cpu_except
  1828                                  exc19:
  1829 00000930 6A13                            push 	dword 19
  1830 00000932 EB3E                    	jmp	short cpu_except
  1831                                  exc20:
  1832 00000934 6A14                            push 	dword 20
  1833 00000936 EB3A                    	jmp	short cpu_except
  1834                                  exc21:
  1835 00000938 6A15                            push 	dword 21
  1836 0000093A EB36                    	jmp	short cpu_except
  1837                                  exc22:
  1838 0000093C 6A16                            push 	dword 22
  1839 0000093E EB32                    	jmp	short cpu_except
  1840                                  exc23:
  1841 00000940 6A17                            push 	dword 23
  1842 00000942 EB2E                    	jmp	short cpu_except
  1843                                  exc24:
  1844 00000944 6A18                            push 	dword 24
  1845 00000946 EB2A                    	jmp	short cpu_except
  1846                                  exc25:
  1847 00000948 6A19                            push 	dword 25
  1848 0000094A EB26                    	jmp	short cpu_except
  1849                                  exc26:
  1850 0000094C 6A1A                            push 	dword 26
  1851 0000094E EB22                    	jmp	short cpu_except
  1852                                  exc27:
  1853 00000950 6A1B                            push 	dword 27
  1854 00000952 EB1E                    	jmp	short cpu_except
  1855                                  exc28:
  1856 00000954 6A1C                            push 	dword 28
  1857 00000956 EB1A                    	jmp	short cpu_except
  1858                                  exc29:
  1859 00000958 6A1D                            push 	dword 29
  1860 0000095A EB16                    	jmp	short cpu_except
  1861                                  exc30:
  1862 0000095C 6A1E                            push 	dword 30
  1863 0000095E EB04                    	jmp	short cpu_except_en
  1864                                  exc31:
  1865 00000960 6A1F                            push 	dword 31
  1866 00000962 EB0E                            jmp     short cpu_except
  1867                                  
  1868                                  	; 19/10/2015
  1869                                  	; 19/09/2015
  1870                                  	; 01/09/2015
  1871                                  	; 28/08/2015
  1872                                  	; 28/08/2014
  1873                                  cpu_except_en:
  1874 00000964 87442404                	xchg	eax, [esp+4] ; Error code
  1875 00000968 36A3[A4E10000]          	mov	[ss:error_code], eax
  1876 0000096E 58                      	pop	eax  ; Exception number
  1877 0000096F 870424                  	xchg	eax, [esp]
  1878                                  		; eax = eax before exception
  1879                                  		; [esp] -> exception number
  1880                                  		; [esp+4] -> EIP to return
  1881                                  	; 19/10/2015
  1882                                  	; 19/09/2015
  1883                                  	; 01/09/2015
  1884                                  	; 28/08/2015
  1885                                  	; 29/08/2014
  1886                                  	; 28/08/2014
  1887                                  	; 25/08/2014
  1888                                  	; 21/08/2014
  1889                                  cpu_except:	; CPU Exceptions
  1890 00000972 FC                      	cld
  1891 00000973 870424                  	xchg	eax, [esp] 
  1892                                  		; eax = Exception number
  1893                                  		; [esp] = eax (before exception)	
  1894 00000976 53                      	push	ebx
  1895 00000977 56                      	push	esi
  1896 00000978 57                      	push	edi
  1897 00000979 1E                      	push 	ds
  1898 0000097A 06                      	push 	es
  1899                                  	; 28/08/2015
  1900 0000097B 66BB1000                	mov	bx, KDATA
  1901 0000097F 8EDB                    	mov	ds, bx
  1902 00000981 8EC3                    	mov	es, bx
  1903 00000983 0F20DB                  	mov	ebx, cr3
  1904 00000986 53                      	push	ebx ; (*) page directory
  1905                                  	; 19/10/2015
  1906 00000987 FC                      	cld
  1907                                  	; 25/03/2015
  1908 00000988 8B1D[78C40000]          	mov	ebx, [k_page_dir]
  1909 0000098E 0F22DB                  	mov	cr3, ebx
  1910                                  	; 28/08/2015
  1911 00000991 83F80E                  	cmp	eax, 0Eh ; 14, PAGE FAULT	
  1912 00000994 7512                    	jne	short cpu_except_nfp
  1913 00000996 E83E2A0000              	call	page_fault_handler
  1914 0000099B 21C0                    	and 	eax, eax
  1915 0000099D 0F84B8000000                    jz	iiretp ; 01/09/2015
  1916 000009A3 B80E000000              	mov	eax, 0Eh ; 14
  1917                                  cpu_except_nfp:
  1918                                  	; 02/04/2015
  1919 000009A8 BB[CA060000]            	mov	ebx, hang
  1920 000009AD 875C241C                	xchg	ebx, [esp+28]
  1921                                  		; EIP (points to instruction which faults)
  1922                                  	  	; New EIP (hang)
  1923 000009B1 891D[A8E10000]          	mov	[FaultOffset], ebx
  1924 000009B7 C744242008000000        	mov	dword [esp+32], KCODE ; kernel's code segment
  1925 000009BF 814C242400020000        	or	dword [esp+36], 200h ; enable interrupts (set IF)
  1926                                  	;
  1927 000009C7 88C4                    	mov	ah, al
  1928 000009C9 240F                    	and	al, 0Fh
  1929 000009CB 3C09                    	cmp	al, 9
  1930 000009CD 7602                    	jna	short h1ok
  1931 000009CF 0407                    	add	al, 'A'-':'
  1932                                  h1ok:
  1933 000009D1 D0EC                    	shr	ah, 1
  1934 000009D3 D0EC                    	shr	ah, 1
  1935 000009D5 D0EC                    	shr	ah, 1
  1936 000009D7 D0EC                    	shr	ah, 1
  1937 000009D9 80FC09                  	cmp	ah, 9
  1938 000009DC 7603                    	jna	short h2ok
  1939 000009DE 80C407                  	add	ah, 'A'-':'
  1940                                  h2ok:	
  1941 000009E1 86E0                    	xchg 	ah, al	
  1942 000009E3 66053030                	add	ax, '00'
  1943 000009E7 66A3[00C00000]          	mov	[excnstr], ax
  1944                                  	;
  1945                                  	; 29/08/2014
  1946 000009ED A1[A8E10000]            	mov	eax, [FaultOffset]
  1947 000009F2 51                      	push	ecx
  1948 000009F3 52                      	push	edx
  1949 000009F4 89E3                    	mov	ebx, esp
  1950                                  	; 28/08/2015
  1951 000009F6 B910000000              	mov	ecx, 16	  ; divisor value to convert binary number
  1952                                  			  ; to hexadecimal string
  1953                                  	;mov	ecx, 10	    ; divisor to convert	
  1954                                  			    ; binary number to decimal string
  1955                                  b2d1:
  1956 000009FB 31D2                    	xor	edx, edx
  1957 000009FD F7F1                    	div	ecx
  1958 000009FF 6652                    	push	dx
  1959 00000A01 39C8                    	cmp	eax, ecx
  1960 00000A03 73F6                    	jnb	short b2d1
  1961 00000A05 BF[0BC00000]            	mov	edi, EIPstr ; EIP value
  1962                                  			    ; points to instruction which faults	
  1963                                  	; 28/08/2015
  1964 00000A0A 89C2                    	mov	edx, eax
  1965                                  b2d2:
  1966                                  	;add	al, '0'
  1967 00000A0C 8A82[F9190000]          	mov	al, [edx+hexchrs]
  1968 00000A12 AA                      	stosb		    ; write hexadecimal digit to its place	
  1969 00000A13 39E3                    	cmp	ebx, esp
  1970 00000A15 7606                    	jna	short b2d3
  1971 00000A17 6658                    	pop	ax
  1972 00000A19 88C2                    	mov	dl, al
  1973 00000A1B EBEF                    	jmp	short b2d2
  1974                                  b2d3:
  1975 00000A1D B068                    	mov 	al, 'h' ; 28/08/2015
  1976 00000A1F AA                      	stosb
  1977 00000A20 B020                    	mov	al, 20h	    ; space
  1978 00000A22 AA                      	stosb
  1979 00000A23 30C0                    	xor	al, al	    ; to do it an ASCIIZ string	
  1980 00000A25 AA                      	stosb
  1981                                  	;
  1982 00000A26 5A                      	pop	edx
  1983 00000A27 59                      	pop	ecx
  1984                                  	;
  1985 00000A28 B44F                    	mov	ah, 4Fh	; red (4) background, 
  1986                                  			; white (F) forecolor
  1987 00000A2A BE[F0BF0000]            	mov	esi, exc_msg ; message offset
  1988                                  	;
  1989 00000A2F EB11                    	jmp	short piemsg
  1990                                  	;
  1991                                          ;add    dword [scr_row], 0A0h
  1992                                          ;mov    edi, [scr_row]
  1993                                          ;
  1994                                  	;call 	printk
  1995                                  	;
  1996                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1997                                  	;out	20h, al	; 8259 PORT
  1998                                  	;
  1999                                  	;pop	es
  2000                                  	;pop	ds
  2001                                  	;pop	edi
  2002                                  	;pop	esi
  2003                                  	;pop 	eax
  2004                                  	;iret
  2005                                  	
  2006                                  	; 28/08/2015
  2007                                  	; 23/02/2015
  2008                                  	; 20/08/2014
  2009                                  ignore_int:
  2010 00000A31 50                      	push	eax
  2011 00000A32 53                      	push	ebx ; 23/02/2015
  2012 00000A33 56                      	push	esi
  2013 00000A34 57                      	push	edi
  2014 00000A35 1E                      	push 	ds
  2015 00000A36 06                      	push 	es
  2016                                  	; 28/08/2015
  2017 00000A37 0F20D8                  	mov	eax, cr3
  2018 00000A3A 50                      	push	eax ; (*) page directory
  2019                                  	;
  2020 00000A3B B467                    	mov	ah, 67h	; brown (6) background, 
  2021                                  			; light gray (7) forecolor
  2022 00000A3D BE[B0BF0000]            	mov	esi, int_msg ; message offset
  2023                                  piemsg:
  2024                                          ; 27/08/2014
  2025 00000A42 8105[A8BF0000]A000-             add     dword [scr_row], 0A0h
  2026 00000A4A 0000               
  2027 00000A4C 8B3D[A8BF0000]                  mov     edi, [scr_row]
  2028                                          ;
  2029 00000A52 E8B0FCFFFF              	call 	printk
  2030                                  	;
  2031                                  	; 23/02/2015
  2032 00000A57 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  2033 00000A59 E6A0                    	out	0A0h, al ; the 2nd 8259
  2034                                  iiretp: ; 01/09/2015
  2035                                  	; 28/08/2015
  2036 00000A5B 58                      	pop	eax ; (*) page directory
  2037 00000A5C 0F22D8                  	mov	cr3, eax
  2038                                  	;
  2039                                  iiret:
  2040                                  	; 22/08/2014
  2041 00000A5F B020                    	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  2042 00000A61 E620                    	out	20h, al	; 8259 PORT
  2043                                  	;
  2044 00000A63 07                      	pop	es
  2045 00000A64 1F                      	pop	ds
  2046 00000A65 5F                      	pop	edi
  2047 00000A66 5E                      	pop	esi
  2048 00000A67 5B                      	pop	ebx ; 29/08/2014
  2049 00000A68 58                      	pop 	eax
  2050 00000A69 CF                      	iretd
  2051                                  
  2052                                  	; 26/02/2015
  2053                                  	; 07/09/2014
  2054                                  	; 25/08/2014
  2055                                  rtc_int:       ; Real Time Clock Interrupt (IRQ 8)
  2056                                  	; 22/08/2014
  2057 00000A6A 50                      	push	eax
  2058 00000A6B 53                      	push	ebx ; 29/08/2014
  2059 00000A6C 56                      	push	esi
  2060 00000A6D 57                      	push	edi
  2061 00000A6E 1E                      	push 	ds
  2062 00000A6F 06                      	push 	es
  2063                                  	;
  2064 00000A70 B810000000              	mov	eax, KDATA
  2065 00000A75 8ED8                    	mov	ds, ax
  2066 00000A77 8EC0                    	mov	es, ax
  2067                                  	;
  2068                                  	; 25/08/2014
  2069 00000A79 E884000000              	call	rtc_p
  2070                                  	;
  2071                                  	; 22/02/2015 - dsectpm.s
  2072                                  	; [ source: http://wiki.osdev.org/RTC ]
  2073                                  	; read status register C to complete procedure
  2074                                  	;(it is needed to get a next IRQ 8) 
  2075 00000A7E B00C                    	mov	al, 0Ch ; 
  2076 00000A80 E670                    	out	70h, al ; select register C
  2077 00000A82 90                      	nop
  2078 00000A83 E471                    	in	al, 71h ; just throw away contents
  2079                                  	; 22/02/2015
  2080 00000A85 B020                    	MOV	AL,EOI		; END OF INTERRUPT
  2081 00000A87 E6A0                    	OUT	INTB00,AL	; FOR CONTROLLER #2
  2082                                  	;
  2083 00000A89 EBD4                    	jmp	short iiret	
  2084                                  
  2085                                  	; 22/08/2014
  2086                                  	; IBM PC/AT BIOS source code ----- 10/06/85 (bios.asm)
  2087                                  	; (INT 1Ah)
  2088                                  	;; Linux (v0.12) source code (main.c) by Linus Torvalds (1991)
  2089                                  time_of_day:
  2090 00000A8B E831330000              	call	UPD_IPR			; WAIT TILL UPDATE NOT IN PROGRESS
  2091 00000A90 726F                            jc      short rtc_retn 
  2092 00000A92 B000                    	mov	al, CMOS_SECONDS
  2093 00000A94 E843330000              	call	CMOS_READ
  2094 00000A99 A2[EEC40000]            	mov	[time_seconds], al 
  2095 00000A9E B002                    	mov	al, CMOS_MINUTES
  2096 00000AA0 E837330000              	call	CMOS_READ
  2097 00000AA5 A2[EFC40000]            	mov	[time_minutes], al 
  2098 00000AAA B004                    	mov	al, CMOS_HOURS
  2099 00000AAC E82B330000              	call	CMOS_READ
  2100 00000AB1 A2[F0C40000]                    mov     [time_hours], al
  2101 00000AB6 B006                    	mov	al, CMOS_DAY_WEEK 
  2102 00000AB8 E81F330000              	call	CMOS_READ
  2103 00000ABD A2[F1C40000]            	mov	[date_wday], al
  2104 00000AC2 B007                     	mov	al, CMOS_DAY_MONTH
  2105 00000AC4 E813330000              	call	CMOS_READ
  2106 00000AC9 A2[F2C40000]            	mov	[date_day], al
  2107 00000ACE B008                    	mov	al, CMOS_MONTH
  2108 00000AD0 E807330000              	call	CMOS_READ
  2109 00000AD5 A2[F3C40000]            	mov	[date_month], al
  2110 00000ADA B009                    	mov	al, CMOS_YEAR
  2111 00000ADC E8FB320000              	call	CMOS_READ
  2112 00000AE1 A2[F4C40000]            	mov	[date_year], al
  2113 00000AE6 B032                    	mov	al, CMOS_CENTURY
  2114 00000AE8 E8EF320000              	call	CMOS_READ
  2115 00000AED A2[F5C40000]            	mov	[date_century], al
  2116                                  	;
  2117 00000AF2 B000                    	mov	al, CMOS_SECONDS
  2118 00000AF4 E8E3320000              	call 	CMOS_READ
  2119 00000AF9 3A05[EEC40000]          	cmp	al, [time_seconds]
  2120 00000AFF 758A                    	jne	short time_of_day
  2121                                  
  2122                                  rtc_retn:
  2123 00000B01 C3                      	retn
  2124                                  
  2125                                  rtc_p:	
  2126                                  	; 07/09/2014
  2127                                  	; 29/08/2014
  2128                                  	; 27/08/2014
  2129                                  	; 25/08/2014
  2130                                   	; Print Real Time Clock content
  2131                                  	;
  2132                                  	;
  2133 00000B02 E884FFFFFF              	call	time_of_day
  2134 00000B07 72F8                    	jc	short rtc_retn
  2135                                  	;
  2136 00000B09 3A05[62C00000]          	cmp	al, [ptime_seconds]
  2137 00000B0F 74F0                            je      short rtc_retn ; 29/08/2014
  2138                                  	;
  2139 00000B11 A2[62C00000]            	mov	[ptime_seconds], al
  2140                                  	;
  2141 00000B16 A0[F5C40000]            	mov	al, [date_century]
  2142 00000B1B E8BE000000              	call	bcd_to_ascii
  2143 00000B20 66A3[2FC00000]          	mov	[datestr+6], ax
  2144 00000B26 A0[F4C40000]            	mov	al, [date_year]
  2145 00000B2B E8AE000000              	call	bcd_to_ascii
  2146 00000B30 66A3[31C00000]          	mov	[datestr+8], ax
  2147 00000B36 A0[F3C40000]            	mov	al, [date_month]
  2148 00000B3B E89E000000              	call	bcd_to_ascii
  2149 00000B40 66A3[2CC00000]          	mov	[datestr+3], ax
  2150 00000B46 A0[F2C40000]            	mov	al, [date_day]
  2151 00000B4B E88E000000              	call	bcd_to_ascii
  2152 00000B50 66A3[29C00000]          	mov	[datestr], ax
  2153                                  	;
  2154 00000B56 0FB61D[F1C40000]        	movzx	ebx, byte [date_wday]
  2155 00000B5D C0E302                  	shl 	bl, 2
  2156 00000B60 81C3[42C00000]          	add	ebx, daytmp
  2157 00000B66 8B03                    	mov	eax, [ebx]
  2158 00000B68 A3[34C00000]            	mov	[daystr], eax
  2159                                  	;
  2160 00000B6D A0[F0C40000]            	mov	al, [time_hours]
  2161 00000B72 E867000000              	call	bcd_to_ascii
  2162 00000B77 66A3[38C00000]          	mov	[timestr], ax
  2163 00000B7D A0[EFC40000]            	mov	al, [time_minutes]
  2164 00000B82 E857000000              	call	bcd_to_ascii
  2165 00000B87 66A3[3BC00000]          	mov	[timestr+3], ax
  2166 00000B8D A0[EEC40000]            	mov	al, [time_seconds]
  2167 00000B92 E847000000              	call	bcd_to_ascii
  2168 00000B97 66A3[3EC00000]          	mov	[timestr+6], ax
  2169                                  	;		
  2170 00000B9D BE[17C00000]            	mov	esi, rtc_msg ; message offset
  2171                                  	; 23/02/2015
  2172 00000BA2 52                      	push	edx
  2173 00000BA3 51                      	push	ecx
  2174                                  	; 07/09/2014
  2175 00000BA4 66BB0200                	mov	bx, 2		; Video page 2
  2176                                  prtmsg:
  2177 00000BA8 AC                      	lodsb
  2178 00000BA9 08C0                    	or	al, al
  2179 00000BAB 740F                    	jz	short prtmsg_ok
  2180 00000BAD 56                      	push	esi
  2181 00000BAE 6653                    	push	bx
  2182 00000BB0 B43F                            mov	ah, 3Fh	; cyan (6) background, 
  2183                                  			; white (F) forecolor
  2184 00000BB2 E8000C0000              	call 	WRITE_TTY
  2185 00000BB7 665B                    	pop	bx
  2186 00000BB9 5E                      	pop	esi
  2187 00000BBA EBEC                    	jmp	short prtmsg
  2188                                  	;
  2189                                  	;mov	edi, 0B8000h+0A0h+0A0h ; Row 2
  2190                                  	;call	printk
  2191                                  prtmsg_ok:
  2192                                  	; 07/09/2014
  2193 00000BBC 6631D2                  	xor	dx, dx		; column 0, row 0
  2194 00000BBF E8870C0000              	call	_set_cpos	; set curspor position to 0,0 
  2195                                  	; 23/02/2015
  2196 00000BC4 59                      	pop	ecx
  2197 00000BC5 5A                      	pop	edx
  2198 00000BC6 C3                      	retn
  2199                                  
  2200                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  2201                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  2202                                  default_irq7:
  2203 00000BC7 6650                    	push	ax
  2204 00000BC9 B00B                    	mov	al, 0Bh  ; In-Service register
  2205 00000BCB E620                    	out	20h, al
  2206 00000BCD EB00                            jmp short $+2
  2207 00000BCF EB00                    	jmp short $+2
  2208 00000BD1 E420                    	in	al, 20h
  2209 00000BD3 2480                    	and 	al, 80h ; bit 7 (is it real IRQ 7 or fake?)
  2210 00000BD5 7404                            jz      short irq7_iret ; Fake (spurious) IRQ, do not send EOI 
  2211 00000BD7 B020                            mov     al, 20h ; EOI
  2212 00000BD9 E620                    	out	20h, al 
  2213                                  irq7_iret:
  2214 00000BDB 6658                    	pop	ax
  2215 00000BDD CF                      	iretd
  2216                                  	
  2217                                  bcd_to_ascii:
  2218                                  	; 25/08/2014
  2219                                  	; INPUT ->
  2220                                  	;	al = Packed BCD number
  2221                                  	; OUTPUT ->
  2222                                  	;	ax  = ASCII word/number
  2223                                  	;
  2224                                  	; Erdogan Tan - 1998 (proc_hex) - TRDOS.ASM (2004-2011)
  2225                                  	;
  2226 00000BDE D410                    	db 0D4h,10h                     ; Undocumented inst. AAM
  2227                                  					; AH = AL / 10h
  2228                                  					; AL = AL MOD 10h
  2229 00000BE0 660D3030                	or ax,'00'                      ; Make it ASCII based
  2230                                  
  2231 00000BE4 86E0                            xchg ah, al 
  2232                                  	
  2233 00000BE6 C3                      	retn	
  2234                                  	
  2235                                  
  2236                                  %include 'keyboard.s' ; 07/03/2015
  2237                              <1> ; ****************************************************************************
  2238                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - keyboard.s
  2239                              <1> ; ----------------------------------------------------------------------------
  2240                              <1> ; Last Update: 29/01/2016
  2241                              <1> ; ----------------------------------------------------------------------------
  2242                              <1> ; Beginning: 17/01/2016
  2243                              <1> ; ----------------------------------------------------------------------------
  2244                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  2245                              <1> ; ----------------------------------------------------------------------------
  2246                              <1> ; Turkish Rational DOS
  2247                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  2248                              <1> ;
  2249                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  2250                              <1> ; keyboard.inc (17/10/2015)
  2251                              <1> ;
  2252                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
  2253                              <1> ; ****************************************************************************
  2254                              <1> 
  2255                              <1> ; Retro UNIX 386 v1 Kernel - KEYBOARD.INC
  2256                              <1> ; Last Modification: 17/10/2015
  2257                              <1> ;		    (Keyboard Data is in 'KYBDATA.INC')	
  2258                              <1> ;
  2259                              <1> ; ///////// KEYBOARD FUNCTIONS (PROCEDURES) ///////////////
  2260                              <1> 
  2261                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
  2262                              <1> 
  2263                              <1> ; 03/12/2014
  2264                              <1> ; 26/08/2014
  2265                              <1> ; KEYBOARD I/O
  2266                              <1> ; (INT_16h - Retro UNIX 8086 v1 - U9.ASM, 30/06/2014)
  2267                              <1> 
  2268                              <1> ;NOTE: 'k0' to 'k7' are name of OPMASK registers.
  2269                              <1> ;	(The reason of using '_k' labels!!!) (27/08/2014)    
  2270                              <1> ;NOTE: 'NOT' keyword is '~' unary operator in NASM.
  2271                              <1> ;	('NOT LC_HC' --> '~LC_HC') (bit reversing operator)
  2272                              <1> 
  2273                              <1> int16h:	; 30/06/2015
  2274                              <1> ;getc:
  2275 00000BE7 9C                  <1> 	pushfd	; 28/08/2014
  2276 00000BE8 0E                  <1> 	push 	cs
  2277 00000BE9 E801000000          <1> 	call 	KEYBOARD_IO_1 ; getc_int
  2278 00000BEE C3                  <1> 	retn	
  2279                              <1> 
  2280                              <1> getc_int:
  2281                              <1> 	; 28/02/2015
  2282                              <1> 	; 03/12/2014 (derivation from pc-xt-286 bios source code -1986-, 
  2283                              <1> 	;	      instead of pc-at bios - 1985-)
  2284                              <1> 	; 28/08/2014 (_k1d)
  2285                              <1> 	; 30/06/2014
  2286                              <1> 	; 03/03/2014
  2287                              <1> 	; 28/02/2014
  2288                              <1> 	; Derived from "KEYBOARD_IO_1" procedure of IBM "pc-xt-286" 
  2289                              <1> 	; rombios source code (21/04/1986)
  2290                              <1> 	;	 'keybd.asm', INT 16H, KEYBOARD_IO
  2291                              <1> 	;
  2292                              <1> 	; KYBD --- 03/06/86  KEYBOARD BIOS
  2293                              <1> 	;
  2294                              <1> 	;--- INT 16 H -----------------------------------------------------------------
  2295                              <1> 	; KEYBOARD I/O								      :
  2296                              <1> 	;	THESE ROUTINES PROVIDE READ KEYBOARD SUPPORT			      :
  2297                              <1> 	; INPUT									      :
  2298                              <1> 	;	(AH)= 00H  READ THE NEXT ASCII CHARACTER ENTERED FROM THE KEYBOARD,   :
  2299                              <1> 	;		   RETURN THE RESULT IN (AL), SCAN CODE IN (AH).              :
  2300                              <1> 	;		   THIS IS THE COMPATIBLE READ INTERFACE, EQUIVALENT TO THE   :
  2301                              <1> 	;                  STANDARD PC OR PCAT KEYBOARD				      :	
  2302                              <1> 	;-----------------------------------------------------------------------------:
  2303                              <1> 	;	(AH)= 01H  SET THE ZERO FLAG TO INDICATE IF AN ASCII CHARACTER IS     :
  2304                              <1> 	;		   AVAILABLE TO BE READ FROM THE KEYBOARD BUFFER.	      :
  2305                              <1> 	;		   (ZF)= 1 -- NO CODE AVAILABLE			              :
  2306                              <1> 	;		   (ZF)= 0 -- CODE IS AVAILABLE  (AX)= CHARACTER              :
  2307                              <1> 	;		   IF (ZF)= 0, THE NEXT CHARACTER IN THE BUFFER TO BE READ IS :
  2308                              <1> 	;		   IN (AX), AND THE ENTRY REMAINS IN THE BUFFER.              :
  2309                              <1> 	;		   THIS WILL RETURN ONLY PC/PCAT KEYBOARD COMPATIBLE CODES    :
  2310                              <1> 	;-----------------------------------------------------------------------------:	
  2311                              <1> 	;	(AH)= 02H  RETURN THE CURRENT SHIFT STATUS IN AL REGISTER             :
  2312                              <1> 	;		   THE BIT SETTINGS FOR THIS CODE ARE INDICATED IN THE        :
  2313                              <1> 	;		   EQUATES FOR @KB_FLAG		                              :
  2314                              <1> 	;-----------------------------------------------------------------------------:	
  2315                              <1> 	;	(AH)= 03H  SET TYPAMATIC RATE AND DELAY                               :
  2316                              <1> 	;	      (AL) = 05H                                                      :
  2317                              <1> 	;	      (BL) = TYPAMATIC RATE (BITS 5 - 7 MUST BE RESET TO 0)           :
  2318                              <1> 	;		       							      :
  2319                              <1> 	;                     REGISTER     RATE      REGISTER     RATE                :
  2320                              <1> 	;                      VALUE     SELECTED     VALUE     SELECTED              :
  2321                              <1> 	;                     --------------------------------------------            :
  2322                              <1> 	;			00H        30.0        10H        7.5                 :
  2323                              <1> 	;			01H        26.7        11H        6.7                 :
  2324                              <1> 	;			02H        24.0        12H        6.0                 :
  2325                              <1> 	;			03H        21.8        13H        5.5                 :
  2326                              <1> 	;			04H        20.0        14H        5.0                 :
  2327                              <1> 	;			05H        18.5        15H        4.6                 :
  2328                              <1> 	;			06H        17.1        16H        4.3                 :
  2329                              <1> 	;			07H        16.0        17H        4.0                 :
  2330                              <1> 	;			08H        15.0        18H        3.7                 :
  2331                              <1> 	;			09H        13.3        19H        3.3                 :
  2332                              <1> 	;			0AH        12.0        1AH        3.0                 :
  2333                              <1> 	;			0BH        10.9        1BH        2.7                 :
  2334                              <1>         ;			0CH        10.0        1CH        2.5                 :
  2335                              <1> 	;			0DH         9.2        1DH        2.3                 :
  2336                              <1> 	;			0EH         8.6        1EH        2.1                 :
  2337                              <1> 	;			0FH         8.0        1FH        2.0                 :
  2338                              <1> 	;									      :
  2339                              <1> 	;	      (BH) = TYPAMATIC DELAY  (BITS 2 - 7 MUST BE RESET TO 0)         :
  2340                              <1> 	;		       							      :
  2341                              <1> 	;                     REGISTER     DELAY                                      :
  2342                              <1> 	;                      VALUE       VALUE                                      :
  2343                              <1> 	;                     ------------------                                      :
  2344                              <1> 	;			00H        250 ms                                     :
  2345                              <1> 	;			01H        500 ms                                     :
  2346                              <1> 	;			02H        750 ms                                     :
  2347                              <1> 	;			03H       1000 ms                                     :
  2348                              <1> 	;-----------------------------------------------------------------------------:
  2349                              <1> 	;	(AH)= 05H  PLACE ASCII CHARACTER/SCAN CODE COMBINATION IN KEYBOARD    :
  2350                              <1> 	;		   BUFFER AS IF STRUCK FROM KEYBOARD                          :
  2351                              <1> 	;		   ENTRY:  (CL) = ASCII CHARACTER		              :
  2352                              <1> 	;		           (CH) = SCAN CODE                                   :
  2353                              <1> 	;		   EXIT:   (AH) = 00H = SUCCESSFUL OPERATION                  :
  2354                              <1> 	;		           (AL) = 01H = UNSUCCESSFUL - BUFFER FULL            :
  2355                              <1> 	;		   FLAGS:  CARRY IF ERROR                                     :
  2356                              <1> 	;-----------------------------------------------------------------------------:		
  2357                              <1> 	;	(AH)= 10H  EXTENDED READ INTERFACE FOR THE ENHANCED KEYBOARD,         :
  2358                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=0                            :
  2359                              <1> 	;-----------------------------------------------------------------------------:
  2360                              <1> 	;	(AH)= 11H  EXTENDED ASCII STATUS FOR THE ENHANCED KEYBOARD,           :
  2361                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=1                            :
  2362                              <1> 	;-----------------------------------------------------------------------------:	
  2363                              <1> 	;	(AH)= 12H  RETURN THE EXTENDED SHIFT STATUS IN AX REGISTER            :
  2364                              <1> 	;		   AL = BITS FROM KB_FLAG, AH = BITS FOR LEFT AND RIGHT       :
  2365                              <1> 	;		   CTL AND ALT KEYS FROM KB_FLAG_1 AND KB_FLAG_3              :
  2366                              <1> 	; OUTPUT					                              :
  2367                              <1> 	;	AS NOTED ABOVE, ONLY (AX) AND FLAGS CHANGED	                      :
  2368                              <1> 	;	ALL REGISTERS RETAINED		                                      :
  2369                              <1> 	;------------------------------------------------------------------------------
  2370                              <1> 
  2371                              <1> KEYBOARD_IO_1:	
  2372 00000BEF FB                  <1> 	sti				; INTERRUPTS BACK ON
  2373 00000BF0 1E                  <1> 	push	ds			; SAVE CURRENT DS
  2374 00000BF1 53                  <1> 	push	ebx			; SAVE BX TEMPORARILY
  2375                              <1> 	;push	ecx			; SAVE CX TEMPORARILY
  2376 00000BF2 66BB1000            <1>         mov     bx, KDATA 
  2377 00000BF6 8EDB                <1> 	mov	ds, bx			; PUT SEGMENT VALUE OF DATA AREA INTO DS
  2378 00000BF8 08E4                <1> 	or	ah, ah			; CHECK FOR (AH)= 00H
  2379 00000BFA 7439                <1> 	jz	short _K1		; ASCII_READ
  2380 00000BFC FECC                <1> 	dec	ah                      ; CHECK FOR (AH)= 01H
  2381 00000BFE 7452                <1>         jz      short _K2               ; ASCII_STATUS
  2382 00000C00 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 02H
  2383 00000C02 0F8485000000        <1>         jz      _K3                     ; SHIFT STATUS
  2384 00000C08 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 03H	
  2385 00000C0A 0F8484000000        <1>         jz      _K300                   ; SET TYPAMATIC RATE/DELAY
  2386 00000C10 80EC02              <1> 	sub	ah, 2			; CHECK FOR (AH)= 05H	
  2387 00000C13 0F84A1000000        <1>         jz      _K500                   ; KEYBOARD WRITE         
  2388                              <1> _KIO1:	
  2389 00000C19 80EC0B              <1> 	sub	ah, 11			; AH =  10H
  2390 00000C1C 740B                <1> 	jz	short _K1E		; EXTENDED ASCII READ
  2391 00000C1E FECC                <1> 	dec	ah			; CHECK FOR (AH)= 11H
  2392 00000C20 7421                <1> 	jz	short _K2E		; EXTENDED_ASCII_STATUS
  2393 00000C22 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 12H
  2394 00000C24 7449                <1> 	jz	short _K3E		; EXTENDED_SHIFT_STATUS
  2395                              <1> _KIO_EXIT:
  2396                              <1> 	;pop	ecx			; RECOVER REGISTER
  2397 00000C26 5B                  <1> 	pop	ebx			; RECOVER REGISTER
  2398 00000C27 1F                  <1> 	pop	ds			; RECOVER SEGMENT
  2399 00000C28 CF                  <1> 	iretd				; INVALID COMMAND, EXIT
  2400                              <1> 
  2401                              <1> 	;-----	ASCII CHARACTER
  2402                              <1> _K1E:	
  2403 00000C29 E8B9000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER (EXTENDED)
  2404 00000C2E E82E010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
  2405 00000C33 EBF1                <1> 	jmp	short _KIO_EXIT         ; GIVE IT TO THE CALLER
  2406                              <1> _K1:	
  2407 00000C35 E8AD000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER
  2408 00000C3A E82D010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
  2409 00000C3F 72F4                <1> 	jc	short _K1		; CARRY SET MEANS TROW CODE AWAY
  2410                              <1> _K1A:
  2411 00000C41 EBE3                <1> 	jmp	short _KIO_EXIT         ; RETURN TO CALLER
  2412                              <1> 
  2413                              <1> 	;-----	ASCII STATUS
  2414                              <1> _K2E:	
  2415 00000C43 E8EA000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER (EXTENDED)
  2416 00000C48 7420                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
  2417 00000C4A 9C                  <1> 	pushf				; SAVE ZF FROM TEST
  2418 00000C4B E811010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
  2419 00000C50 EB17                <1> 	jmp	short _K2A	        ; GIVE IT TO THE CALLER
  2420                              <1> _K2:	
  2421 00000C52 E8DB000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER
  2422 00000C57 7411                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
  2423 00000C59 9C                  <1> 	pushf				; SAVE ZF FROM TEST
  2424 00000C5A E80D010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
  2425 00000C5F 7308                <1> 	jnc	short _K2A	        ; CARRY CLEAR MEANS PASS VALID CODE
  2426 00000C61 9D                  <1> 	popf				; INVALID CODE FOR THIS TYPE OF CALL
  2427 00000C62 E880000000          <1> 	call	_K1S			; THROW THE CHARACTER AWAY
  2428 00000C67 EBE9                <1> 	jmp	short _K2		; GO LOOK FOR NEXT CHAR, IF ANY
  2429                              <1> _K2A:
  2430 00000C69 9D                  <1> 	popf				; RESTORE ZF FROM TEST
  2431                              <1> _K2B:
  2432                              <1> 	;pop	ecx			; RECOVER REGISTER
  2433 00000C6A 5B                  <1> 	pop	ebx			; RECOVER REGISTER
  2434 00000C6B 1F                  <1> 	pop	ds			; RECOVER SEGMENT
  2435 00000C6C CA0400              <1> 	retf	4			; THROW AWAY (e)FLAGS
  2436                              <1> 
  2437                              <1> 	;-----	SHIFT STATUS
  2438                              <1> _K3E:                                   ; GET THE EXTENDED SHIFT STATUS FLAGS
  2439 00000C6F 8A25[72BE0000]      <1> 	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
  2440 00000C75 80E404              <1> 	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
  2441                              <1> 	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
  2442                              <1> 	;shl	ah, cl			; BIT 7 POSITION
  2443 00000C78 C0E405              <1>         shl	ah, 5
  2444 00000C7B A0[72BE0000]        <1> 	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
  2445 00000C80 2473                <1> 	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
  2446 00000C82 08C4                <1> 	or	ah, al                  ; MERGE REMAINING BITS INTO AH
  2447 00000C84 A0[74BE0000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
  2448 00000C89 240C                <1> 	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
  2449 00000C8B 08C4                <1> 	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
  2450                              <1> _K3:
  2451 00000C8D A0[71BE0000]        <1> 	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
  2452 00000C92 EB92                <1> 	jmp	short _KIO_EXIT		; RETURN TO CALLER
  2453                              <1> 
  2454                              <1> 	;-----	SET TYPAMATIC RATE AND DELAY
  2455                              <1> _K300:
  2456 00000C94 3C05                <1> 	cmp	al, 5			; CORRECT FUNCTION CALL?
  2457 00000C96 758E                <1> 	jne	short _KIO_EXIT		; NO, RETURN
  2458 00000C98 F6C3E0              <1>      	test	bl, 0E0h		; TEST FOR OUT-OF-RANGE RATE
  2459 00000C9B 7589                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
  2460 00000C9D F6C7FC              <1> 	test	BH, 0FCh		; TEST FOR OUT-OF-RANGE DELAY
  2461 00000CA0 7584                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
  2462 00000CA2 B0F3                <1> 	mov	al, KB_TYPA_RD		; COMMAND FOR TYPAMATIC RATE/DELAY		
  2463 00000CA4 E8DA060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
  2464                              <1> 	;mov	cx, 5			; SHIFT COUNT
  2465                              <1> 	;shl	bh, cl			; SHIFT DELAY OVER
  2466 00000CA9 C0E705              <1> 	shl	bh, 5
  2467 00000CAC 88D8                <1> 	mov	al, bl			; PUT IN RATE
  2468 00000CAE 08F8                <1> 	or	al, bh			; AND DELAY
  2469 00000CB0 E8CE060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
  2470 00000CB5 E96CFFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER
  2471                              <1> 
  2472                              <1> 	;-----	WRITE TO KEYBOARD BUFFER
  2473                              <1> _K500:
  2474 00000CBA 56                  <1> 	push	esi			; SAVE SI (esi)
  2475 00000CBB FA                  <1> 	cli				; 
  2476 00000CBC 8B1D[82BE0000]      <1>      	mov	ebx, [BUFFER_TAIL]	; GET THE 'IN TO' POINTER TO THE BUFFER
  2477 00000CC2 89DE                <1> 	mov	esi, ebx		; SAVE A COPY IN CASE BUFFER NOT FULL
  2478 00000CC4 E8D3000000          <1> 	call	_K4			; BUMP THE POINTER TO SEE IF BUFFER IS FULL
  2479 00000CC9 3B1D[7EBE0000]      <1> 	cmp	ebx, [BUFFER_HEAD]	; WILL THE BUFFER OVERRUN IF WE STORE THIS?
  2480 00000CCF 740D                <1> 	je	short _K502		; YES - INFORM CALLER OF ERROR		
  2481 00000CD1 66890E              <1> 	mov	[esi], cx		; NO - PUT ASCII/SCAN CODE INTO BUFFER	
  2482 00000CD4 891D[82BE0000]      <1> 	mov	[BUFFER_TAIL], ebx	; ADJUST 'IN TO' POINTER TO REFLECT CHANGE
  2483 00000CDA 28C0                <1> 	sub	al, al			; TELL CALLER THAT OPERATION WAS SUCCESSFUL
  2484 00000CDC EB02                <1> 	jmp	short _K504		; SUB INSTRUCTION ALSO RESETS CARRY FLAG
  2485                              <1> _K502:
  2486 00000CDE B001                <1> 	mov	al, 01h			; BUFFER FULL INDICATION
  2487                              <1> _K504:
  2488 00000CE0 FB                  <1> 	sti				
  2489 00000CE1 5E                  <1> 	pop	esi			; RECOVER SI (esi)
  2490 00000CE2 E93FFFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER WITH STATUS IN AL
  2491                              <1> 
  2492                              <1> 	;-----	READ THE KEY TO FIGURE OUT WHAT TO DO -----
  2493                              <1> _K1S:
  2494 00000CE7 FA                  <1> 	cli	; 03/12/2014
  2495 00000CE8 8B1D[7EBE0000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2496 00000CEE 3B1D[82BE0000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
  2497                              <1> 	;jne	short _K1U		; IF ANYTHING IN BUFFER SKIP INTERRUPT
  2498 00000CF4 750F                <1> 	jne	short _k1x ; 03/12/2014
  2499                              <1> 	;
  2500                              <1> 	; 03/12/2014
  2501                              <1> 	; 28/08/2014
  2502                              <1> 	; PERFORM OTHER FUNCTION ?? here !
  2503                              <1> 	;; MOV	AX, 9002h		; MOVE IN WAIT CODE & TYPE
  2504                              <1> 	;; INT 	15H			; PERFORM OTHER FUNCTION
  2505                              <1> _K1T:                                   ; ASCII READ
  2506 00000CF6 FB                  <1> 	sti				; INTERRUPTS BACK ON DURING LOOP
  2507 00000CF7 90                  <1> 	nop				; ALLOW AN INTERRUPT TO OCCUR
  2508                              <1> _K1U:	
  2509 00000CF8 FA                  <1> 	cli				; INTERRUPTS BACK OFF
  2510 00000CF9 8B1D[7EBE0000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2511 00000CFF 3B1D[82BE0000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
  2512                              <1> _k1x:
  2513 00000D05 53                  <1> 	push	ebx			; SAVE ADDRESS		
  2514 00000D06 9C                  <1> 	pushf				; SAVE FLAGS
  2515 00000D07 E82F070000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2516 00000D0C 8A1D[73BE0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2517 00000D12 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2518 00000D14 80E307              <1> 	and	bl, 07h	; KB_LEDS	; ISOLATE INDICATOR BITS
  2519 00000D17 7406                <1> 	jz	short _K1V		; IF NO CHANGE BYPASS UPDATE
  2520 00000D19 E8C9060000          <1> 	call	SND_LED1
  2521 00000D1E FA                  <1> 	cli				; DISABLE INTERRUPTS
  2522                              <1> _K1V:
  2523 00000D1F 9D                  <1> 	popf				; RESTORE FLAGS
  2524 00000D20 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
  2525 00000D21 74D3                <1>         je      short _K1T              ; LOOP UNTIL SOMETHING IN BUFFER
  2526                              <1> 	;
  2527 00000D23 668B03              <1> 	mov	ax, [ebx] 		; GET SCAN CODE AND ASCII CODE
  2528 00000D26 E871000000          <1>         call    _K4                     ; MOVE POINTER TO NEXT POSITION
  2529 00000D2B 891D[7EBE0000]      <1>         mov     [BUFFER_HEAD], ebx      ; STORE VALUE IN VARIABLE
  2530 00000D31 C3                  <1> 	retn				; RETURN
  2531                              <1> 
  2532                              <1> 	;-----	READ THE KEY TO SEE IF ONE IS PRESENT -----
  2533                              <1> _K2S:
  2534 00000D32 FA                  <1> 	cli				; INTERRUPTS OFF
  2535 00000D33 8B1D[7EBE0000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
  2536 00000D39 3B1D[82BE0000]      <1>         cmp     ebx, [BUFFER_TAIL]      ; IF EQUAL (Z=1) THEN NOTHING THERE
  2537 00000D3F 668B03              <1> 	mov	ax, [ebx]
  2538 00000D42 9C                  <1> 	pushf				; SAVE FLAGS
  2539 00000D43 6650                <1> 	push	ax			; SAVE CODE
  2540 00000D45 E8F1060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2541 00000D4A 8A1D[73BE0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2542 00000D50 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2543 00000D52 80E307              <1> 	and	bl, 07h ; KB_LEDS	; ISOLATE INDICATOR BITS
  2544 00000D55 7405                <1> 	jz	short _K2T		; IF NO CHANGE BYPASS UPDATE
  2545 00000D57 E874060000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
  2546                              <1> _K2T:
  2547 00000D5C 6658                <1> 	pop	ax			; RESTORE CODE
  2548 00000D5E 9D                  <1> 	popf				; RESTORE FLAGS
  2549 00000D5F FB                  <1> 	sti				; INTERRUPTS BACK ON
  2550 00000D60 C3                  <1> 	retn				; RETURN
  2551                              <1> 
  2552                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR EXTENDED CALLS -----
  2553                              <1> _KIO_E_XLAT:
  2554 00000D61 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
  2555 00000D63 7506                <1> 	jne	short _KIO_E_RET	; NO, PASS IT ON
  2556 00000D65 08E4                <1>         or 	ah, ah			; AH = 0 IS SPECIAL CASE
  2557 00000D67 7402                <1>         jz	short _KIO_E_RET        ; PASS THIS ON UNCHANGED
  2558 00000D69 30C0                <1> 	xor	al, al			; OTHERWISE SET AL = 0
  2559                              <1> _KIO_E_RET:				
  2560 00000D6B C3                  <1> 	retn				; GO BACK
  2561                              <1> 
  2562                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR STANDARD CALLS -----
  2563                              <1> _KIO_S_XLAT:
  2564 00000D6C 80FCE0              <1> 	cmp	ah, 0E0h		; IS IT KEYPAD ENTER OR / ?
  2565 00000D6F 750F                <1> 	jne	short _KIO_S2		; NO, CONTINUE
  2566 00000D71 3C0D                <1> 	cmp	al, 0Dh			; KEYPAD ENTER CODE?
  2567 00000D73 7408                <1>         je	short _KIO_S1		; YES, MASSAGE A BIT
  2568 00000D75 3C0A                <1> 	cmp	al, 0Ah			; CTRL KEYPAD ENTER CODE?
  2569 00000D77 7404                <1>         je	short _KIO_S1		; YES, MASSAGE THE SAME
  2570 00000D79 B435                <1> 	mov	ah, 35h			; NO, MUST BE KEYPAD /
  2571                              <1> _kio_ret: ; 03/12/2014
  2572 00000D7B F8                  <1> 	clc
  2573 00000D7C C3                  <1> 	retn
  2574                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
  2575                              <1> _KIO_S1:				
  2576 00000D7D B41C                <1> 	mov	ah, 1Ch			; CONVERT TO COMPATIBLE OUTPUT
  2577                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
  2578 00000D7F C3                  <1> 	retn
  2579                              <1> _KIO_S2:		
  2580 00000D80 80FC84              <1> 	cmp	ah, 84h			; IS IT ONE OF EXTENDED ONES?
  2581 00000D83 7715                <1> 	ja	short _KIO_DIS		; YES, THROW AWAY AND GET ANOTHER CHAR
  2582 00000D85 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
  2583 00000D87 7506                <1>         jne	short _KIO_S3		; NO, TRY LAST TEST
  2584 00000D89 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
  2585 00000D8B 740C                <1>         jz	short _KIO_USE		; PASS THIS ON UNCHANGED
  2586 00000D8D EB0B                <1> 	jmp	short _KIO_DIS		; THROW AWAY THE REST
  2587                              <1> _KIO_S3:
  2588 00000D8F 3CE0                <1> 	cmp	al, 0E0h		; IS IT AN EXTENSION OF A PREVIOUS ONE?
  2589                              <1> 	;jne	short _KIO_USE		; NO, MUST BE A STANDARD CODE
  2590 00000D91 75E8                <1> 	jne	short _kio_ret
  2591 00000D93 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
  2592 00000D95 7402                <1>         jz	short _KIO_USE		; JUMP IF AH = 0
  2593 00000D97 30C0                <1> 	xor	al, al			; CONVERT TO COMPATIBLE OUTPUT
  2594                              <1> 	;jmp	short _KIO_USE		; PASS IT ON TO CALLER
  2595                              <1> _KIO_USE:
  2596                              <1> 	;clc				; CLEAR CARRY TO INDICATE GOOD CODE
  2597 00000D99 C3                  <1> 	retn				; RETURN	
  2598                              <1> _KIO_DIS:
  2599 00000D9A F9                  <1> 	stc				; SET CARRY TO INDICATE DISCARD CODE
  2600 00000D9B C3                  <1> 	retn				; RETURN
  2601                              <1> 
  2602                              <1> 	;-----	INCREMENT BUFFER POINTER ROUTINE -----
  2603                              <1> _K4:    
  2604 00000D9C 43                  <1> 	inc     ebx
  2605 00000D9D 43                  <1> 	inc	ebx			; MOVE TO NEXT WORD IN LIST
  2606 00000D9E 3B1D[7ABE0000]      <1>         cmp     ebx, [BUFFER_END] 	; AT END OF BUFFER?
  2607                              <1>         ;jne    short _K5               ; NO, CONTINUE
  2608 00000DA4 7206                <1> 	jb	short _K5
  2609 00000DA6 8B1D[76BE0000]      <1>         mov     ebx, [BUFFER_START]     ; YES, RESET TO BUFFER BEGINNING
  2610                              <1> _K5:
  2611 00000DAC C3                  <1> 	retn
  2612                              <1> 
  2613                              <1> ; 20/02/2015
  2614                              <1> ; 05/12/2014
  2615                              <1> ; 26/08/2014
  2616                              <1> ; KEYBOARD (HARDWARE) INTERRUPT -  IRQ LEVEL 1
  2617                              <1> ; (INT_09h - Retro UNIX 8086 v1 - U9.ASM, 07/03/2014)
  2618                              <1> ;
  2619                              <1> ; Derived from "KB_INT_1" procedure of IBM "pc-at" 
  2620                              <1> ; rombios source code (06/10/1985)
  2621                              <1> ; 'keybd.asm', HARDWARE INT 09h - (IRQ Level 1)
  2622                              <1> 
  2623                              <1> ; EQUATES (IBM PC-XT-286 BIOS, 1986, 'POSQEQU.INC')
  2624                              <1> 
  2625                              <1> ;--------- 8042 COMMANDS -------------------------------------------------------
  2626                              <1> ENA_KBD		equ	0AEh		; ENABLE KEYBOARD COMMAND
  2627                              <1> DIS_KBD		equ	0ADh		; DISABLE KEYBOARD COMMAND
  2628                              <1> SHUT_CMD	equ	0FEh		; CAUSE A SHUTDOWN COMMAND
  2629                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
  2630                              <1> STATUS_PORT	equ	064h		; 8042 STATUS PORT
  2631                              <1> INPT_BUF_FULL	equ	00000010b 	; 1 = +INPUT BUFFER FULL
  2632                              <1> PORT_A		equ	060h		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
  2633                              <1> ;---------- 8042 KEYBOARD RESPONSE ---------------------------------------------
  2634                              <1> KB_ACK		equ	0FAh		; ACKNOWLEDGE PROM TRANSMISSION
  2635                              <1> KB_RESEND	equ	0FEh		; RESEND REQUEST
  2636                              <1> KB_OVER_RUN	equ	0FFh		; OVER RUN SCAN CODE
  2637                              <1> ;---------- KEYBOARD/LED COMMANDS ----------------------------------------------
  2638                              <1> KB_ENABLE	equ	0F4h		; KEYBOARD ENABLE
  2639                              <1> LED_CMD		equ	0EDh		; LED WRITE COMMAND
  2640                              <1> KB_TYPA_RD	equ	0F3h		; TYPAMATIC RATE/DELAY COMMAND
  2641                              <1> ;---------- KEYBOARD SCAN CODES ------------------------------------------------
  2642                              <1> NUM_KEY		equ	69		; SCAN CODE FOR	 NUMBER LOCK KEY
  2643                              <1> SCROLL_KEY	equ	70		; SCAN CODE FOR	 SCROLL LOCK KEY
  2644                              <1> ALT_KEY		equ	56		; SCAN CODE FOR	 ALTERNATE SHIFT KEY
  2645                              <1> CTL_KEY		equ	29		; SCAN CODE FOR	 CONTROL KEY
  2646                              <1> CAPS_KEY	equ	58		; SCAN CODE FOR	 SHIFT LOCK KEY
  2647                              <1> DEL_KEY		equ	83		; SCAN CODE FOR	 DELETE KEY
  2648                              <1> INS_KEY		equ	82		; SCAN CODE FOR	 INSERT KEY
  2649                              <1> LEFT_KEY	equ	42		; SCAN CODE FOR	 LEFT SHIFT
  2650                              <1> RIGHT_KEY	equ	54		; SCAN CODE FOR	 RIGHT SHIFT
  2651                              <1> SYS_KEY		equ	84		; SCAN CODE FOR	 SYSTEM KEY
  2652                              <1> ;---------- ENHANCED KEYBOARD SCAN CODES ---------------------------------------
  2653                              <1> ID_1		equ	0ABh		; 1ST ID CHARACTER FOR KBX
  2654                              <1> ID_2		equ	041h		; 2ND ID CHARACTER FOR KBX
  2655                              <1> ID_2A		equ	054h		; ALTERNATE 2ND ID CHARACTER FOR KBX
  2656                              <1> F11_M		equ	87		; F11 KEY MAKE
  2657                              <1> F12_M		equ	88		; F12 KEY MAKE
  2658                              <1> MC_E0		equ	224		; GENERAL MARKER CODE
  2659                              <1> MC_E1		equ	225		; PAUSE KEY MARKER CODE
  2660                              <1> ;---------- FLAG EQUATES WITHIN @KB_FLAG----------------------------------------
  2661                              <1> RIGHT_SHIFT	equ	00000001b	; RIGHT SHIFT KEY DEPRESSED
  2662                              <1> LEFT_SHIFT	equ	00000010b	; LEFT SHIFT KEY DEPRESSED
  2663                              <1> CTL_SHIFT	equ	00000100b	; CONTROL SHIFT KEY DEPRESSED
  2664                              <1> ALT_SHIFT	equ	00001000b	; ALTERNATE SHIFT KEY DEPRESSED
  2665                              <1> SCROLL_STATE	equ	00010000b	; SCROLL LOCK STATE IS ACTIVE
  2666                              <1> NUM_STATE	equ	00100000b	; NUM LOCK STATE IS ACTIVE
  2667                              <1> CAPS_STATE	equ	01000000b	; CAPS LOCK STATE IS ACTIVE
  2668                              <1> INS_STATE	equ	10000000b	; INSERT STATE IS ACTIVE
  2669                              <1> ;---------- FLAG EQUATES WITHIN	@KB_FLAG_1 -------------------------------------
  2670                              <1> L_CTL_SHIFT	equ	00000001b	; LEFT CTL KEY DOWN
  2671                              <1> L_ALT_SHIFT	equ	00000010b	; LEFT ALT KEY DOWN
  2672                              <1> SYS_SHIFT	equ	00000100b	; SYSTEM KEY DEPRESSED AND HELD
  2673                              <1> HOLD_STATE	equ	00001000b	; SUSPEND KEY HAS BEEN TOGGLED
  2674                              <1> SCROLL_SHIFT	equ	00010000b	; SCROLL LOCK KEY IS DEPRESSED
  2675                              <1> NUM_SHIFT	equ	00100000b	; NUM LOCK KEY IS DEPRESSED
  2676                              <1> CAPS_SHIFT	equ	01000000b	; CAPS LOCK KEY IS DEPRE55ED
  2677                              <1> INS_SHIFT	equ	10000000b	; INSERT KEY IS DEPRESSED
  2678                              <1> ;---------- FLAGS EQUATES WITHIN @KB_FLAG_2 -----------------------------------
  2679                              <1> KB_LEDS		equ	00000111b	; KEYBOARD LED STATE BITS
  2680                              <1> ;		equ	00000001b	; SCROLL LOCK INDICATOR
  2681                              <1> ;		equ	00000010b	; NUM LOCK INDICATOR
  2682                              <1> ;		equ	00000100b	; CAPS LOCK INDICATOR
  2683                              <1> ;		equ	00001000b	; RESERVED (MUST BE ZERO)
  2684                              <1> KB_FA		equ	00010000b	; ACKNOWLEDGMENT RECEIVED
  2685                              <1> KB_FE		equ	00100000b	; RESEND RECEIVED FLAG
  2686                              <1> KB_PR_LED	equ	01000000b	; MODE INDICATOR UPDATE
  2687                              <1> KB_ERR		equ	10000000b	; KEYBOARD TRANSMIT ERROR FLAG
  2688                              <1> ;----------- FLAGS EQUATES WITHIN @KB_FLAG_3 -----------------------------------
  2689                              <1> LC_E1		equ	00000001b	; LAST CODE WAS THE E1 HIDDEN CODE
  2690                              <1> LC_E0		equ	00000010b	; LAST CODE WAS THE E0 HIDDEN CODE
  2691                              <1> R_CTL_SHIFT	equ	00000100b	; RIGHT CTL KEY DOWN
  2692                              <1> R_ALT_SHIFT	equ	00001000b	; RIGHT ALT KEY DOWN
  2693                              <1> GRAPH_ON	equ	00001000b	; ALT GRAPHICS KEY DOWN (WT ONLY)	
  2694                              <1> KBX		equ	00010000b	; ENHANCED KEYBOARD INSTALLED
  2695                              <1> SET_NUM_LK	equ	00100000b	; FORCE NUM LOCK IF READ ID AND KBX
  2696                              <1> LC_AB		equ	01000000b	; LAST CHARACTER WAS FIRST ID CHARACTER
  2697                              <1> RD_ID		equ	10000000b	; DOING A READ ID (MUST BE BIT0)
  2698                              <1> ;
  2699                              <1> ;----------- INTERRUPT EQUATES -------------------------------------------------
  2700                              <1> EOI		equ	020h		; END OF INTERRUPT COMMAND TO 8259
  2701                              <1> INTA00		equ	020h		; 8259 PORT
  2702                              <1> 
  2703                              <1> 
  2704                              <1> kb_int:
  2705                              <1> 
  2706                              <1> ; 17/10/2015 ('ctrlbrk') 
  2707                              <1> ; 05/12/2014
  2708                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-)
  2709                              <1> ; 26/08/2014
  2710                              <1> ;
  2711                              <1> ; 03/06/86  KEYBOARD BIOS
  2712                              <1> ;
  2713                              <1> ;--- HARDWARE INT 09H -- (IRQ LEVEL 1) ------------------------------------------
  2714                              <1> ;										;
  2715                              <1> ;	KEYBOARD INTERRUPT ROUTINE						;
  2716                              <1> ;										;
  2717                              <1> ;--------------------------------------------------------------------------------
  2718                              <1> 
  2719                              <1> KB_INT_1:
  2720 00000DAD FB                  <1> 	sti				; ENABLE INTERRUPTS
  2721                              <1> 	;push	ebp
  2722 00000DAE 50                  <1> 	push	eax
  2723 00000DAF 53                  <1> 	push	ebx
  2724 00000DB0 51                  <1> 	push	ecx
  2725 00000DB1 52                  <1> 	push	edx
  2726 00000DB2 56                  <1> 	push	esi
  2727 00000DB3 57                  <1> 	push	edi
  2728 00000DB4 1E                  <1> 	push	ds
  2729 00000DB5 06                  <1> 	push	es
  2730 00000DB6 FC                  <1> 	cld				; FORWARD DIRECTION
  2731 00000DB7 66B81000            <1> 	mov	ax, KDATA
  2732 00000DBB 8ED8                <1> 	mov	ds, ax
  2733 00000DBD 8EC0                <1> 	mov	es, ax
  2734                              <1> 	;
  2735                              <1> 	;-----	WAIT FOR KEYBOARD DISABLE COMMAND TO BE ACCEPTED
  2736 00000DBF B0AD                <1> 	mov	al, DIS_KBD		; DISABLE THE KEYBOARD COMMAND
  2737 00000DC1 E8A9050000          <1> 	call	SHIP_IT			; EXECUTE DISABLE
  2738 00000DC6 FA                  <1> 	cli				; DISABLE INTERRUPTS
  2739 00000DC7 B900000100          <1> 	mov	ecx, 10000h		; SET MAXIMUM TIMEOUT
  2740                              <1> KB_INT_01:
  2741 00000DCC E464                <1> 	in	al, STATUS_PORT		; READ ADAPTER STATUS
  2742 00000DCE A802                <1> 	test	al, INPT_BUF_FULL	; CHECK INPUT BUFFER FULL STATUS BIT
  2743 00000DD0 E0FA                <1> 	loopnz	KB_INT_01		; WAIT FOR COMMAND TO BE ACCEPTED
  2744                              <1> 	;
  2745                              <1> 	;-----	READ CHARACTER FROM KEYBOARD INTERFACE
  2746 00000DD2 E460                <1> 	in	al, PORT_A		; READ IN THE CHARACTER
  2747                              <1> 	;
  2748                              <1> 	;-----	SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INT LEVEL 9H) 	
  2749                              <1> 	;MOV	AH, 04FH		; SYSTEM INTERCEPT - KEY CODE FUNCTION
  2750                              <1> 	;STC				; SET CY=1 (IN CASE OF IRET)
  2751                              <1> 	;INT	15H			; CASETTE CALL (AL)=KEY SCAN CODE
  2752                              <1> 	;				; RETURNS CY=1 FOR INVALID FUNCTION
  2753                              <1> 	;JC	KB_INT_02		; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
  2754                              <1> 	;JMP	K26			; EXIT IF SYSTEM HANDLES SCAN CODE
  2755                              <1> 	;				; EXT HANDLES HARDWARE EOI AND ENABLE		
  2756                              <1> 	;
  2757                              <1> 	;-----	CHECK FOR A RESEND COMMAND TO KEYBOARD
  2758                              <1> KB_INT_02:				; 	  (AL)= SCAN CODE
  2759 00000DD4 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  2760 00000DD5 3CFE                <1> 	cmp	al, KB_RESEND		; IS THE INPUT A RESEND
  2761 00000DD7 7411                <1>         je      short KB_INT_4          ; GO IF RESEND
  2762                              <1> 	;
  2763                              <1> 	;-----	CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
  2764 00000DD9 3CFA                <1> 	cmp	al, KB_ACK		; IS THE INPUT AN ACKNOWLEDGE
  2765 00000DDB 751A                <1>         jne     short KB_INT_2          ; GO IF NOT
  2766                              <1> 	;
  2767                              <1> 	;-----	A COMMAND TO THE KEYBOARD WAS ISSUED
  2768 00000DDD FA                  <1> 	cli				; DISABLE INTERRUPTS
  2769 00000DDE 800D[73BE0000]10    <1> 	or	byte [KB_FLAG_2], KB_FA ; INDICATE ACK RECEIVED
  2770 00000DE5 E97A020000          <1>         jmp     K26                     ; RETURN IF NOT (ACK RETURNED FOR DATA)
  2771                              <1> 	;
  2772                              <1> 	;-----	RESEND THE LAST BYTE
  2773                              <1> KB_INT_4:
  2774 00000DEA FA                  <1> 	cli				; DISABLE INTERRUPTS
  2775 00000DEB 800D[73BE0000]20    <1> 	or	byte [KB_FLAG_2], KB_FE ; INDICATE RESEND RECEIVED
  2776 00000DF2 E96D020000          <1>         jmp     K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
  2777                              <1> 	;
  2778                              <1> ;-----	UPDATE MODE INDICATORS IF CHANGE IN STATE
  2779                              <1> KB_INT_2:
  2780 00000DF7 6650                <1> 	push 	ax			; SAVE DATA IN
  2781 00000DF9 E83D060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2782 00000DFE 8A1D[73BE0000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2783 00000E04 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2784 00000E06 80E307              <1> 	and	bl, KB_LEDS		; ISOLATE INDICATOR BITS
  2785 00000E09 7405                <1> 	jz	short UP0		; IF NO CHANGE BYPASS UPDATE
  2786 00000E0B E8C0050000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
  2787                              <1> UP0:
  2788 00000E10 6658                <1> 	pop	ax			; RESTORE DATA IN
  2789                              <1> ;------------------------------------------------------------------------
  2790                              <1> ;	START OF KEY PROCESSING						;
  2791                              <1> ;------------------------------------------------------------------------
  2792 00000E12 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE IN AH ALSO
  2793                              <1> 	;
  2794                              <1> 	;-----	TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
  2795 00000E14 3CFF                <1> 	cmp	al, KB_OVER_RUN		; IS THIS AN OVERRUN CHAR
  2796 00000E16 0F843F050000        <1>         je      K62			; BUFFER_FULL_BEEP
  2797                              <1> 	;
  2798                              <1> K16:	
  2799 00000E1C 8A3D[74BE0000]      <1> 	mov	bh, [KB_FLAG_3]		; LOAD FLAGS FOR TESTING
  2800                              <1> 	;
  2801                              <1> 	;-----	TEST TO SEE IF A READ_ID IS IN PROGRESS
  2802 00000E22 F6C7C0              <1> 	test 	bh, RD_ID+LC_AB 	; ARE WE DOING A READ ID?
  2803 00000E25 7449                <1> 	jz	short NOT_ID		; CONTINUE IF NOT
  2804 00000E27 7917                <1> 	jns	short TST_ID_2		; IS THE RD_ID FLAG ON?
  2805 00000E29 3CAB                <1> 	cmp	al, ID_1		; IS THIS THE 1ST ID CHARACTER?
  2806 00000E2B 7507                <1> 	jne	short RST_RD_ID
  2807 00000E2D 800D[74BE0000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
  2808                              <1> RST_RD_ID:
  2809 00000E34 8025[74BE0000]7F    <1> 	and	byte [KB_FLAG_3], ~RD_ID ; RESET THE READ ID FLAG
  2810                              <1>         ;jmp    short ID_EX		; AND EXIT
  2811 00000E3B E924020000          <1> 	jmp	K26
  2812                              <1> 	;
  2813                              <1> TST_ID_2:
  2814 00000E40 8025[74BE0000]BF    <1> 	and	byte [KB_FLAG_3], ~LC_AB ; RESET FLAG
  2815 00000E47 3C54                <1> 	cmp	al, ID_2A		; IS THIS THE 2ND ID CHARACTER?
  2816 00000E49 7419                <1>         je	short KX_BIT		; JUMP IF SO
  2817 00000E4B 3C41                <1> 	cmp	al, ID_2		; IS THIS THE 2ND ID CHARACTER?
  2818                              <1>         ;jne	short ID_EX		; LEAVE IF NOT
  2819 00000E4D 0F8511020000        <1> 	jne	K26
  2820                              <1> 	;
  2821                              <1> 	;-----	A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
  2822 00000E53 F6C720              <1> 	test	bh, SET_NUM_LK 		; SHOULD WE SET NUM LOCK?
  2823 00000E56 740C                <1>         jz      short KX_BIT		; EXIT IF NOT
  2824 00000E58 800D[71BE0000]20    <1> 	or	byte [KB_FLAG], NUM_STATE ; FORCE NUM LOCK ON
  2825 00000E5F E86C050000          <1> 	call	SND_LED			; GO SET THE NUM LOCK INDICATOR
  2826                              <1> KX_BIT:
  2827 00000E64 800D[74BE0000]10    <1> 	or	byte [KB_FLAG_3], KBX	; INDICATE ENHANCED KEYBOARD WAS FOUND
  2828 00000E6B E9F4010000          <1> ID_EX:	jmp     K26			; EXIT
  2829                              <1> 	;
  2830                              <1> NOT_ID:
  2831 00000E70 3CE0                <1> 	cmp	al, MC_E0		; IS THIS THE GENERAL MARKER CODE?
  2832 00000E72 750C                <1> 	jne	short TEST_E1
  2833 00000E74 800D[74BE0000]12    <1> 	or	byte [KB_FLAG_3], LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
  2834                              <1> 	;jmp	short EXIT		; THROW AWAY THIS CODE
  2835 00000E7B E9EB010000          <1> 	jmp	K26A	
  2836                              <1> TEST_E1:	
  2837 00000E80 3CE1                <1> 	cmp	al, MC_E1		; IS THIS THE PAUSE KEY?
  2838 00000E82 750C                <1> 	jne	short NOT_HC
  2839 00000E84 800D[74BE0000]11    <1> 	or	byte [KB_FLAG_3], LC_E1+KBX ; SET FLAG BIT, SET KBX, AND
  2840 00000E8B E9DB010000          <1> EXIT:	jmp	K26A			; THROW AWAY THIS CODE
  2841                              <1> 	;
  2842                              <1> NOT_HC:
  2843 00000E90 247F                <1> 	and	al, 07Fh		; TURN OFF THE BREAK BIT
  2844 00000E92 F6C702              <1> 	test	bh, LC_E0		; LAST CODE THE E0 MARKER CODE
  2845 00000E95 7414                <1> 	jz	short NOT_LC_E0		; JUMP IF NOT
  2846                              <1> 	;
  2847 00000E97 BF[5EBD0000]        <1> 	mov	edi, _K6+6		; IS THIS A SHIFT KEY?
  2848 00000E9C AE                  <1> 	scasb
  2849 00000E9D 0F84C1010000        <1>         je      K26 ; K16B              ; YES, THROW AWAY & RESET FLAG
  2850 00000EA3 AE                  <1> 	scasb
  2851 00000EA4 757C                <1> 	jne	short K16A		; NO, CONTINUE KEY PROCESSING
  2852                              <1> 	;jmp	short K16B		; YES, THROW AWAY & RESET FLAG
  2853 00000EA6 E9B9010000          <1> 	jmp	K26
  2854                              <1> 	;
  2855                              <1> NOT_LC_E0:
  2856 00000EAB F6C701              <1> 	test	bh, LC_E1		; LAST CODE THE E1 MARKER CODE?
  2857 00000EAE 7435                <1> 	jz	short T_SYS_KEY		; JUMP IF NOT
  2858 00000EB0 B904000000          <1> 	mov	ecx, 4			; LENGHT OF SEARCH
  2859 00000EB5 BF[5CBD0000]        <1> 	mov	edi, _K6+4		; IS THIS AN ALT, CTL, OR SHIFT?
  2860 00000EBA F2AE                <1> 	repne	scasb			; CHECK IT
  2861                              <1> 	;je	short EXIT		; THROW AWAY IF SO
  2862 00000EBC 0F84A9010000        <1> 	je	K26A			
  2863                              <1> 	;
  2864 00000EC2 3C45                <1> 	cmp	al, NUM_KEY		; IS IT THE PAUSE KEY?
  2865                              <1> 	;jne	short K16B		; NO, THROW AWAY & RESET FLAG
  2866 00000EC4 0F859A010000        <1> 	jne	K26
  2867 00000ECA F6C480              <1> 	test	ah, 80h			; YES, IS IT THE BREAK OF THE KEY?
  2868                              <1> 	;jnz	short K16B		; YES, THROW THIS AWAY, TOO	
  2869 00000ECD 0F8591010000        <1> 	jnz	K26
  2870                              <1>         ; 20/02/2015 
  2871 00000ED3 F605[72BE0000]08    <1> 	test	byte [KB_FLAG_1],HOLD_STATE ;  NO, ARE WE PAUSED ALREADY?
  2872                              <1> 	;jnz	short K16B		;  YES, THROW AWAY
  2873 00000EDA 0F8584010000        <1> 	jnz	K26
  2874 00000EE0 E9E1020000          <1> 	jmp     K39P                    ; NO, THIS IS THE REAL PAUSE STATE
  2875                              <1> 	;
  2876                              <1> 	;-----	TEST FOR SYSTEM KEY
  2877                              <1> T_SYS_KEY:
  2878 00000EE5 3C54                <1> 	cmp	al, SYS_KEY		; IS IT THE SYSTEM KEY?
  2879 00000EE7 7539                <1> 	jnz	short K16A		; CONTINUE IF NOT
  2880                              <1> 	;
  2881 00000EE9 F6C480              <1> 	test	ah, 80h			; CHECK IF THIS A BREAK CODE
  2882 00000EEC 7524                <1> 	jnz	short K16C		; DO NOT TOUCH SYSTEM INDICATOR IF TRUE
  2883                              <1> 	;
  2884 00000EEE F605[72BE0000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN 
  2885                              <1>         ;jnz	short K16B		; IF YES, DO NOT PROCESS SYSTEM INDICATOR	
  2886 00000EF5 0F8569010000        <1> 	jnz     K26			
  2887                              <1> 	;
  2888 00000EFB 800D[72BE0000]04    <1> 	or	byte [KB_FLAG_1], SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
  2889 00000F02 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  2890 00000F04 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  2891                              <1> 					; INTERRUPT-RETURN-NO-EOI
  2892 00000F06 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  2893 00000F08 E862040000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  2894                              <1> 	; !!! SYSREQ !!! function/system call (INTERRUPT) must be here !!!
  2895                              <1> 	;MOV	AL, 8500H		; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
  2896                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
  2897                              <1> 	;INT	15H			; USER INTERRUPT	
  2898 00000F0D E965010000          <1>         jmp     K27A                    ; END PROCESSING
  2899                              <1> 	;
  2900                              <1> ;K16B:	jmp	K26			; IGNORE SYSTEM KEY
  2901                              <1> 	;
  2902                              <1> K16C:
  2903 00000F12 8025[72BE0000]FB    <1> 	and	byte [KB_FLAG_1], ~SYS_SHIFT ; TURN OFF SHIFT KEY HELD DOWN
  2904 00000F19 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  2905 00000F1B E620                <1> 	out	20h, al ;out INTA00, al ; SEND COMMAND TO INTERRUPT CONTROL PORT
  2906                              <1> 					; INTERRUPT-RETURN-NO-EOI
  2907                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  2908                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  2909                              <1> 	;
  2910                              <1> 	;MOV	AX, 8501H		; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
  2911                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
  2912                              <1> 	;INT	15H			; USER INTERRUPT
  2913                              <1> 	;JMP	K27A			; INGONRE SYSTEM KEY				
  2914                              <1> 	;
  2915 00000F1D E94E010000          <1> 	jmp     K27			; IGNORE SYSTEM KEY
  2916                              <1> 	;
  2917                              <1> 	;-----	TEST FOR SHIFT KEYS
  2918                              <1> K16A:
  2919 00000F22 8A1D[71BE0000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
  2920 00000F28 BF[58BD0000]        <1> 	mov	edi, _K6		; SHIFT KEY TABLE offset
  2921 00000F2D B908000000          <1> 	mov	ecx, _K6L		; LENGTH
  2922 00000F32 F2AE                <1> 	repne	scasb			; LOOK THROUGH THE TABLE FOR A MATCH
  2923 00000F34 88E0                <1> 	mov	al, ah			; RECOVER SCAN CODE
  2924 00000F36 0F8510010000        <1>         jne     K25                     ; IF NO MATCH, THEN SHIFT NOT FOUND
  2925                              <1> 	;
  2926                              <1> 	;------	SHIFT KEY FOUND
  2927                              <1> K17:
  2928 00000F3C 81EF[59BD0000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
  2929 00000F42 8AA7[60BD0000]      <1>        	mov     ah, [edi+_K7]       	; GET MASK INTO AH
  2930 00000F48 B102                <1> 	mov	cl, 2			; SETUP COUNT FOR FLAG SHIFTS
  2931 00000F4A A880                <1> 	test	al, 80h			; TEST FOR BREAK KEY
  2932 00000F4C 0F8596000000        <1>         jnz     K23                     ; JUMP OF BREAK
  2933                              <1> 	;
  2934                              <1> 	;-----	SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
  2935                              <1> K17C:
  2936 00000F52 80FC10              <1> 	cmp	ah, SCROLL_SHIFT
  2937 00000F55 732B                <1> 	jae	short K18		; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
  2938                              <1> 	;
  2939                              <1> 	;-----	PLAIN SHIFT KEY, SET SHIFT ON
  2940 00000F57 0825[71BE0000]      <1> 	or	[KB_FLAG], ah		; TURN ON SHIFT BIT
  2941 00000F5D A80C                <1>         test	al, CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
  2942                              <1> 	;jnz	short K17D		; YES, MORE FLAGS TO SET
  2943 00000F5F 0F84FF000000        <1> 	jz	K26			; NO, INTERRUPT RETURN
  2944                              <1> K17D:
  2945 00000F65 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF NEW KEYS?
  2946 00000F68 740B                <1> 	jz 	short K17E		; NO, JUMP
  2947 00000F6A 0825[74BE0000]      <1> 	or	[KB_FLAG_3], ah		; SET BITS FOR RIGHT CTRL, ALT
  2948 00000F70 E9EF000000          <1> 	jmp	K26			; INTERRUPT RETURN
  2949                              <1> K17E:
  2950 00000F75 D2EC                <1> 	shr	ah, cl			; MOVE FLAG BITS TWO POSITIONS
  2951 00000F77 0825[72BE0000]      <1> 	or	[KB_FLAG_1], ah		; SET BITS FOR LEFT CTRL, ALT
  2952 00000F7D E9E2000000          <1> 	jmp	K26
  2953                              <1> 	;
  2954                              <1> 	;-----	TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
  2955                              <1> K18:					; SHIFT-TOGGLE
  2956 00000F82 F6C304              <1> 	test	bl, CTL_SHIFT 		; CHECK CTL SHIFT STATE
  2957                              <1>         ;jz    	short K18A              ; JUMP IF NOT CTL STATE
  2958 00000F85 0F85C1000000        <1>         jnz     K25                     ; JUMP IF CTL STATE
  2959                              <1> K18A:
  2960 00000F8B 3C52                <1> 	cmp	al, INS_KEY		; CHECK FOR INSERT KEY
  2961 00000F8D 7524                <1> 	jne	short K22		; JUMP IF NOT INSERT KEY
  2962 00000F8F F6C308              <1> 	test	bl, ALT_SHIFT 		; CHECK FOR ALTERNATE SHIFT
  2963                              <1>       	;jz	short K18B		; JUMP IF NOT ALTERNATE SHIFT	
  2964 00000F92 0F85B4000000        <1>         jnz     K25                     ; JUMP IF ALTERNATE SHIFT
  2965                              <1> K18B:
  2966 00000F98 F6C702              <1> 	test	bh, LC_E0 ;20/02/2015	; IS THIS NEW INSERT KEY?
  2967 00000F9B 7516                <1> 	jnz	short K22		; YES, THIS ONE'S NEVER A '0'
  2968                              <1> K19:	
  2969 00000F9D F6C320              <1> 	test	bl, NUM_STATE 		; CHECK FOR BASE STATE
  2970 00000FA0 750C                <1> 	jnz	short K21		; JUMP IF NUM LOCK IS ON
  2971 00000FA2 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
  2972 00000FA5 740C                <1> 	jz	short K22		; JUMP IF BASE STATE
  2973                              <1> K20:					; NUMERIC ZERO, NOT INSERT KEY
  2974 00000FA7 88C4                <1> 	mov	ah, al			; PUT SCAN CODE BACK IN AH
  2975 00000FA9 E99E000000          <1>         jmp     K25                     ; NUMERAL '0', STNDRD. PROCESSING
  2976                              <1> K21:					; MIGHT BE NUMERIC
  2977 00000FAE F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT
  2978 00000FB1 74F4                <1> 	jz	short K20		; IS NUMERIC, STD. PROC.
  2979                              <1> 	;
  2980                              <1> K22:					; SHIFT TOGGLE KEY HIT; PROCESS IT
  2981 00000FB3 8425[72BE0000]      <1> 	test	ah, [KB_FLAG_1] 	; IS KEY ALREADY DEPRESSED
  2982 00000FB9 0F85A5000000        <1>         jnz     K26                     ; JUMP IF KEY ALREADY DEPRESSED
  2983                              <1> K22A:
  2984 00000FBF 0825[72BE0000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
  2985 00000FC5 3025[71BE0000]      <1> 	xor	[KB_FLAG], ah		; TOGGLE THE SHIFT STATE
  2986                              <1> 	;
  2987                              <1> 	;-----	TOGGLE LED IF CAPS, NUM  OR SCROLL KEY DEPRESSED
  2988 00000FCB F6C470              <1> 	test	ah, CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
  2989 00000FCE 7409                <1> 	jz	short K22B		; GO IF NOT
  2990                              <1> 	;
  2991 00000FD0 6650                <1> 	push	ax			; SAVE SCAN CODE AND SHIFT MASK
  2992 00000FD2 E8F9030000          <1> 	call	SND_LED			; GO TURN MODE INDICATORS ON
  2993 00000FD7 6658                <1> 	pop	ax			; RESTORE SCAN CODE
  2994                              <1> K22B:
  2995 00000FD9 3C52                <1> 	cmp	al, INS_KEY		; TEST FOR 1ST MAKE OF INSERT KEY
  2996 00000FDB 0F8583000000        <1>         jne     K26                     ; JUMP IF NOT INSERT KEY
  2997 00000FE1 88C4                <1> 	mov	ah, al		        ; SCAN CODE IN BOTH HALVES OF AX
  2998 00000FE3 E999000000          <1>         jmp     K28                     ; FLAGS UPDATED, PROC. FOR BUFFER
  2999                              <1> 	;
  3000                              <1> 	;-----	BREAK SHIFT FOUND
  3001                              <1> K23:					; BREAK-SHIFT-FOUND
  3002 00000FE8 80FC10              <1> 	cmp	ah, SCROLL_SHIFT	; IS THIS A TOGGLE KEY
  3003 00000FEB F6D4                <1> 	not	ah			; INVERT MASK
  3004 00000FED 7355                <1> 	jae	short K24		; YES, HANDLE BREAK TOGGLE
  3005 00000FEF 2025[71BE0000]      <1> 	and	[KB_FLAG], ah		; TURN OFF SHIFT BIT
  3006 00000FF5 80FCFB              <1> 	cmp	ah, ~CTL_SHIFT		; IS THIS ALT OR CTL?
  3007 00000FF8 7730                <1> 	ja	short K23D		; NO, ALL DONE
  3008                              <1> 	;
  3009 00000FFA F6C702              <1> 	test	bh, LC_E0		; 2ND ALT OR CTL?
  3010 00000FFD 7408                <1> 	jz	short K23A		; NO, HANSLE NORMALLY
  3011 00000FFF 2025[74BE0000]      <1> 	and 	[KB_FLAG_3], ah		; RESET BIT FOR RIGHT ALT OR CTL
  3012 00001005 EB08                <1> 	jmp	short K23B		; CONTINUE
  3013                              <1> K23A:
  3014 00001007 D2FC                <1> 	sar	ah, cl			; MOVE THE MASK BIT TWO POSITIONS
  3015 00001009 2025[72BE0000]      <1> 	and	[KB_FLAG_1], ah		; RESET BIT FOR LEFT ALT AND CTL
  3016                              <1> K23B:
  3017 0000100F 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE
  3018 00001011 A0[74BE0000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT ALT & CTRL FLAGS
  3019 00001016 D2E8                <1> 	shr	al, cl			; MOVE TO BITS 1 & 0
  3020 00001018 0A05[72BE0000]      <1> 	or	al, [KB_FLAG_1]		; PUT IN LEFT ALT & CTL FLAGS
  3021 0000101E D2E0                <1> 	shl	al, cl			; MOVE BACK TO BITS 3 & 2
  3022 00001020 240C                <1> 	and	al, ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
  3023 00001022 0805[71BE0000]      <1> 	or	[KB_FLAG], al		; PUT RESULT IN THE REAL FLAGS	
  3024 00001028 88E0                <1> 	mov	al, ah
  3025                              <1> K23D:
  3026 0000102A 3CB8                <1> 	cmp	al, ALT_KEY+80h		; IS THIS ALTERNATE SHIFT RELEASE
  3027 0000102C 7536                <1> 	jne	short K26		; INTERRUPT RETURN
  3028                              <1> 	;	
  3029                              <1> 	;-----	ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
  3030 0000102E A0[75BE0000]        <1> 	mov	al, [ALT_INPUT]
  3031 00001033 B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
  3032 00001035 8825[75BE0000]      <1> 	mov	[ALT_INPUT], ah 	; ZERO OUT THE FIELD
  3033 0000103B 3C00                <1> 	cmp	al, 0			; WAS THE INPUT = 0?
  3034 0000103D 7425                <1> 	je	short K26		; INTERRUPT_RETURN
  3035                              <1>         ; 29/01/2016
  3036                              <1> 	;jmp     K61                    ; IT WASN'T, SO PUT IN BUFFER
  3037 0000103F E9D0020000          <1> 	jmp	_K60
  3038                              <1> 	;
  3039                              <1> K24:					; BREAK-TOGGLE
  3040 00001044 2025[72BE0000]      <1> 	and	[KB_FLAG_1], ah 	; INDICATE NO LONGER DEPRESSED
  3041 0000104A EB18                <1> 	jmp	short K26		; INTERRUPT_RETURN
  3042                              <1> 	;
  3043                              <1> 	;-----	TEST FOR HOLD STATE
  3044                              <1> 					; AL, AH = SCAN CODE
  3045                              <1> K25:					; NO-SHIFT-FOUND
  3046 0000104C 3C80                <1> 	cmp	al, 80h			; TEST FOR BREAK KEY
  3047 0000104E 7314                <1> 	jae	short K26		; NOTHING FOR BREAK CHARS FROM HERE ON
  3048 00001050 F605[72BE0000]08    <1> 	test	byte [KB_FLAG_1], HOLD_STATE ; ARE WE IN HOLD STATE
  3049 00001057 7428                <1> 	jz	short K28		; BRANCH AROUND TEST IF NOT
  3050 00001059 3C45                <1> 	cmp	al, NUM_KEY
  3051 0000105B 7407                <1> 	je	short K26		; CAN'T END HOLD ON NUM_LOCK
  3052 0000105D 8025[72BE0000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
  3053                              <1> 	;
  3054                              <1> K26:
  3055 00001064 8025[74BE0000]FC    <1> 	and	byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  3056                              <1> K26A:					; INTERRUPT-RETURN
  3057 0000106B FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3058 0000106C B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  3059 0000106E E620                <1> 	out	20h, al	;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  3060                              <1> K27:					; INTERRUPT-RETURN-NO-EOI
  3061 00001070 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3062 00001072 E8F8020000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3063                              <1> K27A:
  3064 00001077 FA                  <1> 	cli				; DISABLE INTERRUPTS
  3065 00001078 07                  <1> 	pop	es			; RESTORE REGISTERS
  3066 00001079 1F                  <1> 	pop	ds
  3067 0000107A 5F                  <1> 	pop	edi
  3068 0000107B 5E                  <1> 	pop	esi
  3069 0000107C 5A                  <1> 	pop	edx
  3070 0000107D 59                  <1> 	pop	ecx
  3071 0000107E 5B                  <1> 	pop	ebx
  3072 0000107F 58                  <1> 	pop	eax
  3073                              <1> 	;pop	ebp
  3074 00001080 CF                  <1> 	iret				; RETURN
  3075                              <1> 
  3076                              <1> 	;-----	NOT IN	HOLD STATE
  3077                              <1> K28:					; NO-HOLD-STATE
  3078 00001081 3C58                <1> 	cmp	al, 88			; TEST FOR OUT-OF-RANGE SCAN CODES
  3079 00001083 77DF                <1> 	ja	short K26		; IGNORE IF OUT-OF-RANGE	
  3080                              <1> 	;
  3081 00001085 F6C308              <1> 	test	bl, ALT_SHIFT 		; ARE WE IN ALTERNATE SHIFT
  3082                              <1>         ;jz	short K28A		; IF NOT ALTERNATE
  3083 00001088 0F84F1000000        <1>         jz      K38
  3084                              <1> 	;
  3085 0000108E F6C710              <1> 	test	bh, KBX			; IS THIS THE ENCHANCED KEYBOARD?
  3086 00001091 740D                <1> 	jz	short K29		; NO, ALT STATE IS REAL
  3087                              <1> 	 ;28/02/2015
  3088 00001093 F605[72BE0000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
  3089                              <1> 	;jz	short K29		;  NO, ALT STATE IS REAL
  3090 0000109A 0F85DF000000        <1> 	jnz	K38			; YES, THIS IS PHONY ALT STATE 
  3091                              <1>         ;				; DUE TO PRESSING SYSREQ	
  3092                              <1> ;K28A:	jmp	short K38
  3093                              <1> 	;
  3094                              <1> 	;-----	TEST FOR RESET KEY SEQUENCE (CTL ALT DEL)
  3095                              <1> K29:					; TEST-RESET
  3096 000010A0 F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT ALSO?
  3097 000010A3 740B                <1> 	jz	short K31		; NO_RESET
  3098 000010A5 3C53                <1> 	cmp	al, DEL_KEY		; CTL-ALT STATE, TEST FOR DELETE KEY
  3099 000010A7 7507                <1> 	jne	short K31		; NO_RESET, IGNORE
  3100                              <1> 	;
  3101                              <1> 	;-----	CTL-ALT-DEL HAS BEEN FOUND
  3102                              <1>  	; 26/08/2014
  3103                              <1> cpu_reset:
  3104                              <1> 	; IBM PC/AT ROM BIOS source code - 10/06/85 (TEST4.ASM - PROC_SHUTDOWN)
  3105                              <1> 	; Send FEh (system reset command) to the keyboard controller.
  3106 000010A9 B0FE                <1> 	mov	al, SHUT_CMD		; SHUTDOWN COMMAND
  3107 000010AB E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROL PORT
  3108                              <1> khere:
  3109 000010AD F4                  <1> 	hlt				; WAIT FOR 80286 RESET
  3110 000010AE EBFD                <1> 	jmp 	short khere		; INSURE HALT
  3111                              <1> 
  3112                              <1> 	;
  3113                              <1> 	;-----	IN ALTERNATE SHIFT, RESET NOT FOUND
  3114                              <1> K31:					; NO-RESET
  3115 000010B0 3C39                <1> 	cmp	al, 57			; TEST FOR SPACE KEY
  3116 000010B2 7507                <1> 	jne	short K311		; NOT THERE
  3117 000010B4 B020                <1> 	mov	al, ' '			; SET SPACE CHAR
  3118 000010B6 E948020000          <1>         jmp     K57                     ; BUFFER_FILL
  3119                              <1> K311:
  3120 000010BB 3C0F                <1> 	cmp	al, 15			; TEST FOR TAB KEY
  3121 000010BD 7509                <1> 	jne	short K312		; NOT THERE
  3122 000010BF 66B800A5            <1> 	mov	ax, 0A500h		; SET SPECIAL CODE FOR ALT-TAB
  3123 000010C3 E93B020000          <1>         jmp     K57                     ; BUFFER_FILL
  3124                              <1> K312:
  3125 000010C8 3C4A                <1> 	cmp	al, 74			; TEST FOR KEY PAD -
  3126 000010CA 0F84A2000000        <1>         je      K37B                    ; GO PROCESS
  3127 000010D0 3C4E                <1> 	cmp	al, 78			; TEST FOR KEY PAD +
  3128 000010D2 0F849A000000        <1>         je      K37B                    ; GO PROCESS
  3129                              <1> 	;
  3130                              <1> 	;-----	LOOK FOR KEY PAD ENTRY
  3131                              <1> K32:					; ALT-KEY-PAD
  3132 000010D8 BF[34BD0000]        <1> 	mov	edi, K30		; ALT-INPUT-TABLE offset
  3133 000010DD B90A000000          <1> 	mov	ecx, 10			; LOOK FOR ENTRY USING KEYPAD
  3134 000010E2 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH
  3135 000010E4 7525                <1> 	jne	short K33		; NO_ALT_KEYPAD
  3136 000010E6 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF THE NEW KEYS?
  3137 000010E9 0F858A000000        <1>         jnz     K37C                    ; YES, JUMP, NOT NUMPAD KEY
  3138 000010EF 81EF[35BD0000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
  3139 000010F5 A0[75BE0000]        <1> 	mov	al, [ALT_INPUT] 	; GET THE CURRENT BYTE
  3140 000010FA B40A                <1> 	mov	ah, 10			; MULTIPLY BY 10
  3141 000010FC F6E4                <1> 	mul	ah
  3142 000010FE 6601F8              <1> 	add	ax, di			; ADD IN THE LATEST ENTRY
  3143 00001101 A2[75BE0000]        <1> 	mov	[ALT_INPUT], al 	; STORE IT AWAY
  3144                              <1> ;K32A:
  3145 00001106 E959FFFFFF          <1>         jmp     K26                     ; THROW AWAY THAT KEYSTROKE
  3146                              <1> 	;
  3147                              <1> 	;-----	LOOK FOR SUPERSHIFT ENTRY
  3148                              <1> K33:					; NO-ALT-KEYPAD
  3149 0000110B C605[75BE0000]00    <1>         mov     byte [ALT_INPUT], 0     ; ZERO ANY PREVIOUS ENTRY INTO INPUT
  3150 00001112 B91A000000          <1> 	mov	ecx, 26			; (DI),(ES) ALREADY POINTING
  3151 00001117 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH IN ALPHABET
  3152 00001119 7450                <1> 	je	short K37A		; MATCH FOUND, GO FILLL THE BUFFER
  3153                              <1> 	;
  3154                              <1> 	;-----	LOOK FOR TOP ROW OF ALTERNATE SHIFT
  3155                              <1> K34:					; ALT-TOP-ROW
  3156 0000111B 3C02                <1> 	cmp	al, 2			; KEY WITH '1' ON IT
  3157 0000111D 7253                <1> 	jb	short K37B		; MUST BE ESCAPE
  3158 0000111F 3C0D                <1> 	cmp	al, 13			; IS IT IN THE REGION
  3159 00001121 7705                <1> 	ja	short K35		; NO, ALT SOMETHING ELSE
  3160 00001123 80C476              <1> 	add	ah, 118			; CONVERT PSEUDO SCAN CODE TO RANGE
  3161 00001126 EB43                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  3162                              <1> 	;
  3163                              <1> 	;-----	TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
  3164                              <1> K35:					; ALT-FUNCTION
  3165 00001128 3C57                <1> 	cmp	al, F11_M		; IS IT F11?	
  3166 0000112A 7209                <1> 	jb	short K35A ; 20/02/2015	; NO, BRANCH
  3167 0000112C 3C58                <1> 	cmp	al, F12_M		; IS IT F12?
  3168 0000112E 7705                <1> 	ja	short K35A ; 20/02/2015	; NO, BRANCH
  3169 00001130 80C434              <1> 	add	ah, 52			; CONVERT TO PSEUDO SCAN CODE
  3170 00001133 EB36                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  3171                              <1> K35A:
  3172 00001135 F6C702              <1> 	test	bh, LC_E0		; DO WE HAVE ONE OF THE NEW KEYS?
  3173 00001138 7422                <1> 	jz	short K37		; NO, JUMP
  3174 0000113A 3C1C                <1> 	cmp	al, 28			; TEST FOR KEYPAD ENTER
  3175 0000113C 7509                <1>         jne     short K35B              ; NOT THERE
  3176 0000113E 66B800A6            <1> 	mov	ax, 0A600h		; SPECIAL CODE
  3177 00001142 E9BC010000          <1> 	jmp	K57			; BUFFER FILL
  3178                              <1> K35B:
  3179 00001147 3C53                <1> 	cmp	al, 83			; TEST FOR DELETE KEY
  3180 00001149 742E                <1> 	je	short K37C		; HANDLE WITH OTHER EDIT KEYS
  3181 0000114B 3C35                <1> 	cmp	al, 53			; TEST FOR KEYPAD /
  3182                              <1> 	;jne	short K32A		; NOT THERE, NO OTHER E0 SPECIALS	
  3183 0000114D 0F8511FFFFFF        <1>         jne     K26
  3184 00001153 66B800A4            <1> 	mov	ax, 0A400h		; SPECIAL CODE
  3185 00001157 E9A7010000          <1> 	jmp	K57			; BUFFER FILL
  3186                              <1> K37:
  3187 0000115C 3C3B                <1> 	cmp	al, 59			; TEST FOR FUNCTION KEYS (F1)
  3188 0000115E 7212                <1>         jb      short K37B		; NO FN, HANDLE W/OTHER EXTENDED
  3189 00001160 3C44                <1> 	cmp	al, 68			; IN KEYPAD REGION?
  3190                              <1>         ;ja	short K32A		; IF SO, IGNORE
  3191 00001162 0F87FCFEFFFF        <1>         ja      K26
  3192 00001168 80C42D              <1> 	add	ah, 45			; CONVERT TO PSEUDO SCAN CODE
  3193                              <1> K37A:
  3194 0000116B B000                <1> 	mov	al, 0			; ASCII CODE OF ZERO
  3195 0000116D E991010000          <1>         jmp     K57                     ; PUT IT IN THE BUFFER
  3196                              <1> K37B:
  3197 00001172 B0F0                <1> 	mov	al, 0F0h		; USE SPECIAL ASCII CODE
  3198 00001174 E98A010000          <1> 	jmp     K57                     ; PUT IT IN THE BUFFER
  3199                              <1> K37C:
  3200 00001179 0450                <1> 	add	al, 80			; CONVERT SCAN CODE (EDIT KEYS)
  3201 0000117B 88C4                <1> 	mov	ah, al			; (SCAN CODE NOT IN AH FOR INSERT)
  3202 0000117D EBEC                <1> 	jmp     short K37A              ; PUT IT IN THE BUFFER
  3203                              <1> 	;
  3204                              <1> 	;-----	NOT IN ALTERNATE SHIFT
  3205                              <1> K38:					; NOT-ALT-SHIFT
  3206                              <1> 					; BL STILL HAS SHIFT FLAGS
  3207 0000117F F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT?
  3208                              <1> 	;jnz	short K38A		; YES, START PROCESSING	
  3209 00001182 0F84B0000000        <1>         jz      K44                     ; NOT-CTL-SHIFT
  3210                              <1> 	;
  3211                              <1> 	;-----	CONTROL SHIFT, TEST SPECIAL CHARACTERS
  3212                              <1> 	;-----	TEST FOR BREAK
  3213                              <1> K38A:
  3214 00001188 3C46                <1> 	cmp	al, SCROLL_KEY		; TEST FOR BREAK
  3215 0000118A 7531                <1> 	jne	short K39		; JUMP, NO-BREAK
  3216 0000118C F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3217 0000118F 7405                <1> 	jz	short K38B		; NO, BREAK IS VALID	
  3218 00001191 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  3219 00001194 7427                <1> 	jz	short K39		; NO-BREAK, TEST FOR PAUSE	
  3220                              <1> K38B:
  3221 00001196 8B1D[7EBE0000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  3222 0000119C 891D[82BE0000]      <1> 	mov	[BUFFER_TAIL], ebx
  3223 000011A2 C605[70BE0000]80    <1> 	mov	byte [BIOS_BREAK], 80h  ; TURN ON BIOS_BREAK BIT
  3224                              <1> 	;
  3225                              <1> 	;-----	ENABLE KEYBOARD
  3226 000011A9 B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  3227 000011AB E8BF010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3228                              <1> 	;
  3229                              <1> 	; CTRL+BREAK code here !!!
  3230                              <1> 	;INT	1BH			; BREAK INTERRUPT VECTOR
  3231                              <1> 	; 17/10/2015	
  3232 000011B0 E88D2D0000          <1> 	call	ctrlbrk ; control+break subroutine
  3233                              <1> 	;
  3234 000011B5 6629C0              <1> 	sub	ax, ax			; PUT OUT DUMMY CHARACTER
  3235 000011B8 E946010000          <1>         jmp     K57                     ; BUFFER_FILL
  3236                              <1> 	;
  3237                              <1> 	;-----	TEST FOR PAUSE
  3238                              <1> K39:					; NO_BREAK
  3239 000011BD F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3240 000011C0 7537                <1> 	jnz	short K41		; YES, THEN THIS CAN'T BE PAUSE	
  3241 000011C2 3C45                <1> 	cmp	al, NUM_KEY		; LOOK FOR PAUSE KEY
  3242 000011C4 7533                <1> 	jne	short K41		; NO-PAUSE
  3243                              <1> K39P:
  3244 000011C6 800D[72BE0000]08    <1> 	or	byte [KB_FLAG_1], HOLD_STATE ; TURN ON THE HOLD FLAG
  3245                              <1> 	;
  3246                              <1> 	;-----	ENABLE KEYBOARD
  3247 000011CD B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  3248 000011CF E89B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3249                              <1> K39A:
  3250 000011D4 B020                <1> 	mov	al, EOI			; END OF INTERRUPT TO CONTROL PORT
  3251 000011D6 E620                <1> 	out	20h, al ;out INTA00, al	; ALLOW FURTHER KEYSTROKE INTERRUPTS
  3252                              <1> 	;
  3253                              <1> 	;-----	DURING PAUSE INTERVAL, TURN COLOR CRT BACK ON
  3254 000011D8 803D[A6BE0000]07    <1>         cmp     byte [CRT_MODE], 7      ; IS THIS BLACK AND WHITE CARD
  3255 000011DF 740A                <1>         je      short K40              	; YES, NOTHING TO DO
  3256 000011E1 66BAD803            <1> 	mov	dx, 03D8h		; PORT FOR COLOR CARD
  3257 000011E5 A0[A7BE0000]        <1>         mov     al, [CRT_MODE_SET] 	; GET THE VALUE OF THE CURRENT MODE
  3258 000011EA EE                  <1> 	out	dx, al			; SET THE CRT MODE, SO THAT CRT IS ON
  3259                              <1> 	;
  3260                              <1> K40:					; PAUSE-LOOP
  3261 000011EB F605[72BE0000]08    <1>         test    byte [KB_FLAG_1], HOLD_STATE ; CHECK HOLD STATE FLAG
  3262 000011F2 75F7                <1> 	jnz	short K40		; LOOP UNTIL FLAG TURNED OFF
  3263                              <1> 	;
  3264 000011F4 E977FEFFFF          <1>         jmp     K27                     ; INTERRUPT_RETURN_NO_EOI
  3265                              <1>         ;
  3266                              <1> 	;-----	TEST SPECIAL CASE KEY 55
  3267                              <1> K41:					; NO-PAUSE
  3268 000011F9 3C37                <1> 	cmp	al, 55			; TEST FOR */PRTSC KEY
  3269 000011FB 7513                <1> 	jne	short K42		; NOT-KEY-55
  3270 000011FD F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3271 00001200 7405                <1> 	jz	short K41A		; NO, CTL-PRTSC IS VALID	
  3272 00001202 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  3273 00001205 7421                <1> 	jz	short K42B		; NO, TRANSLATE TO A FUNCTION
  3274                              <1> K41A:	
  3275 00001207 66B80072            <1> 	mov	ax, 114*256		; START/STOP PRINTING SWITCH
  3276 0000120B E9F3000000          <1>         jmp     K57                     ; BUFFER_FILL
  3277                              <1> 	;
  3278                              <1> 	;-----	SET UP TO TRANSLATE CONTROL SHIFT
  3279                              <1> K42:					; NOT-KEY-55
  3280 00001210 3C0F                <1> 	cmp	al, 15			; IS IT THE TAB KEY?
  3281 00001212 7414                <1> 	je	short K42B		; YES, XLATE TO FUNCTION CODE
  3282 00001214 3C35                <1> 	cmp	al, 53			; IS IT THE / KEY?
  3283 00001216 750E                <1> 	jne	short K42A		; NO, NO MORE SPECIAL CASES	
  3284 00001218 F6C702              <1> 	test	bh, LC_E0		; YES, IS IT FROM THE KEY PAD?
  3285 0000121B 7409                <1> 	jz	short K42A		; NO, JUST TRANSLATE
  3286 0000121D 66B80095            <1> 	mov	ax, 9500h		; YES, SPECIAL CODE FOR THIS ONE
  3287 00001221 E9DD000000          <1> 	jmp	K57			; BUFFER FILL	
  3288                              <1> K42A: 
  3289                              <1> 	;;mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  3290 00001226 3C3B                <1> 	cmp	al, 59			; IS IT IN CHARACTER TABLE?
  3291                              <1>         ;jb	short K45F              ; YES, GO TRANSLATE CHAR
  3292                              <1> 	;;jb	K56 ; 20/02/2015
  3293                              <1> 	;;jmp	K64 ; 20/02/2015
  3294                              <1> K42B:
  3295 00001228 BB[68BD0000]        <1> 	mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  3296 0000122D 0F82AE000000        <1> 	jb	K56 ;; 20/02/2015	
  3297 00001233 E9B9000000          <1> 	jmp	K64	
  3298                              <1>         ;
  3299                              <1> 	;-----	NOT IN CONTROL SHIFT
  3300                              <1> K44:					; NOT-CTL-SHIFT
  3301 00001238 3C37                <1> 	cmp	al, 55			; PRINT SCREEN KEY?
  3302 0000123A 7528                <1> 	jne	short K45		; NOT PRINT SCREEN
  3303 0000123C F6C710              <1> 	test	bh, KBX			; IS THIS ENHANCED KEYBOARD?
  3304 0000123F 7407                <1> 	jz	short K44A		; NO, TEST FOR SHIFT STATE	
  3305 00001241 F6C702              <1> 	test	bh, LC_E0		; YES, LAST CODE A MARKER?
  3306 00001244 7507                <1> 	jnz	short K44B		; YES, IS PRINT SCREEN
  3307 00001246 EB41                <1> 	jmp	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  3308                              <1> K44A:
  3309 00001248 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; NOT 101 KBD, SHIFT KEY DOWN?
  3310 0000124B 743C                <1> 	jz	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  3311                              <1> 	;
  3312                              <1> 	;-----	ISSUE INTERRUPT TO INDICATE PRINT SCREEN FUNCTION
  3313                              <1> K44B:
  3314 0000124D B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3315 0000124F E81B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3316 00001254 B020                <1> 	mov	al, EOI			; END OF CURRENT INTERRUPT
  3317 00001256 E620                <1> 	out	20h, al ;out INTA00, al	; SO FURTHER THINGS CAN HAPPEN
  3318                              <1> 	; Print Screen !!!		; ISSUE PRINT SCREEN INTERRUPT (INT 05h)
  3319                              <1> 	;PUSH 	BP			; SAVE POINTER
  3320                              <1> 	;INT 	5H			; ISSUE PRINT SCREEN INTERRUPT
  3321                              <1> 	;POP	BP			; RESTORE POINTER
  3322 00001258 8025[74BE0000]FC    <1>         and     byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; ZERO OUT THESE FLAGS
  3323 0000125F E90CFEFFFF          <1>         jmp     K27                     ; GO BACK WITHOUT EOI OCCURRING
  3324                              <1> 	;
  3325                              <1> 	;-----	HANDLE IN-CORE KEYS
  3326                              <1> K45:					; NOT-PRINT-SCREEN
  3327 00001264 3C3A                <1> 	cmp	al, 58			; TEST FOR IN-CORE AREA
  3328 00001266 7734                <1> 	ja	short K46		; JUMP IF NOT
  3329 00001268 3C35                <1> 	cmp	al, 53			; IS THIS THE '/' KEY?
  3330 0000126A 7505                <1> 	jne	short K45A		; NO, JUMP
  3331 0000126C F6C702              <1> 	test	bh, LC_E0		; WAS THE LAST CODE THE MARKER?
  3332 0000126F 7518                <1> 	jnz	short K45C		; YES, TRANSLATE TO CHARACTER
  3333                              <1> K45A:
  3334 00001271 B91A000000          <1> 	mov	ecx, 26			; LENGHT OF SEARCH
  3335 00001276 BF[3EBD0000]        <1> 	mov	edi, K30+10		; POINT TO TABLE OF A-Z CHARS
  3336 0000127B F2AE                <1> 	repne	scasb			; IS THIS A LETTER KEY?
  3337                              <1> 		; 20/02/2015
  3338 0000127D 7505                <1> 	jne	short K45B              ; NO, SYMBOL KEY
  3339                              <1> 	;
  3340 0000127F F6C340              <1> 	test	bl, CAPS_STATE		; ARE WE IN CAPS_LOCK?
  3341 00001282 750C                <1> 	jnz	short K45D		; TEST FOR SURE
  3342                              <1> K45B:
  3343 00001284 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  3344 00001287 750C                <1> 	jnz	short K45E		; YES, UPPERCASE
  3345                              <1> 					; NO, LOWERCASE
  3346                              <1> K45C:
  3347 00001289 BB[C0BD0000]        <1> 	mov	ebx, K10		; TRANSLATE TO LOWERCASE LETTERS
  3348 0000128E EB51                <1> 	jmp	short K56	
  3349                              <1> K45D:					; ALMOST-CAPS-STATE
  3350 00001290 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  3351 00001293 75F4                <1> 	jnz	short K45C		; SHIFTED TEMP OUT OF CAPS STATE
  3352                              <1> K45E:
  3353 00001295 BB[18BE0000]        <1> 	mov	ebx, K11		; TRANSLATE TO UPPER CASE LETTERS
  3354 0000129A EB45                <1> K45F:	jmp	short K56
  3355                              <1> 	;
  3356                              <1> 	;-----	TEST FOR KEYS F1 - F10
  3357                              <1> K46:					; NOT IN-CORE AREA
  3358 0000129C 3C44                <1> 	cmp	al, 68			; TEST FOR F1 - F10
  3359                              <1> 	;ja	short K47		; JUMP IF NOT
  3360                              <1> 	;jmp	short K53		; YES, GO DO FN KEY PROCESS			
  3361 0000129E 7635                <1> 	jna	short K53		
  3362                              <1> 	;
  3363                              <1> 	;-----	HANDLE THE NUMERIC PAD KEYS
  3364                              <1> K47:					; NOT F1 - F10
  3365 000012A0 3C53                <1> 	cmp	al, 83			; TEST NUMPAD KEYS
  3366 000012A2 772D                <1> 	ja	short K52		; JUMP IF NOT
  3367                              <1> 	;
  3368                              <1> 	;-----	KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  3369                              <1> K48:
  3370 000012A4 3C4A                <1> 	cmp	al , 74			; SPECIAL CASE FOR MINUS
  3371 000012A6 74ED                <1> 	je	short K45E		; GO TRANSLATE
  3372 000012A8 3C4E                <1> 	cmp	al , 78			; SPECIAL CASE FOR PLUS
  3373 000012AA 74E9                <1> 	je	short K45E		; GO TRANSLATE
  3374 000012AC F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OFTHE NEW KEYS?
  3375 000012AF 750A                <1> 	jnz	short K49		; YES, TRANSLATE TO BASE STATE
  3376                              <1> 	;		
  3377 000012B1 F6C320              <1> 	test 	bl, NUM_STATE		; ARE WE IN NUM LOCK
  3378 000012B4 7514                <1> 	jnz	short K50		; TEST FOR SURE
  3379 000012B6 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  3380                              <1> 	;jnz	short K51		; IF SHIFTED, REALLY NUM STATE
  3381 000012B9 75DA                <1> 	jnz	short K45E
  3382                              <1> 	;
  3383                              <1> 	;-----	BASE CASE FOR KEYPAD
  3384                              <1> K49:					
  3385 000012BB 3C4C                <1> 	cmp	al, 76			; SPECIAL CASE FOR BASE STATE 5
  3386 000012BD 7504                <1> 	jne	short K49A		; CONTINUE IF NOT KEYPAD 5
  3387 000012BF B0F0                <1> 	mov	al, 0F0h		; SPECIAL ASCII CODE	
  3388 000012C1 EB40                <1> 	jmp	short K57		; BUFFER FILL
  3389                              <1> K49A:
  3390 000012C3 BB[C0BD0000]        <1> 	mov	ebx, K10		; BASE CASE TABLE	
  3391 000012C8 EB27                <1> 	jmp	short K64		; CONVERT TO PSEUDO SCAN
  3392                              <1> 	;
  3393                              <1> 	;-----	MIGHT BE NUM LOCK, TEST SHIFT STATUS
  3394                              <1> K50:					; ALMOST-NUM-STATE
  3395 000012CA F6C303              <1>         test    bl, LEFT_SHIFT+RIGHT_SHIFT
  3396 000012CD 75EC                <1> 	jnz 	short K49		; SHIFTED TEMP OUT OF NUM STATE
  3397 000012CF EBC4                <1> K51:	jmp	short K45E		; REALLY NUM STATE
  3398                              <1> 	;
  3399                              <1> 	;-----	TEST FOR THE NEW KEYS ON WT KEYBOARDS 
  3400                              <1> K52:					; NOT A NUMPAD KEY
  3401 000012D1 3C56                <1> 	cmp	al, 86			; IS IT THE NEW WT KEY?
  3402                              <1> 	;jne	short K53		; JUMP IF NOT
  3403                              <1> 	;jmp	short K45B		; HANDLE WITH REST OF LETTER KEYS
  3404 000012D3 74AF                <1> 	je	short K45B		
  3405                              <1> 	;
  3406                              <1> 	;-----	MUST BE F11 OR F12 
  3407                              <1> K53:					; F1 - F10 COME HERE, TOO
  3408 000012D5 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST SHIFT STATE
  3409 000012D8 74E1                <1> 	jz	short K49		; JUMP, LOWER CASE PSEUDO SC'S
  3410                              <1> 		; 20/02/2015 
  3411 000012DA BB[18BE0000]        <1> 	mov	ebx, K11		; UPPER CASE PSEUDO SCAN CODES
  3412 000012DF EB10                <1> 	jmp	short K64		; TRANSLATE SCAN
  3413                              <1> 	;
  3414                              <1> 	;-----	TRANSLATE THE CHARACTER
  3415                              <1> K56:					; TRANSLATE-CHAR
  3416 000012E1 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  3417 000012E3 D7                  <1> 	xlat    			; CONVERT THE SCAN CODE TO ASCII
  3418 000012E4 F605[74BE0000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  3419 000012EB 7416                <1> 	jz	short K57		; NO, GO FILL BUFFER
  3420 000012ED B4E0                <1> 	mov	ah, MC_E0		; YES, PUT SPECIAL MARKER IN AH
  3421 000012EF EB12                <1> 	jmp	short K57		; PUT IT INTO THE BUFFER	
  3422                              <1> 	;
  3423                              <1> 	;-----	TRANSLATE SCAN FOR PSEUDO SCAN CODES
  3424                              <1> K64:					; TRANSLATE-SCAN-ORGD
  3425 000012F1 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  3426 000012F3 D7                  <1>        	xlat    	                ; CTL TABLE SCAN
  3427 000012F4 88C4                <1> 	mov	ah, al			; PUT VALUE INTO AH
  3428 000012F6 B000                <1> 	mov	al, 0			; ZERO ASCII CODE
  3429 000012F8 F605[74BE0000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  3430 000012FF 7402                <1> 	jz	short K57		; NO, GO FILL BUFFER
  3431 00001301 B0E0                <1> 	mov	al, MC_E0		; YES, PUT SPECIAL MARKER IN AL
  3432                              <1> 	;
  3433                              <1> 	;-----	PUT CHARACTER INTO BUFFER
  3434                              <1> K57:					; BUFFER_FILL
  3435 00001303 3CFF                <1> 	cmp	al, -1			; IS THIS AN IGNORE CHAR
  3436                              <1>         ;je	short K59		; YES, DO NOTHING WITH IT
  3437 00001305 0F8459FDFFFF        <1> 	je      K26			; YES, DO NOTHING WITH IT
  3438 0000130B 80FCFF              <1> 	cmp	ah, -1			; LOOK FOR -1 PSEUDO SCAN
  3439                              <1>         ;jne	short K61		; NEAR_INTERRUPT_RETURN
  3440 0000130E 0F8450FDFFFF        <1> 	je      K26			; INTERRUPT_RETURN
  3441                              <1> ;K59:					; NEAR_INTERRUPT_RETURN
  3442                              <1> ;	jmp	K26			; INTERRUPT_RETURN
  3443                              <1> 
  3444                              <1> _K60: ; 29/01/2016
  3445 00001314 80FC68              <1> 	cmp	ah, 68h	; ALT + F1 key
  3446 00001317 721F                <1> 	jb	short K61
  3447 00001319 80FC6F              <1> 	cmp	ah, 6Fh ; ALT + F8 key	
  3448 0000131C 771A                <1> 	ja	short K61
  3449                              <1> 	;
  3450 0000131E 8A1D[A8C40000]      <1> 	mov	bl, [ACTIVE_PAGE]
  3451 00001324 80C368              <1> 	add	bl, 68h
  3452 00001327 38E3                <1> 	cmp	bl, ah
  3453 00001329 740D                <1> 	je	short K61
  3454 0000132B 6650                <1> 	push	ax
  3455 0000132D 88E0                <1> 	mov	al, ah
  3456 0000132F 2C68                <1> 	sub	al, 68h
  3457 00001331 E85E020000          <1> 	call	set_active_page
  3458 00001336 6658                <1> 	pop	ax
  3459                              <1> K61:					; NOT-CAPS-STATE
  3460 00001338 8B1D[82BE0000]      <1> 	mov	ebx, [BUFFER_TAIL] 	; GET THE END POINTER TO THE BUFFER
  3461 0000133E 89DE                <1> 	mov	esi, ebx		; SAVE THE VALUE
  3462 00001340 E857FAFFFF          <1> 	call	_K4			; ADVANCE THE TAIL
  3463 00001345 3B1D[7EBE0000]      <1> 	cmp	ebx, [BUFFER_HEAD] 	; HAS THE BUFFER WRAPPED AROUND
  3464 0000134B 740E                <1> 	je	short K62		; BUFFER_FULL_BEEP
  3465 0000134D 668906              <1> 	mov	[esi], ax		; STORE THE VALUE
  3466 00001350 891D[82BE0000]      <1> 	mov	[BUFFER_TAIL], ebx 	; MOVE THE POINTER UP
  3467 00001356 E909FDFFFF          <1> 	jmp	K26
  3468                              <1> 	;;cli				; TURN OFF INTERRUPTS
  3469                              <1> 	;;mov	al, EOI			; END OF INTERRUPT COMMAND
  3470                              <1> 	;;out	INTA00, al		; SEND COMMAND TO INTERRUPT CONTROL PORT
  3471                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3472                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  3473                              <1> 	;MOV	AX, 9102H		; MOVE IN POST CODE & TYPE
  3474                              <1> 	;INT	15H			; PERFORM OTHER FUNCTION
  3475                              <1> 	;;and	byte [KB_FLAG_3],~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  3476                              <1> 	;JMP	K27A			; INTERRUPT_RETURN
  3477                              <1> 	;;jmp   K27                    
  3478                              <1> 	;
  3479                              <1> 	;-----	BUFFER IS FULL SOUND THE BEEPER
  3480                              <1> K62:
  3481 0000135B B020                <1> 	mov	al, EOI			; ENABLE INTERRUPT CONTROLLER CHIP
  3482 0000135D E620                <1> 	out	INTA00, al
  3483 0000135F 66B9A602            <1> 	mov	cx, 678			; DIVISOR FOR 1760 HZ
  3484 00001363 B304                <1> 	mov	bl, 4			; SHORT BEEP COUNT (1/16 + 1/64 DELAY)
  3485 00001365 E83A050000          <1> 	call	beep			; GO TO COMMON BEEP HANDLER
  3486 0000136A E901FDFFFF          <1> 	jmp     K27			; EXIT   
  3487                              <1> 
  3488                              <1> SHIP_IT:
  3489                              <1> 	;---------------------------------------------------------------------------------
  3490                              <1> 	; SHIP_IT
  3491                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  3492                              <1> 	;	TO THE KEYBOARD CONTROLLER.
  3493                              <1> 	;---------------------------------------------------------------------------------
  3494                              <1> 	;
  3495 0000136F 6650                <1> 	push	ax			; SAVE DATA TO SEND
  3496                              <1> 
  3497                              <1> 	;-----	WAIT FOR COMMAND TO ACCEPTED
  3498 00001371 FA                  <1> 	cli				; DISABLE INTERRUPTS TILL DATA SENT
  3499                              <1> 	; xor	ecx, ecx		; CLEAR TIMEOUT COUNTER
  3500 00001372 B900000100          <1> 	mov	ecx, 10000h			
  3501                              <1> S10:
  3502 00001377 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD CONTROLLER STATUS
  3503 00001379 A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ITS INPUT BUFFER BUSY
  3504 0000137B E0FA                <1> 	loopnz	S10			; WAIT FOR COMMAND TO BE ACCEPTED
  3505                              <1> 
  3506 0000137D 6658                <1> 	pop	ax			; GET DATA TO SEND
  3507 0000137F E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROLLER
  3508 00001381 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  3509 00001382 C3                  <1> 	retn				; RETURN TO CALLER
  3510                              <1> 
  3511                              <1> SND_DATA:
  3512                              <1> 	; ---------------------------------------------------------------------------------
  3513                              <1> 	; SND_DATA
  3514                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  3515                              <1> 	;	TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  3516                              <1> 	;	HANDLES ANY RETRIES IF REQUIRED
  3517                              <1> 	; ---------------------------------------------------------------------------------
  3518                              <1> 	;
  3519 00001383 6650                <1> 	push	ax			; SAVE REGISTERS
  3520 00001385 6653                <1> 	push	bx
  3521 00001387 51                  <1> 	push	ecx
  3522 00001388 88C7                <1> 	mov	bh, al			; SAVE TRANSMITTED BYTE FOR RETRIES
  3523 0000138A B303                <1> 	mov	bl, 3			; LOAD RETRY COUNT
  3524                              <1> SD0:
  3525 0000138C FA                  <1> 	cli				; DISABLE INTERRUPTS
  3526 0000138D 8025[73BE0000]CF    <1> 	and	byte [KB_FLAG_2], ~(KB_FE+KB_FA) ; CLEAR ACK AND RESEND FLAGS
  3527                              <1> 	;
  3528                              <1> 	;-----	WAIT FOR COMMAND TO BE ACCEPTED
  3529 00001394 B900000100          <1> 	mov	ecx, 10000h		; MAXIMUM WAIT COUNT
  3530                              <1> SD5:
  3531 00001399 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD PROCESSOR STATUS PORT
  3532 0000139B A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ANY PENDING COMMAND
  3533 0000139D E0FA                <1> 	loopnz	SD5			; WAIT FOR COMMAND TO BE ACCEPTED
  3534                              <1> 	;
  3535 0000139F 88F8                <1> 	mov	al, bh			; REESTABLISH BYTE TO TRANSMIT
  3536 000013A1 E660                <1> 	out	PORT_A, al		; SEND BYTE
  3537 000013A3 FB                  <1> 	sti				; ENABLE INTERRUPTS
  3538                              <1> 	;mov	cx, 01A00h		; LOAD COUNT FOR 10 ms+
  3539 000013A4 B9FFFF0000          <1> 	mov	ecx, 0FFFFh
  3540                              <1> SD1:
  3541 000013A9 F605[73BE0000]30    <1> 	test	byte [KB_FLAG_2], KB_FE+KB_FA ; SEE IF EITHER BIT SET
  3542 000013B0 750F                <1> 	jnz	short SD3		; IF SET, SOMETHING RECEIVED GO PROCESS
  3543 000013B2 E2F5                <1> 	loop	SD1			; OTHERWISE WAIT
  3544                              <1> SD2:
  3545 000013B4 FECB                <1> 	dec	bl			; DECREMENT RETRY COUNT
  3546 000013B6 75D4                <1> 	jnz	short SD0		; RETRY TRANSMISSION
  3547 000013B8 800D[73BE0000]80    <1> 	or	byte [KB_FLAG_2], KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  3548 000013BF EB09                <1> 	jmp	short SD4		; RETRIES EXHAUSTED FORGET TRANSMISSION
  3549                              <1> SD3:
  3550 000013C1 F605[73BE0000]10    <1> 	test	byte [KB_FLAG_2], KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  3551 000013C8 74EA                <1> 	jz	short SD2		; IF NOT, GO RESEND
  3552                              <1> SD4:	
  3553 000013CA 59                  <1> 	pop	ecx			; RESTORE REGISTERS
  3554 000013CB 665B                <1> 	pop	bx
  3555 000013CD 6658                <1> 	pop	ax
  3556 000013CF C3                  <1> 	retn				; RETURN, GOOD TRANSMISSION
  3557                              <1> 
  3558                              <1> SND_LED:
  3559                              <1> 	; ---------------------------------------------------------------------------------
  3560                              <1> 	; SND_LED
  3561                              <1> 	;	THIS ROUTINES TURNS ON THE MODE INDICATORS.
  3562                              <1> 	;
  3563                              <1> 	;----------------------------------------------------------------------------------
  3564                              <1> 	;
  3565 000013D0 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3566 000013D1 F605[73BE0000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  3567 000013D8 755F                <1> 	jnz 	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  3568                              <1> 	;
  3569 000013DA 800D[73BE0000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  3570 000013E1 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  3571 000013E3 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  3572 000013E5 EB11                <1> 	jmp	short SL0		; GO SEND MODE INDICATOR COMMAND
  3573                              <1> SND_LED1:
  3574 000013E7 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3575 000013E8 F605[73BE0000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  3576 000013EF 7548                <1> 	jnz	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  3577                              <1> 	;
  3578 000013F1 800D[73BE0000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  3579                              <1> SL0:
  3580 000013F8 B0ED                <1> 	mov	al, LED_CMD		; LED CMD BYTE
  3581 000013FA E884FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3582 000013FF FA                  <1> 	cli
  3583 00001400 E836000000          <1> 	call	MAKE_LED		; GO FORM INDICATOR DATA BYTE
  3584 00001405 8025[73BE0000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  3585 0000140C 0805[73BE0000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  3586 00001412 F605[73BE0000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  3587 00001419 750F                <1> 	jnz	short SL2		; IF SO, BYPASS SECOND BYTE TRANSMISSION
  3588                              <1> 	;
  3589 0000141B E863FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3590 00001420 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3591 00001421 F605[73BE0000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  3592 00001428 7408                <1> 	jz	short SL3		; IF NOT, DON'T SEND AN ENABLE COMMAND
  3593                              <1> SL2:
  3594 0000142A B0F4                <1> 	mov	al, KB_ENABLE		; GET KEYBOARD CSA ENABLE COMMAND
  3595 0000142C E852FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3596 00001431 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3597                              <1> SL3:
  3598 00001432 8025[73BE0000]3F    <1> 	and	byte [KB_FLAG_2], ~(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  3599                              <1> SL1:					; UPDATE AND TRANSMIT ERROR FLAG
  3600 00001439 FB                  <1> 	sti				; ENABLE INTERRUPTS
  3601 0000143A C3                  <1> 	retn				; RETURN TO CALLER
  3602                              <1> 
  3603                              <1> MAKE_LED:
  3604                              <1> 	;---------------------------------------------------------------------------------
  3605                              <1> 	; MAKE_LED
  3606                              <1> 	;	THIS ROUTINES FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  3607                              <1> 	;	THE MODE INDICATORS.
  3608                              <1> 	;---------------------------------------------------------------------------------
  3609                              <1> 	;
  3610                              <1> 	;push 	cx			; SAVE CX
  3611 0000143B A0[71BE0000]        <1> 	mov	al, [KB_FLAG]		; GET CAPS & NUM LOCK INDICATORS
  3612 00001440 2470                <1> 	and	al, CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  3613                              <1> 	;mov	cl, 4			; SHIFT COUNT
  3614                              <1> 	;rol	al, cl			; SHIFT BITS OVER TO TURN ON INDICATORS
  3615 00001442 C0C004              <1> 	rol	al, 4 ; 20/02/2015
  3616 00001445 2407                <1> 	and	al, 07h			; MAKE SURE ONLY MODE BITS ON
  3617                              <1> 	;pop	cx
  3618 00001447 C3                  <1> 	retn				; RETURN TO CALLER
  3619                              <1> 
  3620                              <1> ; % include 'kybdata.s'   ; KEYBOARD DATA
  3621                              <1> 
  3622                              <1> 
  3623                              <1> ; /// End Of KEYBOARD FUNCTIONS ///
  3624                                  
  3625                                  %include 'video.s' ; 07/03/2015
  3626                              <1> ; ****************************************************************************
  3627                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - video.s
  3628                              <1> ; ----------------------------------------------------------------------------
  3629                              <1> ; Last Update: 23/03/2016
  3630                              <1> ; ----------------------------------------------------------------------------
  3631                              <1> ; Beginning: 16/01/2016
  3632                              <1> ; ----------------------------------------------------------------------------
  3633                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  3634                              <1> ; ----------------------------------------------------------------------------
  3635                              <1> ; Turkish Rational DOS
  3636                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  3637                              <1> ;
  3638                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  3639                              <1> ; video.inc (13/08/2015)
  3640                              <1> ;
  3641                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
  3642                              <1> ; ****************************************************************************
  3643                              <1> 
  3644                              <1> ; Retro UNIX 386 v1 Kernel - VIDEO.INC
  3645                              <1> ; Last Modification: 13/08/2015
  3646                              <1> ;		  (Video Data is in 'VIDATA.INC')
  3647                              <1> ;
  3648                              <1> ; ///////// VIDEO (CGA) FUNCTIONS ///////////////
  3649                              <1> 
  3650                              <1> ; 16/01/2016 (32 bit modifications, TRDOS386 - TRDOS v2.0, video.s)
  3651                              <1> ; INT 32H (TRDOS 386) = INT 10H (IBM PC/AT REAL MODE)
  3652                              <1> 
  3653                              <1> ; IBM PC-AT BIOS Source Code
  3654                              <1> ; TITLE VIDEO1 --- 06/10/85  VIDEO DISPLAY BIOS
  3655                              <1> 
  3656                              <1> int10h:
  3657                              <1> 	; 23/03/2016
  3658                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3659 00001448 9C                  <1> 	pushfd
  3660 00001449 0E                  <1> 	push 	cs
  3661 0000144A E851000000          <1> 	call 	VIDEO_IO_1
  3662 0000144F C3                  <1> 	retn
  3663                              <1> 
  3664                              <1> ;--- INT 10 H -------------------------------------------------------------------
  3665                              <1> ; VIDEO_IO									:	
  3666                              <1> ;	THESE ROUTINES PROVIDE THE CRT DISPLAY INTERFACE			:
  3667                              <1> ;	THE FOLLOWING FUNCTIONS ARE PROVIDED:					:
  3668                              <1> ;										:
  3669                              <1> ;    (AH)= 00H	SET MODE (AL) CONTAINS MODE VALUE				:
  3670                              <1> ;		(AL) = 00H  40X25 BW MODE (POWER ON DEFAULT)			:
  3671                              <1> ;		(AL) = 01H  40X25 COLOR						:
  3672                              <1> ;		(AL) = 02H  80X25 BW						:
  3673                              <1> ;		(AL) = 03H  80X25 COLOR						:
  3674                              <1> ;		              GRAPHICS MODES					:
  3675                              <1> ;		(AL) = 04H  320X200 COLOR					:
  3676                              <1> ;		(AL) = 05H  320X200 BW MODE					:
  3677                              <1> ;		(AL) = 06H  640X200 BW MODE					:
  3678                              <1> ;		(AL) = 07H   80X25 MONOCHROME (USED INTERNAL TO VIDEO ONLY)	:
  3679                              <1> ;		*** NOTES -BW MODES OPERATE SAME AS COLOR MODES, BUT COLOR	:
  3680                              <1> ;		           BURST IS NOT ENABLED					:
  3681                              <1> ;		          -CURSOR IS NOT DISPLAYED IN GRAPHICS MODE		:
  3682                              <1> ;    (AH)= 01H	SET CURSOR TYPE							:
  3683                              <1> ;		(CH) = BITS 4-0 = START LINE FOR CURSOR				:
  3684                              <1> ;		       ** HARDWARE WILL ALWAYS CAUSE BLINK			:
  3685                              <1> ;		       ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING	:
  3686                              <1> ;		          OR NO CURSOR AT ALL					:
  3687                              <1> ;		(CL) = BITS 4-0 = END LINE FOR CURSOR				:
  3688                              <1> ;    (AH)= 02H	SET CURSOR POSITION						:
  3689                              <1> ;		(DH,DL) = ROW,COLUMN  (00H,00H) IS UPPER LEFT			:
  3690                              <1> ;		(BH) = A PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3691                              <1> ;    (AH)= 03H	READ CURSOR POSITION						:
  3692                              <1> ;		(BH) = PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3693                              <1> ;		ON EXIT (DH,DL) = ROW,COLUMN OF CURRENT CURSOR			:
  3694                              <1> ;		        (CH,CL) = CURSOR MODE CURRENTLY SET			:
  3695                              <1> ;    (AH)= 04H	READ LIGHT PEN POSITION						:
  3696                              <1> ;		ON EXIT:							:
  3697                              <1> ;		(AH) = 00H -- LIGHT PEN SWITCH NOT DOWN/NOT TRIGGERED		:
  3698                              <1> ;		(AH) = 01H -- VALID LIGHT PEN VALUE IN REGISTERS		:
  3699                              <1> ;		        (DH,DL) = ROW,COLUMN OF CHARACTER LP POSITION		:
  3700                              <1> ;		        (CH) = RASTER LINE (0-199)				:
  3701                              <1> ;		        (BX) = PIXEL COLUMN (0-319,639)				:
  3702                              <1> ;    (AH)= 05H	SELECT ACTIVE DISPLAY PAGE (VALID ONLY FOR ALPHA MODES)		:
  3703                              <1> ;		(AL) = NEW PAGE VALUE (0-7 FOR MODES 0&1, 0-3 FOR MODES 2&3)	:
  3704                              <1> ;    (AH)= 06H	SCROLL ACTIVE PAGE UP						:
  3705                              <1> ;		(AL) = NUMBER OF LINES. ( LINES BLANKED AT BOTTOM OF WINDOW )	:
  3706                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3707                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3708                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3709                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3710                              <1> ;    (AH)= 07H	SCROLL ACTIVE PAGE DOWN						:
  3711                              <1> ;		(AL) = NUMBER OF LINES, INPUT LINES BLANKED AT TOP OF WINDOW	:
  3712                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3713                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3714                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3715                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3716                              <1> ;										:
  3717                              <1> ;   CHARACTER HANDLING ROUTINES							:
  3718                              <1> ;										:
  3719                              <1> ;    (AH)= 08H	READ ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3720                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3721                              <1> ;		ON EXIT:							:
  3722                              <1> ;		(AL) = CHAR READ						:
  3723                              <1> ;		(AH) = ATTRIBUTE OF CHARACTER READ (ALPHA MODES ONLY)		:
  3724                              <1> ;    (AH)= 09H	WRITE ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3725                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3726                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3727                              <1> ;		(AL) = CHAR TO WRITE						:
  3728                              <1> ;		(BL) = ATTRIBUTE OF CHARACTER (ALPHA)/COLOR OF CHAR (GRAPHICS)	:
  3729                              <1> ;		         SEE NOTE ON WRITE DOT FOR BIT 7 OF BL = 1.		:
  3730                              <1> ;    (AH) = 0AH	WRITE CHARACTER ONLY AT CURRENT CURSOR POSITION			:
  3731                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3732                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3733                              <1> ;		(AL) = CHAR TO WRITE						:
  3734                              <1> ;		       NOTE: USE FUNCTION (AH)= 09H IN GRAPHICS MODES		:
  3735                              <1> ;	FOR READ/WRITE CHARACTER INTERFACE WHILE IN GRAPHICS MODE, THE		:
  3736                              <1> ;		CHARACTERS ARE FORMED FROM A CHARACTER GENERATOR IMAGE		:
  3737                              <1> ;		MAINTAINED IN THE SYSTEM ROM. ONLY THE 1ST 128 CHARS		:
  3738                              <1> ;		ARE CONTAINED THERE. TO READ/WRITE THE SECOND 128 CHARS,	:
  3739                              <1> ;		THE USER MUST INITIALIZE THE POINTER AT INTERRUPT 1FH		:
  3740                              <1> ;		(LOCATION 0007CH) TO POINT TO THE 1K BYTE TABLE CONTAINING	:
  3741                              <1> ;		THE CODE POINTS FOR THE SECOND 128 CHARS (128-255).		:
  3742                              <1> ;	FOR WRITE CHARACTER INTERFACE IN GRAPHICS MODE, THE REPLICATION FACTOR	:
  3743                              <1> ;		CONTAINED IN (CX) ON ENTRY WILL PRODUCE VALID RESULTS ONLY	:
  3744                              <1> ;		FOR CHARACTERS CONTAINED ON THE SAME ROW. CONTINUATION TO	:
  3745                              <1> ;		SUCCEEDING LINES WILL NOT PRODUCE CORRECTLY.			:
  3746                              <1> ;										:
  3747                              <1> ;    GRAPHICS INTERFACE								:
  3748                              <1> ;    (AH)= 0BH	SET COLOR PALETTE						:
  3749                              <1> ;		(BH) = PALETTE COLOR ID BEING SET (0-127)			:
  3750                              <1> ;		(BL) = COLOR VALUE TO BE USED WITH THAT COLOR ID		:
  3751                              <1> ;		       NOTE: FOR THE CURRENT COLOR CARD, THIS ENTRY POINT HAS	:
  3752                              <1> ;		               MEANING ONLY FOR 320X200 GRAPHICS.		:
  3753                              <1> ;		       COLOR ID = 0 SELECTS THE BACKGROUND COLOR (0-15)		:
  3754                              <1> ;		       COLOR ID = 1 SELECTS THE PALETTE TO BE USED:		:
  3755                              <1> ;		               0 = GREEN(1)/RED(2)/YELLOW(3)			:
  3756                              <1> ;		               1 = CYAN(1)/MAGENTA(2)/WHITE(3)			:
  3757                              <1> ;		       IN 40X25 OR 80X25 ALPHA MODES, THE VALUE SET FOR 	:
  3758                              <1> ;		               PALETTE COLOR 0 INDICATES THE BORDER COLOR	:
  3759                              <1> ;		               TO BE USED (VALUES 0-31, WHERE 16-31 SELECT	:
  3760                              <1> ;		               THE HIGH INTENSITY BACKGROUND SET.		:
  3761                              <1> ;    (AH)= 0CH	WRITE DOT							:
  3762                              <1> ;		(DX) = ROW NUMBER						:
  3763                              <1> ;		(CX) = COLUMN NUMBER						:
  3764                              <1> ;		(AL) = COLOR VALUE						:
  3765                              <1> ;		        IF BIT 7 OF AL = 1, THEN THE COLOR VALUE IS EXCLUSIVE	:
  3766                              <1> ;		        ORed WITH THE CURRENT CONTENTS OF THE DOT		:
  3767                              <1> ;    (AH)= ODH	READ DOT							:
  3768                              <1> ;		(DX) = ROW NUMBER						:
  3769                              <1> ;		(CX) = COLUMN NUMBER						:
  3770                              <1> ;		(AL) = RETURNS THE DOT READ					:
  3771                              <1> ;										:
  3772                              <1> ;    ASCII TELETYPE ROUTINE FOR OUTPUT						:
  3773                              <1> ;										:
  3774                              <1> ;    (AH)= 0EH	WRITE TELETYPE TO ACTIVE PAGE					:
  3775                              <1> ;		(AL) = CHAR TO WRITE						:
  3776                              <1> ;		(BL) = FOREGROUND COLOR IN GRAPHICS MODE			:
  3777                              <1> ;		NOTE -- SCREEN WIDTH IS CONTROLLED BY PREVIOUS MODE SET		:
  3778                              <1> ;    (AH)= 0FH	CURRENT VIDEO STATE						:
  3779                              <1> ;		RETURNS THE CURRENT VIDEO STATE					:
  3780                              <1> ;		(AL) = MODE CURRENTLY SET ( SEE (AH)=00H FOR EXPLANATION)	:
  3781                              <1> ;		(AH) = NUMBER OR CHARACTER COLUMNS ON SCREEN			:
  3782                              <1> ;		(BH) = CURRENT ACTIVE DISPLAY PAGE				:
  3783                              <1> ;    (AH)= 10H	RESERVED							:
  3784                              <1> ;    (AH)= 11H	RESERVED							:
  3785                              <1> ;    (AH)= 12H	RESERVED							:
  3786                              <1> ;    (AH)= 13H	WRITE STRING							:
  3787                              <1> ;			ES:BP  -  POINTER T0 STRING TO BE WRITTEN		:
  3788                              <1> ;			CX     -  LENGTH OF CHARACTER STRING TO WRITTEN		:
  3789                              <1> ;			DX     -  CURSOR POSITION FOR STRING TO BE WRITTEN	:
  3790                              <1> ;			BH     -  PAGE NUMBER					:
  3791                              <1> ;		(AL)= 00H	WRITE CHARACTER STRING				:
  3792                              <1> ;			BL     -  ATTRIBUTE					:
  3793                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3794                              <1> ;			CURSOR NOT MOVED					:
  3795                              <1> ;		(AL)= 01H	WRITE CHARACTER STRING AND MOVE CURSOR		:
  3796                              <1> ;			BL     -  ATTRIBUTE					:
  3797                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3798                              <1> ;			CURSOR MOVED						:
  3799                              <1> ;		(AL)= 02H	WRITE CHARACTER AND ATTRIBUTE STRING		:
  3800                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3801                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3802                              <1> ;			CURSOR IS NOT MOVED					:
  3803                              <1> ;		(AL)= 03H WRITE CHARACTER AND ATTRIBUTE STRING AND MOVE CURSOR	:
  3804                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3805                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3806                              <1> ;			CURSOR IS MOVED						:
  3807                              <1> ;		 NOTE:  CARRIAGE RETURN, LINE FEED, BACKSPACE, AND BELL ARE	:
  3808                              <1> ;		        TREATED AS COMMANDS RATHER THAN PRINTABLE CHARACTERS.	:
  3809                              <1> ;										:
  3810                              <1> ;	BX,CX,DX,SI,DI,BP,SP,DS,ES,SS PRESERVED DURING CALLS EXCEPT FOR		:
  3811                              <1> ;	BX,CX,DX RETURN VALUES ON FUNCTIONS 03H,04H,0DH AND 0FH. ON ALL CALLS	:
  3812                              <1> ;	AX IS MODIFIED.								:
  3813                              <1> ;--------------------------------------------------------------------------------
  3814                              <1> 
  3815 00001450 [EC140000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
  3816 00001454 [4C150000]          <1> 	dd	SET_CTYPE
  3817 00001458 [61150000]          <1> 	dd	SET_CPOS
  3818 0000145C [68150000]          <1> 	dd	READ_CURSOR
  3819 00001460 [F1140000]          <1> 	dd	VIDEO_RETURN	; READ_LPEN
  3820 00001464 [8A150000]          <1> 	dd	ACT_DISP_PAGE
  3821 00001468 [03160000]          <1> 	dd	SCROLL_UP
  3822 0000146C [E7160000]          <1> 	dd	SCROLL_DOWN
  3823 00001470 [32170000]          <1> 	dd	READ_AC_CURRENT
  3824 00001474 [60170000]          <1> 	dd	WRITE_AC_CURRENT
  3825 00001478 [73170000]          <1> 	dd	WRITE_C_CURRENT
  3826 0000147C [F1140000]          <1> 	dd	VIDEO_RETURN	; SET_COLOR
  3827 00001480 [F1140000]          <1> 	dd	VIDEO_RETURN	; WRITE_DOT
  3828 00001484 [F1140000]          <1> 	dd	VIDEO_RETURN	; READ_DOT
  3829 00001488 [B7170000]          <1> 	dd	WRITE_TTY
  3830 0000148C [D9140000]          <1> 	dd	VIDEO_STATE
  3831 00001490 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3832 00001494 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3833 00001498 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3834 0000149C [F1140000]          <1> 	dd	VIDEO_RETURN	; WRITE_STRING
  3835                              <1> M1L	EQU	$ - M1
  3836                              <1> 
  3837                              <1> VIDEO_IO_1:
  3838 000014A0 FB                  <1> 	sti				; INTERRUPTS BACK ON
  3839 000014A1 FC                  <1> 	cld				; SET DIRECTION FORWARD
  3840 000014A2 80FC14              <1> 	cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
  3841 000014A5 7321                <1> 	jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
  3842                              <1> 
  3843 000014A7 06                  <1> 	push	es
  3844 000014A8 1E                  <1> 	push	ds			; SAVE WORK AND PARAMETER REGISTERS
  3845 000014A9 52                  <1> 	push	edx
  3846 000014AA 51                  <1> 	push	ecx
  3847 000014AB 53                  <1> 	push	ebx
  3848 000014AC 56                  <1> 	push	esi
  3849 000014AD 57                  <1> 	push	edi
  3850 000014AE 55                  <1> 	push	ebp
  3851 000014AF 66BE1000            <1> 	mov	si, KDATA 		; POINT DS: TO DATA SEGMENT
  3852 000014B3 8EDE                <1> 	mov	ds, si
  3853 000014B5 8EC6                <1> 	mov	es, si
  3854 000014B7 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
  3855                              <1> 	; 23/03/2016
  3856 000014BC C0E402              <1> 	shl	ah, 2  ; dword		; TIMES 2 FOR WORD TABLE LOOKUP
  3857 000014BF 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
  3858                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
  3859                              <1> 
  3860 000014C2 FFA6[50140000]      <1> 	JMP	dword [esi+M1]		; GO TO SELECTED FUNCTION
  3861                              <1> 
  3862                              <1> M4:					;	COMMAND NOT VALID
  3863 000014C8 CF                  <1> 	iret				; DO NOTHING IF NOT IN VALID RANGE
  3864                              <1> 
  3865                              <1> 
  3866                              <1> ; 02/09/2014 (Retro UNIX 386 v1)
  3867                              <1> ;
  3868                              <1> ; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3869                              <1> 
  3870                              <1> set_mode_3:  	; will be called from 'write_tty' 
  3871 000014C9 53                  <1> 	push	ebx
  3872 000014CA 52                  <1> 	push	edx
  3873 000014CB 50                  <1> 	push	eax
  3874 000014CC 57                  <1> 	push	edi
  3875 000014CD 51                  <1> 	push	ecx
  3876 000014CE E827000000          <1> 	call	set_txt_mode
  3877 000014D3 59                  <1> 	pop	ecx
  3878 000014D4 5F                  <1> 	pop	edi
  3879 000014D5 58                  <1> 	pop	eax
  3880 000014D6 5A                  <1> 	pop	edx
  3881 000014D7 5B                  <1> 	pop	ebx
  3882 000014D8 C3                  <1> 	retn
  3883                              <1> 
  3884                              <1> VIDEO_STATE:
  3885                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3886                              <1> 
  3887                              <1> ;---------------------------------------------------
  3888                              <1> ; VIDEO STATE
  3889                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
  3890                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
  3891                              <1> ;  AL = CURRENT VIDEO MODE
  3892                              <1> ;  BH = CURRENT ACTIVE PAGE
  3893                              <1> ;---------------------------------------------------
  3894                              <1> 
  3895                              <1> 	;mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
  3896 000014D9 B480                <1> 	mov	ah, 80h
  3897 000014DB A0[A6BE0000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
  3898                              <1> 	;movzx	esi, al
  3899                              <1> 	;mov	ah, [esi+M6] 
  3900                              <1> 	; BL = active page (not BH!)
  3901 000014E0 8A1D[A8C40000]      <1> 	mov	bl, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
  3902 000014E6 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
  3903 000014E7 5F                  <1> 	pop	edi
  3904 000014E8 5E                  <1> 	pop	esi
  3905 000014E9 59                  <1> 	pop	ecx	; DISCARD SAVED BX
  3906 000014EA EB09                <1> 	jmp	short M15	; RETURN TO CALLER
  3907                              <1> 
  3908                              <1> SET_MODE:
  3909                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
  3910                              <1> 	;	valid video mode: 03h only!
  3911                              <1> 	;	(VGA modes will be selected with another routine)
  3912                              <1> 	;
  3913                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
  3914                              <1> 
  3915                              <1> ;------------------------------------------------------
  3916                              <1> ; SET MODE					      :
  3917                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
  3918                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
  3919                              <1> ; INPUT						      :
  3920                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
  3921                              <1> ; OUTPUT					      :
  3922                              <1> ;	NONE					      :
  3923                              <1> ;------------------------------------------------------
  3924                              <1> 
  3925 000014EC E809000000          <1> 	call	set_txt_mode
  3926                              <1> 
  3927                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3928                              <1> 
  3929                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  3930                              <1> 
  3931                              <1> VIDEO_RETURN:
  3932 000014F1 5D                  <1> 	pop	ebp
  3933 000014F2 5F                  <1> 	pop	edi
  3934 000014F3 5E                  <1> 	pop	esi
  3935 000014F4 5B                  <1> 	pop	ebx
  3936                              <1> M15:			; VIDEO_RETURN_C
  3937 000014F5 59                  <1> 	pop	ecx
  3938 000014F6 5A                  <1> 	pop	edx
  3939 000014F7 1F                  <1> 	pop	ds
  3940 000014F8 07                  <1> 	pop	es	; RECOVER SEGMENTS
  3941 000014F9 CF                  <1> 	iret		; ALL DONE
  3942                              <1> 
  3943                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3944                              <1> set_txt_mode:
  3945                              <1> 	;mov	dx, 03D4h 	; address of color card
  3946 000014FA B003                <1> 	mov	al, 3
  3947                              <1> ;M8:
  3948 000014FC A2[A6BE0000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
  3949 00001501 B029                <1> 	mov	al, 29h
  3950                              <1> 	;mov	[CRT_MODE_SET], al ; save the mode set value
  3951 00001503 2437                <1> 	and	al, 037h	; video off, save high resolution bit	
  3952                              <1> 	;push	dx  		; save port value
  3953                              <1> 	;add	dx, 4		; point to control register
  3954 00001505 66BAD803            <1> 	mov	dx, 3D8h
  3955 00001509 EE                  <1> 	out	dx, al		; reset video to off to suppress rolling
  3956                              <1> 	;pop	dx
  3957                              <1> ;M9:
  3958 0000150A BB[A8BE0000]        <1> 	mov	ebx, video_params ; initialization table
  3959 0000150F 668B430A            <1> 	mov	ax, [ebx+10]      ; get the cursor mode from the table	
  3960 00001513 86E0                <1> 	xchg 	ah, al
  3961 00001515 66A3[96C40000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode
  3962 0000151B 30E4                <1> 	xor	ah, ah		  ; ah is register number during loop 
  3963                              <1> 	
  3964                              <1> ;-----	LOOP THROUGH TABLE, OUTPUTTING REGISTER ADDRESS, THEN VALUE FROM TABLE
  3965 0000151D B910000000          <1> 	mov	ecx, 16 ; 16/01/2016
  3966                              <1> M10:			;  initialization loop
  3967 00001522 88E0                <1> 	mov	al, ah 	; get 6845 register number
  3968 00001524 EE                  <1> 	out	dx, al
  3969 00001525 6642                <1> 	inc	dx      ; point to data port
  3970 00001527 FEC4                <1> 	inc	ah	; next register value
  3971 00001529 8A03                <1> 	mov	al, [ebx] ; get table value
  3972 0000152B EE                  <1> 	out	dx, al	; out to chip
  3973 0000152C 43                  <1> 	inc	ebx	; next in table
  3974 0000152D 664A                <1> 	dec	dx	; back to pointer register
  3975 0000152F E2F1                <1> 	loop	M10	; do the whole table
  3976                              <1> 
  3977                              <1> ;-----	FILL REGEN AREA WITH BLANK
  3978                              <1> 	;xor	ax, ax  
  3979                              <1> 	;mov	[CRT_START], ax  ; start address saved in global
  3980                              <1> 	;mov	[ACTIVE_PAGE], al ; 0 ; (re)set page value
  3981                              <1> 	;mov	ecx, 8192 ; number of words in color card
  3982                              <1> 	; black background, light gray characeter color, space character
  3983                              <1> 	;mov	ax, 0720h ; fill char for alpha - attribute
  3984                              <1> ;M13:			  ; clear buffer
  3985                              <1> 	;add	edi, 0B8000h ; [crt_base]
  3986                              <1> 	;rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
  3987                              <1> 
  3988                              <1> ;-----	ENABLE VIDEO AND CORRECT PORT SETTING
  3989                              <1> 	;mov	dx, 3D4h ; mov dx, word [ADDR_6845]
  3990                              <1> 			 ; prepare to output to video enable port
  3991                              <1> 	;add	dx,4	 ; point to the mode control gerister
  3992 00001531 66BAD803            <1> 	mov	dx, 3D8h
  3993                              <1> 	;mov	al, [CRT_MODE_SET] ; get the mode set value
  3994 00001535 B029                <1> 	mov	al, 29h
  3995 00001537 EE                  <1> 	out	dx, al	 ; set video enable port
  3996                              <1> 
  3997                              <1> ;----- 	DETERMINE NUMBER OF COLUMNS, BOTH FOR ENTIRE DISPLAY
  3998                              <1> ;----- 	AND THE NUMBER TO BE USED FOR TTY INTERFACE
  3999                              <1> 	;
  4000                              <1> 	;mov	byte [CRT_COLS], 80h ; initialize number of columns count
  4001                              <1> 	;
  4002                              <1> ;-----	SET CURSOR POSITIONS
  4003                              <1> 	;mov	word [CRT_LEN], 80*25*2
  4004 00001538 BF[98C40000]        <1> 	mov	edi, CURSOR_POSN
  4005 0000153D B904000000          <1> 	mov	ecx, 4	; clear all cursor positions (16 bytes)
  4006 00001542 31C0                <1> 	xor	eax, eax
  4007 00001544 F3AB                <1> 	rep 	stosd	; fill with zeroes
  4008                              <1> 
  4009                              <1> ;-----	SET UP OVERSCAN REGISTER
  4010 00001546 6642                <1> 	inc	dx	; set overscan port to a default
  4011 00001548 B030                <1> 	mov	al, 30h	; 30H value for all modes except 640X200 bw
  4012                              <1> ;M14:
  4013 0000154A EE                  <1> 	out	dx, al	; output the correct value to 3D9 port
  4014                              <1> 	;mov	[CRT_PALETTE], al ; save the value for future use
  4015                              <1> 
  4016                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  4017 0000154B C3                  <1> 	retn
  4018                              <1> 
  4019                              <1> SET_CTYPE:
  4020                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4021 0000154C E802000000          <1> 	call	_set_ctype
  4022 00001551 EB9E                <1> 	jmp	short VIDEO_RETURN
  4023                              <1> 
  4024                              <1> _set_ctype:
  4025                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
  4026                              <1> 	;
  4027                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4028                              <1> 
  4029                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
  4030                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
  4031                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
  4032                              <1> 	;     OR NO CURSOR AT ALL
  4033                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
  4034                              <1> 
  4035                              <1> ;------------------------------------------------
  4036                              <1> ; SET_CTYPE
  4037                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
  4038                              <1> ; INPUT
  4039                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
  4040                              <1> ; OUTPUT	
  4041                              <1> ;	NONE
  4042                              <1> ;------------------------------------------------
  4043                              <1> 
  4044 00001553 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  4045 00001555 66890D[96C40000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  4046                              <1> 	;call	m16	; output cx register
  4047                              <1> 	;retn
  4048 0000155C E915030000          <1>         jmp     m16
  4049                              <1> 
  4050                              <1> SET_CPOS:
  4051                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4052 00001561 E8E5020000          <1> 	call	_set_cpos
  4053 00001566 EB89                <1> 	jmp	short VIDEO_RETURN
  4054                              <1> 
  4055                              <1> READ_CURSOR:
  4056                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4057                              <1> 	;
  4058                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4059                              <1> 
  4060                              <1> ;------------------------------------------------------
  4061                              <1> ; READ_CURSOR
  4062                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
  4063                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
  4064                              <1> ; INPUT
  4065                              <1> ;	BH - PAGE OF CURSOR
  4066                              <1> ; OUTPUT
  4067                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
  4068                              <1> ;	CX - CURRENT CURSOR MODE
  4069                              <1> ;------------------------------------------------------
  4070                              <1> 
  4071                              <1> 	; BL = Video page number (0 to 7)
  4072                              <1> 	
  4073                              <1> 
  4074 00001568 E810000000          <1> 	call	get_cpos
  4075 0000156D 0FB70D[96C40000]    <1> 	movzx	ecx, word [CURSOR_MODE]
  4076                              <1> 
  4077 00001574 5D                  <1> 	pop	ebp
  4078 00001575 5F                  <1> 	pop	edi
  4079 00001576 5E                  <1> 	pop	esi
  4080 00001577 5B                  <1> 	pop	ebx
  4081 00001578 58                  <1> 	pop	eax	; DISCARD SAVED CX AND DX
  4082 00001579 58                  <1> 	pop	eax
  4083 0000157A 1F                  <1> 	pop	ds
  4084 0000157B 07                  <1> 	pop	es
  4085 0000157C CF                  <1> 	iret
  4086                              <1> 
  4087                              <1> get_cpos:
  4088                              <1> 	; 16/01/2016
  4089                              <1> 	; BL = Video page number (0 to 7)
  4090                              <1> 	;
  4091 0000157D D0E3                <1> 	shl	bl, 1 ; WORD OFFSET
  4092 0000157F 0FB6F3              <1> 	movzx	esi, bl 
  4093 00001582 0FB796[98C40000]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
  4094 00001589 C3                  <1> 	retn
  4095                              <1> 
  4096                              <1> ACT_DISP_PAGE:
  4097                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4098                              <1> 	;
  4099                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4100                              <1> 	;
  4101                              <1> ;-----------------------------------------------------
  4102                              <1> ; ACT_DISP_PAGE
  4103                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  4104                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  4105                              <1> ; INPUT
  4106                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  4107                              <1> ; OUTPUT
  4108                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  4109                              <1> ;-----------------------------------------------------
  4110                              <1> 
  4111 0000158A E805000000          <1> 	call	set_active_page
  4112 0000158F E95DFFFFFF          <1>         jmp     VIDEO_RETURN
  4113                              <1> 
  4114                              <1> set_active_page:   ; tty_sw
  4115                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4116                              <1> 	; 30/06/2015
  4117                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  4118                              <1> 	; 10/12/2013
  4119                              <1> 	; 04/12/2013
  4120                              <1> 	;
  4121 00001594 A2[A8C40000]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  4122                              <1> 	;mov	cx, [CRT_LEN] ; get saved length of regen buffer
  4123 00001599 66B9A00F            <1> 	mov	cx, 25*80*2
  4124                              <1> 	; 27/06/2015
  4125 0000159D 0FB6D8              <1> 	movzx	ebx, al
  4126                              <1> 	;
  4127 000015A0 6698                <1> 	cbw	; 07/09/2014 (ah=0)
  4128 000015A2 66F7E1              <1> 	mul 	cx	; display page times regen length
  4129                              <1> 	; 10/12/2013
  4130 000015A5 66A3[94C40000]      <1> 	mov	[CRT_START], ax ; save start address for later
  4131 000015AB 6689C1              <1> 	mov	cx, ax ; start address to cx
  4132                              <1> 	;sar	cx, 1
  4133 000015AE 66D1E9              <1> 	shr	cx, 1	; divide by 2 for 6845 handling
  4134 000015B1 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  4135 000015B3 E8BE020000          <1> 	call	m16
  4136                              <1> 	;sal	bx, 1
  4137                              <1> 	; 01/09/2014
  4138 000015B8 D0E3                <1> 	shl	bl, 1	; *2 for word offset
  4139 000015BA 81C3[98C40000]      <1> 	add	ebx, CURSOR_POSN
  4140 000015C0 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  4141                              <1> 	; 16/01/2016
  4142                              <1> 	;call	m18
  4143                              <1> 	;retn
  4144 000015C3 E99A020000          <1> 	jmp	m18
  4145                              <1> 
  4146                              <1> position:
  4147                              <1> 	; 27/06/2015
  4148                              <1> 	; 02/09/2014
  4149                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4150                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  4151                              <1> 	;
  4152                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4153                              <1> 	;
  4154                              <1> ;-----------------------------------------
  4155                              <1> ; POSITION
  4156                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  4157                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  4158                              <1> ; INPUT
  4159                              <1> ;	AX = ROW, COLUMN POSITION
  4160                              <1> ; OUTPUT
  4161                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  4162                              <1> ;-----------------------------------------
  4163                              <1> 
  4164                              <1> 		; DX = ROW, COLUMN POSITION
  4165                              <1> 	;movzx	eax, byte [CRT_COLS] ; 27/06/2015
  4166 000015C8 31C0                <1> 	xor	eax, eax ; 02/09/2014
  4167 000015CA B050                <1> 	mov	al, 80   ; determine bytes to row	
  4168 000015CC F6E6                <1> 	mul	dh	 ; row value
  4169 000015CE 30F6                <1> 	xor	dh, dh   ; 0	
  4170 000015D0 6601D0              <1> 	add	ax, dx	 ; add column value to the result
  4171 000015D3 66D1E0              <1> 	shl	ax, 1	; * 2 for attribute bytes
  4172                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  4173 000015D6 C3                  <1> 	retn
  4174                              <1> 
  4175                              <1> find_position:
  4176                              <1> 	; 27/06/2015
  4177                              <1> 	; 07/09/2014
  4178                              <1> 	; 02/09/2014
  4179                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4180                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4181 000015D7 0FB6CB              <1> 	movzx	ecx, bl ; video page number ; 27/06/2015 (movzx)
  4182 000015DA 89CE                <1> 	mov	esi, ecx
  4183 000015DC 66D1E6              <1> 	shl	si, 1
  4184 000015DF 668B96[98C40000]    <1> 	mov	dx, [esi + CURSOR_POSN]
  4185 000015E6 740A                <1> 	jz	short p21
  4186 000015E8 6631F6              <1> 	xor	si, si
  4187                              <1> p20:
  4188                              <1> 	;add	si, [CRT_LEN]
  4189 000015EB 6681C6A00F          <1> 	add	si, 80*25*2 ; add length of buffer for one page		
  4190 000015F0 E2F9                <1> 	loop	p20
  4191                              <1> p21:
  4192 000015F2 6621D2              <1> 	and	dx, dx
  4193 000015F5 7407                <1> 	jz	short p22
  4194 000015F7 E8CCFFFFFF          <1> 	call 	position ; determine location in regen in page
  4195 000015FC 01C6                <1> 	add	esi, eax ; add location to start of regen page
  4196                              <1> p22:	
  4197                              <1> 	;mov	dx, [addr_6845] ; get base address of active display			
  4198                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  4199                              <1> 	;add	dx, 6	; point at status port
  4200 000015FE 66BADA03            <1> 	mov	dx, 03DAh ; status port
  4201                              <1> 	; cx = 0
  4202 00001602 C3                  <1> 	retn
  4203                              <1> 
  4204                              <1> SCROLL_UP:
  4205                              <1> 	; 30/01/2016
  4206                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4207                              <1> 	; 07/09/2014
  4208                              <1> 	; 02/09/2014
  4209                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  4210                              <1> 	; 04/04/2014
  4211                              <1> 	; 04/12/2013
  4212                              <1> 	;
  4213                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4214                              <1> 	;
  4215                              <1> ;----------------------------------------------
  4216                              <1> ; SCROLL UP
  4217                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  4218                              <1> ;	ON THE SCREEN
  4219                              <1> ; INPUT
  4220                              <1> ;	(AH) = CURRENT CRT MODE
  4221                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  4222                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  4223                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  4224                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  4225                              <1> ;	(DS) = DATA SEGMENT
  4226                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  4227                              <1> ; OUTPUT
  4228                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  4229                              <1> ;--------------------------------------------
  4230                              <1> 
  4231 00001603 E805000000          <1> 	call	_scroll_up
  4232 00001608 E9E4FEFFFF          <1>         jmp     VIDEO_RETURN
  4233                              <1> 
  4234                              <1> _scroll_up:  ; from 'write_tty'
  4235                              <1> 	;
  4236                              <1> 	; ((ah = 3))
  4237                              <1> 	; cl = left upper column
  4238                              <1> 	; ch = left upper row
  4239                              <1> 	; dl = right lower column
  4240                              <1> 	; dh = right lower row
  4241                              <1> 	;
  4242                              <1> 	; al = line count 
  4243                              <1> 	; ah = attribute to be used on blanked line	
  4244                              <1> 	; bl = video page number (0 to 7)
  4245                              <1> 	; 
  4246                              <1> 
  4247 0000160D E86C000000          <1> 	call	test_line_count ; 16/01/2016
  4248                              <1> 
  4249                              <1> 	;mov	bh, [CRT_MODE] ; current video mode	
  4250                              <1> 	;cmp	bh, 4
  4251                              <1>  	;jb	short n1
  4252                              <1> 
  4253                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4254                              <1> 	;jne	GRAPHICS_UP
  4255                              <1> n1:
  4256 00001612 30FF                <1> 	xor	bh, bh	; 0
  4257 00001614 6650                <1> 	push	ax ; *
  4258                              <1> 	;mov 	esi, [CRT_BASE]
  4259 00001616 BE00800B00          <1>         mov     esi, 0B8000h  
  4260 0000161B 3A1D[A8C40000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4261 00001621 750B                <1> 	jne	short n2
  4262                              <1> 	;
  4263 00001623 66A1[94C40000]      <1>         mov     ax, [CRT_START]
  4264 00001629 6601C6              <1>         add     si, ax
  4265 0000162C EB0F                <1>         jmp     short n4
  4266                              <1> n2:
  4267 0000162E 20DB                <1>         and     bl, bl
  4268 00001630 740B                <1> 	jz	short n4
  4269 00001632 88D8                <1> 	mov	al, bl
  4270                              <1> n3:
  4271                              <1>         ;add    si, [CRT_LEN]
  4272                              <1>         ;add    esi, 80*25*2 
  4273 00001634 6681C6A00F          <1>         add     si, 80*25*2
  4274 00001639 FEC8                <1>         dec	al
  4275 0000163B 75F7                <1> 	jnz	short n3
  4276                              <1> n4:	
  4277 0000163D E84D000000          <1> 	call	scroll_position ; 16/01/2016
  4278 00001642 7419                <1>         jz      short n6 
  4279                              <1> 
  4280 00001644 01CE                <1>         add     esi, ecx ; from address for scroll
  4281 00001646 88F7                <1> 	mov	bh, dh  ; #rows in block
  4282 00001648 28C7                <1> 	sub	bh, al	; #rows to be moved
  4283                              <1> n5:
  4284 0000164A E880000000          <1> 	call	n10 ; 16/01/2016
  4285                              <1> 	
  4286                              <1>         ;mov    cl, [CRT_COLS] 
  4287                              <1> 	;add	cl, cl
  4288                              <1>         ;mov    ecx, 80*2
  4289 0000164F 66B9A000            <1>         mov     cx, 80*2
  4290 00001653 01CE                <1>         add     esi, ecx  ; next line
  4291 00001655 01CF                <1>         add     edi, ecx
  4292 00001657 FECF                <1> 	dec	bh	 ; count of lines to move
  4293 00001659 75EF                <1> 	jnz	short n5 ; row loop
  4294                              <1> 	; bh = 0
  4295 0000165B 88C6                <1> 	mov	dh, al	 ; #rows	
  4296                              <1> n6:
  4297                              <1> 	; attribute in ah
  4298 0000165D B020                <1> 	mov	al, ' '	 ; fill with blanks
  4299                              <1> n7:
  4300 0000165F E878000000          <1> 	call	n11 ; 16/01/2016
  4301                              <1> 
  4302                              <1> 	;mov	cl, [CRT_COLS]
  4303                              <1> 	;add	cl, cl
  4304                              <1>         ;mov    ecx, 80*2
  4305 00001664 66B9A000            <1>         mov	cx, 80*2
  4306 00001668 01CF                <1>         add     edi, ecx
  4307 0000166A FECE                <1> 	dec	dh
  4308 0000166C 75F1                <1> 	jnz	short n7
  4309                              <1> 	;
  4310 0000166E 3A1D[A8C40000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4311 00001674 7507                <1> 	jne	short n8
  4312                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4313 00001676 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4314 00001678 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4315 0000167C EE                  <1> 	out	dx, al
  4316                              <1> n8:
  4317 0000167D C3                  <1> 	retn
  4318                              <1> 
  4319                              <1> 
  4320                              <1> test_line_count:
  4321                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4322                              <1> 	; 07/09/2014 (scroll_up)
  4323 0000167E 08C0                <1> 	or	al, al
  4324 00001680 740C                <1> 	jz	short al_set
  4325 00001682 88F7                <1> 	mov	bh, dh	; subtract lower row from upper row
  4326 00001684 28EF                <1> 	sub	bh, ch
  4327 00001686 FEC7                <1> 	inc	bh	; adjust difference by 1
  4328 00001688 38C7                <1> 	cmp	bh, al 	; line count = amount of rows in window?
  4329 0000168A 7502                <1> 	jne	short al_set ; if not the we're all set
  4330 0000168C 30C0                <1> 	xor	al, al	; otherwise set al to zero
  4331                              <1> al_set:
  4332 0000168E C3                  <1> 	retn
  4333                              <1> 
  4334                              <1> scroll_position:
  4335                              <1> 	; 30/01/2016
  4336                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4337                              <1> 	; 07/09/2014 (scroll_up)
  4338                              <1> 
  4339 0000168F 6652                <1> 	push	dx
  4340 00001691 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  4341 00001694 E82FFFFFFF          <1> 	call	position
  4342 00001699 01C6                <1> 	add	esi, eax
  4343 0000169B 89F7                <1> 	mov	edi, esi
  4344 0000169D 665A                <1> 	pop	dx	; lower right position in DX
  4345 0000169F 6629CA              <1> 	sub	dx, cx
  4346 000016A2 FEC6                <1> 	inc	dh	; dh = #rows 
  4347 000016A4 FEC2                <1> 	inc	dl	; dl = #cols in block
  4348 000016A6 59                  <1> 	pop	ecx 	; return address
  4349 000016A7 6658                <1> 	pop	ax	; * ; al = line count, ah = attribute
  4350 000016A9 51                  <1> 	push	ecx	; return address
  4351 000016AA 0FB7C8              <1> 	movzx	ecx, ax
  4352                              <1> 	;mov	ah, [CRT_COLS]
  4353 000016AD B450                <1> 	mov	ah, 80
  4354 000016AF F6E4                <1> 	mul	ah	; determine offset to from address
  4355 000016B1 6601C0              <1> 	add	ax, ax  ; *2 for attribute byte
  4356                              <1> 	;
  4357 000016B4 6650                <1> 	push	ax	; offset 
  4358 000016B6 6652                <1> 	push	dx
  4359                              <1> 	;
  4360                              <1> 	; 04/04/2014
  4361 000016B8 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  4362                              <1> n9:                      ; wait_display_enable
  4363 000016BC EC                  <1>         in      al, dx   ; get port
  4364 000016BD A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  4365 000016BF 74FB                <1> 	jz	short n9 ; wait_display_enable
  4366 000016C1 B025                <1> 	mov	al, 25h
  4367 000016C3 B2D8                <1> 	mov	dl, 0D8h ; address control port
  4368 000016C5 EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  4369 000016C6 665A                <1> 	pop	dx	; #rows, #cols
  4370 000016C8 6658                <1>        	pop	ax	; offset
  4371 000016CA 6691                <1> 	xchg	ax, cx	; 
  4372                              <1> 	; ecx = offset, al = line count, ah = attribute
  4373                              <1> 	;
  4374 000016CC 08C0                <1> 	or	al, al
  4375 000016CE C3                  <1> 	retn
  4376                              <1> 
  4377                              <1> n10:
  4378                              <1> 	; Move rows
  4379 000016CF 88D1                <1> 	mov	cl, dl	; get # of cols to move
  4380 000016D1 56                  <1> 	push	esi
  4381 000016D2 57                  <1> 	push	edi	; save start address
  4382                              <1> n10r:
  4383 000016D3 66A5                <1> 	movsw		; move that line on screen
  4384 000016D5 FEC9                <1> 	dec	cl
  4385 000016D7 75FA                <1>         jnz     short n10r
  4386 000016D9 5F                  <1> 	pop	edi
  4387 000016DA 5E                  <1> 	pop	esi	; recover addresses
  4388 000016DB C3                  <1> 	retn
  4389                              <1> n11:
  4390                              <1> 	; Clear rows
  4391                              <1>                 ; dh =  #rows
  4392 000016DC 88D1                <1>         mov	cl, dl	; get # of cols to clear
  4393 000016DE 57                  <1>         push    edi     ; save address
  4394                              <1> n11r:
  4395 000016DF 66AB                <1>         stosw           ; store fill character
  4396 000016E1 FEC9                <1> 	dec	cl
  4397 000016E3 75FA                <1>         jnz     short n11r
  4398 000016E5 5F                  <1>         pop     edi     ; recover address
  4399 000016E6 C3                  <1> 	retn
  4400                              <1> 
  4401                              <1> SCROLL_DOWN:
  4402                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4403                              <1> 	;
  4404                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4405                              <1> 
  4406                              <1> ;------------------------------------------
  4407                              <1> ; SCROLL DOWN
  4408                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  4409                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  4410                              <1> ;	WITH A DEFINED CHARACTER
  4411                              <1> ; INPUT
  4412                              <1> ;	(AH) = CURRENT CRT MODE
  4413                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  4414                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  4415                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  4416                              <1> ;	(BH) = FILL CHARACTER
  4417                              <1> ;	(DS) = DATA SEGMENT
  4418                              <1> ;	(ES) = REGEN SEGMENT
  4419                              <1> ; OUTPUT
  4420                              <1> ;	NONE -- SCREEN IS SCROLLED
  4421                              <1> ;------------------------------------------
  4422                              <1> 
  4423                              <1> 	; ((ah = 3))
  4424                              <1> 	; cl = left upper column
  4425                              <1> 	; ch = left upper row
  4426                              <1> 	; dl = right lower column
  4427                              <1> 	; dh = right lower row
  4428                              <1> 	;
  4429                              <1> 	; al = line count 
  4430                              <1> 	; ah = attribute to be used on blanked line	
  4431                              <1> 	; bl = video page number (0 to 7)
  4432                              <1> 	; 
  4433                              <1> 
  4434                              <1> 	; !!!!
  4435 000016E7 FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  4436                              <1> 	; !!!!
  4437 000016E8 E891FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  4438                              <1> 	
  4439                              <1> 	;mov	bh, [CRT_MODE] ; current video mode
  4440                              <1> 	;cmp	bh, 4
  4441                              <1>  	;jb	short n12
  4442                              <1> 
  4443                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4444                              <1> 	;jne	GRAPHICS_DOWN
  4445                              <1> 
  4446                              <1> n12:			; CONTINUE_DOWN
  4447 000016ED 6650                <1> 	push	ax	; * ; save attribute in ah
  4448 000016EF 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  4449 000016F2 E898FFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  4450 000016F7 7419                <1> 	jz	short n14
  4451 000016F9 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  4452 000016FB 88F7                <1> 	mov	bh, dh  ; #rows in block
  4453 000016FD 28C7                <1> 	sub	bh, al	; #rows to be moved
  4454                              <1> n13:
  4455 000016FF E8CBFFFFFF          <1> 	call	n10	; MOVE ONE ROW
  4456                              <1> 
  4457                              <1> 	;mov    cl, [CRT_COLS] 
  4458                              <1> 	;add	cl, cl
  4459                              <1>         ;mov    ecx, 80*2
  4460 00001704 66B9A000            <1>         mov     cx, 80*2
  4461 00001708 29CE                <1>         sub     esi, ecx  ; next line
  4462 0000170A 29CF                <1>         sub     edi, ecx
  4463 0000170C FECF                <1> 	dec	bh	 ; count of lines to move
  4464 0000170E 75EF                <1> 	jnz	short n13 ; row loop
  4465                              <1> 	; bh = 0
  4466 00001710 88C6                <1> 	mov	dh, al	 ; #rows
  4467                              <1> n14:
  4468                              <1> 	; attribute in ah
  4469 00001712 B020                <1> 	mov	al, ' '	 ; fill with blanks
  4470                              <1> n15:
  4471 00001714 E8C3FFFFFF          <1> 	call	n11 ; 16/01/2016
  4472                              <1> 
  4473                              <1> 	;mov	cl, [CRT_COLS]
  4474                              <1> 	;add	cl, cl
  4475                              <1>         ;mov    ecx, 80*2
  4476 00001719 B1A0                <1>         mov	cl, 80*2
  4477 0000171B 29CF                <1>         sub     edi, ecx
  4478 0000171D FECE                <1> 	dec	dh
  4479 0000171F 75F3                <1> 	jnz	short n15
  4480                              <1> 	;
  4481 00001721 3A1D[A8C40000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4482 00001727 7507                <1> 	jne	short n16
  4483                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4484 00001729 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4485 0000172B 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4486 0000172F EE                  <1> 	out	dx, al
  4487                              <1> n16:
  4488                              <1> 	; !!!!
  4489 00001730 FC                  <1> 	cld		; Clear direction flag !
  4490                              <1> 	; !!!!
  4491 00001731 C3                  <1> 	retn
  4492                              <1> 
  4493                              <1> READ_AC_CURRENT:
  4494                              <1> 	; 18/01/2016
  4495                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4496                              <1> 	;
  4497                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4498                              <1> 	;
  4499                              <1> 
  4500 00001732 E805000000          <1> 	call	_read_ac_current
  4501 00001737 E9B5FDFFFF          <1>         jmp     VIDEO_RETURN
  4502                              <1> 
  4503                              <1> ;------------------------------------------------------------------------
  4504                              <1> ; READ_AC_CURRENT							:
  4505                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  4506                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  4507                              <1> ; INPUT									:
  4508                              <1> ;	(AH) = CURRENT CRT MODE						:
  4509                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  4510                              <1> ;	(DS) = DATA SEGMENT						:
  4511                              <1> ;	(ES) = REGEN SEGMENT						:
  4512                              <1> ; OUTPUT								:
  4513                              <1> ;	(AL) = CHARACTER READ						:
  4514                              <1> ;	(AH) = ATTRIBUTE READ						:
  4515                              <1> ;------------------------------------------------------------------------
  4516                              <1> 
  4517                              <1> _read_ac_current: ; 18/01/2016
  4518                              <1> 
  4519                              <1> p10:
  4520 0000173C E896FEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  4521                              <1> 	;
  4522                              <1> 	; esi = regen location
  4523                              <1> 	; dx = status port
  4524                              <1> 	;
  4525                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4526                              <1> 	;
  4527                              <1> p11:			; wait for horizontal retrace is low or vertical
  4528 00001741 FB                  <1> 	sti		; enable interrupts first
  4529 00001742 3A1D[A8C40000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4530 00001748 750C                <1> 	jne	short p14 
  4531 0000174A FA                  <1> 	cli 		; block interrupts for single loop
  4532 0000174B EC                  <1> 	in	al, dx	; get status from the adapter
  4533 0000174C A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4534 0000174E 75F1                <1> 	jnz	short p11 ; wait until it is
  4535                              <1> p12:			;  wait for either retrace high
  4536 00001750 EC                  <1> 	in	al, dx ; get status again
  4537 00001751 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4538 00001753 74FB                <1> 	jz	short p12 ; wait until either retrace active
  4539 00001755 FB                  <1> 	sti
  4540                              <1> p14:
  4541 00001756 81C600800B00        <1> 	add	esi, 0B8000h 
  4542 0000175C 668B06              <1> 	mov	ax, [esi]
  4543                              <1> 
  4544 0000175F C3                  <1> 	retn	; 18/01/2016
  4545                              <1> 
  4546                              <1> 
  4547                              <1> WRITE_AC_CURRENT:
  4548                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4549                              <1> 	;
  4550                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4551                              <1> 	;
  4552                              <1> ;----------------------------------------------------------------
  4553                              <1> ; WRITE_AC_CURRENT						:
  4554                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  4555                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  4556                              <1> ; INPUT								:
  4557                              <1> ;	(AH) = CURRENT CRT MODE					:
  4558                              <1> ;	(BH) = DISPLAY PAGE					:
  4559                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4560                              <1> ;	(AL) = CHAR TO WRITE					:
  4561                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  4562                              <1> ;	(DS) = DATA SEGMENT					:
  4563                              <1> ;	(ES) = REGEN SEGMENT					:
  4564                              <1> ; OUTPUT							:
  4565                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4566                              <1> ;----------------------------------------------------------------
  4567                              <1> 
  4568 00001760 E821000000          <1> 	call	_write_c_current
  4569                              <1> 
  4570 00001765 0FB6F3              <1> 	movzx	esi, bl ; video page number (0 to 7)	
  4571 00001768 88A6[B8BE0000]      <1> 	mov	[esi+chr_attrib], ah ; color/attribute
  4572                              <1> 
  4573 0000176E E97EFDFFFF          <1>         jmp     VIDEO_RETURN
  4574                              <1> 
  4575                              <1> WRITE_C_CURRENT:
  4576                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4577                              <1> 	;
  4578                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4579                              <1> 	;
  4580                              <1> 
  4581                              <1> 	;and	bl, 7 ; video page number (<= 7)
  4582 00001773 0FB6F3              <1> 	movzx	esi, bl	
  4583 00001776 8AA6[B8BE0000]      <1> 	mov	ah, [esi+chr_attrib]
  4584                              <1> 
  4585 0000177C E805000000          <1> 	call	_write_c_current
  4586 00001781 E96BFDFFFF          <1>         jmp     VIDEO_RETURN
  4587                              <1> 
  4588                              <1> ;----------------------------------------------------------------
  4589                              <1> ; WRITE_C_CURRENT						:
  4590                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  4591                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  4592                              <1> ; INPUT								:
  4593                              <1> ;	(AH) = CURRENT CRT MODE					:
  4594                              <1> ;	(BH) = DISPLAY PAGE					:
  4595                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4596                              <1> ;	(AL) = CHAR TO WRITE					:
  4597                              <1> ;	(DS) = DATA SEGMENT					:
  4598                              <1> ;	(ES) = REGEN SEGMENT					:
  4599                              <1> ; OUTPUT							:
  4600                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4601                              <1> ;----------------------------------------------------------------
  4602                              <1> 
  4603                              <1> _write_c_current:  ; from 'write_tty'
  4604                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4605                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4606                              <1> 	; 18/01/2014
  4607                              <1> 	; 04/12/2013
  4608                              <1> 	;
  4609                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4610                              <1> 	;
  4611                              <1> 
  4612 00001786 FA                  <1> 	cli		
  4613                              <1> 	; bl = video page
  4614                              <1> 	; al = character
  4615                              <1> 	; ah = color/attribute
  4616 00001787 6652                <1> 	push	dx
  4617 00001789 6650                <1> 	push	ax	; save character & attribute/color
  4618 0000178B E847FEFFFF          <1> 	call 	find_position  ; get regen location and port address
  4619                              <1> 	; esi = regen location
  4620                              <1> 	; dx = status port
  4621                              <1> 	;
  4622                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4623                              <1> 	;
  4624                              <1> p41:			; wait for horizontal retrace is low or vertical
  4625 00001790 FB                  <1> 	sti		; enable interrupts first
  4626 00001791 3A1D[A8C40000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4627 00001797 7510                <1> 	jne	short p44 
  4628 00001799 FA                  <1> 	cli 		; block interrupts for single loop
  4629 0000179A EC                  <1> 	in	al, dx	; get status from the adapter
  4630 0000179B A808                <1> 	test	al, RVRT ; check for vertical retrace first
  4631 0000179D 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  4632 0000179F A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4633 000017A1 75ED                <1> 	jnz	short p41 ; wait until it is
  4634                              <1> p42:			;  wait for either retrace high
  4635 000017A3 EC                  <1> 	in	al, dx ; get status again
  4636 000017A4 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4637 000017A6 74FB                <1> 	jz	short p42 ; wait until either retrace active
  4638                              <1> p43:	
  4639 000017A8 FB                  <1> 	sti
  4640                              <1> p44:
  4641 000017A9 6658                <1> 	pop	ax	; restore the character (al) & attribute (ah)
  4642 000017AB 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  4643                              <1> 				; Retro UNIX 386 v1 feature only!
  4644 000017B1 668906              <1> 	mov	[esi], ax
  4645 000017B4 665A                <1> 	pop	dx
  4646 000017B6 C3                  <1> 	retn
  4647                              <1> 
  4648                              <1> ; 18/01/2016
  4649                              <1> ; 16/01/2016
  4650                              <1> ; 30/06/2015
  4651                              <1> ; 27/06/2015
  4652                              <1> ; 11/03/2015
  4653                              <1> ; 02/09/2014
  4654                              <1> ; 30/08/2014
  4655                              <1> ; VIDEO FUNCTIONS
  4656                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  4657                              <1> 
  4658                              <1> WRITE_TTY:
  4659                              <1> 	; 30/01/2016
  4660                              <1> 	; 18/01/2016
  4661                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4662                              <1> 	; 13/08/2015
  4663                              <1> 	; 02/09/2014
  4664                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4665                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  4666                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  4667                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  4668                              <1> 	;
  4669                              <1> 	; INPUT -> AH = Color (Forecolor, Backcolor)
  4670                              <1> 	;	   AL = Character to be written
  4671                              <1> 	;	   EBX = Video Page (0 to 7)
  4672                              <1> 	;	   (BH = 0 --> Video Mode 3)
  4673                              <1> 
  4674                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  4675                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  4676                              <1> 
  4677                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  4678                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  4679                              <1> ;
  4680                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  4681                              <1> ;
  4682                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  4683                              <1> ;										:
  4684                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  4685                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  4686                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  4687                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  4688                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  4689                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  4690                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  4691                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  4692                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  4693                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  4694                              <1> ;   THE 0 COLOR IS USED.							:
  4695                              <1> ;   ENTRY --									:
  4696                              <1> ;     (AH) = CURRENT CRT MODE							:
  4697                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  4698                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  4699                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  4700                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  4701                              <1> ;   EXIT -- 									:
  4702                              <1> ;     ALL REGISTERS SAVED							:
  4703                              <1> ;--------------------------------------------------------------------------------
  4704                              <1> 
  4705 000017B7 FA                  <1> 	cli
  4706                              <1> 	;
  4707                              <1> 	; READ CURSOR (04/12/2013)
  4708                              <1> 	; Retro UNIX 386 v1 Modifications: 30/08/2014
  4709 000017B8 08FF                <1> 	or	bh, bh
  4710 000017BA 0F85D5000000        <1> 	jnz	beeper
  4711                              <1> 	; 01/09/2014
  4712 000017C0 803D[A6BE0000]03    <1> 	cmp	byte [CRT_MODE], 3
  4713 000017C7 7405                <1> 	je	short m3
  4714                              <1> 	;
  4715 000017C9 E8FBFCFFFF          <1> 	call	set_mode_3 ; 16/01/2016
  4716                              <1> m3:
  4717 000017CE 89DE                <1> 	mov 	esi, ebx ; 13/08/2015 (0 to 7)
  4718 000017D0 66D1E6              <1> 	shl	si, 1
  4719 000017D3 81C6[98C40000]      <1> 	add	esi, CURSOR_POSN
  4720 000017D9 668B16              <1> 	mov	dx, [esi]
  4721                              <1> 	;
  4722                              <1> 	; dx now has the current cursor position
  4723                              <1> 	;
  4724 000017DC 3C0D                <1> 	cmp	al, 0Dh		; is it carriage return or control character
  4725 000017DE 762F                <1> 	jbe	short u8
  4726                              <1> 	;
  4727                              <1> 	; write the char to the screen
  4728                              <1> u0:	
  4729                              <1> 	; ah = attribute/color
  4730                              <1> 	; al = character
  4731                              <1> 	; bl = video page number (0 to 7)
  4732                              <1> 	; bh = 0
  4733                              <1> 	;
  4734 000017E0 E8A1FFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  4735                              <1> 	;
  4736                              <1> 	; position the cursor for next char
  4737 000017E5 FEC2                <1> 	inc	dl		; next column
  4738                              <1> 	;cmp	dl, [CRT_COLS]
  4739 000017E7 80FA50              <1> 	cmp	dl, 80		; test for column overflow 
  4740 000017EA 755F                <1>         jne     _set_cpos
  4741 000017EC B200                <1> 	mov	dl, 0		; column = 0
  4742                              <1> u10:				; (line feed found)
  4743 000017EE 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  4744 000017F1 7218                <1> 	jb 	short u6
  4745                              <1> 	;
  4746                              <1> 	; scroll required
  4747                              <1> u1:	
  4748                              <1> 	; SET CURSOR POSITION (04/12/2013)
  4749 000017F3 E853000000          <1> 	call	_set_cpos
  4750                              <1> 	;
  4751                              <1> 	; determine value to fill with during scroll
  4752                              <1> u2:
  4753                              <1> 	; bl = video page number
  4754                              <1> 	;
  4755 000017F8 E83FFFFFFF          <1> 	call _read_ac_current ; 18/01/2016
  4756                              <1> 	;
  4757                              <1> 	; al = character, ah = attribute
  4758                              <1> 	; bl = video page number 	
  4759                              <1> u3:
  4760                              <1> 	;;mov	ax, 0601h 	; scroll one line
  4761                              <1> 	;;sub	cx, cx		; upper left corner
  4762                              <1> 	;;mov	dh, 25-1 	; lower right row
  4763                              <1> 	;;;mov	dl, [CRT_COLS]
  4764                              <1> 	;mov	dl, 80		; lower right column	
  4765                              <1> 	;;dec	dl
  4766                              <1> 	;;mov	dl, 79
  4767                              <1> 
  4768                              <1> 	;;call	scroll_up	; 04/12/2013
  4769                              <1> 	;;; 11/03/2015
  4770                              <1> 	; 02/09/2014
  4771                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  4772                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  4773                              <1> 	; 11/03/2015
  4774 000017FD 6629C9              <1> 	sub	cx, cx
  4775 00001800 66BA4F18            <1> 	mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  4776                              <1> 	;
  4777 00001804 B001                <1> 	mov	al, 1		; scroll 1 line up
  4778                              <1> 		; ah = attribute
  4779 00001806 E902FEFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  4780                              <1> ;u4:
  4781                              <1> 	;;int	10h		; video-call return
  4782                              <1> 				; scroll up the screen
  4783                              <1> 				; tty return
  4784                              <1> ;u5:
  4785                              <1> 	;retn			; return to the caller
  4786                              <1> 
  4787                              <1> u6:				; set-cursor-inc
  4788 0000180B FEC6                <1> 	inc	dh		; next row
  4789                              <1> 				; set cursor
  4790                              <1> ;u7:					
  4791                              <1> 	;;mov	ah, 02h
  4792                              <1> 	;;jmp	short u4 	; establish the new cursor
  4793                              <1> 	;call	_set_cpos
  4794                              <1> 	;jmp 	short u5
  4795 0000180D EB3C                <1> 	jmp     _set_cpos
  4796                              <1> 
  4797                              <1> 	; check for control characters
  4798                              <1> u8:
  4799 0000180F 7438                <1> 	je	short u9
  4800 00001811 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  4801 00001813 74D9                <1> 	je	short u10
  4802 00001815 3C07                <1> 	cmp	al, 07h 	; is it a bell
  4803 00001817 747C                <1> 	je	short u11
  4804 00001819 3C08                <1> 	cmp	al, 08h		; is it a backspace
  4805                              <1> 	;jne	short u0
  4806 0000181B 7424                <1> 	je	short bs	; 12/12/2013
  4807                              <1> 	; 12/12/2013 (tab stop)
  4808 0000181D 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  4809 0000181F 75BF                <1> 	jne	short u0
  4810 00001821 88D0                <1> 	mov	al, dl
  4811 00001823 6698                <1> 	cbw
  4812 00001825 B108                <1> 	mov	cl, 8
  4813 00001827 F6F1                <1> 	div	cl
  4814 00001829 28E1                <1> 	sub	cl, ah
  4815                              <1> ts:
  4816                              <1> 	; 02/09/2014
  4817                              <1> 	; 01/09/2014
  4818 0000182B B020                <1> 	mov	al, 20h
  4819                              <1> tsloop:
  4820 0000182D 6651                <1> 	push	cx
  4821 0000182F 6650                <1> 	push	ax
  4822 00001831 30FF                <1> 	xor 	bh, bh
  4823                              <1> 	;mov	bl, [ACTIVE_PAGE]
  4824 00001833 E896FFFFFF          <1> 	call	m3
  4825 00001838 6658                <1> 	pop	ax  ; ah = attribute/color
  4826 0000183A 6659                <1> 	pop	cx
  4827 0000183C FEC9                <1> 	dec	cl
  4828 0000183E 75ED                <1> 	jnz	short tsloop
  4829 00001840 C3                  <1> 	retn
  4830                              <1> bs:	
  4831                              <1> 	; back space found
  4832                              <1> 
  4833 00001841 08D2                <1> 	or	dl, dl 		; is it already at start of line
  4834                              <1> 	;je	short u7 	; set_cursor
  4835 00001843 7406                <1> 	jz	short _set_cpos
  4836 00001845 664A                <1> 	dec	dx     		; no -- just move it back
  4837                              <1> 	;jmp	short u7
  4838 00001847 EB02                <1> 	jmp	short _set_cpos
  4839                              <1> 
  4840                              <1> 	; carriage return found
  4841                              <1> u9:
  4842 00001849 B200                <1> 	mov	dl, 0 		; move to first column
  4843                              <1> 	;jmp	short u7
  4844                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  4845                              <1> 
  4846                              <1> 	; line feed found
  4847                              <1> ;u10:
  4848                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  4849                              <1> ;	jne	short u6 	; no, just set the cursor
  4850                              <1> ;       jmp     u1              ; yes, scroll the screen
  4851                              <1> 
  4852                              <1> _set_cpos:
  4853                              <1> 	; 27/06/2015
  4854                              <1> 	; 01/09/2014
  4855                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4856                              <1> 	;
  4857                              <1> 	; 12/12/2013 (Retro UNIX 8086 v1 - last update) 
  4858                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1 - beginning)
  4859                              <1> 	;
  4860                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4861                              <1> 	;
  4862                              <1> ;----------------------------------------------
  4863                              <1> ; SET_CPOS
  4864                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  4865                              <1> ;	NEW X-Y VALUES PASSED
  4866                              <1> ; INPUT
  4867                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  4868                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  4869                              <1> ; OUTPUT
  4870                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  4871                              <1> ;----------------------------------------------
  4872                              <1> 	;
  4873 0000184B BE[98C40000]        <1> 	mov	esi, CURSOR_POSN
  4874 00001850 0FB6C3              <1>         movzx   eax, bl	; BL = video page number ; 27/06/2015 (movzx)
  4875                              <1> ;	or	al, al
  4876                              <1> ;	jz	short _set_cpos_0
  4877 00001853 D0E0                <1>         shl     al, 1   ; word offset
  4878 00001855 01C6                <1>         add     esi, eax
  4879                              <1> ;_set_cpos_0:
  4880 00001857 668916              <1> 	mov	[esi], dx ; save the pointer
  4881 0000185A 381D[A8C40000]      <1> 	cmp	[ACTIVE_PAGE], bl
  4882 00001860 7532                <1> 	jne	short m17
  4883                              <1> 	;call	m18	; CURSOR SET
  4884                              <1> ;m17:			; SET_CPOS_RETURN
  4885                              <1> 	; 01/09/2014
  4886                              <1> ;	retn
  4887                              <1> 		; DX  = row/column
  4888                              <1> m18:
  4889 00001862 E861FDFFFF          <1> 	call	position ; determine location in regen buffer	
  4890 00001867 668B0D[94C40000]    <1> 	mov	cx, [CRT_START]
  4891 0000186E 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  4892                              <1> 			; to the start address (offset) for this page
  4893 00001871 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  4894 00001874 B40E                <1> 	mov	ah, 14	; register number for cursor
  4895                              <1> 	;call	m16	; output value to the 6845	
  4896                              <1> 	;retn
  4897                              <1> 
  4898                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  4899                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  4900                              <1> m16:
  4901 00001876 FA                  <1> 	cli
  4902                              <1> 	;mov	dx, [addr_6845] ; address register
  4903 00001877 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  4904 0000187B 88E0                <1> 	mov	al, ah	; get value
  4905 0000187D EE                  <1> 	out	dx, al	; register set
  4906 0000187E 6642                <1> 	inc	dx	; data register
  4907 00001880 EB00                <1> 	jmp	$+2	; i/o delay
  4908 00001882 88E8                <1> 	mov	al, ch	; data
  4909 00001884 EE                  <1> 	out	dx, al	
  4910 00001885 664A                <1> 	dec	dx	
  4911 00001887 88E0                <1> 	mov	al, ah
  4912 00001889 FEC0                <1> 	inc	al	; point to other data register
  4913 0000188B EE                  <1> 	out	dx, al	; set for second register
  4914 0000188C 6642                <1> 	inc	dx
  4915 0000188E EB00                <1> 	jmp	$+2	; i/o delay
  4916 00001890 88C8                <1> 	mov	al, cl	; second data value
  4917 00001892 EE                  <1> 	out	dx, al
  4918 00001893 FB                  <1> 	sti
  4919                              <1> m17:
  4920 00001894 C3                  <1> 	retn
  4921                              <1> 
  4922                              <1> beeper: 
  4923                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4924                              <1> 	; 18/01/2014
  4925                              <1> 	; 03/12/2013
  4926                              <1> 	; bell found
  4927                              <1> u11:
  4928 00001895 FB                  <1> 	sti
  4929 00001896 3A1D[A8C40000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4930 0000189C 7551                <1> 	jne	short u12	; Do not sound the beep 
  4931                              <1> 				; if it is not written on the active page
  4932 0000189E 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  4933 000018A2 B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  4934                              <1> 	;call	beep		; sound the pod bell
  4935                              <1> 	;jmp	short u5 	; tty_return
  4936                              <1> 	;retn
  4937                              <1> 	
  4938                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  4939                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  4940                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  4941                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  4942                              <1> 
  4943                              <1> beep:
  4944                              <1> 	; 07/02/2015
  4945                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4946                              <1> 	; 18/01/2014
  4947                              <1> 	; 03/12/2013
  4948                              <1> 	;
  4949                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  4950                              <1> 	;
  4951                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  4952                              <1> 	;
  4953                              <1> 	; ENTRY:
  4954                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  4955                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  4956                              <1> 	; EXIT:				:
  4957                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  4958                              <1> 
  4959 000018A4 9C                  <1> 	pushf  ; 18/01/2014	; save interrupt status
  4960 000018A5 FA                  <1> 	cli			; block interrupts during update
  4961 000018A6 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  4962 000018A8 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  4963 000018AA EB00                <1> 	jmp	$+2		; I/O delay
  4964 000018AC 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  4965 000018AE E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  4966 000018B0 EB00                <1> 	jmp	$+2		; I/O delay
  4967 000018B2 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  4968 000018B4 E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  4969 000018B6 E461                <1> 	in	al, PORT_B	; get current setting of port
  4970 000018B8 88C4                <1> 	mov	ah, al		; save that setting
  4971 000018BA 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  4972 000018BC E661                <1> 	out	PORT_B, al	; and restore interrupt status
  4973                              <1> 	;popf	; 18/01/2014
  4974 000018BE FB                  <1> 	sti
  4975                              <1> g7:				; 1/64 second per count (bl)
  4976 000018BF B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second	
  4977 000018C4 E827000000          <1> 	call	waitf		; go to beep delay 1/64 count
  4978 000018C9 FECB                <1> 	dec	bl		; (bl) length count expired?
  4979 000018CB 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  4980                              <1> 	;
  4981                              <1> 	;pushf			; save interrupt status
  4982 000018CD FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  4983 000018CE E461                <1> 	in	al, PORT_B	; get current port value
  4984                              <1>         ;or      al, not (GATE2+SPK2) ; isolate current speaker bits in case
  4985 000018D0 0CFC                <1>         or      al, ~(GATE2+SPK2)
  4986 000018D2 20C4                <1>         and	ah, al		; someone turned them off during beep
  4987 000018D4 88E0                <1> 	mov	al, ah		; recover value of port
  4988                              <1>         ;or      al, not (GATE2+SPK2) ; force speaker data off
  4989 000018D6 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  4990 000018D8 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  4991                              <1> 	;popf			; restore interrupt flag state
  4992 000018DA FB                  <1> 	sti
  4993 000018DB B90B040000          <1> 	mov	ecx, 1035	; force 1/64 second delay (short)
  4994 000018E0 E80B000000          <1> 	call	waitf		; minimum delay between all beeps
  4995                              <1> 	;pushf			; save interrupt status
  4996 000018E5 FA                  <1> 	cli			; block interrupts during update
  4997 000018E6 E461                <1> 	in	al, PORT_B	; get current port value in case	
  4998 000018E8 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  4999 000018EA 08E0                <1> 	or	al, ah		; recover value of port_b
  5000 000018EC E661                <1> 	out	PORT_B, al	; restore speaker status
  5001 000018EE 9D                  <1> 	popf			; restore interrupt flag state
  5002                              <1> u12:	
  5003 000018EF C3                  <1> 	retn
  5004                              <1> 
  5005                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  5006                              <1> 
  5007                              <1> WAITF:
  5008                              <1> waitf:
  5009                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  5010                              <1> 	; 03/12/2013
  5011                              <1> 	;
  5012                              <1> ;	push ax			; save work register (ah)	
  5013                              <1> ;waitf1:
  5014                              <1> 				; use timer 1 output bits
  5015                              <1> ;	in	al, PORT_B	; read current counter output status
  5016                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  5017                              <1> ;	cmp	al, ah		; did it just change
  5018                              <1> ;	je	short waitf1	; wait for a change in output line
  5019                              <1> ;	;
  5020                              <1> ;	mov	ah, al		; save new lflag state
  5021                              <1> ;	loop	waitf1		; decrement half cycles till count end		
  5022                              <1> ;	;
  5023                              <1> ;	pop	ax		; restore (ah)
  5024                              <1> ;	retn			; return (cx)=0
  5025                              <1> 
  5026                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  5027                              <1> ; 17/12/2014 (dsectrm2.s)
  5028                              <1> ; WAITF
  5029                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  5030                              <1> ;
  5031                              <1> ;---WAITF-----------------------------------------------------------------------
  5032                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  5033                              <1> ; ENTRY:
  5034                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  5035                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  5036                              <1> ; EXIT:
  5037                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  5038                              <1> ;	(CX) = 0	
  5039                              <1> ;-------------------------------------------------------------------------------
  5040                              <1> 
  5041                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  5042                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  5043                              <1> 
  5044                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  5045 000018F0 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER (AH)
  5046                              <1> 	; 16/12/2014
  5047                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  5048 000018F2 D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  5049                              <1> ;17/12/2014	
  5050                              <1> ;WAITF1:
  5051                              <1> ;	IN	AL, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  5052                              <1> ;	AND	AL, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  5053                              <1> ;	CMP	AL, AH			; DID IT JUST CHANGE
  5054                              <1> ;	JE	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  5055                              <1> ;	MOV	AH, AL			; SAVE NEW FLAG STATE
  5056                              <1> ;	LOOP	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  5057                              <1> 	;
  5058                              <1> 	; 17/12/2014
  5059                              <1> 	;
  5060                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  5061                              <1> 	;
  5062                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  5063                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  5064                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  5065                              <1> WR_STATE_0:
  5066 000018F4 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5067 000018F6 A810                <1> 	TEST	AL,010H
  5068 000018F8 74FA                <1> 	JZ	SHORT WR_STATE_0
  5069                              <1> WR_STATE_1:
  5070 000018FA E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5071 000018FC A810                <1> 	TEST	AL,010H
  5072 000018FE 75FA                <1> 	JNZ	SHORT WR_STATE_1
  5073 00001900 E2F2                <1>         LOOP    WR_STATE_0
  5074                              <1> 	;
  5075 00001902 6658                <1> 	POP	AX			; RESTORE (AH)
  5076 00001904 C3                  <1> 	RETn				; (CX) = 0
  5077                              <1> 
  5078                              <1> ; % include 'vidata.s' ; VIDEO DATA
  5079                              <1> 
  5080                              <1> ; /// End Of VIDEO FUNCTIONS ///
  5081                                  
  5082                                  setup_rtc_int:
  5083                                  ; source: http://wiki.osdev.org/RTC
  5084 00001905 FA                      	cli		; disable interrupts
  5085                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  5086                                  	; in order to change this ...
  5087                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  5088                                  	; (rate must be above 2 and not over 15)
  5089                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  5090 00001906 B08A                    	mov	al, 8Ah 
  5091 00001908 E670                    	out	70h, al ; set index to register A, disable NMI
  5092 0000190A 90                      	nop
  5093 0000190B E471                    	in	al, 71h ; get initial value of register A
  5094 0000190D 88C4                    	mov 	ah, al
  5095 0000190F 80E4F0                  	and	ah, 0F0h
  5096 00001912 B08A                    	mov	al, 8Ah 
  5097 00001914 E670                    	out	70h, al ; reset index to register A
  5098 00001916 88E0                    	mov	al, ah
  5099 00001918 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  5100 0000191A E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  5101                                  	; enable RTC interrupt
  5102 0000191C B08B                    	mov	al, 8Bh ;
  5103 0000191E E670                    	out	70h, al ; select register B and disable NMI
  5104 00001920 90                      	nop
  5105 00001921 E471                    	in	al, 71h ; read the current value of register B
  5106 00001923 88C4                    	mov	ah, al  ;
  5107 00001925 B08B                    	mov 	al, 8Bh ;
  5108 00001927 E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  5109 00001929 88E0                    	mov	al, ah  ;
  5110 0000192B 0C40                    	or	al, 40h ;
  5111 0000192D E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  5112 0000192F FB                      	sti
  5113 00001930 C3                      	retn
  5114                                  
  5115                                  ; Write memory information
  5116                                  ; 29/01/2016
  5117                                  ; 06/11/2014
  5118                                  ; 14/08/2015 
  5119                                  memory_info:	
  5120 00001931 A1[7CC40000]            	mov	eax, [memory_size] ; in pages
  5121 00001936 50                      	push	eax
  5122 00001937 C1E00C                  	shl	eax, 12		   ; in bytes
  5123 0000193A BB0A000000              	mov	ebx, 10
  5124 0000193F 89D9                    	mov	ecx, ebx	   ; 10
  5125 00001941 BE[C7C00000]            	mov	esi, mem_total_b_str	
  5126 00001946 E8BE000000              	call	bintdstr
  5127 0000194B 58                      	pop	eax
  5128 0000194C B107                    	mov	cl, 7
  5129 0000194E BE[EBC00000]            	mov	esi, mem_total_p_str
  5130 00001953 E8B1000000              	call	bintdstr	
  5131                                  	; 14/08/2015
  5132 00001958 E8C9000000              	call	calc_free_mem
  5133                                  	; edx = calculated free pages
  5134                                  	; ecx = 0
  5135 0000195D A1[80C40000]            	mov 	eax, [free_pages]
  5136 00001962 39D0                    	cmp	eax, edx ; calculated free mem value 
  5137                                  		; and initial free mem value are same or not?
  5138 00001964 751D                    	jne 	short pmim ; print mem info with '?' if not
  5139 00001966 52                      	push 	edx ; free memory in pages	
  5140                                  	;mov 	eax, edx
  5141 00001967 C1E00C                  	shl	eax, 12 ; convert page count
  5142                                  			; to byte count
  5143 0000196A B10A                    	mov	cl, 10
  5144 0000196C BE[0BC10000]            	mov	esi, free_mem_b_str
  5145 00001971 E893000000              	call	bintdstr
  5146 00001976 58                      	pop	eax
  5147 00001977 B107                    	mov	cl, 7
  5148 00001979 BE[2FC10000]            	mov	esi, free_mem_p_str
  5149 0000197E E886000000              	call	bintdstr
  5150                                  pmim:
  5151 00001983 BE[B5C00000]            	mov	esi, msg_memory_info
  5152                                  	;
  5153 00001988 B407                    	mov	ah, 07h ; Black background, 
  5154                                  			; light gray forecolor
  5155                                  print_kmsg: ; 29/01/2016
  5156 0000198A 8825[A9C40000]          	mov	[ccolor], ah
  5157                                  pkmsg_loop:
  5158 00001990 AC                      	lodsb
  5159 00001991 08C0                    	or	al, al
  5160 00001993 7411                    	jz	short pkmsg_ok
  5161 00001995 56                      	push	esi
  5162 00001996 31DB                    	xor	ebx, ebx ; 0
  5163                                  			; Video page 0 (bl=0)
  5164 00001998 8A25[A9C40000]          	mov	ah, [ccolor]
  5165 0000199E E814FEFFFF              	call	WRITE_TTY
  5166 000019A3 5E                      	pop	esi
  5167 000019A4 EBEA                    	jmp	short pkmsg_loop
  5168                                  pkmsg_ok:
  5169 000019A6 C3                      	retn
  5170                                  
  5171                                  ; Convert binary number to hexadecimal string
  5172                                  ; 10/05/2015  
  5173                                  ; dsectpm.s (28/02/2015)
  5174                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  5175                                  ; 01/12/2014
  5176                                  ; 25/11/2014
  5177                                  ;
  5178                                  bytetohex:
  5179                                  	; INPUT ->
  5180                                  	; 	AL = byte (binary number)
  5181                                  	; OUTPUT ->
  5182                                  	;	AX = hexadecimal string
  5183                                  	;
  5184 000019A7 53                      	push	ebx
  5185 000019A8 31DB                    	xor	ebx, ebx
  5186 000019AA 88C3                    	mov	bl, al
  5187 000019AC C0EB04                  	shr	bl, 4
  5188 000019AF 8A9B[F9190000]          	mov	bl, [ebx+hexchrs] 	 	
  5189 000019B5 86D8                    	xchg	bl, al
  5190 000019B7 80E30F                  	and	bl, 0Fh
  5191 000019BA 8AA3[F9190000]          	mov	ah, [ebx+hexchrs] 
  5192 000019C0 5B                      	pop	ebx	
  5193 000019C1 C3                      	retn
  5194                                  
  5195                                  wordtohex:
  5196                                  	; INPUT ->
  5197                                  	; 	AX = word (binary number)
  5198                                  	; OUTPUT ->
  5199                                  	;	EAX = hexadecimal string
  5200                                  	;
  5201 000019C2 53                      	push	ebx
  5202 000019C3 31DB                    	xor	ebx, ebx
  5203 000019C5 86E0                    	xchg	ah, al
  5204 000019C7 6650                    	push	ax
  5205 000019C9 88E3                    	mov	bl, ah
  5206 000019CB C0EB04                  	shr	bl, 4
  5207 000019CE 8A83[F9190000]          	mov	al, [ebx+hexchrs] 	 	
  5208 000019D4 88E3                    	mov	bl, ah
  5209 000019D6 80E30F                  	and	bl, 0Fh
  5210 000019D9 8AA3[F9190000]          	mov	ah, [ebx+hexchrs]
  5211 000019DF C1E010                  	shl	eax, 16
  5212 000019E2 6658                    	pop	ax
  5213 000019E4 5B                      	pop	ebx
  5214 000019E5 EBC0                    	jmp	short bytetohex
  5215                                  	;mov	bl, al
  5216                                  	;shr	bl, 4
  5217                                  	;mov	bl, [ebx+hexchrs] 	 	
  5218                                  	;xchg	bl, al	 	
  5219                                  	;and	bl, 0Fh
  5220                                  	;mov	ah, [ebx+hexchrs] 
  5221                                  	;pop	ebx	
  5222                                  	;retn
  5223                                  
  5224                                  dwordtohex:
  5225                                  	; INPUT ->
  5226                                  	; 	EAX = dword (binary number)
  5227                                  	; OUTPUT ->
  5228                                  	;	EDX:EAX = hexadecimal string
  5229                                  	;
  5230 000019E7 50                      	push	eax
  5231 000019E8 C1E810                  	shr	eax, 16
  5232 000019EB E8D2FFFFFF              	call	wordtohex
  5233 000019F0 89C2                    	mov	edx, eax
  5234 000019F2 58                      	pop	eax
  5235 000019F3 E8CAFFFFFF              	call	wordtohex
  5236 000019F8 C3                      	retn
  5237                                  
  5238                                  ; 10/05/2015
  5239                                  hex_digits:
  5240                                  hexchrs:
  5241 000019F9 303132333435363738-     	db '0123456789ABCDEF'
  5242 00001A02 39414243444546     
  5243                                  
  5244                                  ; Convert binary number to decimal/numeric string
  5245                                  ; 06/11/2014
  5246                                  ; Temporary Code
  5247                                  ;
  5248                                  
  5249                                  bintdstr:
  5250                                  	; EAX = binary number
  5251                                  	; ESI = decimal/numeric string address
  5252                                  	; EBX = divisor (10)
  5253                                  	; ECX = string length (<=10)
  5254 00001A09 01CE                    	add	esi, ecx
  5255                                  btdstr0:
  5256 00001A0B 4E                      	dec	esi
  5257 00001A0C 31D2                    	xor	edx, edx
  5258 00001A0E F7F3                    	div	ebx
  5259 00001A10 80C230                  	add	dl, 30h
  5260 00001A13 8816                    	mov	[esi], dl
  5261 00001A15 FEC9                    	dec	cl
  5262 00001A17 740C                    	jz	btdstr2
  5263 00001A19 09C0                    	or	eax, eax
  5264 00001A1B 75EE                    	jnz	short btdstr0
  5265                                  btdstr1:
  5266 00001A1D 4E                      	dec	esi
  5267 00001A1E C60620                          mov     byte [esi], 20h ; blank space
  5268 00001A21 FEC9                    	dec	cl
  5269 00001A23 75F8                    	jnz	short btdstr1
  5270                                  btdstr2:
  5271 00001A25 C3                      	retn
  5272                                  
  5273                                  ; Calculate free memory pages on M.A.T.
  5274                                  ; 06/11/2014
  5275                                  ; Temporary Code
  5276                                  ;
  5277                                  
  5278                                  calc_free_mem:
  5279 00001A26 31D2                    	xor	edx, edx
  5280                                  	;xor	ecx, ecx
  5281 00001A28 668B0D[90C40000]        	mov	cx, [mat_size] ; in pages
  5282 00001A2F C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  5283 00001A32 BE00001000              	mov	esi, MEM_ALLOC_TBL
  5284                                  cfm0:
  5285 00001A37 AD                      	lodsd
  5286 00001A38 51                      	push	ecx
  5287 00001A39 B920000000              	mov	ecx, 32
  5288                                  cfm1:
  5289 00001A3E D1E8                    	shr	eax, 1
  5290 00001A40 7301                    	jnc	short cfm2
  5291 00001A42 42                      	inc	edx
  5292                                  cfm2:
  5293 00001A43 E2F9                    	loop	cfm1
  5294 00001A45 59                      	pop	ecx
  5295 00001A46 E2EF                    	loop	cfm0
  5296 00001A48 C3                      	retn
  5297                                  
  5298                                  %include 'diskio.s'  ; 07/03/2015
  5299                              <1> ; ****************************************************************************
  5300                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskio.s
  5301                              <1> ; ----------------------------------------------------------------------------
  5302                              <1> ; Last Update: 18/02/2016
  5303                              <1> ; ----------------------------------------------------------------------------
  5304                              <1> ; Beginning: 24/01/2016
  5305                              <1> ; ----------------------------------------------------------------------------
  5306                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  5307                              <1> ; ----------------------------------------------------------------------------
  5308                              <1> ; Turkish Rational DOS
  5309                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  5310                              <1> ;
  5311                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  5312                              <1> ; diskio.inc (22/08/2015)
  5313                              <1> ;
  5314                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
  5315                              <1> ; ****************************************************************************
  5316                              <1> 
  5317                              <1> ; Retro UNIX 386 v1 Kernel - DISKIO.INC
  5318                              <1> ; Last Modification: 22/08/2015
  5319                              <1> ; 	(Initialized Disk Parameters Data is in 'DISKDATA.INC') 
  5320                              <1> ; 	(Uninitialized Disk Parameters Data is in 'DISKBSS.INC') 
  5321                              <1> 
  5322                              <1> ; DISK I/O SYSTEM - Erdogan Tan (Retro UNIX 386 v1 project)
  5323                              <1> 
  5324                              <1> ; ///////// DISK I/O SYSTEM ///////////////
  5325                              <1> 
  5326                              <1> ; 06/02/2015
  5327                              <1> diskette_io:
  5328 00001A49 9C                  <1> 	pushfd
  5329 00001A4A 0E                  <1> 	push 	cs
  5330 00001A4B E809000000          <1> 	call 	DISKETTE_IO_1
  5331 00001A50 C3                  <1> 	retn
  5332                              <1> 	
  5333                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
  5334                              <1> ;//////////////////////////////////////////////////////
  5335                              <1> 
  5336                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  5337                              <1> ; 20/02/2015
  5338                              <1> ; 06/02/2015 (unix386.s)
  5339                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
  5340                              <1> ;
  5341                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
  5342                              <1> ;
  5343                              <1> ; ADISK.EQU
  5344                              <1> 
  5345                              <1> ;----- Wait control constants 
  5346                              <1> 
  5347                              <1> ;amount of time to wait while RESET is active.
  5348                              <1> 
  5349                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
  5350                              <1> 						;at 250 KBS xfer rate.
  5351                              <1> 						;see INTEL MCS, 1985, pg. 5-456
  5352                              <1> 
  5353                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
  5354                              <1> 						;status register to become valid
  5355                              <1> 						;before re-reading.
  5356                              <1> 
  5357                              <1> ;After sending a byte to NEC, status register may remain
  5358                              <1> ;incorrectly set for 24 us.
  5359                              <1> 
  5360                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
  5361                              <1> 						;RQM low.
  5362                              <1> 
  5363                              <1> ; COMMON.MAC
  5364                              <1> ;
  5365                              <1> ;	Timing macros
  5366                              <1> ;
  5367                              <1> 
  5368                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
  5369                              <1> 		jmp short $+2
  5370                              <1> %endmacro		
  5371                              <1> 
  5372                              <1> %macro		IODELAY  0			; NORMAL IODELAY
  5373                              <1> 		jmp short $+2
  5374                              <1> 		jmp short $+2
  5375                              <1> %endmacro
  5376                              <1> 
  5377                              <1> %macro		NEWIODELAY 0
  5378                              <1> 		out	0ebh,al
  5379                              <1> %endmacro 
  5380                              <1> 
  5381                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
  5382                              <1> ;;; WAIT_FOR_MEM
  5383                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
  5384                              <1> ;WAIT_FDU_INT_HI	equ	1
  5385                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
  5386                              <1> ;;; WAIT_FOR_PORT
  5387                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
  5388                              <1> ;WAIT_FDU_SEND_HI	equ	0
  5389                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
  5390                              <1> ;Time to wait while waiting for each byte of NEC results = .5
  5391                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  5392                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
  5393                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
  5394                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
  5395                              <1> ;;; WAIT_REFRESH
  5396                              <1> ;amount of time to wait for head settle, per unit in parameter
  5397                              <1> ;table = 1 ms.
  5398                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
  5399                              <1> 
  5400                              <1> 
  5401                              <1> ; //////////////// DISKETTE I/O ////////////////
  5402                              <1> 
  5403                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
  5404                              <1> 
  5405                              <1> ;----------------------------------------
  5406                              <1> ;	EQUATES USED BY POST AND BIOS	:
  5407                              <1> ;----------------------------------------
  5408                              <1> 
  5409                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
  5410                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
  5411                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  5412                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
  5413                              <1> 
  5414                              <1> ;----------------------------------------
  5415                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
  5416                              <1> ;-------------------------------------------------------------------------------
  5417                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
  5418                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
  5419                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
  5420                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
  5421                              <1> 
  5422                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
  5423                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
  5424                              <1> ;		EQU	011H		; - RESERVED			      ;C
  5425                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
  5426                              <1> ;		EQU	013H		; - RESERVED			      ;E
  5427                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
  5428                              <1> 
  5429                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
  5430                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
  5431                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
  5432                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
  5433                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
  5434                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
  5435                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
  5436                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
  5437                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
  5438                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
  5439                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
  5440                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
  5441                              <1> 
  5442                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
  5443                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
  5444                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
  5445                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
  5446                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
  5447                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
  5448                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
  5449                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
  5450                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
  5451                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
  5452                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
  5453                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
  5454                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
  5455                              <1> 
  5456                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
  5457                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
  5458                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
  5459                              <1> 
  5460                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
  5461                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
  5462                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
  5463                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
  5464                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
  5465                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
  5466                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
  5467                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
  5468                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
  5469                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
  5470                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
  5471                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
  5472                              <1> 
  5473                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
  5474                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
  5475                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
  5476                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
  5477                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
  5478                              <1> 
  5479                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
  5480                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
  5481                              <1> ;INTA00		EQU	020H		; 8259 PORT
  5482                              <1> INTA01		EQU	021H		; 8259 PORT
  5483                              <1> INTB00		EQU	0A0H		; 2ND 8259
  5484                              <1> INTB01		EQU	0A1H		;
  5485                              <1> 
  5486                              <1> ;-------------------------------------------------------------------------------
  5487                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
  5488                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
  5489                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
  5490                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
  5491                              <1> ;-------------------------------------------------------------------------------
  5492                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
  5493                              <1> 
  5494                              <1> ;-------------------------------------------------------------------------------
  5495                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
  5496                              <1> 
  5497                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
  5498                              <1> ; (unix386.s <-- dsectrm2.s)
  5499                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
  5500                              <1> 
  5501                              <1> ; 10/12/2014
  5502                              <1> ;
  5503                              <1> ;int40h:
  5504                              <1> ;	pushf
  5505                              <1> ;	push 	cs
  5506                              <1> ;	;cli
  5507                              <1> ;	call 	DISKETTE_IO_1
  5508                              <1> ;	retn
  5509                              <1> 
  5510                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
  5511                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  5512                              <1> ;
  5513                              <1> 
  5514                              <1> ;-- INT13H ---------------------------------------------------------------------
  5515                              <1> ; DISKETTE I/O
  5516                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
  5517                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
  5518                              <1> ; INPUT
  5519                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
  5520                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
  5521                              <1> ;		ON ALL DRIVES
  5522                              <1> ;------------------------------------------------------------------------------- 
  5523                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
  5524                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
  5525                              <1> ;-------------------------------------------------------------------------------
  5526                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
  5527                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5528                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
  5529                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
  5530                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
  5531                              <1> ;		320/360	320/360	    0-39
  5532                              <1> ;		320/360	1.2M	    0-39
  5533                              <1> ;		1.2M	1.2M	    0-79
  5534                              <1> ;		720K	720K	    0-79
  5535                              <1> ;		1.44M	1.44M	    0-79	
  5536                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
  5537                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
  5538                              <1> ;		320/360	320/360	     1-8/9
  5539                              <1> ;		320/360	1.2M	     1-8/9
  5540                              <1> ;		1.2M	1.2M	     1-15
  5541                              <1> ;		720K	720K	     1-9
  5542                              <1> ;		1.44M	1.44M	     1-18		
  5543                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
  5544                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
  5545                              <1> ;		320/360	320/360	        8/9
  5546                              <1> ;		320/360	1.2M	        8/9
  5547                              <1> ;		1.2M	1.2M		15
  5548                              <1> ;		720K	720K		9
  5549                              <1> ;		1.44M	1.44M		18
  5550                              <1> ;
  5551                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
  5552                              <1> ;
  5553                              <1> ;-------------------------------------------------------------------------------
  5554                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
  5555                              <1> ;-------------------------------------------------------------------------------
  5556                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
  5557                              <1> ;-------------------------------------------------------------------------------
  5558                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
  5559                              <1> ;-------------------------------------------------------------------------------
  5560                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
  5561                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
  5562                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
  5563                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
  5564                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
  5565                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
  5566                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
  5567                              <1> ;		READ/WRITE ACCESS.
  5568                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
  5569                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
  5570                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
  5571                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
  5572                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
  5573                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
  5574                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
  5575                              <1> ;
  5576                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
  5577                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
  5578                              <1> ;		---------------------------------------------
  5579                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
  5580                              <1> ;		---------------------------------------------
  5581                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
  5582                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
  5583                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
  5584                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
  5585                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
  5586                              <1> ;		---------------------------------------------
  5587                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
  5588                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
  5589                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
  5590                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
  5591                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
  5592                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
  5593                              <1> ;-------------------------------------------------------------------------------
  5594                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
  5595                              <1> ;	REGISTERS
  5596                              <1> ;	  INPUT
  5597                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5598                              <1> ;	  OUTPUT
  5599                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
  5600                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
  5601                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5602                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5603                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
  5604                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
  5605                              <1> ;	    (BH) - 0
  5606                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
  5607                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
  5608                              <1> ;	    (AX) - 0
  5609                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
  5610                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
  5611                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
  5612                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
  5613                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
  5614                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
  5615                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
  5616                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
  5617                              <1> ;-------------------------------------------------------------------------------
  5618                              <1> ;	(AH)= 15H  READ DASD TYPE
  5619                              <1> ;	OUTPUT REGISTERS
  5620                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
  5621                              <1> ;		00 - DRIVE NOT PRESENT	
  5622                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
  5623                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
  5624                              <1> ;		03 - RESERVED (FIXED DISK)
  5625                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5626                              <1> ;-------------------------------------------------------------------------------
  5627                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
  5628                              <1> ;	OUTPUT REGISTERS
  5629                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
  5630                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
  5631                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5632                              <1> ;-------------------------------------------------------------------------------
  5633                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
  5634                              <1> ;	INPUT REGISTERS
  5635                              <1> ;	(AL) -	00 - NOT USED	
  5636                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
  5637                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
  5638                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
  5639                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
  5640                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
  5641                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
  5642                              <1> ;-------------------------------------------------------------------------------
  5643                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
  5644                              <1> ;	INPUT REGISTERS
  5645                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
  5646                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5647                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5648                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
  5649                              <1> ;	OUTPUT REGISTERS:
  5650                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
  5651                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
  5652                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
  5653                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
  5654                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
  5655                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
  5656                              <1> ;-------------------------------------------------------------------------------
  5657                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
  5658                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
  5659                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
  5660                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
  5661                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
  5662                              <1> ;		CHANGE ERROR CODE
  5663                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
  5664                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
  5665                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
  5666                              <1> ;
  5667                              <1> ; DATA VARIABLE -- @DISK_POINTER
  5668                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
  5669                              <1> ;-------------------------------------------------------------------------------
  5670                              <1> ; OUTPUT FOR ALL FUNCTIONS
  5671                              <1> ;	AH = STATUS OF OPERATION
  5672                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
  5673                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
  5674                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
  5675                              <1> ;		TYPE AH=(15)).
  5676                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
  5677                              <1> ;	FOR READ/WRITE/VERIFY
  5678                              <1> ;		DS,BX,DX,CX PRESERVED
  5679                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
  5680                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
  5681                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
  5682                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
  5683                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
  5684                              <1> ;-------------------------------------------------------------------------------
  5685                              <1> ;
  5686                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
  5687                              <1> ;
  5688                              <1> ;   -----------------------------------------------------------------
  5689                              <1> ;   |       |       |       |       |       |       |       |       |
  5690                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
  5691                              <1> ;   |       |       |       |       |       |       |       |       |
  5692                              <1> ;   -----------------------------------------------------------------
  5693                              <1> ;	|	|	|	|	|	|	|	|
  5694                              <1> ;	|	|	|	|	|	-----------------
  5695                              <1> ;	|	|	|	|	|		|
  5696                              <1> ;	|	|	|	|    RESERVED		|
  5697                              <1> ;	|	|	|	|		  PRESENT STATE
  5698                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
  5699                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
  5700                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
  5701                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
  5702                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
  5703                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
  5704                              <1> ;	|	|	|	|	110: RESERVED
  5705                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
  5706                              <1> ;	|	|	|	|
  5707                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
  5708                              <1> ;	|	|	|
  5709                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
  5710                              <1> ;	|	|			DRIVE)
  5711                              <1> ;	|	|
  5712                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
  5713                              <1> ;
  5714                              <1> ;						00: 500 KBS
  5715                              <1> ;						01: 300 KBS
  5716                              <1> ;						10: 250 KBS
  5717                              <1> ;						11: RESERVED
  5718                              <1> ;
  5719                              <1> ;
  5720                              <1> ;-------------------------------------------------------------------------------
  5721                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
  5722                              <1> ;-------------------------------------------------------------------------------
  5723                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
  5724                              <1> ;-------------------------------------------------------------------------------
  5725                              <1> 
  5726                              <1> struc MD
  5727 00000000 <res 00000001>      <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
  5728 00000001 <res 00000001>      <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
  5729 00000002 <res 00000001>      <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
  5730 00000003 <res 00000001>      <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
  5731 00000004 <res 00000001>      <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
  5732 00000005 <res 00000001>      <1> 	.GAP		resb	1	; GAP LENGTH
  5733 00000006 <res 00000001>      <1> 	.DTL		resb	1	; DTL
  5734 00000007 <res 00000001>      <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
  5735 00000008 <res 00000001>      <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
  5736 00000009 <res 00000001>      <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
  5737 0000000A <res 00000001>      <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
  5738 0000000B <res 00000001>      <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
  5739 0000000C <res 00000001>      <1> 	.RATE		resb	1	; DATA TRANSFER RATE
  5740                              <1> endstruc
  5741                              <1> 
  5742                              <1> BIT7OFF	EQU	7FH
  5743                              <1> BIT7ON	EQU	80H
  5744                              <1> 
  5745                              <1> ;;int13h: ; 16/02/2015
  5746                              <1> ;; 16/02/2015 - 21/02/2015
  5747                              <1> int40h:
  5748 00001A51 9C                  <1> 	pushfd
  5749 00001A52 0E                  <1> 	push 	cs
  5750 00001A53 E801000000          <1> 	call 	DISKETTE_IO_1
  5751 00001A58 C3                  <1> 	retn	
  5752                              <1> 
  5753                              <1> DISKETTE_IO_1:
  5754                              <1> 
  5755 00001A59 FB                  <1> 	STI				; INTERRUPTS BACK ON
  5756 00001A5A 55                  <1> 	PUSH	eBP			; USER REGISTER
  5757 00001A5B 57                  <1> 	PUSH	eDI			; USER REGISTER
  5758 00001A5C 52                  <1> 	PUSH	eDX			; HEAD #, DRIVE # OR USER REGISTER
  5759 00001A5D 53                  <1> 	PUSH	eBX			; BUFFER OFFSET PARAMETER OR REGISTER
  5760 00001A5E 51                  <1> 	PUSH	eCX			; TRACK #-SECTOR # OR USER REGISTER
  5761 00001A5F 89E5                <1> 	MOV	eBP,eSP			; BP     => PARAMETER LIST DEP. ON AH
  5762                              <1> 					; [BP]   = SECTOR #
  5763                              <1> 					; [BP+1] = TRACK #
  5764                              <1> 					; [BP+2] = BUFFER OFFSET
  5765                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
  5766                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
  5767                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
  5768                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
  5769                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
  5770                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
  5771                              <1> 					; BH/[BP+3] = 0
  5772                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
  5773                              <1> 					; DH/[BP+5] = MAX HEAD #
  5774                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
  5775 00001A61 06                  <1> 	push	es ; 06/02/2015	
  5776 00001A62 1E                  <1> 	PUSH	DS			; BUFFER SEGMENT PARM OR USER REGISTER
  5777 00001A63 56                  <1> 	PUSH	eSI			; USER REGISTERS
  5778                              <1> 	;CALL	DDS			; SEGMENT OF BIOS DATA AREA TO DS
  5779                              <1> 	;mov	cx, cs
  5780                              <1> 	;mov	ds, cx
  5781 00001A64 66B91000            <1> 	mov	cx, KDATA
  5782 00001A68 8ED9                <1>         mov     ds, cx
  5783 00001A6A 8EC1                <1>         mov     es, cx
  5784                              <1> 
  5785                              <1> 	;CMP	AH,(FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
  5786 00001A6C 80FC19              <1> 	cmp	ah,(FNC_TAE-FNC_TAB)/4 ; 18/02/2015
  5787 00001A6F 7202                <1> 	JB	short OK_FUNC		; FUNCTION OK
  5788 00001A71 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5789                              <1> OK_FUNC:
  5790 00001A73 80FC01              <1> 	CMP	AH,1			; RESET OR STATUS ?
  5791 00001A76 760C                <1> 	JBE	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
  5792 00001A78 80FC08              <1> 	CMP	AH,8			; READ DRIVE PARMS ?
  5793 00001A7B 7407                <1> 	JZ	short OK_DRV		; IF SO DRIVE CHECKED LATER
  5794 00001A7D 80FA01              <1> 	CMP	DL,1			; DRIVES 0 AND 1 OK
  5795 00001A80 7602                <1> 	JBE	short OK_DRV		; IF 0 OR 1 THEN JUMP
  5796 00001A82 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5797                              <1> OK_DRV:
  5798 00001A84 31C9                <1> 	xor	ecx, ecx
  5799                              <1> 	;mov	esi, ecx ; 08/02/2015
  5800 00001A86 89CF                <1> 	mov	edi, ecx ; 08/02/2015
  5801 00001A88 88E1                <1> 	MOV	CL,AH			; CL = FUNCTION
  5802                              <1> 	;XOR	CH,CH			; CX = FUNCTION
  5803                              <1> 	;SHL	CL, 1			; FUNCTION TIMES 2
  5804 00001A8A C0E102              <1> 	SHL	CL, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
  5805 00001A8D BB[C51A0000]        <1> 	MOV	eBX,FNC_TAB		; LOAD START OF FUNCTION TABLE
  5806 00001A92 01CB                <1> 	ADD	eBX,eCX			; ADD OFFSET INTO TABLE => ROUTINE
  5807 00001A94 88F4                <1> 	MOV	AH,DH			; AX = HEAD #,# OF SECTORS OR DASD TYPE
  5808 00001A96 30F6                <1> 	XOR	DH,DH			; DX = DRIVE #
  5809 00001A98 6689C6              <1> 	MOV	SI,AX			; SI = HEAD #,# OF SECTORS OR DASD TYPE
  5810 00001A9B 6689D7              <1> 	MOV     DI,DX                   ; DI = DRIVE #
  5811                              <1> 	;
  5812                              <1> 	; 11/12/2014
  5813 00001A9E 8815[41BF0000]      <1>         mov     [cfd], dl               ; current floppy drive (for 'GET_PARM')        
  5814                              <1> 	;
  5815 00001AA4 8A25[04C50000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
  5816 00001AAA C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; INITIALIZE FOR ALL OTHERS
  5817                              <1> 
  5818                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
  5819                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
  5820                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
  5821                              <1> ;
  5822                              <1> ;		DI	: DRIVE #
  5823                              <1> ;		SI-HI	: HEAD #
  5824                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
  5825                              <1> ;		ES	: BUFFER SEGMENT
  5826                              <1> ;		[BP]	: SECTOR #
  5827                              <1> ;		[BP+1]	: TRACK #
  5828                              <1> ;		[BP+2]	: BUFFER OFFSET
  5829                              <1> ;
  5830                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
  5831                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
  5832                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
  5833                              <1> ;	SPECIFIC ERROR CODE.
  5834                              <1> ;
  5835                              <1> 					; (AH) = @DSKETTE_STATUS
  5836 00001AB1 FF13                <1> 	CALL	dWORD [eBX]		; CALL THE REQUESTED FUNCTION
  5837 00001AB3 5E                  <1> 	POP	eSI			; RESTORE ALL REGISTERS
  5838 00001AB4 1F                  <1> 	POP	DS
  5839 00001AB5 07                  <1> 	pop	es	; 06/02/2015
  5840 00001AB6 59                  <1> 	POP	eCX
  5841 00001AB7 5B                  <1> 	POP	eBX
  5842 00001AB8 5A                  <1> 	POP	eDX
  5843 00001AB9 5F                  <1> 	POP	eDI
  5844 00001ABA 89E5                <1> 	MOV	eBP, eSP
  5845 00001ABC 50                  <1> 	PUSH	eAX
  5846 00001ABD 9C                  <1> 	PUSHFd
  5847 00001ABE 58                  <1> 	POP	eAX
  5848                              <1> 	;MOV	[BP+6], AX
  5849 00001ABF 89450C              <1> 	mov	[ebp+12], eax  ; 18/02/2015, flags
  5850 00001AC2 58                  <1> 	POP	eAX
  5851 00001AC3 5D                  <1> 	POP	eBP
  5852 00001AC4 CF                  <1> 	IRETd
  5853                              <1> 
  5854                              <1> ;-------------------------------------------------------------------------------
  5855                              <1> ; DW --> dd (06/02/2015)
  5856 00001AC5 [291B0000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
  5857 00001AC9 [A21B0000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
  5858 00001ACD [B31B0000]          <1> 	dd	DSK_READ		; AH = 02H; READ
  5859 00001AD1 [C41B0000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
  5860 00001AD5 [D51B0000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
  5861 00001AD9 [E61B0000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
  5862 00001ADD [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
  5863 00001AE1 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
  5864 00001AE5 [781C0000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
  5865 00001AE9 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
  5866 00001AED [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
  5867 00001AF1 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
  5868 00001AF5 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
  5869 00001AF9 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
  5870 00001AFD [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
  5871 00001B01 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
  5872 00001B05 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
  5873 00001B09 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
  5874 00001B0D [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
  5875 00001B11 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
  5876 00001B15 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
  5877 00001B19 [391D0000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
  5878 00001B1D [641D0000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
  5879 00001B21 [9E1D0000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
  5880 00001B25 [211E0000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
  5881                              <1> FNC_TAE EQU     $                       ; END
  5882                              <1> 
  5883                              <1> ;-------------------------------------------------------------------------------
  5884                              <1> ; DISK_RESET	(AH = 00H)	
  5885                              <1> ;		RESET THE DISKETTE SYSTEM.
  5886                              <1> ;
  5887                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5888                              <1> ;-------------------------------------------------------------------------------
  5889                              <1> DSK_RESET:
  5890 00001B29 66BAF203            <1> 	MOV	DX,03F2H		; ADAPTER CONTROL PORT
  5891 00001B2D FA                  <1> 	CLI				; NO INTERRUPTS
  5892 00001B2E A0[02C50000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  5893 00001B33 243F                <1> 	AND	AL,00111111B		; KEEP SELECTED AND MOTOR ON BITS
  5894 00001B35 C0C004              <1> 	ROL	AL,4			; MOTOR VALUE TO HIGH NIBBLE
  5895                              <1> 					; DRIVE SELECT TO LOW NIBBLE
  5896 00001B38 0C08                <1> 	OR	AL,00001000B		; TURN ON INTERRUPT ENABLE
  5897 00001B3A EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5898 00001B3B C605[01C50000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  5899                              <1> 	;JMP	$+2			; WAIT FOR I/O
  5900                              <1> 	;JMP	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
  5901                              <1> 					;      PULSE WIDTH)
  5902                              <1> 	; 19/12/2014
  5903                              <1> 	NEWIODELAY
  5904 00001B42 E6EB                <2>  out 0ebh,al
  5905                              <1> 
  5906                              <1> 	; 17/12/2014 
  5907                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
  5908 00001B44 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
  5909                              <1> wdw1:
  5910                              <1> 	NEWIODELAY   ; 27/02/2015
  5911 00001B49 E6EB                <2>  out 0ebh,al
  5912 00001B4B E2FC                <1> 	loop	wdw1
  5913                              <1> 	;
  5914 00001B4D 0C04                <1> 	OR	AL,00000100B		; TURN OFF RESET BIT
  5915 00001B4F EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5916                              <1> 	; 16/12/2014
  5917                              <1> 	IODELAY
  5918 00001B50 EB00                <2>  jmp short $+2
  5919 00001B52 EB00                <2>  jmp short $+2
  5920                              <1> 	;
  5921                              <1> 	;STI				; ENABLE THE INTERRUPTS
  5922 00001B54 E8250C0000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  5923 00001B59 723E                <1> 	JC	short DR_ERR		; IF ERROR, RETURN IT
  5924 00001B5B 66B9C000            <1> 	MOV	CX,11000000B		; CL = EXPECTED @NEC_STATUS
  5925                              <1> NXT_DRV:
  5926 00001B5F 6651                <1> 	PUSH	CX			; SAVE FOR CALL
  5927 00001B61 B8[971B0000]        <1> 	MOV	eAX, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
  5928 00001B66 50                  <1> 	PUSH	eAX			; "
  5929 00001B67 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  5930 00001B69 E8030B0000          <1> 	CALL	NEC_OUTPUT
  5931 00001B6E 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  5932 00001B6F E83A0C0000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  5933 00001B74 6659                <1> 	POP	CX			; RESTORE AFTER CALL
  5934 00001B76 7221                <1> 	JC	short DR_ERR		; ERROR RETURN
  5935 00001B78 3A0D[05C50000]      <1> 	CMP	CL, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
  5936 00001B7E 7519                <1> 	JNZ	short DR_ERR		; EVERYTHING OK
  5937 00001B80 FEC1                <1> 	INC	CL			; NEXT EXPECTED @NEC_STATUS
  5938 00001B82 80F9C3              <1> 	CMP	CL,11000011B		; ALL POSSIBLE DRIVES CLEARED
  5939 00001B85 76D8                <1> 	JBE	short NXT_DRV		; FALL THRU IF 11000100B OR >
  5940                              <1> 	;
  5941 00001B87 E852030000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  5942                              <1> RESBAC:
  5943 00001B8C E806090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5944 00001B91 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5945 00001B94 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5946 00001B96 C3                  <1> 	RETn		
  5947                              <1> DR_POP_ERR:
  5948 00001B97 6659                <1> 	POP	CX			; CLEAR STACK
  5949                              <1> DR_ERR:
  5950 00001B99 800D[04C50000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; SET ERROR CODE
  5951 00001BA0 EBEA                <1> 	JMP	SHORT RESBAC		; RETURN FROM RESET
  5952                              <1> 
  5953                              <1> ;-------------------------------------------------------------------------------
  5954                              <1> ; DISK_STATUS	(AH = 01H)
  5955                              <1> ;	DISKETTE STATUS.
  5956                              <1> ;
  5957                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
  5958                              <1> ;
  5959                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
  5960                              <1> ;-------------------------------------------------------------------------------
  5961                              <1> DSK_STATUS:
  5962 00001BA2 8825[04C50000]      <1> 	MOV	[DSKETTE_STATUS],AH	; PUT BACK FOR SETUP END
  5963 00001BA8 E8EA080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5964 00001BAD 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5965 00001BB0 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5966 00001BB2 C3                  <1> 	RETn		
  5967                              <1> 
  5968                              <1> ;-------------------------------------------------------------------------------
  5969                              <1> ; DISK_READ	(AH = 02H)	
  5970                              <1> ;	DISKETTE READ.
  5971                              <1> ;
  5972                              <1> ; ON ENTRY:	DI	: DRIVE #
  5973                              <1> ;		SI-HI	: HEAD #
  5974                              <1> ;		SI-LOW	: # OF SECTORS
  5975                              <1> ;		ES	: BUFFER SEGMENT
  5976                              <1> ;		[BP]	: SECTOR #
  5977                              <1> ;		[BP+1]	: TRACK #
  5978                              <1> ;		[BP+2]	: BUFFER OFFSET
  5979                              <1> ;
  5980                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5981                              <1> ;-------------------------------------------------------------------------------
  5982                              <1> 
  5983                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  5984                              <1> 
  5985                              <1> DSK_READ:
  5986 00001BB3 8025[02C50000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  5987 00001BBA 66B846E6            <1> 	MOV	AX,0E646H		; AX = NEC COMMAND, DMA COMMAND
  5988 00001BBE E825040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  5989 00001BC3 C3                  <1> 	RETn
  5990                              <1> 
  5991                              <1> ;-------------------------------------------------------------------------------
  5992                              <1> ; DISK_WRITE	(AH = 03H)
  5993                              <1> ;	DISKETTE WRITE.
  5994                              <1> ;
  5995                              <1> ; ON ENTRY:	DI	: DRIVE #
  5996                              <1> ;		SI-HI	: HEAD #
  5997                              <1> ;		SI-LOW	: # OF SECTORS
  5998                              <1> ;		ES	: BUFFER SEGMENT
  5999                              <1> ;		[BP]	: SECTOR #
  6000                              <1> ;		[BP+1]	: TRACK #
  6001                              <1> ;		[BP+2]	: BUFFER OFFSET
  6002                              <1> ;
  6003                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6004                              <1> ;-------------------------------------------------------------------------------
  6005                              <1> 
  6006                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  6007                              <1> 
  6008                              <1> DSK_WRITE:
  6009 00001BC4 66B84AC5            <1> 	MOV	AX,0C54AH		; AX = NEC COMMAND, DMA COMMAND
  6010 00001BC8 800D[02C50000]80    <1>         OR      byte [MOTOR_STATUS],10000000B ; INDICATE WRITE OPERATION
  6011 00001BCF E814040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6012 00001BD4 C3                  <1> 	RETn
  6013                              <1> 
  6014                              <1> ;-------------------------------------------------------------------------------
  6015                              <1> ; DISK_VERF	(AH = 04H)
  6016                              <1> ;	DISKETTE VERIFY.
  6017                              <1> ;
  6018                              <1> ; ON ENTRY:	DI	: DRIVE #
  6019                              <1> ;		SI-HI	: HEAD #
  6020                              <1> ;		SI-LOW	: # OF SECTORS
  6021                              <1> ;		ES	: BUFFER SEGMENT
  6022                              <1> ;		[BP]	: SECTOR #
  6023                              <1> ;		[BP+1]	: TRACK #
  6024                              <1> ;		[BP+2]	: BUFFER OFFSET
  6025                              <1> ;
  6026                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6027                              <1> ;-------------------------------------------------------------------------------
  6028                              <1> DSK_VERF:
  6029 00001BD5 8025[02C50000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  6030 00001BDC 66B842E6            <1> 	MOV	AX,0E642H		; AX = NEC COMMAND, DMA COMMAND
  6031 00001BE0 E803040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6032 00001BE5 C3                  <1> 	RETn
  6033                              <1> 
  6034                              <1> ;-------------------------------------------------------------------------------
  6035                              <1> ; DISK_FORMAT	(AH = 05H)
  6036                              <1> ;	DISKETTE FORMAT.
  6037                              <1> ;
  6038                              <1> ; ON ENTRY:	DI	: DRIVE #
  6039                              <1> ;		SI-HI	: HEAD #
  6040                              <1> ;		SI-LOW	: # OF SECTORS
  6041                              <1> ;		ES	: BUFFER SEGMENT
  6042                              <1> ;		[BP]	: SECTOR #
  6043                              <1> ;		[BP+1]	: TRACK #
  6044                              <1> ;		[BP+2]	: BUFFER OFFSET
  6045                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
  6046                              <1> ;
  6047                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6048                              <1> ;-------------------------------------------------------------------------------
  6049                              <1> DSK_FORMAT:
  6050 00001BE6 E83C030000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6051 00001BEB E838050000          <1> 	CALL	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
  6052 00001BF0 800D[02C50000]80    <1>         OR      byte [MOTOR_STATUS], 10000000B ; INDICATE WRITE OPERATION
  6053 00001BF7 E880050000          <1> 	CALL	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
  6054 00001BFC 725D                <1>         JC      short FM_DON            ; MEDIA CHANGED, SKIP
  6055 00001BFE E8DB020000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  6056 00001C03 E8E6050000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
  6057 00001C08 7405                <1>         JZ      short FM_WR             ; YES, SKIP SPECIFY COMMAND
  6058 00001C0A E8BD050000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO CONTROLLER
  6059                              <1> FM_WR:
  6060 00001C0F E873060000          <1> 	CALL	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
  6061 00001C14 7245                <1>         JC      short FM_DON            ; RETURN WITH ERROR
  6062 00001C16 B44D                <1> 	MOV	AH,04DH			; ESTABLISH THE FORMAT COMMAND
  6063 00001C18 E8D0060000          <1> 	CALL	NEC_INIT		; INITIALIZE THE NEC
  6064 00001C1D 723C                <1>         JC      short FM_DON            ; ERROR - EXIT
  6065 00001C1F B8[5B1C0000]        <1>         MOV     eAX, FM_DON             ; LOAD ERROR ADDRESS
  6066 00001C24 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6067 00001C25 B203                <1> 	MOV	DL,3			; BYTES/SECTOR VALUE TO NEC
  6068 00001C27 E83F090000          <1> 	CALL	GET_PARM
  6069 00001C2C E8400A0000          <1> 	CALL	NEC_OUTPUT
  6070 00001C31 B204                <1> 	MOV	DL,4			; SECTORS/TRACK VALUE TO NEC
  6071 00001C33 E833090000          <1> 	CALL	GET_PARM
  6072 00001C38 E8340A0000          <1> 	CALL	NEC_OUTPUT
  6073 00001C3D B207                <1> 	MOV	DL,7			; GAP LENGTH VALUE TO NEC
  6074 00001C3F E827090000          <1> 	CALL	GET_PARM
  6075 00001C44 E8280A0000          <1> 	CALL	NEC_OUTPUT
  6076 00001C49 B208                <1> 	MOV	DL,8			; FILLER BYTE TO NEC
  6077 00001C4B E81B090000          <1> 	CALL	GET_PARM
  6078 00001C50 E81C0A0000          <1> 	CALL	NEC_OUTPUT
  6079 00001C55 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  6080 00001C56 E810070000          <1> 	CALL	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
  6081                              <1> FM_DON:
  6082 00001C5B E8F8020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6083 00001C60 E832080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6084 00001C65 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6085 00001C68 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6086 00001C6A C3                  <1> 	RETn
  6087                              <1> 
  6088                              <1> ;-------------------------------------------------------------------------------
  6089                              <1> ; FNC_ERR
  6090                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
  6091                              <1> ;	SET BAD COMMAND IN STATUS.
  6092                              <1> ;
  6093                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6094                              <1> ;-------------------------------------------------------------------------------
  6095                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
  6096 00001C6B 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6097 00001C6E B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6098 00001C70 8825[04C50000]      <1> 	MOV	[DSKETTE_STATUS],AH	; STORE IN DATA AREA
  6099 00001C76 F9                  <1> 	STC				; SET CARRY INDICATING ERROR
  6100 00001C77 C3                  <1> 	RETn
  6101                              <1> 
  6102                              <1> ;-------------------------------------------------------------------------------
  6103                              <1> ; DISK_PARMS	(AH = 08H)	
  6104                              <1> ;	READ DRIVE PARAMETERS.
  6105                              <1> ;
  6106                              <1> ; ON ENTRY:	DI : DRIVE #
  6107                              <1> ;
  6108                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
  6109                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
  6110                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
  6111                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
  6112                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
  6113                              <1> ;		BH/[BP+3] = 0
  6114                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
  6115                              <1> ;		DH/[BP+5] = MAX HEAD #
  6116                              <1> ;		DI/[BP+6] = OFFSET TO DISK_BASE
  6117                              <1> ;		ES        = SEGMENT OF DISK_BASE
  6118                              <1> ;		AX        = 0
  6119                              <1> ;
  6120                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
  6121                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
  6122                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
  6123                              <1> ;		       CALLER.
  6124                              <1> ;-------------------------------------------------------------------------------
  6125                              <1> DSK_PARMS:
  6126 00001C78 E8AA020000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  6127                              <1>      ;	MOV	WORD [BP+2],0		; DRIVE TYPE = 0
  6128 00001C7D 29D2                <1> 	sub     edx, edx ; 20/02/2015
  6129 00001C7F 895504              <1>         mov	[ebp+4], edx ; 20/02/2015
  6130                              <1>      ;  MOV     AX, [EQUIP_FLAG]        ; LOAD EQUIPMENT FLAG FOR # DISKETTES
  6131                              <1>      ;  AND     AL,11000001B            ; KEEP DISKETTE DRIVE BITS
  6132                              <1>      ;  MOV     DL,2                    ; DISKETTE DRIVES = 2
  6133                              <1>      ;  CMP     AL,01000001B            ; 2 DRIVES INSTALLED ?
  6134                              <1>      ;  JZ      short STO_DL            ; IF YES JUMP
  6135                              <1>      ;  DEC     DL                      ; DISKETTE DRIVES = 1
  6136                              <1>      ;  CMP     AL,00000001B            ; 1 DRIVE INSTALLED ?
  6137                              <1>      ;  JNZ     short NON_DRV           ; IF NO JUMP
  6138                              <1> 	;sub	edx, edx
  6139 00001C82 66A1[4EBF0000]      <1> 	mov     ax, [fd0_type]
  6140 00001C88 6621C0              <1> 	and     ax, ax
  6141 00001C8B 7474                <1> 	jz      short NON_DRV
  6142 00001C8D FEC2                <1> 	inc     dl
  6143 00001C8F 20E4                <1> 	and     ah, ah
  6144 00001C91 7402                <1> 	jz      short STO_DL
  6145 00001C93 FEC2                <1> 	inc     dl
  6146                              <1> STO_DL:
  6147                              <1> 	;MOV	[BP+4],DL		; STORE NUMBER OF DRIVES
  6148 00001C95 895508              <1> 	mov	[ebp+8], edx ; 20/02/2015	 	
  6149 00001C98 6683FF01            <1> 	CMP	DI,1			; CHECK FOR VALID DRIVE
  6150 00001C9C 7766                <1> 	JA	short NON_DRV1		; DRIVE INVALID
  6151                              <1> 	;MOV	BYTE [BP+5],1		; MAXIMUM HEAD NUMBER =	1
  6152 00001C9E C6450901            <1> 	mov	byte [ebp+9], 1  ; 20/02/2015	
  6153 00001CA2 E8BB080000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6154                              <1> 	;;20/02/2015
  6155                              <1> 	;;JC	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
  6156                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE TYPE
  6157 00001CA7 7412                <1> 	JZ	short CHK_EST		; JUMP IF SO
  6158 00001CA9 E805020000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6159 00001CAE 720B                <1> 	JC	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
  6160                              <1> 	;MOV	[BP+2],AL		; STORE VALID CMOS DRIVE TYPE
  6161 00001CB0 884504              <1>         mov	[ebp+4], al ; 06/02/2015
  6162 00001CB3 8A4B04              <1> 	MOV     CL, [eBX+MD.SEC_TRK]     ; GET SECTOR/TRACK
  6163 00001CB6 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]     ; GET MAX. TRACK NUMBER
  6164 00001CB9 EB36                <1> 	JMP	SHORT STO_CX		; CMOS GOOD, USE CMOS
  6165                              <1> CHK_EST:
  6166 00001CBB 8AA7[11C50000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; LOAD STATE FOR THIS DRIVE
  6167 00001CC1 F6C410              <1> 	TEST	AH,MED_DET		; CHECK FOR ESTABLISHED STATE
  6168 00001CC4 743E                <1> 	JZ	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
  6169                              <1> USE_EST:
  6170 00001CC6 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE STATE
  6171 00001CC9 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6172 00001CCC 7557                <1> 	JNE	short USE_EST2		; NO, GO CHECK OTHER RATE
  6173                              <1> 
  6174                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
  6175                              <1> 
  6176 00001CCE B001                <1> 	MOV	AL,01			; DRIVE TYPE 1 (360KB)
  6177 00001CD0 E8DE010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6178 00001CD5 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6179 00001CD8 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6180 00001CDB F687[11C50000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; 80 TRACK ?
  6181 00001CE2 740D                <1> 	JZ	short STO_CX		; MUST BE 360KB DRIVE 
  6182                              <1> 
  6183                              <1> ;-----	IT IS 1.44 MB DRIVE
  6184                              <1> 
  6185                              <1> PARM144:
  6186 00001CE4 B004                <1> 	MOV	AL,04			; DRIVE TYPE 4 (1.44MB)
  6187 00001CE6 E8C8010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6188 00001CEB 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6189 00001CEE 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6190                              <1> STO_CX:
  6191 00001CF1 894D00              <1> 	MOV	[eBP],eCX		; SAVE POINTER IN STACK FOR RETURN
  6192                              <1> ES_DI:
  6193                              <1> 	;MOV	[BP+6],BX		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
  6194 00001CF4 895D0C              <1> 	mov	[ebp+12], ebx ; 06/02/2015
  6195                              <1> 	;MOV	AX,CS			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
  6196                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6197                              <1> DP_OUT:
  6198 00001CF7 E85C020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6199 00001CFC 6631C0              <1> 	XOR	AX,AX			; CLEAR
  6200 00001CFF F8                  <1> 	CLC
  6201 00001D00 C3                  <1> 	RETn
  6202                              <1> 
  6203                              <1> ;-----	NO DRIYE PRESENT HANDLER
  6204                              <1> 
  6205                              <1> NON_DRV:
  6206                              <1> 	;MOV	BYTE [BP+4],0		; CLEAR NUMBER OF DRIVES
  6207 00001D01 895508              <1> 	mov	[ebp+8], edx ; 0 ; 20/02/2015
  6208                              <1> NON_DRV1:
  6209 00001D04 6681FF8000          <1> 	CMP	DI,80H			; CHECK FOR FIXED MEDIA TYPE REQUEST
  6210 00001D09 720C                <1> 	JB	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
  6211                              <1> 
  6212                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
  6213                              <1> 	
  6214 00001D0B E848020000          <1> 	CALL	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
  6215 00001D10 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6216 00001D13 B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6217 00001D15 F9                  <1> 	STC
  6218 00001D16 C3                  <1> 	RETn
  6219                              <1> 
  6220                              <1> NON_DRV2:
  6221                              <1> 	;XOR	AX,AX			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
  6222 00001D17 31C0                <1> 	xor	eax, eax	
  6223 00001D19 66894500            <1> 	MOV	[eBP],AX		; TRACKS, SECTORS/TRACK = 0
  6224                              <1> 	;MOV	[BP+5],AH		; HEAD = 0
  6225 00001D1D 886509              <1> 	mov	[ebp+9], ah ; 06/02/2015
  6226                              <1> 	;MOV	[BP+6],AX		; OFFSET TO DISK_BASE = 0
  6227 00001D20 89450C              <1> 	mov	[ebp+12], eax
  6228                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6229 00001D23 EBD2                <1> 	JMP	SHORT DP_OUT
  6230                              <1> 
  6231                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
  6232                              <1> 
  6233                              <1> USE_EST2:
  6234 00001D25 B002                <1> 	MOV	AL,02			; DRIVE TYPE 2 (1.2MB)
  6235 00001D27 E887010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6236 00001D2C 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6237 00001D2F 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6238 00001D32 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6239 00001D35 74BA                <1> 	JZ	short STO_CX		; MUST BE 1.2MB DRIVE
  6240 00001D37 EBAB                <1> 	JMP	SHORT PARM144		; ELSE, IT IS 1.44MB DRIVE 
  6241                              <1> 
  6242                              <1> ;-------------------------------------------------------------------------------
  6243                              <1> ; DISK_TYPE (AH = 15H)	
  6244                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
  6245                              <1> ;
  6246                              <1> ;  ON ENTRY:	DI = DRIVE #
  6247                              <1> ;
  6248                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
  6249                              <1> ;-------------------------------------------------------------------------------
  6250                              <1> DSK_TYPE:
  6251 00001D39 E8E9010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6252 00001D3E 8A87[11C50000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET PRESENT STATE INFORMATION
  6253 00001D44 08C0                <1> 	OR	AL,AL			; CHECK FOR NO DRIVE
  6254 00001D46 7418                <1> 	JZ	short NO_DRV
  6255 00001D48 B401                <1> 	MOV	AH,NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
  6256 00001D4A A801                <1> 	TEST	AL,TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
  6257 00001D4C 7402                <1> 	JZ	short DT_BACK			; IF NO JUMP
  6258 00001D4E B402                <1> 	MOV	AH,CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
  6259                              <1> DT_BACK:
  6260 00001D50 6650                <1> 	PUSH	AX			; SAVE RETURN VALUE
  6261 00001D52 E801020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6262 00001D57 6658                <1> 	POP	AX			; RESTORE RETURN VALUE
  6263 00001D59 F8                  <1> 	CLC				; NO ERROR
  6264 00001D5A 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6265 00001D5D 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6266 00001D5F C3                  <1> 	RETn
  6267                              <1> NO_DRV:	
  6268 00001D60 30E4                <1> 	XOR	AH,AH			; NO DRIVE PRESENT OR UNKNOWN
  6269 00001D62 EBEC                <1> 	JMP	SHORT DT_BACK
  6270                              <1> 
  6271                              <1> ;-------------------------------------------------------------------------------
  6272                              <1> ; DISK_CHANGE	(AH = 16H)
  6273                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  6274                              <1> ;
  6275                              <1> ; ON ENTRY:	DI = DRIVE #
  6276                              <1> ;
  6277                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  6278                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  6279                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  6280                              <1> ;-------------------------------------------------------------------------------
  6281                              <1> DSK_CHANGE:
  6282 00001D64 E8BE010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6283 00001D69 8A87[11C50000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET MEDIA STATE INFORMATION
  6284 00001D6F 08C0                <1> 	OR	AL,AL			; DRIVE PRESENT ?
  6285 00001D71 7422                <1> 	JZ	short DC_NON		; JUMP IF NO DRIVE
  6286 00001D73 A801                <1> 	TEST	AL,TRK_CAPA		; 80 TRACK DRIVE ?
  6287 00001D75 7407                <1> 	JZ	short SETIT		; IF SO , CHECK CHANGE LINE
  6288                              <1> DC0:
  6289 00001D77 E88D0A0000          <1>         CALL    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  6290 00001D7C 7407                <1> 	JZ	short FINIS		; CHANGE LINE NOT ACTIVE
  6291                              <1> 
  6292 00001D7E C605[04C50000]06    <1> SETIT:	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  6293                              <1> 
  6294 00001D85 E8CE010000          <1> FINIS:	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6295 00001D8A E808070000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6296 00001D8F 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6297 00001D92 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6298 00001D94 C3                  <1> 	RETn
  6299                              <1> DC_NON:
  6300 00001D95 800D[04C50000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  6301 00001D9C EBE7                <1> 	JMP	SHORT FINIS
  6302                              <1> 
  6303                              <1> ;-------------------------------------------------------------------------------
  6304                              <1> ; FORMAT_SET	(AH = 17H)
  6305                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  6306                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  6307                              <1> ;
  6308                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  6309                              <1> ;		DI     = DRIVE #
  6310                              <1> ;
  6311                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  6312                              <1> ;		AH = @DSKETTE_STATUS
  6313                              <1> ;		CY = 1 IF ERROR
  6314                              <1> ;-------------------------------------------------------------------------------
  6315                              <1> FORMAT_SET:
  6316 00001D9E E884010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6317 00001DA3 6656                <1> 	PUSH	SI			; SAVE DASD TYPE
  6318 00001DA5 6689F0              <1> 	MOV	AX,SI			; AH = ? , AL , DASD TYPE
  6319 00001DA8 30E4                <1> 	XOR	AH,AH			; AH , 0 , AL , DASD TYPE
  6320 00001DAA 6689C6              <1> 	MOV	SI,AX			; SI = DASD TYPE
  6321 00001DAD 80A7[11C50000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6322 00001DB4 664E                <1> 	DEC	SI			; CHECK FOR 320/360K MEDIA & DRIVE
  6323 00001DB6 7509                <1> 	JNZ	short NOT_320		; BYPASS IF NOT
  6324 00001DB8 808F[11C50000]90    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_250 ; SET TO 320/360
  6325 00001DBF EB48                <1> 	JMP	SHORT S0
  6326                              <1> 
  6327                              <1> NOT_320:
  6328 00001DC1 E8B6030000          <1> 	CALL	MED_CHANGE		; CHECK FOR TIME_OUT
  6329 00001DC6 803D[04C50000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT
  6330 00001DCD 743A                <1> 	JZ	short S0		; IF TIME OUT TELL CALLER
  6331                              <1> S3:
  6332 00001DCF 664E                <1> 	DEC	SI			; CHECK FOR 320/360K IN 1.2M DRIVE
  6333 00001DD1 7509                <1> 	JNZ	short NOT_320_12	; BYPASS IF NOT
  6334 00001DD3 808F[11C50000]70    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  6335 00001DDA EB2D                <1> 	JMP	SHORT S0
  6336                              <1> 
  6337                              <1> NOT_320_12:
  6338 00001DDC 664E                <1> 	DEC	SI			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  6339 00001DDE 7509                <1> 	JNZ	short NOT_12		; BYPASS IF NOT
  6340 00001DE0 808F[11C50000]10    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_500 ; SET STATE VARIABLE
  6341 00001DE7 EB20                <1> 	JMP	SHORT S0		; RETURN TO CALLER
  6342                              <1> 
  6343                              <1> NOT_12:	
  6344 00001DE9 664E                <1> 	DEC	SI			; CHECK FOR SET DASD TYPE 04
  6345 00001DEB 752B                <1> 	JNZ	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  6346                              <1> 
  6347 00001DED F687[11C50000]04    <1> 	TEST	byte [DSK_STATE+eDI], DRV_DET ; DRIVE DETERMINED ?
  6348 00001DF4 740B                <1> 	JZ	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  6349 00001DF6 B050                <1> 	MOV	AL,MED_DET+RATE_300
  6350 00001DF8 F687[11C50000]02    <1>         TEST    byte [DSK_STATE+eDI], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  6351 00001DFF 7502                <1> 	JNZ	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  6352                              <1> 
  6353                              <1> ASSUME:
  6354 00001E01 B090                <1> 	MOV	AL,MED_DET+RATE_250	; SET UP
  6355                              <1> 
  6356                              <1> OR_IT_IN:
  6357 00001E03 0887[11C50000]      <1> 	OR	[DSK_STATE+eDI], AL	; OR IN THE CORRECT STATE
  6358                              <1> S0:
  6359 00001E09 E84A010000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6360 00001E0E E884060000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6361 00001E13 665B                <1> 	POP	BX			; GET SAVED AL TO BL
  6362 00001E15 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6363 00001E17 C3                  <1> 	RETn
  6364                              <1> 
  6365                              <1> FS_ERR:
  6366 00001E18 C605[04C50000]01    <1> 	MOV	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  6367 00001E1F EBE8                <1> 	JMP	SHORT S0
  6368                              <1> 
  6369                              <1> ;-------------------------------------------------------------------------------
  6370                              <1> ; SET_MEDIA	(AH = 18H)
  6371                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  6372                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  6373                              <1> ;
  6374                              <1> ; ON ENTRY:
  6375                              <1> ;	[BP]	= SECTOR PER TRACK
  6376                              <1> ;	[BP+1]	= TRACK #
  6377                              <1> ;	DI	= DRIVE #
  6378                              <1> ;
  6379                              <1> ; ON EXIT:
  6380                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  6381                              <1> ;	IF NO ERROR:
  6382                              <1> ;		AH = 0
  6383                              <1> ;		CY = 0
  6384                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6385                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  6386                              <1> ;	IF ERROR:	
  6387                              <1> ;		AH = @DSKETTE_STATUS
  6388                              <1> ;		CY = 1
  6389                              <1> ;-------------------------------------------------------------------------------
  6390                              <1> SET_MEDIA:
  6391 00001E21 E801010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6392 00001E26 F687[11C50000]01    <1>         TEST    byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  6393 00001E2D 7415                <1> 	JZ	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  6394 00001E2F E848030000          <1> 	CALL	MED_CHANGE		; RESET CHANGE LINE
  6395 00001E34 803D[04C50000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  6396 00001E3B 746B                <1> 	JE	short SM_RTN
  6397 00001E3D C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  6398                              <1> SM_CMOS:
  6399 00001E44 E819070000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6400                              <1> 	;;20/02/2015
  6401                              <1> 	;;JC	short MD_NOT_FND	; ERROR IN CMOS
  6402                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE
  6403 00001E49 745D                <1> 	JZ	short SM_RTN		; RETURN IF SO
  6404 00001E4B E863000000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6405 00001E50 7231                <1> 	JC	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  6406 00001E52 57                  <1> 	PUSH	eDI			; SAVE REG.
  6407 00001E53 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR. TYPE TABLE
  6408 00001E55 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6409                              <1> DR_SEARCH:
  6410 00001E5A 8AA3[CCBE0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6411 00001E60 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6412 00001E63 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH ?
  6413 00001E65 7516                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  6414                              <1> DR_FND:
  6415 00001E67 8BBB[CDBE0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  6416                              <1> MD_SEARCH:
  6417 00001E6D 8A6704              <1>         MOV     AH, [eDI+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6418 00001E70 386500              <1> 	CMP	[eBP],AH		; MATCH?
  6419 00001E73 7508                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT MEDIA
  6420 00001E75 8A670B              <1>         MOV     AH, [eDI+MD.MAX_TRK]    ; GET MAX. TRACK #
  6421 00001E78 386501              <1> 	CMP 	[eBP+1],AH		; MATCH?
  6422 00001E7B 740F                <1> 	JE	short MD_FND		; YES, GO GET RATE
  6423                              <1> NXT_MD:
  6424                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6425 00001E7D 83C305              <1>         add	ebx, 5 ; 18/02/2015
  6426 00001E80 E2D8                <1> 	LOOP    DR_SEARCH
  6427 00001E82 5F                  <1> 	POP	eDI			; RESTORE REG.
  6428                              <1> MD_NOT_FND:
  6429 00001E83 C605[04C50000]0C    <1> 	MOV	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  6430 00001E8A EB1C                <1> 	JMP	SHORT SM_RTN		; RETURN
  6431                              <1> MD_FND:
  6432 00001E8C 8A470C              <1>         MOV     AL, [eDI+MD.RATE]       ; GET RATE
  6433 00001E8F 3C40                <1> 	CMP	AL,RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  6434 00001E91 7502                <1> 	JNE	short MD_SET
  6435 00001E93 0C20                <1> 	OR	AL,DBL_STEP
  6436                              <1> MD_SET:
  6437                              <1> 	;MOV	[BP+6],DI		; SAVE TABLE POINTER IN STACK
  6438 00001E95 897D0C              <1> 	mov	[ebp+12], edi ; 18/02/2015
  6439 00001E98 0C10                <1> 	OR	AL,MED_DET		; SET MEDIA ESTABLISHED
  6440 00001E9A 5F                  <1> 	POP	eDI
  6441 00001E9B 80A7[11C50000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6442 00001EA2 0887[11C50000]      <1> 	OR	[DSK_STATE+eDI], AL
  6443                              <1> 	;MOV	AX, CS			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6444                              <1> 	;MOV	ES, AX			; ES IS SEGMENT OF TABLE
  6445                              <1> SM_RTN:
  6446 00001EA8 E8AB000000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6447 00001EAD E8E5050000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6448 00001EB2 C3                  <1> 	RETn
  6449                              <1> 
  6450                              <1> ;----------------------------------------------------------------
  6451                              <1> ; DR_TYPE_CHECK							:
  6452                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  6453                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  6454                              <1> ; ON ENTRY:							:
  6455                              <1> ;	AL = DRIVE TYPE						:
  6456                              <1> ; ON EXIT:							:
  6457                              <1> ;	CS = SEGMENT MEDIA/DRIVE PARAMETER TABLE (CODE)		:
  6458                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  6459                              <1> ;	     BX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE		:
  6460                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  6461                              <1> ; REGISTERS ALTERED: eBX						:
  6462                              <1> ;----------------------------------------------------------------		
  6463                              <1> DR_TYPE_CHECK:
  6464 00001EB3 6650                <1> 	PUSH	AX			
  6465 00001EB5 51                  <1> 	PUSH	eCX
  6466 00001EB6 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6467 00001EB8 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6468                              <1> TYPE_CHK:	
  6469 00001EBD 8AA3[CCBE0000]      <1> 	MOV	AH,[DR_TYPE+eBX]	; GET DRIVE TYPE
  6470 00001EC3 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6471 00001EC5 740D                <1> 	JE	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  6472                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6473 00001EC7 83C305              <1>         add	ebx, 5	; 16/02/2015 (32 bit address modification)
  6474 00001ECA E2F1                <1> 	LOOP    TYPE_CHK
  6475                              <1> 	;
  6476 00001ECC BB[2BBF0000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  6477                              <1> 					; Default for GET_PARM (11/12/2014)
  6478                              <1> 	;
  6479 00001ED1 F9                  <1> 	STC				; DRIVE TYPE NOT FOUND IN TABLE
  6480 00001ED2 EB06                <1> 	JMP	SHORT TYPE_RTN
  6481                              <1> DR_TYPE_VALID:
  6482 00001ED4 8B9B[CDBE0000]      <1> 	MOV	eBX,[DR_TYPE+eBX+1] 	; BX = MEDIA TABLE
  6483                              <1> TYPE_RTN:
  6484 00001EDA 59                  <1> 	POP	eCX
  6485 00001EDB 6658                <1> 	POP	AX
  6486 00001EDD C3                  <1> 	RETn	
  6487                              <1> 		
  6488                              <1> ;----------------------------------------------------------------
  6489                              <1> ; SEND_SPEC							:
  6490                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6491                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  6492                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  6493                              <1> ; ON EXIT:	NONE						:	
  6494                              <1> ; REGISTERS ALTERED: CX, DX					:
  6495                              <1> ;----------------------------------------------------------------		
  6496                              <1> SEND_SPEC:
  6497 00001EDE 50                  <1> 	PUSH	eAX			; SAVE AX
  6498 00001EDF B8[051F0000]        <1> 	MOV	eAX, SPECBAC		; LOAD ERROR ADDRESS
  6499 00001EE4 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6500 00001EE5 B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6501 00001EE7 E885070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6502 00001EEC 28D2                <1> 	SUB	DL,DL			; FIRST SPECIFY BYTE
  6503 00001EEE E878060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6504 00001EF3 E879070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6505 00001EF8 B201                <1> 	MOV	DL,1			; SECOND SPECIFY BYTE
  6506 00001EFA E86C060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6507 00001EFF E86D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6508 00001F04 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6509                              <1> SPECBAC:
  6510 00001F05 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6511 00001F06 C3                  <1> 	RETn
  6512                              <1> 
  6513                              <1> ;----------------------------------------------------------------
  6514                              <1> ; SEND_SPEC_MD							:
  6515                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6516                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  6517                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  6518                              <1> ; ON EXIT:	NONE						:	
  6519                              <1> ; REGISTERS ALTERED: AX						:
  6520                              <1> ;----------------------------------------------------------------		
  6521                              <1> SEND_SPEC_MD:
  6522 00001F07 50                  <1> 	PUSH	eAX			; SAVE RATE DATA
  6523 00001F08 B8[251F0000]        <1> 	MOV	eAX, SPEC_ESBAC		; LOAD ERROR ADDRESS
  6524 00001F0D 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6525 00001F0E B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6526 00001F10 E85C070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6527 00001F15 8A23                <1>         MOV     AH, [eBX+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  6528 00001F17 E855070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6529 00001F1C 8A6301              <1>         MOV     AH, [eBX+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  6530 00001F1F E84D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6531 00001F24 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6532                              <1> SPEC_ESBAC:
  6533 00001F25 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6534 00001F26 C3                  <1> 	RETn
  6535                              <1> 
  6536                              <1> ;-------------------------------------------------------------------------------
  6537                              <1> ; XLAT_NEW  
  6538                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  6539                              <1> ;	MODE TO NEW ARCHITECTURE.
  6540                              <1> ;
  6541                              <1> ; ON ENTRY:	DI = DRIVE #
  6542                              <1> ;-------------------------------------------------------------------------------
  6543                              <1> XLAT_NEW:
  6544 00001F27 83FF01              <1> 	CMP	eDI,1				; VALID DRIVE
  6545 00001F2A 7725                <1> 	JA	short XN_OUT			; IF INVALID BACK
  6546 00001F2C 80BF[11C50000]00    <1> 	CMP	byte [DSK_STATE+eDI], 0		; NO DRIVE ?
  6547 00001F33 741D                <1> 	JZ	short DO_DET			; IF NO DRIVE ATTEMPT DETERMINE
  6548 00001F35 6689F9              <1> 	MOV	CX,DI				; CX = DRIVE NUMBER
  6549 00001F38 C0E102              <1> 	SHL	CL,2				; CL = SHIFT COUNT, A=0, B=4
  6550 00001F3B A0[10C50000]        <1> 	MOV	AL, [HF_CNTRL]			; DRIVE INFORMATION
  6551 00001F40 D2C8                <1> 	ROR	AL,CL				; TO LOW NIBBLE
  6552 00001F42 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA	; KEEP DRIVE BITS
  6553 00001F44 80A7[11C50000]F8    <1>         AND     byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  6554 00001F4B 0887[11C50000]      <1> 	OR	[DSK_STATE+eDI], AL		; UPDATE DRIVE STATE
  6555                              <1> XN_OUT:
  6556 00001F51 C3                  <1> 	RETn
  6557                              <1> DO_DET:
  6558 00001F52 E8BF080000          <1> 	CALL	DRIVE_DET			; TRY TO DETERMINE
  6559 00001F57 C3                  <1> 	RETn
  6560                              <1> 
  6561                              <1> ;-------------------------------------------------------------------------------
  6562                              <1> ; XLAT_OLD 
  6563                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  6564                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  6565                              <1> ;
  6566                              <1> ; ON ENTRY:	DI = DRIVE
  6567                              <1> ;-------------------------------------------------------------------------------
  6568                              <1> XLAT_OLD:
  6569 00001F58 83FF01              <1> 	CMP	eDI,1			; VALID DRIVE ?
  6570                              <1>         ;JA     short XO_OUT            ; IF INVALID BACK
  6571 00001F5B 0F8786000000        <1>         ja      XO_OUT
  6572 00001F61 80BF[11C50000]00    <1>         CMP	byte [DSK_STATE+eDI],0	; NO DRIVE ?
  6573 00001F68 747D                <1> 	JZ	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  6574                              <1> 
  6575                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  6576                              <1> 
  6577 00001F6A 6689F9              <1> 	MOV	CX,DI			; CX = DRIVE NUMBER
  6578 00001F6D C0E102              <1> 	SHL	CL,2			; CL = SHIFT COUNT, A=0, B=4
  6579 00001F70 B402                <1> 	MOV	AH,FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  6580 00001F72 D2CC                <1> 	ROR	AH,CL			; ROTATE BY MASK
  6581 00001F74 8425[10C50000]      <1> 	TEST	[HF_CNTRL], AH		; MULTIPLE-DATA RATE DETERMINED ?
  6582 00001F7A 751C                <1> 	JNZ	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  6583                              <1> 
  6584                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  6585                              <1> 
  6586 00001F7C B407                <1> 	MOV	AH,DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  6587 00001F7E D2CC                <1> 	ROR	AH,CL			; FIX MASK TO KEEP
  6588 00001F80 F6D4                <1> 	NOT	AH			; TRANSLATE MASK
  6589 00001F82 2025[10C50000]      <1> 	AND	[HF_CNTRL], AH		; KEEP BITS FROM OTHER DRIVE INTACT
  6590                              <1> 
  6591                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  6592                              <1> 
  6593 00001F88 8A87[11C50000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; ACCESS STATE
  6594 00001F8E 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  6595 00001F90 D2C8                <1> 	ROR	AL,CL			; FIX FOR THIS DRIVE
  6596 00001F92 0805[10C50000]      <1> 	OR	[HF_CNTRL], AL		; UPDATE SAVED DRIVE STATE
  6597                              <1> 
  6598                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  6599                              <1> 
  6600                              <1> SAVE_SET:
  6601 00001F98 8AA7[11C50000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  6602 00001F9E 88E7                <1> 	MOV	BH,AH			; TO BH FOR LATER
  6603 00001FA0 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE
  6604 00001FA3 80FC00              <1> 	CMP	AH,RATE_500		; RATE 500 ?
  6605 00001FA6 7410                <1> 	JZ	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  6606 00001FA8 B001                <1> 	MOV	AL,M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  6607 00001FAA 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6608 00001FAD 7518                <1> 	JNZ	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  6609 00001FAF F6C720              <1> 	TEST	BH,DBL_STEP		; CHECK FOR DOUBLE STEP
  6610 00001FB2 751F                <1> 	JNZ	short TST_DET		; MUST BE 360 IN 1.2
  6611                              <1> UNKNO:
  6612 00001FB4 B007                <1> 	MOV	AL,MED_UNK		; NONE OF THE ABOVE
  6613 00001FB6 EB22                <1> 	JMP	SHORT AL_SET		; PROCESS COMPLETE
  6614                              <1> CHK_144:
  6615 00001FB8 E8A5050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6616                              <1> 	;;20/02/2015
  6617                              <1> 	;;JC	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  6618 00001FBD 74F5                <1> 	jz	short UNKNO ;; 20/02/2015
  6619 00001FBF 3C02                <1> 	CMP	AL,2			; 1.2MB DRIVE ?
  6620 00001FC1 75F1                <1> 	JNE	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  6621 00001FC3 B002                <1> 	MOV	AL,M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  6622 00001FC5 EB0C                <1> 	JMP	SHORT TST_DET
  6623                              <1> CHK_250:
  6624 00001FC7 B000                <1> 	MOV	AL,M3D3U		; AL = 360 IN 360 UNESTABLISHED
  6625 00001FC9 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6626 00001FCC 75E6                <1> 	JNZ	short UNKNO		; IF SO FALL IHRU
  6627 00001FCE F6C701              <1> 	TEST	BH,TRK_CAPA		; 80 TRACK CAPABILITY ?
  6628 00001FD1 75E1                <1> 	JNZ	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  6629                              <1> TST_DET:
  6630 00001FD3 F6C710              <1> 	TEST	BH,MED_DET		; DETERMINED ?
  6631 00001FD6 7402                <1> 	JZ	short AL_SET		; IF NOT THEN SET
  6632 00001FD8 0403                <1> 	ADD	AL,3			; MAKE DETERMINED/ESTABLISHED
  6633                              <1> AL_SET:
  6634 00001FDA 80A7[11C50000]F8    <1> 	AND	byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  6635 00001FE1 0887[11C50000]      <1> 	OR	[DSK_STATE+eDI], AL	; REPLACE WITH COMPATIBLE MODE
  6636                              <1> XO_OUT:
  6637 00001FE7 C3                  <1> 	RETn
  6638                              <1> 
  6639                              <1> ;-------------------------------------------------------------------------------
  6640                              <1> ; RD_WR_VF
  6641                              <1> ;	COMMON READ, WRITE AND VERIFY: 
  6642                              <1> ;	MAIN LOOP FOR STATE RETRIES.
  6643                              <1> ;
  6644                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
  6645                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
  6646                              <1> ;
  6647                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6648                              <1> ;-------------------------------------------------------------------------------
  6649                              <1> RD_WR_VF:
  6650 00001FE8 6650                <1> 	PUSH	AX			; SAVE DMA, NEC PARAMETERS
  6651 00001FEA E838FFFFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6652 00001FEF E8F3000000          <1> 	CALL	SETUP_STATE		; INITIALIZE START AND END RATE
  6653 00001FF4 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6654                              <1> DO_AGAIN:
  6655 00001FF6 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6656 00001FF8 E87F010000          <1> 	CALL	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
  6657 00001FFD 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6658 00001FFF 0F82C9000000        <1>         JC      RWV_END                 ; MEDIA CHANGE ERROR OR TIME-OUT
  6659                              <1> RWV:
  6660 00002005 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6661 00002007 8AB7[11C50000]      <1> 	MOV	DH, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6662 0000200D 80E6C0              <1> 	AND	DH,RATE_MSK		; KEEP ONLY RATE
  6663 00002010 E84D050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
  6664                              <1> 	;;20/02/2015
  6665                              <1> 	;;JC	short RWV_ASSUME	; ERROR IN CMOS
  6666 00002015 7451                <1> 	jz	short RWV_ASSUME ; 20/02/2015
  6667 00002017 3C01                <1> 	CMP	AL,1			; 40 TRACK DRIVE?
  6668 00002019 750D                <1> 	JNE	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
  6669 0000201B F687[11C50000]01    <1> 	TEST	byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
  6670 00002022 7413                <1> 	JZ	short RWV_2		; YES, CMOS IS CORRECT
  6671 00002024 B002                <1> 	MOV	AL,2			; CHANGE TO 1.2M
  6672 00002026 EB0F                <1> 	JMP	SHORT RWV_2
  6673                              <1> RWV_1:
  6674 00002028 720D                <1> 	JB	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
  6675 0000202A F687[11C50000]01    <1> 	TEST    byte [DSK_STATE+eDI], TRK_CAPA ; IS IT REALLY 40 TRACK?
  6676 00002031 7504                <1> 	JNZ	short RWV_2		; NO, 80 TRACK
  6677 00002033 B001                <1> 	MOV	AL,1			; IT IS 40 TRACK, FIX CMOS VALUE
  6678 00002035 EB04                <1> 	jmp	short rwv_3
  6679                              <1> RWV_2:
  6680 00002037 08C0                <1> 	OR	AL,AL			; TEST FOR NO DRIVE
  6681 00002039 742D                <1> 	JZ	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
  6682                              <1> rwv_3:
  6683 0000203B E873FEFFFF          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
  6684 00002040 7226                <1> 	JC	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
  6685                              <1> 
  6686                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
  6687                              <1> 
  6688 00002042 57                  <1> 	PUSH	eDI			; SAVE DRIVE #
  6689 00002043 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6690 00002045 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6691                              <1> RWV_DR_SEARCH:
  6692 0000204A 8AA3[CCBE0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6693 00002050 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6694 00002053 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6695 00002055 750B                <1> 	JNE	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
  6696                              <1> RWV_DR_FND:
  6697 00002057 8BBB[CDBE0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAMETER TABLE
  6698                              <1> RWV_MD_SEARH:
  6699 0000205D 3A770C              <1>         CMP     DH, [eDI+MD.RATE]       ; MATCH?
  6700 00002060 741B                <1> 	JE	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
  6701                              <1> RWV_NXT_MD:
  6702                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6703 00002062 83C305              <1> 	add	eBX, 5
  6704 00002065 E2E3                <1> 	LOOP	RWV_DR_SEARCH
  6705 00002067 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6706                              <1> 
  6707                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
  6708                              <1> 
  6709                              <1> RWV_ASSUME:
  6710 00002068 BB[EABE0000]        <1> 	MOV	eBX, MD_TBL1		; POINT TO 40 TRACK 250 KBS
  6711 0000206D F687[11C50000]01    <1> 	TEST 	byte [DSK_STATE+eDI], TRK_CAPA ; TEST FOR 80 TRACK
  6712 00002074 740A                <1> 	JZ	short RWV_MD_FND1	; MUST BE 40 TRACK
  6713 00002076 BB[04BF0000]        <1> 	MOV	eBX, MD_TBL3		; POINT TO 80 TRACK 500 KBS
  6714 0000207B EB03                <1> 	JMP	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
  6715                              <1> 
  6716                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
  6717                              <1> 	 			
  6718                              <1> RWV_MD_FND:
  6719 0000207D 89FB                <1> 	MOV	eBX,eDI			; BX = MEDIA/DRIVE PARAMETER TABLE
  6720 0000207F 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6721                              <1> 	
  6722                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
  6723                              <1> 
  6724                              <1> RWV_MD_FND1:
  6725 00002080 E882FEFFFF          <1> 	CALL	SEND_SPEC_MD
  6726 00002085 E864010000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
  6727 0000208A 7405                <1> 	JZ	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
  6728 0000208C E83B010000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO NEC
  6729                              <1> RWV_DBL:
  6730 00002091 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6731 00002092 E822040000          <1> 	CALL	SETUP_DBL		; CHECK FOR DOUBLE STEP
  6732 00002097 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6733 00002098 7226                <1> 	JC	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
  6734 0000209A 6658                <1> 	POP	AX			; RESTORE NEC, DMA COMMAND
  6735 0000209C 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6736 0000209E 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6737 0000209F E861010000          <1> 	CALL	DMA_SETUP		; SET UP THE DMA
  6738 000020A4 5B                  <1> 	POP	eBX 
  6739 000020A5 6658                <1> 	POP	AX			; RESTORE NEC COMMAND
  6740 000020A7 722F                <1> 	JC	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
  6741 000020A9 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6742 000020AB 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6743 000020AC E83C020000          <1> 	CALL	NEC_INIT		; INITIALIZE NEC
  6744 000020B1 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6745 000020B2 720C                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6746 000020B4 E866020000          <1> 	CALL	RWV_COM			; OP CODE COMMON TO READ/WRITE/VERIFY
  6747 000020B9 7205                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6748 000020BB E8AB020000          <1> 	CALL	NEC_TERM		; TERMINATE, GET STATUS, ETC.
  6749                              <1> CHK_RET:
  6750 000020C0 E84A030000          <1> 	CALL	RETRY			; CHECK FOR, SETUP RETRY
  6751 000020C5 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY PARAMETER
  6752 000020C7 7305                <1> 	JNC	short RWV_END		; CY = 0 NO RETRY
  6753 000020C9 E928FFFFFF          <1>         JMP     DO_AGAIN                ; CY = 1 MEANS RETRY
  6754                              <1> RWV_END:
  6755 000020CE E8F4020000          <1> 	CALL	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
  6756 000020D3 E887030000          <1> 	CALL	NUM_TRANS		; AL = NUMBER TRANSFERRED
  6757                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
  6758 000020D8 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  6759 000020DA E879FEFFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6760 000020DF 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  6761 000020E1 E8B1030000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6762 000020E6 C3                  <1> 	RETn
  6763                              <1> 
  6764                              <1> ;-------------------------------------------------------------------------------
  6765                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  6766                              <1> ;-------------------------------------------------------------------------------
  6767                              <1> SETUP_STATE:
  6768 000020E7 F687[11C50000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; MEDIA DETERMINED ?
  6769 000020EE 7537                <1> 	JNZ	short J1C		; NO STATES IF DETERMINED
  6770 000020F0 66B84000            <1>         MOV     AX,(RATE_500*256)+RATE_300  ; AH = START RATE, AL = END RATE
  6771 000020F4 F687[11C50000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE ?
  6772 000020FB 740D                <1> 	JZ	short AX_SET		; DO NOT KNOW DRIVE
  6773 000020FD F687[11C50000]02    <1> 	TEST	byte [DSK_STATE+eDI], FMT_CAPA ; MULTI-RATE?
  6774 00002104 7504                <1> 	JNZ	short AX_SET		; JUMP IF YES
  6775 00002106 66B88080            <1>         MOV     AX,RATE_250*257         ; START A END RATE 250 FOR 360 DRIVE
  6776                              <1> AX_SET:	
  6777 0000210A 80A7[11C50000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  6778 00002111 08A7[11C50000]      <1> 	OR	[DSK_STATE+eDI], AH	; RATE FIRST TO TRY
  6779 00002117 8025[0CC50000]F3    <1> 	AND	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  6780 0000211E C0C804              <1> 	ROR	AL,4			; TO OPERATION LAST RATE LOCATION
  6781 00002121 0805[0CC50000]      <1> 	OR	[LASTRATE], AL		; LAST RATE
  6782                              <1> J1C:	
  6783 00002127 C3                  <1> 	RETn
  6784                              <1> 
  6785                              <1> ;-------------------------------------------------------------------------------
  6786                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  6787                              <1> ;-------------------------------------------------------------------------------
  6788                              <1> FMT_INIT:
  6789 00002128 F687[11C50000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; IS MEDIA ESTABLISHED
  6790 0000212F 7546                <1> 	JNZ	short F1_OUT		; IF SO RETURN
  6791 00002131 E82C040000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6792                              <1> 	;; 20/02/2015
  6793                              <1> 	;;JC	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  6794 00002136 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  6795 00002138 FEC8                <1> 	DEC	AL			; MAKE ZERO ORIGIN
  6796                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  6797 0000213A 8AA7[11C50000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; AH = CURRENT STATE
  6798 00002140 80E40F              <1> 	AND	AH, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  6799 00002143 08C0                <1> 	OR	AL,AL			; CHECK FOR 360
  6800 00002145 7505                <1> 	JNZ	short N_360		; IF 360 WILL BE 0
  6801 00002147 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; ESTABLISH MEDIA
  6802 0000214A EB25                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6803                              <1> N_360:	
  6804 0000214C FEC8                <1> 	DEC	AL			; 1.2 M DRIVE
  6805 0000214E 7505                <1> 	JNZ	short N_12		; JUMP IF NOT
  6806                              <1> F1_RATE:
  6807 00002150 80CC10              <1> 	OR	AH,MED_DET+RATE_500	; SET FORMAT RATE
  6808 00002153 EB1C                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6809                              <1> N_12:	
  6810 00002155 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 3
  6811 00002157 750F                <1> 	JNZ	short N_720		; JUMP IF NOT
  6812 00002159 F6C404              <1> 	TEST	AH,DRV_DET		; IS DRIVE DETERMINED
  6813 0000215C 7410                <1> 	JZ	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  6814 0000215E F6C402              <1> 	TEST	AH,FMT_CAPA		; IS 1.2M
  6815 00002161 740B                <1> 	JZ	short ISNT_12		; JUMP IF NOT
  6816 00002163 80CC50              <1> 	OR	AH,MED_DET+RATE_300	; RATE 300
  6817 00002166 EB09                <1> 	JMP	SHORT SKP_STATE		; CONTINUE
  6818                              <1> N_720:
  6819 00002168 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 4
  6820 0000216A 750C                <1> 	JNZ	short CL_DRV		; NO DRIVE, CMOS BAD
  6821 0000216C EBE2                <1> 	JMP	SHORT F1_RATE
  6822                              <1> ISNT_12: 
  6823 0000216E 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; MUST BE RATE 250
  6824                              <1> 
  6825                              <1> SKP_STATE:
  6826 00002171 88A7[11C50000]      <1> 	MOV	[DSK_STATE+eDI], AH	; STORE AWAY
  6827                              <1> F1_OUT:
  6828 00002177 C3                  <1> 	RETn
  6829                              <1> CL_DRV:	
  6830 00002178 30E4                <1> 	XOR	AH,AH			; CLEAR STATE
  6831 0000217A EBF5                <1> 	JMP	SHORT SKP_STATE		; SAVE IT
  6832                              <1> 
  6833                              <1> ;-------------------------------------------------------------------------------
  6834                              <1> ; MED_CHANGE	
  6835                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  6836                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  6837                              <1> ;
  6838                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  6839                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  6840                              <1> ;-------------------------------------------------------------------------------
  6841                              <1> MED_CHANGE:
  6842 0000217C E888060000          <1> 	CALL	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  6843 00002181 7447                <1> 	JZ	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  6844 00002183 80A7[11C50000]EF    <1> 	AND	byte [DSK_STATE+eDI], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  6845                              <1> 
  6846                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  6847                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  6848                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  6849                              <1> 
  6850 0000218A 6689F9              <1> 	MOV	CX,DI			; CL = DRIVE 0
  6851 0000218D B001                <1> 	MOV	AL,1			; MOTOR ON BIT MASK
  6852 0000218F D2E0                <1> 	SHL	AL,CL			; TO APPROPRIATE POSITION
  6853 00002191 F6D0                <1> 	NOT	AL			; KEEP ALL BUT MOTOR ON
  6854 00002193 FA                  <1> 	CLI				; NO INTERRUPTS
  6855 00002194 2005[02C50000]      <1> 	AND	[MOTOR_STATUS], AL	; TURN MOTOR OFF INDICATOR
  6856 0000219A FB                  <1> 	STI				; INTERRUPTS ENABLED
  6857 0000219B E810040000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON
  6858                              <1> 
  6859                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  6860                              <1> 
  6861 000021A0 E884F9FFFF          <1> 	CALL	DSK_RESET		; RESET NEC
  6862 000021A5 B501                <1> 	MOV	CH,01H			; MOVE TO CYLINDER 1
  6863 000021A7 E8FF040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6864 000021AC 30ED                <1> 	XOR	CH,CH			; MOVE TO CYLINDER 0
  6865 000021AE E8F8040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6866 000021B3 C605[04C50000]06    <1> 	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  6867                              <1> OK1:
  6868 000021BA E84A060000          <1> 	CALL	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  6869 000021BF 7407                <1> 	JZ	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  6870                              <1> OK4:
  6871 000021C1 C605[04C50000]80    <1> 	MOV	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  6872                              <1> OK2:		
  6873 000021C8 F9                  <1> 	STC				; MEDIA CHANGED, SET CY
  6874 000021C9 C3                  <1> 	RETn
  6875                              <1> MC_OUT:
  6876 000021CA F8                  <1> 	CLC				; NO MEDIA CHANGED, CLEAR CY
  6877 000021CB C3                  <1> 	RETn
  6878                              <1> 
  6879                              <1> ;-------------------------------------------------------------------------------
  6880                              <1> ; SEND_RATE
  6881                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  6882                              <1> ; ON ENTRY:	DI = DRIVE #
  6883                              <1> ; ON EXIT:	NONE
  6884                              <1> ; REGISTERS ALTERED: DX
  6885                              <1> ;-------------------------------------------------------------------------------
  6886                              <1> SEND_RATE:
  6887 000021CC 6650                <1> 	PUSH	AX			; SAVE REG.
  6888 000021CE 8025[0CC50000]3F    <1> 	AND	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  6889 000021D5 8A87[11C50000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6890 000021DB 24C0                <1> 	AND	AL,SEND_MSK		; KEEP ONLY RATE BITS
  6891 000021DD 0805[0CC50000]      <1> 	OR	[LASTRATE], AL		; SAVE NEW RATE FOR NEXT CHECK
  6892 000021E3 C0C002              <1> 	ROL	AL,2			; MOVE TO BIT OUTPUT POSITIONS
  6893 000021E6 66BAF703            <1> 	MOV	DX,03F7H		; OUTPUT NEW DATA RATE
  6894 000021EA EE                  <1> 	OUT	DX,AL
  6895 000021EB 6658                <1> 	POP	AX			; RESTORE REG.
  6896 000021ED C3                  <1> 	RETn
  6897                              <1> 
  6898                              <1> ;-------------------------------------------------------------------------------
  6899                              <1> ; CHK_LASTRATE
  6900                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  6901                              <1> ; ON ENTRY:
  6902                              <1> ;	DI = DRIVE #
  6903                              <1> ; ON EXIT:
  6904                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  6905                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  6906                              <1> ; REGISTERS ALTERED: DX
  6907                              <1> ;-------------------------------------------------------------------------------
  6908                              <1> CHK_LASTRATE:
  6909 000021EE 6650                <1> 	PUSH	AX			; SAVE REG
  6910 000021F0 2225[0CC50000]      <1> 	AND	AH, [LASTRATE]		; GET LAST DATA RATE SELECTED
  6911 000021F6 8A87[11C50000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6912 000021FC 6625C0C0            <1>         AND     AX, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  6913 00002200 38E0                <1> 	CMP	AL, AH			; COMPARE TO PREVIOUSLY TRIED
  6914                              <1> 					; ZF = 1 RATE IS THE SAME
  6915 00002202 6658                <1> 	POP	AX			; RESTORE REG.
  6916 00002204 C3                  <1> 	RETn
  6917                              <1> 
  6918                              <1> ;-------------------------------------------------------------------------------
  6919                              <1> ; DMA_SETUP
  6920                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  6921                              <1> ;
  6922                              <1> ; ON ENTRY:	AL = DMA COMMAND
  6923                              <1> ;
  6924                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6925                              <1> ;-------------------------------------------------------------------------------
  6926                              <1> 
  6927                              <1> ; SI = Head #, # of Sectors or DASD Type
  6928                              <1> 
  6929                              <1> ; 22/08/2015
  6930                              <1> ; 08/02/2015 - Protected Mode Modification
  6931                              <1> ; 06/02/2015 - 07/02/2015
  6932                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  6933                              <1> ; (DMA Addres = Physical Address)
  6934                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  6935                              <1> ;
  6936                              <1> 
  6937                              <1> 
  6938                              <1> ; 04/02/2016 (clc)
  6939                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  6940                              <1> ; 16/12/2014 (IODELAY)
  6941                              <1> 
  6942                              <1> DMA_SETUP:
  6943                              <1> 
  6944                              <1> ;; 20/02/2015
  6945 00002205 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  6946 00002208 F7C2000000FF        <1> 	test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  6947 0000220E 756E                <1> 	jnz	short dma_bnd_err_stc
  6948                              <1> 	;
  6949 00002210 6650                <1> 	push	ax			; DMA command
  6950 00002212 52                  <1> 	push	edx			; *
  6951 00002213 B203                <1> 	mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  6952 00002215 E851030000          <1> 	call	GET_PARM		; 
  6953 0000221A 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  6954 0000221C 6689F0              <1> 	mov	ax, si			; Sector count
  6955 0000221F 88C4                <1> 	mov	ah, al			; AH =  # OF SECTORS
  6956 00002221 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  6957 00002223 66D1E8              <1> 	shr	ax, 1			; AX = # SECTORS * 128
  6958 00002226 66D3E0              <1> 	shl	ax, cl			; SHIFT BY PARAMETER VALUE
  6959 00002229 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  6960 0000222B 6689C1              <1> 	mov	cx, ax
  6961 0000222E 5A                  <1> 	pop	edx			; *
  6962 0000222F 6658                <1> 	pop	ax
  6963 00002231 3C42                <1> 	cmp	al, 42h
  6964 00002233 7507                <1>         jne     short NOT_VERF
  6965 00002235 BA0000FF00          <1> 	mov	edx, 0FF0000h
  6966 0000223A EB08                <1> 	jmp	short J33
  6967                              <1> NOT_VERF:
  6968 0000223C 6601CA              <1> 	add	dx, cx			; check for overflow
  6969 0000223F 723E                <1> 	jc	short dma_bnd_err
  6970                              <1> 	;
  6971 00002241 6629CA              <1> 	sub	dx, cx			; Restore start address
  6972                              <1> J33:
  6973 00002244 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  6974 00002245 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  6975                              <1> 	IODELAY				; WAIT FOR I/O
  6976 00002247 EB00                <2>  jmp short $+2
  6977 00002249 EB00                <2>  jmp short $+2
  6978 0000224B E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  6979 0000224D 89D0                <1> 	mov	eax, edx		; Buffer address
  6980 0000224F E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  6981                              <1> 	IODELAY				; WAIT FOR I/O
  6982 00002251 EB00                <2>  jmp short $+2
  6983 00002253 EB00                <2>  jmp short $+2
  6984 00002255 88E0                <1> 	MOV	AL,AH
  6985 00002257 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  6986 00002259 C1E810              <1> 	shr	eax, 16
  6987                              <1> 	IODELAY				; I/O WAIT STATE
  6988 0000225C EB00                <2>  jmp short $+2
  6989 0000225E EB00                <2>  jmp short $+2
  6990 00002260 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  6991                              <1> 	IODELAY
  6992 00002262 EB00                <2>  jmp short $+2
  6993 00002264 EB00                <2>  jmp short $+2
  6994 00002266 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  6995 00002269 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  6996                              <1> 	IODELAY				; WAIT FOR I/O
  6997 0000226B EB00                <2>  jmp short $+2
  6998 0000226D EB00                <2>  jmp short $+2
  6999 0000226F 88E0                <1> 	MOV	AL, AH
  7000 00002271 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7001                              <1> 	IODELAY
  7002 00002273 EB00                <2>  jmp short $+2
  7003 00002275 EB00                <2>  jmp short $+2
  7004 00002277 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7005 00002278 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7006 0000227A E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7007                              <1> 
  7008 0000227C F8                  <1> 	clc	; 04/02/2016
  7009 0000227D C3                  <1> 	retn
  7010                              <1> 
  7011                              <1> dma_bnd_err_stc:
  7012 0000227E F9                  <1> 	stc
  7013                              <1> dma_bnd_err:
  7014 0000227F C605[04C50000]09    <1> 	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7015 00002286 C3                  <1> 	RETn				; CY SET BY ABOVE IF ERROR
  7016                              <1> 
  7017                              <1> ;; 16/12/2014
  7018                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7019                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7020                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7021                              <1> ;;	IODELAY
  7022                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7023                              <1> ;;	;SIODELAY
  7024                              <1> ;;      ;CMP	AL, 42H			; DMA VERIFY COMMAND
  7025                              <1> ;;      ;JNE	short NOT_VERF		; NO
  7026                              <1> ;;      ;XOR	AX, AX			; START ADDRESS
  7027                              <1> ;;      ;JMP	SHORT J33
  7028                              <1> ;;;NOT_VERF:	
  7029                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7030                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7031                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7032                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7033                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7034                              <1> ;;	mov	eax, [ebp+4] ; 06/02/2015	
  7035                              <1> ;;	;JNC	short J33
  7036                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7037                              <1> ;;;J33:
  7038                              <1> ;;	PUSH	eAX			; SAVE START ADDRESS
  7039                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7040                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7041                              <1> ;;	IODELAY
  7042                              <1> ;;	MOV	AL,AH
  7043                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7044                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  7045                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7046                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7047                              <1> ;;	IODELAY
  7048                              <1> ;;	;AND	AL,00001111B
  7049                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7050                              <1> ;;	;SIODELAY
  7051                              <1> ;;
  7052                              <1> ;;;----- DETERMINE COUNT
  7053                              <1> ;;	sub	eax, eax ; 08/02/2015
  7054                              <1> ;;	MOV	AX, SI			; AL =  # OF SECTORS
  7055                              <1> ;;	XCHG	AL, AH			; AH =  # OF SECTORS
  7056                              <1> ;;	SUB	AL, AL			; AL = 0, AX = # SECTORS * 256
  7057                              <1> ;;	SHR	AX, 1			; AX = # SECTORS * 128
  7058                              <1> ;;	PUSH	AX			; SAVE # OF SECTORS * 128
  7059                              <1> ;;	MOV	DL, 3			; GET BYTES/SECTOR PARAMETER
  7060                              <1> ;;	CALL	GET_PARM		; "
  7061                              <1> ;;	MOV	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  7062                              <1> ;;	POP	AX			; AX = # SECTORS * 128
  7063                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  7064                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7065                              <1> ;;	PUSH	eAX  ; 08/02/2015	; SAVE COUNT VALUE
  7066                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7067                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7068                              <1> ;;	IODELAY
  7069                              <1> ;;	MOV	AL, AH
  7070                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7071                              <1> ;;	;IODELAY
  7072                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7073                              <1> ;;	POP	eCX  ; 08/02/2015 	; RECOVER COUNT VALUE
  7074                              <1> ;;	POP	eAX  ; 08/02/2015	; RECOVER ADDRESS VALUE
  7075                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7076                              <1> ;;	add	ecx, eax ; 08/02/2015
  7077                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7078                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7079                              <1> ;;	SIODELAY
  7080                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7081                              <1> ;;	;JNC	short NO_BAD		; CHECK FOR ERROR
  7082                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  7083                              <1> ;;	and	ecx, 0FFF00000h ; 16 MB limit
  7084                              <1> ;;	jz	short NO_BAD
  7085                              <1> ;;dma_bnd_err:
  7086                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7087                              <1> ;;NO_BAD:
  7088                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7089                              <1> 
  7090                              <1> ;-------------------------------------------------------------------------------
  7091                              <1> ; FMTDMA_SET
  7092                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  7093                              <1> ;
  7094                              <1> ; ON ENTRY:	NOTHING REQUIRED
  7095                              <1> ;
  7096                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7097                              <1> ;-------------------------------------------------------------------------------
  7098                              <1> 
  7099                              <1> FMTDMA_SET:
  7100                              <1> ;; 20/02/2015 modification	
  7101 00002287 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  7102 0000228A F7C20000F0FF        <1> 	test	edx, 0FFF00000h		; 16 MB limit
  7103 00002290 75EC                <1> 	jnz	short dma_bnd_err_stc
  7104                              <1> 	;
  7105 00002292 6652                <1> 	push	dx			; *
  7106 00002294 B204                <1> 	mov	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7107 00002296 E8D0020000          <1> 	call	GET_PARM		; "
  7108 0000229B 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  7109 0000229D 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  7110 0000229F 66C1E002            <1> 	shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7111 000022A3 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  7112 000022A5 6689C1              <1> 	mov	cx, ax
  7113 000022A8 665A                <1> 	pop	dx			; *
  7114 000022AA 6601CA              <1> 	add	dx, cx			; check for overflow
  7115 000022AD 72D0                <1> 	jc	short dma_bnd_err
  7116                              <1> 	;
  7117 000022AF 6629CA              <1> 	sub	dx, cx			; Restore start address
  7118                              <1> 	;
  7119 000022B2 B04A                <1> 	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7120 000022B4 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7121 000022B5 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7122                              <1> 	IODELAY				; WAIT FOR I/O
  7123 000022B7 EB00                <2>  jmp short $+2
  7124 000022B9 EB00                <2>  jmp short $+2
  7125 000022BB E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7126 000022BD 89D0                <1> 	mov	eax, edx		; Buffer address
  7127 000022BF E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7128                              <1> 	IODELAY				; WAIT FOR I/O
  7129 000022C1 EB00                <2>  jmp short $+2
  7130 000022C3 EB00                <2>  jmp short $+2
  7131 000022C5 88E0                <1> 	MOV	AL,AH
  7132 000022C7 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7133 000022C9 C1E810              <1> 	shr	eax, 16
  7134                              <1> 	IODELAY				; I/O WAIT STATE
  7135 000022CC EB00                <2>  jmp short $+2
  7136 000022CE EB00                <2>  jmp short $+2
  7137 000022D0 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  7138                              <1> 	IODELAY
  7139 000022D2 EB00                <2>  jmp short $+2
  7140 000022D4 EB00                <2>  jmp short $+2
  7141 000022D6 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  7142 000022D9 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7143                              <1> 	IODELAY				; WAIT FOR I/O
  7144 000022DB EB00                <2>  jmp short $+2
  7145 000022DD EB00                <2>  jmp short $+2
  7146 000022DF 88E0                <1> 	MOV	AL, AH
  7147 000022E1 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7148                              <1> 	IODELAY
  7149 000022E3 EB00                <2>  jmp short $+2
  7150 000022E5 EB00                <2>  jmp short $+2
  7151 000022E7 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7152 000022E8 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7153 000022EA E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7154 000022EC C3                  <1> 	retn
  7155                              <1> 
  7156                              <1> ;; 08/02/2015 - Protected Mode Modification
  7157                              <1> ;;	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7158                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7159                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7160                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7161                              <1> ;;	IODELAY
  7162                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7163                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7164                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7165                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7166                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7167                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7168                              <1> ;;	;JNC	short J33A
  7169                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7170                              <1> ;;	mov	eax, [ebp+4] ; 08/02/2015
  7171                              <1> ;;;J33A:
  7172                              <1> ;;	PUSH	eAX ; 08/02/2015	; SAVE START ADDRESS
  7173                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7174                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7175                              <1> ;;	IODELAY
  7176                              <1> ;;	MOV	AL,AH
  7177                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7178                              <1> ;;	shr 	eax, 16 ; 08/02/2015
  7179                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7180                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7181                              <1> ;;	IODELAY
  7182                              <1> ;;	;AND	AL,00001111B
  7183                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7184                              <1> ;;
  7185                              <1> ;;;----- DETERMINE COUNT
  7186                              <1> ;;	sub	eax, eax ; 08/02/2015
  7187                              <1> ;;	MOV	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7188                              <1> ;;	CALL	GET_PARM		; "
  7189                              <1> ;;	XCHG	AL, AH			; AL = SECTORS/TRACK VALUE
  7190                              <1> ;;	SUB	AH, AH			; AX = SECTORS/TRACK VALUE
  7191                              <1> ;;	SHL	AX, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7192                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7193                              <1> ;;	PUSH	eAX 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  7194                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7195                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7196                              <1> ;;	IODELAY
  7197                              <1> ;;	MOV	AL, AH
  7198                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7199                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7200                              <1> ;;	POP	eCX	; 08/02/2015	; RECOVER COUNT VALUE
  7201                              <1> ;;	POP	eAX	; 08/02/2015	; RECOVER ADDRESS VALUE
  7202                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7203                              <1> ;;	add	ecx, eax ; 08/02/2015
  7204                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7205                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7206                              <1> ;;	SIODELAY
  7207                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7208                              <1> ;;	;JNC	short FMTDMA_OK		; CHECK FOR ERROR
  7209                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  7210                              <1> ;;	and	ecx, 0FFF00000h  ; 16 MB limit
  7211                              <1> ;;	jz	short FMTDMA_OK
  7212                              <1> ;;	stc	; 20/02/2015
  7213                              <1> ;;fmtdma_bnd_err:
  7214                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7215                              <1> ;;FMTDMA_OK:
  7216                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7217                              <1> 
  7218                              <1> ;-------------------------------------------------------------------------------
  7219                              <1> ; NEC_INIT	
  7220                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  7221                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  7222                              <1> ;
  7223                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  7224                              <1> ;
  7225                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7226                              <1> ;-------------------------------------------------------------------------------
  7227                              <1> NEC_INIT:
  7228 000022ED 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  7229 000022EF E8BC020000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  7230                              <1> 
  7231                              <1> ;-----	DO THE SEEK OPERATION
  7232                              <1> 
  7233 000022F4 8A6D01              <1> 	MOV	CH,[eBP+1]		; CH = TRACK #
  7234 000022F7 E8AF030000          <1> 	CALL	SEEK			; MOVE TO CORRECT TRACK
  7235 000022FC 6658                <1> 	POP	AX			; RECOVER COMMAND
  7236 000022FE 721E                <1> 	JC	short ER_1		; ERROR ON SEEK
  7237 00002300 BB[1E230000]        <1> 	MOV	eBX, ER_1		; LOAD ERROR ADDRESS
  7238 00002305 53                  <1> 	PUSH	eBX			; PUSH NEC_OUT ERROR RETURN
  7239                              <1> 
  7240                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  7241                              <1> 
  7242 00002306 E866030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  7243 0000230B 6689F0              <1> 	MOV	AX,SI			; AH = HEAD #
  7244 0000230E 89FB                <1> 	MOV	eBX,eDI			; BL = DRIVE #
  7245 00002310 C0E402              <1> 	SAL	AH,2			; MOVE IT TO BIT 2
  7246 00002313 80E404              <1> 	AND	AH,00000100B		; ISOLATE THAT BIT
  7247 00002316 08DC                <1> 	OR	AH,BL			; OR IN THE DRIVE NUMBER
  7248 00002318 E854030000          <1> 	CALL	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  7249 0000231D 5B                  <1> 	POP	eBX			; THROW AWAY ERROR RETURN
  7250                              <1> ER_1:
  7251 0000231E C3                  <1> 	RETn
  7252                              <1> 
  7253                              <1> ;-------------------------------------------------------------------------------
  7254                              <1> ; RWV_COM
  7255                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  7256                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  7257                              <1> ;
  7258                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  7259                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7260                              <1> ;-------------------------------------------------------------------------------
  7261                              <1> RWV_COM:
  7262 0000231F B8[6A230000]        <1> 	MOV	eAX, ER_2		; LOAD ERROR ADDRESS
  7263 00002324 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  7264 00002325 8A6501              <1> 	MOV	AH,[eBP+1]		; OUTPUT TRACK #
  7265 00002328 E844030000          <1> 	CALL	NEC_OUTPUT
  7266 0000232D 6689F0              <1> 	MOV	AX,SI			; OUTPUT HEAD #
  7267 00002330 E83C030000          <1> 	CALL	NEC_OUTPUT
  7268 00002335 8A6500              <1>         MOV     AH,[eBP]                ; OUTPUT SECTOR #
  7269 00002338 E834030000          <1> 	CALL	NEC_OUTPUT
  7270 0000233D B203                <1> 	MOV	DL,3			; BYTES/SECTOR PARAMETER FROM BLOCK
  7271 0000233F E827020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7272 00002344 E828030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7273 00002349 B204                <1> 	MOV	DL,4			; EOT PARAMETER FROM BLOCK
  7274 0000234B E81B020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7275 00002350 E81C030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7276 00002355 8A6305              <1>         MOV     AH, [eBX+MD.GAP]        ; GET GAP LENGTH
  7277                              <1> _R15:
  7278 00002358 E814030000          <1> 	CALL	NEC_OUTPUT
  7279 0000235D B206                <1> 	MOV	DL,6			; DTL PARAMETER PROM BLOCK
  7280 0000235F E807020000          <1> 	CALL	GET_PARM		;  TO THE NEC
  7281 00002364 E808030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7282 00002369 58                  <1> 	POP	eAX			; THROW AWAY ERROR EXIT
  7283                              <1> ER_2:
  7284 0000236A C3                  <1> 	RETn
  7285                              <1> 
  7286                              <1> ;-------------------------------------------------------------------------------
  7287                              <1> ; NEC_TERM
  7288                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  7289                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  7290                              <1> ;
  7291                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7292                              <1> ;-------------------------------------------------------------------------------
  7293                              <1> NEC_TERM:
  7294                              <1> 
  7295                              <1> ;-----	LET THE OPERATION HAPPEN
  7296                              <1> 
  7297 0000236B 56                  <1> 	PUSH	eSI			; SAVE HEAD #, # OF SECTORS
  7298 0000236C E80D040000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  7299 00002371 9C                  <1> 	PUSHF
  7300 00002372 E837040000          <1> 	CALL	RESULTS			; GET THE NEC STATUS
  7301 00002377 724B                <1> 	JC	short SET_END_POP
  7302 00002379 9D                  <1> 	POPF
  7303 0000237A 723E                <1> 	JC	short SET_END		; LOOK FOR ERROR
  7304                              <1> 
  7305                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  7306                              <1> 
  7307 0000237C FC                  <1> 	CLD				; SET THE CORRECT DIRECTION
  7308 0000237D BE[05C50000]        <1> 	MOV	eSI, NEC_STATUS		; POINT TO STATUS FIELD
  7309 00002382 AC                  <1> 	lodsb				; GET ST0
  7310 00002383 24C0                <1> 	AND	AL,11000000B		; TEST FOR NORMAL TERMINATION
  7311 00002385 7433                <1> 	JZ	short SET_END
  7312 00002387 3C40                <1> 	CMP	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  7313 00002389 7527                <1> 	JNZ	short J18		; NOT ABNORMAL, BAD NEC
  7314                              <1> 
  7315                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  7316                              <1> 
  7317 0000238B AC                  <1> 	lodsb				; GET ST1
  7318 0000238C D0E0                <1> 	SAL	AL,1			; TEST FOR EDT FOUND
  7319 0000238E B404                <1> 	MOV	AH,RECORD_NOT_FND
  7320 00002390 7222                <1> 	JC	short J19
  7321 00002392 C0E002              <1> 	SAL	AL,2
  7322 00002395 B410                <1> 	MOV	AH,BAD_CRC
  7323 00002397 721B                <1> 	JC	short J19
  7324 00002399 D0E0                <1> 	SAL	AL,1			; TEST FOR DMA OVERRUN
  7325 0000239B B408                <1> 	MOV	AH,BAD_DMA
  7326 0000239D 7215                <1> 	JC	short J19
  7327 0000239F C0E002              <1> 	SAL	AL,2			; TEST FOR RECORD NOT FOUND
  7328 000023A2 B404                <1> 	MOV	AH,RECORD_NOT_FND
  7329 000023A4 720E                <1> 	JC	short J19
  7330 000023A6 D0E0                <1> 	SAL	AL,1
  7331 000023A8 B403                <1> 	MOV	AH,WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  7332 000023AA 7208                <1> 	JC	short J19
  7333 000023AC D0E0                <1> 	SAL	AL,1			; TEST MISSING ADDRESS MARK
  7334 000023AE B402                <1> 	MOV	AH,BAD_ADDR_MARK
  7335 000023B0 7202                <1> 	JC	short J19
  7336                              <1> 
  7337                              <1> ;----- 	NEC MUST HAVE FAILED
  7338                              <1> J18:
  7339 000023B2 B420                <1> 	MOV	AH,BAD_NEC
  7340                              <1> J19:
  7341 000023B4 0825[04C50000]      <1> 	OR	[DSKETTE_STATUS], AH
  7342                              <1> SET_END:
  7343 000023BA 803D[04C50000]01    <1> 	CMP	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  7344 000023C1 F5                  <1> 	CMC
  7345 000023C2 5E                  <1> 	POP	eSI
  7346 000023C3 C3                  <1> 	RETn				; RESTORE HEAD #, # OF SECTORS
  7347                              <1> 
  7348                              <1> SET_END_POP:
  7349 000023C4 9D                  <1> 	POPF
  7350 000023C5 EBF3                <1> 	JMP	SHORT SET_END
  7351                              <1> 
  7352                              <1> ;-------------------------------------------------------------------------------
  7353                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  7354                              <1> ;-------------------------------------------------------------------------------
  7355                              <1> DSTATE:
  7356 000023C7 803D[04C50000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7357 000023CE 753E                <1> 	JNZ	short SETBAC		    ; IF ERROR JUMP
  7358 000023D0 808F[11C50000]10    <1> 	OR	byte [DSK_STATE+eDI],MED_DET ; NO ERROR, MARK MEDIA AS DETERMINED
  7359 000023D7 F687[11C50000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE DETERMINED ?
  7360 000023DE 752E                <1> 	JNZ	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  7361 000023E0 8A87[11C50000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7362 000023E6 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7363 000023E8 3C80                <1> 	CMP	AL,RATE_250		; RATE 250 ?
  7364 000023EA 751B                <1> 	JNE	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  7365                              <1> 
  7366                              <1> ;----- 	CHECK IF IT IS 1.44M
  7367                              <1> 
  7368 000023EC E871010000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  7369                              <1> 	;;20/02/2015
  7370                              <1> 	;;JC	short M_12		; CMOS BAD
  7371 000023F1 7414                <1> 	jz	short M_12 ;; 20/02/2015
  7372 000023F3 3C04                <1> 	CMP	AL, 4			; 1.44MB DRIVE ?
  7373 000023F5 7410                <1> 	JE	short M_12		; YES
  7374                              <1> M_720:
  7375 000023F7 80A7[11C50000]FD    <1> 	AND	byte [DSK_STATE+eDI], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  7376 000023FE 808F[11C50000]04    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET  ; MARK DRIVE DETERMINED
  7377 00002405 EB07                <1> 	JMP	SHORT SETBAC		; BACK
  7378                              <1> M_12:	
  7379 00002407 808F[11C50000]06    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET+FMT_CAPA 
  7380                              <1> 					; TURN ON DETERMINED & FMT CAPA
  7381                              <1> SETBAC:
  7382 0000240E C3                  <1> 	RETn
  7383                              <1> 
  7384                              <1> ;-------------------------------------------------------------------------------
  7385                              <1> ; RETRY	
  7386                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  7387                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  7388                              <1> ;
  7389                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  7390                              <1> ;-------------------------------------------------------------------------------
  7391                              <1> RETRY:
  7392 0000240F 803D[04C50000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; GET STATUS OF OPERATION
  7393 00002416 7445                <1> 	JZ	short NO_RETRY		; SUCCESSFUL OPERATION
  7394 00002418 803D[04C50000]80    <1> 	CMP	byte [DSKETTE_STATUS],TIME_OUT ; IF TIME OUT NO RETRY
  7395 0000241F 743C                <1> 	JZ	short NO_RETRY
  7396 00002421 8AA7[11C50000]      <1> 	MOV	AH,[DSK_STATE+eDI]	; GET MEDIA STATE OF DRIVE
  7397 00002427 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED/DETERMINED ?
  7398 0000242A 7531                <1> 	JNZ	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  7399 0000242C 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE RATE
  7400 0000242F 8A2D[0CC50000]      <1> 	MOV	CH,[LASTRATE]		; GET START OPERATION STATE
  7401 00002435 C0C504              <1> 	ROL	CH,4			; TO CORRESPONDING BITS
  7402 00002438 80E5C0              <1> 	AND	CH,RATE_MSK		; ISOLATE RATE BITS
  7403 0000243B 38E5                <1> 	CMP	CH,AH			; ALL RATES TRIED
  7404 0000243D 741E                <1> 	JE	short NO_RETRY		; IF YES, THEN TRUE ERROR
  7405                              <1> 
  7406                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  7407                              <1> ;	 00000000B (500) -> 10000000B	(250)
  7408                              <1> ;	 10000000B (250) -> 01000000B	(300)
  7409                              <1> ;	 01000000B (300) -> 00000000B	(500)
  7410                              <1> 
  7411 0000243F 80FC01              <1> 	CMP	AH,RATE_500+1		; SET CY FOR RATE 500
  7412 00002442 D0DC                <1> 	RCR	AH,1			; TO NEXT STATE
  7413 00002444 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE BITS
  7414 00002447 80A7[11C50000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP)
  7415                              <1> 					; RATE, DBL STEP OFF
  7416 0000244E 08A7[11C50000]      <1> 	OR	[DSK_STATE+eDI],AH	; TURN ON NEW RATE
  7417 00002454 C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; RESET STATUS FOR RETRY
  7418 0000245B F9                  <1> 	STC				; SET CARRY FOR RETRY
  7419 0000245C C3                  <1> 	RETn				; RETRY RETURN
  7420                              <1> 
  7421                              <1> NO_RETRY:
  7422 0000245D F8                  <1> 	CLC				; CLEAR CARRY NO RETRY
  7423 0000245E C3                  <1> 	RETn				; NO RETRY RETURN
  7424                              <1> 
  7425                              <1> ;-------------------------------------------------------------------------------
  7426                              <1> ; NUM_TRANS
  7427                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  7428                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  7429                              <1> ;
  7430                              <1> ; ON ENTRY:	[BP+1] = TRACK
  7431                              <1> ;		SI-HI  = HEAD
  7432                              <1> ;		[BP]   = START SECTOR
  7433                              <1> ;
  7434                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  7435                              <1> ;-------------------------------------------------------------------------------
  7436                              <1> NUM_TRANS:
  7437 0000245F 30C0                <1> 	XOR	AL,AL			; CLEAR FOR ERROR
  7438 00002461 803D[04C50000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7439 00002468 752C                <1> 	JNZ	NT_OUT			; IF ERROR 0 TRANSFERRED
  7440 0000246A B204                <1> 	MOV	DL,4			; SECTORS/TRACK OFFSET TO DL
  7441 0000246C E8FA000000          <1> 	CALL	GET_PARM		; AH = SECTORS/TRACK
  7442 00002471 8A1D[0AC50000]      <1> 	MOV	BL, [NEC_STATUS+5]	; GET ENDING SECTOR
  7443 00002477 6689F1              <1> 	MOV	CX,SI			; CH = HEAD # STARTED
  7444 0000247A 3A2D[09C50000]      <1> 	CMP	CH, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  7445 00002480 750D                <1> 	JNZ	DIF_HD			; IF ON SAME HEAD, THEN NO ADJUST
  7446 00002482 8A2D[08C50000]      <1> 	MOV	CH, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  7447 00002488 3A6D01              <1> 	CMP	CH,[eBP+1]		; IS IT ASKED FOR TRACK
  7448 0000248B 7404                <1> 	JZ	short SAME_TRK		; IF SAME TRACK NO INCREASE
  7449 0000248D 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7450                              <1> DIF_HD:
  7451 0000248F 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7452                              <1> SAME_TRK:
  7453 00002491 2A5D00              <1> 	SUB	BL,[eBP]		; SUBTRACT START FROM END
  7454 00002494 88D8                <1> 	MOV	AL,BL			; TO AL
  7455                              <1> NT_OUT:
  7456 00002496 C3                  <1> 	RETn
  7457                              <1> 
  7458                              <1> ;-------------------------------------------------------------------------------
  7459                              <1> ; SETUP_END
  7460                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
  7461                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
  7462                              <1> ;
  7463                              <1> ; ON EXIT:
  7464                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7465                              <1> ;-------------------------------------------------------------------------------
  7466                              <1> SETUP_END:
  7467 00002497 B202                <1> 	MOV	DL,2			; GET THE MOTOR WAIT PARAMETER
  7468 00002499 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  7469 0000249B E8CB000000          <1> 	CALL	GET_PARM
  7470 000024A0 8825[03C50000]      <1> 	MOV	[MOTOR_COUNT],AH	; STORE UPON RETURN
  7471 000024A6 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  7472 000024A8 8A25[04C50000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  7473 000024AE 08E4                <1> 	OR	AH,AH			; CHECK FOR ERROR
  7474 000024B0 7402                <1> 	JZ	short NUN_ERR			; NO ERROR
  7475 000024B2 30C0                <1> 	XOR	AL,AL			; CLEAR NUMBER RETURNED
  7476                              <1> NUN_ERR: 
  7477 000024B4 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  7478 000024B7 F5                  <1> 	CMC				; SUCCESS OR FAILURE
  7479 000024B8 C3                  <1> 	RETn
  7480                              <1> 
  7481                              <1> ;-------------------------------------------------------------------------------
  7482                              <1> ; SETUP_DBL
  7483                              <1> ;	CHECK DOUBLE STEP.
  7484                              <1> ;
  7485                              <1> ; ON ENTRY :	DI = DRIVE
  7486                              <1> ;
  7487                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  7488                              <1> ;-------------------------------------------------------------------------------
  7489                              <1> SETUP_DBL:
  7490 000024B9 8AA7[11C50000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  7491 000024BF F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED STATE ?
  7492 000024C2 757E                <1> 	JNZ	short NO_DBL			; IF ESTABLISHED THEN DOUBLE DONE
  7493                              <1> 
  7494                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  7495                              <1> 
  7496 000024C4 C605[01C50000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  7497 000024CB E8E0000000          <1> 	CALL	MOTOR_ON		; ENSURE MOTOR STAY ON
  7498 000024D0 B500                <1> 	MOV	CH,0			; LOAD TRACK 0
  7499 000024D2 E8D4010000          <1> 	CALL	SEEK			; SEEK TO TRACK 0
  7500 000024D7 E868000000          <1> 	CALL	READ_ID			; READ ID FUNCTION
  7501 000024DC 7249                <1> 	JC	short SD_ERR		; IF ERROR NO TRACK 0
  7502                              <1> 
  7503                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  7504                              <1> 
  7505 000024DE 66B95004            <1> 	MOV	CX,0450H 		; START, MAX TRACKS
  7506 000024E2 F687[11C50000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  7507 000024E9 7402                <1> 	JZ	short CNT_OK		; IF NOT COUNT IS SETUP
  7508 000024EB B1A0                <1> 	MOV	CL,0A0H			; MAXIMUM TRACK 1.2 MB
  7509                              <1> 
  7510                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  7511                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  7512                              <1> ;	THEN SET DOUBLE STEP ON.
  7513                              <1> 
  7514                              <1> CNT_OK:
  7515 000024ED C605[03C50000]FF    <1>         MOV     byte [MOTOR_COUNT], 0FFH ; ENSURE MOTOR STAYS ON FOR OPERATION 
  7516 000024F4 6651                <1> 	PUSH	CX			; SAVE TRACK, COUNT
  7517 000024F6 C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR STATUS, EXPECT ERRORS
  7518 000024FD 6631C0              <1> 	XOR	AX,AX			; CLEAR AX
  7519 00002500 D0ED                <1> 	SHR	CH,1			; HALVE TRACK, CY = HEAD
  7520 00002502 C0D003              <1> 	RCL	AL,3			; AX = HEAD IN CORRECT BIT
  7521 00002505 6650                <1> 	PUSH	AX			; SAVE HEAD
  7522 00002507 E89F010000          <1> 	CALL	SEEK			; SEEK TO TRACK
  7523 0000250C 6658                <1> 	POP	AX			; RESTORE HEAD
  7524 0000250E 6609C7              <1> 	OR	DI,AX			; DI = HEAD OR'ED DRIVE
  7525 00002511 E82E000000          <1> 	CALL	READ_ID			; READ ID HEAD 0
  7526 00002516 9C                  <1> 	PUSHF				; SAVE RETURN FROM READ_ID
  7527 00002517 6681E7FB00          <1> 	AND	DI,11111011B		; TURN OFF HEAD 1 BIT
  7528 0000251C 9D                  <1> 	POPF				; RESTORE ERROR RETURN
  7529 0000251D 6659                <1> 	POP	CX			; RESTORE COUNT
  7530 0000251F 7308                <1> 	JNC	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  7531 00002521 FEC5                <1> 	INC	CH			; INC FOR NEXT TRACK
  7532 00002523 38CD                <1> 	CMP	CH,CL			; REACHED MAXIMUM YET
  7533 00002525 75C6                <1> 	JNZ	short CNT_OK		; CONTINUE TILL ALL TRIED
  7534                              <1> 
  7535                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  7536                              <1> 
  7537                              <1> SD_ERR:	
  7538 00002527 F9                  <1> 	STC				; SET CARRY FOR ERROR
  7539 00002528 C3                  <1> 	RETn				; SETUP_DBL ERROR EXIT
  7540                              <1> 
  7541                              <1> DO_CHK:
  7542 00002529 8A0D[08C50000]      <1> 	MOV	CL, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  7543 0000252F 888F[15C50000]      <1> 	MOV	[DSK_TRK+eDI], CL	; STORE TRACK NUMBER
  7544 00002535 D0ED                <1> 	SHR	CH,1			; HALVE TRACK
  7545 00002537 38CD                <1> 	CMP	CH,CL			; IS IT THE SAME AS ASKED FOR TRACK
  7546 00002539 7407                <1> 	JZ	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  7547 0000253B 808F[11C50000]20    <1> 	OR	byte [DSK_STATE+eDI],DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  7548                              <1> NO_DBL:
  7549 00002542 F8                  <1> 	CLC				; CLEAR ERROR FLAG
  7550 00002543 C3                  <1> 	RETn
  7551                              <1> 
  7552                              <1> ;-------------------------------------------------------------------------------
  7553                              <1> ; READ_ID
  7554                              <1> ;	READ ID FUNCTION.
  7555                              <1> ;
  7556                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  7557                              <1> ;
  7558                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  7559                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7560                              <1> ;-------------------------------------------------------------------------------
  7561                              <1> READ_ID:
  7562 00002544 B8[61250000]        <1> 	MOV	eAX, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  7563 00002549 50                  <1> 	PUSH	eAX
  7564 0000254A B44A                <1> 	MOV	AH,4AH			; READ ID COMMAND
  7565 0000254C E820010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7566 00002551 6689F8              <1> 	MOV	AX,DI			; DRIVE # TO AH, HEAD 0
  7567 00002554 88C4                <1> 	MOV	AH,AL
  7568 00002556 E816010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7569 0000255B E80BFEFFFF          <1> 	CALL	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  7570 00002560 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  7571                              <1> ER_3:
  7572 00002561 C3                  <1> 	RETn
  7573                              <1> 
  7574                              <1> ;-------------------------------------------------------------------------------
  7575                              <1> ; CMOS_TYPE
  7576                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  7577                              <1> ;
  7578                              <1> ; ON ENTRY:	DI = DRIVE #
  7579                              <1> ;
  7580                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  7581                              <1> ;-------------------------------------------------------------------------------
  7582                              <1> 
  7583                              <1> CMOS_TYPE: ; 11/12/2014
  7584 00002562 8A87[4EBF0000]      <1> mov	al, [eDI+fd0_type]
  7585 00002568 20C0                <1> and 	al, al ; 18/12/2014
  7586 0000256A C3                  <1> retn
  7587                              <1> 
  7588                              <1> ;CMOS_TYPE:
  7589                              <1> ;	MOV	AL, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  7590                              <1> ;	CALL	CMOS_READ		; GET CMOS STATUS
  7591                              <1> ;	TEST	AL,BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  7592                              <1> ;	STC				; SET CY = 1 INDICATING ERROR FOR RETURN
  7593                              <1> ;	JNZ	short BAD_CM		; ERROR IF EITHER BIT ON
  7594                              <1> ;	MOV	AL,CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  7595                              <1> ;	CALL	CMOS_READ		; GET DISKETTE BYTE
  7596                              <1> ;	OR	DI,DI			; SEE WHICH DRIVE IN QUESTION
  7597                              <1> ;	JNZ	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  7598                              <1> ;	ROR	AL,4			; EXCHANGE NIBBLES IF SECOND DRIVE
  7599                              <1> ;TB:
  7600                              <1> ;	AND	AL,0FH			; KEEP ONLY DRIVE DATA, RESET CY, 0
  7601                              <1> ;BAD_CM:
  7602                              <1> ;	RETn				; CY, STATUS OF READ
  7603                              <1> 
  7604                              <1> ;-------------------------------------------------------------------------------
  7605                              <1> ; GET_PARM
  7606                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  7607                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  7608                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  7609                              <1> ;	THE PARAMETER IN DL.
  7610                              <1> ;
  7611                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  7612                              <1> ;
  7613                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  7614                              <1> ;		AL,DH DESTROYED
  7615                              <1> ;-------------------------------------------------------------------------------
  7616                              <1> GET_PARM:
  7617                              <1> 	;PUSH	DS
  7618 0000256B 56                  <1> 	PUSH	eSI
  7619                              <1>     	;SUB	AX,AX			; DS = 0, BIOS DATA AREA
  7620                              <1>     	;MOV	DS,AX
  7621                              <1> 	;;mov	ax, cs
  7622                              <1> 	;;mov	ds, ax
  7623                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  7624 0000256C 87D3                <1> 	XCHG	eDX,eBX			; BL = INDEX
  7625                              <1> 	;SUB	BH,BH			; BX = INDEX
  7626 0000256E 81E3FF000000        <1> 	and	ebx, 0FFh
  7627                              <1>     	;LDS	SI, [DISK_POINTER]	; POINT TO BLOCK
  7628                              <1> 	;
  7629                              <1> 	; 17/12/2014
  7630 00002574 66A1[41BF0000]      <1> 	mov	ax, [cfd] ; current (AL) and previous fd (AH)
  7631 0000257A 38E0                <1> 	cmp	al, ah
  7632 0000257C 7425                <1> 	je	short gpndc
  7633 0000257E A2[42BF0000]        <1> 	mov	[pfd], al ; current drive -> previous drive
  7634 00002583 53                  <1> 	push	ebx ; 08/02/2015
  7635 00002584 88C3                <1> 	mov	bl, al 
  7636                              <1> 	; 11/12/2014
  7637 00002586 8A83[4EBF0000]      <1> 	mov	al, [eBX+fd0_type]	; Drive type (0,1,2,3,4)
  7638                              <1> 	; 18/12/2014
  7639 0000258C 20C0                <1> 	and	al, al
  7640 0000258E 7507                <1> 	jnz	short gpdtc
  7641 00002590 BB[2BBF0000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  7642 00002595 EB05                <1>         jmp     short gpdpu
  7643                              <1> gpdtc:	
  7644 00002597 E817F9FFFF          <1> 	call	DR_TYPE_CHECK
  7645                              <1> 	; cf = 1 -> eBX points to 1.44MB fd parameter table (default)
  7646                              <1> gpdpu:
  7647 0000259C 891D[C8BE0000]      <1> 	mov	[DISK_POINTER], ebx
  7648 000025A2 5B                  <1> 	pop	ebx
  7649                              <1> gpndc:
  7650 000025A3 8B35[C8BE0000]      <1> 	mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  7651 000025A9 8A241E              <1> 	MOV	AH, [eSI+eBX]		; GET THE WORD
  7652 000025AC 87D3                <1> 	XCHG	eDX,eBX			; RESTORE BX
  7653 000025AE 5E                  <1> 	POP	eSI
  7654                              <1> 	;POP	DS
  7655 000025AF C3                  <1> 	RETn
  7656                              <1> 
  7657                              <1> ;-------------------------------------------------------------------------------
  7658                              <1> ; MOTOR_ON
  7659                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  7660                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  7661                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  7662                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  7663                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  7664                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  7665                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  7666                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  7667                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  7668                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  7669                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  7670                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  7671                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  7672                              <1> ;
  7673                              <1> ; ON ENTRY:	DI = DRIVE #
  7674                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  7675                              <1> ;-------------------------------------------------------------------------------
  7676                              <1> MOTOR_ON:
  7677 000025B0 53                  <1> 	PUSH	eBX			; SAVE REG.
  7678 000025B1 E82A000000          <1> 	CALL	TURN_ON			; TURN ON MOTOR
  7679 000025B6 7226                <1> 	JC	short MOT_IS_ON		; IF CY=1 NO WAIT
  7680 000025B8 E89BF9FFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  7681 000025BD E865F9FFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  7682                              <1> 	;CALL	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  7683                              <1> 	;JC	MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  7684                              <1> M_WAIT:
  7685 000025C2 B20A                <1> 	MOV	DL,10			; GET THE MOTOR WAIT PARAMETER
  7686 000025C4 E8A2FFFFFF          <1> 	CALL	GET_PARM
  7687                              <1> 	;MOV	AL,AH			; AL = MOTOR WAIT PARAMETER
  7688                              <1> 	;XOR	AH,AH			; AX = MOTOR WAIT PARAMETER
  7689                              <1> 	;CMP	AL,8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  7690 000025C9 80FC08              <1> 	cmp	ah, 8
  7691                              <1> 	;JAE	short GP2		; IF YES, CONTINUE
  7692 000025CC 7702                <1> 	ja	short J13
  7693                              <1> 	;MOV	AL,8			; ONE SECOND WAIT FOR MOTOR START UP
  7694 000025CE B408                <1> 	mov	ah, 8
  7695                              <1> 
  7696                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  7697                              <1> GP2:	
  7698                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  7699                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  7700 000025D0 B95E200000          <1> 	MOV	eCX,8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  7701 000025D5 E816F3FFFF          <1> 	CALL	WAITF			; GO TO FIXED WAIT ROUTINE
  7702                              <1> 	;DEC	AL			; DECREMENT TIME VALUE
  7703 000025DA FECC                <1> 	dec	ah
  7704 000025DC 75F2                <1> 	JNZ	short J13		; ARE WE DONE YET
  7705                              <1> MOT_IS_ON:
  7706 000025DE 5B                  <1> 	POP	eBX			; RESTORE REG.
  7707 000025DF C3                  <1> 	RETn
  7708                              <1> 
  7709                              <1> ;-------------------------------------------------------------------------------
  7710                              <1> ; TURN_ON
  7711                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  7712                              <1> ;
  7713                              <1> ; ON ENTRY:	DI = DRIVE #
  7714                              <1> ;
  7715                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  7716                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  7717                              <1> ;		AX,BX,CX,DX DESTROYED
  7718                              <1> ;-------------------------------------------------------------------------------
  7719                              <1> TURN_ON:
  7720 000025E0 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7721 000025E2 88D9                <1> 	MOV	CL,BL			; CL = DRIVE #
  7722 000025E4 C0C304              <1> 	ROL	BL,4			; BL = DRIVE SELECT
  7723 000025E7 FA                  <1> 	CLI				; NO INTERRUPTS WHILE DETERMINING STATUS
  7724 000025E8 C605[03C50000]FF    <1> 	MOV	byte [MOTOR_COUNT],0FFH	; ENSURE MOTOR STAYS ON FOR OPERATION
  7725 000025EF A0[02C50000]        <1> 	MOV	AL, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7726 000025F4 2430                <1> 	AND	AL,00110000B		; KEEP ONLY DRIVE SELECT BITS
  7727 000025F6 B401                <1> 	MOV	AH,1			; MASK FOR DETERMINING MOTOR BIT
  7728 000025F8 D2E4                <1> 	SHL	AH,CL			; AH = MOTOR ON, A=00000001, B=00000010
  7729                              <1> 
  7730                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  7731                              <1> ;  BL = DRIVE SELECT DESIRED
  7732                              <1> ;  AH = MOTOR ON MASK DESIRED
  7733                              <1> 
  7734 000025FA 38D8                <1> 	CMP	AL,BL			; REQUESTED DRIVE ALREADY SELECTED ?
  7735 000025FC 7508                <1> 	JNZ	short TURN_IT_ON	; IF NOT SELECTED JUMP
  7736 000025FE 8425[02C50000]      <1> 	TEST	AH, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  7737 00002604 7535                <1> 	JNZ	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  7738                              <1> 
  7739                              <1> TURN_IT_ON:
  7740 00002606 08DC                <1> 	OR	AH,BL			; AH = DRIVE SELECT AND MOTOR ON
  7741 00002608 8A3D[02C50000]      <1> 	MOV	BH,[MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  7742 0000260E 80E70F              <1> 	AND	BH,00001111B		; KEEP ONLY MOTOR BITS
  7743 00002611 8025[02C50000]CF    <1> 	AND	byte [MOTOR_STATUS],11001111B ; CLEAR OUT DRIVE SELECT
  7744 00002618 0825[02C50000]      <1> 	OR	[MOTOR_STATUS],AH	; OR IN DRIVE SELECTED AND MOTOR ON
  7745 0000261E A0[02C50000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7746 00002623 88C3                <1> 	MOV	BL,AL			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  7747 00002625 80E30F              <1> 	AND	BL,00001111B		; KEEP ONLY MOTOR BITS
  7748 00002628 FB                  <1> 	STI				; ENABLE INTERRUPTS AGAIN
  7749 00002629 243F                <1> 	AND	AL,00111111B		; STRIP AWAY UNWANTED BITS
  7750 0000262B C0C004              <1> 	ROL	AL,4			; PUT BITS IN DESIRED POSITIONS
  7751 0000262E 0C0C                <1> 	OR	AL,00001100B		; NO RESET, ENABLE DMA/INTERRUPT
  7752 00002630 66BAF203            <1> 	MOV	DX,03F2H		; SELECT DRIVE AND TURN ON MOTOR
  7753 00002634 EE                  <1> 	OUT	DX,AL
  7754 00002635 38FB                <1> 	CMP	BL,BH			; NEW MOTOR TURNED ON ?
  7755                              <1> 	;JZ	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  7756 00002637 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  7757 00002639 F8                  <1> 	CLC				; (re)SET CARRY MEANING WAIT
  7758 0000263A C3                  <1> 	RETn
  7759                              <1> 
  7760                              <1> NO_MOT_WAIT:
  7761 0000263B FB                  <1> 	sti
  7762                              <1> no_mot_w1: ; 27/02/2015
  7763 0000263C F9                  <1> 	STC				; SET NO WAIT REQUIRED
  7764                              <1> 	;STI				; INTERRUPTS BACK ON
  7765 0000263D C3                  <1> 	RETn
  7766                              <1> 
  7767                              <1> ;-------------------------------------------------------------------------------
  7768                              <1> ; HD_WAIT
  7769                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  7770                              <1> ;
  7771                              <1> ; ON ENTRY:	DI = DRIVE #
  7772                              <1> ;
  7773                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  7774                              <1> ;-------------------------------------------------------------------------------
  7775                              <1> HD_WAIT:
  7776 0000263E B209                <1> 	MOV	DL,9			; GET HEAD SETTLE PARAMETER
  7777 00002640 E826FFFFFF          <1> 	CALL	GET_PARM
  7778 00002645 08E4                <1> 	or	ah, ah	; 17/12/2014
  7779 00002647 7519                <1> 	jnz	short DO_WAT
  7780 00002649 F605[02C50000]80    <1>         TEST    byte [MOTOR_STATUS],10000000B ; SEE IF A WRITE OPERATION
  7781                              <1> 	;JZ	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  7782                              <1> 	;OR	AH,AH			; CHECK FOR ANY WAIT?
  7783                              <1> 	;JNZ	short DO_WAT		; IF THERE DO NOT ENFORCE
  7784 00002650 741E                <1> 	jz	short HW_DONE
  7785 00002652 B40F                <1> 	MOV	AH,HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  7786 00002654 8A87[11C50000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7787 0000265A 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7788 0000265C 3C80                <1> 	CMP	AL,RATE_250		; 1.2 M DRIVE ?
  7789 0000265E 7502                <1> 	JNZ	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  7790                              <1> ;GP3:
  7791 00002660 B414                <1> 	MOV	AH,HD320_SETTLE		; USE 320/360 HEAD SETTLE
  7792                              <1> ;	JMP	SHORT DO_WAT
  7793                              <1> 
  7794                              <1> ;ISNT_WRITE:
  7795                              <1> ;	OR	AH,AH			; CHECK FOR NO WAIT
  7796                              <1> ;	JZ	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  7797                              <1> 
  7798                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  7799                              <1> DO_WAT:
  7800                              <1> ;	MOV	AL,AH			; AL = # MILLISECONDS
  7801                              <1> ;	;XOR	AH,AH			; AX = # MILLISECONDS
  7802                              <1> J29:					; 	1 MILLISECOND LOOP
  7803                              <1> 	;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  7804 00002662 B942000000          <1> 	MOV	eCX,66			; COUNT AT 15.085737 US PER COUNT
  7805 00002667 E884F2FFFF          <1> 	CALL	WAITF			; DELAY FOR 1 MILLISECOND
  7806                              <1> 	;DEC	AL			; DECREMENT THE COUNT
  7807 0000266C FECC                <1> 	dec	ah
  7808 0000266E 75F2                <1> 	JNZ	short J29		; DO AL MILLISECOND # OF TIMES
  7809                              <1> HW_DONE:
  7810 00002670 C3                  <1> 	RETn
  7811                              <1> 
  7812                              <1> ;-------------------------------------------------------------------------------
  7813                              <1> ; NEC_OUTPUT
  7814                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  7815                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  7816                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  7817                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  7818                              <1> ; 
  7819                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  7820                              <1> ;
  7821                              <1> ; ON EXIT:	CY = 0  SUCCESS
  7822                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  7823                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  7824                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  7825                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  7826                              <1> ;		AX,CX,DX DESTROYED
  7827                              <1> ;-------------------------------------------------------------------------------
  7828                              <1> 
  7829                              <1> ; 09/12/2014 [Erdogan Tan] 
  7830                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  7831                              <1> ; Diskette Drive Controller Status Register (3F4h)
  7832                              <1> ;	This read only register facilitates the transfer of data between
  7833                              <1> ;	the system microprocessor and the controller.
  7834                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  7835                              <1> ;	  with the system micrprocessor.
  7836                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  7837                              <1> ;	  the transfer is to the controller.
  7838                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  7839                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  7840                              <1> ; Bit 3 - Reserved.
  7841                              <1> ; Bit 2 - Reserved.
  7842                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7843                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7844                              <1> 
  7845                              <1> ; Data Register (3F5h)
  7846                              <1> ; This read/write register passes data, commands and parameters, and provides
  7847                              <1> ; diskette status information.
  7848                              <1>   		
  7849                              <1> NEC_OUTPUT:
  7850                              <1> 	;PUSH	BX			; SAVE REG.
  7851 00002671 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  7852                              <1> 	;MOV	BL,2			; HIGH ORDER COUNTER
  7853                              <1> 	;XOR	CX,CX			; COUNT FOR TIME OUT
  7854                              <1> 	; 16/12/2014
  7855                              <1> 	; waiting for (max.) 0.5 seconds
  7856                              <1>         ;;mov     byte [wait_count], 0 ;; 27/02/2015
  7857                              <1> 	;
  7858                              <1> 	; 17/12/2014
  7859                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  7860                              <1> 	;
  7861                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  7862                              <1> 	;		go on.
  7863                              <1> 	;INPUT:
  7864                              <1> 	;	AH=Mask for isolation bits.
  7865                              <1> 	;	AL=pattern to look for.
  7866                              <1> 	;	DX=Port to test for
  7867                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  7868                              <1> 	;	     (normally 30 microseconds per period.)
  7869                              <1> 	;
  7870                              <1> 	;WFP_SHORT:  
  7871                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  7872                              <1> 	;
  7873                              <1> 
  7874                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  7875                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  7876 00002675 B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  7877                              <1> ;
  7878                              <1> ;WFPS_OUTER_LP:
  7879                              <1> ;	;
  7880                              <1> ;WFPS_CHECK_PORT:
  7881                              <1> J23:
  7882 0000267A EC                  <1> 	IN	AL,DX			; GET STATUS
  7883 0000267B 24C0                <1> 	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7884 0000267D 3C80                <1> 	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7885 0000267F 7418                <1> 	JZ	short J27		; STATUS AND DIRECTION OK
  7886                              <1> WFPS_HI:
  7887 00002681 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  7888 00002683 A810                <1> 	TEST	AL,010H			; transition on memory
  7889 00002685 75FA                <1> 	JNZ	SHORT WFPS_HI		; refresh.
  7890                              <1> WFPS_LO:
  7891 00002687 E461                <1> 	IN	AL, PORT_B		; SYS1
  7892 00002689 A810                <1> 	TEST	AL,010H
  7893 0000268B 74FA                <1> 	JZ	SHORT WFPS_LO
  7894                              <1> 	;LOOP	SHORT WFPS_CHECK_PORT
  7895 0000268D E2EB                <1> 	loop	J23	; 27/02/2015
  7896                              <1> ;	;
  7897                              <1> ;	dec	bl
  7898                              <1> ;	jnz	short WFPS_OUTER_LP
  7899                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  7900                              <1> ;J23:
  7901                              <1> ;	IN	AL,DX			; GET STATUS
  7902                              <1> ;	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7903                              <1> ;	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7904                              <1> ;	JZ	short J27		; STATUS AND DIRECTION OK
  7905                              <1> 	;LOOP	J23			; CONTINUE TILL CX EXHAUSTED
  7906                              <1> 	;DEC	BL			; DECREMENT COUNTER
  7907                              <1> 	;JNZ	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  7908                              <1>    
  7909                              <1> 	;;27/02/2015
  7910                              <1> 	;16/12/2014
  7911                              <1>         ;;cmp     byte [wait_count], 10   ; (10/18.2 seconds)
  7912                              <1> 	;;jb	short J23
  7913                              <1> 
  7914                              <1> ;WFPS_TIMEOUT:
  7915                              <1> 
  7916                              <1> ;-----	FALL THRU TO ERROR RETURN
  7917                              <1> 
  7918 0000268F 800D[04C50000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  7919                              <1> 	;POP	BX			; RESTORE REG.
  7920 00002696 58                  <1> 	POP	eAX ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  7921 00002697 F9                  <1> 	STC				; INDICATE ERROR TO CALLER
  7922 00002698 C3                  <1> 	RETn
  7923                              <1> 
  7924                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  7925                              <1> 
  7926                              <1> J27:	
  7927 00002699 88E0                <1> 	MOV	AL,AH			; GET BYTE TO OUTPUT
  7928 0000269B 6642                <1> 	INC	DX			; DATA PORT = STATUS PORT + 1
  7929 0000269D EE                  <1> 	OUT	DX,AL			; OUTPUT THE BYTE
  7930                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  7931                              <1> 	; 27/02/2015
  7932 0000269E 9C                  <1> 	PUSHF				; SAVE FLAGS
  7933 0000269F B903000000          <1> 	MOV	eCX, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  7934 000026A4 E847F2FFFF          <1> 	CALL 	WAITF			; NEC FLAGS UPDATE CYCLE
  7935 000026A9 9D                  <1> 	POPF				; RESTORE FLAGS FOR EXIT
  7936                              <1> 	;POP	BX			; RESTORE REG
  7937 000026AA C3                  <1> 	RETn				; CY = 0 FROM TEST INSTRUCTION
  7938                              <1> 
  7939                              <1> ;-------------------------------------------------------------------------------
  7940                              <1> ; SEEK
  7941                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  7942                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  7943                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  7944                              <1> ;
  7945                              <1> ; ON ENTRY:	DI = DRIVE #
  7946                              <1> ;		CH = TRACK #
  7947                              <1> ;
  7948                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  7949                              <1> ;		AX,BX,CX DX DESTROYED
  7950                              <1> ;-------------------------------------------------------------------------------
  7951                              <1> SEEK:
  7952 000026AB 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7953 000026AD B001                <1> 	MOV	AL,1			; ESTABLISH MASK FOR RECALIBRATE TEST
  7954 000026AF 86CB                <1> 	XCHG	CL,BL			; SET DRIVE VALULE INTO CL
  7955 000026B1 D2C0                <1> 	ROL	AL,CL			; SHIFT MASK BY THE DRIVE VALUE
  7956 000026B3 86CB                <1> 	XCHG	CL,BL			; RECOVER TRACK VALUE
  7957 000026B5 8405[01C50000]      <1> 	TEST	AL,[SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  7958 000026BB 7526                <1> 	JNZ	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  7959                              <1> 
  7960 000026BD 0805[01C50000]      <1> 	OR	[SEEK_STATUS],AL	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  7961 000026C3 E862000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7962 000026C8 730E                <1> 	JNC	short AFT_RECAL		; RECALIBRATE DONE
  7963                              <1> 
  7964                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  7965                              <1> 
  7966 000026CA C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR OUT INVALID STATUS
  7967 000026D1 E854000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7968 000026D6 7251                <1> 	JC	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  7969                              <1> 
  7970                              <1> AFT_RECAL:
  7971 000026D8 C687[15C50000]00    <1>         MOV     byte [DSK_TRK+eDI],0    ; SAVE NEW CYLINDER AS PRESENT POSITION
  7972 000026DF 08ED                <1> 	OR	CH,CH			; CHECK FOR SEEK TO TRACK 0
  7973 000026E1 743F                <1> 	JZ	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  7974                              <1> 
  7975                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  7976                              <1> 
  7977 000026E3 F687[11C50000]20    <1> J28A:	TEST	byte [DSK_STATE+eDI],DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  7978 000026EA 7402                <1> 	JZ	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  7979 000026EC D0E5                <1> 	SHL	CH,1			; DOUBLE NUMBER OF STEP TO TAKE
  7980                              <1> 
  7981 000026EE 3AAF[15C50000]      <1> _R7:	CMP	CH, [DSK_TRK+eDI]	; SEE IF ALREADY AT THE DESIRED TRACK
  7982 000026F4 7433                <1> 	JE	short RB		; IF YES, DO NOT NEED TO SEEK
  7983                              <1> 
  7984 000026F6 BA[29270000]        <1> 	MOV	eDX, NEC_ERR		; LOAD RETURN ADDRESS
  7985 000026FB 52                  <1> 	PUSH	eDX ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  7986 000026FC 88AF[15C50000]      <1> 	MOV	[DSK_TRK+eDI],CH	; SAVE NEW CYLINDER AS PRESENT POSITION
  7987 00002702 B40F                <1> 	MOV	AH,0FH			; SEEK COMMAND TO NEC
  7988 00002704 E868FFFFFF          <1> 	CALL	NEC_OUTPUT
  7989 00002709 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7990 0000270B 88DC                <1> 	MOV	AH,BL			; OUTPUT DRIVE NUMBER
  7991 0000270D E85FFFFFFF          <1> 	CALL	NEC_OUTPUT
  7992 00002712 8AA7[15C50000]      <1> 	MOV	AH, [DSK_TRK+eDI]	; GET CYLINDER NUMBER
  7993 00002718 E854FFFFFF          <1> 	CALL	NEC_OUTPUT
  7994 0000271D E829000000          <1> 	CALL	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  7995                              <1> 
  7996                              <1> ;-----	WAIT FOR HEAD SETTLE
  7997                              <1> 
  7998                              <1> DO_WAIT:
  7999 00002722 9C                  <1> 	PUSHF				; SAVE STATUS
  8000 00002723 E816FFFFFF          <1> 	CALL	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  8001 00002728 9D                  <1> 	POPF				; RESTORE STATUS
  8002                              <1> RB:
  8003                              <1> NEC_ERR:
  8004                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  8005                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  8006 00002729 C3                  <1> 	RETn				; RETURN TO CALLER
  8007                              <1> 
  8008                              <1> ;-------------------------------------------------------------------------------
  8009                              <1> ; RECAL
  8010                              <1> ;	RECALIBRATE DRIVE
  8011                              <1> ;
  8012                              <1> ; ON ENTRY:	DI = DRIVE #
  8013                              <1> ;
  8014                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  8015                              <1> ;-------------------------------------------------------------------------------
  8016                              <1> RECAL:
  8017 0000272A 6651                <1> 	PUSH	CX
  8018 0000272C B8[48270000]        <1> 	MOV	eAX, RC_BACK		; LOAD NEC_OUTPUT ERROR
  8019 00002731 50                  <1> 	PUSH	eAX
  8020 00002732 B407                <1> 	MOV	AH,07H			; RECALIBRATE COMMAND
  8021 00002734 E838FFFFFF          <1> 	CALL	NEC_OUTPUT
  8022 00002739 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  8023 0000273B 88DC                <1> 	MOV	AH,BL
  8024 0000273D E82FFFFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  8025 00002742 E804000000          <1> 	CALL	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  8026 00002747 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  8027                              <1> RC_BACK:
  8028 00002748 6659                <1> 	POP	CX
  8029 0000274A C3                  <1> 	RETn
  8030                              <1> 
  8031                              <1> ;-------------------------------------------------------------------------------
  8032                              <1> ; CHK_STAT_2
  8033                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  8034                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  8035                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  8036                              <1> ;
  8037                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8038                              <1> ;-------------------------------------------------------------------------------
  8039                              <1> CHK_STAT_2:
  8040 0000274B B8[73270000]        <1>         MOV     eAX, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  8041 00002750 50                  <1> 	PUSH	eAX
  8042 00002751 E828000000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  8043 00002756 721A                <1> 	JC	short J34		; IF ERROR, RETURN IT
  8044 00002758 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  8045 0000275A E812FFFFFF          <1> 	CALL	NEC_OUTPUT
  8046 0000275F E84A000000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  8047 00002764 720C                <1> 	JC	short J34
  8048 00002766 A0[05C50000]        <1> 	MOV	AL,[NEC_STATUS]		; GET THE FIRST STATUS BYTE
  8049 0000276B 2460                <1> 	AND	AL,01100000B		; ISOLATE THE BITS
  8050 0000276D 3C60                <1> 	CMP	AL,01100000B		; TEST FOR CORRECT VALUE
  8051 0000276F 7403                <1> 	JZ	short J35		; IF ERROR, GO MARK IT
  8052 00002771 F8                  <1> 	CLC				; GOOD RETURN
  8053                              <1> J34:
  8054 00002772 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  8055                              <1> CS_BACK:
  8056 00002773 C3                  <1> 	RETn
  8057                              <1> J35:
  8058 00002774 800D[04C50000]40    <1> 	OR	byte [DSKETTE_STATUS], BAD_SEEK
  8059 0000277B F9                  <1> 	STC				; ERROR RETURN CODE
  8060 0000277C EBF4                <1> 	JMP	SHORT J34
  8061                              <1> 
  8062                              <1> ;-------------------------------------------------------------------------------
  8063                              <1> ; WAIT_INT
  8064                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  8065                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  8066                              <1> ;	IF THE DRIVE IS NOT READY.
  8067                              <1> ;
  8068                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8069                              <1> ;-------------------------------------------------------------------------------
  8070                              <1> 
  8071                              <1> ; 17/12/2014
  8072                              <1> ; 2.5 seconds waiting !
  8073                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  8074                              <1> ; amount of time to wait for completion interrupt from NEC.
  8075                              <1> 
  8076                              <1> 
  8077                              <1> WAIT_INT:
  8078 0000277E FB                  <1> 	STI				; TURN ON INTERRUPTS, JUST IN CASE
  8079 0000277F F8                  <1> 	CLC				; CLEAR TIMEOUT INDICATOR
  8080                              <1>        ;MOV	BL,10			; CLEAR THE COUNTERS
  8081                              <1>        ;XOR	CX,CX			; FOR 2 SECOND WAIT
  8082                              <1> 
  8083                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  8084                              <1> 	;
  8085                              <1> 	;WAIT_FOR_MEM:	
  8086                              <1> 	;	Waits for a bit at a specified memory location pointed
  8087                              <1> 	;	to by ES:[DI] to become set.
  8088                              <1> 	;INPUT:
  8089                              <1> 	;	AH=Mask to test with.
  8090                              <1> 	;	ES:[DI] = memory location to watch.
  8091                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  8092                              <1> 	;	     (normally 30 microseconds per period.)
  8093                              <1> 
  8094                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  8095                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  8096                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  8097                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  8098                              <1> 	; 27/02/2015
  8099 00002780 B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  8100                              <1> WFMS_CHECK_MEM:
  8101 00002785 F605[01C50000]80    <1> 	test	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8102 0000278C 7516                <1>         jnz     short J37
  8103                              <1> WFMS_HI:
  8104 0000278E E461                <1> 	IN	AL,PORT_B  ; 061h	; SYS1, wait for lo to hi
  8105 00002790 A810                <1> 	TEST	AL,010H			; transition on memory
  8106 00002792 75FA                <1> 	JNZ	SHORT WFMS_HI		; refresh.
  8107                              <1> WFMS_LO:
  8108 00002794 E461                <1> 	IN	AL,PORT_B		;SYS1
  8109 00002796 A810                <1> 	TEST	AL,010H
  8110 00002798 74FA                <1> 	JZ	SHORT WFMS_LO
  8111 0000279A E2E9                <1>         LOOP    WFMS_CHECK_MEM
  8112                              <1> ;WFMS_OUTER_LP:
  8113                              <1> ;;	or	bl, bl			; check outer counter
  8114                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  8115                              <1> ;	dec	bl
  8116                              <1> ;	jz	short J36A	
  8117                              <1> ;	jmp	short WFMS_CHECK_MEM
  8118                              <1> 
  8119                              <1> 	;17/12/2014
  8120                              <1> 	;16/12/2014
  8121                              <1> ;        mov     byte [wait_count], 0    ; Reset (INT 08H) counter
  8122                              <1> ;J36:
  8123                              <1> ;	TEST	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8124                              <1> ;	JNZ	short J37
  8125                              <1> 	;16/12/2014
  8126                              <1> 	;LOOP	J36			; COUNT DOWN WHILE WAITING
  8127                              <1> 	;DEC	BL			; SECOND LEVEL COUNTER
  8128                              <1> 	;JNZ	short J36
  8129                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  8130                              <1> ;	jb	short J36
  8131                              <1> 
  8132                              <1> ;WFMS_TIMEOUT:
  8133                              <1> ;J36A:
  8134 0000279C 800D[04C50000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  8135 000027A3 F9                  <1> 	STC				; ERROR RETURN
  8136                              <1> J37:
  8137 000027A4 9C                  <1> 	PUSHF				; SAVE CURRENT CARRY
  8138 000027A5 8025[01C50000]7F    <1> 	AND	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  8139 000027AC 9D                  <1> 	POPF				; RECOVER CARRY
  8140 000027AD C3                  <1> 	RETn				; GOOD RETURN CODE
  8141                              <1> 
  8142                              <1> ;-------------------------------------------------------------------------------
  8143                              <1> ; RESULTS
  8144                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  8145                              <1> ;	FOLLOWING AN INTERRUPT.
  8146                              <1> ;
  8147                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8148                              <1> ;		AX,BX,CX,DX DESTROYED
  8149                              <1> ;-------------------------------------------------------------------------------
  8150                              <1> RESULTS:
  8151 000027AE 57                  <1> 	PUSH	eDI
  8152 000027AF BF[05C50000]        <1> 	MOV	eDI, NEC_STATUS		; POINTER TO DATA AREA
  8153 000027B4 B307                <1> 	MOV	BL,7			; MAX STATUS BYTES
  8154 000027B6 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  8155                              <1> 
  8156                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  8157                              <1> 
  8158                              <1> _R10: 
  8159                              <1> 	; 16/12/2014
  8160                              <1> 	; wait for (max) 0.5 seconds
  8161                              <1> 	;MOV	BH,2			; HIGH ORDER COUNTER
  8162                              <1> 	;XOR	CX,CX			; COUNTER
  8163                              <1> 
  8164                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  8165                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  8166                              <1> 	; 27/02/2015
  8167 000027BA B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  8168                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  8169                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  8170                              <1> 
  8171                              <1> WFPSR_OUTER_LP:
  8172                              <1> 	;
  8173                              <1> WFPSR_CHECK_PORT:
  8174                              <1> J39:					; WAIT FOR MASTER
  8175 000027BF EC                  <1> 	IN	AL,DX			; GET STATUS
  8176 000027C0 24C0                <1> 	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8177 000027C2 3CC0                <1> 	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8178 000027C4 7418                <1> 	JZ	short J42		; STATUS AND DIRECTION OK
  8179                              <1> WFPSR_HI:
  8180 000027C6 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  8181 000027C8 A810                <1> 	TEST	AL,010H			; transition on memory
  8182 000027CA 75FA                <1> 	JNZ	SHORT WFPSR_HI		; refresh.
  8183                              <1> WFPSR_LO:
  8184 000027CC E461                <1> 	IN	AL, PORT_B		; SYS1
  8185 000027CE A810                <1> 	TEST	AL,010H
  8186 000027D0 74FA                <1> 	JZ	SHORT WFPSR_LO
  8187 000027D2 E2EB                <1>         LOOP    WFPSR_CHECK_PORT
  8188                              <1> 	;; 27/02/2015
  8189                              <1> 	;;dec	bh
  8190                              <1> 	;;jnz	short WFPSR_OUTER_LP
  8191                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  8192                              <1> 
  8193                              <1> 	;;mov	byte [wait_count], 0
  8194                              <1> ;J39:					; WAIT FOR MASTER
  8195                              <1> ;	IN	AL,DX			; GET STATUS
  8196                              <1> ;	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8197                              <1> ;	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8198                              <1> ;	JZ	short J42		; STATUS AND DIRECTION OK
  8199                              <1> 	;LOOP	J39			; LOOP TILL TIMEOUT
  8200                              <1> 	;DEC	BH			; DECREMENT HIGH ORDER COUNTER
  8201                              <1> 	;JNZ	short J39		; REPEAT TILL DELAY DONE
  8202                              <1> 	;
  8203                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  8204                              <1> 	;;jb	short J39	
  8205                              <1> 
  8206                              <1> ;WFPSR_TIMEOUT:
  8207 000027D4 800D[04C50000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  8208 000027DB F9                  <1> 	STC				; SET ERROR RETURN
  8209 000027DC EB29                <1> 	JMP	SHORT POPRES		; POP REGISTERS AND RETURN
  8210                              <1> 
  8211                              <1> ;-----	READ IN THE STATUS
  8212                              <1> 
  8213                              <1> J42:
  8214 000027DE EB00                <1> 	JMP	$+2			; I/O DELAY
  8215 000027E0 6642                <1> 	INC	DX			; POINT AT DATA PORT
  8216 000027E2 EC                  <1> 	IN	AL,DX			; GET THE DATA
  8217                              <1> 	; 16/12/2014
  8218                              <1> 	NEWIODELAY
  8219 000027E3 E6EB                <2>  out 0ebh,al
  8220 000027E5 8807                <1>         MOV     [eDI],AL                ; STORE THE BYTE
  8221 000027E7 47                  <1> 	INC	eDI			; INCREMENT THE POINTER
  8222                              <1> 	; 16/12/2014
  8223                              <1> ;	push	cx
  8224                              <1> ;	mov	cx, 30
  8225                              <1> ;wdw2:
  8226                              <1> ;	NEWIODELAY
  8227                              <1> ;	loop	wdw2
  8228                              <1> ;	pop	cx
  8229                              <1> 
  8230 000027E8 B903000000          <1> 	MOV	eCX,3			; MINIMUM 24 MICROSECONDS FOR NEC
  8231 000027ED E8FEF0FFFF          <1> 	CALL	WAITF			; WAIT 30 TO 45 MICROSECONDS
  8232 000027F2 664A                <1> 	DEC	DX			; POINT AT STATUS PORT
  8233 000027F4 EC                  <1> 	IN	AL,DX			; GET STATUS
  8234                              <1> 	; 16/12/2014
  8235                              <1> 	NEWIODELAY
  8236 000027F5 E6EB                <2>  out 0ebh,al
  8237                              <1> 	;
  8238 000027F7 A810                <1> 	TEST	AL,00010000B		; TEST FOR NEC STILL BUSY
  8239 000027F9 740C                <1> 	JZ	short POPRES		; RESULTS DONE ?
  8240                              <1> 
  8241 000027FB FECB                <1> 	DEC	BL			; DECREMENT THE STATUS COUNTER
  8242 000027FD 75BB                <1>         JNZ     short _R10              ; GO BACK FOR MORE
  8243 000027FF 800D[04C50000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; TOO MANY STATUS BYTES
  8244 00002806 F9                  <1> 	STC				; SET ERROR FLAG
  8245                              <1> 
  8246                              <1> ;-----	RESULT OPERATION IS DONE
  8247                              <1> POPRES:
  8248 00002807 5F                  <1> 	POP	eDI
  8249 00002808 C3                  <1> 	RETn				; RETURN WITH CARRY SET
  8250                              <1> 
  8251                              <1> ;-------------------------------------------------------------------------------
  8252                              <1> ; READ_DSKCHNG
  8253                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  8254                              <1> ;
  8255                              <1> ; ON ENTRY:	DI = DRIVE #
  8256                              <1> ;
  8257                              <1> ; ON EXIT:	DI = DRIVE #
  8258                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  8259                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  8260                              <1> ;		AX,CX,DX DESTROYED
  8261                              <1> ;-------------------------------------------------------------------------------
  8262                              <1> READ_DSKCHNG:
  8263 00002809 E8A2FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  8264 0000280E 66BAF703            <1> 	MOV	DX,03F7H		; ADDRESS DIGITAL INPUT REGISTER
  8265 00002812 EC                  <1> 	IN	AL,DX			; INPUT DIGITAL INPUT REGISTER
  8266 00002813 A880                <1> 	TEST	AL,DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  8267 00002815 C3                  <1> 	RETn				; RETURN TO CALLER WITH ZERO FLAG SET
  8268                              <1> 
  8269                              <1> ;-------------------------------------------------------------------------------
  8270                              <1> ; DRIVE_DET
  8271                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  8272                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  8273                              <1> ; ON ENTRY:	DI = DRIVE #
  8274                              <1> ;-------------------------------------------------------------------------------
  8275                              <1> DRIVE_DET:
  8276 00002816 E895FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  8277 0000281B E80AFFFFFF          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  8278 00002820 7251                <1> 	JC	short DD_BAC		; ASSUME NO DRIVE PRESENT
  8279 00002822 B530                <1> 	MOV	CH,TRK_SLAP		; SEEK TO TRACK 48
  8280 00002824 E882FEFFFF          <1> 	CALL	SEEK
  8281 00002829 7248                <1> 	JC	short DD_BAC		; ERROR NO DRIVE
  8282 0000282B B50B                <1> 	MOV	CH,QUIET_SEEK+1		; SEEK TO TRACK 10
  8283                              <1> SK_GIN:
  8284 0000282D FECD                <1> 	DEC	CH			; DECREMENT TO NEXT TRACK
  8285 0000282F 6651                <1> 	PUSH	CX			; SAVE TRACK
  8286 00002831 E875FEFFFF          <1> 	CALL	SEEK
  8287 00002836 723C                <1> 	JC	short POP_BAC		; POP AND RETURN
  8288 00002838 B8[74280000]        <1> 	MOV	eAX, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  8289 0000283D 50                  <1> 	PUSH	eAX
  8290 0000283E B404                <1> 	MOV	AH,SENSE_DRV_ST		; SENSE DRIVE STATUS COMMAND BYTE
  8291 00002840 E82CFEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8292 00002845 6689F8              <1> 	MOV	AX,DI			; AL = DRIVE
  8293 00002848 88C4                <1> 	MOV	AH,AL			; AH = DRIVE
  8294 0000284A E822FEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8295 0000284F E85AFFFFFF          <1> 	CALL	RESULTS			; GO GET STATUS
  8296 00002854 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  8297 00002855 6659                <1> 	POP	CX			; RESTORE TRACK
  8298 00002857 F605[05C50000]10    <1> 	TEST	byte [NEC_STATUS], HOME	; TRACK 0 ?
  8299 0000285E 74CD                <1> 	JZ	short SK_GIN		; GO TILL TRACK 0
  8300 00002860 08ED                <1> 	OR	CH,CH			; IS HOME AT TRACK 0
  8301 00002862 7408                <1> 	JZ	short IS_80		; MUST BE 80 TRACK DRIVE
  8302                              <1> 
  8303                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  8304                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  8305                              <1> 
  8306 00002864 808F[11C50000]94    <1> 	OR	byte [DSK_STATE+eDI], DRV_DET+MED_DET+RATE_250
  8307 0000286B C3                  <1> 	RETn				; ALL INFORMATION SET
  8308                              <1> IS_80:
  8309 0000286C 808F[11C50000]01    <1> 	OR	byte [DSK_STATE+eDI], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  8310                              <1> DD_BAC:
  8311 00002873 C3                  <1> 	RETn
  8312                              <1> POP_BAC:
  8313 00002874 6659                <1> 	POP	CX			; THROW AWAY
  8314 00002876 C3                  <1> 	RETn
  8315                              <1> 
  8316                              <1> fdc_int:  
  8317                              <1> 	  ; 30/07/2015	
  8318                              <1> 	  ; 16/02/2015
  8319                              <1> ;int_0Eh: ; 11/12/2014
  8320                              <1> 
  8321                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL  6 ) --------------------------------------
  8322                              <1> ; DISK_INT
  8323                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  8324                              <1> ;
  8325                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  8326                              <1> ;-------------------------------------------------------------------------------
  8327                              <1> DISK_INT_1:
  8328                              <1> 
  8329 00002877 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER
  8330 00002879 1E                  <1> 	push	ds
  8331 0000287A 66B81000            <1> 	mov	ax, KDATA
  8332 0000287E 8ED8                <1> 	mov 	ds, ax
  8333 00002880 800D[01C50000]80    <1>         OR      byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  8334 00002887 B020                <1> 	MOV     AL,EOI                  ; END OF INTERRUPT MARKER
  8335 00002889 E620                <1> 	OUT	INTA00,AL		; INTERRUPT CONTROL PORT
  8336 0000288B 1F                  <1> 	pop	ds
  8337 0000288C 6658                <1> 	POP	AX			; RECOVER REGISTER
  8338 0000288E CF                  <1> 	IRET				; RETURN FROM INTERRUPT
  8339                              <1> 
  8340                              <1> ;-------------------------------------------------------------------------------
  8341                              <1> ; DSKETTE_SETUP
  8342                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  8343                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  8344                              <1> ;-------------------------------------------------------------------------------
  8345                              <1> DSKETTE_SETUP:
  8346                              <1> 	;PUSH	AX			; SAVE REGISTERS
  8347                              <1> 	;PUSH	BX
  8348                              <1> 	;PUSH	CX
  8349 0000288F 52                  <1> 	PUSH	eDX
  8350                              <1> 	;PUSH	DI
  8351                              <1> 	;;PUSH	DS
  8352                              <1> 	; 14/12/2014
  8353                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  8354                              <1> 	;mov	[DISK_POINTER+2], cs
  8355                              <1> 	;
  8356                              <1> 	;OR	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  8357 00002890 31FF                <1> 	XOR	eDI,eDI			; INITIALIZE DRIVE POINTER
  8358 00002892 66C705[11C50000]00- <1> 	MOV	WORD [DSK_STATE],0	; INITIALIZE STATES
  8359 0000289A 00                  <1>
  8360 0000289B 8025[0CC50000]33    <1> 	AND	byte [LASTRATE],~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  8361 000028A2 800D[0CC50000]C0    <1> 	OR	byte [LASTRATE],SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  8362 000028A9 C605[01C50000]00    <1> 	MOV	byte [SEEK_STATUS],0	; INDICATE RECALIBRATE NEEDED
  8363 000028B0 C605[03C50000]00    <1> 	MOV	byte [MOTOR_COUNT],0	; INITIALIZE MOTOR COUNT
  8364 000028B7 C605[02C50000]00    <1> 	MOV	byte [MOTOR_STATUS],0	; INITIALIZE DRIVES TO OFF STATE
  8365 000028BE C605[04C50000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; NO ERRORS
  8366                              <1> 	;
  8367                              <1> 	; 28/02/2015
  8368                              <1> 	;mov	word [cfd], 100h 
  8369 000028C5 E85FF2FFFF          <1> 	call	DSK_RESET
  8370 000028CA 5A                  <1> 	pop	edx
  8371 000028CB C3                  <1> 	retn
  8372                              <1> 
  8373                              <1> ;SUP0:
  8374                              <1> ;	CALL	DRIVE_DET		; DETERMINE DRIVE
  8375                              <1> ;	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  8376                              <1> ;	; 02/01/2015
  8377                              <1> ;	;INC	DI			; POINT TO NEXT DRIVE
  8378                              <1> ;	;CMP	DI,MAX_DRV		; SEE IF DONE
  8379                              <1> ;	;JNZ	short SUP0		; REPEAT FOR EACH ORIVE
  8380                              <1> ;       cmp     byte [fd1_type], 0	
  8381                              <1> ;	jna	short sup1
  8382                              <1> ;	or	di, di
  8383                              <1> ;	jnz	short sup1
  8384                              <1> ;	inc	di
  8385                              <1> ;       jmp     short SUP0
  8386                              <1> ;sup1:
  8387                              <1> ;	MOV	byte [SEEK_STATUS],0	; FORCE RECALIBRATE
  8388                              <1> ;	;AND	byte [RTC_WAIT_FLAG],0FEH ; ALLOW FOR RTC WAIT
  8389                              <1> ;	CALL	SETUP_END		; VARIOUS CLEANUPS
  8390                              <1> ;	;;POP	DS			; RESTORE CALLERS REGISTERS
  8391                              <1> ;	;POP	DI
  8392                              <1> ;	POP	eDX
  8393                              <1> ;	;POP	CX
  8394                              <1> ;	;POP	BX
  8395                              <1> ;	;POP	AX
  8396                              <1> ;	RETn
  8397                              <1> 
  8398                              <1> ;//////////////////////////////////////////////////////
  8399                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8400                              <1> ;
  8401                              <1> 
  8402                              <1> int13h: ; 21/02/2015
  8403 000028CC 9C                  <1> 	pushfd
  8404 000028CD 0E                  <1> 	push 	cs
  8405 000028CE E858000000          <1> 	call 	DISK_IO
  8406 000028D3 C3                  <1> 	retn
  8407                              <1> 
  8408                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  8409                              <1> ;/////////////////////////////////////////////////////////////////////
  8410                              <1> 
  8411                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  8412                              <1> ; 18/02/2016
  8413                              <1> ; 17/02/2016
  8414                              <1> ; 23/02/2015
  8415                              <1> ; 21/02/2015 (unix386.s)
  8416                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  8417                              <1> ;
  8418                              <1> ; Original Source Code:
  8419                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  8420                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  8421                              <1> ;
  8422                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  8423                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  8424                              <1> ;
  8425                              <1> 
  8426                              <1> 
  8427                              <1> ;The wait for controller to be not busy is 10 seconds.
  8428                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8429                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ	1615h		
  8430                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ	  05h
  8431                              <1> WAIT_HDU_CTRL_BUSY_LH	equ	51615h	 ;21/02/2015		
  8432                              <1> 
  8433                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  8434                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8435                              <1> ;;WAIT_HDU_INT_LO	equ	1615h
  8436                              <1> ;;WAIT_HDU_INT_HI	equ	  05h
  8437                              <1> WAIT_HDU_INT_LH		equ	51615h	; 21/02/2015
  8438                              <1> 
  8439                              <1> ;The wait for Data request on read and write longs is
  8440                              <1> ;2000 us. (?)
  8441                              <1> ;;WAIT_HDU_DRQ_LO	equ	1000	; 03E8h
  8442                              <1> ;;WAIT_HDU_DRQ_HI	equ	0
  8443                              <1> WAIT_HDU_DRQ_LH		equ	1000	; 21/02/2015
  8444                              <1> 
  8445                              <1> ; Port 61h (PORT_B)
  8446                              <1> SYS1		equ	61h	; PORT_B  (diskette.inc)
  8447                              <1> 
  8448                              <1> ; 23/12/2014
  8449                              <1> %define CMD_BLOCK       eBP-8  ; 21/02/2015
  8450                              <1> 
  8451                              <1> 
  8452                              <1> ;--- INT 13H -------------------------------------------------------------------
  8453                              <1> ;									       :
  8454                              <1> ; FIXED DISK I/O INTERFACE						       :
  8455                              <1> ;									       :
  8456                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  8457                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  8458                              <1> ;									       :
  8459                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  8460                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  8461                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  8462                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  8463                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  8464                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  8465                              <1> ;									       :
  8466                              <1> ;------------------------------------------------------------------------------:
  8467                              <1> ;									       :
  8468                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  8469                              <1> ;									       :
  8470                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  8471                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  8472                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  8473                              <1> ;			  DL > 80H - DISK				       :
  8474                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  8475                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  8476                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  8477                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  8478                              <1> ;	(AH)= 06H  UNUSED						       :
  8479                              <1> ;	(AH)= 07H  UNUSED						       :
  8480                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  8481                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  8482                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  8483                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  8484                              <1> ;	(AH)= 0AH  READ LONG						       :
  8485                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  8486                              <1> ;	(AH)= 0CH  SEEK 						       :
  8487                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  8488                              <1> ;	(AH)= 0EH  UNUSED						       :
  8489                              <1> ;	(AH)= 0FH  UNUSED						       :
  8490                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  8491                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  8492                              <1> ;	(AH)= 12H  UNUSED						       :
  8493                              <1> ;	(AH)= 13H  UNUSED						       :
  8494                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  8495                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  8496                              <1> ;									       :
  8497                              <1> ;-------------------------------------------------------------------------------
  8498                              <1> ;									       :
  8499                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  8500                              <1> ;									       :
  8501                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  8502                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  8503                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  8504                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  8505                              <1> ;									       :
  8506                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  8507                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  8508                              <1> ;				 (10 BITS TOTAL)			       :
  8509                              <1> ;									       :
  8510                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  8511                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  8512                              <1> ;									       :
  8513                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  8514                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  8515                              <1> ;									       :
  8516                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  8517                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  8518                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  8519                              <1> ;			       80H FOR A BAD SECTOR			       :
  8520                              <1> ;			   N = SECTOR NUMBER				       :
  8521                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  8522                              <1> ;			   THE TABLE SHOULD BE: 			       :
  8523                              <1> ;									       :
  8524                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  8525                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  8526                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  8527                              <1> ;									       :
  8528                              <1> ;-------------------------------------------------------------------------------
  8529                              <1> 
  8530                              <1> ;-------------------------------------------------------------------------------
  8531                              <1> ; OUTPUT								       :
  8532                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  8533                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  8534                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  8535                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  8536                              <1> ;									       :
  8537                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  8538                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  8539                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  8540                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  8541                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  8542                              <1> ;		REWRITTEN.						       :
  8543                              <1> ;									       :
  8544                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  8545                              <1> ;	   INPUT:							       :
  8546                              <1> ;	     (DL) = DRIVE NUMBER					       :
  8547                              <1> ;	   OUTPUT:							       :
  8548                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  8549                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  8550                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  8551                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  8552                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  8553                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  8554                              <1> ;									       :
  8555                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  8556                              <1> ;									       :
  8557                              <1> ;	AH = 0 - NOT PRESENT						       :
  8558                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  8559                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  8560                              <1> ;	     3 - FIXED DISK						       :
  8561                              <1> ;									       :
  8562                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  8563                              <1> ;									       :
  8564                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  8565                              <1> ;	INFORMATION.							       :
  8566                              <1> ;									       :
  8567                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  8568                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  8569                              <1> ;									       :
  8570                              <1> ;-------------------------------------------------------------------------------
  8571                              <1> 
  8572                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  8573                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  8574                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  8575                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  8576                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  8577                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  8578                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  8579                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  8580                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  8581                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  8582                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  8583                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  8584                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  8585                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  8586                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  8587                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  8588                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  8589                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  8590                              <1> 
  8591                              <1> ;--------------------------------------------------------
  8592                              <1> ;							:
  8593                              <1> ; FIXED DISK PARAMETER TABLE				:
  8594                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  8595                              <1> ;							:
  8596                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  8597                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  8598                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  8599                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  8600                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  8601                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  8602                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  8603                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  8604                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  8605                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  8606                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  8607                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  8608                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  8609                              <1> ;							:
  8610                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  8611                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  8612                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  8613                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  8614                              <1> ;							:
  8615                              <1> ;--------------------------------------------------------
  8616                              <1> 
  8617                              <1> ;--------------------------------------------------------
  8618                              <1> ;							:
  8619                              <1> ; HARDWARE SPECIFIC VALUES				:
  8620                              <1> ;							:
  8621                              <1> ;  -  CONTROLLER I/O PORT				:
  8622                              <1> ;							:
  8623                              <1> ;     > WHEN READ FROM: 				:
  8624                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  8625                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  8626                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  8627                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  8628                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  8629                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  8630                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  8631                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  8632                              <1> ;							:
  8633                              <1> ;     > WHEN WRITTEN TO:				:
  8634                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  8635                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  8636                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  8637                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  8638                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  8639                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  8640                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  8641                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  8642                              <1> ;							:
  8643                              <1> ;--------------------------------------------------------
  8644                              <1> 
  8645                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  8646                              <1> ;HF1_PORT	equ	0170h	
  8647                              <1> ;HF_REG_PORT	EQU	03F6H
  8648                              <1> ;HF1_REG_PORT	equ	0376h
  8649                              <1> 
  8650                              <1> HDC1_BASEPORT	equ	1F0h
  8651                              <1> HDC2_BASEPORT	equ	170h		
  8652                              <1> 
  8653                              <1> align 2
  8654                              <1> 
  8655                              <1> ;-----		STATUS REGISTER
  8656                              <1> 
  8657                              <1> ST_ERROR	EQU	00000001B	;
  8658                              <1> ST_INDEX	EQU	00000010B	;
  8659                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  8660                              <1> ST_DRQ		EQU	00001000B	;
  8661                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  8662                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  8663                              <1> ST_READY	EQU	01000000B	;
  8664                              <1> ST_BUSY 	EQU	10000000B	;
  8665                              <1> 
  8666                              <1> ;-----		ERROR REGISTER
  8667                              <1> 
  8668                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  8669                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  8670                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  8671                              <1> ;		EQU	00001000B	; NOT USED
  8672                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  8673                              <1> ;		EQU	00100000B	; NOT USED
  8674                              <1> ERR_DATA_ECC	EQU	01000000B
  8675                              <1> ERR_BAD_BLOCK	EQU	10000000B
  8676                              <1> 
  8677                              <1> 
  8678                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  8679                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  8680                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  8681                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  8682                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  8683                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  8684                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  8685                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  8686                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  8687                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  8688                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  8689                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  8690                              <1> 
  8691                              <1> ;MAX_FILE	EQU	2
  8692                              <1> ;S_MAX_FILE	EQU	2
  8693                              <1> MAX_FILE	equ	4		; 22/12/2014
  8694                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  8695                              <1> 
  8696                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  8697                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  8698                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  8699                              <1> 
  8700                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  8701                              <1> 
  8702                              <1> ;-----		COMMAND BLOCK REFERENCE
  8703                              <1> 
  8704                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  8705                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  8706                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  8707                              <1> ; 19/12/2014
  8708                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  8709                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  8710                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8711                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8712                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  8713                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  8714                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  8715                              <1> 
  8716                              <1> align 2
  8717                              <1> 
  8718                              <1> ;----------------------------------------------------------------
  8719                              <1> ; FIXED DISK I/O SETUP						:
  8720                              <1> ;								:
  8721                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  8722                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  8723                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  8724                              <1> ;								:
  8725                              <1> ;----------------------------------------------------------------
  8726                              <1> 
  8727                              <1> DISK_SETUP:
  8728                              <1> 	;CLI
  8729                              <1> 	;;MOV	AX,ABS0 			; GET ABSOLUTE SEGMENT
  8730                              <1> 	;xor	ax,ax
  8731                              <1> 	;MOV	DS,AX				; SET SEGMENT REGISTER
  8732                              <1> 	;MOV	AX, [ORG_VECTOR] 		; GET DISKETTE VECTOR
  8733                              <1> 	;MOV	[DISK_VECTOR],AX		;  INTO INT 40H
  8734                              <1> 	;MOV	AX, [ORG_VECTOR+2]
  8735                              <1> 	;MOV	[DISK_VECTOR+2],AX
  8736                              <1> 	;MOV	word [ORG_VECTOR],DISK_IO	; FIXED DISK HANDLER
  8737                              <1> 	;MOV	[ORG_VECTOR+2],CS
  8738                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  8739                              <1> 	;;MOV	word [HDISK_INT],HD_INT		; FIXED DISK INTERRUPT
  8740                              <1> 	;mov	word [HDISK_INT1],HD_INT	;
  8741                              <1> 	;;MOV	[HDISK_INT+2],CS
  8742                              <1> 	;mov	[HDISK_INT1+2],CS
  8743                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  8744                              <1> 	;mov	word [HDISK_INT2],HD1_INT	;
  8745                              <1> 	;mov	[HDISK_INT2+2],CS
  8746                              <1> 	;
  8747                              <1> 	;;MOV	word [HF_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80
  8748                              <1> 	;;MOV	word [HF_TBL_VEC+2],DPT_SEGM
  8749                              <1> 	;;MOV	word [HF1_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81
  8750                              <1> 	;;MOV	word [HF1_TBL_VEC+2],DPT_SEGM
  8751                              <1> 	;push	cs
  8752                              <1> 	;pop	ds
  8753                              <1> 	;mov	word [HDPM_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80h
  8754                              <1> 	;mov	word [HDPM_TBL_VEC+2],DPT_SEGM
  8755 000028D4 C705[1CC50000]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  8756 000028DC 0900                <1>
  8757                              <1> 	;mov	word [HDPS_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81h
  8758                              <1> 	;mov	word [HDPS_TBL_VEC+2],DPT_SEGM
  8759 000028DE C705[20C50000]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  8760 000028E6 0900                <1>
  8761                              <1> 	;mov	word [HDSM_TBL_VEC],HD2_DPT	; PARM TABLE DRIVE 82h
  8762                              <1> 	;mov	word [HDSM_TBL_VEC+2],DPT_SEGM
  8763 000028E8 C705[24C50000]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  8764 000028F0 0900                <1>
  8765                              <1> 	;mov	word [HDSS_TBL_VEC],HD3_DPT	; PARM TABLE DRIVE 83h
  8766                              <1> 	;mov	word [HDSS_TBL_VEC+2],DPT_SEGM
  8767 000028F2 C705[28C50000]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  8768 000028FA 0900                <1>
  8769                              <1> 	;
  8770                              <1> 	;;IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  8771                              <1> 	;;;AND	AL,0BFH
  8772                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  8773                              <1> 	;;;JMP	$+2
  8774                              <1> 	;;IODELAY
  8775                              <1> 	;;OUT	INTB01,AL
  8776                              <1> 	;;IODELAY
  8777                              <1> 	;;IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  8778                              <1> 	;;AND	AL,0FBH 		;  SECOND CHIP
  8779                              <1> 	;;;JMP	$+2
  8780                              <1> 	;;IODELAY
  8781                              <1> 	;;OUT	INTA01,AL
  8782                              <1> 	;
  8783                              <1> 	;STI
  8784                              <1> 	;;PUSH	DS			; MOVE ABS0 POINTER TO
  8785                              <1> 	;;POP	ES			; EXTRA SEGMENT POINTER
  8786                              <1> 	;;;CALL	DDS			; ESTABLISH DATA SEGMENT
  8787                              <1> 	;;MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  8788                              <1> 	;;MOV	byte [HF_NUM],0		; ZERO NUMBER OF FIXED DISKS
  8789                              <1> 	;;MOV	byte [CONTROL_BYTE],0
  8790                              <1> 	;;MOV	byte [PORT_OFF],0	; ZERO CARD OFFSET
  8791                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  8792                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  8793                              <1> 	;mov	si, hd0_type
  8794 000028FC BE[50BF0000]        <1> 	mov	esi, hd0_type
  8795                              <1> 	;mov	cx, 4
  8796 00002901 B904000000          <1> 	mov	ecx, 4
  8797                              <1> hde_l:
  8798 00002906 AC                  <1> 	lodsb
  8799 00002907 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  8800 00002909 7206                <1> 	jb	short _L4
  8801 0000290B FE05[18C50000]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  8802                              <1> _L4: ; 26/02/2015
  8803 00002911 E2F3                <1> 	loop	hde_l	
  8804                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  8805                              <1> ;L4:
  8806                              <1> 	; 
  8807                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  8808                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  8809                              <1> 	;;mov 	cl, 3
  8810                              <1> 	;;
  8811                              <1> 	;;MOV	DL,80H			; CHECK THE CONTROLLER
  8812                              <1> ;;hdc_dl:
  8813                              <1> 	;;MOV	AH,14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  8814                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  8815                              <1> 	;;;JC	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  8816                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  8817                              <1> 	;;jnc	short hdc_reset0
  8818                              <1> 	;;loop	hdc_dl
  8819                              <1> 	;;; 27/12/2014
  8820                              <1> 	;;stc
  8821                              <1> 	;;retn
  8822                              <1> 	;
  8823                              <1> ;;hdc_reset0:
  8824                              <1> 	; 18/01/2015
  8825 00002913 8A0D[18C50000]      <1> 	mov	cl, [HF_NUM]
  8826 00002919 20C9                <1> 	and	cl, cl
  8827 0000291B 740D                <1> 	jz	short POD_DONE
  8828                              <1> 	;
  8829 0000291D B27F                <1> 	mov	dl, 7Fh
  8830                              <1> hdc_reset1:
  8831 0000291F FEC2                <1> 	inc	dl
  8832                              <1> 	;; 31/12/2015
  8833                              <1> 	;;push	dx
  8834                              <1> 	;;push	cx
  8835                              <1> 	;;push	ds
  8836                              <1> 	;;sub	ax, ax
  8837                              <1> 	;;mov	ds, ax
  8838                              <1> 	;;MOV	AX, [TIMER_LOW]		; GET START TIMER COUNTS
  8839                              <1> 	;;pop	ds
  8840                              <1> 	;;MOV	BX,AX
  8841                              <1> 	;;ADD	AX,6*182		; 60 SECONDS* 18.2
  8842                              <1> 	;;MOV	CX,AX
  8843                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  8844                              <1> 	;;
  8845                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  8846                              <1> 	;;CALL	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  8847                              <1> 	;;pop	cx
  8848                              <1> 	;;pop	dx
  8849                              <1> 	;;
  8850                              <1> 	; 18/01/2015
  8851 00002921 B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  8852                              <1> 	;int	13h
  8853 00002923 E8A4FFFFFF          <1> 	call	int13h
  8854 00002928 E2F5                <1> 	loop	hdc_reset1
  8855                              <1> POD_DONE:
  8856 0000292A C3                  <1> 	RETn
  8857                              <1> 
  8858                              <1> ;;-----	POD_ERROR
  8859                              <1> 
  8860                              <1> ;;CTL_ERRX:
  8861                              <1> ;	;MOV	SI,OFFSET F1782 	; CONTROLLER ERROR
  8862                              <1> ;	;CALL	SET_FAIL		; DO NOT IPL FROM DISK
  8863                              <1> ;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8864                              <1> ;	;JMP	short POD_DONE
  8865                              <1> 
  8866                              <1> ;;HD_RESET_1:
  8867                              <1> ;;	;PUSH	BX			; SAVE TIMER LIMITS
  8868                              <1> ;;	;PUSH	CX
  8869                              <1> ;;RES_1: MOV	AH,09H			; SET DRIVE PARAMETERS
  8870                              <1> ;;	INT	13H
  8871                              <1> ;;	JC	short RES_2
  8872                              <1> ;;	MOV	AH,11H			; RECALIBRATE DRIVE
  8873                              <1> ;;	INT	13H
  8874                              <1> ;;	JNC	short RES_CK		; DRIVE OK
  8875                              <1> ;;RES_2: ;CALL	POD_TCHK		; CHECK TIME OUT
  8876                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8877                              <1> ;;					; (30 seconds)		
  8878                              <1> ;;	;cmc
  8879                              <1> ;;	;JNC	short RES_1
  8880                              <1> ;;	jb	short RES_1
  8881                              <1> ;;;RES_FL: ;MOV	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  8882                              <1> ;;	;TEST	DL,1
  8883                              <1> ;;	;JNZ	RES_E1
  8884                              <1> ;;	;MOV	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  8885                              <1> ;;	;CALL	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  8886                              <1> ;;	;JMP	SHORT RES_E1
  8887                              <1> ;;RES_ER: ; 22/12/2014
  8888                              <1> ;;RES_OK:
  8889                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8890                              <1> ;;	;POP	BX
  8891                              <1> ;;	RETn
  8892                              <1> ;;
  8893                              <1> ;;RES_RS: MOV	AH,00H			; RESET THE DRIVE
  8894                              <1> ;;	INT	13H
  8895                              <1> ;;RES_CK: MOV	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  8896                              <1> ;;	MOV	BL,DL			; SAVE DRIVE CODE
  8897                              <1> ;;	INT	13H
  8898                              <1> ;;	JC	short RES_ER
  8899                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  8900                              <1> ;;	MOV	DL,BL			; RESTORE DRIVE CODE
  8901                              <1> ;;RES_3: MOV	AX,0401H		; VERIFY THE LAST SECTOR
  8902                              <1> ;;	INT	13H
  8903                              <1> ;;	JNC	short RES_OK		; VERIFY OK
  8904                              <1> ;;	CMP	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  8905                              <1> ;;	JE	short RES_OK
  8906                              <1> ;;	CMP	AH,DATA_CORRECTED
  8907                              <1> ;;	JE	short RES_OK
  8908                              <1> ;;	CMP	AH,BAD_ECC
  8909                              <1> ;;	JE	short RES_OK
  8910                              <1> ;;	;CALL	POD_TCHK		; CHECK FOR TIME OUT
  8911                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8912                              <1> ;;					; (60 seconds)		
  8913                              <1> ;;	cmc
  8914                              <1> ;;	JC	short RES_ER		; FAILED
  8915                              <1> ;;	MOV	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  8916                              <1> ;;	MOV	AL,CL			; SEPARATE OUT SECTOR NUMBER
  8917                              <1> ;;	AND	AL,3FH
  8918                              <1> ;;	DEC	AL			; TRY PREVIOUS ONE
  8919                              <1> ;;	JZ	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  8920                              <1> ;;	AND	CL,0C0H 		; KEEP CYLINDER BITS
  8921                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  8922                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  8923                              <1> ;;	JMP	short RES_3		; TRY AGAIN
  8924                              <1> ;;;RES_ER: MOV	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  8925                              <1> ;;	;TEST	DL,1
  8926                              <1> ;;	;JNZ	short RES_E1
  8927                              <1> ;;	;MOV	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  8928                              <1> ;;;RES_E1:
  8929                              <1> ;;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8930                              <1> ;;;RES_OK:
  8931                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8932                              <1> ;;	;POP	BX
  8933                              <1> ;;	;RETn
  8934                              <1> ;
  8935                              <1> ;;SET_FAIL:
  8936                              <1> ;	;MOV	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  8937                              <1> ;	;CALL	CMOS_READ
  8938                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  8939                              <1> ;	;XCHG	AH,AL			; SAVE IT
  8940                              <1> ;	;CALL	CMOS_WRITE		; PUT IT OUT
  8941                              <1> ;	;RETn
  8942                              <1> ;
  8943                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  8944                              <1> ;	;POP	AX			; SAVE RETURN
  8945                              <1> ;	;POP	CX			; GET TIME OUT LIMITS
  8946                              <1> ;	;POP	BX
  8947                              <1> ;	;PUSH	BX			; AND SAVE THEM AGAIN
  8948                              <1> ;	;PUSH	CX
  8949                              <1> ;	;PUSH	AX
  8950                              <1> ;	;push	ds
  8951                              <1> ;	;xor	ax, ax
  8952                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  8953                              <1> ;	;MOV	AX, [TIMER_LOW]		; AX = CURRENT TIME
  8954                              <1> ;	;				; BX = START TIME
  8955                              <1> ;	;				; CX = END TIME
  8956                              <1> ;	;pop	ds
  8957                              <1> ;	;CMP	BX,CX
  8958                              <1> ;	;JB	short TCHK1		; START < END
  8959                              <1> ;	;CMP	BX,AX
  8960                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  8961                              <1> ;	;JMP	SHORT TCHK2		; END, CURRENT < START
  8962                              <1> ;;TCHK1: CMP	AX,BX
  8963                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  8964                              <1> ;;TCHK2: CMP	AX,CX
  8965                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  8966                              <1> ;;					; OR CURRENT < END < START
  8967                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  8968                              <1> ;;	RETn
  8969                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  8970                              <1> ;;	RETn
  8971                              <1> ;;
  8972                              <1> ;;int_13h:
  8973                              <1> 
  8974                              <1> ;----------------------------------------
  8975                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  8976                              <1> ;----------------------------------------
  8977                              <1> 
  8978                              <1> DISK_IO:
  8979 0000292B 80FA80              <1> 	CMP	DL,80H			; TEST FOR FIXED DISK DRIVE
  8980                              <1> 	;JAE	short A1		; YES, HANDLE HERE
  8981                              <1> 	;;;INT	40H			; DISKETTE HANDLER
  8982                              <1> 	;;call	int40h
  8983 0000292E 0F8225F1FFFF        <1> 	jb	DISKETTE_IO_1
  8984                              <1> ;RET_2:
  8985                              <1> 	;RETf	2			; BACK TO CALLER
  8986                              <1> ;	retf	4
  8987                              <1> A1:
  8988 00002934 FB                  <1> 	STI				; ENABLE INTERRUPTS
  8989                              <1> 	;; 04/01/2015
  8990                              <1> 	;;OR	AH,AH
  8991                              <1> 	;;JNZ	short A2
  8992                              <1> 	;;INT	40H			; RESET NEC WHEN AH=0
  8993                              <1> 	;;SUB	AH,AH
  8994 00002935 80FA83              <1> 	CMP	DL,(80H + S_MAX_FILE - 1)
  8995 00002938 772C                <1> 	JA	short RET_2
  8996                              <1> 	; 18/01/2015
  8997 0000293A 08E4                <1> 	or	ah,ah
  8998 0000293C 742B                <1> 	jz	short A4
  8999 0000293E 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  9000 00002941 7504                <1> 	jne	short A2
  9001 00002943 28E4                <1> 	sub	ah,ah	; Reset
  9002 00002945 EB22                <1> 	jmp	short A4
  9003                              <1> A2:
  9004 00002947 80FC08              <1> 	CMP	AH,08H			; GET PARAMETERS IS A SPECIAL CASE
  9005                              <1> 	;JNZ	short A3
  9006                              <1>         ;JMP    GET_PARM_N
  9007 0000294A 0F841C030000        <1> 	je	GET_PARM_N
  9008 00002950 80FC15              <1> A3:	CMP	AH,15H			; READ DASD TYPE IS ALSO
  9009                              <1> 	;JNZ	short A4
  9010                              <1>         ;JMP    READ_DASD_TYPE
  9011 00002953 0F84C7020000        <1>         je      READ_DASD_TYPE
  9012                              <1> 	; 02/02/2015
  9013 00002959 80FC1D              <1> 	cmp	ah, 1Dh			;(Temporary for Retro UNIX 386 v1)
  9014                              <1> 	; 12/01/2015
  9015 0000295C F5                  <1> 	cmc
  9016 0000295D 730A                <1> 	jnc	short A4
  9017                              <1> 	; 30/01/2015
  9018                              <1> 	;mov     byte [CS:DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9019 0000295F C605[17C50000]01    <1>         mov     byte [DISK_STATUS1], BAD_CMD
  9020                              <1> 	;jmp	short RET_2
  9021                              <1> RET_2:
  9022 00002966 CA0400              <1> 	retf	4
  9023                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  9024 00002969 C8080000            <1> 	ENTER	8,0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  9025 0000296D 53                  <1> 	PUSH	eBX			;  IN THE STACK, THE COMMAND BLOCK IS:
  9026 0000296E 51                  <1> 	PUSH	eCX			;   @CMD_BLOCK == BYTE PTR [BP]-8
  9027 0000296F 52                  <1> 	PUSH	eDX
  9028 00002970 1E                  <1> 	PUSH	DS
  9029 00002971 06                  <1> 	PUSH	ES
  9030 00002972 56                  <1> 	PUSH	eSI
  9031 00002973 57                  <1> 	PUSH	eDI
  9032                              <1> 	;;04/01/2015
  9033                              <1> 	;;OR	AH,AH			; CHECK FOR RESET
  9034                              <1> 	;;JNZ	short A5
  9035                              <1> 	;;MOV	DL,80H			; FORCE DRIVE 80 FOR RESET
  9036                              <1> ;;A5:	
  9037                              <1> 	;push	cs
  9038                              <1> 	;pop	ds
  9039                              <1> 	; 21/02/2015
  9040 00002974 6650                <1> 	push	ax
  9041 00002976 66B81000            <1> 	mov	ax, KDATA
  9042 0000297A 8ED8                <1> 	mov	ds, ax
  9043 0000297C 8EC0                <1> 	mov	es, ax	
  9044 0000297E 6658                <1> 	pop	ax
  9045 00002980 E889000000          <1> 	CALL	DISK_IO_CONT		; PERFORM THE OPERATION
  9046                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9047 00002985 8A25[17C50000]      <1> 	MOV	AH,[DISK_STATUS1]	; GET STATUS FROM OPERATION
  9048 0000298B 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  9049 0000298E F5                  <1> 	CMC				; SUCCESS OR FAILURE
  9050 0000298F 5F                  <1> 	POP	eDI			; RESTORE REGISTERS
  9051 00002990 5E                  <1> 	POP	eSI
  9052 00002991 07                  <1>         POP     ES
  9053 00002992 1F                  <1>         POP     DS
  9054 00002993 5A                  <1> 	POP	eDX
  9055 00002994 59                  <1> 	POP	eCX
  9056 00002995 5B                  <1> 	POP	eBX
  9057 00002996 C9                  <1> 	LEAVE				; ADJUST (SP) AND RESTORE (BP)
  9058                              <1> 	;RETf	2			; THROW AWAY SAVED FLAGS
  9059 00002997 CA0400              <1> 	retf	4
  9060                              <1> 
  9061                              <1> ; 21/02/2015
  9062                              <1> ;       dw --> dd
  9063                              <1> D1:					; FUNCTION TRANSFER TABLE
  9064 0000299A [5C2B0000]          <1> 	dd	DISK_RESET		; 000H
  9065 0000299E [D32B0000]          <1> 	dd	RETURN_STATUS		; 001H
  9066 000029A2 [E02B0000]          <1> 	dd	DISK_READ		; 002H
  9067 000029A6 [E92B0000]          <1> 	dd	DISK_WRITE		; 003H
  9068 000029AA [F22B0000]          <1> 	dd	DISK_VERF		; 004H
  9069 000029AE [0A2C0000]          <1> 	dd	FMT_TRK 		; 005H
  9070 000029B2 [522B0000]          <1> 	dd	BAD_COMMAND		; 006H	FORMAT BAD SECTORS
  9071 000029B6 [522B0000]          <1> 	dd	BAD_COMMAND		; 007H	FORMAT DRIVE
  9072 000029BA [522B0000]          <1> 	dd	BAD_COMMAND		; 008H	RETURN PARAMETERS
  9073 000029BE [D12C0000]          <1> 	dd	INIT_DRV		; 009H
  9074 000029C2 [302D0000]          <1> 	dd	RD_LONG 		; 00AH
  9075 000029C6 [392D0000]          <1> 	dd	WR_LONG 		; 00BH
  9076 000029CA [422D0000]          <1> 	dd	DISK_SEEK		; 00CH
  9077 000029CE [5C2B0000]          <1> 	dd	DISK_RESET		; 00DH
  9078 000029D2 [522B0000]          <1> 	dd	BAD_COMMAND		; 00EH	READ BUFFER
  9079 000029D6 [522B0000]          <1> 	dd	BAD_COMMAND		; 00FH	WRITE BUFFER
  9080 000029DA [6A2D0000]          <1> 	dd	TST_RDY 		; 010H
  9081 000029DE [8E2D0000]          <1> 	dd	HDISK_RECAL		; 011H
  9082 000029E2 [522B0000]          <1> 	dd	BAD_COMMAND		; 012H	MEMORY DIAGNOSTIC
  9083 000029E6 [522B0000]          <1> 	dd	BAD_COMMAND		; 013H	DRIVE DIAGNOSTIC
  9084 000029EA [C42D0000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 014H	CONTROLLER DIAGNOSTIC
  9085                              <1> 	; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  9086 000029EE [522B0000]          <1> 	dd	BAD_COMMAND		; 015h
  9087 000029F2 [522B0000]          <1> 	dd	BAD_COMMAND		; 016h
  9088 000029F6 [522B0000]          <1> 	dd	BAD_COMMAND		; 017h
  9089 000029FA [522B0000]          <1> 	dd	BAD_COMMAND		; 018h
  9090 000029FE [522B0000]          <1> 	dd	BAD_COMMAND		; 019h
  9091 00002A02 [522B0000]          <1> 	dd	BAD_COMMAND		; 01Ah
  9092 00002A06 [E02B0000]          <1> 	dd	DISK_READ		; 01Bh ; LBA read
  9093 00002A0A [E92B0000]          <1> 	dd	DISK_WRITE		; 01Ch ; LBA write
  9094                              <1> D1L     EQU    $ - D1
  9095                              <1> 
  9096                              <1> DISK_IO_CONT:
  9097                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9098 00002A0E 80FC01              <1> 	CMP	AH,01H			; RETURN STATUS
  9099                              <1> 	;;JNZ	short SU0
  9100                              <1>         ;;JMP    RETURN_STATUS
  9101 00002A11 0F84BC010000        <1> 	je	RETURN_STATUS
  9102                              <1> SU0:
  9103 00002A17 C605[17C50000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  9104                              <1> 	;;PUSH	BX			; SAVE DATA ADDRESS
  9105                              <1> 	;mov	si, bx ;; 14/02/2015
  9106 00002A1E 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  9107 00002A20 8A1D[18C50000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9108                              <1> 	;; 04/01/2015
  9109                              <1> 	;;PUSH	AX
  9110 00002A26 80E27F              <1> 	AND	DL,7FH			; GET DRIVE AS 0 OR 1
  9111                              <1> 					; (get drive number as 0 to 3)
  9112 00002A29 38D3                <1> 	CMP	BL,DL
  9113                              <1>         ;;JBE   BAD_COMMAND_POP         ; INVALID DRIVE
  9114 00002A2B 0F8621010000        <1>         jbe     BAD_COMMAND ;; 14/02/2015
  9115                              <1>         ;
  9116                              <1> 	;;03/01/2015
  9117 00002A31 29DB                <1> 	sub	ebx, ebx
  9118 00002A33 88D3                <1> 	mov	bl, dl
  9119                              <1> 	;sub	bh, bh
  9120 00002A35 883D[2CC50000]      <1> 	mov	[LBAMode], bh 	; 0
  9121                              <1> 	;;test	byte [bx+hd0_type], 1	; LBA ready ?
  9122                              <1> 	;test	byte [ebx+hd0_type], 1
  9123                              <1> 	;jz	short su1		; no
  9124                              <1> 	;inc	byte [LBAMode]
  9125                              <1> ;su1:
  9126                              <1> 	; 21/02/2015 (32 bit modification)
  9127                              <1> 	;04/01/2015
  9128 00002A3B 6650                <1> 	push	ax ; ***
  9129                              <1> 	;PUSH	ES ; **
  9130 00002A3D 6652                <1> 	PUSH	DX ; *
  9131 00002A3F 6650                <1> 	push	ax
  9132 00002A41 E864060000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS
  9133                              <1> 	; 02/02/2015
  9134                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  9135 00002A46 668B4310            <1> 	mov	ax, [ebx+16]
  9136 00002A4A 66A3[44BF0000]      <1> 	mov	[HF_PORT], ax
  9137                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  9138 00002A50 668B5312            <1> 	mov	dx, [ebx+18]
  9139 00002A54 668915[46BF0000]    <1> 	mov	[HF_REG_PORT], dx
  9140                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  9141 00002A5B 8A4314              <1> 	mov	al, [ebx+20]
  9142                              <1> 	; 23/02/2015
  9143 00002A5E A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  9144 00002A60 7406                <1> 	jz 	short su1
  9145 00002A62 FE05[2CC50000]      <1> 	inc	byte [LBAMode] ; 1 
  9146                              <1> su1: 	 
  9147 00002A68 C0E804              <1> 	shr 	al, 4
  9148 00002A6B 2401                <1> 	and	al, 1			
  9149 00002A6D A2[48BF0000]        <1> 	mov	[hf_m_s], al 
  9150                              <1> 	;
  9151                              <1> 	; 03/01/2015
  9152                              <1> 	;MOV	AL,byte [ES:BX+8]	; GET CONTROL BYTE MODIFIER
  9153 00002A72 8A4308              <1> 	mov	al, [ebx+8]
  9154                              <1> 	;MOV	DX,[HF_REG_PORT]	; Device Control register	
  9155 00002A75 EE                  <1> 	OUT	DX,AL			; SET EXTRA HEAD OPTION
  9156                              <1> 					; Control Byte:  (= 08h, here)
  9157                              <1> 					; bit 0 - 0
  9158                              <1> 					; bit 1 - nIEN (1 = disable irq)
  9159                              <1> 					; bit 2 - SRST (software RESET)
  9160                              <1> 					; bit 3 - use extra heads (8 to 15)
  9161                              <1> 					;         -always set to 1-	
  9162                              <1> 					; (bits 3 to 7 are reserved
  9163                              <1> 					;          for ATA devices)
  9164 00002A76 8A25[19C50000]      <1> 	MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9165 00002A7C 80E4C0              <1> 	AND	AH,0C0H 		; CONTROL BYTE
  9166 00002A7F 08C4                <1> 	OR	AH,AL
  9167 00002A81 8825[19C50000]      <1> 	MOV	[CONTROL_BYTE],AH	
  9168                              <1> 	; 04/01/2015
  9169 00002A87 6658                <1> 	pop	ax
  9170 00002A89 665A                <1> 	pop	dx ; * ;; 14/02/2015
  9171 00002A8B 20E4                <1> 	and	ah, ah	; Reset function ?
  9172 00002A8D 7507                <1> 	jnz	short su2
  9173                              <1> 	;;pop	dx ; * ;; 14/02/2015
  9174                              <1> 	;pop	es ; **
  9175 00002A8F 6658                <1> 	pop	ax ; ***
  9176                              <1> 	;;pop	bx
  9177 00002A91 E9C6000000          <1>         jmp     DISK_RESET
  9178                              <1> su2:
  9179 00002A96 803D[2CC50000]00    <1> 	cmp	byte [LBAMode], 0
  9180 00002A9D 7661                <1> 	jna	short su3
  9181                              <1> 	;
  9182                              <1> 	; 02/02/2015 (LBA read/write function calls)
  9183 00002A9F 80FC1B              <1> 	cmp	ah, 1Bh
  9184 00002AA2 720B                <1> 	jb	short lbarw1
  9185 00002AA4 80FC1C              <1> 	cmp	ah, 1Ch
  9186 00002AA7 775C                <1> 	ja 	short invldfnc
  9187                              <1> 	;;pop	dx ; * ; 14/02/2015
  9188                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  9189 00002AA9 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  9190                              <1> 	;; 14/02/2015
  9191 00002AAB 88D1                <1> 	mov	cl, dl ; 14/02/2015
  9192                              <1> 	;;mov	dx, bx
  9193                              <1> 	;mov	dx, si ; higher word of LBA address (bits 16-23)
  9194                              <1> 	;;mov	bx, di
  9195                              <1> 	;mov	si, di ; Buffer offset
  9196 00002AAD EB31                <1> 	jmp	short lbarw2
  9197                              <1> lbarw1:
  9198                              <1> 	; convert CHS to LBA
  9199                              <1> 	;
  9200                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  9201                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  9202                              <1> 	;	+ Sector - 1
  9203 00002AAF 6652                <1> 	push	dx ; * ;; 14/02/2015
  9204                              <1> 	;xor	dh, dh
  9205 00002AB1 31D2                <1> 	xor	edx, edx
  9206                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  9207 00002AB3 8A530E              <1> 	mov	dl, [ebx+14]
  9208                              <1> 	;xor	ah, ah
  9209 00002AB6 31C0                <1> 	xor	eax, eax
  9210                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  9211 00002AB8 8A4302              <1> 	mov	al, [ebx+2]
  9212 00002ABB FEC8                <1> 	dec	al
  9213 00002ABD 6640                <1> 	inc	ax		; 0 =  256
  9214 00002ABF 66F7E2              <1> 	mul 	dx
  9215                              <1> 		; AX = # of Heads" * Sectors/Track
  9216 00002AC2 6689CA              <1> 	mov	dx, cx
  9217                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  9218 00002AC5 83E13F              <1> 	and	ecx, 3fh
  9219 00002AC8 86D6                <1> 	xchg	dl, dh
  9220 00002ACA C0EE06              <1> 	shr	dh, 6
  9221                              <1> 		; DX = cylinder (0 to 1023)
  9222                              <1> 	;mul 	dx
  9223                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  9224 00002ACD F7E2                <1> 	mul	edx
  9225 00002ACF FEC9                <1> 	dec	cl  ; sector - 1
  9226                              <1> 	;add	ax, cx
  9227                              <1> 	;adc	dx, 0
  9228                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector -1
  9229 00002AD1 01C8                <1> 	add	eax, ecx
  9230 00002AD3 6659                <1> 	pop	cx ; * ; ch = head, cl = drive number (zero based)
  9231                              <1> 	;push	dx
  9232                              <1> 	;push	ax
  9233 00002AD5 50                  <1> 	push	eax
  9234                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  9235 00002AD6 8A430E              <1> 	mov	al, [ebx+14]
  9236 00002AD9 F6E5                <1> 	mul	ch
  9237                              <1> 		;  AX = Head * Sectors/Track
  9238 00002ADB 6699                <1>         cwd
  9239                              <1> 	;pop	dx
  9240 00002ADD 5A                  <1> 	pop	edx
  9241                              <1> 	;add	ax, dx
  9242                              <1> 	;pop	dx
  9243                              <1> 	;adc	dx, 0 ; add carry bit
  9244 00002ADE 01D0                <1> 	add	eax, edx
  9245                              <1> lbarw2:
  9246 00002AE0 29D2                <1> 	sub	edx, edx ; 21/02/2015
  9247 00002AE2 88CA                <1> 	mov	dl, cl ; 21/02/2015
  9248 00002AE4 C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  9249                              <1> 				; NOTE: Features register (1F1h, 171h)
  9250                              <1> 				; is not used for ATA device R/W functions. 
  9251                              <1> 				; It is old/obsolete 'write precompensation'
  9252                              <1> 				; register and error register
  9253                              <1> 				; for old ATA/IDE devices.
  9254                              <1> 	; 18/01/2014
  9255                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  9256 00002AE8 8A0D[48BF0000]      <1> 	mov	cl, [hf_m_s]
  9257                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  9258                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  9259                              <1> 				; bit 6 = 1 = LBA mode
  9260                              <1> 				; bit 7 = 1
  9261 00002AEE 80C90E              <1> 	or	cl, 0Eh ; 1110b
  9262                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  9263 00002AF1 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  9264 00002AF6 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  9265                              <1> 	;or	dh, ch
  9266 00002AF9 09C8                <1> 	or	eax, ecx	
  9267                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  9268                              <1> 				  ; (Sector Number Register)
  9269                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  9270                              <1> 				  ; (Cylinder Low Register)
  9271                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  9272                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  9273                              <1> 				  ; (Cylinder High Register)
  9274                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  9275                              <1> 				  ; (Drive/Head Register)
  9276                              <1> 	
  9277                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  9278 00002AFB 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  9279                              <1> 	;14/02/2015
  9280                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  9281 00002AFE EB38                <1> 	jmp	short su4
  9282                              <1> su3:
  9283                              <1> 	; 02/02/2015 
  9284                              <1> 	; (Temporary functions 1Bh & 1Ch are not valid for CHS mode) 
  9285 00002B00 80FC14              <1> 	cmp 	ah, 14h
  9286 00002B03 7604                <1> 	jna 	short chsfnc
  9287                              <1> invldfnc:
  9288                              <1>         ; 14/02/2015  
  9289                              <1> 	;pop	es ; **
  9290 00002B05 6658                <1>         pop     ax ; ***
  9291                              <1>         ;jmp     short BAD_COMMAND_POP
  9292 00002B07 EB49                <1>         jmp     short BAD_COMMAND
  9293                              <1> chsfnc:	
  9294                              <1> 	;MOV	AX,[ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  9295 00002B09 668B4305            <1> 	mov	ax, [ebx+5]
  9296 00002B0D 66C1E802            <1> 	SHR	AX,2
  9297 00002B11 8845F8              <1> 	MOV	[CMD_BLOCK],AL
  9298                              <1> 	;;MOV	AL,[ES:BX+8]		; GET CONTROL BYTE MODIFIER
  9299                              <1> 	;;PUSH	DX
  9300                              <1> 	;;MOV	DX,[HF_REG_PORT]
  9301                              <1> 	;;OUT	DX,AL			; SET EXTRA HEAD OPTION
  9302                              <1> 	;;POP	DX ; * 
  9303                              <1> 	;;POP	ES ; **
  9304                              <1> 	;;MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9305                              <1> 	;;AND	AH,0C0H 		; CONTROL BYTE	
  9306                              <1> 	;;OR	AH,AL
  9307                              <1> 	;;MOV	[CONTROL_BYTE],AH
  9308                              <1> 	;
  9309 00002B14 88C8                <1> 	MOV	AL,CL			; GET SECTOR NUMBER
  9310 00002B16 243F                <1> 	AND	AL,3FH
  9311 00002B18 8845FA              <1> 	MOV	[CMD_BLOCK+2],AL
  9312 00002B1B 886DFB              <1> 	MOV	[CMD_BLOCK+3],CH 	; GET CYLINDER NUMBER
  9313 00002B1E 88C8                <1> 	MOV	AL,CL
  9314 00002B20 C0E806              <1> 	SHR	AL,6
  9315 00002B23 8845FC              <1> 	MOV	[CMD_BLOCK+4],AL 	; CYLINDER HIGH ORDER 2 BITS
  9316                              <1> 	;;05/01/2015
  9317                              <1> 	;;MOV	AL,DL			; DRIVE NUMBER
  9318 00002B26 A0[48BF0000]        <1> 	mov	al, [hf_m_s]
  9319 00002B2B C0E004              <1> 	SHL	AL,4
  9320 00002B2E 80E60F              <1> 	AND	DH,0FH			; HEAD NUMBER
  9321 00002B31 08F0                <1> 	OR	AL,DH
  9322                              <1> 	;OR	AL,80H or 20H
  9323 00002B33 0CA0                <1> 	OR	AL,80h+20h		; ECC AND 512 BYTE SECTORS
  9324 00002B35 8845FD              <1> 	MOV	[CMD_BLOCK+5],AL 	; ECC/SIZE/DRIVE/HEAD
  9325                              <1> su4:
  9326                              <1> 	;POP	ES ; **
  9327                              <1>         ;; 14/02/2015
  9328                              <1>         ;;POP   AX
  9329                              <1>         ;;MOV   [CMD_BLOCK+1],AL        ; SECTOR COUNT
  9330                              <1>         ;;PUSH  AX
  9331                              <1>         ;;MOV   AL,AH                   ; GET INTO LOW BYTE
  9332                              <1>         ;;XOR   AH,AH                   ; ZERO HIGH BYTE
  9333                              <1>         ;;SAL   AX,1                    ; *2 FOR TABLE LOOKUP
  9334 00002B38 6658                <1>         pop     ax ; ***
  9335 00002B3A 8845F9              <1>         mov     [CMD_BLOCK+1], al
  9336 00002B3D 29DB                <1>         sub	ebx, ebx
  9337 00002B3F 88E3                <1> 	mov     bl, ah
  9338                              <1>         ;xor     bh, bh
  9339                              <1>         ;sal     bx, 1
  9340 00002B41 66C1E302            <1>         sal	bx, 2	; 32 bit offset (21/02/2015)
  9341                              <1> 	;;MOV   SI,AX                   ; PUT INTO SI FOR BRANCH
  9342                              <1>         ;;CMP   AX,D1L                  ; TEST WITHIN RANGE
  9343                              <1>         ;;JNB   short BAD_COMMAND_POP
  9344                              <1>         ;cmp     bx, D1L
  9345 00002B45 83FB74              <1> 	cmp	ebx, D1L
  9346 00002B48 7308                <1> 	jnb	short BAD_COMMAND
  9347                              <1>         ;xchg    bx, si
  9348 00002B4A 87DE                <1>         xchg	ebx, esi
  9349                              <1> 	;;;POP	AX			; RESTORE AX
  9350                              <1> 	;;;POP	BX			; AND DATA ADDRESS
  9351                              <1> 	
  9352                              <1> 	;;PUSH	CX
  9353                              <1> 	;;PUSH	AX			; ADJUST ES:BX
  9354                              <1> 	;MOV	CX,BX			; GET 3 HIGH ORDER NIBBLES OF BX
  9355                              <1> 	;SHR	CX,4
  9356                              <1> 	;MOV	AX,ES
  9357                              <1> 	;ADD	AX,CX
  9358                              <1> 	;MOV	ES,AX
  9359                              <1> 	;AND	BX,000FH		; ES:BX CHANGED TO ES:000X
  9360                              <1> 	;;POP	AX
  9361                              <1> 	;;POP	CX
  9362                              <1> 	;;JMP	word [CS:SI+D1]
  9363                              <1> 	;jmp	word [SI+D1]
  9364 00002B4C FFA6[9A290000]      <1> 	jmp	dword [esi+D1]
  9365                              <1> ;;BAD_COMMAND_POP:
  9366                              <1> ;;	POP	AX
  9367                              <1> ;;	POP	BX
  9368                              <1> BAD_COMMAND:
  9369 00002B52 C605[17C50000]01    <1>         MOV     byte [DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9370 00002B59 B000                <1> 	MOV	AL,0
  9371 00002B5B C3                  <1> 	RETn
  9372                              <1> 
  9373                              <1> ;----------------------------------------
  9374                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  9375                              <1> ;----------------------------------------
  9376                              <1> 
  9377                              <1> ; 18-1-2015 : one controller reset (not other one)
  9378                              <1> 
  9379                              <1> DISK_RESET:
  9380 00002B5C FA                  <1> 	CLI
  9381 00002B5D E4A1                <1> 	IN	AL,INTB01		; GET THE MASK REGISTER
  9382                              <1> 	;JMP	$+2
  9383                              <1> 	IODELAY
  9384 00002B5F EB00                <2>  jmp short $+2
  9385 00002B61 EB00                <2>  jmp short $+2
  9386                              <1> 	;AND	AL,0BFH 		; ENABLE FIXED DISK INTERRUPT
  9387 00002B63 243F                <1> 	and	al,3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  9388 00002B65 E6A1                <1> 	OUT	INTB01,AL
  9389 00002B67 FB                  <1> 	STI				; START INTERRUPTS
  9390                              <1> 	; 14/02/2015
  9391 00002B68 6689D7              <1> 	mov	di, dx	
  9392                              <1> 	; 04/01/2015
  9393                              <1> 	;xor	di,di
  9394                              <1> drst0:
  9395 00002B6B B004                <1> 	MOV	AL,04H  ; bit 2 - SRST 
  9396                              <1> 	;MOV	DX,HF_REG_PORT
  9397 00002B6D 668B15[46BF0000]    <1> 	MOV	DX,[HF_REG_PORT]
  9398 00002B74 EE                  <1> 	OUT	DX,AL			; RESET
  9399                              <1> ;	MOV	CX,10			; DELAY COUNT
  9400                              <1> ;DRD:	DEC	CX
  9401                              <1> ;	JNZ	short DRD		; WAIT 4.8 MICRO-SEC
  9402                              <1> 	;mov	cx,2			; wait for 30 micro seconds	
  9403 00002B75 B902000000          <1>         mov	ecx, 2 ; 21/02/2015
  9404 00002B7A E871EDFFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  9405                              <1>                                         ; 40 micro seconds)
  9406 00002B7F A0[19C50000]        <1> 	mov	al,[CONTROL_BYTE]
  9407 00002B84 240F                <1> 	AND	AL,0FH			; SET HEAD OPTION
  9408 00002B86 EE                  <1> 	OUT	DX,AL			; TURN RESET OFF
  9409 00002B87 E814040000          <1> 	CALL	NOT_BUSY
  9410 00002B8C 7515                <1> 	JNZ	short DRERR		; TIME OUT ON RESET
  9411 00002B8E 668B15[44BF0000]    <1> 	MOV	DX,[HF_PORT]
  9412 00002B95 FEC2                <1> 	inc	dl  ; HF_PORT+1
  9413                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  9414                              <1>         ;mov     cl, 10
  9415 00002B97 B90A000000          <1>         mov     ecx, 10 ; 21/02/2015 
  9416                              <1> drst1:
  9417 00002B9C EC                  <1> 	IN	AL,DX			; GET RESET STATUS
  9418 00002B9D 3C01                <1> 	CMP	AL,1
  9419                              <1> 	; 04/01/2015
  9420 00002B9F 740A                <1> 	jz	short drst2
  9421                              <1> 	;JNZ	short DRERR		; BAD RESET STATUS
  9422                              <1>         	; Drive/Head Register - bit 4
  9423 00002BA1 E2F9                <1> 	loop	drst1
  9424                              <1> DRERR:	
  9425 00002BA3 C605[17C50000]05    <1> 	MOV	byte [DISK_STATUS1],BAD_RESET ; CARD FAILED
  9426 00002BAA C3                  <1> 	RETn
  9427                              <1> drst2:
  9428                              <1> 	; 14/02/2015
  9429 00002BAB 6689FA              <1> 	mov	dx,di
  9430                              <1> ;drst3:
  9431                              <1> ;	; 05/01/2015
  9432                              <1> ;	shl 	di,1
  9433                              <1> ;	; 04/01/2015
  9434                              <1> ;	mov	ax,[di+hd_cports]
  9435                              <1> ;	cmp	ax,[HF_REG_PORT]
  9436                              <1> ;	je	short drst4
  9437                              <1> ;	mov	[HF_REG_PORT], ax
  9438                              <1> ;	; 03/01/2015
  9439                              <1> ;	mov	ax,[di+hd_ports]
  9440                              <1> ;       mov     [HF_PORT], ax
  9441                              <1> ;	; 05/01/2014
  9442                              <1> ;	shr	di,1
  9443                              <1> ;	; 04/01/2015
  9444                              <1> ;	jmp	short drst0	; reset other controller
  9445                              <1> ;drst4:
  9446                              <1> ;	; 05/01/2015
  9447                              <1> ;	shr	di,1
  9448                              <1> ;	mov	al,[di+hd_dregs]
  9449                              <1> ;	and	al,10h ; bit 4 only
  9450                              <1> ;	shr	al,4 ; bit 4  -> bit 0
  9451                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  9452                              <1> 	;
  9453 00002BAE A0[48BF0000]        <1> 	mov	al, [hf_m_s] ; 18/01/2015
  9454 00002BB3 A801                <1> 	test	al,1
  9455                              <1> ;	jnz	short drst6
  9456 00002BB5 7516                <1>         jnz     short drst4
  9457 00002BB7 8065FDEF            <1> 	AND     byte [CMD_BLOCK+5],0EFH ; SET TO DRIVE 0
  9458                              <1> ;drst5:
  9459                              <1> drst3:
  9460 00002BBB E811010000          <1> 	CALL	INIT_DRV		; SET MAX HEADS
  9461                              <1> 	;mov	dx,di
  9462 00002BC0 E8C9010000          <1> 	CALL	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  9463                              <1> 	; 04/01/2014
  9464                              <1> ;	inc	di
  9465                              <1> ;	mov	dx,di
  9466                              <1> ;	cmp	dl,[HF_NUM]
  9467                              <1> ;	jb	short drst3
  9468                              <1> ;DRE:
  9469 00002BC5 C605[17C50000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; IGNORE ANY SET UP ERRORS
  9470 00002BCC C3                  <1> 	RETn
  9471                              <1> ;drst6:
  9472                              <1> drst4:		; Drive/Head Register - bit 4
  9473 00002BCD 804DFD10            <1> 	OR      byte [CMD_BLOCK+5],010H ; SET TO DRIVE 1     
  9474                              <1>         ;jmp    short drst5
  9475 00002BD1 EBE8                <1>         jmp     short drst3
  9476                              <1> 
  9477                              <1> ;----------------------------------------
  9478                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  9479                              <1> ;----------------------------------------
  9480                              <1> 
  9481                              <1> RETURN_STATUS:
  9482 00002BD3 A0[17C50000]        <1> 	MOV	AL,[DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  9483 00002BD8 C605[17C50000]00    <1>         MOV     byte [DISK_STATUS1],0   ; RESET STATUS
  9484 00002BDF C3                  <1> 	RETn
  9485                              <1> 
  9486                              <1> ;----------------------------------------
  9487                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  9488                              <1> ;----------------------------------------
  9489                              <1> 
  9490                              <1> DISK_READ:
  9491 00002BE0 C645FE20            <1> 	MOV	byte [CMD_BLOCK+6],READ_CMD
  9492 00002BE4 E930020000          <1>         JMP     COMMANDI
  9493                              <1> 
  9494                              <1> ;----------------------------------------
  9495                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  9496                              <1> ;----------------------------------------
  9497                              <1> 
  9498                              <1> DISK_WRITE:
  9499 00002BE9 C645FE30            <1> 	MOV	byte [CMD_BLOCK+6],WRITE_CMD
  9500 00002BED E982020000          <1>         JMP     COMMANDO
  9501                              <1> 
  9502                              <1> ;----------------------------------------
  9503                              <1> ;	DISK VERIFY	     (AH = 04H) :
  9504                              <1> ;----------------------------------------
  9505                              <1> 
  9506                              <1> DISK_VERF:
  9507 00002BF2 C645FE40            <1> 	MOV	byte [CMD_BLOCK+6],VERIFY_CMD
  9508 00002BF6 E8F0020000          <1> 	CALL	COMMAND
  9509 00002BFB 750C                <1> 	JNZ	short VERF_EXIT		; CONTROLLER STILL BUSY
  9510 00002BFD E862030000          <1> 	CALL	_WAIT			; (Original: CALL WAIT)	
  9511 00002C02 7505                <1> 	JNZ	short VERF_EXIT		; TIME OUT
  9512 00002C04 E8EF030000          <1> 	CALL	CHECK_STATUS
  9513                              <1> VERF_EXIT:
  9514 00002C09 C3                  <1> 	RETn
  9515                              <1> 
  9516                              <1> ;----------------------------------------
  9517                              <1> ;	FORMATTING	     (AH = 05H) :
  9518                              <1> ;----------------------------------------
  9519                              <1> 
  9520                              <1> FMT_TRK:				; FORMAT TRACK	(AH = 005H)
  9521 00002C0A C645FE50            <1> 	MOV	byte [CMD_BLOCK+6],FMTTRK_CMD
  9522                              <1> 	;PUSH	ES
  9523                              <1> 	;PUSH	BX
  9524 00002C0E 53                  <1> 	push	ebx
  9525 00002C0F E896040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  9526                              <1> 	;MOV	AL,[ES:BX+14]		; GET SECTORS/TRACK
  9527 00002C14 8A430E              <1> 	mov	al, [ebx+14]
  9528 00002C17 8845F9              <1> 	MOV	[CMD_BLOCK+1],AL 	; SET SECTOR COUNT IN COMMAND
  9529 00002C1A 5B                  <1> 	pop	ebx
  9530                              <1> 	;POP	BX
  9531                              <1> 	;POP	ES
  9532 00002C1B E95B020000          <1>         JMP     CMD_OF                  ; GO EXECUTE THE COMMAND
  9533                              <1> 
  9534                              <1> ;----------------------------------------
  9535                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  9536                              <1> ;----------------------------------------
  9537                              <1> 
  9538                              <1> READ_DASD_TYPE:
  9539                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  9540 00002C20 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9541                              <1> 	;PUSH	ES
  9542 00002C21 53                  <1> 	PUSH	eBX
  9543                              <1> 	;CALL	DDS			; ESTABLISH ADDRESSING
  9544                              <1> 	;push	cs
  9545                              <1> 	;pop	ds
  9546 00002C22 66BB1000            <1>         mov	bx, KDATA
  9547 00002C26 8EDB                <1> 	mov	ds, bx
  9548                              <1> 	;mov	es, bx
  9549 00002C28 C605[17C50000]00    <1> 	MOV     byte [DISK_STATUS1],0
  9550 00002C2F 8A1D[18C50000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9551 00002C35 80E27F              <1> 	AND	DL,7FH			; GET DRIVE NUMBER
  9552 00002C38 38D3                <1> 	CMP	BL,DL
  9553 00002C3A 7625                <1> 	JBE	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  9554 00002C3C E869040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETER ADDRESS
  9555                              <1> 	;MOV	AL,[ES:BX+2]		; HEADS
  9556 00002C41 8A4302              <1> 	mov	al, [ebx+2]
  9557                              <1> 	;MOV	CL,[ES:BX+14]
  9558 00002C44 8A4B0E              <1> 	mov	cl, [ebx+14]
  9559 00002C47 F6E9                <1> 	IMUL	CL			; * NUMBER OF SECTORS
  9560                              <1> 	;MOV	CX,[ES:BX]		; MAX NUMBER OF CYLINDERS
  9561 00002C49 668B0B              <1> 	mov	cx ,[ebx]
  9562                              <1> 	;
  9563                              <1> 	; 02/01/2015 
  9564                              <1> 	; ** leave the last cylinder as reserved for diagnostics **
  9565                              <1> 	; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  9566 00002C4C 6649                <1> 	DEC	CX			; LEAVE ONE FOR DIAGNOSTICS
  9567                              <1> 	;
  9568 00002C4E 66F7E9              <1> 	IMUL	CX			; NUMBER OF SECTORS
  9569 00002C51 6689D1              <1> 	MOV	CX,DX			; HIGH ORDER HALF
  9570 00002C54 6689C2              <1> 	MOV	DX,AX			; LOW ORDER HALF
  9571                              <1> 	;SUB	AX,AX
  9572 00002C57 28C0                <1> 	sub	al, al
  9573 00002C59 B403                <1> 	MOV	AH,03H			; INDICATE FIXED DISK
  9574 00002C5B 5B                  <1> RDT2:	POP	eBX			; RESTORE REGISTERS
  9575                              <1> 	;POP	ES
  9576 00002C5C 1F                  <1> 	POP	DS
  9577 00002C5D F8                  <1> 	CLC				; CLEAR CARRY
  9578                              <1> 	;RETf	2
  9579 00002C5E CA0400              <1> 	retf	4
  9580                              <1> RDT_NOT_PRESENT:
  9581 00002C61 6629C0              <1> 	SUB	AX,AX			; DRIVE NOT PRESENT RETURN
  9582 00002C64 6689C1              <1> 	MOV	CX,AX			; ZERO BLOCK COUNT
  9583 00002C67 6689C2              <1> 	MOV	DX,AX
  9584 00002C6A EBEF                <1> 	JMP	short RDT2
  9585                              <1> 
  9586                              <1> ;----------------------------------------
  9587                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  9588                              <1> ;----------------------------------------
  9589                              <1> 
  9590                              <1> GET_PARM_N:
  9591                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  9592 00002C6C 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9593                              <1> 	;PUSH	ES
  9594 00002C6D 53                  <1> 	PUSH	eBX
  9595                              <1> 	;MOV	AX,ABS0 		; ESTABLISH ADDRESSING
  9596                              <1> 	;MOV	DS,AX
  9597                              <1> 	;TEST	DL,1			; CHECK FOR DRIVE 1
  9598                              <1> 	;JZ	short G0
  9599                              <1> 	;LES	BX,@HF1_TBL_VEC
  9600                              <1> 	;JMP	SHORT G1
  9601                              <1> ;G0:	LES	BX,@HF_TBL_VEC
  9602                              <1> ;G1:
  9603                              <1> 	;CALL	DDS			; ESTABLISH SEGMENT
  9604                              <1> 	; 22/12/2014
  9605                              <1> 	;push	cs
  9606                              <1> 	;pop	ds
  9607 00002C6E 66BB1000            <1> 	mov	bx, KDATA
  9608 00002C72 8EDB                <1> 	mov	ds, bx
  9609                              <1> 	;mov	es, bx
  9610                              <1> 	;
  9611 00002C74 80EA80              <1> 	SUB	DL,80H
  9612 00002C77 80FA04              <1> 	CMP	DL,MAX_FILE		; TEST WITHIN RANGE
  9613 00002C7A 7341                <1> 	JAE	short G4
  9614                              <1> 	;
  9615 00002C7C 31DB                <1> 	xor	ebx, ebx ; 21/02/2015
  9616                              <1> 	; 22/12/2014
  9617 00002C7E 88D3                <1> 	mov	bl, dl
  9618                              <1> 	;xor	bh, bh  
  9619 00002C80 C0E302              <1> 	shl	bl, 2			; convert index to offset
  9620                              <1> 	;add	bx, HF_TBL_VEC
  9621 00002C83 81C3[1CC50000]      <1> 	add	ebx, HF_TBL_VEC
  9622                              <1> 	;mov	ax, [bx+2]
  9623                              <1> 	;mov	es, ax			; dpt segment
  9624                              <1> 	;mov	bx, [bx]		; dpt offset
  9625 00002C89 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  9626                              <1> 
  9627 00002C8B C605[17C50000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9628                              <1>         ;MOV     AX,[ES:BX]              ; MAX NUMBER OF CYLINDERS
  9629 00002C92 668B03              <1> 	mov	ax, [ebx]
  9630                              <1> 	;;SUB	AX,2			; ADJUST FOR 0-N
  9631 00002C95 6648                <1> 	dec	ax			; max. cylinder number
  9632 00002C97 88C5                <1> 	MOV	CH,AL
  9633 00002C99 66250003            <1> 	AND	AX,0300H		; HIGH TWO BITS OF CYLINDER
  9634 00002C9D 66D1E8              <1> 	SHR	AX,1
  9635 00002CA0 66D1E8              <1> 	SHR	AX,1
  9636                              <1> 	;OR	AL,[ES:BX+14]		; SECTORS
  9637 00002CA3 0A430E              <1> 	or	al, [ebx+14]
  9638 00002CA6 88C1                <1> 	MOV	CL,AL
  9639                              <1> 	;MOV	DH,[ES:BX+2]		; HEADS
  9640 00002CA8 8A7302              <1> 	mov	dh, [ebx+2]
  9641 00002CAB FECE                <1> 	DEC	DH			; 0-N RANGE
  9642 00002CAD 8A15[18C50000]      <1> 	MOV	DL,[HF_NUM]		; DRIVE COUNT
  9643 00002CB3 6629C0              <1> 	SUB	AX,AX
  9644                              <1>         ;27/12/2014 
  9645                              <1> 	; ES:DI = Address of disk parameter table from BIOS
  9646                              <1> 	;(Programmer's Guide to the AMIBIOS - 1993)
  9647                              <1> 	;mov	di, bx			; HDPT offset
  9648 00002CB6 89DF                <1> 	mov	edi, ebx
  9649                              <1> G5:
  9650 00002CB8 5B                  <1> 	POP	eBX			; RESTORE REGISTERS
  9651                              <1> 	;POP	ES
  9652 00002CB9 1F                  <1> 	POP	DS
  9653                              <1> 	;RETf	2
  9654 00002CBA CA0400              <1> 	retf	4
  9655                              <1> G4:
  9656 00002CBD C605[17C50000]07    <1> 	MOV     byte [DISK_STATUS1],INIT_FAIL ; OPERATION FAILED
  9657 00002CC4 B407                <1> 	MOV	AH,INIT_FAIL
  9658 00002CC6 28C0                <1> 	SUB	AL,AL
  9659 00002CC8 6629D2              <1> 	SUB	DX,DX
  9660 00002CCB 6629C9              <1> 	SUB	CX,CX
  9661 00002CCE F9                  <1> 	STC				; SET ERROR FLAG
  9662 00002CCF EBE7                <1> 	JMP	short G5
  9663                              <1> 
  9664                              <1> ;----------------------------------------
  9665                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  9666                              <1> ;----------------------------------------
  9667                              <1> 	; 03/01/2015
  9668                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  9669                              <1> 	; logical sector per logical track
  9670                              <1> 	; and logical heads - 1 would be set but
  9671                              <1> 	; it is seen as it will be good
  9672                              <1> 	; if physical parameters will be set here
  9673                              <1> 	; because, number of heads <= 16.
  9674                              <1> 	; (logical heads usually more than 16)
  9675                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  9676                              <1> 	;	== INT 13h physical parameters
  9677                              <1> 
  9678                              <1> ;INIT_DRV:
  9679                              <1> ;	MOV	byte [CMD_BLOCK+6],SET_PARM_CMD
  9680                              <1> ;	CALL	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  9681                              <1> ;	MOV	AL,[ES:BX+2]		; GET NUMBER OF HEADS
  9682                              <1> ;	DEC	AL			; CONVERT TO 0-INDEX
  9683                              <1> ;	MOV	AH,[CMD_BLOCK+5] 	; GET SDH REGISTER
  9684                              <1> ;	AND	AH,0F0H 		; CHANGE HEAD NUMBER
  9685                              <1> ;	OR	AH,AL			; TO MAX HEAD
  9686                              <1> ;	MOV	[CMD_BLOCK+5],AH
  9687                              <1> ;	MOV	AL,[ES:BX+14]		; MAX SECTOR NUMBER
  9688                              <1> ;	MOV	[CMD_BLOCK+1],AL
  9689                              <1> ;	SUB	AX,AX
  9690                              <1> ;	MOV	[CMD_BLOCK+3],AL 	; ZERO FLAGS
  9691                              <1> ;	CALL	COMMAND 		; TELL CONTROLLER
  9692                              <1> ;	JNZ	short INIT_EXIT		; CONTROLLER BUSY ERROR
  9693                              <1> ;	CALL	NOT_BUSY		; WAIT FOR IT TO BE DONE
  9694                              <1> ;	JNZ	short INIT_EXIT		; TIME OUT
  9695                              <1> ;	CALL	CHECK_STATUS
  9696                              <1> ;INIT_EXIT:
  9697                              <1> ;	RETn
  9698                              <1> 
  9699                              <1> ; 04/01/2015
  9700                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  9701                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  9702                              <1> INIT_DRV:
  9703                              <1> 	;xor	ah,ah
  9704 00002CD1 31C0                <1> 	xor	eax, eax ; 21/02/2015
  9705 00002CD3 B00B                <1> 	mov	al,11 ; Physical heads from translated HDPT
  9706 00002CD5 3825[2CC50000]      <1>         cmp     [LBAMode], ah   ; 0
  9707 00002CDB 7702                <1> 	ja	short idrv0
  9708 00002CDD B002                <1> 	mov	al,2  ; Physical heads from standard HDPT
  9709                              <1> idrv0:
  9710                              <1> 	; DL = drive number (0 based)
  9711 00002CDF E8C6030000          <1> 	call	GET_VEC
  9712                              <1> 	;push	bx
  9713 00002CE4 53                  <1> 	push	ebx ; 21/02/2015
  9714                              <1> 	;add	bx,ax
  9715 00002CE5 01C3                <1> 	add	ebx, eax
  9716                              <1> 	;; 05/01/2015
  9717 00002CE7 8A25[48BF0000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  9718                              <1> 	;;and 	ah,1 
  9719 00002CED C0E404              <1> 	shl	ah,4
  9720 00002CF0 80CCA0              <1> 	or	ah,0A0h  ; Drive/Head register - 10100000b (A0h)	
  9721                              <1> 	;mov	al,[es:bx]
  9722 00002CF3 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  9723 00002CF5 FEC8                <1> 	dec	al	 ; last head number 
  9724                              <1> 	;and	al,0Fh
  9725 00002CF7 08E0                <1> 	or	al,ah	 ; lower 4 bits for head number
  9726                              <1> 	;
  9727 00002CF9 C645FE91            <1> 	mov	byte [CMD_BLOCK+6],SET_PARM_CMD
  9728 00002CFD 8845FD              <1> 	mov	[CMD_BLOCK+5],al
  9729                              <1> 	;pop	bx
  9730 00002D00 5B                  <1> 	pop	ebx
  9731 00002D01 29C0                <1> 	sub	eax, eax ; 21/02/2015
  9732 00002D03 B004                <1> 	mov	al,4 ; Physical sec per track from translated HDPT
  9733 00002D05 803D[2CC50000]00    <1> 	cmp	byte [LBAMode], 0
  9734 00002D0C 7702                <1> 	ja	short idrv1
  9735 00002D0E B00E                <1> 	mov	al,14 ; Physical sec per track from standard HDPT
  9736                              <1> idrv1:
  9737                              <1> 	;xor	ah,ah
  9738                              <1> 	;add	bx,ax
  9739 00002D10 01C3                <1> 	add	ebx, eax ; 21/02/2015
  9740                              <1> 	;mov	al,[es:bx]
  9741                              <1> 			; sector number
  9742 00002D12 8A03                <1> 	mov	al, [ebx]
  9743 00002D14 8845F9              <1> 	mov	[CMD_BLOCK+1],al
  9744 00002D17 28C0                <1> 	sub	al,al
  9745 00002D19 8845FB              <1> 	mov	[CMD_BLOCK+3],al  ; ZERO FLAGS
  9746 00002D1C E8CA010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  9747 00002D21 750C                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  9748 00002D23 E878020000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  9749 00002D28 7505                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  9750 00002D2A E8C9020000          <1> 	call	CHECK_STATUS
  9751                              <1> INIT_EXIT:
  9752 00002D2F C3                  <1> 	RETn
  9753                              <1> 
  9754                              <1> ;----------------------------------------
  9755                              <1> ;	READ LONG	     (AH = 0AH) :
  9756                              <1> ;----------------------------------------
  9757                              <1> 
  9758                              <1> RD_LONG:
  9759                              <1> 	;MOV	@CMD_BLOCK+6,READ_CMD OR ECC_MODE
  9760 00002D30 C645FE22            <1>         mov     byte [CMD_BLOCK+6],READ_CMD + ECC_MODE 
  9761 00002D34 E9E0000000          <1>         JMP     COMMANDI
  9762                              <1> 
  9763                              <1> ;----------------------------------------
  9764                              <1> ;	WRITE LONG	     (AH = 0BH) :
  9765                              <1> ;----------------------------------------
  9766                              <1> 
  9767                              <1> WR_LONG:
  9768                              <1> 	;MOV	@CMD_BLOCK+6,WRITE_CMD OR ECC_MODE
  9769 00002D39 C645FE32            <1>         MOV     byte [CMD_BLOCK+6],WRITE_CMD + ECC_MODE
  9770 00002D3D E932010000          <1>         JMP     COMMANDO
  9771                              <1> 
  9772                              <1> ;----------------------------------------
  9773                              <1> ;	SEEK		     (AH = 0CH) :
  9774                              <1> ;----------------------------------------
  9775                              <1> 
  9776                              <1> DISK_SEEK:
  9777 00002D42 C645FE70            <1>         MOV     byte [CMD_BLOCK+6],SEEK_CMD
  9778 00002D46 E8A0010000          <1> 	CALL	COMMAND
  9779 00002D4B 751C                <1> 	JNZ	short DS_EXIT 		; CONTROLLER BUSY ERROR
  9780 00002D4D E812020000          <1> 	CALL	_WAIT
  9781 00002D52 7515                <1>         JNZ     DS_EXIT                 ; TIME OUT ON SEEK
  9782 00002D54 E89F020000          <1> 	CALL	CHECK_STATUS
  9783 00002D59 803D[17C50000]40    <1>         CMP     byte [DISK_STATUS1],BAD_SEEK
  9784 00002D60 7507                <1> 	JNE	short DS_EXIT
  9785 00002D62 C605[17C50000]00    <1>         MOV     byte [DISK_STATUS1],0
  9786                              <1> DS_EXIT:
  9787 00002D69 C3                  <1> 	RETn
  9788                              <1> 
  9789                              <1> ;----------------------------------------
  9790                              <1> ;	TEST DISK READY      (AH = 10H) :
  9791                              <1> ;----------------------------------------
  9792                              <1> 
  9793                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  9794 00002D6A E831020000          <1> 	CALL	NOT_BUSY
  9795 00002D6F 751C                <1> 	JNZ	short TR_EX
  9796 00002D71 8A45FD              <1> 	MOV	AL,[CMD_BLOCK+5] 	; SELECT DRIVE
  9797 00002D74 668B15[44BF0000]    <1> 	MOV	DX,[HF_PORT]
  9798 00002D7B 80C206              <1> 	add	dl,6
  9799 00002D7E EE                  <1> 	OUT	DX,AL
  9800 00002D7F E88C020000          <1> 	CALL	CHECK_ST		; CHECK STATUS ONLY
  9801 00002D84 7507                <1> 	JNZ	short TR_EX
  9802 00002D86 C605[17C50000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; WIPE OUT DATA CORRECTED ERROR
  9803                              <1> TR_EX:	
  9804 00002D8D C3                  <1> 	RETn
  9805                              <1> 
  9806                              <1> ;----------------------------------------
  9807                              <1> ;	RECALIBRATE	     (AH = 11H) :
  9808                              <1> ;----------------------------------------
  9809                              <1> 
  9810                              <1> HDISK_RECAL:
  9811 00002D8E C645FE10            <1>         MOV     byte [CMD_BLOCK+6],RECAL_CMD ; 10h, 16
  9812 00002D92 E854010000          <1> 	CALL	COMMAND 		; START THE OPERATION
  9813 00002D97 7523                <1> 	JNZ	short RECAL_EXIT	; ERROR
  9814 00002D99 E8C6010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION
  9815 00002D9E 7407                <1> 	JZ	short RECAL_X 		; TIME OUT ONE OK ?
  9816 00002DA0 E8BF010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION LONGER
  9817 00002DA5 7515                <1> 	JNZ	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  9818                              <1> RECAL_X:
  9819 00002DA7 E84C020000          <1> 	CALL	CHECK_STATUS
  9820 00002DAC 803D[17C50000]40    <1> 	CMP	byte [DISK_STATUS1],BAD_SEEK ; SEEK NOT COMPLETE
  9821 00002DB3 7507                <1> 	JNE	short RECAL_EXIT	; IS OK
  9822 00002DB5 C605[17C50000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9823                              <1> RECAL_EXIT:
  9824 00002DBC 803D[17C50000]00    <1>         CMP     byte [DISK_STATUS1],0
  9825 00002DC3 C3                  <1> 	RETn
  9826                              <1> 
  9827                              <1> ;----------------------------------------
  9828                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  9829                              <1> ;----------------------------------------
  9830                              <1> 
  9831                              <1> CTLR_DIAGNOSTIC:
  9832 00002DC4 FA                  <1>         CLI                             ; DISABLE INTERRUPTS WHILE CHANGING MASK
  9833 00002DC5 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  9834                              <1> 	;AND	AL,0BFH
  9835 00002DC7 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  9836                              <1> 	;JMP	$+2
  9837                              <1> 	IODELAY
  9838 00002DC9 EB00                <2>  jmp short $+2
  9839 00002DCB EB00                <2>  jmp short $+2
  9840 00002DCD E6A1                <1> 	OUT	INTB01,AL
  9841                              <1> 	IODELAY
  9842 00002DCF EB00                <2>  jmp short $+2
  9843 00002DD1 EB00                <2>  jmp short $+2
  9844 00002DD3 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  9845 00002DD5 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  9846                              <1> 	;JMP	$+2
  9847                              <1> 	IODELAY
  9848 00002DD7 EB00                <2>  jmp short $+2
  9849 00002DD9 EB00                <2>  jmp short $+2
  9850 00002DDB E621                <1> 	OUT	INTA01,AL
  9851 00002DDD FB                  <1> 	STI
  9852 00002DDE E8BD010000          <1> 	CALL	NOT_BUSY		; WAIT FOR CARD
  9853 00002DE3 752B                <1> 	JNZ	short CD_ERR		; BAD CARD
  9854                              <1> 	;MOV	DX, HF_PORT+7
  9855 00002DE5 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
  9856 00002DEC 80C207              <1> 	add	dl, 7
  9857 00002DEF B090                <1> 	MOV	AL,DIAG_CMD		; START DIAGNOSE
  9858 00002DF1 EE                  <1> 	OUT	DX,AL
  9859 00002DF2 E8A9010000          <1> 	CALL	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  9860 00002DF7 B480                <1> 	MOV	AH,TIME_OUT
  9861 00002DF9 7517                <1> 	JNZ	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  9862                              <1> 	;MOV	DX,HF_PORT+1		; GET ERROR REGISTER
  9863 00002DFB 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
  9864 00002E02 FEC2                <1> 	inc	dl
  9865 00002E04 EC                  <1> 	IN	AL,DX
  9866 00002E05 A2[0EC50000]        <1> 	MOV	[HF_ERROR],AL		; SAVE IT
  9867 00002E0A B400                <1> 	MOV	AH,0
  9868 00002E0C 3C01                <1> 	CMP	AL,1			; CHECK FOR ALL OK
  9869 00002E0E 7402                <1> 	JE	SHORT CD_EXIT
  9870 00002E10 B420                <1> CD_ERR: MOV	AH,BAD_CNTLR
  9871                              <1> CD_EXIT:
  9872 00002E12 8825[17C50000]      <1> 	MOV	[DISK_STATUS1],AH
  9873 00002E18 C3                  <1> 	RETn
  9874                              <1> 
  9875                              <1> ;----------------------------------------
  9876                              <1> ; COMMANDI				:
  9877                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  9878                              <1> ;	NSECTOR RETURNS ZERO		:
  9879                              <1> ;----------------------------------------
  9880                              <1> COMMANDI:
  9881 00002E19 E862020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9882 00002E1E 7253                <1> 	JC	short CMD_ABORT
  9883                              <1> 	;MOV	DI,BX
  9884 00002E20 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  9885 00002E22 E8C4000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9886 00002E27 754A                <1> 	JNZ	short CMD_ABORT
  9887                              <1> CMD_I1:
  9888 00002E29 E836010000          <1> 	CALL	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  9889 00002E2E 7543                <1> 	JNZ	short TM_OUT		; TIME OUT
  9890                              <1> cmd_i1x: ; 18/02/2016
  9891                              <1> 	;MOV	CX,256			; SECTOR SIZE IN WORDS
  9892 00002E30 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015	
  9893                              <1> 	;MOV	DX,HF_PORT
  9894 00002E35 668B15[44BF0000]    <1> 	mov	dx,[HF_PORT]
  9895 00002E3C FA                  <1> 	CLI
  9896 00002E3D FC                  <1> 	CLD
  9897 00002E3E F3666D              <1> 	REP	INSW			; GET THE SECTOR
  9898 00002E41 FB                  <1> 	STI
  9899 00002E42 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL INPUT
  9900 00002E46 7419                <1> 	JZ	short CMD_I3
  9901 00002E48 E880010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9902 00002E4D 7224                <1> 	JC	short TM_OUT
  9903                              <1> 	;MOV	DX,HF_PORT
  9904 00002E4F 668B15[44BF0000]    <1> 	mov	dx,[HF_PORT]
  9905                              <1> 	;MOV	CX,4			; GET ECC BYTES
  9906 00002E56 B904000000          <1> 	mov 	ecx, 4 ; mov cx, 4 
  9907 00002E5B EC                  <1> CMD_I2: IN	AL,DX
  9908                              <1> 	;MOV	[ES:DI],AL		; GO SLOW FOR BOARD
  9909 00002E5C 8807                <1> 	mov 	[edi], al ; 21/02/2015
  9910 00002E5E 47                  <1> 	INC	eDI
  9911 00002E5F E2FA                <1> 	LOOP	CMD_I2
  9912                              <1> CMD_I3: 
  9913                              <1> 	; wait for 400 ns
  9914 00002E61 80C207              <1> 	add 	dl, 7
  9915 00002E64 EC                  <1> 	in	al, dx
  9916 00002E65 EC                  <1> 	in	al, dx
  9917 00002E66 EC                  <1> 	in	al, dx
  9918                              <1> 	;
  9919 00002E67 E88C010000          <1> 	CALL	CHECK_STATUS
  9920 00002E6C 7505                <1> 	JNZ	short CMD_ABORT		; ERROR RETURNED
  9921 00002E6E FE4DF9              <1> 	DEC	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  9922                              <1> 	;JNZ	SHORT CMD_I1
  9923 00002E71 75BD                <1> 	jnz	short cmd_i1x ; 18/02/2016
  9924                              <1> CMD_ABORT:
  9925 00002E73 C3                  <1> TM_OUT: RETn
  9926                              <1> 
  9927                              <1> ;----------------------------------------
  9928                              <1> ; COMMANDO				:
  9929                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  9930                              <1> ;	NSECTOR RETURNS ZERO		:
  9931                              <1> ;----------------------------------------
  9932                              <1> COMMANDO:
  9933 00002E74 E807020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9934 00002E79 72F8                <1> 	JC	short CMD_ABORT
  9935 00002E7B 89DE                <1> CMD_OF: MOV	eSI,eBX ; 21/02/2015
  9936 00002E7D E869000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9937 00002E82 75EF                <1> 	JNZ	short CMD_ABORT
  9938 00002E84 E844010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9939 00002E89 72E8                <1> 	JC	short TM_OUT			; TOO LONG
  9940                              <1> CMD_O1: ;PUSH	DS
  9941                              <1> 	;PUSH	ES			; MOVE ES TO DS
  9942                              <1> 	;POP	DS
  9943                              <1> 	;MOV	CX,256			; PUT THE DATA OUT TO THE CARD
  9944                              <1> 	;MOV	DX,HF_PORT
  9945                              <1> 	; 01/02/2015
  9946 00002E8B 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
  9947                              <1> 	;push	es
  9948                              <1> 	;pop	ds
  9949                              <1> 	;mov	cx, 256
  9950 00002E92 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015
  9951 00002E97 FA                  <1> 	CLI
  9952 00002E98 FC                  <1> 	CLD
  9953 00002E99 F3666F              <1> 	REP	OUTSW
  9954 00002E9C FB                  <1> 	STI
  9955                              <1> 	;POP	DS			; RESTORE DS
  9956 00002E9D F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL OUTPUT
  9957 00002EA1 7419                <1> 	JZ	short CMD_O3
  9958 00002EA3 E825010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9959 00002EA8 72C9                <1> 	JC	short TM_OUT
  9960                              <1> 	;MOV	DX,HF_PORT
  9961 00002EAA 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
  9962                              <1> 	;MOV	CX,4			; OUTPUT THE ECC BYTES
  9963 00002EB1 B904000000          <1> 	mov	ecx, 4  ; mov cx, 4
  9964                              <1> CMD_O2: ;MOV	AL,[ES:SI]
  9965 00002EB6 8A06                <1> 	mov	al, [esi]
  9966 00002EB8 EE                  <1> 	OUT	DX,AL
  9967 00002EB9 46                  <1> 	INC	eSI
  9968 00002EBA E2FA                <1> 	LOOP	CMD_O2
  9969                              <1> CMD_O3:
  9970 00002EBC E8A3000000          <1> 	CALL	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  9971 00002EC1 75B0                <1> 	JNZ	short TM_OUT		; ERROR RETURNED
  9972 00002EC3 E830010000          <1> 	CALL	CHECK_STATUS
  9973 00002EC8 75A9                <1> 	JNZ	short CMD_ABORT
  9974 00002ECA F605[0DC50000]08    <1> 	TEST	byte [HF_STATUS],ST_DRQ	; CHECK FOR MORE
  9975 00002ED1 75B8                <1> 	JNZ	SHORT CMD_O1
  9976                              <1> 	;MOV	DX,HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  9977 00002ED3 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
  9978                              <1> 	;add	dl, 2
  9979 00002EDA FEC2                <1> 	inc	dl
  9980 00002EDC FEC2                <1> 	inc	dl
  9981 00002EDE EC                  <1> 	IN	AL,DX			;
  9982 00002EDF A8FF                <1> 	TEST	AL,0FFH 		;
  9983 00002EE1 7407                <1> 	JZ	short CMD_O4			; COUNT = 0  OK
  9984 00002EE3 C605[17C50000]BB    <1> 	MOV	byte [DISK_STATUS1],UNDEF_ERR 
  9985                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  9986                              <1> CMD_O4:
  9987 00002EEA C3                  <1> 	RETn
  9988                              <1> 
  9989                              <1> ;--------------------------------------------------------
  9990                              <1> ; COMMAND						:
  9991                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  9992                              <1> ; OUTPUT						:
  9993                              <1> ;	BL = STATUS					:
  9994                              <1> ;	BH = ERROR REGISTER				:
  9995                              <1> ;--------------------------------------------------------
  9996                              <1> 
  9997                              <1> COMMAND:
  9998 00002EEB 53                  <1> 	PUSH	eBX			; WAIT FOR SEEK COMPLETE AND READY
  9999                              <1> 	;;MOV	CX,DELAY_2		; SET INITIAL DELAY BEFORE TEST
 10000                              <1> COMMAND1:
 10001                              <1> 	;;PUSH	CX			; SAVE LOOP COUNT
 10002 00002EEC E879FEFFFF          <1> 	CALL	TST_RDY 		; CHECK DRIVE READY
 10003                              <1> 	;;POP	CX
 10004 00002EF1 7419                <1> 	JZ	short COMMAND2		; DRIVE IS READY
 10005 00002EF3 803D[17C50000]80    <1>         CMP     byte [DISK_STATUS1],TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
 10006                              <1> 	;JZ	short CMD_TIMEOUT
 10007                              <1> 	;;LOOP	COMMAND1		; KEEP TRYING FOR A WHILE
 10008                              <1> 	;JMP	SHORT COMMAND4		; ITS NOT GOING TO GET READY
 10009 00002EFA 7507                <1> 	jne	short COMMAND4
 10010                              <1> CMD_TIMEOUT:
 10011 00002EFC C605[17C50000]20    <1> 	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10012                              <1> COMMAND4:
 10013 00002F03 5B                  <1> 	POP	eBX
 10014 00002F04 803D[17C50000]00    <1>         CMP     byte [DISK_STATUS1],0   ; SET CONDITION CODE FOR CALLER
 10015 00002F0B C3                  <1> 	RETn
 10016                              <1> COMMAND2:
 10017 00002F0C 5B                  <1> 	POP	eBX
 10018 00002F0D 57                  <1> 	PUSH	eDI
 10019 00002F0E C605[0FC50000]00    <1> 	MOV	byte [HF_INT_FLAG],0	; RESET INTERRUPT FLAG
 10020 00002F15 FA                  <1> 	CLI				; INHIBIT INTERRUPTS WHILE CHANGING MASK
 10021 00002F16 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
 10022                              <1> 	;AND	AL,0BFH
 10023 00002F18 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
 10024                              <1> 	;JMP	$+2
 10025                              <1> 	IODELAY
 10026 00002F1A EB00                <2>  jmp short $+2
 10027 00002F1C EB00                <2>  jmp short $+2
 10028 00002F1E E6A1                <1> 	OUT	INTB01,AL
 10029 00002F20 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
 10030 00002F22 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
 10031                              <1> 	;JMP	$+2
 10032                              <1> 	IODELAY
 10033 00002F24 EB00                <2>  jmp short $+2
 10034 00002F26 EB00                <2>  jmp short $+2
 10035 00002F28 E621                <1> 	OUT	INTA01,AL
 10036 00002F2A FB                  <1> 	STI
 10037 00002F2B 31FF                <1> 	XOR	eDI,eDI			; INDEX THE COMMAND TABLE
 10038                              <1> 	;MOV	DX,HF_PORT+1		; DISK ADDRESS
 10039 00002F2D 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
 10040 00002F34 FEC2                <1> 	inc	dl
 10041 00002F36 F605[19C50000]C0    <1> 	TEST	byte [CONTROL_BYTE],0C0H ; CHECK FOR RETRY SUPPRESSION
 10042 00002F3D 7411                <1> 	JZ	short COMMAND3
 10043 00002F3F 8A45FE              <1> 	MOV	AL, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
 10044 00002F42 24F0                <1> 	AND	AL,0F0H 		; GET RID OF MODIFIERS
 10045 00002F44 3C20                <1> 	CMP	AL,20H			; 20H-40H IS READ, WRITE, VERIFY
 10046 00002F46 7208                <1> 	JB	short COMMAND3
 10047 00002F48 3C40                <1> 	CMP	AL,40H
 10048 00002F4A 7704                <1> 	JA	short COMMAND3
 10049 00002F4C 804DFE01            <1> 	OR	byte [CMD_BLOCK+6],NO_RETRIES 
 10050                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
 10051                              <1> COMMAND3:
 10052 00002F50 8A443DF8            <1> 	MOV	AL,[CMD_BLOCK+eDI]	; GET THE COMMAND STRING BYTE
 10053 00002F54 EE                  <1> 	OUT	DX,AL			; GIVE IT TO CONTROLLER
 10054                              <1> 	IODELAY
 10055 00002F55 EB00                <2>  jmp short $+2
 10056 00002F57 EB00                <2>  jmp short $+2
 10057 00002F59 47                  <1> 	INC	eDI			; NEXT BYTE IN COMMAND BLOCK
 10058 00002F5A 6642                <1> 	INC	DX			; NEXT DISK ADAPTER REGISTER
 10059 00002F5C 6683FF07            <1> 	cmp	di, 7	; 1/1/2015	; ALL DONE?
 10060 00002F60 75EE                <1> 	JNZ	short COMMAND3		; NO--GO DO NEXT ONE
 10061 00002F62 5F                  <1> 	POP	eDI
 10062 00002F63 C3                  <1> 	RETn				; ZERO FLAG IS SET
 10063                              <1> 
 10064                              <1> ;CMD_TIMEOUT:
 10065                              <1> ;	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10066                              <1> ;COMMAND4:
 10067                              <1> ;	POP	BX
 10068                              <1> ;	CMP	[DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10069                              <1> ;	RETn
 10070                              <1> 
 10071                              <1> ;----------------------------------------
 10072                              <1> ;	WAIT FOR INTERRUPT		:
 10073                              <1> ;----------------------------------------
 10074                              <1> ;WAIT:
 10075                              <1> _WAIT:
 10076 00002F64 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10077                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10078                              <1> 	;CLC
 10079                              <1> 	;MOV	AX,9000H		; DEVICE WAIT INTERRUPT
 10080                              <1> 	;INT	15H
 10081                              <1> 	;JC	WT2			; DEVICE TIMED OUT
 10082                              <1> 	;MOV	BL,DELAY_1		; SET DELAY COUNT
 10083                              <1> 
 10084                              <1> 	;mov	bl, WAIT_HDU_INT_HI
 10085                              <1> 	;; 21/02/2015
 10086                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
 10087                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
 10088 00002F65 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
 10089                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
 10090                              <1> ;-----	WAIT LOOP
 10091                              <1> 
 10092                              <1> WT1:	
 10093                              <1> 	;TEST	byte [HF_INT_FLAG],80H	; TEST FOR INTERRUPT
 10094 00002F6A F605[0FC50000]C0    <1> 	test 	byte [HF_INT_FLAG],0C0h
 10095                              <1> 	;LOOPZ	WT1
 10096 00002F71 7517                <1> 	JNZ	short WT3		; INTERRUPT--LETS GO
 10097                              <1> 	;DEC	BL
 10098                              <1> 	;JNZ	short WT1		; KEEP TRYING FOR A WHILE
 10099                              <1> 
 10100                              <1> WT1_hi:
 10101 00002F73 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
 10102 00002F75 A810                <1> 	test	al, 10h			; transition on memory
 10103 00002F77 75FA                <1> 	jnz	short WT1_hi		; refresh.
 10104                              <1> WT1_lo:
 10105 00002F79 E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
 10106 00002F7B A810                <1> 	test	al, 10h			
 10107 00002F7D 74FA                <1> 	jz	short WT1_lo
 10108 00002F7F E2E9                <1> 	loop	WT1
 10109                              <1> 	;;or	bl, bl
 10110                              <1> 	;;jz	short WT2	
 10111                              <1> 	;;dec	bl
 10112                              <1> 	;;jmp	short WT1
 10113                              <1> 	;dec	bl
 10114                              <1> 	;jnz	short WT1	
 10115                              <1> 
 10116 00002F81 C605[17C50000]80    <1> WT2:	MOV	byte [DISK_STATUS1],TIME_OUT ; REPORT TIME OUT ERROR
 10117 00002F88 EB0E                <1> 	JMP	SHORT WT4
 10118 00002F8A C605[17C50000]00    <1> WT3:	MOV	byte [DISK_STATUS1],0
 10119 00002F91 C605[0FC50000]00    <1> 	MOV	byte [HF_INT_FLAG],0
 10120 00002F98 803D[17C50000]00    <1> WT4:	CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10121 00002F9F C3                  <1> 	RETn
 10122                              <1> 
 10123                              <1> ;----------------------------------------
 10124                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
 10125                              <1> ;----------------------------------------
 10126                              <1> NOT_BUSY:
 10127 00002FA0 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10128                              <1> 	;PUSH	eBX
 10129                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10130 00002FA1 668B15[44BF0000]    <1> 	mov	DX, [HF_PORT]
 10131 00002FA8 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
 10132                              <1> 	;MOV	BL,DELAY_1
 10133                              <1> 					; wait for 10 seconds
 10134                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
 10135                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
 10136                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
 10137 00002FAB B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
 10138                              <1> 	;
 10139                              <1> ;;      mov     byte [wait_count], 0    ; Reset wait counter
 10140                              <1> NB1:	
 10141 00002FB0 EC                  <1> 	IN	AL,DX			; CHECK STATUS
 10142                              <1> 	;TEST	AL,ST_BUSY
 10143 00002FB1 2480                <1> 	and	al, ST_BUSY
 10144                              <1> 	;LOOPNZ	NB1
 10145 00002FB3 7410                <1> 	JZ	short NB2		; NOT BUSY--LETS GO
 10146                              <1> 	;DEC	BL			
 10147                              <1> 	;JNZ	short NB1		; KEEP TRYING FOR A WHILE
 10148                              <1> 
 10149 00002FB5 E461                <1> NB1_hi: IN	AL,SYS1			; wait for hi to lo
 10150 00002FB7 A810                <1> 	TEST	AL,010H			; transition on memory
 10151 00002FB9 75FA                <1> 	JNZ	SHORT NB1_hi		; refresh.
 10152 00002FBB E461                <1> NB1_lo: IN	AL,SYS1
 10153 00002FBD A810                <1> 	TEST	AL,010H
 10154 00002FBF 74FA                <1> 	JZ	short NB1_lo
 10155 00002FC1 E2ED                <1> 	LOOP	NB1
 10156                              <1> 	;dec	bl
 10157                              <1> 	;jnz	short NB1
 10158                              <1> 	;
 10159                              <1> ;;      cmp     byte [wait_count], 182  ; 10 seconds (182 timer ticks)
 10160                              <1> ;;	jb	short NB1
 10161                              <1> 	;
 10162                              <1> 	;MOV	[DISK_STATUS1],TIME_OUT	; REPORT TIME OUT ERROR
 10163                              <1> 	;JMP	SHORT NB3
 10164 00002FC3 B080                <1> 	mov	al, TIME_OUT
 10165                              <1> NB2:	
 10166                              <1> 	;MOV	byte [DISK_STATUS1],0
 10167                              <1> ;NB3:	
 10168                              <1> 	;POP	eBX
 10169 00002FC5 A2[17C50000]        <1> 	mov	[DISK_STATUS1], al	;;; will be set after return
 10170                              <1> 	;CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10171 00002FCA 08C0                <1> 	or	al, al			; (zf = 0 --> timeout)
 10172 00002FCC C3                  <1> 	RETn
 10173                              <1> 
 10174                              <1> ;----------------------------------------
 10175                              <1> ;	WAIT FOR DATA REQUEST		:
 10176                              <1> ;----------------------------------------
 10177                              <1> WAIT_DRQ:
 10178                              <1> 	;MOV	CX,DELAY_3
 10179                              <1> 	;MOV	DX,HF_PORT+7
 10180 00002FCD 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
 10181 00002FD4 80C207              <1> 	add	dl, 7
 10182                              <1> 	;;MOV	bl, WAIT_HDU_DRQ_HI	; 0
 10183                              <1> 	;MOV	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
 10184                              <1> 					; (but it is written as 2000
 10185                              <1> 					; micro seconds in ATORGS.ASM file
 10186                              <1> 					; of Award Bios - 1999, D1A0622)
 10187 00002FD7 B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
 10188 00002FDC EC                  <1> WQ_1:	IN	AL,DX			; GET STATUS
 10189 00002FDD A808                <1> 	TEST	AL,ST_DRQ		; WAIT FOR DRQ
 10190 00002FDF 7516                <1> 	JNZ	short WQ_OK
 10191                              <1> 	;LOOP	WQ_1			; KEEP TRYING FOR A SHORT WHILE
 10192                              <1> WQ_hi:	
 10193 00002FE1 E461                <1> 	IN	AL,SYS1			; wait for hi to lo
 10194 00002FE3 A810                <1> 	TEST	AL,010H			; transition on memory
 10195 00002FE5 75FA                <1> 	JNZ	SHORT WQ_hi		; refresh.
 10196 00002FE7 E461                <1> WQ_lo:  IN      AL,SYS1
 10197 00002FE9 A810                <1> 	TEST	AL,010H
 10198 00002FEB 74FA                <1> 	JZ	SHORT WQ_lo
 10199 00002FED E2ED                <1> 	LOOP	WQ_1
 10200                              <1> 
 10201 00002FEF C605[17C50000]80    <1>         MOV     byte [DISK_STATUS1],TIME_OUT ; ERROR
 10202 00002FF6 F9                  <1> 	STC
 10203                              <1> WQ_OK:
 10204 00002FF7 C3                  <1> 	RETn
 10205                              <1> ;WQ_OK:	;CLC
 10206                              <1> ;	RETn
 10207                              <1> 
 10208                              <1> ;----------------------------------------
 10209                              <1> ;	CHECK FIXED DISK STATUS 	:
 10210                              <1> ;----------------------------------------
 10211                              <1> CHECK_STATUS:
 10212 00002FF8 E813000000          <1> 	CALL	CHECK_ST		; CHECK THE STATUS BYTE
 10213 00002FFD 7509                <1> 	JNZ	short CHECK_S1		; AN ERROR WAS FOUND
 10214 00002FFF A801                <1> 	TEST	AL,ST_ERROR		; WERE THERE ANY OTHER ERRORS
 10215 00003001 7405                <1> 	JZ	short CHECK_S1		; NO ERROR REPORTED
 10216 00003003 E849000000          <1> 	CALL	CHECK_ER		; ERROR REPORTED
 10217                              <1> CHECK_S1:
 10218 00003008 803D[17C50000]00    <1> 	CMP	byte [DISK_STATUS1],0 	; SET STATUS FOR CALLER
 10219 0000300F C3                  <1> 	RETn
 10220                              <1> 
 10221                              <1> ;----------------------------------------
 10222                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
 10223                              <1> ;----------------------------------------
 10224                              <1> CHECK_ST:
 10225                              <1> 	;MOV	DX,HF_PORT+7		; GET THE STATUS
 10226 00003010 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]
 10227 00003017 80C207              <1> 	add	dl, 7
 10228                              <1> 	
 10229                              <1> 	; 17/02/2016
 10230                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
 10231                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
 10232 0000301A EC                  <1> 	IN	AL,DX
 10233                              <1> 	;in	al, dx ; 100ns
 10234                              <1> 	;in	al, dx ; 100ns
 10235                              <1>  	;in	al, dx ; 100ns
 10236                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
 10237 0000301B E6EB                <2>  out 0ebh,al
 10238                              <1> 	;
 10239 0000301D A2[0DC50000]        <1> 	MOV	[HF_STATUS],AL
 10240 00003022 B400                <1> 	MOV	AH,0
 10241 00003024 A880                <1> 	TEST	AL,ST_BUSY		; IF STILL BUSY
 10242 00003026 751A                <1> 	JNZ	short CKST_EXIT		;  REPORT OK
 10243 00003028 B4CC                <1> 	MOV	AH,WRITE_FAULT
 10244 0000302A A820                <1> 	TEST	AL,ST_WRT_FLT		; CHECK FOR WRITE FAULT
 10245 0000302C 7514                <1> 	JNZ	short CKST_EXIT
 10246 0000302E B4AA                <1> 	MOV	AH,NOT_RDY
 10247 00003030 A840                <1> 	TEST	AL,ST_READY		; CHECK FOR NOT READY
 10248 00003032 740E                <1> 	JZ	short CKST_EXIT
 10249 00003034 B440                <1> 	MOV	AH,BAD_SEEK
 10250 00003036 A810                <1> 	TEST	AL,ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
 10251 00003038 7408                <1> 	JZ	short CKST_EXIT
 10252 0000303A B411                <1> 	MOV	AH,DATA_CORRECTED
 10253 0000303C A804                <1> 	TEST	AL,ST_CORRCTD		; CHECK FOR CORRECTED ECC
 10254 0000303E 7502                <1> 	JNZ	short CKST_EXIT
 10255 00003040 B400                <1> 	MOV	AH,0
 10256                              <1> CKST_EXIT:
 10257 00003042 8825[17C50000]      <1> 	MOV	[DISK_STATUS1],AH	; SET ERROR FLAG
 10258 00003048 80FC11              <1> 	CMP	AH,DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
 10259 0000304B 7403                <1> 	JZ	short CKST_EX1
 10260 0000304D 80FC00              <1> 	CMP	AH,0
 10261                              <1> CKST_EX1:
 10262 00003050 C3                  <1> 	RETn
 10263                              <1> 
 10264                              <1> ;----------------------------------------
 10265                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
 10266                              <1> ;----------------------------------------
 10267                              <1> CHECK_ER:
 10268                              <1> 	;MOV	DX, HF_PORT+1		; GET THE ERROR REGISTER
 10269 00003051 668B15[44BF0000]    <1> 	mov	dx, [HF_PORT]		;
 10270 00003058 FEC2                <1> 	inc	dl
 10271 0000305A EC                  <1> 	IN	AL,DX
 10272 0000305B A2[0EC50000]        <1> 	MOV	[HF_ERROR],AL
 10273 00003060 53                  <1> 	PUSH	eBX ; 21/02/2015
 10274 00003061 B908000000          <1> 	MOV	eCX,8			; TEST ALL 8 BITS
 10275 00003066 D0E0                <1> CK1:	SHL	AL,1			; MOVE NEXT ERROR BIT TO CARRY
 10276 00003068 7202                <1> 	JC	short CK2		; FOUND THE ERROR
 10277 0000306A E2FA                <1> 	LOOP	CK1			; KEEP TRYING
 10278 0000306C BB[38BF0000]        <1> CK2:	MOV	eBX, ERR_TBL		; COMPUTE ADDRESS OF
 10279 00003071 01CB                <1> 	ADD	eBX,eCX			; ERROR CODE
 10280                              <1> 	;;MOV	AH,BYTE [CS:BX]		; GET ERROR CODE
 10281                              <1> 	;mov	ah, [bx]
 10282 00003073 8A23                <1> 	mov	ah, [ebx] ; 21/02/2015	
 10283 00003075 8825[17C50000]      <1> CKEX:	MOV	[DISK_STATUS1],AH	; SAVE ERROR CODE
 10284 0000307B 5B                  <1> 	POP	eBX
 10285 0000307C 80FC00              <1> 	CMP	AH,0
 10286 0000307F C3                  <1> 	RETn
 10287                              <1> 
 10288                              <1> ;--------------------------------------------------------
 10289                              <1> ; CHECK_DMA						:
 10290                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
 10291                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
 10292                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
 10293                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
 10294                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
 10295                              <1> ;  -ERROR OTHERWISE					:
 10296                              <1> ;--------------------------------------------------------
 10297                              <1> CHECK_DMA:
 10298 00003080 6650                <1> 	PUSH	AX			; SAVE REGISTERS
 10299 00003082 66B80080            <1> 	MOV	AX,8000H		; AH = MAX # SECTORS AL = MAX OFFSET
 10300 00003086 F645FE02            <1>         TEST    byte [CMD_BLOCK+6],ECC_MODE
 10301 0000308A 7404                <1> 	JZ	short CKD1
 10302 0000308C 66B8047F            <1> 	MOV	AX,7F04H		; ECC IS 4 MORE BYTES
 10303 00003090 3A65F9              <1> CKD1:	CMP	AH, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
 10304 00003093 7706                <1> 	JA	short CKDOK		; IT WILL FIT
 10305 00003095 7208                <1> 	JB	short CKDERR		; TOO MANY
 10306 00003097 38D8                <1> 	CMP	AL,BL			; CHECK OFFSET ON MAX SECTORS
 10307 00003099 7204                <1> 	JB	short CKDERR		; ERROR
 10308 0000309B F8                  <1> CKDOK:	CLC				; CLEAR CARRY
 10309 0000309C 6658                <1> 	POP	AX
 10310 0000309E C3                  <1> 	RETn				; NORMAL RETURN
 10311 0000309F F9                  <1> CKDERR: STC				; INDICATE ERROR
 10312 000030A0 C605[17C50000]09    <1>         MOV     byte [DISK_STATUS1],DMA_BOUNDARY
 10313 000030A7 6658                <1> 	POP	AX
 10314 000030A9 C3                  <1> 	RETn
 10315                              <1> 
 10316                              <1> ;----------------------------------------
 10317                              <1> ;	SET UP ES:BX-> DISK PARMS	:
 10318                              <1> ;----------------------------------------
 10319                              <1> 					
 10320                              <1> ; INPUT -> DL = 0 based drive number
 10321                              <1> ; OUTPUT -> ES:BX = disk parameter table address
 10322                              <1> 
 10323                              <1> GET_VEC:
 10324                              <1> 	;SUB	AX,AX			; GET DISK PARAMETER ADDRESS
 10325                              <1> 	;MOV	ES,AX
 10326                              <1> 	;TEST	DL,1
 10327                              <1> 	;JZ	short GV_0
 10328                              <1> ;	LES	BX,[HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
 10329                              <1> ;	JMP	SHORT GV_EXIT
 10330                              <1> ;GV_0:
 10331                              <1> ;	LES	BX,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
 10332                              <1> ;
 10333                              <1> 	;xor	bh, bh
 10334 000030AA 31DB                <1> 	xor	ebx, ebx
 10335 000030AC 88D3                <1> 	mov	bl, dl
 10336                              <1> 	;;02/01/2015
 10337                              <1> 	;;shl	bl, 1			; port address offset
 10338                              <1> 	;;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
 10339                              <1> 	;;shl	bl, 1			; dpt pointer offset
 10340 000030AE C0E302              <1> 	shl	bl, 2	;;
 10341                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
 10342 000030B1 81C3[1CC50000]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
 10343                              <1> 	;push	word [bx+2]		; dpt segment
 10344                              <1> 	;pop	es
 10345                              <1> 	;mov	bx, [bx]		; dpt offset
 10346 000030B7 8B1B                <1> 	mov	ebx, [ebx]		
 10347                              <1> ;GV_EXIT:
 10348 000030B9 C3                  <1> 	RETn
 10349                              <1> 
 10350                              <1> hdc1_int: ; 21/02/2015
 10351                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL  14 ) ----------------------
 10352                              <1> ;								:
 10353                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10354                              <1> ;								:
 10355                              <1> ;----------------------------------------------------------------
 10356                              <1> 
 10357                              <1> ; 22/12/2014
 10358                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
 10359                              <1> ;	 '11/15/85'
 10360                              <1> ; AWARD BIOS 1999 (D1A0622) 
 10361                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
 10362                              <1> 
 10363                              <1> ;int_76h:
 10364                              <1> HD_INT:
 10365 000030BA 6650                <1> 	PUSH	AX
 10366 000030BC 1E                  <1> 	PUSH	DS
 10367                              <1> 	;CALL	DDS
 10368                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10369 000030BD 66B81000            <1> 	mov	ax, KDATA
 10370 000030C1 8ED8                <1> 	mov 	ds, ax
 10371                              <1> 	;
 10372                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10373                              <1>         ;mov     byte [CS:HF_INT_FLAG], 0FFh
 10374 000030C3 C605[0FC50000]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
 10375                              <1> 	;
 10376 000030CA 6652                <1> 	push	dx
 10377 000030CC 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
 10378                              <1> 					; Clear Controller
 10379                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
 10380 000030D0 EC                  <1> 	in	al, dx			;
 10381 000030D1 665A                <1> 	pop	dx
 10382                              <1> 	NEWIODELAY
 10383 000030D3 E6EB                <2>  out 0ebh,al
 10384                              <1> 	;
 10385 000030D5 B020                <1> 	MOV	AL,EOI			; NON-SPECIFIC END OF INTERRUPT
 10386 000030D7 E6A0                <1> 	OUT	INTB00,AL		; FOR CONTROLLER #2
 10387                              <1> 	;JMP	$+2			; WAIT
 10388                              <1> 	NEWIODELAY
 10389 000030D9 E6EB                <2>  out 0ebh,al
 10390 000030DB E620                <1> 	OUT	INTA00,AL		; FOR CONTROLLER #1
 10391 000030DD 1F                  <1> 	POP	DS
 10392                              <1> 	;STI				; RE-ENABLE INTERRUPTS
 10393                              <1> 	;MOV	AX,9100H		; DEVICE POST
 10394                              <1> 	;INT	15H			;  INTERRUPT
 10395                              <1> irq15_iret: ; 25/02/2015
 10396 000030DE 6658                <1> 	POP	AX
 10397 000030E0 CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
 10398                              <1> 
 10399                              <1> hdc2_int: ; 21/02/2015
 10400                              <1> ;++++ HARDWARE INT 77H ++ ( IRQ LEVEL  15 ) +++++++++++++++++++++
 10401                              <1> ;								:
 10402                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10403                              <1> ;								:
 10404                              <1> ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 10405                              <1> 
 10406                              <1> ;int_77h:
 10407                              <1> HD1_INT:
 10408 000030E1 6650                <1> 	PUSH	AX
 10409                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
 10410                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 10411 000030E3 B00B                <1> 	mov	al, 0Bh  ; In-Service Register
 10412 000030E5 E6A0                <1> 	out	0A0h, al
 10413 000030E7 EB00                <1>         jmp short $+2
 10414 000030E9 EB00                <1> 	jmp short $+2
 10415 000030EB E4A0                <1> 	in	al, 0A0h
 10416 000030ED 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
 10417 000030EF 74ED                <1> 	jz	short irq15_iret ; Fake (spurious)IRQ, do not send EOI)
 10418                              <1> 	;
 10419 000030F1 1E                  <1> 	PUSH	DS
 10420                              <1> 	;CALL	DDS
 10421                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10422 000030F2 66B81000            <1> 	mov	ax, KDATA
 10423 000030F6 8ED8                <1> 	mov 	ds, ax
 10424                              <1> 	;
 10425                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10426                              <1>         ;or      byte [CS:HF_INT_FLAG],0C0h 
 10427 000030F8 800D[0FC50000]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
 10428                              <1> 	;
 10429 000030FF 6652                <1> 	push	dx
 10430 00003101 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
 10431                              <1> 					; Clear Controller (Award BIOS 1999)
 10432 00003105 EBC9                <1> 	jmp	short Clear_IRQ1415
 10433                              <1> 
 10434                              <1> 
 10435                              <1> ;%include 'diskdata.inc' ; 11/03/2015
 10436                              <1> ;%include 'diskbss.inc' ; 11/03/2015
 10437                              <1> 
 10438                              <1> 
 10439                              <1> ;////////////////////////////////////////////////////////////////////
 10440                              <1> ;; END OF DISK I/O SYTEM ///
 10441                                  %include 'memory.s'  ; 09/03/2015
 10442                              <1> ; ****************************************************************************
 10443                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - memory.s
 10444                              <1> ; ----------------------------------------------------------------------------
 10445                              <1> ; Last Update: 03/04/2016
 10446                              <1> ; ----------------------------------------------------------------------------
 10447                              <1> ; Beginning: 24/01/2016
 10448                              <1> ; ----------------------------------------------------------------------------
 10449                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 10450                              <1> ; ----------------------------------------------------------------------------
 10451                              <1> ; Turkish Rational DOS
 10452                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 10453                              <1> ;
 10454                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 10455                              <1> ; memory.inc (18/10/2015)
 10456                              <1> ; ****************************************************************************
 10457                              <1> 
 10458                              <1> ; MEMORY.ASM - Retro UNIX 386 v1 MEMORY MANAGEMENT FUNCTIONS (PROCEDURES)
 10459                              <1> ; Retro UNIX 386 v1 Kernel (unix386.s, v0.2.0.14) - MEMORY.INC
 10460                              <1> ; Last Modification: 18/10/2015
 10461                              <1> 
 10462                              <1> ; ///////// MEMORY MANAGEMENT FUNCTIONS (PROCEDURES) ///////////////
 10463                              <1> 
 10464                              <1> ;;04/11/2014 (unix386.s)	
 10465                              <1> ;PDE_A_PRESENT	equ	1		; Present flag for PDE
 10466                              <1> ;PDE_A_WRITE	equ 	2		; Writable (write permission) flag
 10467                              <1> ;PDE_A_USER	equ	4		; User (non-system/kernel) page flag
 10468                              <1> ;;
 10469                              <1> ;PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
 10470                              <1> ;PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
 10471                              <1> ;PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
 10472                              <1> ;PTE_A_ACCESS   equ	32		; Accessed flag (bit 5) ; 09/03/2015
 10473                              <1> 
 10474                              <1> ; 27/04/2015
 10475                              <1> ; 09/03/2015
 10476                              <1> PAGE_SIZE 	equ 4096		; page size in bytes
 10477                              <1> PAGE_SHIFT 	equ 12			; page table shift count
 10478                              <1> PAGE_D_SHIFT 	equ 22	; 12 + 10	; page directory shift count
 10479                              <1> PAGE_OFF	equ 0FFFh		; 12 bit byte offset in page frame
 10480                              <1> PTE_MASK 	equ 03FFh		; page table entry mask
 10481                              <1> PTE_DUPLICATED  equ 200h		; duplicated page sign (AVL bit 0)
 10482                              <1> PDE_A_CLEAR	equ 0F000h		; to clear PDE attribute bits
 10483                              <1> PTE_A_CLEAR	equ 0F000h		; to clear PTE attribute bits
 10484                              <1> LOGIC_SECT_SIZE equ 512			; logical sector size
 10485                              <1> ERR_MAJOR_PF	equ 0E0h		; major error: page fault
 10486                              <1> ERR_MINOR_IM	equ 1			; insufficient (out of) memory
 10487                              <1> ERR_MINOR_DSK	equ 2			; disk read/write error
 10488                              <1> ERR_MINOR_PV	equ 3			; protection violation
 10489                              <1> SWP_DISK_READ_ERR equ 4
 10490                              <1> SWP_DISK_NOT_PRESENT_ERR equ 5
 10491                              <1> SWP_SECTOR_NOT_PRESENT_ERR equ 6
 10492                              <1> SWP_NO_FREE_SPACE_ERR equ 7
 10493                              <1> SWP_DISK_WRITE_ERR equ 8
 10494                              <1> SWP_NO_PAGE_TO_SWAP_ERR equ 9
 10495                              <1> PTE_A_ACCESS_BIT equ 5  ; Bit 5 (accessed flag)        
 10496                              <1> SECTOR_SHIFT    equ 3   ; sector shift (to convert page block number)
 10497                              <1> 
 10498                              <1> ;
 10499                              <1> ;; Retro Unix 386 v1 - paging method/principles
 10500                              <1> ;;
 10501                              <1> ;; 10/10/2014
 10502                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
 10503                              <1> ;;
 10504                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
 10505                              <1> ;;	(virtual address = physical address)
 10506                              <1> ;; KERNEL PAGE TABLES:
 10507                              <1> ;;	Kernel page directory and all page tables are
 10508                              <1> ;;	on memory as initialized, as equal to physical memory
 10509                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
 10510                              <1> ;;
 10511                              <1> ;;	what for: User pages may be swapped out, when accessing
 10512                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
 10513                              <1> ;;	kernel would have to swap it in! But it is also may be
 10514                              <1> ;;	in use by a user process. (In system/kernel mode
 10515                              <1> ;;	kernel can access all memory pages even if they are
 10516                              <1> ;;	reserved/allocated for user processes. Swap out/in would
 10517                              <1> ;;	cause conflicts.) 
 10518                              <1> ;;	
 10519                              <1> ;;	As result of these conditions,
 10520                              <1> ;;	all kernel pages must be initialized as equal to 
 10521                              <1> ;;	physical layout for preventing page faults. 
 10522                              <1> ;;	Also, calling "allocate page" procedure after
 10523                              <1> ;;	a page fault can cause another page fault (double fault)
 10524                              <1> ;;	if all kernel page tables would not be initialized.
 10525                              <1> ;;
 10526                              <1> ;;	[first_page] = Beginning of users space, as offset to 
 10527                              <1> ;;	memory allocation table. (double word aligned)
 10528                              <1> ;;
 10529                              <1> ;;	[next_page] = first/next free space to be searched
 10530                              <1> ;;	as offset to memory allocation table. (dw aligned)
 10531                              <1> ;;
 10532                              <1> ;;	[last_page] = End of memory (users space), as offset
 10533                              <1> ;;	to memory allocation table. (double word aligned)
 10534                              <1> ;;
 10535                              <1> ;; USER PAGE TABLES:
 10536                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
 10537                              <1> ;;		'ready only' marked copies of the 
 10538                              <1> ;;		parent process's page table entries (for
 10539                              <1> ;;		same physical memory).
 10540                              <1> ;;		(A page will be copied to a new page after
 10541                              <1> ;;		 if it causes R/W page fault.)
 10542                              <1> ;;
 10543                              <1> ;;	Every user process has own (different)
 10544                              <1> ;;	page directory and page tables.	
 10545                              <1> ;;
 10546                              <1> ;;	Code starts at virtual address 0, always.
 10547                              <1> ;;	(Initial value of EIP is 0 in user mode.)
 10548                              <1> ;;	(Programs can be written/developed as simple
 10549                              <1> ;;	 flat memory programs.)
 10550                              <1> ;;
 10551                              <1> ;; MEMORY ALLOCATION STRATEGY:
 10552                              <1> ;;	Memory page will be allocated by kernel only 
 10553                              <1> ;;		(in kernel/system mode only).
 10554                              <1> ;;	* After a
 10555                              <1> ;;	  - 'not present' page fault
 10556                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
 10557                              <1> ;;	* For loading (opening, reading) a file or disk/drive
 10558                              <1> ;;	* As responce to 'allocate additional memory blocks' 
 10559                              <1> ;;	  request by running process.
 10560                              <1> ;;	* While creating a process, allocating a new buffer,
 10561                              <1> ;;	  new page tables etc.
 10562                              <1> ;;
 10563                              <1> ;;	At first,
 10564                              <1> ;;	- 'allocate page' procedure will be called;
 10565                              <1> ;,	   if it will return with a valid (>0) physical address
 10566                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
 10567                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
 10568                              <1> ;;	- 'allocate page' will be called for allocating page
 10569                              <1> ;;	   directory, page table and running space (data/code).
 10570                              <1> ;;	- every successful 'allocate page' call will decrease
 10571                              <1> ;;	  'free_pages' count (pointer).
 10572                              <1> ;;	- 'out of (insufficient) memory error' will be returned
 10573                              <1> ;;	  if 'free_pages' points to a ZERO.
 10574                              <1> ;;	- swapping out and swapping in (if it is not a new page)
 10575                              <1> ;;	  procedures will be called as responce to 'out of memory'
 10576                              <1> ;;	  error except errors caused by attribute conflicts.
 10577                              <1> ;;	 (swapper functions)	 
 10578                              <1> ;;					
 10579                              <1> ;;	At second,
 10580                              <1> ;;	- page directory entry will be updated then page table
 10581                              <1> ;;	  entry will be updated.		
 10582                              <1> ;;
 10583                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
 10584                              <1> ;;	- M.A.T. has a size according to available memory as
 10585                              <1> ;;	  follows:
 10586                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
 10587                              <1> ;;		  - a bit with value of 0 means allocated page
 10588                              <1> ;;		  - a bit with value of 1 means a free page
 10589                              <1> ;,	- 'free_pages' pointer holds count of free pages
 10590                              <1> ;;	  depending on M.A.T.
 10591                              <1> ;;		(NOTE: Free page count will not be checked
 10592                              <1> ;;		again -on M.A.T.- after initialization. 
 10593                              <1> ;;		Kernel will trust on initial count.)
 10594                              <1> ;,	- 'free_pages' count will be decreased by allocation
 10595                              <1> ;;	  and it will be increased by deallocation procedures.
 10596                              <1> ;;	
 10597                              <1> ;;	- Available memory will be calculated during
 10598                              <1> ;;	  the kernel's initialization stage (in real mode).
 10599                              <1> ;;	  Memory allocation table and kernel page tables 
 10600                              <1> ;;	  will be formatted/sized as result of available
 10601                              <1> ;;	  memory calculation before paging is enabled.
 10602                              <1> ;;
 10603                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
 10604                              <1> ;;	- Memory Allocation Table size will be 128 KB.
 10605                              <1> ;;	- Memory allocation for kernel page directory size 
 10606                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10607                              <1> ;;	  for page tables)
 10608                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
 10609                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
 10610                              <1> ;;	- User (available) space will be started 
 10611                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
 10612                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10613                              <1> ;;	  memory allocation table and kernel's page directory
 10614                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10615                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10616                              <1> ;; 	  for buffers.
 10617                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10618                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10619                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
 10620                              <1> ;;
 10621                              <1> ;; For 1GB Available Memory:
 10622                              <1> ;;	- Memory Allocation Table size will be 32 KB.
 10623                              <1> ;;	- Memory allocation for kernel page directory size 
 10624                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10625                              <1> ;;	  for page tables)
 10626                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
 10627                              <1> ;;	  is 1 MB (256*4*1024 bytes).
 10628                              <1> ;;	- User (available) space will be started 
 10629                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
 10630                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10631                              <1> ;;	  memory allocation table and kernel's page directory
 10632                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10633                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10634                              <1> ;; 	  for buffers.
 10635                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10636                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10637                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
 10638                              <1> ;;
 10639                              <1> ;;
 10640                              <1> 
 10641                              <1> 
 10642                              <1> ;;************************************************************************************
 10643                              <1> ;; 
 10644                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
 10645                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
 10646                              <1> 
 10647                              <1> ;; Main factor: "sys fork" system call 
 10648                              <1> ;;	
 10649                              <1> ;; 		FORK
 10650                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
 10651                              <1> ;;  writable pages ---->|
 10652                              <1> ;;                      |----> child - duplicated PTEs, read only pages
 10653                              <1> ;; 
 10654                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
 10655                              <1> ;; 
 10656                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
 10657                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
 10658                              <1> ;;       -while R/W bit is 0-. 
 10659                              <1> ;; 
 10660                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
 10661                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
 10662                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
 10663                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
 10664                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
 10665                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
 10666                              <1> ;; 
 10667                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
 10668                              <1> ;; # Parent's read only pages are copied to new child pages. 
 10669                              <1> ;;   Parent's PTE attributes are not changed.
 10670                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
 10671                              <1> ;;    destroy/mix previous fork result).
 10672                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
 10673                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
 10674                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
 10675                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
 10676                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
 10677                              <1> ;;   as Child's Page Table Entries without copying actual page.
 10678                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
 10679                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
 10680                              <1> ;; 
 10681                              <1> ;; !? WHAT FOR (duplication after duplication):
 10682                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
 10683                              <1> ;; program/executable code continues from specified location as child process, 
 10684                              <1> ;; returns back previous code location as parent process, every child after 
 10685                              <1> ;; every sys fork uses last image of code and data just prior the fork.
 10686                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
 10687                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
 10688                              <1> ;; was copied to child's process segment (all of code and data) according to
 10689                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
 10690                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
 10691                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
 10692                              <1> ;; (complete running image of parent process) to the child process; 
 10693                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
 10694                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
 10695                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
 10696                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
 10697                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
 10698                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
 10699                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
 10700                              <1> ;; new/fresh pages will be used to load and run new executable/program.
 10701                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
 10702                              <1> ;; for sharing same read only pages between parent and child processes.
 10703                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
 10704                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
 10705                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
 10706                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
 10707                              <1> ;; -deallocation problem-.
 10708                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
 10709                              <1> ;; 
 10710                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10711                              <1> ;; # Page fault handler will do those:
 10712                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10713                              <1> ;;   - If it is reset/clear, there is a child uses same page.
 10714                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
 10715                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
 10716                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
 10717                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
 10718                              <1> ;;     read only page will be converted to writable and unique page which belongs
 10719                              <1> ;;     to child process.)	
 10720                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10721                              <1> ;; # Page fault handler will do those:
 10722                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10723                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
 10724                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
 10725                              <1> ;;     address or not. 
 10726                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
 10727                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
 10728                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
 10729                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
 10730                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
 10731                              <1> ;; 
 10732                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
 10733                              <1> ;;       will be set as writable (and unique) in case of child process was using 
 10734                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
 10735                              <1> ;;       duplication method details, it is not possible multiple child processes
 10736                              <1> ;;       were using same page with duplicated PTEs.
 10737                              <1> ;; 
 10738                              <1> ;;************************************************************************************   
 10739                              <1> 
 10740                              <1> ;; 08/10/2014
 10741                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
 10742                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
 10743                              <1> 
 10744                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
 10745                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
 10746                              <1> ;; (25/08/2014, Revision: 5057) file 
 10747                              <1> ;; by KolibriOS Team (2004-2012)
 10748                              <1> 
 10749                              <1> allocate_page:
 10750                              <1> 	; 01/07/2015
 10751                              <1> 	; 05/05/2015
 10752                              <1> 	; 30/04/2015
 10753                              <1> 	; 16/10/2014
 10754                              <1> 	; 08/10/2014
 10755                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
 10756                              <1> 	;
 10757                              <1> 	; INPUT -> none
 10758                              <1> 	;
 10759                              <1> 	; OUTPUT ->
 10760                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 10761                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
 10762                              <1> 	;
 10763                              <1> 	;	CF = 1 and EAX = 0 
 10764                              <1> 	; 		   if there is not a free page to be allocated	
 10765                              <1> 	;
 10766                              <1> 	; Modified Registers -> none (except EAX)
 10767                              <1> 	;
 10768 00003107 A1[80C40000]        <1> 	mov	eax, [free_pages]
 10769 0000310C 21C0                <1> 	and	eax, eax
 10770 0000310E 7438                <1> 	jz	short out_of_memory
 10771                              <1> 	;
 10772 00003110 53                  <1> 	push	ebx
 10773 00003111 51                  <1> 	push	ecx
 10774                              <1> 	;
 10775 00003112 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
 10776 00003117 89D9                <1> 	mov	ecx, ebx
 10777                              <1>  				     ; NOTE: 32 (first_page) is initial
 10778                              <1> 				     ; value of [next_page].
 10779                              <1> 				     ; It points to the first available
 10780                              <1> 				     ; page block for users (ring 3) ...	
 10781                              <1> 				     ; (MAT offset 32 = 1024/32)	
 10782                              <1> 				     ; (at the of the first 4 MB)		
 10783 00003119 031D[84C40000]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
 10784                              <1> 				 ; next_free_page >> 5
 10785 0000311F 030D[88C40000]      <1> 	add	ecx, [last_page] ; Free page searching ends here
 10786                              <1> 				 ; (total_pages - 1) >> 5
 10787                              <1> al_p_scan:
 10788 00003125 39CB                <1> 	cmp	ebx, ecx
 10789 00003127 770A                <1> 	ja	short al_p_notfound
 10790                              <1> 	;
 10791                              <1> 	; 01/07/2015
 10792                              <1> 	; AMD64 Architecture Programmers Manual
 10793                              <1> 	; Volume 3:
 10794                              <1> 	; General-Purpose and System Instructions
 10795                              <1> 	;
 10796                              <1> 	; BSF - Bit Scan Forward
 10797                              <1> 	;
 10798                              <1> 	;   Searches the value in a register or a memory location
 10799                              <1> 	;   (second operand) for the least-significant set bit. 
 10800                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
 10801                              <1> 	;   and stores the index of the least-significant set bit in a destination
 10802                              <1> 	;   register (first operand). If the second operand contains 0, 
 10803                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
 10804                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
 10805                              <1> 	;   of the searched value
 10806                              <1> 	;
 10807 00003129 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 10808                              <1> 			   ; Clear ZF if a bit is found set (1) and 
 10809                              <1> 			   ; loads the destination with an index to
 10810                              <1> 			   ; first set bit. (0 -> 31) 
 10811                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 10812 0000312C 7525                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
 10813                              <1> 			 ;
 10814                              <1> 			 ; NOTE:  a Memory Allocation Table bit 
 10815                              <1> 			 ;	  with value of 1 means 
 10816                              <1> 			 ;	  the corresponding page is free 
 10817                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 10818 0000312E 83C304              <1> 	add	ebx, 4
 10819                              <1> 			 ; We return back for searching next page block
 10820                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
 10821                              <1> 			 ;	 we always will find at least 1 free page here.
 10822 00003131 EBF2                <1>         jmp     short al_p_scan
 10823                              <1> 	;
 10824                              <1> al_p_notfound:
 10825 00003133 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10826 00003139 890D[84C40000]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
 10827                              <1> 				 ; (deallocate_page procedure will change it)
 10828 0000313F 31C0                <1> 	xor	eax, eax
 10829 00003141 A3[80C40000]        <1> 	mov	[free_pages], eax ; 0
 10830 00003146 59                  <1> 	pop	ecx
 10831 00003147 5B                  <1> 	pop	ebx
 10832                              <1> 	;
 10833                              <1> out_of_memory:
 10834 00003148 E857040000          <1> 	call	swap_out
 10835 0000314D 7325                <1> 	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
 10836                              <1> 	;
 10837 0000314F 29C0                <1> 	sub 	eax, eax ; 0
 10838 00003151 F9                  <1> 	stc
 10839 00003152 C3                  <1> 	retn
 10840                              <1> 
 10841                              <1> al_p_found:
 10842 00003153 89D9                <1> 	mov	ecx, ebx
 10843 00003155 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10844 0000315B 890D[84C40000]      <1> 	mov	[next_page], ecx ; Set first free page searching start
 10845                              <1> 				 ; address/offset (to the next)
 10846 00003161 FF0D[80C40000]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
 10847                              <1> 	;
 10848 00003167 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 10849                              <1> 				 ; is copied into the Carry Flag and then cleared
 10850                              <1> 				 ; in the destination.
 10851                              <1> 				 ;
 10852                              <1> 				 ; Reset the bit which is corresponding to the 
 10853                              <1> 				 ; (just) allocated page.
 10854                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
 10855 0000316A C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
 10856 0000316D 01C8                <1> 	add	eax, ecx	 ; = page number
 10857 0000316F C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
 10858                              <1> 	; EAX = physical address of memory page
 10859                              <1> 	;
 10860                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
 10861                              <1> 	;       according to this EAX value...
 10862 00003172 59                  <1> 	pop	ecx
 10863 00003173 5B                  <1> 	pop	ebx
 10864                              <1> al_p_ok:
 10865 00003174 C3                  <1> 	retn
 10866                              <1> 
 10867                              <1> 
 10868                              <1> make_page_dir:
 10869                              <1> 	; 18/04/2015
 10870                              <1> 	; 12/04/2015
 10871                              <1> 	; 23/10/2014
 10872                              <1> 	; 16/10/2014
 10873                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10874                              <1> 	;
 10875                              <1> 	; INPUT ->
 10876                              <1> 	;	none
 10877                              <1> 	; OUTPUT ->
 10878                              <1> 	;	(EAX = 0)
 10879                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10880                              <1> 	;	cf = 0 ->
 10881                              <1> 	;	u.pgdir = page directory (physical) address of the current
 10882                              <1> 	;		  process/user.
 10883                              <1> 	;
 10884                              <1> 	; Modified Registers -> EAX
 10885                              <1> 	;
 10886 00003175 E88DFFFFFF          <1> 	call	allocate_page
 10887 0000317A 7216                <1> 	jc	short mkpd_error
 10888                              <1> 	;
 10889 0000317C A3[31D50000]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
 10890                              <1> 				  ; (Physical address)
 10891                              <1> clear_page:
 10892                              <1> 	; 18/04/2015
 10893                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10894                              <1> 	;
 10895                              <1> 	; INPUT ->
 10896                              <1> 	;	EAX = physical address of the page
 10897                              <1> 	; OUTPUT ->
 10898                              <1> 	;	all bytes of the page will be cleared
 10899                              <1> 	;
 10900                              <1> 	; Modified Registers -> none
 10901                              <1> 	;
 10902 00003181 57                  <1> 	push	edi
 10903 00003182 51                  <1> 	push	ecx
 10904 00003183 50                  <1> 	push	eax
 10905 00003184 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 10906 00003189 89C7                <1> 	mov	edi, eax
 10907 0000318B 31C0                <1> 	xor	eax, eax
 10908 0000318D F3AB                <1> 	rep	stosd
 10909 0000318F 58                  <1> 	pop	eax
 10910 00003190 59                  <1> 	pop	ecx
 10911 00003191 5F                  <1> 	pop	edi
 10912                              <1> mkpd_error:
 10913                              <1> mkpt_error:
 10914 00003192 C3                  <1> 	retn
 10915                              <1> 
 10916                              <1> make_page_table:
 10917                              <1> 	; 23/06/2015
 10918                              <1> 	; 18/04/2015
 10919                              <1> 	; 12/04/2015
 10920                              <1> 	; 16/10/2014
 10921                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10922                              <1> 	;
 10923                              <1> 	; INPUT ->
 10924                              <1> 	;	EBX = virtual (linear) address
 10925                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10926                              <1> 	;	      (higher 20 bits must be ZERO)
 10927                              <1> 	;	      (bit 0 must be 1)	 
 10928                              <1> 	;	u.pgdir = page directory (physical) address
 10929                              <1> 	; OUTPUT ->
 10930                              <1> 	;	EDX = Page directory entry address
 10931                              <1> 	;	EAX = Page table address
 10932                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10933                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
 10934                              <1> 	;
 10935                              <1> 	; Modified Registers -> EAX, EDX
 10936                              <1> 	;
 10937 00003193 E86FFFFFFF          <1> 	call	allocate_page
 10938 00003198 72F8                <1> 	jc	short mkpt_error
 10939 0000319A E811000000          <1> 	call	set_pde	
 10940 0000319F EBE0                <1> 	jmp	short clear_page
 10941                              <1> 
 10942                              <1> make_page:
 10943                              <1> 	; 24/07/2015
 10944                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
 10945                              <1> 	;
 10946                              <1> 	; INPUT ->
 10947                              <1> 	;	EBX = virtual (linear) address
 10948                              <1> 	;	ECX = page attributes (lower 12 bits)
 10949                              <1> 	;	      (higher 20 bits must be ZERO)
 10950                              <1> 	;	      (bit 0 must be 1)	 
 10951                              <1> 	;	u.pgdir = page directory (physical) address
 10952                              <1> 	; OUTPUT ->
 10953                              <1> 	;	EBX = Virtual address
 10954                              <1> 	;	(EDX = PTE value)
 10955                              <1> 	;	EAX = Physical address
 10956                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10957                              <1> 	;
 10958                              <1> 	; Modified Registers -> EAX, EDX
 10959                              <1> 	;
 10960 000031A1 E861FFFFFF          <1> 	call	allocate_page
 10961 000031A6 7207                <1> 	jc	short mkp_err
 10962 000031A8 E821000000          <1> 	call	set_pte	
 10963 000031AD 73D2                <1> 	jnc	short clear_page ; 18/04/2015
 10964                              <1> mkp_err:
 10965 000031AF C3                  <1> 	retn
 10966                              <1> 
 10967                              <1> 
 10968                              <1> set_pde:	; Set page directory entry (PDE)
 10969                              <1> 	; 20/07/2015
 10970                              <1> 	; 18/04/2015
 10971                              <1> 	; 12/04/2015
 10972                              <1> 	; 23/10/2014
 10973                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10974                              <1> 	;
 10975                              <1> 	; INPUT ->
 10976                              <1> 	;	EAX = physical address
 10977                              <1> 	;	      (use present value if EAX = 0)
 10978                              <1> 	;	EBX = virtual (linear) address
 10979                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10980                              <1> 	;	      (higher 20 bits must be ZERO)
 10981                              <1> 	;	      (bit 0 must be 1)	 
 10982                              <1> 	;	u.pgdir = page directory (physical) address
 10983                              <1> 	; OUTPUT ->
 10984                              <1> 	;	EDX = PDE address
 10985                              <1> 	;	EAX = page table address (physical)
 10986                              <1> 	;	;(CF=1 -> Invalid page address)
 10987                              <1> 	;
 10988                              <1> 	; Modified Registers -> EDX
 10989                              <1> 	;
 10990 000031B0 89DA                <1> 	mov	edx, ebx
 10991 000031B2 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
 10992 000031B5 C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
 10993 000031B8 0315[31D50000]      <1> 	add	edx, [u.pgdir]
 10994                              <1> 	;
 10995 000031BE 21C0                <1> 	and	eax, eax
 10996 000031C0 7506                <1> 	jnz	short spde_1
 10997                              <1> 	;
 10998 000031C2 8B02                <1> 	mov	eax, [edx]  ; old PDE value
 10999                              <1> 	;test	al, 1
 11000                              <1> 	;jz	short spde_2
 11001 000031C4 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
 11002                              <1> spde_1:
 11003                              <1> 	;and	cx, 0FFFh
 11004 000031C8 8902                <1> 	mov	[edx], eax
 11005 000031CA 66090A              <1> 	or	[edx], cx
 11006 000031CD C3                  <1> 	retn
 11007                              <1> ;spde_2: ; error
 11008                              <1> ;	stc
 11009                              <1> ;	retn
 11010                              <1> 
 11011                              <1> set_pte:	; Set page table entry (PTE)
 11012                              <1> 	; 24/07/2015
 11013                              <1> 	; 20/07/2015
 11014                              <1> 	; 23/06/2015
 11015                              <1> 	; 18/04/2015
 11016                              <1> 	; 12/04/2015
 11017                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11018                              <1> 	;
 11019                              <1> 	; INPUT ->
 11020                              <1> 	;	EAX = physical page address
 11021                              <1> 	;	      (use present value if EAX = 0)
 11022                              <1> 	;	EBX = virtual (linear) address
 11023                              <1> 	;	ECX = page attributes (lower 12 bits)
 11024                              <1> 	;	      (higher 20 bits must be ZERO)
 11025                              <1> 	;	      (bit 0 must be 1)	 
 11026                              <1> 	;	u.pgdir = page directory (physical) address
 11027                              <1> 	; OUTPUT ->
 11028                              <1> 	;	EAX = physical page address
 11029                              <1> 	;	(EDX = PTE value)
 11030                              <1> 	;	EBX = virtual address
 11031                              <1> 	;
 11032                              <1> 	;	CF = 1 -> error
 11033                              <1> 	;
 11034                              <1> 	; Modified Registers -> EAX, EDX
 11035                              <1> 	;
 11036 000031CE 50                  <1> 	push	eax
 11037 000031CF A1[31D50000]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
 11038 000031D4 E837000000          <1> 	call 	get_pde
 11039                              <1> 		; EDX = PDE address
 11040                              <1> 		; EAX = PDE value
 11041 000031D9 5A                  <1> 	pop	edx ; physical page address
 11042 000031DA 722A                <1> 	jc	short spte_err ; PDE not present
 11043                              <1> 	;
 11044 000031DC 53                  <1> 	push	ebx ; 24/07/2015
 11045 000031DD 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11046                              <1> 			    ; EDX = PT address (physical)	
 11047 000031E1 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
 11048 000031E4 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
 11049                              <1> 			 ; clear higher 10 bits (PD bits)
 11050 000031EA C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
 11051 000031ED 01C3                <1> 	add	ebx, eax
 11052                              <1> 	;
 11053 000031EF 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
 11054 000031F1 A801                <1> 	test	al, 1
 11055 000031F3 740C                <1> 	jz	short spte_0
 11056 000031F5 09D2                <1> 	or	edx, edx
 11057 000031F7 750F                <1> 	jnz	short spte_1
 11058 000031F9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11059 000031FD 89C2                <1> 	mov	edx, eax
 11060 000031FF EB09                <1> 	jmp	short spte_2	
 11061                              <1> spte_0:
 11062                              <1> 	; If this PTE contains a swap (disk) address,
 11063                              <1> 	; it can be updated by using 'swap_in' procedure
 11064                              <1> 	; only!
 11065 00003201 21C0                <1> 	and	eax, eax
 11066 00003203 7403                <1> 	jz	short spte_1
 11067                              <1> 	; 24/07/2015
 11068                              <1> 	; swapped page ! (on disk)
 11069 00003205 5B                  <1> 	pop	ebx
 11070                              <1> spte_err:
 11071 00003206 F9                  <1> 	stc
 11072 00003207 C3                  <1> 	retn
 11073                              <1> spte_1: 
 11074 00003208 89D0                <1> 	mov	eax, edx
 11075                              <1> spte_2:
 11076 0000320A 09CA                <1> 	or	edx, ecx
 11077                              <1> 	; 23/06/2015
 11078 0000320C 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
 11079                              <1> 	; 24/07/2015
 11080 0000320E 5B                  <1> 	pop	ebx
 11081 0000320F C3                  <1> 	retn
 11082                              <1> 
 11083                              <1> get_pde:	; Get present value of the relevant PDE
 11084                              <1> 	; 20/07/2015
 11085                              <1> 	; 18/04/2015
 11086                              <1> 	; 12/04/2015
 11087                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11088                              <1> 	;
 11089                              <1> 	; INPUT ->
 11090                              <1> 	;	EBX = virtual (linear) address
 11091                              <1> 	;	EAX = page directory (physical) address
 11092                              <1> 	; OUTPUT ->
 11093                              <1> 	;	EDX = Page directory entry address
 11094                              <1> 	;	EAX = Page directory entry value
 11095                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11096                              <1> 	; Modified Registers -> EDX, EAX
 11097                              <1> 	;
 11098 00003210 89DA                <1> 	mov	edx, ebx
 11099 00003212 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
 11100 00003215 C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
 11101 00003218 01C2                <1> 	add	edx, eax ; page directory address (physical)
 11102 0000321A 8B02                <1> 	mov	eax, [edx]
 11103 0000321C A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
 11104 0000321E 751F                <1> 	jnz	short gpte_retn
 11105 00003220 F9                  <1> 	stc
 11106                              <1> gpde_retn:	
 11107 00003221 C3                  <1> 	retn
 11108                              <1> 
 11109                              <1> get_pte:
 11110                              <1> 		; Get present value of the relevant PTE
 11111                              <1> 	; 29/07/2015
 11112                              <1> 	; 20/07/2015
 11113                              <1> 	; 18/04/2015
 11114                              <1> 	; 12/04/2015
 11115                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11116                              <1> 	;
 11117                              <1> 	; INPUT ->
 11118                              <1> 	;	EBX = virtual (linear) address
 11119                              <1> 	;	EAX = page directory (physical) address
 11120                              <1> 	; OUTPUT ->
 11121                              <1> 	;	EDX = Page table entry address (if CF=0)
 11122                              <1> 	;	      Page directory entry address (if CF=1)
 11123                              <1> 	;            (Bit 0 value is 0 if PT is not present)
 11124                              <1> 	;	EAX = Page table entry value (page address)
 11125                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11126                              <1> 	; Modified Registers -> EAX, EDX
 11127                              <1> 	;
 11128 00003222 E8E9FFFFFF          <1> 	call 	get_pde
 11129 00003227 72F8                <1> 	jc	short gpde_retn	; page table is not present
 11130                              <1> 	;jnc	short gpte_1
 11131                              <1> 	;retn
 11132                              <1> ;gpte_1:
 11133 00003229 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11134 0000322D 89DA                <1> 	mov	edx, ebx
 11135 0000322F C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
 11136 00003232 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
 11137                              <1> 			 ; clear higher 10 bits (PD bits)
 11138 00003238 C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
 11139 0000323B 01C2                <1> 	add	edx, eax
 11140 0000323D 8B02                <1> 	mov	eax, [edx]
 11141                              <1> gpte_retn:
 11142 0000323F C3                  <1> 	retn
 11143                              <1> 
 11144                              <1> deallocate_page_dir:
 11145                              <1> 	; 15/09/2015
 11146                              <1> 	; 05/08/2015
 11147                              <1> 	; 30/04/2015
 11148                              <1> 	; 28/04/2015
 11149                              <1> 	; 17/10/2014
 11150                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11151                              <1> 	;
 11152                              <1> 	; INPUT ->
 11153                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
 11154                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11155                              <1> 	; OUTPUT ->
 11156                              <1> 	;	All of page tables in the page directory
 11157                              <1> 	;	and page dir's itself will be deallocated
 11158                              <1> 	;	except 'read only' duplicated pages (will be converted
 11159                              <1> 	;	to writable pages).
 11160                              <1> 	;
 11161                              <1> 	; Modified Registers -> EAX
 11162                              <1> 	;
 11163                              <1> 	;
 11164 00003240 56                  <1> 	push	esi
 11165 00003241 51                  <1> 	push	ecx
 11166 00003242 50                  <1> 	push	eax
 11167 00003243 89C6                <1> 	mov	esi, eax 
 11168 00003245 31C9                <1> 	xor	ecx, ecx
 11169                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
 11170                              <1> 	; it must not be deallocated
 11171 00003247 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
 11172                              <1> dapd_0:
 11173 00003249 AD                  <1> 	lodsd
 11174 0000324A A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
 11175 0000324C 7409                <1> 	jz	short dapd_1	
 11176 0000324E 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11177 00003252 E812000000          <1> 	call	deallocate_page_table			
 11178                              <1> dapd_1:
 11179 00003257 41                  <1> 	inc	ecx ; page directory entry index
 11180 00003258 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
 11181 0000325E 72E9                <1> 	jb	short dapd_0
 11182                              <1> dapd_2:
 11183 00003260 58                  <1> 	pop	eax
 11184 00003261 E879000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
 11185 00003266 59                  <1> 	pop	ecx
 11186 00003267 5E                  <1> 	pop	esi
 11187 00003268 C3                  <1> 	retn
 11188                              <1> 
 11189                              <1> deallocate_page_table:
 11190                              <1> 	; 19/09/2015
 11191                              <1> 	; 15/09/2015
 11192                              <1> 	; 05/08/2015
 11193                              <1> 	; 30/04/2015
 11194                              <1> 	; 28/04/2015
 11195                              <1> 	; 24/10/2014
 11196                              <1> 	; 23/10/2014
 11197                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11198                              <1> 	;
 11199                              <1> 	; INPUT ->
 11200                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
 11201                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11202                              <1> 	;	(ECX = page directory entry index)
 11203                              <1> 	; OUTPUT ->
 11204                              <1> 	;	All of pages in the page table and page table's itself
 11205                              <1> 	;	will be deallocated except 'read only' duplicated pages
 11206                              <1> 	;	(will be converted to writable pages).
 11207                              <1> 	;
 11208                              <1> 	; Modified Registers -> EAX
 11209                              <1> 	;
 11210 00003269 56                  <1> 	push	esi
 11211 0000326A 57                  <1> 	push	edi
 11212 0000326B 52                  <1> 	push	edx
 11213 0000326C 50                  <1> 	push	eax ; *
 11214 0000326D 89C6                <1> 	mov	esi, eax 
 11215 0000326F 31FF                <1> 	xor	edi, edi ; 0
 11216                              <1> dapt_0:
 11217 00003271 AD                  <1> 	lodsd
 11218 00003272 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
 11219 00003274 7441                <1> 	jz	short dapt_1
 11220                              <1> 	;
 11221 00003276 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
 11222                              <1> 				  ; (must be 1)
 11223 00003278 754C                <1> 	jnz	short dapt_3
 11224                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
 11225 0000327A 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
 11226                              <1> 				   ; as child's page ?
 11227 0000327E 744B                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
 11228                              <1> 	; check the parent's PTE value is read only & same page or not.. 
 11229                              <1> 	; ECX = page directory entry index (0-1023)
 11230 00003280 53                  <1> 	push	ebx
 11231 00003281 51                  <1> 	push	ecx
 11232 00003282 66C1E102            <1> 	shl	cx, 2 ; *4 
 11233 00003286 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
 11234 00003288 8B0B                <1> 	mov	ecx, [ebx]
 11235 0000328A F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
 11236 0000328D 7435                <1> 	jz	short dapt_2	; parent process does not use this page
 11237 0000328F 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11238                              <1> 	; EDI = page table entry index (0-1023)
 11239 00003294 89FA                <1> 	mov	edx, edi 
 11240 00003296 66C1E202            <1> 	shl	dx, 2 ; *4 
 11241 0000329A 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
 11242 0000329C 8B1A                <1> 	mov	ebx, [edx]
 11243 0000329E F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
 11244 000032A1 7421                <1> 	jz	short dapt_2	; parent process does not use this page
 11245 000032A3 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
 11246 000032A7 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
 11247 000032AC 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
 11248 000032AE 7514                <1> 	jne	short dapt_2	; not same page
 11249                              <1> 				; deallocate the child's page
 11250 000032B0 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
 11251 000032B3 59                  <1> 	pop	ecx
 11252 000032B4 5B                  <1> 	pop	ebx
 11253 000032B5 EB14                <1> 	jmp	short dapt_4
 11254                              <1> dapt_1:
 11255 000032B7 09C0                <1> 	or	eax, eax	; swapped page ?
 11256 000032B9 7417                <1> 	jz	short dapt_5	; no
 11257                              <1> 				; yes
 11258 000032BB D1E8                <1> 	shr	eax, 1
 11259 000032BD E848040000          <1> 	call	unlink_swap_block ; Deallocate swapped page block
 11260                              <1> 				  ; on the swap disk (or in file)
 11261 000032C2 EB0E                <1> 	jmp	short dapt_5
 11262                              <1> dapt_2:
 11263 000032C4 59                  <1> 	pop	ecx
 11264 000032C5 5B                  <1> 	pop	ebx
 11265                              <1> dapt_3:	
 11266                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11267 000032C6 E814000000          <1> 	call	deallocate_page
 11268                              <1> dapt_4:
 11269 000032CB C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
 11270                              <1> dapt_5:
 11271 000032D2 47                  <1> 	inc	edi ; page table entry index
 11272 000032D3 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
 11273 000032D9 7296                <1> 	jb	short dapt_0
 11274                              <1> 	;
 11275 000032DB 58                  <1> 	pop	eax ; *
 11276 000032DC 5A                  <1> 	pop	edx
 11277 000032DD 5F                  <1> 	pop	edi	
 11278 000032DE 5E                  <1> 	pop	esi
 11279                              <1> 	;
 11280                              <1> 	;call	deallocate_page	; deallocate the page table's itself
 11281                              <1> 	;retn
 11282                              <1> 
 11283                              <1> deallocate_page:
 11284                              <1> 	; 15/09/2015
 11285                              <1> 	; 28/04/2015
 11286                              <1> 	; 10/03/2015
 11287                              <1> 	; 17/10/2014
 11288                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11289                              <1> 	;
 11290                              <1> 	; INPUT -> 
 11291                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11292                              <1> 	; OUTPUT ->
 11293                              <1> 	;	[free_pages] is increased
 11294                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
 11295                              <1> 	;	CF = 1 if the page is already deallocated
 11296                              <1> 	; 	       (or not allocated) before.  
 11297                              <1> 	;
 11298                              <1> 	; Modified Registers -> EAX
 11299                              <1> 	;
 11300 000032DF 53                  <1> 	push	ebx
 11301 000032E0 52                  <1> 	push	edx
 11302                              <1> 	;
 11303 000032E1 C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
 11304                              <1> 				     ; 12 bits right
 11305                              <1> 				     ; to get page number
 11306 000032E4 89C2                <1> 	mov	edx, eax
 11307                              <1> 	; 15/09/2015
 11308 000032E6 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 11309                              <1> 				     ; (1 allocation bit = 1 page)
 11310                              <1> 				     ; (1 allocation bytes = 8 pages)
 11311 000032E9 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 11312                              <1> 				     ; (to get 32 bit position)			
 11313                              <1> 	;
 11314 000032EC BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
 11315 000032F1 01D3                <1> 	add	ebx, edx
 11316 000032F3 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 11317                              <1> 				     ; (allocation bit position)	 
 11318 000032F6 3B15[84C40000]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
 11319                              <1> 				     ; than the address in 'next_page' ?
 11320                              <1> 				     ; (next/first free page value)		
 11321 000032FC 7306                <1> 	jnb	short dap_1	     ; no	
 11322 000032FE 8915[84C40000]      <1> 	mov	[next_page], edx     ; yes
 11323                              <1> dap_1:
 11324 00003304 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
 11325                              <1> 				     ; set relevant bit to 1.
 11326                              <1> 				     ; set CF to the previous bit value	
 11327                              <1> 	;cmc			     ; complement carry flag	
 11328                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
 11329                              <1> 				     ; if the page is already deallocated
 11330                              <1> 				     ; before.	
 11331 00003307 FF05[80C40000]      <1>         inc     dword [free_pages]
 11332                              <1> dap_2:
 11333 0000330D 5A                  <1> 	pop	edx
 11334 0000330E 5B                  <1> 	pop	ebx
 11335 0000330F C3                  <1> 	retn
 11336                              <1> 
 11337                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11338                              <1> ;;                                                              ;;
 11339                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
 11340                              <1> ;; Distributed under terms of the GNU General Public License    ;;
 11341                              <1> ;;                                                              ;;
 11342                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11343                              <1> 
 11344                              <1> ;;$Revision: 5057 $
 11345                              <1> 
 11346                              <1> 
 11347                              <1> ;;align 4
 11348                              <1> ;;proc alloc_page
 11349                              <1> 
 11350                              <1> ;;        pushfd
 11351                              <1> ;;        cli
 11352                              <1> ;;        push    ebx
 11353                              <1> ;;;//-
 11354                              <1> ;;        cmp     [pg_data.pages_free], 1
 11355                              <1> ;;        jle     .out_of_memory
 11356                              <1> ;;;//-
 11357                              <1> ;;
 11358                              <1> ;;        mov     ebx, [page_start]
 11359                              <1> ;;        mov     ecx, [page_end]
 11360                              <1> ;;.l1:
 11361                              <1> ;;        bsf     eax, [ebx];
 11362                              <1> ;;        jnz     .found
 11363                              <1> ;;        add     ebx, 4
 11364                              <1> ;;        cmp     ebx, ecx
 11365                              <1> ;;        jb      .l1
 11366                              <1> ;;        pop     ebx
 11367                              <1> ;;        popfd
 11368                              <1> ;;        xor     eax, eax
 11369                              <1> ;;        ret
 11370                              <1> ;;.found:
 11371                              <1> ;;;//-
 11372                              <1> ;;        dec     [pg_data.pages_free]
 11373                              <1> ;;        jz      .out_of_memory
 11374                              <1> ;;;//-
 11375                              <1> ;;        btr     [ebx], eax
 11376                              <1> ;;        mov     [page_start], ebx
 11377                              <1> ;;        sub     ebx, sys_pgmap
 11378                              <1> ;;        lea     eax, [eax+ebx*8]
 11379                              <1> ;;        shl     eax, 12
 11380                              <1> ;;;//-       dec [pg_data.pages_free]
 11381                              <1> ;;        pop     ebx
 11382                              <1> ;;        popfd
 11383                              <1> ;;        ret
 11384                              <1> ;;;//-
 11385                              <1> ;;.out_of_memory:
 11386                              <1> ;;        mov     [pg_data.pages_free], 1
 11387                              <1> ;;        xor     eax, eax
 11388                              <1> ;;        pop     ebx
 11389                              <1> ;;        popfd
 11390                              <1> ;;        ret
 11391                              <1> ;;;//-
 11392                              <1> ;;endp
 11393                              <1> 
 11394                              <1> duplicate_page_dir:
 11395                              <1> 	; 21/09/2015
 11396                              <1> 	; 31/08/2015
 11397                              <1> 	; 20/07/2015
 11398                              <1> 	; 28/04/2015
 11399                              <1> 	; 27/04/2015
 11400                              <1> 	; 18/04/2015
 11401                              <1> 	; 12/04/2015
 11402                              <1> 	; 18/10/2014
 11403                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11404                              <1> 	;
 11405                              <1> 	; INPUT -> 
 11406                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 11407                              <1> 	;		    page directory.
 11408                              <1> 	; OUTPUT ->
 11409                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 11410                              <1> 	;	       page directory.
 11411                              <1> 	;	(New page directory with new page table entries.)
 11412                              <1> 	;	(New page tables with read only copies of the parent's
 11413                              <1> 	;	pages.)
 11414                              <1> 	;	EAX = 0 -> Error (CF = 1)
 11415                              <1> 	;
 11416                              <1> 	; Modified Registers -> none (except EAX)
 11417                              <1> 	;
 11418 00003310 E8F2FDFFFF          <1> 	call	allocate_page
 11419 00003315 723E                <1> 	jc	short dpd_err
 11420                              <1> 	;
 11421 00003317 55                  <1> 	push	ebp ; 20/07/2015
 11422 00003318 56                  <1> 	push	esi
 11423 00003319 57                  <1> 	push	edi
 11424 0000331A 53                  <1> 	push	ebx
 11425 0000331B 51                  <1> 	push	ecx
 11426 0000331C 8B35[31D50000]      <1> 	mov	esi, [u.pgdir]
 11427 00003322 89C7                <1> 	mov	edi, eax
 11428 00003324 50                  <1> 	push	eax ; save child's page directory address
 11429                              <1> 	; 31/08/2015
 11430                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 11431                              <1> 	; (use same system space for all user page tables) 
 11432 00003325 A5                  <1> 	movsd
 11433 00003326 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 11434 0000332B B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 11435                              <1> dpd_0:	
 11436 00003330 AD                  <1> 	lodsd
 11437                              <1> 	;or	eax, eax
 11438                              <1>         ;jnz     short dpd_1
 11439 00003331 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 11440 00003333 7508                <1> 	jnz	short dpd_1
 11441                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
 11442 00003335 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 11443 0000333B EB0F                <1> 	jmp	short dpd_2
 11444                              <1> dpd_1:	
 11445 0000333D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 11446 00003341 89C3                <1> 	mov	ebx, eax
 11447                              <1> 	; EBX = Parent's page table address
 11448 00003343 E81F000000          <1> 	call	duplicate_page_table
 11449 00003348 720C                <1> 	jc	short dpd_p_err
 11450                              <1> 	; EAX = Child's page table address
 11451 0000334A 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 11452                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 11453                              <1> 			 ; (present, writable, user)
 11454                              <1> dpd_2:
 11455 0000334C AB                  <1> 	stosd
 11456 0000334D E2E1                <1> 	loop	dpd_0
 11457                              <1> 	;
 11458 0000334F 58                  <1> 	pop	eax  ; restore child's page directory address
 11459                              <1> dpd_3:
 11460 00003350 59                  <1> 	pop	ecx
 11461 00003351 5B                  <1> 	pop	ebx
 11462 00003352 5F                  <1> 	pop	edi
 11463 00003353 5E                  <1> 	pop	esi
 11464 00003354 5D                  <1> 	pop	ebp ; 20/07/2015
 11465                              <1> dpd_err:
 11466 00003355 C3                  <1> 	retn
 11467                              <1> dpd_p_err:
 11468                              <1> 	; release the allocated pages missing (recover free space)
 11469 00003356 58                  <1> 	pop	eax  ; the new page directory address (physical)
 11470 00003357 8B1D[31D50000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 11471 0000335D E8DEFEFFFF          <1> 	call 	deallocate_page_dir
 11472 00003362 29C0                <1> 	sub	eax, eax ; 0
 11473 00003364 F9                  <1> 	stc
 11474 00003365 EBE9                <1> 	jmp	short dpd_3	
 11475                              <1> 
 11476                              <1> duplicate_page_table:
 11477                              <1> 	; 21/09/2015
 11478                              <1> 	; 20/07/2015
 11479                              <1> 	; 05/05/2015
 11480                              <1> 	; 28/04/2015
 11481                              <1> 	; 27/04/2015
 11482                              <1> 	; 18/04/2015
 11483                              <1> 	; 18/10/2014
 11484                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11485                              <1> 	;
 11486                              <1> 	; INPUT -> 
 11487                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 11488                              <1> 	;	EBP = page table entry index (from 'duplicate_page_dir')
 11489                              <1> 	; OUTPUT ->
 11490                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 11491                              <1> 	;	      (with 'read only' attribute of page table entries)
 11492                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 11493                              <1> 	;	CF = 1 -> error 
 11494                              <1> 	;
 11495                              <1> 	; Modified Registers -> EBP (except EAX)
 11496                              <1> 	;
 11497 00003367 E89BFDFFFF          <1> 	call	allocate_page
 11498 0000336C 726A                <1> 	jc	short dpt_err
 11499                              <1> 	;
 11500 0000336E 50                  <1> 	push	eax ; *
 11501 0000336F 56                  <1> 	push	esi
 11502 00003370 57                  <1> 	push	edi
 11503 00003371 52                  <1> 	push	edx
 11504 00003372 51                  <1> 	push	ecx
 11505                              <1> 	;
 11506 00003373 89DE                <1> 	mov	esi, ebx
 11507 00003375 89C7                <1> 	mov	edi, eax
 11508 00003377 89C2                <1> 	mov	edx, eax
 11509 00003379 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 11510                              <1> dpt_0:
 11511 0000337F AD                  <1> 	lodsd
 11512 00003380 21C0                <1> 	and	eax, eax
 11513 00003382 7444                <1> 	jz	short dpt_3
 11514 00003384 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 11515 00003386 7507                <1> 	jnz	short dpt_1
 11516                              <1> 	; 20/07/2015
 11517                              <1> 	; ebp = virtual (linear) address of the memory page
 11518 00003388 E887040000          <1> 	call	reload_page ; 28/04/2015
 11519 0000338D 7244                <1> 	jc	short dpt_p_err
 11520                              <1> dpt_1:
 11521                              <1> 	; 21/09/2015
 11522 0000338F 89C1                <1> 	mov	ecx, eax
 11523 00003391 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11524 00003395 F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
 11525 00003398 7525                <1> 	jnz	short dpt_2
 11526                              <1> 	; Read only (parent) page
 11527                              <1> 	; 	- there is a third process which uses this page -
 11528                              <1> 	; Allocate a new page for the child process
 11529 0000339A E868FDFFFF          <1> 	call	allocate_page
 11530 0000339F 7232                <1> 	jc	short dpt_p_err
 11531 000033A1 57                  <1> 	push	edi
 11532 000033A2 56                  <1> 	push	esi
 11533 000033A3 89CE                <1> 	mov	esi, ecx
 11534 000033A5 89C7                <1> 	mov	edi, eax
 11535 000033A7 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 11536 000033AC F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 11537 000033AE 5E                  <1> 	pop	esi
 11538 000033AF 5F                  <1> 	pop	edi
 11539                              <1> 	; 
 11540 000033B0 53                  <1> 	push	ebx
 11541 000033B1 50                  <1> 	push	eax
 11542                              <1> 	; 20/07/2015
 11543 000033B2 89EB                <1> 	mov	ebx, ebp
 11544                              <1> 	; ebx = virtual address of the memory page
 11545 000033B4 E80B030000          <1> 	call	add_to_swap_queue
 11546 000033B9 58                  <1> 	pop	eax
 11547 000033BA 5B                  <1> 	pop	ebx
 11548                              <1> 	; 21/09/2015
 11549 000033BB 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 11550                              <1> 		; user + writable + present page
 11551 000033BD EB09                <1> 	jmp	short dpt_3
 11552                              <1> dpt_2:
 11553                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 11554 000033BF 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
 11555                              <1> 		    ; (read only page!)
 11556 000033C1 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
 11557 000033C4 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
 11558                              <1> dpt_3:
 11559 000033C8 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 11560                              <1> 	;
 11561 000033C9 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 11562                              <1> 	;
 11563 000033CF 39D7                <1> 	cmp	edi, edx
 11564 000033D1 72AC                <1> 	jb	short dpt_0
 11565                              <1> dpt_p_err:
 11566 000033D3 59                  <1> 	pop	ecx
 11567 000033D4 5A                  <1> 	pop	edx
 11568 000033D5 5F                  <1> 	pop	edi
 11569 000033D6 5E                  <1> 	pop	esi
 11570 000033D7 58                  <1> 	pop	eax ; *
 11571                              <1> dpt_err:
 11572 000033D8 C3                  <1> 	retn
 11573                              <1> 
 11574                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
 11575                              <1> 	; 21/09/2015
 11576                              <1> 	; 19/09/2015
 11577                              <1> 	; 17/09/2015
 11578                              <1> 	; 28/08/2015
 11579                              <1> 	; 20/07/2015
 11580                              <1> 	; 28/06/2015
 11581                              <1> 	; 03/05/2015
 11582                              <1> 	; 30/04/2015
 11583                              <1> 	; 18/04/2015
 11584                              <1> 	; 12/04/2015
 11585                              <1> 	; 30/10/2014
 11586                              <1> 	; 11/09/2014
 11587                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
 11588                              <1> 	;
 11589                              <1> 	; Note: This is not an interrupt/exception handler.
 11590                              <1> 	;	This is a 'page fault remedy' subroutine 
 11591                              <1> 	;	which will be called by standard/uniform
 11592                              <1> 	;	exception handler.
 11593                              <1> 	;
 11594                              <1> 	; INPUT -> 
 11595                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
 11596                              <1> 	;
 11597                              <1> 	;	cr2 = the virtual (linear) address 
 11598                              <1> 	;	      which has caused to page fault (19/09/2015)
 11599                              <1> 	;
 11600                              <1> 	; OUTPUT ->
 11601                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11602                              <1> 	;	EAX = 0 -> no error
 11603                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
 11604                              <1> 	;
 11605                              <1> 	; Modified Registers -> none (except EAX)
 11606                              <1> 	;	
 11607                              <1>         ;
 11608                              <1>         ; ERROR CODE:
 11609                              <1> 	;	 31  .....	4   3	2   1	0
 11610                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11611                              <1> 	;	|   Reserved  | I | R | U | W | P |
 11612                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11613                              <1> 	;
 11614                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
 11615                              <1>     	;		a page-protection violation. When not set,
 11616                              <1> 	;		it was caused by a non-present page.
 11617                              <1> 	; W : WRITE   -	When set, the page fault was caused by
 11618                              <1> 	;		a page write. When not set, it was caused
 11619                              <1> 	;		by a page read.
 11620                              <1> 	; U : USER    -	When set, the page fault was caused 
 11621                              <1> 	;		while CPL = 3. 
 11622                              <1> 	;		This does not necessarily mean that
 11623                              <1> 	;		the page fault was a privilege violation.
 11624                              <1> 	; R : RESERVD -	When set, the page fault was caused by
 11625                              <1> 	;     WRITE	reading a 1 in a reserved field.
 11626                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
 11627                              <1> 	;     FETCH	an instruction fetch
 11628                              <1> 	;
 11629                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
 11630                              <1> 	;  31               22                  12 11                    0
 11631                              <1> 	; +-------------------+-------------------+-----------------------+
 11632                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
 11633                              <1>        	; +-------------------+-------------------+-----------------------+
 11634                              <1> 	;
 11635                              <1> 
 11636                              <1> 	;; CR3 REGISTER (Control Register 3)
 11637                              <1> 	;  31                                   12             5 4 3 2   0
 11638                              <1> 	; +---------------------------------------+-------------+---+-----+
 11639                              <1>       	; |                                       |  		|P|P|     |
 11640                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
 11641                              <1>       	; |                                       | 		|D|T|     |
 11642                              <1>    	; +---------------------------------------+-------------+---+-----+
 11643                              <1> 	;
 11644                              <1> 	;	PWT    - WRITE THROUGH
 11645                              <1> 	;	PCD    - CACHE DISABLE		
 11646                              <1> 	;
 11647                              <1> 	;
 11648                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
 11649                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11650                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11651                              <1>       	; |                                       |     | | | | |P|P|U|R| |
 11652                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
 11653                              <1>       	; |                                       |     | | | | |D|T|S|W| |
 11654                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11655                              <1> 	;
 11656                              <1>         ;       P      - PRESENT
 11657                              <1>         ;       R/W    - READ/WRITE
 11658                              <1>         ;       U/S    - USER/SUPERVISOR
 11659                              <1> 	;	PWT    - WRITE THROUGH
 11660                              <1> 	;	PCD    - CACHE DISABLE	
 11661                              <1> 	;	A      - ACCESSED	
 11662                              <1>         ;       D      - DIRTY (IGNORED)
 11663                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11664                              <1> 	;	G      - GLOBAL	(IGNORED) 
 11665                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11666                              <1> 	;
 11667                              <1> 	;
 11668                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
 11669                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11670                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11671                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
 11672                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
 11673                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
 11674                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11675                              <1> 	;
 11676                              <1>         ;       P      - PRESENT
 11677                              <1>         ;       R/W    - READ/WRITE
 11678                              <1>         ;       U/S    - USER/SUPERVISOR
 11679                              <1> 	;	PWT    - WRITE THROUGH
 11680                              <1> 	;	PCD    - CACHE DISABLE	
 11681                              <1> 	;	A      - ACCESSED	
 11682                              <1>         ;       D      - DIRTY
 11683                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11684                              <1> 	;	G      - GLOBAL	 
 11685                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11686                              <1> 	;
 11687                              <1> 	;
 11688                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
 11689                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11690                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11691                              <1>       	; |                                       |     | | | | | | |U|R| |
 11692                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
 11693                              <1>       	; |                                       |     | | | | | | |S|W| |
 11694                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11695                              <1> 	;
 11696                              <1>         ;       P      - PRESENT
 11697                              <1>         ;       R/W    - READ/WRITE
 11698                              <1>         ;       U/S    - USER/SUPERVISOR
 11699                              <1>         ;       D      - DIRTY
 11700                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11701                              <1> 	;
 11702                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
 11703                              <1> 	;
 11704                              <1> 	;
 11705                              <1> 	;; Invalid Page Table Entry
 11706                              <1> 	; 31                                                           1 0
 11707                              <1>       	; +-------------------------------------------------------------+-+
 11708                              <1>       	; |                                                             | |
 11709                              <1>       	; |                          AVAILABLE                          |0|
 11710                              <1>       	; |                                                             | |
 11711                              <1>       	; +-------------------------------------------------------------+-+
 11712                              <1> 	;
 11713                              <1> 
 11714 000033D9 53                  <1> 	push	ebx
 11715 000033DA 52                  <1> 	push	edx
 11716 000033DB 51                  <1> 	push	ecx
 11717                              <1> 	;
 11718                              <1> 	; 21/09/2015 (debugging)
 11719 000033DC FF05[41D50000]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
 11720 000033E2 FF05[ACE10000]      <1> 	inc	dword [PF_Count] ; total page fault count	
 11721                              <1> 	; 28/06/2015
 11722                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
 11723 000033E8 8A15[A4E10000]      <1> 	mov	dl, [error_code]
 11724                              <1> 	;
 11725 000033EE F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
 11726                              <1> 			; sign
 11727 000033F1 7422                <1> 	jz	short pfh_alloc_np
 11728                              <1> 	; 
 11729                              <1> 	; If it is not a 'write on read only page' type page fault
 11730                              <1> 	; major page fault error with minor reason must be returned without 
 11731                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
 11732                              <1> 	; after return here!
 11733                              <1> 	; Page fault will be remedied, by copying page contents
 11734                              <1> 	; to newly allocated page with write permission;
 11735                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
 11736                              <1> 	; used for working with minimum possible memory usage. 
 11737                              <1> 	; sys_fork will duplicate page directory and tables of parent  
 11738                              <1> 	; process with 'read only' flag. If the child process attempts to
 11739                              <1> 	; write on these read only pages, page fault will be directed here
 11740                              <1> 	; for allocating a new page with same data/content. 
 11741                              <1> 	;
 11742                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
 11743                              <1> 	; will not force to separate CODE and DATA space 
 11744                              <1> 	; in a process/program... 
 11745                              <1> 	; CODE segment/section may contain DATA!
 11746                              <1> 	; It is flat, smoth and simplest programming method already as in 
 11747                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
 11748                              <1> 	;	
 11749 000033F3 F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
 11750                              <1> 			; sign
 11751 000033F6 0F84AB000000        <1>         jz      pfh_p_err
 11752                              <1> 	; 31/08/2015
 11753 000033FC F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
 11754                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
 11755 000033FF 0F84A2000000        <1>         jz	pfh_pv_err
 11756                              <1> 	;
 11757                              <1> 	; make a new page and copy the parent's page content
 11758                              <1> 	; as the child's new page content
 11759                              <1> 	;
 11760 00003405 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
 11761                              <1> 			 ; which has caused to page fault
 11762 00003408 E8A2000000          <1> 	call 	copy_page
 11763 0000340D 0F828D000000        <1>         jc      pfh_im_err ; insufficient memory
 11764                              <1> 	;
 11765 00003413 EB7D                <1>         jmp     pfh_cpp_ok
 11766                              <1> 	;
 11767                              <1> pfh_alloc_np:
 11768 00003415 E8EDFCFFFF          <1> 	call	allocate_page	; (allocate a new page)
 11769 0000341A 0F8280000000        <1>         jc      pfh_im_err	; 'insufficient memory' error
 11770                              <1> pfh_chk_cpl:
 11771                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11772                              <1> 		; (Lower 12 bits are ZERO, because 
 11773                              <1> 		;	the address is on a page boundary)
 11774 00003420 80E204              <1> 	and	dl, 4	; CPL = 3 ?
 11775 00003423 7505                <1> 	jnz	short pfh_um
 11776                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
 11777 00003425 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
 11778                              <1> 			 ; of the current/active page directory
 11779                              <1> 			 ; (Always kernel/system mode page directory, here!)
 11780                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
 11781 00003428 EB06                <1> 	jmp	short pfh_get_pde
 11782                              <1> 	;
 11783                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
 11784 0000342A 8B1D[31D50000]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
 11785                              <1> 			; Physical address of the USER's page directory
 11786                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
 11787                              <1> pfh_get_pde:
 11788 00003430 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
 11789 00003433 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
 11790                              <1> 			 ; which has been caused to page fault
 11791                              <1> 			 ;
 11792 00003436 C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
 11793 00003439 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
 11794                              <1> 	;
 11795 0000343C 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
 11796 0000343E 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
 11797 00003440 F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
 11798 00003443 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
 11799                              <1> 			  	  ; set/validate page directory entry
 11800 00003445 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11801 0000344A 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
 11802 0000344C 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
 11803 0000344E EB16                <1> 	jmp	short pfh_get_pte
 11804                              <1> pfh_set_pde:
 11805                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
 11806                              <1> 	;;	 (So, we know this PDE is empty or invalid)
 11807                              <1> 	;
 11808 00003450 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
 11809 00003452 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
 11810 00003454 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
 11811 00003456 89C3                <1> 	mov	ebx, eax
 11812 00003458 E8AAFCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
 11813 0000345D 7241                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
 11814                              <1> pfh_spde_1:
 11815                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11816 0000345F 89C1                <1> 	mov	ecx, eax
 11817 00003461 E81BFDFFFF          <1> 	call	clear_page ; Clear page content
 11818                              <1> pfh_get_pte:
 11819 00003466 0F20D0              <1> 	mov	eax, cr2 ; virtual address
 11820                              <1> 			 ; which has been caused to page fault
 11821 00003469 89C7                <1> 	mov	edi, eax ; 20/07/2015
 11822 0000346B C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
 11823                              <1> 			 ; higher 20 bits of the page fault address 
 11824 0000346E 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
 11825 00003473 C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
 11826 00003476 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
 11827 00003478 8B03                <1> 	mov	eax, [ebx] ; get previous value of pte
 11828                              <1> 		; bit 0 of EAX is always 0 (otherwise we would not be here)
 11829 0000347A 21C0                <1> 	and	eax, eax
 11830 0000347C 7410                <1> 	jz	short pfh_gpte_1
 11831                              <1> 	; 20/07/2015
 11832 0000347E 87D9                <1> 	xchg	ebx, ecx ; new page address (physical)
 11833 00003480 55                  <1> 	push	ebp ; 20/07/2015
 11834 00003481 0F20D5              <1> 	mov	ebp, cr2
 11835                              <1> 		; ECX = physical address of the page table entry
 11836                              <1> 		; EBX = Memory page address (physical!)
 11837                              <1> 		; EAX = Swap disk (offset) address
 11838                              <1> 		; EBP = virtual address (page fault address)
 11839 00003484 E8B7000000          <1> 	call	swap_in
 11840 00003489 5D                  <1> 	pop	ebp
 11841 0000348A 7210                <1> 	jc      short pfh_err_retn
 11842 0000348C 87CB                <1> 	xchg	ecx, ebx
 11843                              <1> 		; EBX = physical address of the page table entry
 11844                              <1> 		; ECX = new page
 11845                              <1> pfh_gpte_1:
 11846 0000348E 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
 11847 00003490 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
 11848                              <1> pfh_cpp_ok:
 11849                              <1> 	; 20/07/2015
 11850 00003492 0F20D3              <1> 	mov	ebx, cr2
 11851 00003495 E82A020000          <1> 	call 	add_to_swap_queue
 11852                              <1> 	;
 11853                              <1> 	; The new PTE (which contains the new page) will be added to 
 11854                              <1> 	; the swap queue, here. 
 11855                              <1> 	; (Later, if memory will become insufficient, 
 11856                              <1> 	; one page will be swapped out which is at the head of 
 11857                              <1> 	; the swap queue by using FIFO and access check methods.)
 11858                              <1> 	;
 11859 0000349A 31C0                <1> 	xor	eax, eax  ; 0
 11860                              <1> 	;
 11861                              <1> pfh_err_retn:
 11862 0000349C 59                  <1> 	pop	ecx
 11863 0000349D 5A                  <1> 	pop	edx
 11864 0000349E 5B                  <1> 	pop	ebx
 11865 0000349F C3                  <1> 	retn 
 11866                              <1> 	
 11867                              <1> pfh_im_err:
 11868 000034A0 B8E1000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
 11869                              <1> 			; Major (Primary) Error: Page Fault
 11870                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
 11871 000034A5 EBF5                <1> 	jmp	short pfh_err_retn
 11872                              <1> 
 11873                              <1> 
 11874                              <1> pfh_p_err: ; 09/03/2015
 11875                              <1> pfh_pv_err:
 11876                              <1> 	; Page fault was caused by a protection-violation
 11877 000034A7 B8E3000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
 11878                              <1> 			; Major (Primary) Error: Page Fault
 11879                              <1> 			; Minor (Secondary) Error: Protection violation !
 11880 000034AC F9                  <1> 	stc
 11881 000034AD EBED                <1> 	jmp	short pfh_err_retn
 11882                              <1> 
 11883                              <1> copy_page:
 11884                              <1> 	; 22/09/2015
 11885                              <1> 	; 21/09/2015
 11886                              <1> 	; 19/09/2015
 11887                              <1> 	; 07/09/2015
 11888                              <1> 	; 31/08/2015
 11889                              <1> 	; 20/07/2015
 11890                              <1> 	; 05/05/2015
 11891                              <1> 	; 03/05/2015
 11892                              <1> 	; 18/04/2015
 11893                              <1> 	; 12/04/2015
 11894                              <1> 	; 30/10/2014
 11895                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
 11896                              <1> 	;
 11897                              <1> 	; INPUT -> 
 11898                              <1> 	;	EBX = Virtual (linear) address of source page
 11899                              <1> 	;	     (Page fault address)
 11900                              <1> 	; OUTPUT ->
 11901                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11902                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11903                              <1> 	;	EAX = 0 (CF = 1) 
 11904                              <1> 	;		if there is not a free page to be allocated
 11905                              <1> 	;	(page content of the source page will be copied
 11906                              <1> 	;	onto the target/new page) 	
 11907                              <1> 	;
 11908                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
 11909                              <1> 	;	
 11910 000034AF 56                  <1> 	push	esi
 11911 000034B0 57                  <1> 	push	edi
 11912                              <1> 	;push	ebx
 11913                              <1> 	;push	ecx
 11914 000034B1 31F6                <1> 	xor 	esi, esi
 11915 000034B3 C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
 11916 000034B6 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
 11917 000034B8 C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
 11918 000034BB 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
 11919 000034BE 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
 11920 000034C0 031D[31D50000]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
 11921 000034C6 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
 11922 000034C8 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
 11923 000034CC 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
 11924 000034CE 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11925 000034D4 66C1E302            <1> 	shl	bx, 2	   ; shift 2 bits left to get PTE offset
 11926 000034D8 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
 11927                              <1> 	; 07/09/2015
 11928 000034DA 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
 11929                              <1> 				     ; read only page as a child process?)	
 11930 000034DF 7509                <1> 	jnz	short cpp_0 ; yes
 11931 000034E1 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
 11932 000034E3 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
 11933 000034E8 EB32                <1> 	jmp	short cpp_1
 11934                              <1> cpp_0:
 11935 000034EA 89FE                <1> 	mov	esi, edi
 11936 000034EC 0335[35D50000]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
 11937 000034F2 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
 11938 000034F4 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11939 000034F8 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
 11940 000034FA 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11941 00003500 66C1E602            <1> 	shl	si, 2	   ; shift 2 bits left to get PTE offset
 11942 00003504 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
 11943 00003506 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
 11944                              <1> 	; 21/09/2015
 11945 00003508 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
 11946 0000350A 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
 11947                              <1> 	;
 11948 0000350E F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
 11949 00003511 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
 11950                              <1> 	;
 11951 00003513 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
 11952 00003518 39C8                <1> 	cmp	eax, ecx   ; Same page?	
 11953 0000351A 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
 11954                              <1> 			    ; Convert child's page to writable page
 11955                              <1> cpp_1:
 11956 0000351C E8E6FBFFFF          <1> 	call	allocate_page
 11957 00003521 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
 11958 00003523 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
 11959 00003525 7405                <1> 	jz	short cpp_2
 11960                              <1> 		; Convert read only page to writable page 
 11961                              <1> 		;(for the parent of the current process)
 11962                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
 11963                              <1> 	; 22/09/2015
 11964 00003527 890E                <1> 	mov	[esi], ecx
 11965 00003529 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
 11966                              <1> 				 ; 1+2+4 = 7
 11967                              <1> cpp_2:
 11968 0000352C 89C7                <1> 	mov	edi, eax ; new page address of the child process
 11969                              <1> 	; 07/09/2015
 11970 0000352E 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
 11971 00003530 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 11972 00003535 F3A5                <1> 	rep	movsd ; 31/08/2015
 11973                              <1> cpp_3:		
 11974 00003537 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
 11975 00003539 8903                <1> 	mov	[ebx], eax ; Update PTE
 11976 0000353B 28C0                <1> 	sub	al, al ; clear attributes
 11977                              <1> cpp_4:
 11978                              <1> 	;pop	ecx
 11979                              <1> 	;pop	ebx
 11980 0000353D 5F                  <1> 	pop	edi
 11981 0000353E 5E                  <1> 	pop	esi
 11982 0000353F C3                  <1> 	retn
 11983                              <1> 
 11984                              <1> ;; 28/04/2015
 11985                              <1> ;; 24/10/2014
 11986                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
 11987                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
 11988                              <1> ;;
 11989                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
 11990                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
 11991                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
 11992                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
 11993                              <1> ;;
 11994                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
 11995                              <1> ;;
 11996                              <1> ;; Method:
 11997                              <1> ;;	Swap page queue is a list of allocated pages with physical
 11998                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
 11999                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
 12000                              <1> ;;	When a new page is being allocated, swap queue is updated
 12001                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
 12002                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
 12003                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
 12004                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
 12005                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
 12006                              <1> ;;	offset value becomes it's previous offset value - 4.
 12007                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
 12008                              <1> ;;	the queue/list is not shifted.
 12009                              <1> ;;	After the queue/list shift, newly allocated page is added
 12010                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
 12011                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
 12012                              <1> ;;	will not be added to the tail of swap page queue.  		 
 12013                              <1> ;;	
 12014                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
 12015                              <1> ;;	the first non-accessed, writable page in the list, 
 12016                              <1> ;;	from the head to the tail. The list is shifted to left 
 12017                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
 12018                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
 12019                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
 12020                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
 12021                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
 12022                              <1> ;;	procedure will be failed)...
 12023                              <1> ;;
 12024                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
 12025                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
 12026                              <1> ;;	(PTE) will be added to the tail of the queue after
 12027                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
 12028                              <1> ;;	the queue will be rotated and the PTE in the head will be
 12029                              <1> ;;	added to the tail after resetting 'accessed' bit. 
 12030                              <1> ;;
 12031                              <1> ;;
 12032                              <1> ;;	
 12033                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
 12034                              <1> ;;
 12035                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
 12036                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
 12037                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
 12038                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
 12039                              <1> ;;
 12040                              <1> ;; [swpd_next] = the first free block address in swapped page records
 12041                              <1> ;;    		 for next free block search by 'swap_out' procedure.
 12042                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
 12043                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
 12044                              <1> ;; 		 (entire swap space must be accessed by using
 12045                              <1> ;;		 31 bit offset address) 
 12046                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
 12047                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
 12048                              <1> ;;		  0 for file, or beginning sector of the swap partition
 12049                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
 12050                              <1> ;;
 12051                              <1> ;; 					
 12052                              <1> ;; Method:
 12053                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
 12054                              <1> ;;	procedure swaps out a page from memory to the swap disk 
 12055                              <1> ;;	(partition) or swap file to get a new free page at the memory.
 12056                              <1> ;;	Swapping out is performed by using swap page queue.
 12057                              <1> ;;
 12058                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
 12059                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
 12060                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
 12061                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
 12062                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
 12063                              <1> ;;	Absolute physical (logical) address of the swapped page is 
 12064                              <1> ;;	calculated by adding offset value to the swap partition's 
 12065                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
 12066                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
 12067                              <1> ;;	and offset value is equal to absolute (physical or logical)
 12068                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
 12069                              <1> ;;	is in a partitioned virtual hard disk.) 
 12070                              <1> ;;
 12071                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
 12072                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
 12073                              <1> ;;
 12074                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
 12075                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
 12076                              <1> ;;
 12077                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
 12078                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
 12079                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
 12080                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
 12081                              <1> ;;	it means relevant (respective) block is in use, and, 
 12082                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
 12083                              <1> ;;      swap disk/file block is free.
 12084                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
 12085                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
 12086                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
 12087                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
 12088                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
 12089                              <1> ;;	------------------------------------------------------------
 12090                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
 12091                              <1> ;;	------------------------------------------------------------
 12092                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
 12093                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
 12094                              <1> ;;
 12095                              <1> ;;	..............................................................
 12096                              <1> ;;
 12097                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
 12098                              <1> ;;	then it searches Swap Allocation Table if free count is not
 12099                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
 12100                              <1> ;;	position with value of 1 on the table is converted to swap
 12101                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
 12102                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
 12103                              <1> ;;	number of physical swap disk or virtual swap disk)
 12104                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
 12105                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
 12106                              <1> ;;	(memory page). That will be a direct disk write procedure.
 12107                              <1> ;;	(for preventing late memory allocation, significant waiting). 
 12108                              <1> ;;	If disk write procedure returns with error or free count of 
 12109                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
 12110                              <1> ;;	'insufficient memory error' (cf=1). 
 12111                              <1> ;;
 12112                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
 12113                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
 12114                              <1> ;;	in other words, 'swap_out' will not check the table for other
 12115                              <1> ;;	free blocks after a disk write error. It will return to 
 12116                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
 12117                              <1> ;;
 12118                              <1> ;;	After writing the page on to swap disk/file address/sector,
 12119                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
 12120                              <1> ;;	address (cf=0). 
 12121                              <1> ;;
 12122                              <1> ;;	..............................................................
 12123                              <1> ;;
 12124                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
 12125                              <1> ;;	file sectors at specified memory page. Then page allocation
 12126                              <1> ;;	procedure updates relevant page table entry with 'present' 
 12127                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
 12128                              <1> ;;	to do, except to terminate the process which is the owner of
 12129                              <1> ;;	the swapped page.
 12130                              <1> ;;
 12131                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
 12132                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
 12133                              <1> ;;	updates [swpd_first] pointer if it is required.
 12134                              <1> ;;
 12135                              <1> ;;	..............................................................	 
 12136                              <1> ;;
 12137                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
 12138                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
 12139                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
 12140                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
 12141                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
 12142                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
 12143                              <1> ;;
 12144                              <1> 
 12145                              <1> swap_in:
 12146                              <1> 	; 31/08/2015
 12147                              <1> 	; 20/07/2015
 12148                              <1> 	; 28/04/2015
 12149                              <1> 	; 18/04/2015
 12150                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12151                              <1> 	;
 12152                              <1> 	; INPUT -> 
 12153                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
 12154                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
 12155                              <1> 	;	EAX = Offset Address for the swapped page on the
 12156                              <1> 	;	      swap disk or in the swap file.
 12157                              <1> 	;
 12158                              <1> 	; OUTPUT ->
 12159                              <1> 	;	EAX = 0 if loading at memory has been successful
 12160                              <1> 	;
 12161                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
 12162                              <1> 	;		  or sector not present or drive not ready
 12163                              <1> 	;	     EAX = Error code
 12164                              <1> 	;	     [u.error] = EAX 
 12165                              <1> 	;		       = The last error code for the process
 12166                              <1> 	;		         (will be reset after returning to user)	  
 12167                              <1> 	;
 12168                              <1> 	; Modified Registers -> EAX
 12169                              <1> 	;
 12170                              <1> 
 12171 00003540 833D[8FE10000]00    <1>         cmp     dword [swp_drv], 0
 12172 00003547 7648                <1> 	jna	short swpin_dnp_err
 12173                              <1> 
 12174 00003549 3B05[93E10000]      <1> 	cmp	eax, [swpd_size]
 12175 0000354F 734C                <1> 	jnb	short swpin_snp_err
 12176                              <1> 
 12177 00003551 56                  <1> 	push	esi
 12178 00003552 53                  <1> 	push	ebx
 12179 00003553 51                  <1> 	push	ecx
 12180 00003554 8B35[8FE10000]      <1> 	mov	esi, [swp_drv]	
 12181 0000355A B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12182                              <1> 		; Note: Even if corresponding physical disk's sector 
 12183                              <1> 		; size different than 512 bytes, logical disk sector
 12184                              <1> 		; size is 512 bytes and disk reading procedure
 12185                              <1> 		; will be performed for reading 4096 bytes
 12186                              <1> 		; (2*2048, 8*512). 
 12187                              <1> 	; ESI = Logical disk description table address
 12188                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12189                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12190                              <1> 	; ECX = Sector count ; 8 sectors
 12191 0000355F 50                  <1> 	push	eax
 12192 00003560 E833020000          <1> 	call	logical_disk_read
 12193 00003565 58                  <1> 	pop	eax
 12194 00003566 730C                <1> 	jnc	short swpin_read_ok
 12195                              <1> 	;
 12196 00003568 B804000000          <1> 	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
 12197 0000356D A3[2DD50000]        <1> 	mov	[u.error], eax
 12198 00003572 EB19                <1> 	jmp	short swpin_retn
 12199                              <1> 	;
 12200                              <1> swpin_read_ok:
 12201                              <1> 	; EAX = Offset address (logical sector number)
 12202 00003574 E891010000          <1> 	call	unlink_swap_block  ; Deallocate swap block	
 12203                              <1> 	;
 12204                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12205                              <1> 	; 20/07/2015
 12206 00003579 89EB                <1> 	mov	ebx, ebp ; virtual address (page fault address)
 12207 0000357B 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12208 00003580 8A1D[27D50000]      <1> 	mov	bl, [u.uno] ; current process number
 12209                              <1> 	; EBX = Virtual address & process number combination
 12210 00003586 E89E000000          <1> 	call	swap_queue_shift
 12211 0000358B 29C0                <1> 	sub	eax, eax  ; 0 ; Error Code = 0  (no error)
 12212                              <1> 	;
 12213                              <1> swpin_retn:
 12214 0000358D 59                  <1> 	pop	ecx
 12215 0000358E 5B                  <1> 	pop	ebx
 12216 0000358F 5E                  <1> 	pop	esi
 12217 00003590 C3                  <1> 	retn
 12218                              <1> 
 12219                              <1> swpin_dnp_err:
 12220 00003591 B805000000          <1> 	mov	eax, SWP_DISK_NOT_PRESENT_ERR
 12221                              <1> swpin_err_retn:
 12222 00003596 A3[2DD50000]        <1> 	mov	[u.error], eax
 12223 0000359B F9                  <1> 	stc
 12224 0000359C C3                  <1> 	retn
 12225                              <1> 
 12226                              <1> swpin_snp_err:
 12227 0000359D B806000000          <1> 	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
 12228 000035A2 EBF2                <1> 	jmp	short swpin_err_retn
 12229                              <1> 
 12230                              <1> swap_out:
 12231                              <1> 	; 31/08/2015
 12232                              <1> 	; 05/05/2015
 12233                              <1> 	; 30/04/2015
 12234                              <1> 	; 28/04/2015
 12235                              <1> 	; 18/04/2015
 12236                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12237                              <1> 	;
 12238                              <1> 	; INPUT -> 
 12239                              <1> 	;	none
 12240                              <1> 	;
 12241                              <1> 	; OUTPUT ->
 12242                              <1> 	;	EAX = Physical page address (which is swapped out
 12243                              <1> 	;	      for allocating a new page)
 12244                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
 12245                              <1> 	;		  or sector not present or drive not ready
 12246                              <1> 	;	     EAX = Error code
 12247                              <1> 	;	     [u.error] = EAX 
 12248                              <1> 	;		       = The last error code for the process
 12249                              <1> 	;		         (will be reset after returning to user)	  
 12250                              <1> 	;
 12251                              <1> 	; Modified Registers -> non (except EAX)
 12252                              <1> 	;
 12253 000035A4 66833D[8DE10000]01  <1> 	cmp 	word [swpq_count], 1
 12254 000035AC 7274                <1>         jc      short swpout_im_err ; 'insufficient memory'
 12255                              <1> 
 12256                              <1>         ;cmp     dword [swp_drv], 1
 12257                              <1> 	;jc	short swpout_dnp_err ; 'swap disk/file not present'
 12258                              <1> 
 12259 000035AE 833D[97E10000]01    <1>         cmp     dword [swpd_free], 1
 12260 000035B5 7258                <1> 	jc	short swpout_nfspc_err ; 'no free space on swap disk'
 12261                              <1> 
 12262 000035B7 53                  <1> 	push	ebx
 12263                              <1> swpout_1:
 12264 000035B8 31DB                <1> 	xor	ebx, ebx
 12265 000035BA E86A000000          <1> 	call	swap_queue_shift
 12266 000035BF 21C0                <1> 	and	eax, eax	; entry count (before shifting)
 12267 000035C1 7457                <1> 	jz	short swpout_npts_err  ; There is no any PTE in
 12268                              <1> 				       ; the swap queue
 12269 000035C3 BB00E00800          <1> 	mov	ebx, swap_queue	       ; Addres of the head of 
 12270                              <1> 				       ; the swap queue		
 12271 000035C8 8B03                <1> 	mov	eax, [ebx]	       ; The PTE in the queue head	
 12272                              <1> 
 12273                              <1> 	;test	al, PTE_A_PRESENT      ; bit 0 = 1
 12274                              <1> 	;jz	short swpout_1	       ; non-present page already
 12275                              <1> 				       ; must not be in the queue
 12276                              <1> 
 12277                              <1> 	;test	al, PTE_A_WRITE	       ; bit 1 = 0
 12278                              <1> 	;jz	short swpout_1 	       ; read only page (must not be
 12279                              <1> 				       ; swapped out)
 12280                              <1> 	
 12281 000035CA A820                <1> 	test	al, PTE_A_ACCESS       ; bit 5 = 1 (Accessed)
 12282 000035CC 75EA                <1> 	jnz	short swpout_1 	       ; accessed page (must not be
 12283                              <1> 				       ; swapped out, at this stage)
 12284                              <1> 	;
 12285 000035CE 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12286                              <1> 	;
 12287 000035D2 52                  <1> 	push	edx
 12288 000035D3 89DA                <1> 	mov	edx, ebx	       ; Page table entry address	
 12289 000035D5 89C3                <1> 	mov	ebx, eax	       ; Buffer (Page) Address				
 12290                              <1> 	;
 12291 000035D7 E861010000          <1> 	call	link_swap_block
 12292 000035DC 7304                <1> 	jnc	short swpout_2	       ; It may not be needed here	
 12293 000035DE 5A                  <1> 	pop	edx		       ; because [swpd_free] value	
 12294 000035DF 5B                  <1> 	pop	ebx
 12295 000035E0 EB2D                <1> 	jmp	short swpout_nfspc_err ; was checked at the beginging. 	
 12296                              <1> swpout_2:	
 12297 000035E2 56                  <1> 	push	esi
 12298 000035E3 51                  <1> 	push	ecx
 12299 000035E4 50                  <1> 	push	eax ; sector address
 12300 000035E5 8B35[8FE10000]      <1> 	mov	esi, [swp_drv]	
 12301 000035EB B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12302                              <1> 		; Note: Even if corresponding physical disk's sector 
 12303                              <1> 		; size different than 512 bytes, logical disk sector
 12304                              <1> 		; size is 512 bytes and disk writing procedure
 12305                              <1> 		; will be performed for writing 4096 bytes
 12306                              <1> 		; (2*2048, 8*512). 
 12307                              <1> 	; ESI = Logical disk description table address
 12308                              <1> 	; EBX = Buffer address
 12309                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12310                              <1> 	; ECX = Sector count ; 8 sectors
 12311 000035F0 E8A4010000          <1> 	call	logical_disk_write
 12312 000035F5 59                  <1> 	pop	ecx ; sector address	
 12313 000035F6 730C                <1> 	jnc	short swpout_write_ok
 12314                              <1> 	;
 12315                              <1> 	;; call	unlink_swap_block ; this block must be left as 'in use'
 12316                              <1> swpout_dw_err:
 12317 000035F8 B808000000          <1> 	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
 12318 000035FD A3[2DD50000]        <1> 	mov	[u.error], eax
 12319 00003602 EB06                <1> 	jmp	short swpout_retn
 12320                              <1> 	;
 12321                              <1> swpout_write_ok:
 12322                              <1> 	; EBX = Buffer (page) address
 12323                              <1> 	; EDX = Page Table entry address
 12324                              <1> 	; ECX = Swap disk sector (file block) address (31 bit)
 12325 00003604 D1E1                <1> 	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
 12326 00003606 890A                <1> 	mov 	[edx], ecx 
 12327                              <1> 		; bit 0 = 0 (swapped page)
 12328 00003608 89D8                <1> 	mov	eax, ebx
 12329                              <1> swpout_retn:
 12330 0000360A 59                  <1> 	pop	ecx
 12331 0000360B 5E                  <1> 	pop	esi
 12332 0000360C 5A                  <1> 	pop	edx
 12333 0000360D 5B                  <1> 	pop	ebx
 12334 0000360E C3                  <1> 	retn
 12335                              <1> 
 12336                              <1> ; Note: Swap_queue will not be updated in 'swap_out' procedure
 12337                              <1> ;	after the page is swapped out. (the PTE at the queue head
 12338                              <1> ;	-with 'non-present' attribute- will be dropped from the
 12339                              <1> ;	the queue in next 'swap_out' or in next 'swap_queue_shift'.
 12340                              <1> 	
 12341                              <1> ;swpout_dnp_err:
 12342                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
 12343                              <1> ;	jmp	short swpout_err_retn
 12344                              <1> swpout_nfspc_err:
 12345 0000360F B807000000          <1> 	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
 12346                              <1> swpout_err_retn:
 12347 00003614 A3[2DD50000]        <1> 	mov	[u.error], eax
 12348                              <1> 	;stc
 12349 00003619 C3                  <1> 	retn
 12350                              <1> swpout_npts_err:
 12351 0000361A B809000000          <1> 	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
 12352 0000361F 5B                  <1> 	pop	ebx
 12353 00003620 EBF2                <1> 	jmp	short swpout_err_retn
 12354                              <1> swpout_im_err:
 12355 00003622 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
 12356 00003627 EBEB                <1> 	jmp	short swpout_err_retn
 12357                              <1> 
 12358                              <1> swap_queue_shift:
 12359                              <1> 	; 20/07/2015
 12360                              <1> 	; 28/04/2015
 12361                              <1> 	; 18/04/2015
 12362                              <1> 	; 23/10/2014 (Retro UNIX 386 v1 - beginning)
 12363                              <1> 	;
 12364                              <1> 	; INPUT ->
 12365                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
 12366                              <1> 	;	      and process number combination (bit 0 to 11)
 12367                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
 12368                              <1> 	; OUTPUT ->
 12369                              <1> 	;	If EBX input > 0 
 12370                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12371                              <1> 	; 	    from the tail to the head, up to entry offset
 12372                              <1> 	; 	    which points to EBX input value or nothing
 12373                              <1> 	;	    to do if EBX value is not found in the queue.
 12374                              <1> 	;	    (The entry -with EBX value- will be removed
 12375                              <1> 	;	     from the queue if it is found.)	
 12376                              <1> 	;	If EBX input = 0
 12377                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12378                              <1> 	; 	    from the tail to the head, if the PTE address
 12379                              <1> 	;	    in head of the queue is marked as "accessed"
 12380                              <1> 	;	    or it is marked as "non present".
 12381                              <1> 	;	    (If "accessed" flag of the PTE -in the head-
 12382                              <1> 	; 	    is set -to 1-, it will be reset -to 0- and then, 
 12383                              <1> 	;	    the queue will be rotated -without dropping
 12384                              <1> 	; 	    the PTE from the queue-, for 4 bytes on head
 12385                              <1> 	; 	    to tail direction. The PTE in the head will be
 12386                              <1> 	;	    moved in the tail, other PTEs will be shifted on
 12387                              <1> 	;	    head direction.)	
 12388                              <1> 	;
 12389                              <1> 	;	EAX = [swpq_count] (before the shifting)
 12390                              <1> 	;	    (EAX = 0 -> next 'swap_out' stage 
 12391                              <1> 	; 	     is not applicable)	
 12392                              <1> 	;
 12393                              <1> 	; Modified Registers -> EAX
 12394                              <1> 	;
 12395 00003629 0FB705[8DE10000]    <1> 	movzx   eax, word [swpq_count]  ; Max. 1024
 12396 00003630 6621C0              <1> 	and	ax, ax
 12397 00003633 7433                <1> 	jz	short swpqs_retn
 12398 00003635 57                  <1> 	push	edi
 12399 00003636 56                  <1> 	push	esi
 12400 00003637 53                  <1> 	push	ebx
 12401 00003638 51                  <1> 	push	ecx
 12402 00003639 50                  <1> 	push	eax
 12403 0000363A BE00E00800          <1> 	mov	esi, swap_queue
 12404 0000363F 89C1                <1> 	mov	ecx, eax
 12405 00003641 09DB                <1> 	or	ebx, ebx
 12406 00003643 7424                <1> 	jz	short swpqs_7
 12407                              <1> swpqs_1:
 12408 00003645 AD                  <1> 	lodsd
 12409 00003646 39D8                <1> 	cmp	eax, ebx
 12410 00003648 7404                <1> 	je	short swpqs_2
 12411 0000364A E2F9                <1> 	loop	swpqs_1
 12412 0000364C EB15                <1> 	jmp	short swpqs_6
 12413                              <1> swpqs_2:
 12414 0000364E 89F7                <1> 	mov	edi, esi
 12415 00003650 83EF04              <1> 	sub 	edi, 4
 12416                              <1> swpqs_3:
 12417 00003653 66FF0D[8DE10000]    <1> 	dec	word [swpq_count]
 12418 0000365A 7403                <1> 	jz	short swpqs_5
 12419                              <1> swpqs_4:
 12420 0000365C 49                  <1> 	dec 	ecx
 12421 0000365D F3A5                <1> 	rep	movsd	; shift up (to the head)
 12422                              <1> swpqs_5:
 12423 0000365F 31C0                <1> 	xor	eax, eax
 12424 00003661 8907                <1> 	mov	[edi], eax
 12425                              <1> swpqs_6:
 12426 00003663 58                  <1> 	pop	eax
 12427 00003664 59                  <1> 	pop	ecx
 12428 00003665 5B                  <1> 	pop	ebx
 12429 00003666 5E                  <1> 	pop	esi
 12430 00003667 5F                  <1> 	pop	edi
 12431                              <1> swpqs_retn:
 12432 00003668 C3                  <1> 	retn		
 12433                              <1> swpqs_7:
 12434 00003669 89F7                <1> 	mov	edi, esi ; head
 12435 0000366B AD                  <1> 	lodsd
 12436                              <1> 	; 20/07/2015
 12437 0000366C 89C3                <1> 	mov	ebx, eax
 12438 0000366E 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF ; ~0FFFh 
 12439                              <1> 		      ; ebx = virtual address (at page boundary)	
 12440 00003674 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 0FFFh
 12441                              <1> 		      ; ax = process number (1 to 4095)
 12442 00003679 3A05[27D50000]      <1> 	cmp	al, [u.uno]
 12443                              <1> 		; Max. 16 (nproc) processes for Retro UNIX 386 v1
 12444 0000367F 7507                <1> 	jne	short swpqs_8
 12445 00003681 A1[31D50000]        <1> 	mov	eax, [u.pgdir]
 12446 00003686 EB16                <1> 	jmp	short swpqs_9
 12447                              <1> swpqs_8:
 12448                              <1> 	;shl	ax, 2
 12449 00003688 C0E002              <1> 	shl	al, 2
 12450 0000368B 8B80[68D20000]      <1> 	mov 	eax, [eax+p.upage-4]
 12451 00003691 09C0                <1> 	or	eax, eax
 12452 00003693 74BE                <1> 	jz	short swpqs_3 ; invalid upage
 12453 00003695 83C061              <1> 	add	eax, u.pgdir - user
 12454                              <1> 			 ; u.pgdir value for the process
 12455                              <1> 			 ; is in [eax]
 12456 00003698 8B00                <1> 	mov	eax, [eax]
 12457 0000369A 21C0                <1> 	and	eax, eax
 12458 0000369C 74B5                <1> 	jz	short swpqs_3 ; invalid page directory
 12459                              <1> swpqs_9:
 12460 0000369E 52                  <1> 	push	edx
 12461                              <1> 	; eax = page directory
 12462                              <1> 	; ebx = virtual address
 12463 0000369F E87EFBFFFF          <1> 	call	get_pte
 12464 000036A4 89D3                <1> 	mov	ebx, edx ; PTE address
 12465 000036A6 5A                  <1> 	pop	edx
 12466 000036A7 72AA                <1> 	jc	short swpqs_3 ; empty PDE
 12467                              <1> 	; EAX = PTE value
 12468 000036A9 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0 = 1
 12469 000036AB 74A6                <1> 	jz	short swpqs_3 ; Drop non-present page
 12470                              <1> 			      ; from the queue (head)
 12471 000036AD A802                <1> 	test	al, PTE_A_WRITE	  ; bit 1 = 0
 12472 000036AF 74A2                <1> 	jz	short swpqs_3 ; Drop read only page
 12473                              <1> 			      ; from the queue (head) 	
 12474                              <1> 	;test	al, PTE_A_ACCESS  ; bit 5 = 1 (Accessed)
 12475                              <1> 	;jz	short swpqs_6 ; present
 12476                              <1> 			      ; non-accessed page
 12477 000036B1 0FBAF005            <1>         btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
 12478 000036B5 73AC                <1> 	jnc	short swpqs_6  ; non-accessed page
 12479 000036B7 8903                <1> 	mov	[ebx], eax     ; save changed attribute
 12480                              <1> 	;
 12481                              <1> 	; Rotation (head -> tail)
 12482 000036B9 49                  <1> 	dec	ecx     ; entry count -> last entry number		
 12483 000036BA 74A7                <1> 	jz	short swpqs_6
 12484                              <1> 		; esi = head + 4
 12485                              <1> 		; edi = head
 12486 000036BC 8B07                <1> 	mov	eax, [edi] ; 20/07/2015
 12487 000036BE F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
 12488 000036C0 8907                <1> 	mov	[edi], eax ; head -> tail ; [k] = [1] 		
 12489 000036C2 EB9F                <1> 	jmp	short swpqs_6
 12490                              <1> 
 12491                              <1> add_to_swap_queue:
 12492                              <1> ; temporary - 16/09/2015
 12493 000036C4 C3                  <1> retn
 12494                              <1> 	; 20/07/2015
 12495                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12496                              <1> 	;
 12497                              <1> 	; Adds new page to swap queue
 12498                              <1> 	; (page directories and page tables must not be added
 12499                              <1> 	; to swap queue)	
 12500                              <1> 	;
 12501                              <1> 	; INPUT ->
 12502                              <1> 	;	EBX = Virtual address (for current process, [u.uno])
 12503                              <1> 	;
 12504                              <1> 	; OUTPUT ->
 12505                              <1> 	;	EAX = [swpq_count]
 12506                              <1> 	;	      (after the PTE has been added)
 12507                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
 12508                              <1> 	;	      the pte could not be added.
 12509                              <1> 	;
 12510                              <1> 	; Modified Registers -> EAX
 12511                              <1> 	;
 12512 000036C5 53                  <1> 	push	ebx
 12513 000036C6 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12514 000036CB 8A1D[27D50000]      <1> 	mov	bl, [u.uno] ; current process number
 12515 000036D1 E853FFFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
 12516                              <1> 				 ; it is already in the queue
 12517                              <1> 		; Then add it to the tail of the queue
 12518 000036D6 0FB705[8DE10000]    <1> 	movzx	eax, word [swpq_count]
 12519 000036DD 663D0004            <1> 	cmp	ax, 1024
 12520 000036E1 7205                <1> 	jb	short atsq_1
 12521 000036E3 6629C0              <1> 	sub	ax, ax
 12522 000036E6 5B                  <1> 	pop	ebx
 12523 000036E7 C3                  <1> 	retn
 12524                              <1> atsq_1:
 12525 000036E8 56                  <1> 	push	esi
 12526 000036E9 BE00E00800          <1> 	mov	esi, swap_queue
 12527 000036EE 6621C0              <1> 	and	ax, ax
 12528 000036F1 740A                <1> 	jz	short atsq_2
 12529 000036F3 66C1E002            <1> 	shl	ax, 2	; convert to offset
 12530 000036F7 01C6                <1> 	add	esi, eax
 12531 000036F9 66C1E802            <1> 	shr	ax, 2
 12532                              <1> atsq_2:
 12533 000036FD 6640                <1> 	inc	ax
 12534 000036FF 891E                <1> 	mov	[esi], ebx ; Virtual address + [u.uno] combination
 12535 00003701 66A3[8DE10000]      <1> 	mov	[swpq_count], ax
 12536 00003707 5E                  <1> 	pop	esi
 12537 00003708 5B                  <1> 	pop	ebx
 12538 00003709 C3                  <1> 	retn
 12539                              <1> 
 12540                              <1> unlink_swap_block:
 12541                              <1> 	; 15/09/2015
 12542                              <1> 	; 30/04/2015
 12543                              <1> 	; 18/04/2015
 12544                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12545                              <1> 	;
 12546                              <1> 	; INPUT -> 
 12547                              <1> 	;	EAX = swap disk/file offset address
 12548                              <1> 	;	      (bit 1 to bit 31)
 12549                              <1> 	; OUTPUT ->
 12550                              <1> 	;	[swpd_free] is increased
 12551                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
 12552                              <1> 	;
 12553                              <1> 	; Modified Registers -> EAX
 12554                              <1> 	;
 12555 0000370A 53                  <1> 	push	ebx
 12556 0000370B 52                  <1> 	push	edx
 12557                              <1> 	;
 12558 0000370C C1E804              <1> 	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
 12559                              <1> 				     ; 3 bits right
 12560                              <1> 				     ; to get swap block/page number
 12561 0000370F 89C2                <1> 	mov	edx, eax
 12562                              <1> 	; 15/09/2015
 12563 00003711 C1EA03              <1> 	shr	edx, 3		     ; to get offset to S.A.T.
 12564                              <1> 				     ; (1 allocation bit = 1 page)
 12565                              <1> 				     ; (1 allocation bytes = 8 pages)
 12566 00003714 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 12567                              <1> 				     ; (to get 32 bit position)			
 12568                              <1> 	;
 12569 00003717 BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table address
 12570 0000371C 01D3                <1> 	add	ebx, edx
 12571 0000371E 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 12572                              <1> 				     ; (allocation bit position)	 
 12573 00003721 3B05[9BE10000]      <1> 	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
 12574                              <1> 				     ; than the address in 'swpd_next' ?
 12575                              <1> 				     ; (next/first free block value)		
 12576 00003727 7305                <1> 	jnb	short uswpbl_1	     ; no	
 12577 00003729 A3[9BE10000]        <1> 	mov	[swpd_next], eax     ; yes	
 12578                              <1> uswpbl_1:
 12579 0000372E 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate block
 12580                              <1> 				     ; set relevant bit to 1.
 12581                              <1> 				     ; set CF to the previous bit value	
 12582 00003731 F5                  <1> 	cmc			     ; complement carry flag	
 12583 00003732 7206                <1> 	jc	short uswpbl_2	     ; do not increase swfd_free count
 12584                              <1> 				     ; if the block is already deallocated
 12585                              <1> 				     ; before.	
 12586 00003734 FF05[97E10000]      <1>         inc     dword [swpd_free]
 12587                              <1> uswpbl_2:
 12588 0000373A 5A                  <1> 	pop	edx
 12589 0000373B 5B                  <1> 	pop	ebx
 12590 0000373C C3                  <1> 	retn
 12591                              <1> 
 12592                              <1> link_swap_block:
 12593                              <1> 	; 01/07/2015
 12594                              <1> 	; 18/04/2015
 12595                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12596                              <1> 	;
 12597                              <1> 	; INPUT -> none
 12598                              <1> 	;
 12599                              <1> 	; OUTPUT ->
 12600                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
 12601                              <1> 	;	      in sectors (corresponding 
 12602                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
 12603                              <1> 	;
 12604                              <1> 	;	CF = 1 and EAX = 0 
 12605                              <1> 	; 		   if there is not a free block to be allocated	
 12606                              <1> 	;
 12607                              <1> 	; Modified Registers -> none (except EAX)
 12608                              <1> 	;
 12609                              <1> 
 12610                              <1> 	;mov	eax, [swpd_free]
 12611                              <1> 	;and	eax, eax
 12612                              <1> 	;jz	short out_of_swpspc
 12613                              <1> 	;
 12614 0000373D 53                  <1> 	push	ebx
 12615 0000373E 51                  <1> 	push	ecx
 12616                              <1> 	;
 12617 0000373F BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
 12618 00003744 89D9                <1> 	mov	ecx, ebx
 12619 00003746 031D[9BE10000]      <1> 	add	ebx, [swpd_next] ; Free block searching starts from here
 12620                              <1> 				 ; next_free_swap_block >> 5
 12621 0000374C 030D[9FE10000]      <1> 	add	ecx, [swpd_last] ; Free block searching ends here
 12622                              <1> 				 ; (total_swap_blocks - 1) >> 5
 12623                              <1> lswbl_scan:
 12624 00003752 39CB                <1> 	cmp	ebx, ecx
 12625 00003754 770A                <1> 	ja	short lswbl_notfound
 12626                              <1> 	;
 12627 00003756 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 12628                              <1> 			   ; Clears ZF if a bit is found set (1) and 
 12629                              <1> 			   ; loads the destination with an index to
 12630                              <1> 			   ; first set bit. (0 -> 31) 
 12631                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 12632                              <1> 	; 01/07/2015
 12633 00003759 751C                <1> 	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
 12634                              <1> 			 ;
 12635                              <1> 			 ; NOTE:  a Swap Disk Allocation Table bit 
 12636                              <1> 			 ;	  with value of 1 means 
 12637                              <1> 			 ;	  the corresponding page is free 
 12638                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 12639 0000375B 83C304              <1> 	add	ebx, 4
 12640                              <1> 			 ; We return back for searching next page block
 12641                              <1> 			 ; NOTE: [swpd_free] is not ZERO; so, 
 12642                              <1> 			 ;	 we always will find at least 1 free block here.
 12643 0000375E EBF2                <1> 	jmp    	short lswbl_scan
 12644                              <1> 	;
 12645                              <1> lswbl_notfound:	
 12646 00003760 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12647 00003766 890D[9BE10000]      <1> 	mov	[swpd_next], ecx ; next/first free page = last page 
 12648                              <1> 				 ; (unlink_swap_block procedure will change it)
 12649 0000376C 31C0                <1> 	xor	eax, eax
 12650 0000376E A3[97E10000]        <1> 	mov	[swpd_free], eax
 12651 00003773 F9                  <1> 	stc
 12652                              <1> lswbl_ok:
 12653 00003774 59                  <1> 	pop	ecx
 12654 00003775 5B                  <1> 	pop	ebx
 12655 00003776 C3                  <1> 	retn
 12656                              <1> 	;
 12657                              <1> ;out_of_swpspc:
 12658                              <1> ;	stc
 12659                              <1> ;	retn
 12660                              <1> 
 12661                              <1> lswbl_found:
 12662 00003777 89D9                <1> 	mov	ecx, ebx
 12663 00003779 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12664 0000377F 890D[9BE10000]      <1> 	mov	[swpd_next], ecx ; Set first free block searching start
 12665                              <1> 				 ; address/offset (to the next)
 12666 00003785 FF0D[97E10000]      <1>         dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
 12667                              <1> 	;
 12668 0000378B 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 12669                              <1> 				 ; is copied into the Carry Flag and then cleared
 12670                              <1> 				 ; in the destination.
 12671                              <1> 				 ;
 12672                              <1> 				 ; Reset the bit which is corresponding to the 
 12673                              <1> 				 ; (just) allocated block.
 12674 0000378E C1E105              <1> 	shl	ecx, 5		 ; (block offset * 32) + block index
 12675 00003791 01C8                <1> 	add	eax, ecx	 ; = block number
 12676 00003793 C1E003              <1> 	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
 12677                              <1> 				 ; 1 block =  8 sectors
 12678                              <1> 	;
 12679                              <1> 	; EAX = offset address of swap disk/file sector (beginning of the block)
 12680                              <1> 	;
 12681                              <1> 	; NOTE: The relevant page table entry will be updated
 12682                              <1> 	;       according to this EAX value...
 12683                              <1> 	;
 12684 00003796 EBDC                <1> 	jmp	short lswbl_ok
 12685                              <1> 
 12686                              <1> logical_disk_read:
 12687                              <1> 	; 20/07/2015
 12688                              <1> 	; 09/03/2015 (temporary code here)
 12689                              <1> 	;
 12690                              <1> 	; INPUT ->
 12691                              <1> 	; 	ESI = Logical disk description table address
 12692                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12693                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12694                              <1> 	; 	ECX = Sector count
 12695                              <1> 	;
 12696                              <1> 	;
 12697 00003798 C3                  <1> 	retn
 12698                              <1> 
 12699                              <1> logical_disk_write:
 12700                              <1> 	; 20/07/2015
 12701                              <1> 	; 09/03/2015 (temporary code here)
 12702                              <1> 	;
 12703                              <1> 	; INPUT ->
 12704                              <1> 	; 	ESI = Logical disk description table address
 12705                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12706                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12707                              <1> 	; 	ECX = Sector count
 12708                              <1> 	;
 12709 00003799 C3                  <1> 	retn
 12710                              <1> 
 12711                              <1> get_physical_addr:
 12712                              <1> 	; 18/10/2015
 12713                              <1> 	; 29/07/2015
 12714                              <1> 	; 20/07/2015
 12715                              <1> 	; 04/06/2015
 12716                              <1> 	; 20/05/2015
 12717                              <1> 	; 28/04/2015
 12718                              <1> 	; 18/04/2015
 12719                              <1> 	; Get physical address
 12720                              <1> 	;     (allocates a new page for user if it is not present)
 12721                              <1> 	;	
 12722                              <1> 	; (This subroutine is needed for mapping user's virtual 
 12723                              <1> 	; (buffer) address to physical address (of the buffer).)
 12724                              <1> 	; ('sys write', 'sys read' system calls...)
 12725                              <1> 	;
 12726                              <1> 	; INPUT ->
 12727                              <1> 	;	EBX = virtual address
 12728                              <1> 	;	u.pgdir = page directory (physical) address
 12729                              <1> 	;
 12730                              <1> 	; OUTPUT ->
 12731                              <1> 	;	EAX = physical address 
 12732                              <1> 	;	EBX = linear address	
 12733                              <1> 	;	EDX = physical address of the page frame
 12734                              <1> 	;	      (with attribute bits)
 12735                              <1> 	;	ECX = byte count within the page frame
 12736                              <1> 	;
 12737                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
 12738                              <1> 	;
 12739 0000379A 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
 12740                              <1> 	;
 12741 000037A0 A1[31D50000]        <1> 	mov	eax, [u.pgdir]
 12742 000037A5 E878FAFFFF          <1> 	call	get_pte
 12743                              <1> 		; EDX = Page table entry address (if CF=0)
 12744                              <1> 	        ;       Page directory entry address (if CF=1)
 12745                              <1> 		;       (Bit 0 value is 0 if PT is not present)
 12746                              <1> 		; EAX = Page table entry value (page address)
 12747                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
 12748 000037AA 731C                <1> 	jnc	short gpa_1
 12749                              <1> 	;
 12750 000037AC E856F9FFFF          <1> 	call	allocate_page
 12751 000037B1 725B                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
 12752                              <1> gpa_0:
 12753 000037B3 E8C9F9FFFF          <1> 	call 	clear_page
 12754                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 12755 000037B8 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
 12756                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
 12757                              <1> 			   ; (user, writable, present page)	
 12758 000037BA 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
 12759 000037BC A1[31D50000]        <1> 	mov	eax, [u.pgdir]	
 12760 000037C1 E85CFAFFFF          <1> 	call	get_pte
 12761 000037C6 7246                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12762                              <1> gpa_1:
 12763                              <1> 	; EAX = PTE value, EDX = PTE address
 12764 000037C8 A801                <1> 	test 	al, PTE_A_PRESENT
 12765 000037CA 751A                <1> 	jnz	short gpa_3
 12766 000037CC 09C0                <1> 	or	eax, eax
 12767 000037CE 7430                <1> 	jz	short gpa_4  ; Allocate a new page
 12768                              <1> 	; 20/07/2015
 12769 000037D0 55                  <1> 	push	ebp
 12770 000037D1 89DD                <1> 	mov	ebp, ebx ; virtual (linear) address
 12771                              <1> 	; reload swapped page
 12772 000037D3 E83C000000          <1> 	call	reload_page ; 28/04/2015
 12773 000037D8 5D                  <1> 	pop	ebp
 12774 000037D9 7224                <1> 	jc	short gpa_retn
 12775                              <1> gpa_2:
 12776                              <1> 	; 20/07/2015
 12777                              <1> 	; 20/05/2015
 12778                              <1> 	; add this page to swap queue
 12779 000037DB 50                  <1> 	push	eax 
 12780                              <1> 	; EBX = virtual address
 12781 000037DC E8E3FEFFFF          <1> 	call 	add_to_swap_queue
 12782 000037E1 58                  <1> 	pop	eax
 12783                              <1> 		; PTE address in EDX
 12784                              <1> 		; virtual address in EBX
 12785                              <1> 	; EAX = memory page address
 12786 000037E2 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
 12787                              <1> 				  ; present flag, bit 0 = 1
 12788                              <1> 				  ; user flag, bit 2 = 1	
 12789                              <1> 				  ; writable flag, bit 1 = 1
 12790 000037E4 8902                <1> 	mov	[edx], eax  ; Update PTE value
 12791                              <1> gpa_3:
 12792                              <1> 	; 18/10/2015
 12793 000037E6 89D9                <1> 	mov	ecx, ebx
 12794 000037E8 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
 12795 000037EE 89C2                <1> 	mov 	edx, eax
 12796 000037F0 662500F0            <1> 	and	ax, PTE_A_CLEAR
 12797 000037F4 01C8                <1> 	add	eax, ecx
 12798 000037F6 F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
 12799 000037F8 81C100100000        <1> 	add	ecx, PAGE_SIZE
 12800 000037FE F8                  <1> 	clc
 12801                              <1> gpa_retn:
 12802 000037FF C3                  <1> 	retn	
 12803                              <1> gpa_4:	
 12804 00003800 E802F9FFFF          <1> 	call	allocate_page
 12805 00003805 7207                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12806 00003807 E875F9FFFF          <1> 	call	clear_page
 12807 0000380C EBCD                <1> 	jmp	short gpa_2
 12808                              <1> 
 12809                              <1> gpa_im_err:	
 12810 0000380E B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12811                              <1> 				  ; Major error = 0 (No protection fault)	
 12812 00003813 C3                  <1> 	retn
 12813                              <1> 
 12814                              <1> reload_page:
 12815                              <1> 	; 20/07/2015
 12816                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
 12817                              <1> 	;
 12818                              <1> 	; Reload (Restore) swapped page at memory
 12819                              <1> 	;
 12820                              <1> 	; INPUT -> 
 12821                              <1> 	;	EBP = Virtual (linear) memory address
 12822                              <1> 	;	EAX = PTE value (swap disk sector address)
 12823                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
 12824                              <1> 	; OUTPUT ->
 12825                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
 12826                              <1> 	;
 12827                              <1> 	;	CF = 1 and EAX = error code
 12828                              <1> 	;
 12829                              <1> 	; Modified Registers -> none (except EAX)
 12830                              <1> 	;
 12831 00003814 D1E8                <1> 	shr	eax, 1   ; Convert PTE value to swap disk address 
 12832 00003816 53                  <1> 	push	ebx      ;
 12833 00003817 89C3                <1> 	mov	ebx, eax ; Swap disk (offset) address	
 12834 00003819 E8E9F8FFFF          <1> 	call	allocate_page
 12835 0000381E 720C                <1> 	jc	short rlp_im_err
 12836 00003820 93                  <1> 	xchg 	eax, ebx	
 12837                              <1> 	; EBX = Physical memory (page) address
 12838                              <1> 	; EAX = Swap disk (offset) address
 12839                              <1> 	; EBP = Virtual (linear) memory address
 12840 00003821 E81AFDFFFF          <1> 	call	swap_in
 12841 00003826 720B                <1> 	jc	short rlp_swp_err  ; (swap disk/file read error)
 12842 00003828 89D8                <1> 	mov	eax, ebx	
 12843                              <1> rlp_retn:
 12844 0000382A 5B                  <1> 	pop	ebx
 12845 0000382B C3                  <1> 	retn
 12846                              <1> 	
 12847                              <1> rlp_im_err:	
 12848 0000382C B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12849                              <1> 				  ; Major error = 0 (No protection fault)	
 12850 00003831 EBF7                <1> 	jmp	short rlp_retn
 12851                              <1> 
 12852                              <1> rlp_swp_err:
 12853 00003833 B804000000          <1> 	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
 12854 00003838 EBF0                <1> 	jmp	short rlp_retn
 12855                              <1> 
 12856                              <1> 
 12857                              <1> copy_page_dir:
 12858                              <1> 	; 19/09/2015
 12859                              <1> 	; temporary - 07/09/2015
 12860                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12861                              <1> 	;
 12862                              <1> 	; INPUT -> 
 12863                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 12864                              <1> 	;		    page directory.
 12865                              <1> 	; OUTPUT ->
 12866                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 12867                              <1> 	;	       page directory.
 12868                              <1> 	;	(New page directory with new page table entries.)
 12869                              <1> 	;	(New page tables with read only copies of the parent's
 12870                              <1> 	;	pages.)
 12871                              <1> 	;	EAX = 0 -> Error (CF = 1)
 12872                              <1> 	;
 12873                              <1> 	; Modified Registers -> none (except EAX)
 12874                              <1> 	;
 12875 0000383A E8C8F8FFFF          <1> 	call	allocate_page
 12876 0000383F 723E                <1> 	jc	short cpd_err
 12877                              <1> 	;
 12878 00003841 55                  <1> 	push	ebp ; 20/07/2015
 12879 00003842 56                  <1> 	push	esi
 12880 00003843 57                  <1> 	push	edi
 12881 00003844 53                  <1> 	push	ebx
 12882 00003845 51                  <1> 	push	ecx
 12883 00003846 8B35[31D50000]      <1> 	mov	esi, [u.pgdir]
 12884 0000384C 89C7                <1> 	mov	edi, eax
 12885 0000384E 50                  <1> 	push	eax ; save child's page directory address
 12886                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 12887                              <1> 	; (use same system space for all user page tables) 
 12888 0000384F A5                  <1> 	movsd
 12889 00003850 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 12890 00003855 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 12891                              <1> cpd_0:	
 12892 0000385A AD                  <1> 	lodsd
 12893                              <1> 	;or	eax, eax
 12894                              <1>         ;jnz     short cpd_1
 12895 0000385B A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 12896 0000385D 7508                <1> 	jnz	short cpd_1
 12897                              <1>  	; (virtual address at the end of the page table)	
 12898 0000385F 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 12899 00003865 EB0F                <1> 	jmp	short cpd_2
 12900                              <1> cpd_1:	
 12901 00003867 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 12902 0000386B 89C3                <1> 	mov	ebx, eax
 12903                              <1> 	; EBX = Parent's page table address
 12904 0000386D E81F000000          <1> 	call	copy_page_table
 12905 00003872 720C                <1> 	jc	short cpd_p_err
 12906                              <1> 	; EAX = Child's page table address
 12907 00003874 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 12908                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 12909                              <1> 			 ; (present, writable, user)
 12910                              <1> cpd_2:
 12911 00003876 AB                  <1> 	stosd
 12912 00003877 E2E1                <1> 	loop	cpd_0
 12913                              <1> 	;
 12914 00003879 58                  <1> 	pop	eax  ; restore child's page directory address
 12915                              <1> cpd_3:
 12916 0000387A 59                  <1> 	pop	ecx
 12917 0000387B 5B                  <1> 	pop	ebx
 12918 0000387C 5F                  <1> 	pop	edi
 12919 0000387D 5E                  <1> 	pop	esi
 12920 0000387E 5D                  <1> 	pop	ebp
 12921                              <1> cpd_err:
 12922 0000387F C3                  <1> 	retn
 12923                              <1> cpd_p_err:
 12924                              <1> 	; release the allocated pages missing (recover free space)
 12925 00003880 58                  <1> 	pop	eax  ; the new page directory address (physical)
 12926 00003881 8B1D[31D50000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 12927 00003887 E8B4F9FFFF          <1> 	call 	deallocate_page_dir
 12928 0000388C 29C0                <1> 	sub	eax, eax ; 0
 12929 0000388E F9                  <1> 	stc
 12930 0000388F EBE9                <1> 	jmp	short cpd_3	
 12931                              <1> 
 12932                              <1> copy_page_table:
 12933                              <1> 	; 19/09/2015
 12934                              <1> 	; temporary - 07/09/2015
 12935                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12936                              <1> 	;
 12937                              <1> 	; INPUT -> 
 12938                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 12939                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
 12940                              <1> 	; OUTPUT ->
 12941                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 12942                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 12943                              <1> 	;	CF = 1 -> error 
 12944                              <1> 	;
 12945                              <1> 	; Modified Registers -> EBP (except EAX)
 12946                              <1> 	;
 12947 00003891 E871F8FFFF          <1> 	call	allocate_page
 12948 00003896 725A                <1> 	jc	short cpt_err
 12949                              <1> 	;
 12950 00003898 50                  <1> 	push	eax ; *
 12951                              <1> 	;push 	ebx
 12952 00003899 56                  <1> 	push	esi
 12953 0000389A 57                  <1> 	push	edi
 12954 0000389B 52                  <1> 	push	edx
 12955 0000389C 51                  <1> 	push	ecx
 12956                              <1> 	;
 12957 0000389D 89DE                <1> 	mov	esi, ebx
 12958 0000389F 89C7                <1> 	mov	edi, eax
 12959 000038A1 89C2                <1> 	mov	edx, eax
 12960 000038A3 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 12961                              <1> cpt_0:
 12962 000038A9 AD                  <1> 	lodsd
 12963 000038AA A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 12964 000038AC 750B                <1> 	jnz	short cpt_1
 12965 000038AE 21C0                <1> 	and	eax, eax
 12966 000038B0 7430                <1> 	jz	short cpt_2
 12967                              <1> 	; ebp = virtual (linear) address of the memory page
 12968 000038B2 E85DFFFFFF          <1> 	call	reload_page ; 28/04/2015
 12969 000038B7 7234                <1> 	jc	short cpt_p_err
 12970                              <1> cpt_1:
 12971 000038B9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12972 000038BD 89C1                <1> 	mov	ecx, eax
 12973                              <1> 	; Allocate a new page for the child process
 12974 000038BF E843F8FFFF          <1> 	call	allocate_page
 12975 000038C4 7227                <1> 	jc	short cpt_p_err
 12976 000038C6 57                  <1> 	push	edi
 12977 000038C7 56                  <1> 	push	esi
 12978 000038C8 89CE                <1> 	mov	esi, ecx
 12979 000038CA 89C7                <1> 	mov	edi, eax
 12980 000038CC B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 12981 000038D1 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 12982 000038D3 5E                  <1> 	pop	esi
 12983 000038D4 5F                  <1> 	pop	edi
 12984                              <1> 	; 
 12985 000038D5 53                  <1> 	push	ebx
 12986 000038D6 50                  <1> 	push	eax
 12987 000038D7 89EB                <1> 	mov	ebx, ebp
 12988                              <1> 	; ebx = virtual address of the memory page
 12989 000038D9 E8E6FDFFFF          <1> 	call	add_to_swap_queue
 12990 000038DE 58                  <1> 	pop	eax
 12991 000038DF 5B                  <1> 	pop	ebx
 12992                              <1> 	;
 12993                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 12994 000038E0 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 12995                              <1> cpt_2:
 12996 000038E2 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 12997                              <1> 	;
 12998 000038E3 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 12999                              <1> 	;
 13000 000038E9 39D7                <1> 	cmp	edi, edx
 13001 000038EB 72BC                <1> 	jb	short cpt_0
 13002                              <1> cpt_p_err:
 13003 000038ED 59                  <1> 	pop	ecx
 13004 000038EE 5A                  <1> 	pop	edx
 13005 000038EF 5F                  <1> 	pop	edi
 13006 000038F0 5E                  <1> 	pop	esi
 13007                              <1> 	;pop	ebx
 13008 000038F1 58                  <1> 	pop	eax ; *
 13009                              <1> cpt_err:
 13010 000038F2 C3                  <1> 	retn
 13011                              <1> 
 13012                              <1> 
 13013                              <1> allocate_memory_block:
 13014                              <1> 	; 03/04/2016
 13015                              <1> 	; 02/04/2016
 13016                              <1> 	; 01/04/2016
 13017                              <1> 	; 14/03/2016
 13018                              <1> 	; 13/03/2016
 13019                              <1> 	; 12/03/2016 (TRDOS 386 = TRDOS v2.0)
 13020                              <1> 	; Allocating contiguous memory pages (in the kernel's memory space)
 13021                              <1> 	;
 13022                              <1> 	; INPUT -> 
 13023                              <1> 	;	EAX = Beginning address (physical)
 13024                              <1> 	;	EAX = 0 -> Allocate memory block from the first proper aperture	
 13025                              <1> 	;	ECX = Number of bytes to be allocated
 13026                              <1> 	;
 13027                              <1> 	; OUTPUT ->
 13028                              <1> 	; 	1) cf = 0 -> successful
 13029                              <1> 	;	EAX = Beginning (physical) address of the allocated memory block
 13030                              <1> 	;	ECX = Number of allocated bytes (rounded up to page borders) 
 13031                              <1> 	;	2) cf = 1 -> unsuccessful
 13032                              <1> 	;	 2.1) If EAX > 0 -> 
 13033                              <1> 	;	      (Number of requested pages is more than # of free pages
 13034                              <1> 	;	       but contiguous free pages -the aperture- is not enough!)	   	
 13035                              <1> 	;	      EAX = Beginning address of available aperture
 13036                              <1> 	;		    (one of all aperture with max. aperture size/length)		
 13037                              <1> 	;	      ECX = Size of available aperture (memory block) in bytes
 13038                              <1> 	;	 2.2) If EAX = 0 -> Out of memory error 
 13039                              <1> 	;	            (number of free pages is less than requested number)
 13040                              <1> 	;	      ECX = Total number of free bytes (free pages * 4096) 
 13041                              <1> 	;		    (It is not number of contiguous free bytes)	
 13042                              <1> 	;
 13043                              <1> 	; (Modified Registers -> EAX, ECX)
 13044                              <1> 	;
 13045                              <1> 	; PURPOSE: Loading a file at memory for copying or running etc.
 13046                              <1> 	; If this procedure returns with cf is set, ECX contains maximum
 13047                              <1> 	; available space and EAX contains the beginning address of it.
 13048                              <1> 	; If EAX has zero, ECX contains total number of free bytes.
 13049                              <1> 	; If requested block has been successfully allocated (by rounding up to
 13050                              <1> 	; the last page border), it must be deallocated later by using
 13051                              <1> 	; 'dealloacate_memory_block' procedure.    
 13052                              <1> 
 13053 000038F3 52                  <1> 	push	edx ; *
 13054 000038F4 BAFF0F0000          <1> 	mov	edx, PAGE_SIZE - 1   ; 4095
 13055 000038F9 01D1                <1> 	add	ecx, edx
 13056 000038FB 01D0                <1> 	add	eax, edx
 13057 000038FD C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
 13058                              <1> 
 13059                              <1> 	; ECX = number of contiguous pages to be allocated
 13060 00003900 8B15[80C40000]      <1> 	mov	edx, [free_pages]
 13061 00003906 39D1                <1> 	cmp	ecx, edx
 13062 00003908 7775                <1> 	ja	short amb_6
 13063                              <1> 
 13064 0000390A C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; 12
 13065                              <1> 
 13066 0000390D 89C2                <1> 	mov	edx, eax 	     ; page number
 13067 0000390F C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 13068                              <1> 				     ; (1 allocation bit = 1 page)
 13069                              <1> 				     ; (1 allocation bytes = 8 pages)
 13070 00003912 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 13071                              <1> 				     ; (to get 32 bit position)	
 13072 00003915 53                  <1> 	push	ebx ; **
 13073                              <1> amb_0:
 13074 00003916 890D[36D10000]      <1> 	mov	[mem_ipg_count], ecx ; initial (reset) value of page count
 13075 0000391C 890D[3AD10000]      <1> 	mov	[mem_pg_count], ecx
 13076 00003922 31C9                <1> 	xor	ecx, ecx ; 0
 13077 00003924 890D[3ED10000]      <1> 	mov	[mem_aperture], ecx ; 0
 13078 0000392A 890D[42D10000]      <1> 	mov	[mem_max_aperture], ecx ; 0
 13079                              <1> 	
 13080 00003930 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address.
 13081 00003935 3B15[84C40000]      <1> 	cmp	edx, [next_page]     ; Is the beginning page address lower
 13082                              <1> 				     ; than the address in 'next_page' ?
 13083                              <1> 				     ; (the first/next free page of user space)		
 13084 0000393B 7208                <1> 	jb	short amb_1
 13085 0000393D 3B15[88C40000]      <1> 	cmp 	edx, [last_page]     ; is the beginning page address higher
 13086                              <1> 				     ; than the address in 'last_page' ?
 13087                              <1> 				     ; (end of the memory)		
 13088 00003943 7606                <1> 	jna	short amb_2	     ; no	
 13089                              <1> amb_1:
 13090 00003945 8B15[84C40000]      <1> 	mov	edx, [next_page]     ; yes (reset to the first page of user space)
 13091                              <1> amb_2:
 13092 0000394B 01D3                <1> 	add	ebx, edx
 13093                              <1> 
 13094 0000394D A3[46D10000]        <1> 	mov	[mem_pg_pos], eax    ; beginning page no (for curr. mem. aperture)
 13095 00003952 A3[4AD10000]        <1>  	mov	[mem_max_pg_pos], eax ; beginning page no for max. mem. aperture
 13096                              <1> 
 13097 00003957 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only (0 to 31)
 13098                              <1> 				     ; (allocation bit position)	 
 13099 0000395A 744B                <1> 	jz	short amb_10	     ; 0	
 13100                              <1> amb_3:
 13101 0000395C 8B13                <1> 	mov	edx, [ebx]
 13102 0000395E 88C1                <1> 	mov	cl, al ; 1 to 31
 13103 00003960 D3EA                <1> 	shr	edx, cl
 13104 00003962 89D0                <1> 	mov	eax, edx
 13105                              <1> amb_4:
 13106 00003964 D1E8                <1> 	shr	eax, 1 ; (***)
 13107 00003966 7321                <1> 	jnc	short amb_7
 13108 00003968 FF05[3ED10000]      <1> 	inc	dword [mem_aperture]
 13109 0000396E FF0D[3AD10000]      <1> 	dec	dword [mem_pg_count]
 13110 00003974 747B                <1> 	jz	short amb_15
 13111                              <1> amb_5:
 13112 00003976 80F91F              <1> 	cmp	cl, 31
 13113 00003979 7317                <1> 	jnb	short amb_8
 13114 0000397B FEC1                <1> 	inc	cl
 13115 0000397D EBE5                <1> 	jmp	short amb_4
 13116                              <1> 
 13117                              <1> amb_6:	; out_of_memory
 13118 0000397F 31C0                <1> 	xor	eax, eax ; 0
 13119 00003981 89D1                <1> 	mov	ecx, edx ; free pages
 13120 00003983 C1E10C              <1> 	shl	ecx, PAGE_SHIFT
 13121 00003986 5A                  <1> 	pop	edx ; *
 13122 00003987 F9                  <1> 	stc
 13123 00003988 C3                  <1> 	retn
 13124                              <1> amb_7:
 13125 00003989 50                  <1> 	push	eax ; (***) allocation bits (in shifted status)
 13126 0000398A E819010000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
 13127 0000398F 58                  <1> 	pop	eax ; (***)
 13128 00003990 EBE4                <1> 	jmp	short amb_5
 13129                              <1> amb_8:
 13130 00003992 28C9                <1> 	sub	cl, cl ; 0
 13131                              <1> amb_9:
 13132 00003994 89DA                <1> 	mov	edx, ebx
 13133 00003996 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
 13134 0000399C 3B15[88C40000]      <1> 	cmp	edx, [last_page]
 13135 000039A2 7336                <1> 	jnb	short amb_14 ; contiguous pages not enough
 13136 000039A4 83C304              <1> 	add	ebx, 4
 13137                              <1> amb_10:
 13138 000039A7 8B03                <1> 	mov	eax, [ebx]
 13139 000039A9 21C0                <1> 	and 	eax, eax
 13140 000039AB 7406                <1>         jz      short amb_11 ; there is not a free page bit in this alloc dword
 13141 000039AD 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
 13142 000039AE 740A                <1> 	jz	short amb_12 ; all of bits are set (32 free pages)
 13143 000039B0 48                  <1> 	dec	eax
 13144 000039B1 EBB1                <1> 	jmp	short amb_4
 13145                              <1> amb_11:
 13146 000039B3 E8F0000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
 13147 000039B8 EBDA                <1> 	jmp	short amb_9	
 13148                              <1> amb_12:
 13149 000039BA B120                <1> 	mov	cl, 32
 13150 000039BC 390D[3AD10000]      <1> 	cmp	[mem_pg_count], ecx ; 32
 13151 000039C2 7306                <1> 	jnb	short amb_13
 13152 000039C4 8B0D[3AD10000]      <1> 	mov	ecx, [mem_pg_count]
 13153                              <1> amb_13:
 13154 000039CA 010D[3ED10000]      <1> 	add	[mem_aperture], ecx
 13155 000039D0 290D[3AD10000]      <1> 	sub	[mem_pg_count], ecx
 13156 000039D6 7619                <1> 	jna	short amb_15
 13157 000039D8 EBB8                <1> 	jmp	short amb_8
 13158                              <1> amb_14:
 13159 000039DA A1[4AD10000]        <1> 	mov	eax, [mem_max_pg_pos] ; begin address of max. mem aperture	
 13160 000039DF 8B0D[42D10000]      <1> 	mov	ecx, [mem_max_aperture] ; max. (largest) memory aperture
 13161 000039E5 C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
 13162 000039E8 C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
 13163 000039EB F9                  <1> 	stc
 13164 000039EC E9AC000000          <1>         jmp     amb_25
 13165                              <1> 
 13166                              <1> amb_15: ; OK !
 13167 000039F1 A1[46D10000]        <1> 	mov	eax, [mem_pg_pos]    ; Beginning address as page number
 13168 000039F6 8B0D[3ED10000]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count
 13169                              <1> amb_16:
 13170                              <1> 	; allocate contiguous memory pages (via memory allocation table bits)
 13171 000039FC 89C2                <1> 	mov	edx, eax
 13172 000039FE C1EA05              <1> 	shr	edx, 5 ; 32 pages in one allocation dword (32 bits)
 13173 00003A01 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
 13174 00003A06 01D3                <1> 	add	ebx, edx
 13175 00003A08 83E01F              <1> 	and	eax, 1Fh ; 31
 13176                              <1> 	; 03/04/2016
 13177 00003A0B BA20000000          <1> 	mov	edx, 32
 13178 00003A10 28C2                <1> 	sub	dl, al
 13179 00003A12 39CA                <1> 	cmp	edx, ecx
 13180 00003A14 7602                <1> 	jna	short amb_17
 13181 00003A16 89CA                <1> 	mov	edx, ecx
 13182                              <1> amb_17:
 13183 00003A18 29D1                <1> 	sub	ecx, edx
 13184 00003A1A 51                  <1> 	push	ecx ; ***
 13185 00003A1B 89D1                <1> 	mov	ecx, edx
 13186                              <1> amb_18:		
 13187 00003A1D 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 13188                              <1> 				 ; is copied into the Carry Flag and then cleared
 13189                              <1> 				 ; in the destination.
 13190 00003A20 FF0D[80C40000]      <1> 	dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
 13191 00003A26 49                  <1> 	dec	ecx
 13192 00003A27 7404                <1> 	jz	short amb_19
 13193 00003A29 FEC0                <1> 	inc	al
 13194 00003A2B EBF0                <1> 	jmp	short amb_18
 13195                              <1> amb_19:	
 13196 00003A2D 59                  <1> 	pop	ecx ; ***
 13197 00003A2E 21C9                <1> 	and	ecx, ecx ; 0 ?
 13198 00003A30 741E                <1> 	jz	short amb_22	
 13199                              <1> 	; 01/04/2016
 13200 00003A32 B020                <1> 	mov	al, 32
 13201                              <1> amb_20:
 13202 00003A34 83C304              <1> 	add	ebx, 4
 13203 00003A37 39C1                <1> 	cmp	ecx, eax ; 32
 13204 00003A39 7305                <1> 	jnb	short amb_21
 13205                              <1> 	; ECX < 32
 13206 00003A3B 28C0                <1> 	sub	al, al ; 0
 13207 00003A3D 50                  <1> 	push	eax ; 0 ***
 13208 00003A3E EBDD                <1> 	jmp	short amb_18
 13209                              <1> amb_21:
 13210 00003A40 2905[80C40000]      <1> 	sub	[free_pages], eax ; [free_pages] = [free_pages] - 32
 13211 00003A46 C70300000000        <1> 	mov	dword [ebx], 0 ; reset 32 bits
 13212 00003A4C 29C1                <1> 	sub	ecx, eax ; 32
 13213 00003A4E 75E4                <1> 	jnz	short amb_20
 13214                              <1> amb_22:
 13215 00003A50 A1[46D10000]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
 13216 00003A55 8B0D[3ED10000]      <1> 	mov	ecx, [mem_aperture] ; Free contiguous page count
 13217                              <1> 	; [next_page] update
 13218 00003A5B 89C2                <1> 	mov	edx, eax
 13219                              <1> 	; 03/04/2016
 13220 00003A5D C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 13221                              <1> 				     ; (1 allocation bit = 1 page)
 13222                              <1> 				     ; (1 allocation bytes = 8 pages)
 13223 00003A60 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 13224                              <1> 				     ; (to get 32 bit position)	
 13225 00003A63 3B15[84C40000]      <1> 	cmp	edx, [next_page] ; first free page pointer offset
 13226 00003A69 7732                <1> 	ja	short amb_25
 13227 00003A6B BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
 13228 00003A70 833C1300            <1> 	cmp	dword [ebx+edx], 0
 13229 00003A74 7721                <1> 	ja	short amb_24
 13230 00003A76 89C2                <1> 	mov	edx, eax
 13231 00003A78 01CA                <1> 	add	edx, ecx
 13232 00003A7A C1EA03              <1> 	shr	edx, 3
 13233 00003A7D 80E2FC              <1> 	and	dl, 0FCh
 13234                              <1> amb_23:
 13235 00003A80 833C1300            <1> 	cmp	dword [ebx+edx], 0
 13236 00003A84 7711                <1> 	ja	short amb_24
 13237 00003A86 83C204              <1> 	add	edx, 4
 13238 00003A89 3B15[88C40000]      <1> 	cmp	edx, [last_page]    ; last page pointer offset
 13239 00003A8F 76EF                <1> 	jna	short amb_23
 13240 00003A91 8B15[8CC40000]      <1> 	mov	edx, [first_page]   ; (for) beginning of user's space
 13241                              <1> amb_24:
 13242 00003A97 8915[84C40000]      <1> 	mov	[next_page], edx
 13243                              <1> amb_25:
 13244 00003A9D 9C                  <1> 	pushf
 13245 00003A9E C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
 13246 00003AA1 C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
 13247 00003AA4 9D                  <1> 	popf
 13248 00003AA5 5B                  <1> 	pop	ebx ; **
 13249 00003AA6 5A                  <1> 	pop	edx ; *
 13250 00003AA7 C3                  <1> 	retn
 13251                              <1> 
 13252                              <1> amb_26:	; set maximum free memory aperture (free memory block size) 
 13253 00003AA8 89DA                <1> 	mov	edx, ebx ; current address
 13254 00003AAA 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL ; MAT beginning address
 13255                              <1> 	; 02/04/2016 
 13256 00003AB0 C1E203              <1> 	shl	edx, 3 ; MAT byte offset * 8 = page number base
 13257 00003AB3 01CA                <1> 	add	edx, ecx ; current page number (ecx =  0 to 31)
 13258                              <1> 	;
 13259 00003AB5 A1[3ED10000]        <1> 	mov	eax, [mem_aperture]
 13260 00003ABA 21C0                <1> 	and	eax, eax
 13261 00003ABC 7424                <1>         jz      short amb_27
 13262 00003ABE C705[3ED10000]0000- <1>         mov     dword [mem_aperture], 0
 13263 00003AC6 0000                <1>
 13264 00003AC8 3B05[42D10000]      <1> 	cmp	eax, [mem_max_aperture]
 13265 00003ACE 7612                <1> 	jna	short amb_27
 13266 00003AD0 A3[42D10000]        <1> 	mov	[mem_max_aperture], eax
 13267                              <1> 	;
 13268 00003AD5 89D0                <1> 	mov	eax, edx
 13269 00003AD7 2B05[42D10000]      <1> 	sub	eax, [mem_max_aperture] ; the last aperture size in pages
 13270                              <1> 	; EAX = Beginning page number of the max. aperture 
 13271 00003ADD A3[4AD10000]        <1> 	mov	[mem_max_pg_pos], eax
 13272                              <1> amb_27: 
 13273 00003AE2 42                  <1> 	inc	edx	
 13274 00003AE3 8915[46D10000]      <1> 	mov	[mem_pg_pos], edx ; next page
 13275                              <1> 
 13276 00003AE9 A1[36D10000]        <1> 	mov	eax, [mem_ipg_count] ; initial (reset) value of page count
 13277 00003AEE A3[3AD10000]        <1> 	mov	[mem_pg_count], eax
 13278                              <1> 
 13279 00003AF3 C3                  <1> 	retn
 13280                              <1> 
 13281                              <1> deallocate_memory_block:
 13282                              <1> 	; 03/04/2016
 13283                              <1> 	; 14/03/2016 (TRDOS 386 = TRDOS v2.0)
 13284                              <1> 	; Deallocating contiguous memory pages (in the kernel's memory space)
 13285                              <1> 	;
 13286                              <1> 	; INPUT -> 
 13287                              <1> 	;	EAX = Beginning address (physical)
 13288                              <1> 	;	ECX = Number of bytes to be deallocated
 13289                              <1> 	;
 13290                              <1> 	; OUTPUT ->
 13291                              <1> 	;	Mememory Allocation Table bits will be updated
 13292                              <1> 	;	[free_pages] will be changed (increased)
 13293                              <1> 	;
 13294                              <1> 	; (Modified Registers -> EAX, ECX)
 13295                              <1> 	;
 13296                              <1> 	; PURPOSE: Unloading/Freeing a file -or an allocated memory block- 
 13297                              <1> 	; at memory after copying, running, saving, reading, writing etc.
 13298                              <1> 	;
 13299                              <1> 
 13300 00003AF4 52                  <1> 	push	edx ; *
 13301 00003AF5 53                  <1> 	push	ebx ; **
 13302                              <1> 
 13303 00003AF6 C1E80C              <1> 	shr	eax, PAGE_SHIFT	     ; 12
 13304 00003AF9 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
 13305                              <1> 
 13306                              <1> 	; EAX = Beginning page number
 13307                              <1> 	; ECX = Number of contiguous pages to be deallocated
 13308                              <1> damb_0:
 13309                              <1> 	; deallocate contiguous memory pages (via memory allocation table bits)
 13310 00003AFC 89C2                <1> 	mov	edx, eax
 13311 00003AFE C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 13312                              <1> 				     ; (1 allocation bit = 1 page)
 13313                              <1> 				     ; (1 allocation bytes = 8 pages)
 13314 00003B01 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 13315                              <1> 				     ; (to get 32 bit position)	
 13316 00003B04 3B15[84C40000]      <1> 	cmp	edx, [next_page] ; next free page
 13317 00003B0A 7306                <1> 	jnb	short damb_1
 13318 00003B0C 8915[84C40000]      <1> 	mov	[next_page], edx
 13319                              <1> damb_1:
 13320 00003B12 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
 13321 00003B17 01D3                <1> 	add	ebx, edx
 13322 00003B19 83E01F              <1> 	and	eax, 1Fh ; 31
 13323                              <1> 
 13324                              <1> 	; 03/04/2016
 13325 00003B1C BA20000000          <1> 	mov	edx, 32
 13326 00003B21 28C2                <1> 	sub	dl, al
 13327 00003B23 39CA                <1> 	cmp	edx, ecx
 13328 00003B25 7602                <1> 	jna	short damb_2
 13329 00003B27 89CA                <1> 	mov	edx, ecx
 13330                              <1> damb_2:
 13331 00003B29 29D1                <1> 	sub	ecx, edx
 13332 00003B2B 51                  <1> 	push	ecx ; ***
 13333 00003B2C 89D1                <1> 	mov	ecx, edx
 13334                              <1> damb_3:		
 13335 00003B2E 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
 13336                              <1> 				     ; set relevant bit to 1.
 13337                              <1> 				     ; set CF to the previous bit value	
 13338 00003B31 FF05[80C40000]      <1> 	inc     dword [free_pages]   ; 1 page has been deallocated (X = X+1) 
 13339 00003B37 49                  <1> 	dec	ecx
 13340 00003B38 7404                <1> 	jz	short damb_4
 13341 00003B3A FEC0                <1> 	inc	al
 13342 00003B3C EBF0                <1> 	jmp	short damb_3
 13343                              <1> damb_4:	
 13344 00003B3E 59                  <1> 	pop	ecx ; ***
 13345 00003B3F 21C9                <1> 	and	ecx, ecx ; 0 ?
 13346 00003B41 741E                <1> 	jz	short damb_7
 13347                              <1> 	; 03/04/2016
 13348 00003B43 B020                <1> 	mov	al, 32
 13349                              <1> damb_5:
 13350 00003B45 83C304              <1> 	add	ebx, 4
 13351 00003B48 39C1                <1> 	cmp	ecx, eax ; 32
 13352 00003B4A 7305                <1> 	jnb	short damb_6
 13353                              <1> 	; ECX < 32
 13354 00003B4C 28C0                <1> 	sub	al, al ; 0
 13355 00003B4E 50                  <1> 	push	eax ; 0 ***
 13356 00003B4F EBDD                <1> 	jmp	short damb_3
 13357                              <1> damb_6:
 13358 00003B51 0105[80C40000]      <1> 	add	[free_pages], eax ; [free_pages] = [free_pages] + 32
 13359 00003B57 C703FFFFFFFF        <1> 	mov	dword [ebx], 0FFFFFFFFh ; set 32 bits
 13360 00003B5D 29C1                <1> 	sub	ecx, eax ; 32
 13361 00003B5F 75E4                <1> 	jnz	short damb_5
 13362                              <1> damb_7:
 13363 00003B61 5B                  <1> 	pop	ebx ; **
 13364 00003B62 5A                  <1> 	pop	edx ; *
 13365 00003B63 C3                  <1> 	retn
 13366                              <1> 
 13367                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
 13368                              <1> 
 13369                              <1> ;; Data:
 13370                              <1> 
 13371                              <1> ; 09/03/2015
 13372                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
 13373                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
 13374                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 13375                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 13376                              <1> ;swpd_next:  dd 0 ; next free page block
 13377                              <1> ;swpd_last:  dd 0 ; last swap page block		 		
 13378                                  %include 'timer.s'   ; 17/01/2015
 13379                              <1> ; ****************************************************************************
 13380                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - timer.s
 13381                              <1> ; ----------------------------------------------------------------------------
 13382                              <1> ; Last Update: 29/01/2016
 13383                              <1> ; ----------------------------------------------------------------------------
 13384                              <1> ; Beginning: 17/01/2016
 13385                              <1> ; ----------------------------------------------------------------------------
 13386                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13387                              <1> ; ----------------------------------------------------------------------------
 13388                              <1> ; Turkish Rational DOS
 13389                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 13390                              <1> ;
 13391                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13392                              <1> ;
 13393                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 13394                              <1> ; ****************************************************************************
 13395                              <1> 
 13396                              <1> ; TRDOS 386  (TRDOS v2.0) Kernel - TIMER & REAL TIME CLOCK (BIOS) FUNCTIONS
 13397                              <1> 
 13398                              <1> ; IBM PC-AT BIOS Source Code ('BIOS2.ASM')
 13399                              <1> ; TITLE BIOS2 ---- 06/10/85 BIOS INTERRUPT ROUTINES
 13400                              <1> 
 13401                              <1> ;
 13402                              <1> ; ///////// TIMER (& REAL TIME CLOCK) FUNCTIONS ///////////////
 13403                              <1> 
 13404                              <1> int1Ah:
 13405                              <1> 	; 29/01/2016
 13406                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13407 00003B64 9C                  <1> 	pushfd
 13408 00003B65 0E                  <1> 	push 	cs
 13409 00003B66 E801000000          <1> 	call 	TIME_OF_DAY_1
 13410 00003B6B C3                  <1> 	retn
 13411                              <1> 
 13412                              <1> ;--- INT  1A H -- (TIME OF DAY) -------------------------------------------------
 13413                              <1> ;       THIS BIOS ROUTINE ALLOWS THE CLOCKS TO BE SET OR READ			:
 13414                              <1> ;										:
 13415                              <1> ; PARAMETERS:									:
 13416                              <1> ;     (AH) = 00H  READ THE CURRENT SETTING AND RETURN WITH,			:
 13417                              <1> ;                      (CX) = HIGH PORTION OF COUNT				:
 13418                              <1> ;                      (DX) = LOW PORTION OF COUNT				:
 13419                              <1> ;                      (AL) = 0 TIMER HAS NOT PASSED 24 HOURS SINCE LAST READ	:
 13420                              <1> ;                             1 IF ON ANOTHER DAY. (RESET TO ZERO AFTER READ)	:
 13421                              <1> ;										:
 13422                              <1> ;     (AH) = 01H  SET THE CURRENT CLOCK USING,					:
 13423                              <1> ;		     (CX) = HIGH PORTION OF COUNT				:
 13424                              <1> ;		     (DX) = LOW PORTION OF COUNT.				:
 13425                              <1> ;										:
 13426                              <1> ;               NOTE: COUNTS OCCUR AT THE RATE OF 1193180/65536 COUNTS/SECOND	:
 13427                              <1> ;                            (OR ABOUT 18.2 PER SECOND -- SEE EQUATES)		:
 13428                              <1> ;										:
 13429                              <1> ;     (AH) = 02H  READ THE REAL TIME CLOCK AND RETURN WITH,			:
 13430                              <1> ;                      (CH) = HOURS IN BCD (00-23)				:
 13431                              <1> ;                      (CL) = MINUTES IN BCD (00-59)				:
 13432                              <1> ;                      (DH) = SECONDS IN BCD (00-59)				:
 13433                              <1> ;                      (DL) = DAYLIGHT SAVINGS ENABLE (00-01)			:
 13434                              <1> ;										:
 13435                              <1> ;     (AH) = 03H  SET THE REAL TIME CLOCK USING,				:
 13436                              <1> ;                     (CH) = HOURS IN BCD (00-23)				:
 13437                              <1> ;                     (CL) = MINUTES IN BCD (00-59)				:
 13438                              <1> ;                     (DH) = SECONDS IN BCD (00-59)				:
 13439                              <1> ;                     (DL) = 01 IF DAYLIGHT SAVINGS ENABLE OPTION, ELSE 00.	:
 13440                              <1> ;										:
 13441                              <1> ;             NOTE: (DL) = 00 IF DAYLIGHT SAVINGS TIME ENABLE IS NOT ENABLED.	:
 13442                              <1> ;                   (DL) = 01 ENABLES TWO SPECIAL UPDATES THE LAST SUNDAY IN	:
 13443                              <1> ;	           APRIL   (1:59:59 --> 3:00:00 AM) AND THE LAST SUNDAY IN	:
 13444                              <1> ;                   OCTOBER (1:59:59 --> 1:00:00 AM) THE FIRST TIME.		:
 13445                              <1> ;										:
 13446                              <1> ;     (AH) = 04H  READ THE DATE FROM THE REAL TIME CLOCK AND RETURN WITH,	:
 13447                              <1> ;                      (CH) = CENTURY IN BCD (19 OR 20)				:
 13448                              <1> ;                      (CL) = YEAR IN BCD (00-99)				:
 13449                              <1> ;                      (DH) = MONTH IN BCD (01-12)				:
 13450                              <1> ;                      (DL) = DAY IN BCD (01-31).				:
 13451                              <1> ;										:
 13452                              <1> ;     (AH) = 05H  SET THE DATE INTO THE REAL TIME CLOCK USING,			:
 13453                              <1> ;                     (CH) = CENTURY IN BCD (19 OR 20)				:
 13454                              <1> ;                     (CL) = YEAR IN BCD (00-99)				:
 13455                              <1> ;                     (DH) = MONTH IN BCD (01-12)				:
 13456                              <1> ;                     (DL) = DAY IN BCD (01-31).				:
 13457                              <1> ;										:
 13458                              <1> ;     (AH) = 06H  SET THE ALARM TO INTERRUPT AT SPECIFIED TIME,			:
 13459                              <1> ;                     (CH) = HOURS IN BCD (00-23 (OR FFH))			:
 13460                              <1> ;                     (CL) = MINUTES IN BCD (00-59 (OR FFH))			:
 13461                              <1> ;                     (DH) = SECONDS IN BCD (00-59 (OR FFH))			:
 13462                              <1> ;										:
 13463                              <1> ;     (AH) = 07H  RESET THE ALARM INTERRUPT FUNCTION.				:
 13464                              <1> ;										:
 13465                              <1> ; NOTES: FOR ALL RETURNS CY= 0 FOR SUCCESSFUL OPERATION.			:
 13466                              <1> ;        FOR (AH)= 2, 4, 6 - CARRY FLAG SET IF REAL TIME CLOCK NOT OPERATING.	:
 13467                              <1> ;        FOR (AH)= 6 - CARRY FLAG SET IF ALARM ALREADY ENABLED. 		:
 13468                              <1> ;        FOR THE ALARM FUNCTION (AH = 6) THE USER MUST SUPPLY A ROUTINE AND	:
 13469                              <1> ;         INTERCEPT THE CORRECT ADDRESS IN THE VECTOR TABLE FOR INTERRUPT 4AH.	:
 13470                              <1> ;         USE 0FFH FOR ANY "DO NOT CARE" POSITION FOR INTERVAL INTERRUPTS.	:
 13471                              <1> ;        INTERRUPTS ARE DISABLED DURING DATA MODIFICATION. 			:
 13472                              <1> ;        AH & AL ARE RETURNED MODIFIED AND NOT DEFINED EXCEPT WHERE INDICATED.	:
 13473                              <1> ;--------------------------------------------------------------------------------
 13474                              <1> 
 13475                              <1> ; 29/01/2016
 13476                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13477                              <1> 
 13478                              <1> TIME_OF_DAY_1:
 13479 00003B6C FB                  <1> 	sti				; INTERRUPTS BACK ON
 13480 00003B6D 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
 13481 00003B70 F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
 13482 00003B71 721A                <1> 	jc	short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
 13483                              <1> 
 13484 00003B73 1E                  <1> 	push	ds
 13485 00003B74 56                  <1> 	push	esi
 13486 00003B75 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
 13487 00003B79 8EDE                <1> 	mov	ds, si
 13488 00003B7B C0E402              <1> 	shl	ah, 2			; convert function to dword offset
 13489 00003B7E 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
 13490 00003B81 FA                  <1> 	cli				; NO INTERRUPTS DURING TIME FUNCTIONS
 13491 00003B82 FF96[903B0000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
 13492                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
 13493 00003B88 FB                  <1> 	sti				; INTERRUPTS BACK ON
 13494 00003B89 B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
 13495 00003B8B 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
 13496 00003B8C 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
 13497                              <1> TIME_9:					; RETURN WITH CY= 0 IF NO ERROR
 13498 00003B8D CA0400              <1> 	retf	4
 13499                              <1> 					; ROUTINE VECTOR TABLE (AH)=
 13500                              <1> RTC_TB:
 13501 00003B90 [B03B0000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
 13502 00003B94 [C33B0000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
 13503 00003B98 [D13B0000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
 13504 00003B9C [003C0000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
 13505 00003BA0 [423C0000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
 13506 00003BA4 [6F3C0000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
 13507 00003BA8 [BC3C0000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
 13508 00003BAC [0F3D0000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
 13509                              <1> 
 13510                              <1> RTC_TBE	equ	$
 13511                              <1> 
 13512                              <1> RTC_00:				; READ TIME COUNT
 13513 00003BB0 A0[00C50000]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
 13514 00003BB5 C605[00C50000]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
 13515 00003BBC 8B0D[FCC40000]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
 13516 00003BC2 C3                  <1> 	retn
 13517                              <1> 
 13518                              <1> RTC_10:				; SET TIME COUNT
 13519 00003BC3 890D[FCC40000]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
 13520 00003BC9 C605[00C50000]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
 13521 00003BD0 C3                  <1> 	retn				; RETURN WITH NO CARRY
 13522                              <1> 
 13523                              <1> RTC_20:				; GET RTC TIME
 13524 00003BD1 E8EB010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13525 00003BD6 7227                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
 13526                              <1> 
 13527 00003BD8 B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
 13528 00003BDA E8FD010000          <1> 	call	CMOS_READ		; GET SECONDS
 13529 00003BDF 88C6                <1> 	mov	dh, al			; SAVE
 13530 00003BE1 B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13531 00003BE3 E8F4010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
 13532 00003BE8 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
 13533 00003BEA 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
 13534 00003BEC B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
 13535 00003BEE E8E9010000          <1> 	call	CMOS_READ		; GET MINUTES
 13536 00003BF3 88C1                <1> 	mov	cl, al			; SAVE
 13537 00003BF5 B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
 13538 00003BF7 E8E0010000          <1> 	call	CMOS_READ		; GET HOURS
 13539 00003BFC 88C5                <1> 	mov	ch, al			; SAVE
 13540 00003BFE F8                  <1> 	clc				; SET CY= 0
 13541                              <1> RTC_29:
 13542 00003BFF C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
 13543                              <1> 
 13544                              <1> RTC_30:				; SET RTC TIME
 13545 00003C00 E8BC010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13546 00003C05 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
 13547 00003C07 E817010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
 13548                              <1> RTC_35:
 13549 00003C0C 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
 13550 00003C0E B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
 13551 00003C10 E8DF010000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
 13552 00003C15 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
 13553 00003C17 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
 13554 00003C19 E8D6010000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
 13555 00003C1E 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
 13556 00003C20 B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
 13557 00003C22 E8CD010000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
 13558                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13559                              <1> 	;mov	ah, al
 13560 00003C27 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13561 00003C2B E8AC010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
 13562 00003C30 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
 13563 00003C32 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
 13564 00003C34 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
 13565 00003C37 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
 13566 00003C39 86E0                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
 13567 00003C3B E8B4010000          <1> 	call	CMOS_WRITE		; SET NEW ALARM SITS
 13568 00003C40 F8                  <1> 	clc				; SET CY= 0
 13569 00003C41 C3                  <1> 	retn				; RETURN WITH CY= 0
 13570                              <1> 
 13571                              <1> RTC_40:				; GET RTC DATE
 13572 00003C42 E87A010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13573 00003C47 7225                <1> 	jc	short RTC_49		; EXIT IF ERROR (CY= 1)
 13574                              <1> 
 13575 00003C49 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
 13576 00003C4B E88C010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
 13577 00003C50 88C2                <1> 	mov	dl, al			; SAVE
 13578 00003C52 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
 13579 00003C54 E883010000          <1> 	call	CMOS_READ		; READ MONTH
 13580 00003C59 88C6                <1> 	mov	dh, al			; SAVE
 13581 00003C5B B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
 13582 00003C5D E87A010000          <1> 	call	CMOS_READ		; READ YEAR
 13583 00003C62 88C1                <1> 	mov	cl, al			; SAVE
 13584 00003C64 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
 13585 00003C66 E871010000          <1> 	call	CMOS_READ		; GET CENTURY BYTE
 13586 00003C6B 88C5                <1> 	mov	ch, al			; SAVE
 13587 00003C6D F8                  <1> 	clc				; SET CY=0
 13588                              <1> RTC_49:
 13589 00003C6E C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAG
 13590                              <1> 
 13591                              <1> RTC_50:				; SET RTC DATE
 13592 00003C6F E84D010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13593 00003C74 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
 13594 00003C76 E8A8000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13595                              <1> RTC_55:
 13596 00003C7B 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
 13597 00003C7F E870010000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
 13598 00003C84 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
 13599 00003C86 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
 13600 00003C88 E867010000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
 13601 00003C8D 88F4                <1> 	mov	ah, dh			; GET MONTH
 13602 00003C8F B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
 13603 00003C91 E85E010000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
 13604 00003C96 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
 13605 00003C98 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
 13606 00003C9A E855010000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
 13607 00003C9F 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
 13608 00003CA1 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
 13609 00003CA3 E84C010000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
 13610                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13611                              <1> 	;mov	ah, al
 13612 00003CA8 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13613 00003CAC E82B010000          <1> 	call	CMOS_READ		; READ WIRRENT SETTINGS
 13614 00003CB1 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
 13615 00003CB3 86E0                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
 13616 00003CB5 E83A010000          <1> 	call	CMOS_WRITE		; AND START CLOCK UPDATING
 13617 00003CBA F8                  <1> 	clc				; SET CY= 0
 13618 00003CBB C3                  <1> 	retn				; RETURN CY=0
 13619                              <1> 
 13620                              <1> RTC_60:				; SET RTC ALARM
 13621 00003CBC B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
 13622 00003CBE E819010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13623 00003CC3 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
 13624 00003CC5 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
 13625 00003CC6 7542                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
 13626 00003CC8 E8F4000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13627 00003CCD 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
 13628 00003CCF E84F000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13629                              <1> RTC_65:	
 13630 00003CD4 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
 13631 00003CD6 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
 13632 00003CD8 E817010000          <1> 	call	CMOS_WRITE		; INSERT SECONDS
 13633 00003CDD 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
 13634 00003CDF B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
 13635 00003CE1 E80E010000          <1> 	call	CMOS_WRITE		; INSERT MINUTES
 13636 00003CE6 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
 13637 00003CE8 B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
 13638 00003CEA E805010000          <1> 	call	CMOS_WRITE		; INSERT HOURS
 13639 00003CEF E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
 13640 00003CF1 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
 13641 00003CF3 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
 13642                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13643                              <1> 	;mov	ah, al
 13644 00003CF5 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13645 00003CF9 E8DE000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
 13646 00003CFE 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
 13647 00003D00 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
 13648 00003D02 86E0                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
 13649 00003D04 E8EB000000          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
 13650 00003D09 F8                  <1> 	clc				; SET CY= 0
 13651                              <1> RTC_69:
 13652 00003D0A 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
 13653 00003D0E C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
 13654                              <1> 
 13655                              <1> RTC_70:				; RESET ALARM
 13656                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13657                              <1> 	;mov	ah, al
 13658 00003D0F 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
 13659 00003D13 E8C4000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13660 00003D18 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
 13661 00003D1A 86E0                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
 13662 00003D1C E8D3000000          <1> 	call	CMOS_WRITE		; RESTORE NEW VALUE
 13663 00003D21 F8                  <1> 	clc				; SET CY= 0
 13664 00003D22 C3                  <1> 	retn				; RETURN WITH NO CARRY
 13665                              <1> 
 13666                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
 13667                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
 13668                              <1> 	;mov	ah, 26h
 13669 00003D23 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
 13670 00003D27 E8C8000000          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
 13671                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
 13672                              <1> 	;mov	ah, 82h
 13673 00003D2C 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
 13674 00003D30 E8BF000000          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
 13675 00003D35 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
 13676 00003D37 E8A0000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
 13677 00003D3C B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
 13678 00003D3E E899000000          <1> 	call	CMOS_READ		; READ REGISTER D TO INITIALIZE
 13679 00003D43 C3                  <1> 	retn
 13680                              <1> 
 13681                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13682                              <1> 
 13683                              <1> ;--- HARDWARE INT  70 H -- ( IRQ LEVEL  8) --------------------------------------
 13684                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
 13685                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
 13686                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
 13687                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
 13688                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
 13689                              <1> ;										:
 13690                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
 13691                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
 13692                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
 13693                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
 13694                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
 13695                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
 13696                              <1> ;--------------------------------------------------------------------------------
 13697                              <1> 
 13698                              <1> RTC_INT:			; ALARM INTERRUPT
 13699 00003D44 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
 13700 00003D45 50                  <1> 	push	eax			; SAVE REGISTERS
 13701 00003D46 57                  <1> 	push	edi
 13702                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
 13703 00003D47 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
 13704 00003D4B E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
 13705 00003D4D 90                  <1> 	nop				; I/O DELAY
 13706 00003D4E EB00                <1> 	jmp	short $+2
 13707 00003D50 E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
 13708 00003D52 A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
 13709 00003D54 745D                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
 13710                              <1> 
 13711 00003D56 86E0                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
 13712 00003D58 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
 13713 00003D5A 90                  <1> 	nop				; I/O DELAY
 13714 00003D5B EB00                <1> 	jmp	short $+2	
 13715 00003D5D E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
 13716 00003D5F 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
 13717 00003D61 A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
 13718 00003D63 743B                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
 13719                              <1> 
 13720                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
 13721                              <1> 
 13722 00003D65 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
 13723 00003D69 8EDF                <1> 	mov	ds, di
 13724                              <1> 	
 13725 00003D6B 812D[F6C40000]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
 13726 00003D73 0000                <1>
 13727 00003D75 7329                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
 13728                              <1> 
 13729                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
 13730                              <1> 
 13731 00003D77 6650                <1> 	push	ax			; SAVE INTERRUPT FLAG MASK
 13732 00003D79 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
 13733 00003D7D E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
 13734 00003D7F 90                  <1> 	nop				; I/O DELAY
 13735 00003D80 EB00                <1> 	jmp	short $+2
 13736 00003D82 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
 13737 00003D84 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
 13738 00003D86 86C4                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
 13739 00003D88 E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
 13740 00003D8A 86C4                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
 13741 00003D8C E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
 13742 00003D8E C605[FAC40000]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
 13743 00003D95 8B3D[FBC40000]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
 13744 00003D9B C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
 13745 00003D9E 6658                <1> 	pop	ax			; GET INTERRUPT SOURCE BACK
 13746                              <1> RTC_I_5:
 13747 00003DA0 A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
 13748 00003DA2 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
 13749                              <1> 
 13750 00003DA4 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13751 00003DA6 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13752 00003DA8 FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
 13753 00003DA9 52                  <1> 	push	edx
 13754 00003DAA E820750000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
 13755 00003DAF 5A                  <1> 	pop	edx
 13756 00003DB0 FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
 13757                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
 13758 00003DB1 EB94                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
 13759                              <1> 
 13760                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
 13761 00003DB3 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13762 00003DB5 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13763 00003DB7 B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
 13764 00003DB9 E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
 13765 00003DBB E620                <1> 	out	INTA00,	al		; TO 8259 - 1
 13766 00003DBD 5F                  <1> 	pop	edi			; RESTORE REGISTERS
 13767 00003DBE 58                  <1> 	pop	eax
 13768 00003DBF 1F                  <1> 	pop	ds
 13769 00003DC0 CF                  <1> 	iret				; END OF INTERRUPT
 13770                              <1> 
 13771                              <1> 
 13772                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13773                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
 13774                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
 13775 00003DC1 51                  <1> 	push	ecx
 13776 00003DC2 B9FFFF0000          <1> 	mov	ecx, 65535		; SET TIMEOUT LOOP COUNT (= 800)
 13777                              <1> 		; mov cx, 800	
 13778                              <1> UPD_10:
 13779 00003DC7 B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
 13780 00003DC9 FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
 13781 00003DCA E80D000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
 13782 00003DCF A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
 13783 00003DD1 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
 13784 00003DD3 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
 13785 00003DD4 E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
 13786 00003DD6 31C0                <1> 	xor	eax, eax		; CLEAR RESULTS IF ERROR
 13787                              <1> 		; xor ax, ax
 13788 00003DD8 F9                  <1> 	stc				; SET CARRY FOR ERROR
 13789                              <1> UPD_90:
 13790 00003DD9 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
 13791 00003DDA FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
 13792 00003DDB C3                  <1> 	retn				; RETURN WITH CY FLAG SET
 13793                              <1> 
 13794                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13795                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
 13796                              <1> 
 13797                              <1> ;--- CMOS_READ -----------------------------------------------------------------
 13798                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
 13799                              <1> ;									       :
 13800                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
 13801                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13802                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
 13803                              <1> ;									       :
 13804                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
 13805                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
 13806                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13807                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13808                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13809                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
 13810                              <1> ;-------------------------------------------------------------------------------
 13811                              <1> 
 13812                              <1> CMOS_READ:
 13813 00003DDC 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13814 00003DDD D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13815 00003DDF F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13816 00003DE0 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13817 00003DE2 FA                  <1> 	cli				; DISABLE INTERRUPTS
 13818 00003DE3 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13819 00003DE5 90                  <1> 	nop				; I/O DELAY
 13820 00003DE6 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
 13821 00003DE8 6650                <1> 	push	ax			; SAVE (AH) REGISTER VALUE AND CMOS BYTE
 13822                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
 13823                              <1> 		     ; ----- 10/06/85 (test4.asm)
 13824 00003DEA B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 ; GET ADDRESS OF DEFAULT LOCATION
 13825                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13826 00003DEC D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13827 00003DEE E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13828 00003DF0 6658                <1> 	pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
 13829 00003DF2 9D                  <1> 	popf	
 13830 00003DF3 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
 13831                              <1> 
 13832                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13833                              <1> 
 13834                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
 13835                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
 13836                              <1> ;									       :
 13837                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
 13838                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13839                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
 13840                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
 13841                              <1> ;									       :
 13842                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
 13843                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
 13844                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13845                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13846                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13847                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
 13848                              <1> ;-------------------------------------------------------------------------------
 13849                              <1> 
 13850                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
 13851 00003DF4 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13852 00003DF5 6650                <1> 	push	ax			; SAVE WORK REGISTER VALUES
 13853 00003DF7 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13854 00003DF9 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13855 00003DFA D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13856 00003DFC FA                  <1> 	cli				; DISABLE INTERRUPTS
 13857 00003DFD E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13858 00003DFF 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
 13859 00003E01 E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
 13860 00003E03 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
 13861                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13862 00003E05 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13863 00003E07 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13864 00003E09 90                  <1> 	nop				; I/O DELAY
 13865 00003E0A E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
 13866 00003E0C 6658                <1> 	pop	ax			; RESTORE WORK REGISTERS
 13867 00003E0E 9D                  <1> 	popf
 13868 00003E0F C3                  <1> 	retn
 13869                              <1> 
 13870                              <1> ; /// End Of TIMER FUNCTIONS ///
 13871                                  %include 'sysdefs.s' ; 24/01/2015
 13872                              <1> ; ****************************************************************************
 13873                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYSTEM DEFINITIONS : sysdefs.s
 13874                              <1> ; ----------------------------------------------------------------------------
 13875                              <1> ; Last Update: 24/01/2016
 13876                              <1> ; ----------------------------------------------------------------------------
 13877                              <1> ; Beginning: 24/01/2016
 13878                              <1> ; ----------------------------------------------------------------------------
 13879                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13880                              <1> ; ----------------------------------------------------------------------------
 13881                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13882                              <1> ; sysdefs.inc (14/11/2015)
 13883                              <1> ; ****************************************************************************
 13884                              <1> 
 13885                              <1> ; Retro UNIX 386 v1 Kernel - SYSDEFS.INC
 13886                              <1> ; Last Modification: 14/11/2015
 13887                              <1> ;
 13888                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 13889                              <1> ; (Modified from 
 13890                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 13891                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 13892                              <1> ; 	UNIX.ASM (MASM 6.11) --> SYSDEFS.INC (NASM 2.11)
 13893                              <1> ; ----------------------------------------------------------------------------
 13894                              <1> ;
 13895                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 13896                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 13897                              <1> ; <Bell Laboratories (17/3/1972)>
 13898                              <1> ; <Preliminary Release of UNIX Implementation Document>
 13899                              <1> ;
 13900                              <1> ; ****************************************************************************
 13901                              <1> 
 13902                              <1> nproc 	equ	16  ; number of processes
 13903                              <1> nfiles 	equ	50
 13904                              <1> ntty	equ     8   ; 8+1 -> 8 (10/05/2013)
 13905                              <1> nbuf	equ	4   ; 6 ;; 21/08/2015 - 'namei' buffer problem when nbuf > 4 	
 13906                              <1> 		; NOTE: If fd0 super block buffer addres is beyond of the 1st
 13907                              <1> 		; 32K, DMA r/w routine or someting else causes a jump to 
 13908                              <1> 		; kernel panic routine (in 'alloc' routine, in u5.s)
 13909                              <1> 		; because of invalid buffer content (r/w error). 
 13910                              <1> 		; When all buffers are set before the end of the 1st 32k,
 13911                              <1> 		; there is no problem!? (14/11/2015) 
 13912                              <1> 
 13913                              <1> ;csgmnt	equ	2000h	; 26/05/2013 (segment of process 1)
 13914                              <1> ;core	equ 	0  	    ; 19/04/2013	
 13915                              <1> ;ecore	equ	32768 - 64  ; 04/06/2013 (24/05/2013)
 13916                              <1> 	; (if total size of argument list and arguments is 128 bytes)
 13917                              <1> 	; maximum executable file size = 32768-(64+40+128-6) = 32530 bytes
 13918                              <1> 	; maximum stack size = 40 bytes (+6 bytes for 'IRET' at 32570)	
 13919                              <1> 	; initial value of user's stack pointer = 32768-64-128-2 = 32574
 13920                              <1> 	; 	(sp=32768-args_space-2 at the beginning of execution)
 13921                              <1> 	; argument list offset = 32768-64-128 = 32576 (if it is 128 bytes)
 13922                              <1> 	; 'u' structure offset (for the '/core' dump file) = 32704
 13923                              <1> 	; '/core' dump file size = 32768 bytes
 13924                              <1>  
 13925                              <1> ; 08/03/2014 
 13926                              <1> ;sdsegmnt equ	6C0h  ; 256*16 bytes (swap data segment size for 16 processes)		 	 
 13927                              <1> ; 19/04/2013 Retro UNIX 8086 v1 feaure only !
 13928                              <1> ;;sdsegmnt equ 	740h  ; swap data segment (for user structures and registers)
 13929                              <1> 
 13930                              <1> ; 30/08/2013
 13931                              <1> time_count equ 4 ; 10 --> 4 01/02/2014
 13932                              <1> 
 13933                              <1> ; 05/02/2014
 13934                              <1> ; process status
 13935                              <1> ;SFREE 	equ 0
 13936                              <1> ;SRUN	equ 1
 13937                              <1> ;SWAIT	equ 2
 13938                              <1> ;SZOMB	equ 3
 13939                              <1> ;SSLEEP	equ 4 ; Retro UNIX 8086 V1 extension (for sleep and wakeup)
 13940                              <1> 
 13941                              <1> ; 09/03/2015
 13942                              <1> userdata equ 80000h ; user structure data address for current user ; temporary
 13943                              <1> swap_queue equ 90000h - 2000h ; swap queue address ; temporary
 13944                              <1> swap_alloc_table equ 0D0000h  ;  swap allocation table address ; temporary
 13945                              <1> 
 13946                              <1> ; 17/09/2015
 13947                              <1> ESPACE equ 48 ; [u.usp] (at 'sysent') - [u.sp] value for error return
 13948                              <1> 
 13949                              <1> ; 21/09/2015 (36) 
 13950                              <1> ; 01/07/2015 (35)
 13951                              <1> ; 14/07/2013 (0-34)
 13952                              <1> ; UNIX v1 system calls
 13953                              <1> _rele 	equ 0
 13954                              <1> _exit 	equ 1
 13955                              <1> _fork 	equ 2
 13956                              <1> _read 	equ 3
 13957                              <1> _write	equ 4
 13958                              <1> _open	equ 5
 13959                              <1> _close 	equ 6
 13960                              <1> _wait 	equ 7
 13961                              <1> _creat 	equ 8
 13962                              <1> _link 	equ 9
 13963                              <1> _unlink	equ 10
 13964                              <1> _exec	equ 11
 13965                              <1> _chdir	equ 12
 13966                              <1> _time 	equ 13
 13967                              <1> _mkdir 	equ 14
 13968                              <1> _chmod	equ 15
 13969                              <1> _chown	equ 16
 13970                              <1> _break	equ 17
 13971                              <1> _stat	equ 18
 13972                              <1> _seek	equ 19
 13973                              <1> _tell 	equ 20
 13974                              <1> _mount	equ 21
 13975                              <1> _umount	equ 22
 13976                              <1> _setuid	equ 23
 13977                              <1> _getuid	equ 24
 13978                              <1> _stime	equ 25
 13979                              <1> _quit	equ 26	
 13980                              <1> _intr	equ 27
 13981                              <1> _fstat	equ 28
 13982                              <1> _emt 	equ 29
 13983                              <1> _mdate 	equ 30
 13984                              <1> _stty 	equ 31
 13985                              <1> _gtty	equ 32
 13986                              <1> _ilgins	equ 33
 13987                              <1> _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
 13988                              <1> _msg	equ 35 ; Retro UNIX 386 v1 feature only !
 13989                              <1> _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
 13990                              <1> 
 13991                              <1> %macro sys 1-4
 13992                              <1>     ; 13/04/2015
 13993                              <1>     ; Retro UNIX 386 v1 system call.		
 13994                              <1>     mov eax, %1
 13995                              <1>     %if %0 >= 2   
 13996                              <1>         mov ebx, %2
 13997                              <1>         %if %0 >= 3    
 13998                              <1>             mov ecx, %3
 13999                              <1>             %if %0 = 4
 14000                              <1>                mov edx, %4   
 14001                              <1>             %endif
 14002                              <1>         %endif
 14003                              <1>     %endif
 14004                              <1>     int 30h	   
 14005                              <1> %endmacro
 14006                              <1> 
 14007                              <1> ; 13/05/2015 - ERROR CODES
 14008                              <1> ERR_FILE_NOT_OPEN  equ 10 ; 'file not open !' error
 14009                              <1> ERR_FILE_ACCESS    equ 11 ; 'permission denied !' error
 14010                              <1> ; 14/05/2015
 14011                              <1> ERR_DIR_ACCESS     equ 11 ; 'permission denied !' error
 14012                              <1> ERR_FILE_NOT_FOUND equ 12 ; 'file not found !' error
 14013                              <1> ERR_TOO_MANY_FILES equ 13 ; 'too many open files !' error
 14014                              <1> ERR_DIR_EXISTS     equ 14 ; 'directory already exists !' error 	
 14015                              <1> ; 16/05/2015		
 14016                              <1> ERR_DRV_NOT_RDY    equ 15 ; 'drive not ready !' error
 14017                              <1> ; 18/05/2015
 14018                              <1> ERR_DEV_NOT_RDY    equ 15 ; 'device not ready !' error
 14019                              <1> ERR_DEV_ACCESS     equ 11 ; 'permission denied !' error 
 14020                              <1> ERR_DEV_NOT_OPEN   equ 10 ; 'device not open !' error	
 14021                              <1> ; 07/06/2015
 14022                              <1> ERR_FILE_EOF	   equ 16 ; 'end of file !' error
 14023                              <1> ERR_DEV_VOL_SIZE   equ 16 ; 'out of volume' error
 14024                              <1> ; 09/06/2015
 14025                              <1> ERR_DRV_READ	   equ 17 ; 'disk read error !'
 14026                              <1> ERR_DRV_WRITE	   equ 18 ; 'disk write error !'
 14027                              <1> ; 16/06/2015
 14028                              <1> ERR_NOT_DIR	   equ 19 ; 'not a (valid) directory !' error
 14029                              <1> ERR_FILE_SIZE	   equ 20 ; 'file size error !'	
 14030                              <1> ; 22/06/2015
 14031                              <1> ERR_NOT_SUPERUSER  equ 11 ; 'permission denied !' error
 14032                              <1> ERR_NOT_OWNER      equ 11 ; 'permission denied !' error
 14033                              <1> ERR_NOT_FILE       equ 11 ; 'permission denied !' error	
 14034                              <1> ; 23/06/2015
 14035                              <1> ERR_FILE_EXISTS    equ 14 ; 'file already exists !' error
 14036                              <1> ERR_DRV_NOT_SAME   equ 21 ; 'not same drive !' error
 14037                              <1> ERR_DIR_NOT_FOUND  equ 12 ; 'directory not found !' error
 14038                              <1> ERR_NOT_EXECUTABLE equ 22 ; 'not executable file !' error
 14039                              <1> ; 27/06/2015
 14040                              <1> ERR_INV_PARAMETER  equ 23 ; 'invalid parameter !' error
 14041                              <1> ERR_INV_DEV_NAME   equ 24 ; 'invalid device name !' error
 14042                              <1> ; 29/06/2015
 14043                              <1> ERR_TIME_OUT	   equ 25 ; 'time out !' error			
 14044                              <1> ERR_DEV_NOT_RESP   equ 25 ; 'device not responding !' error	
 14045                              <1> 
 14046                              <1> ; 26/08/2015
 14047                              <1> ; 24/07/2015
 14048                              <1> ; 24/06/2015
 14049                              <1> MAX_ARG_LEN	   equ 256 ; max. length of sys exec arguments
 14050                              <1> ; 01/07/2015
 14051                              <1> MAX_MSG_LEN	   equ 255 ; max. msg length for 'sysmsg'
 14052                              <1> ;	 					 		
 14053                                  %include 'trdosk0.s' ; 04/01/2016 
 14054                              <1> ; ****************************************************************************
 14055                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DEFINITIONS : trdosk0.s
 14056                              <1> ; ----------------------------------------------------------------------------
 14057                              <1> ; Last Update: 29/02/2016
 14058                              <1> ; ----------------------------------------------------------------------------
 14059                              <1> ; Beginning: 04/01/2016
 14060                              <1> ; ----------------------------------------------------------------------------
 14061                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14062                              <1> ; ----------------------------------------------------------------------------
 14063                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14064                              <1> ; TRDOS2.ASM (09/11/2011)
 14065                              <1> ; ****************************************************************************
 14066                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 14067                              <1> ;
 14068                              <1> ; Masterboot / Partition Table at Beginning+1BEh
 14069                              <1> ptBootable       equ 0
 14070                              <1> ptBeginHead      equ 1
 14071                              <1> ptBeginSector    equ 2
 14072                              <1> ptBeginCylinder  equ 3
 14073                              <1> ptFileSystemID   equ 4
 14074                              <1> ptEndHead        equ 5
 14075                              <1> ptEndSector      equ 6
 14076                              <1> ptEndCylinder    equ 7
 14077                              <1> ptStartSector    equ 8
 14078                              <1> ptSectors        equ 12
 14079                              <1> 
 14080                              <1> ; Boot Sector Parameters at 7C00h
 14081                              <1> DataArea1     equ -4
 14082                              <1> DataArea2     equ -2
 14083                              <1> BootStart     equ 0h
 14084                              <1> OemName       equ 03h
 14085                              <1> BytesPerSec   equ 0Bh
 14086                              <1> SecPerClust   equ 0Dh
 14087                              <1> ResSectors    equ 0Eh
 14088                              <1> FATs          equ 10h
 14089                              <1> RootDirEnts   equ 11h
 14090                              <1> Sectors       equ 13h
 14091                              <1> Media         equ 15h
 14092                              <1> FATSecs       equ 16h
 14093                              <1> SecPerTrack   equ 18h
 14094                              <1> Heads         equ 1Ah 
 14095                              <1> Hidden1       equ 1Ch
 14096                              <1> Hidden2       equ 1Eh
 14097                              <1> HugeSec1      equ 20h
 14098                              <1> HugeSec2      equ 22h
 14099                              <1> DriveNumber   equ 24h
 14100                              <1> Reserved1     equ 25h
 14101                              <1> bootsignature equ 26h                 
 14102                              <1> VolumeID      equ 27h
 14103                              <1> VolumeLabel   equ 2Bh
 14104                              <1> FileSysType   equ 36h          
 14105                              <1> Reserved2     equ 3Eh                           ; Starting cluster of P2000
 14106                              <1> 
 14107                              <1> ; FAT32 BPB Structure
 14108                              <1> FAT32_FAT_Size equ 36
 14109                              <1> FAT32_RootFClust equ 44
 14110                              <1> FAT32_FSInfoSec equ 48
 14111                              <1> FAT32_DrvNum equ 64
 14112                              <1> FAT32_BootSig equ 66
 14113                              <1> FAT32_VolID equ 67
 14114                              <1> FAT32_VolLab equ 71
 14115                              <1> FAT32_FilSysType equ 82
 14116                              <1> 
 14117                              <1> ; BIOS Disk Parameters
 14118                              <1> DPDiskNumber  equ 0h
 14119                              <1> DPDType       equ 1h
 14120                              <1> DPReturn      equ 2h
 14121                              <1> DPHeads       equ 3h
 14122                              <1> DPCylinders   equ 4h
 14123                              <1> DPSecPerTrack equ 6h
 14124                              <1> DPDisks       equ 7h
 14125                              <1> DPTableOff    equ 8h
 14126                              <1> DPTableSeg    equ 0Ah
 14127                              <1> DPNumOfSecs   equ 0Ch
 14128                              <1> 
 14129                              <1> ; BIOS INT 13h Extensions (LBA extensions)
 14130                              <1> ; Just After DP Data (DPDiskNumber+)
 14131                              <1> DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
 14132                              <1> DAP_Reserved1 equ 11h   ; Reserved Byte 
 14133                              <1> DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
 14134                              <1> DAP_Reserved2 equ 13h   ; Reserved Byte
 14135                              <1> DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
 14136                              <1> DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
 14137                              <1>                         ; C1= Selected Cylinder Number
 14138                              <1>                         ; H0= Number Of Heads (Maximum Head Number + 1)
 14139                              <1>                         ; H1= Selected Head Number
 14140                              <1>                         ; S0= Maximum Sector Number
 14141                              <1>                         ; S1= Selected Sector Number
 14142                              <1>                         ; QUAD WORD
 14143                              <1> ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
 14144                              <1>                              ; QUAD WORD (Also, value in 0h must be 18h) 
 14145                              <1>                              ; TR-DOS will not use 64 bit Flat Address
 14146                              <1> 
 14147                              <1> ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
 14148                              <1> ; Just After DP Data (DPDiskNumber+)
 14149                              <1> GetDParams_48h equ 20h ; Word. Data Length, must be 26 (1Ah) for short data.
 14150                              <1> GDP_48h_InfoFlag equ 22h ; Word
 14151                              <1> ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
 14152                              <1> GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
 14153                              <1> GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
 14154                              <1> GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
 14155                              <1> GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
 14156                              <1> GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
 14157                              <1> 
 14158                              <1> ; TR-DOS Standalone Program Extensions to the DiskParams Block
 14159                              <1> ; Just After DP Data (DPDiskNumber+)
 14160                              <1> TRDP_CurrentSector equ 3Ah  ; DX:AX (LBA)
 14161                              <1> TRDP_SectorCount equ 3Eh    ; CX (or Counter)
 14162                              <1> 
 14163                              <1> 
 14164                              <1> ; DOS Logical Disks
 14165                              <1> LD_Name equ 0
 14166                              <1> LD_DiskType equ 1
 14167                              <1> LD_PhyDrvNo equ 2
 14168                              <1> LD_FATType equ 3
 14169                              <1> LD_FSType equ 4
 14170                              <1> LD_LBAYes equ 5
 14171                              <1> LD_BPB equ 6
 14172                              <1> LD_FATBegin equ 96
 14173                              <1> LD_ROOTBegin equ 100
 14174                              <1> LD_DATABegin equ 104
 14175                              <1> LD_StartSector equ 108
 14176                              <1> LD_TotalSectors equ 112
 14177                              <1> LD_FreeSectors equ 116
 14178                              <1> LD_Clusters equ 120
 14179                              <1> LD_PartitionEntry equ 124
 14180                              <1> LD_DParamEntry equ 125
 14181                              <1> LD_MediaChanged equ 126
 14182                              <1> LD_CDirLevel equ 127
 14183                              <1> LD_CurrentDirectory equ 128
 14184                              <1> 
 14185                              <1> ; Singlix FS Extensions to DOS Logical Disks
 14186                              <1> ; 03/01/2010 (LD_BPB compatibility for CHS r/w)
 14187                              <1> 
 14188                              <1> LD_FS_Name equ 0
 14189                              <1> LD_FS_DiskType equ 1
 14190                              <1> LD_FS_PhyDrvNo equ 2
 14191                              <1> LD_FS_FATType equ 3
 14192                              <1> LD_FS_FSType equ 4
 14193                              <1> LD_FS_LBAYes equ 5
 14194                              <1> LD_FS_BPB equ 6
 14195                              <1> LD_FS_MediaAttrib equ 6
 14196                              <1> LD_FS_VersionMajor equ 7
 14197                              <1> LD_FS_RootDirD equ 8
 14198                              <1> LD_FS_MATLocation equ 12
 14199                              <1> LD_FS_Reserved1 equ 16 ;1 reserved byte
 14200                              <1> LD_FS_BytesPerSec equ 17 ; LD_BPB + 0Bh
 14201                              <1> LD_FS_Reserved2 equ 19 ;2 reserved byte
 14202                              <1> LD_FS_DATLocation equ 20
 14203                              <1> LD_FS_DATSectors equ 24
 14204                              <1> LD_FS_Reserved3 equ 28 ;3 reserved word
 14205                              <1> LD_FS_SecPerTrack equ 30 ; LD_BPB + 18h
 14206                              <1> LD_FS_NumHeads equ 32    ; LD_BPB + 1Ah
 14207                              <1> LD_FS_UnDelDirD equ 34
 14208                              <1> LD_FS_Reserved4 equ 38 ;4 reserved word
 14209                              <1> LD_FS_VolumeSerial equ 40
 14210                              <1> LD_FS_VolumeName equ 44
 14211                              <1> LD_FS_BeginSector equ 108
 14212                              <1> LD_FS_VolumeSize equ 112
 14213                              <1> LD_FS_FreeSectors equ 116
 14214                              <1> LD_FS_FirstFreeSector equ 120
 14215                              <1> LD_FS_PartitionEntry equ 124
 14216                              <1> LD_FS_DParamEntry equ 125
 14217                              <1> LD_FS_MediaChanged equ 126
 14218                              <1> LD_FS_CDirLevel equ 127
 14219                              <1> LD_FS_CDIR_Converted equ 128
 14220                              <1> 
 14221                              <1> ; Valid FAT Types
 14222                              <1> FS_FAT12 equ 1
 14223                              <1> FS_FAT16_CHS equ 2
 14224                              <1> FS_FAT32_CHS equ 3
 14225                              <1> FS_FAT16_LBA equ 4
 14226                              <1> FS_FAT32_LBA equ 5
 14227                              <1> 
 14228                              <1> ; Cursor Location
 14229                              <1> CCCpointer equ  0450h   ; BIOS data, current cursor column
 14230                              <1> ; FAT Clusters EOC sign
 14231                              <1> FAT12EOC equ 0FFFh
 14232                              <1> FAT16EOC equ 0FFFFh
 14233                              <1> ;FAT32EOC equ 0FFFFFFFh ; It is not direct usable for 8086 code
 14234                              <1> ; BAD Cluster
 14235                              <1> FAT12BADC equ 0FF7h
 14236                              <1> FAT16BADC equ 0FFF7h
 14237                              <1> ;FAT32BADC equ 0FFFFFF7h ; It is not direct usable for 8086 code
 14238                              <1> ; MS-DOS FAT16 FS (Maximum Possible) Last Cluster Number= 0FFF6h 
 14239                              <1> 
 14240                              <1> ; TRFS
 14241                              <1> 
 14242                              <1> bs_FS_JmpBoot equ 0 ; jmp short bsBootCode
 14243                              <1>                 ; db 0EBh, db 3Fh, db 90h
 14244                              <1> bs_FS_Identifier equ 3  ; db 'FS', db 0
 14245                              <1> bs_FS_BytesPerSec equ 6 ; dw 512
 14246                              <1> bs_FS_MediaAttrib equ 8 ; db 3
 14247                              <1> bs_FS_PartitionID equ 9 ; db 0A1h
 14248                              <1> bs_FS_VersionMaj equ 10 ; db 01h
 14249                              <1> bs_FS_VersionMin equ 11 ; db 0
 14250                              <1> bs_FS_BeginSector equ 12   ; dd 0 
 14251                              <1> bs_FS_VolumeSize equ 16 ; dd 2880
 14252                              <1> bs_FS_StartupFD equ 20 ; dd 0
 14253                              <1> bs_FS_MATLocation equ 24 ; dd 1
 14254                              <1> bs_FS_RootDirD equ 28 ; dd 8
 14255                              <1> bs_FS_SystemConfFD equ 32 ; dd 0
 14256                              <1> bs_FS_SwapFD equ 36 ; dd 0
 14257                              <1> bs_FS_UnDelDirD equ 40 ; dd 0
 14258                              <1> bs_FS_DriveNumber equ 44 ; db 0
 14259                              <1> bs_FS_LBA_Ready equ 45 ; db 0
 14260                              <1> bs_FS_MagicWord equ 46 
 14261                              <1> bs_FS_SecPerTrack equ 46 ; db 0A1h
 14262                              <1> bs_FS_Heads equ 47 ; db 01h 
 14263                              <1> bs_FS_OperationSys equ 48 ; db "TR-SINGLIX v1.0b"
 14264                              <1> bs_FS_Terminator equ 64 ; db 0
 14265                              <1> bs_FS_BootCode equ 65 
 14266                              <1> 
 14267                              <1> FS_MAT_DATLocation equ 12
 14268                              <1> FS_MAT_DATScount equ 16
 14269                              <1> FS_MAT_FreeSectors equ 20
 14270                              <1> FS_MAT_FirstFreeSector equ 24
 14271                              <1> FS_RDT_VolumeSerialNo equ 28
 14272                              <1> FS_RDT_VolumeName equ 64
 14273                              <1> 
 14274                              <1> ; FAT12 + FAT16 + FAT32
 14275                              <1> BS_JmpBoot equ 0
 14276                              <1> BS_OEMName equ 3
 14277                              <1> BPB_BytsPerSec equ 11
 14278                              <1> BPB_SecPerClust equ 13
 14279                              <1> BPB_RsvdSecCnt equ 14
 14280                              <1> BPB_NumFATs equ 16
 14281                              <1> BPB_RootEntCnt equ 17
 14282                              <1> BPB_TotalSec16 equ 19
 14283                              <1> BPB_Media equ 21
 14284                              <1> BPB_FATSz16 equ 22
 14285                              <1> BPB_SecPerTrk equ 24
 14286                              <1> BPB_NumHeads equ 26
 14287                              <1> BPB_HiddSec equ 28
 14288                              <1> BPB_TotalSec32 equ 32
 14289                              <1> 
 14290                              <1> ; FAT12 and FAT16 only
 14291                              <1> BS_DrvNum equ 36
 14292                              <1> BS_Reserved1 equ 37
 14293                              <1> BS_BootSig equ 38
 14294                              <1> BS_VolID equ 39
 14295                              <1> BS_VolLab equ 43
 14296                              <1> BS_FilSysType equ 54 ; 8 bytes
 14297                              <1> BS_BootCode equ 62
 14298                              <1> 
 14299                              <1> ; FAT32 only
 14300                              <1> BPB_FATSz32 equ 36 ; FAT32, 4 bytes
 14301                              <1> BPB_ExtFlags equ 40 ; FAT32, 2 bytes
 14302                              <1> BPB_FSVer equ 42 ; FAT32, 2 bytes
 14303                              <1> BPB_RootClus equ 44 ; FAT32, 4 bytes
 14304                              <1> BPB_FSInfo equ 48 ; FAT 32, 2 bytes 
 14305                              <1> BPB_BkBootSec equ 50 ; FAT32, 2 bytes
 14306                              <1> BPB_Reserved equ 52 ; FAT32, 12 bytes
 14307                              <1> BS_FAT32_DrvNum equ 64 ; FAT32, 1 byte
 14308                              <1> BS_FAT32_Reserved1 equ 65 ; FAT32, 1 byte
 14309                              <1> BS_FAT32_BootSig equ 66 ; FAT32, 1 byte
 14310                              <1> BS_FAT32_VolID equ 67 ; FAT32, 4 bytes
 14311                              <1> BS_FAT32_VolLab equ 71 ; FAT32, 11 bytes
 14312                              <1> BS_FAT32_FilSysType equ 82 ; FAT32, 8 bytes
 14313                              <1> BS_FAT32_BootCode equ 90
 14314                              <1> 
 14315                              <1> ; 29/02/2016
 14316                              <1> ;(FAT32 Free Cluster Count & First Free Cluster values)
 14317                              <1> ;[BPB_Reserved] = Free Cluster Count (offset 52)
 14318                              <1> ;[BPB_Reserved+4] = First Free Cluster (offset 56)
 14319                              <1> 
 14320                              <1> BS_Validation equ 510
 14321                              <1> 
 14322                              <1> ; 15/02/2016
 14323                              <1> ; FILE.ASM - 09/10/2011
 14324                              <1> ; Directory Entry Structure
 14325                              <1> ; 29/10/2009 (According to Microsoft FAT32 File System Specification)
 14326                              <1> DirEntry_Name equ 0
 14327                              <1> DirEntry_Attr equ 11
 14328                              <1> DirEntry_NTRes equ 12
 14329                              <1> DirEntry_CrtTimeTenth equ 13
 14330                              <1> DirEntry_CrtTime equ 14
 14331                              <1> DirEntry_CrtDate equ 16
 14332                              <1> DirEntry_LastAccDate equ 18
 14333                              <1> DirEntry_FstClusHI equ 20
 14334                              <1> DirEntry_WrtTime equ 22
 14335                              <1> DirEntry_WrtDate equ 24
 14336                              <1> DirEntry_FstClusLO equ 26
 14337                              <1> DirEntry_FileSize equ 28
 14338                                  %include 'trdosk1.s' ; 04/01/2016 
 14339                              <1> ; ****************************************************************************
 14340                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYS INIT : trdosk1.s
 14341                              <1> ; ----------------------------------------------------------------------------
 14342                              <1> ; Last Update: 14/04/2016
 14343                              <1> ; ----------------------------------------------------------------------------
 14344                              <1> ; Beginning: 04/01/2016
 14345                              <1> ; ----------------------------------------------------------------------------
 14346                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14347                              <1> ; ----------------------------------------------------------------------------
 14348                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14349                              <1> ; TRDOS2.ASM (09/11/2011)
 14350                              <1> ; ****************************************************************************
 14351                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 14352                              <1> ;
 14353                              <1> 
 14354                              <1> sys_init:
 14355                              <1> 	; 14/04/2016
 14356                              <1> 	; 13/04/2016
 14357                              <1> 	; 30/03/2016
 14358                              <1> 	; 24/01/2016
 14359                              <1> 	; 06/01/2016
 14360                              <1> 	; 04/01/2016
 14361                              <1> 
 14362                              <1> 	; 30/03/2016
 14363                              <1> 	; Clear Logical DOS Disk Description Tables Area
 14364 00003E10 31C0                <1> 	xor	eax, eax
 14365 00003E12 BF00010900          <1> 	mov	edi, Logical_DOSDisks
 14366 00003E17 B980060000          <1> 	mov	ecx, 6656/4 ; 26*256 = 6656 bytes
 14367 00003E1C F3AB                <1> 	rep	stosd ; 1664 times 4 bytes
 14368                              <1> 
 14369 00003E1E B83F3A2F00          <1> 	mov	eax, '?:/'
 14370 00003E23 A3[43C50000]        <1> 	mov	[Current_Dir_Drv], eax
 14371                              <1> 
 14372                              <1> 	; Logical DRV INIT (only for hard disks)
 14373 00003E28 E865010000          <1> 	call 	ldrv_init  ; trdosk2.s
 14374                              <1> 	
 14375                              <1> 	; When floppy_drv_init call is disabled
 14376                              <1> 	; media changed sign is needed
 14377                              <1> 	; for proper drive initialization
 14378                              <1>         
 14379 00003E2D BE00010900          <1> 	mov 	esi, Logical_DOSDisks
 14380 00003E32 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
 14381 00003E34 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
 14382 00003E37 8806                <1> 	mov 	[esi], al ; A:
 14383 00003E39 81C600010000        <1> 	add 	esi, 100h 
 14384 00003E3F 8806                <1> 	mov 	[esi], al ; B: 
 14385                              <1>            
 14386                              <1> _current_drive_bootdisk:
 14387 00003E41 8A15[4ABF0000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
 14388 00003E47 80FAFF              <1> 	cmp 	dl, 0FFh
 14389 00003E4A 740A                <1> 	je 	short _last_dos_diskno_check
 14390                              <1> _boot_drive_check:
 14391 00003E4C 80FA80              <1> 	cmp 	dl, 80h
 14392 00003E4F 7218                <1> 	jb 	short _current_drive_a
 14393 00003E51 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
 14394 00003E54 EB13                <1> 	jmp 	short _current_drive_a 
 14395                              <1> 
 14396                              <1> _last_dos_diskno_check:
 14397 00003E56 8A15[F5B40000]      <1> 	mov 	dl, [Last_DOS_DiskNo]
 14398 00003E5C 80FA02              <1> 	cmp 	dl, 2
 14399 00003E5F 7706                <1> 	ja 	short _current_drive_c
 14400 00003E61 7406                <1> 	je 	short _current_drive_a
 14401 00003E63 30D2                <1> 	xor 	dl, dl ; A:
 14402 00003E65 EB02                <1> 	jmp 	short _current_drive_a
 14403                              <1> 
 14404                              <1> _current_drive_c:
 14405 00003E67 B202                <1> 	mov 	dl, 2 ; C:
 14406                              <1> 
 14407                              <1> _current_drive_a:
 14408 00003E69 8815[4BBF0000]      <1> 	mov	[drv], dl
 14409 00003E6F BE[F7B40000]        <1>         mov     esi, msg_CRLF_temp
 14410 00003E74 E851000000          <1> 	call 	print_msg
 14411                              <1> 
 14412 00003E79 8A15[4BBF0000]      <1> 	mov	dl, [drv]
 14413 00003E7F E84A090000          <1> 	call 	change_current_drive
 14414 00003E84 730C                <1> 	jnc 	short _start_mainprog
 14415                              <1> 
 14416                              <1> _drv_not_ready_error: 
 14417 00003E86 BE[BBB70000]        <1> 	mov 	esi, msgl_drv_not_ready
 14418 00003E8B E83A000000          <1> 	call 	print_msg
 14419 00003E90 EB16                <1> 	jmp 	short _end_of_mainprog
 14420                              <1> 
 14421                              <1> _start_mainprog:
 14422                              <1> 	; Clear Environment Variables Page/Area (13/04/2016)
 14423 00003E92 BF00300900          <1> 	mov	edi, Env_Page ; 93000h
 14424 00003E97 B980000000          <1> 	mov	ecx, Env_Page_Size / 4 	; 512/4  (4096/4)				 	  		 	  
 14425                              <1> 	;xor	eax, eax
 14426 00003E9C F3AB                <1> 	rep	stosd
 14427                              <1> 
 14428 00003E9E E8B2320000          <1>  	call	mainprog_startup_configuration ; 14/04/2016
 14429                              <1> 
 14430 00003EA3 E8620A0000          <1>         call    dos_prompt
 14431                              <1>               
 14432                              <1> _end_of_mainprog:
 14433 00003EA8 BE[F7B40000]        <1>         mov     esi, msg_CRLF_temp
 14434 00003EAD E818000000          <1> 	call 	print_msg
 14435 00003EB2 BE[FDB40000]        <1> 	mov 	esi, mainprog_Version
 14436 00003EB7 E80E000000          <1> 	call 	print_msg
 14437                              <1> 	; 24/01/2016
 14438 00003EBC 28E4                <1> 	sub	ah, ah
 14439 00003EBE E824CDFFFF          <1> 	call	int16h ; call getch
 14440 00003EC3 E9E1D1FFFF          <1> 	jmp	cpu_reset
 14441                              <1> 
 14442 00003EC8 EBFE                <1> infinitiveloop: jmp short infinitiveloop
 14443                              <1> 
 14444                              <1> 
 14445                              <1> print_msg:
 14446                              <1> 	; 04/01/2016
 14447                              <1> 	; 01/07/2015
 14448                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14449                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14450                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
 14451                              <1> 	;
 14452 00003ECA AC                  <1> 	lodsb
 14453                              <1> pmsg1:
 14454 00003ECB 56                  <1> 	push 	esi
 14455 00003ECC 0FB61D[A8C40000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; 04/01/2016 (ptty)
 14456 00003ED3 B407                <1> 	mov	ah, 07h ; Black background, light gray forecolor
 14457 00003ED5 E8DDD8FFFF          <1> 	call 	WRITE_TTY
 14458 00003EDA 5E                  <1> 	pop	esi
 14459 00003EDB AC                  <1> 	lodsb
 14460 00003EDC 20C0                <1> 	and 	al, al
 14461 00003EDE 75EB                <1> 	jnz 	short pmsg1
 14462 00003EE0 C3                  <1> 	retn
 14463                              <1> 
 14464                              <1> clear_screen:
 14465                              <1> 	; 30/01/2016
 14466                              <1> 	; 24/01/2016
 14467                              <1> 	; 04/01/2016
 14468 00003EE1 0FB61D[A8C40000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
 14469 00003EE8 8AA3[C0BE0000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
 14470 00003EEE 80FC04              <1> 	cmp	ah, 4
 14471 00003EF1 7205                <1> 	jb	short cls1
 14472 00003EF3 80FC07              <1> 	cmp	ah, 7
 14473 00003EF6 7524                <1> 	jne	short vga_clear
 14474                              <1> cls1:
 14475 00003EF8 3A25[A6BE0000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
 14476                              <1> 	;je	short cls2 ; yes (current video mode = 3)
 14477                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
 14478                              <1> 	;;retn
 14479                              <1> 	;jmp	set_mode_3
 14480 00003EFE 0F85C5D5FFFF        <1> 	jne	set_mode_3
 14481                              <1> cls2:
 14482 00003F04 B407                <1> 	mov	ah, 07h ; attribute to be used on blanked line
 14483 00003F06 28C0                <1> 	sub 	al, al ; 0 =  entire window
 14484 00003F08 6631C9              <1> 	xor 	cx, cx
 14485 00003F0B 66BA4F18            <1> 	mov 	dx, 184Fh
 14486 00003F0F E8F9D6FFFF          <1> 	call	_scroll_up ; 24/01/2016
 14487                              <1> 	;
 14488                              <1> 	;mov	bl, [ACTIVE_PAGE] ; video page number (0 to 7)
 14489 00003F14 6631D2              <1> 	xor 	dx, dx
 14490 00003F17 E82FD9FFFF          <1> 	call	_set_cpos ; 24/01/2016 
 14491                              <1> 	;retn
 14492                              <1> vga_clear:
 14493 00003F1C C3                  <1> 	retn	
 14494                              <1> 
 14495                              <1> panic:
 14496                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14497                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14498 00003F1D BE[59C10000]        <1> 	mov 	esi, panic_msg
 14499 00003F22 E8A3FFFFFF          <1> 	call 	print_msg
 14500                              <1> key_to_reboot:
 14501                              <1>         ; 24/01/2016
 14502 00003F27 28E4                <1>         sub     ah, ah
 14503 00003F29 E8B9CCFFFF          <1>         call    int16h ; call   getch
 14504                              <1>         ; wait for a character from the current tty
 14505                              <1> 	;
 14506 00003F2E B00A                <1> 	mov	al, 0Ah
 14507 00003F30 8A1D[A8C40000]      <1> 	mov	bl, [ptty] ; [ACTIVE_PAGE]
 14508 00003F36 B407                <1> 	mov	ah, 07h ; Black background, 
 14509                              <1> 			; light gray forecolor
 14510 00003F38 E87AD8FFFF          <1> 	call 	WRITE_TTY
 14511 00003F3D E967D1FFFF          <1> 	jmp	cpu_reset 
 14512                              <1> 
 14513                              <1> ctrlbrk:
 14514                              <1> 	; 12/11/2015
 14515                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14516                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
 14517                              <1> 	;
 14518                              <1> 	; INT 1Bh (control+break) handler		
 14519                              <1> 	;
 14520                              <1>       	; Retro Unix 8086 v1 feature only!
 14521                              <1>       	;
 14522 00003F42 66833D[1CD50000]00  <1> 	cmp 	word [u.intr], 0
 14523 00003F4A 7645                <1> 	jna 	short cbrk4
 14524                              <1> cbrk0:
 14525                              <1> 	; 12/11/2015
 14526                              <1> 	; 06/12/2013
 14527 00003F4C 66833D[1ED50000]00  <1> 	cmp 	word [u.quit], 0
 14528 00003F54 743B                <1> 	jz	short cbrk4
 14529                              <1> 	;
 14530                              <1> 	; 20/09/2013	
 14531 00003F56 6650                <1> 	push 	ax
 14532 00003F58 A0[A8C40000]        <1> 	mov	al, [ptty]
 14533                              <1> 	;
 14534                              <1> 	; 12/11/2015
 14535                              <1> 	;
 14536                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
 14537                              <1> 	; or ctrl+break from console (pseudo) tty
 14538                              <1> 	; (!redirection!)
 14539                              <1> 	;
 14540 00003F5D 3C08                <1> 	cmp	al, 8 ; serial port tty nums > 7
 14541 00003F5F 7211                <1>         jb      short cbrk1 ; console (pseudo) tty
 14542                              <1> 	;	
 14543                              <1> 	; Serial port interrupt handler sets [ptty]
 14544                              <1> 	; to the port's tty number (as temporary).
 14545                              <1> 	;
 14546                              <1> 	; If active process is using a stdin or 
 14547                              <1> 	; stdout redirection (by the shell),
 14548                              <1>         ; console tty keyboard must be available
 14549                              <1> 	; to terminate running process,
 14550                              <1> 	; in order to prevent a deadlock. 
 14551                              <1> 	;
 14552 00003F61 52                  <1> 	push	edx
 14553 00003F62 0FB615[27D50000]    <1> 	movzx	edx, byte [u.uno]
 14554 00003F69 3A82[2BD20000]      <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
 14555 00003F6F 5A                  <1> 	pop	edx
 14556 00003F70 7412                <1> 	je	short cbrk2
 14557                              <1> cbrk1:
 14558 00003F72 FEC0                <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
 14559                              <1> 	; 06/12/2013
 14560 00003F74 3A05[08D50000]      <1> 	cmp	al, [u.ttyp] ; recent open tty (r)
 14561 00003F7A 7408                <1> 	je	short cbrk2	
 14562 00003F7C 3A05[09D50000]      <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
 14563 00003F82 750B                <1> 	jne	short cbrk3	
 14564                              <1> cbrk2:
 14565                              <1> 	;; 06/12/2013
 14566                              <1> 	;mov	ax, [u.quit]
 14567                              <1> 	;and	ax, ax
 14568                              <1> 	;jz	short cbrk3
 14569                              <1> 	;
 14570 00003F84 6631C0              <1> 	xor	ax, ax ; 0
 14571 00003F87 6648                <1> 	dec	ax
 14572                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
 14573 00003F89 66A3[1ED50000]      <1> 	mov	[u.quit], ax
 14574                              <1> cbrk3:
 14575 00003F8F 6658                <1> 	pop	ax
 14576                              <1> cbrk4:
 14577 00003F91 C3                  <1> 	retn
 14578                                  %include 'trdosk2.s' ; 04/01/2016
 14579                              <1> ; ****************************************************************************
 14580                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DRV INIT : trdosk2.s
 14581                              <1> ; ----------------------------------------------------------------------------
 14582                              <1> ; Last Update: 29/02/2016
 14583                              <1> ; ----------------------------------------------------------------------------
 14584                              <1> ; Beginning: 04/01/2016
 14585                              <1> ; ----------------------------------------------------------------------------
 14586                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14587                              <1> ; ----------------------------------------------------------------------------
 14588                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14589                              <1> ; TRDOS2.ASM (09/11/2011)
 14590                              <1> ; ****************************************************************************
 14591                              <1> ; DRV_INIT.ASM (c) 2009-2011 Erdogan TAN  [26/09/2009] Last Update: 07/08/2011
 14592                              <1> ;
 14593                              <1> 
 14594                              <1> ldrv_init: ; Logical Drive Initialization
 14595                              <1> 	; 12/02/2016
 14596                              <1> 	; 06/01/2016
 14597                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
 14598                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
 14599                              <1> 	; 07/08/2011
 14600                              <1> 	; 20/09/2009
 14601                              <1> 	; 2005
 14602 00003F92 0FB60D[18C50000]    <1> 	movzx	ecx, byte [HF_NUM] ; number of fixed disks
 14603 00003F99 80F901              <1> 	cmp	cl, 1
 14604 00003F9C 7301                <1> 	jnb	short load_hd_partition_tables
 14605                              <1> 	; No hard disks
 14606 00003F9E C3                  <1> 	retn
 14607                              <1> load_hd_partition_tables:
 14608 00003F9F 8B35[1CC50000]      <1> 	mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
 14609 00003FA5 BF[42C90000]        <1> 	mov 	edi, PTable_hd0
 14610 00003FAA B280                <1> 	mov 	dl, 80h
 14611                              <1> load_next_hd_partition_table:
 14612 00003FAC 51                  <1> 	push	ecx
 14613 00003FAD 57                  <1> 	push	edi
 14614 00003FAE 56                  <1> 	push	esi ; FDPT (+ DPTE) address
 14615 00003FAF 8A4614              <1> 	mov	al, [esi+20] ; DPTE offset 4
 14616 00003FB2 2440                <1> 	and	al, 40h ;  LBA bit (bit 6)
 14617                              <1> 	;shr	al, 6
 14618 00003FB4 A2[42CB0000]        <1> 	mov 	[HD_LBA_yes], al
 14619 00003FB9 E81C040000          <1> 	call	load_masterboot
 14620 00003FBE 7275                <1> 	jc	short pass_pt_this_hard_disk
 14621                              <1> 
 14622 00003FC0 BE[00C90000]        <1> 	mov	esi, PartitionTable
 14623 00003FC5 89F3                <1> 	mov	ebx, esi
 14624                              <1> 	;mov	ecx, 16
 14625 00003FC7 B110                <1> 	mov	cl, 16
 14626 00003FC9 F3A5                <1> 	rep 	movsd
 14627 00003FCB 89DE                <1> 	mov 	esi, ebx 
 14628 00003FCD C605[4DBF0000]04    <1> 	mov 	byte [hdc], 4 ; 4 - partition index
 14629                              <1> loc_validate_hdp_partition:
 14630 00003FD4 807E0400            <1> 	cmp 	byte [esi+ptFileSystemID], 0
 14631 00003FD8 7641                <1> 	jna	short loc_validate_next_hdp_partition2
 14632 00003FDA 56                  <1> 	push	esi ; Masterboot partition table offset
 14633 00003FDB 52                  <1> 	push	edx ; dl = Physical drive number 
 14634 00003FDC FE05[43CB0000]      <1> 	inc	byte [PP_Counter]
 14635 00003FE2 31FF                <1>         xor	edi, edi ; 0  
 14636                              <1> 	; Input -> ESI = PartitionTable offset
 14637                              <1> 	; DL = Hard disk drive number 
 14638                              <1> 	; EDI = 0 -> Primary Partition
 14639                              <1> 	; EDI > 0 -> Extended Partition's Start Sector   
 14640 00003FE4 E879010000          <1> 	call 	validate_hd_fat_partition
 14641 00003FE9 730A                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
 14642                              <1> 	;pop	edx
 14643                              <1> 	;push	edx
 14644 00003FEB 8B1424              <1> 	mov	edx, [esp] 
 14645 00003FEE E8C5020000          <1> 	call	validate_hd_fs_partition
 14646 00003FF3 7224                <1> 	jc	short loc_validate_next_hdp_partition1
 14647                              <1> loc_set_valid_hdp_partition_entry:
 14648 00003FF5 8A0D[F5B40000]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
 14649 00003FFB 80C141              <1> 	add 	cl, 'A'
 14650                              <1> 	; ESI = Logical dos drive description table address
 14651 00003FFE 880E                <1> 	mov	[esi+LD_Name], cl
 14652 00004000 8A6602              <1> 	mov	ah, [esi+LD_PhyDrvNo]
 14653 00004003 88E0                <1> 	mov	al, ah ; Physical drive number
 14654 00004005 2C80                <1> 	sub	al, 80h
 14655 00004007 C0E002              <1> 	shl	al, 2
 14656 0000400A 0404                <1> 	add	al, 4 ; 0 Based
 14657 0000400C 2A05[4DBF0000]      <1> 	sub	al, [hdc] ; 4 - partition index
 14658                              <1> 	; AL = Partition entry/index, 0 based
 14659                              <1> 	;  0 -> hd 0, Partition Table offset = 0
 14660                              <1> 	; 15 -> hd 3, Partition Table offset = 3
 14661                              <1> 	;mov	[esi+LD_PartitionEntry], al 
 14662 00004012 80EC7E              <1> 	sub 	ah, 7Eh
 14663                              <1> 	; AH = Physical drive index, zero based
 14664                              <1> 	;  0 for drive A:, 2 for drive C:
 14665                              <1> 	;mov 	[esi+LD_DParamEntry], ah 
 14666 00004015 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
 14667                              <1> loc_validate_next_hdp_partition1:
 14668 00004019 5A                  <1> 	pop 	edx ; dl = Physical drive number 
 14669 0000401A 5E                  <1> 	pop	esi ; Masterboot partition table offset
 14670                              <1> loc_validate_next_hdp_partition2:
 14671                              <1> 	; ESI = PartitionTable offset
 14672                              <1> 	; DL = Hard/Fixed disk drive number
 14673 0000401B FE0D[4DBF0000]      <1> 	dec	byte [hdc] ; 4 - partition index
 14674 00004021 7412                <1> 	jz	short pass_pt_this_hard_disk
 14675 00004023 83C610              <1> 	add	esi, 16 ; 10h
 14676 00004026 EBAC                <1> 	jmp	short loc_validate_hdp_partition
 14677                              <1> loc_next_hd_partition_table:
 14678 00004028 FEC2                <1> 	inc	dl
 14679 0000402A 83C620              <1> 	add	esi, 32 ; next FDPT address
 14680 0000402D 83C740              <1> 	add	edi, 64 ; next partition table destination
 14681 00004030 E977FFFFFF          <1>         jmp     load_next_hd_partition_table
 14682                              <1> pass_pt_this_hard_disk:
 14683 00004035 5E                  <1> 	pop	esi ; FDPT (+ DPTE) address
 14684 00004036 5F                  <1> 	pop	edi ; Ptable_hd?
 14685 00004037 59                  <1> 	pop	ecx
 14686 00004038 E2EE                <1> 	loop	loc_next_hd_partition_table
 14687 0000403A 803D[43CB0000]01    <1> 	cmp	byte [PP_Counter], 1
 14688 00004041 7301                <1> 	jnb	short load_extended_dos_partitions
 14689                              <1> 	; Empty partition table
 14690 00004043 C3                  <1> 	retn 
 14691                              <1> load_extended_dos_partitions:
 14692 00004044 BE[42C90000]        <1> 	mov	esi, PTable_hd0
 14693 00004049 BF[42CA0000]        <1> 	mov	edi, PTable_ep0
 14694 0000404E C605[4DBF0000]80    <1> 	mov	byte [hdc], 80h
 14695                              <1> next_hd_extd_partition:
 14696 00004055 56                  <1> 	push	esi ; PTable_hd? offset
 14697 00004056 57                  <1> 	push	edi ; PTable_ep?
 14698                              <1> 	;mov	ecx, 4
 14699 00004057 B104                <1> 	mov	cl, 4
 14700 00004059 8A15[4DBF0000]      <1> 	mov	dl, byte [hdc]
 14701                              <1> hd_check_fs_id_05h:
 14702 0000405F 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
 14703 00004062 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
 14704 00004064 7404                <1> 	je	short loc_set_ep_start_sector
 14705 00004066 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
 14706 00004068 7546                <1> 	jne	short continue_to_check_ep
 14707                              <1> loc_set_ep_start_sector:
 14708 0000406A FE05[44CB0000]      <1> 	inc	byte [EP_Counter]
 14709 00004070 88D4                <1> 	mov	ah, dl ; byte [hdc]
 14710 00004072 86E0                <1> 	xchg	ah, al ; al = Drv Number, ah = Partition Identifier
 14711 00004074 50                  <1> 	push	eax 
 14712 00004075 30E4                <1> 	xor	ah, ah  
 14713 00004077 2C80                <1> 	sub	al, 80h
 14714 00004079 50                  <1> 	push	eax
 14715 0000407A C0E002              <1> 	shl	al, 2 ; al = al * 4
 14716 0000407D 0FB6D8              <1> 	movzx	ebx, al
 14717 00004080 81C3[45CB0000]      <1> 	add	ebx, EP_StartSector
 14718 00004086 8B4608              <1> 	mov	eax, [esi+ptStartSector]
 14719                              <1>         ; EAX = Extended partition's start sector
 14720 00004089 8903                <1>         mov	[ebx], eax
 14721 0000408B 58                  <1> 	pop	eax ; AL = Drv number - 80h, AH = 0 
 14722 0000408C 5A                  <1> 	pop	edx ; DL = Drv number, DH = Partition ID
 14723 0000408D BB[42C70000]        <1> 	mov	ebx, MasterBootBuff
 14724 00004092 803D[42CB0000]01    <1> 	cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
 14725 00004099 7240                <1> 	jb	short loc_hd_load_ep_05h
 14726 0000409B 80FE05              <1> 	cmp	dh, 05h
 14727 0000409E 743B                <1> 	je	short loc_hd_load_ep_05h
 14728                              <1> loc_hd_load_ep_0Fh:
 14729                              <1> 	; 04/01/2016
 14730 000040A0 51                  <1> 	push	ecx
 14731 000040A1 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; sector number
 14732                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
 14733                              <1> 	; LBA read/write (with private LBA function) 
 14734                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14735                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14736 000040A4 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14737 000040A6 B001                <1> 	mov	al, 1 ; sector count
 14738 000040A8 E81FE8FFFF          <1> 	call	int13h
 14739 000040AD 59                  <1> 	pop	ecx
 14740 000040AE 733F                <1> 	jnc	short loc_hd_move_ep_table
 14741                              <1> continue_to_check_ep:
 14742 000040B0 83C610              <1> 	add	esi, 16
 14743 000040B3 E2AA                <1> 	loop	hd_check_fs_id_05h
 14744                              <1> continue_check_ep_next_disk:
 14745 000040B5 5F                  <1> 	pop	edi ; PTable_ep?
 14746 000040B6 5E                  <1> 	pop	esi ; PTable_hd?
 14747 000040B7 A0[18C50000]        <1> 	mov	al, [HF_NUM] ; number of hard disks
 14748 000040BC 047F                <1> 	add	al, 7Fh
 14749 000040BE 3805[4DBF0000]      <1> 	cmp	[hdc], al
 14750 000040C4 0F8392000000        <1> 	jnb	loc_validating_hd_partitions_ok
 14751 000040CA 83C640              <1> 	add	esi, 64
 14752 000040CD 83C740              <1> 	add	edi, 64
 14753 000040D0 FE05[4DBF0000]      <1> 	inc	byte [hdc]
 14754 000040D6 E97AFFFFFF          <1> 	jmp	next_hd_extd_partition
 14755                              <1> loc_hd_load_ep_05h:
 14756 000040DB 51                  <1> 	push	ecx 
 14757 000040DC 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14758 000040DF 668B4E02            <1>         mov     cx, word [esi+ptBeginSector]
 14759 000040E3 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14760                              <1> 	;mov	ebx, MasterBootBuff
 14761 000040E7 E8E0E7FFFF          <1> 	call	int13h
 14762 000040EC 59                  <1> 	pop	ecx  
 14763 000040ED 72C1                <1> 	jc	short continue_to_check_ep
 14764                              <1> loc_hd_move_ep_table:
 14765                              <1>         ;pop	edi
 14766                              <1> 	;push	edi  ; PTable_ep?
 14767 000040EF 8B3C24              <1> 	mov	edi, [esp]        
 14768 000040F2 BE[00C90000]        <1>         mov	esi, PartitionTable ; Extended
 14769 000040F7 89F3                <1> 	mov	ebx, esi
 14770                              <1> 	;mov	ecx, 16
 14771 000040F9 B110                <1> 	mov	cl, 16
 14772 000040FB F3A5                <1>        	rep	movsd
 14773 000040FD 89DE                <1> 	mov	esi, ebx 
 14774                              <1> loc_set_hde_sub_partition_count:
 14775 000040FF C605[43CB0000]04    <1> 	mov	byte [PP_Counter], 4
 14776                              <1> loc_validate_hde_partition:
 14777 00004106 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
 14778 0000410A 763F                <1> 	jna	short loc_validate_next_hde_partition2
 14779 0000410C 56                  <1> 	push	esi ; Extended partition table offset
 14780 0000410D 8A15[4DBF0000]      <1> 	mov	dl, byte [hdc]
 14781 00004113 0FB6C2              <1> 	movzx	eax, dl
 14782 00004116 2C80                <1> 	sub	al, 80h
 14783 00004118 C0E002              <1> 	shl	al, 2
 14784                              <1> 	; 06/01/2016 
 14785                              <1> 	; (TRDOS v1.0 had a bug here, in 'DRV_INIT.ASM')
 14786                              <1> 	; BUGFIX *
 14787                              <1> 	;mov	ecx, eax
 14788 0000411B 88C1                <1> 	mov	cl, al
 14789 0000411D 80C104              <1> 	add	cl, 4
 14790 00004120 2A0D[43CB0000]      <1> 	sub	cl, [PP_Counter] ; 4 to 1
 14791                              <1> 	; CL = Partition entry/index, 0 based
 14792                              <1>         ;  0 -> hd 0, Partition Table offset = 0
 14793                              <1>         ; 15 -> hd 3, Partition Table offset = 3
 14794 00004126 88D5                <1>       	mov	ch, dl   
 14795 00004128 80ED7E              <1> 	sub	ch, 7Eh ;
 14796                              <1> 	; CH = Physical drive index, zero based
 14797                              <1> 	;  0 for drive A:, 2 for drive C:	
 14798                              <1> 	; BUGFIX *
 14799 0000412B 51                  <1> 	push	ecx ; *
 14800 0000412C BF[45CB0000]        <1> 	mov	edi, EP_StartSector
 14801 00004131 01C7                <1> 	add	edi, eax
 14802                              <1> 	; Input -> ESI = PartitionTable offset
 14803                              <1> 	; DL = Hard disk drive number   
 14804                              <1> 	; EDI = Extended partition start sector pointer
 14805 00004133 E82A000000          <1> 	call	validate_hd_fat_partition
 14806 00004138 59                  <1> 	pop	ecx ; *
 14807 00004139 720F                <1> 	jc	short loc_validate_next_hde_partition1
 14808                              <1> loc_set_valid_hde_partition_entry:
 14809                              <1> 	; 06/01/2016 (TRDOS v2.0)
 14810                              <1> 	; BUGFIX *
 14811                              <1> 	;mov	[esi+LD_PartitionEntry], cl 
 14812                              <1> 	;mov	[esi+LD_DParamEntry], ch 
 14813 0000413B 66894E7C            <1> 	mov	[esi+LD_PartitionEntry], cx 
 14814                              <1> 	;
 14815 0000413F 8A0D[F5B40000]      <1> 	mov	cl, [Last_DOS_DiskNo] 
 14816 00004145 80C141              <1> 	add	cl, 'A'
 14817 00004148 880E                <1> 	mov	[esi+LD_Name], cl
 14818                              <1> loc_validate_next_hde_partition1:
 14819 0000414A 5E                  <1> 	pop	esi ; Extended partition table offset
 14820                              <1> loc_validate_next_hde_partition2:
 14821                              <1> 	; ESI = Extended partition table offset
 14822                              <1> 	; DL = Hard disk drive number
 14823 0000414B FE0D[43CB0000]      <1> 	dec	byte [PP_Counter]
 14824 00004151 0F845EFFFFFF        <1> 	jz	continue_check_ep_next_disk
 14825 00004157 83C610              <1> 	add 	esi, 16 ; 10h
 14826 0000415A EBAA                <1> 	jmp	short loc_validate_hde_partition
 14827                              <1> loc_validating_hd_partitions_ok:
 14828 0000415C A0[F5B40000]        <1> 	mov	al, [Last_DOS_DiskNo]
 14829                              <1> loc_drv_init_retn:
 14830 00004161 C3                  <1> 	retn
 14831                              <1> 
 14832                              <1> validate_hd_fat_partition:
 14833                              <1> 	; 12/02/2016
 14834                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 14835                              <1> 	; 07/08/2011
 14836                              <1> 	; 23/07/2011
 14837                              <1> 	; Input
 14838                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 14839                              <1> 	;   ESI = PartitionTable offset
 14840                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
 14841                              <1> 	;   EDI = 0 -> Primary Partition 
 14842                              <1> 	;   byte [Last_DOS_DiskNo]
 14843                              <1>  	; Output
 14844                              <1> 	;  cf=0 -> Validated
 14845                              <1> 	;   ESI = Logical dos drv desc. table
 14846                              <1> 	;   EBX = FAT boot sector buffer
 14847                              <1> 	;   byte [Last_DOS_DiskNo]
 14848                              <1> 	;  cf=1 -> Not a valid FAT partition
 14849                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 14850                              <1> 	
 14851                              <1> 	;mov 	esi, PartitionTable
 14852 00004162 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
 14853 00004165 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition
 14854                              <1> 	; 12/02/2016
 14855                              <1> 	;jb	short loc_not_a_valid_fat_partition2
 14856 00004168 7305                <1>  	jnb	short vhdp_FAT16_32
 14857                              <1> 	;
 14858 0000416A 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)		
 14859 0000416D 7519                <1> 	jne	short loc_not_a_valid_fat_partition1
 14860                              <1> vhdp_FAT16_32:
 14861 0000416F B002                <1> 	mov	al, 2
 14862 00004171 7417                <1> 	je	short loc_set_valid_hd_partition_params
 14863 00004173 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
 14864 00004176 7710                <1> 	ja	short loc_not_a_valid_fat_partition1
 14865 00004178 7410                <1> 	je	short loc_set_valid_hd_partition_params
 14866                              <1> 
 14867 0000417A FEC0                <1> 	inc	al ; 3
 14868 0000417C 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
 14869 0000417F 7409                <1> 	je	short loc_set_valid_hd_partition_params
 14870 00004181 7206                <1> 	jb	short loc_not_a_valid_fat_partition2
 14871 00004183 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
 14872 00004186 7402                <1> 	je	short loc_set_valid_hd_partition_params
 14873                              <1> loc_not_a_valid_fat_partition1:
 14874 00004188 F9                  <1> 	stc
 14875                              <1> loc_not_a_valid_fat_partition2:
 14876 00004189 C3                  <1> 	retn
 14877                              <1> 
 14878                              <1> loc_set_valid_hd_partition_params:
 14879 0000418A FE05[F5B40000]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
 14880                              <1> 	;
 14881 00004190 31DB                <1> 	xor	ebx, ebx
 14882 00004192 8A3D[F5B40000]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256	
 14883 00004198 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 14884                              <1> 	;
 14885 0000419E C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 14886 000041A2 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
 14887                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
 14888                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
 14889 000041A5 66894303            <1> 	mov	word [ebx+LD_FATType], ax
 14890                              <1> 	;
 14891 000041A9 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
 14892 000041AC 09FF                <1> 	or	edi, edi 
 14893 000041AE 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
 14894                              <1> loc_add_hd_FAT_ep_start_sector:
 14895 000041B0 030F                <1> 	add	ecx, [edi]
 14896                              <1> pass_hd_FAT_ep_start_sector_adding:
 14897 000041B2 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
 14898                              <1> loc_hd_FAT_logical_drv_init:
 14899 000041B5 89DD                <1> 	mov	ebp, ebx
 14900                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 14901 000041B7 A0[42CB0000]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
 14902 000041BC 884305              <1> 	mov	[ebx+LD_LBAYes], al
 14903 000041BF BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
 14904 000041C4 08C0                <1> 	or	al, al
 14905 000041C6 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
 14906                              <1> loc_hd_FAT_drv_init_load_bs_lba:
 14907                              <1> 	; DL = Physical drive number
 14908                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
 14909                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 14910                              <1> 	; LBA read/write (with private LBA function) 
 14911                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14912                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14913 000041C8 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14914 000041CA B001                <1> 	mov	al, 1 ; sector count
 14915 000041CC E8FBE6FFFF          <1> 	call	int13h
 14916 000041D1 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
 14917                              <1> loc_not_a_valid_fat_partition3:
 14918 000041D3 C3                  <1> 	retn
 14919                              <1> loc_hd_FAT_drv_init_load_bs_chs:
 14920 000041D4 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14921 000041D7 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 14922 000041DB 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14923                              <1> 	;mov	ebx, DOSBootSectorBuff
 14924 000041DF E8E8E6FFFF          <1> 	call	int13h
 14925 000041E4 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
 14926                              <1> loc_hd_drv_FAT_boot_validation:
 14927                              <1> 	;mov	esi, DOSBootSectorBuff
 14928 000041E6 89DE                <1> 	mov	esi, ebx
 14929 000041E8 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 14930 000041F1 751A                <1> 	jne	short loc_not_a_valid_fat_partition4
 14931 000041F3 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
 14932 000041F7 7514                <1> 	jne	short loc_not_a_valid_fat_partition4
 14933 000041F9 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
 14934 000041FE 770F                <1> 	ja	short loc_hd_FAT16_BPB
 14935 00004200 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
 14936 00004204 7507                <1> 	jne	short loc_not_a_valid_fat_partition4
 14937                              <1> loc_hd_FAT32_BPB:
 14938 00004206 B92D000000          <1> 	mov	ecx, 45
 14939 0000420B EB0D                <1> 	jmp	short loc_hd_move_FAT_BPB
 14940                              <1> 	;
 14941                              <1> loc_not_a_valid_fat_partition4:
 14942 0000420D F9                  <1> 	stc
 14943 0000420E C3                  <1> 	retn
 14944                              <1> 	;
 14945                              <1> loc_hd_FAT16_BPB:
 14946 0000420F 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 14947 00004213 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
 14948 00004215 B920000000          <1> 	mov	ecx, 32
 14949                              <1> loc_hd_move_FAT_BPB:
 14950 0000421A 89EF                <1> 	mov 	edi, ebp
 14951                              <1> 	;mov	esi, ebx ; Boot sector
 14952 0000421C 57                  <1> 	push	edi
 14953 0000421D 83C706              <1> 	add	edi, LD_BPB
 14954 00004220 F366A5              <1> 	rep	movsw 
 14955 00004223 5E                  <1> 	pop	esi
 14956 00004224 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
 14957 00004228 03466C              <1> 	add	eax, [esi+LD_StartSector]
 14958 0000422B 894660              <1> 	mov	[esi+LD_FATBegin], eax
 14959 0000422E 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 14960 00004232 7224                <1> 	jb	short loc_set_FAT16_RootDirLoc
 14961                              <1> loc_set_FAT32_RootDirLoc:
 14962 00004234 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
 14963 00004237 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
 14964 0000423B F7E3                <1> 	mul	ebx
 14965 0000423D 034660              <1> 	add	eax, [esi+LD_FATBegin]
 14966                              <1> loc_set_FAT32_data_begin:
 14967 00004240 894668              <1> 	mov	[esi+LD_DATABegin], eax
 14968 00004243 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14969                              <1> 	; If Root Directory Cluster <> 2 then
 14970                              <1> 	; change the beginning sector value 
 14971                              <1> 	; of the root dir by adding sector offset.
 14972 00004246 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 14973 00004249 83E802              <1> 	sub	eax, 2
 14974 0000424C 7442                <1> 	jz	short short loc_set_32bit_FAT_total_sectors  
 14975                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 14976 0000424E 8A5E13              <1> 	mov	bl, byte [esi+LD_BPB+BPB_SecPerClust] 
 14977 00004251 F7E3                <1> 	mul	ebx
 14978 00004253 014664              <1> 	add	[esi+LD_ROOTBegin], eax
 14979 00004256 EB38                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
 14980                              <1> 	;
 14981                              <1> loc_set_FAT16_RootDirLoc:
 14982 00004258 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
 14983 0000425C 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
 14984 00004260 F7E2                <1> 	mul	edx
 14985 00004262 034660              <1> 	add	eax, [esi+LD_FATBegin]  
 14986 00004265 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14987                              <1> loc_set_FAT16_data_begin:
 14988 00004268 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 14989 0000426B B820000000          <1> 	mov	eax, 20h  ; Size of a directory entry
 14990                              <1> 	;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
 14991 00004270 668B5617            <1>         mov     dx, [esi+LD_BPB+BPB_RootEntCnt]
 14992 00004274 F7E2                <1>         mul	edx
 14993                              <1> 	;mov	ecx, 511
 14994 00004276 66B9FF01            <1> 	mov	cx, 511
 14995 0000427A 01C8                <1> 	add	eax, ecx
 14996 0000427C 41                  <1> 	inc	ecx ; 512
 14997 0000427D F7F1                <1> 	div	ecx
 14998 0000427F 014668              <1> 	add	[esi+LD_DATABegin], eax
 14999 00004282 0FB74619            <1> 	movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 15000 00004286 6685C0              <1> 	test	ax, ax
 15001 00004289 7405                <1> 	jz	short loc_set_32bit_FAT_total_sectors
 15002                              <1> loc_set_16bit_FAT_total_sectors:
 15003 0000428B 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 15004 0000428E EB06                <1> 	jmp	short loc_set_hd_FAT_cluster_count
 15005                              <1> loc_set_32bit_FAT_total_sectors:
 15006 00004290 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
 15007 00004293 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 15008                              <1> loc_set_hd_FAT_cluster_count:
 15009 00004296 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
 15010 00004299 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
 15011 0000429C 29D0                <1> 	sub	eax, edx
 15012 0000429E 31D2                <1> 	xor	edx, edx ; 0
 15013 000042A0 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 15014 000042A4 F7F1                <1>         div	ecx 
 15015 000042A6 894678              <1> 	mov	[esi+LD_Clusters], eax
 15016                              <1> 	; Maximum Valid Cluster Number= EAX +1
 15017                              <1> 	; with 2 reserved clusters= EAX +2
 15018                              <1> loc_set_hd_FAT_fs_free_sectors:
 15019                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
 15020 000042A9 E859010000          <1> 	call	get_free_FAT_sectors
 15021 000042AE 7207                <1> 	jc	short loc_validate_hd_FAT_partition_retn
 15022 000042B0 894674              <1> 	mov	[esi+LD_FreeSectors], eax
 15023 000042B3 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
 15024                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
 15025                              <1> 	;add	cl, 'A'
 15026                              <1> 	;mov	[esi+LD_FS_Name], cl
 15027                              <1> 
 15028                              <1> loc_validate_hd_FAT_partition_retn:         
 15029 000042B7 C3                  <1> 	retn
 15030                              <1> 
 15031                              <1> validate_hd_fs_partition:
 15032                              <1> 	; 13/02/2016
 15033                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15034                              <1> 	; 29/01/2011
 15035                              <1> 	; 23/07/2011
 15036                              <1> 	; Input
 15037                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 15038                              <1> 	;   ESI = PartitionTable offset
 15039                              <1> 	;   byte [Last_DOS_DiskNo]
 15040                              <1> 	; Output
 15041                              <1> 	;  cf=0 -> Validated
 15042                              <1> 	;   ESI = Logical dos drv desc. table
 15043                              <1> 	;   EBX = Singlix FS boot sector buffer
 15044                              <1> 	;   byte [Last_DOS_DiskNo]
 15045                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
 15046                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 15047                              <1> 
 15048                              <1> 	;mov	esi, PartitionTable
 15049 000042B8 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
 15050 000042BB 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
 15051 000042BE 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15052                              <1> loc_set_valid_hd_fs_partition_params:
 15053 000042C0 FE05[F5B40000]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
 15054 000042C6 30C0                <1> 	xor	al, al ; mov al, 0
 15055                              <1> 	;mov	[drv], dl
 15056 000042C8 29DB                <1> 	sub	ebx, ebx ; 0
 15057 000042CA 8A3D[F5B40000]      <1> 	mov	bh, [Last_DOS_DiskNo] 
 15058 000042D0 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 15059 000042D6 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 15060 000042DA 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
 15061                              <1> 	;mov	[ebx+LD_FATType], al ; 0
 15062                              <1> 	;mov	[ebx+LD_FSType], ah
 15063 000042DD 66894303            <1> 	mov	[ebx+LD_FATType], ax
 15064                              <1> 	;mov	eax, [esi+ptStartSector]
 15065                              <1> 	;mov	[ebx+LD_StartSector], eax
 15066                              <1> loc_hd_fs_logical_drv_init:
 15067 000042E1 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
 15068                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 15069 000042E3 A0[42CB0000]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
 15070 000042E8 884305              <1> 	mov	[ebx+LD_LBAYes], al
 15071 000042EB 89DE                <1> 	mov	esi, ebx
 15072 000042ED BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer addressh
 15073 000042F2 08C0                <1> 	or	al, al
 15074 000042F4 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
 15075                              <1> loc_hd_fs_drv_init_load_bs_chs:
 15076 000042F6 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 15077 000042F9 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 15078 000042FD 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 15079                              <1> 	;mov	ebx, DOSBootSectorBuff
 15080 00004301 E8C6E5FFFF          <1> 	call	int13h
 15081 00004306 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
 15082                              <1> loc_validate_hd_fs_partition_err_retn:
 15083 00004308 C3                  <1> 	retn
 15084                              <1> loc_validate_hd_fs_partition_stc_retn:
 15085 00004309 F9                  <1> 	stc
 15086 0000430A C3                  <1> 	retn
 15087                              <1> loc_hd_fs_drv_init_load_bs_lba:
 15088                              <1> 	; DL = Physical drive number
 15089                              <1> 	;mov	esi, ebx
 15090 0000430B 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
 15091                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 15092                              <1> 	; LBA read/write (with private LBA function) 
 15093                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 15094                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 15095 0000430E B41B                <1> 	mov	ah, 1Bh ; LBA read
 15096 00004310 B001                <1> 	mov	al, 1 ; sector count
 15097 00004312 E8B5E5FFFF          <1> 	call	int13h
 15098 00004317 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
 15099                              <1> loc_hd_drv_fs_boot_validation:
 15100                              <1> 	;mov	esi, DOSBootSectorBuff
 15101 00004319 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
 15102 0000431B 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 15103 00004324 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15104                              <1>         ;
 15105                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
 15106 00004326 66817E035346        <1> 	cmp	word [esi+bs_FS_Identifier], 'SF'
 15107 0000432C 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15108                              <1>         ;'A1h' check is not necessary
 15109                              <1> 	;  if 'FS' check is passed as OK/Yes.
 15110 0000432E 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
 15111 00004332 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15112                              <1> 	;
 15113 00004334 89EF                <1> 	mov	edi, ebp ; 10/01/2016
 15114                              <1> 	;
 15115 00004336 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
 15116 00004339 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 15117                              <1> 	;
 15118                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 15119 0000433C 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 15120 0000433F 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
 15121                              <1> 	;
 15122 00004342 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
 15123 00004345 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
 15124                              <1> 	;
 15125 00004348 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 15126 0000434C 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 15127 00004350 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 15128 00004353 6698                <1> 	cbw
 15129 00004355 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 15130 00004359 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 15131                              <1> 	;cbw
 15132 0000435C 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 15133                              <1> 	;
 15134 00004360 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 15135 00004363 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 15136 00004366 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
 15137 00004369 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
 15138 0000436C 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 15139 0000436F 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 15140 00004372 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 15141 00004375 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 15142 00004378 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
 15143 0000437B 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 15144                              <1> 	;
 15145 0000437E 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
 15146 00004380 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 15147 00004383 89FE                <1> 	mov	esi, edi
 15148                              <1> mread_hd_fs_MAT_sector:
 15149                              <1>        ;mov	ebx, DOSBootSectorBuff
 15150 00004385 B901000000          <1> 	mov	ecx, 1
 15151 0000438A E82D6E0000          <1> 	call	disk_read
 15152 0000438F 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
 15153                              <1> 	; EDI will not be changed
 15154 00004391 89DE                <1> 	mov	esi, ebx
 15155                              <1> use_hdfs_mat_sector_params:
 15156 00004393 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 15157 00004396 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 15158 00004399 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 15159 0000439C 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 15160 0000439F 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
 15161 000043A2 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
 15162 000043A5 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 15163 000043A8 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 15164 000043AB 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
 15165 000043AE 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 15166 000043B1 89FE                <1> 	mov	esi, edi   
 15167                              <1> read_hd_fs_RDT_sector:
 15168 000043B3 BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff
 15169                              <1> 	;mov	ecx, 1
 15170 000043B8 B101                <1> 	mov	cl, 1
 15171 000043BA E8FD6D0000          <1> 	call	disk_read
 15172 000043BF 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
 15173                              <1> 	; EDI will not be changed
 15174 000043C1 89DE                <1> 	mov	esi, ebx
 15175                              <1> use_hdfs_RDT_sector_params:
 15176 000043C3 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 15177 000043C6 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 15178 000043C9 57                  <1> 	push	edi
 15179                              <1> 	;mov	ecx, 16
 15180 000043CA B110                <1> 	mov	cl, 16
 15181 000043CC 83C640              <1> 	add	esi, FS_RDT_VolumeName
 15182 000043CF 83C72C              <1> 	add	edi, LD_FS_VolumeName
 15183 000043D2 F3A5                <1> 	rep	movsd ; 64 bytes
 15184 000043D4 5E                  <1> 	pop	esi
 15185                              <1> 		; Volume Name Reset
 15186 000043D5 C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
 15187                              <1> 	;
 15188                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
 15189                              <1> 	;add	cl, 'A'
 15190                              <1> 	;mov	[esi+LD_FS_Name], cl
 15191                              <1> 
 15192                              <1> loc_validate_hd_fs_partition_retn:
 15193 000043D9 C3                  <1> 	retn
 15194                              <1> 
 15195                              <1> load_masterboot:
 15196                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15197                              <1> 	; 2005 - 2011
 15198                              <1> 	; input -> DL = drive number
 15199 000043DA B40D                <1> 	mov	ah, 0Dh ; Alternate disk reset
 15200 000043DC E8EBE4FFFF          <1> 	call	int13h
 15201 000043E1 7301                <1> 	jnc	short pass_reset_error
 15202                              <1> harddisk_error:
 15203 000043E3 C3                  <1>   	retn
 15204                              <1> pass_reset_error:
 15205 000043E4 BB[42C70000]        <1> 	mov	ebx, MasterBootBuff
 15206 000043E9 66B80102            <1> 	mov	ax, 0201h
 15207 000043ED 66B90100            <1> 	mov	cx, 1
 15208 000043F1 30F6                <1> 	xor	dh, dh
 15209 000043F3 E8D4E4FFFF          <1>  	call	int13h
 15210 000043F8 72E9                <1> 	jc	short harddisk_error
 15211                              <1> 	;
 15212 000043FA 66813D[40C90000]55- <1> 	cmp	word [MBIDCode], 0AA55h
 15213 00004402 AA                  <1>
 15214 00004403 7401                <1> 	je	short load_masterboot_ok
 15215 00004405 F9                  <1> 	stc
 15216                              <1> load_masterboot_ok:
 15217 00004406 C3                  <1> 	retn
 15218                              <1> 
 15219                              <1> get_free_FAT_sectors:
 15220                              <1> 	; 29/02/2016
 15221                              <1> 	; 13/02/2016
 15222                              <1> 	; 04/02/2016
 15223                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 15224                              <1> 	; 11/07/2010
 15225                              <1> 	; 21/06/2009
 15226                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
 15227                              <1> 	; OUTPUT: STC => Error
 15228                              <1>         ;	cf = 0 and EAX = Free FAT sectors
 15229                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
 15230                              <1> 
 15231 00004407 31C0                <1> 	xor	eax, eax
 15232                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
 15233                              <1> 	
 15234 00004409 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 15235 0000440D 7650                <1> 	jna	short loc_gfc_get_fat_free_clusters
 15236                              <1> 
 15237                              <1> 	; 29/02/2016
 15238 0000440F 48                  <1> 	dec	eax ; 0FFFFFFFFh
 15239 00004410 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
 15240 00004413 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
 15241 00004416 40                  <1> 	inc	eax ; 0
 15242                              <1> 	;
 15243 00004417 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
 15244 0000441B 03466C              <1> 	add	eax, [esi+LD_StartSector]
 15245                              <1> 
 15246 0000441E BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff
 15247 00004423 B901000000          <1> 	mov	ecx, 1
 15248 00004428 E88F6D0000          <1>  	call	disk_read
 15249 0000442D 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
 15250                              <1> retn_gfc_get_fsinfo_sec:
 15251 0000442F C3                  <1> 	retn
 15252                              <1> 
 15253                              <1> loc_gfc_check_fsinfo_signs:
 15254 00004430 BB[55CB0000]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
 15255 00004435 813B52526141        <1>         cmp     dword [ebx], 41615252h
 15256 0000443B 7520                <1> 	jne	short retn_gfc_get_fsinfo_stc
 15257                              <1> 	;add	ebx, 484
 15258                              <1> 	;cmp	dword [ebx], 61417272h
 15259 0000443D 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 15260 00004446 61                  <1>
 15261 00004447 7514                <1> 	jne	short retn_gfc_get_fsinfo_stc
 15262                              <1> 	;add	ebx, 4
 15263                              <1> 	;mov	eax, [ebx]
 15264 00004449 8B83E8010000        <1> 	mov	eax, [ebx+488]
 15265                              <1> 	; 29/02/2016
 15266 0000444F 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
 15267 00004452 8B93EC010000        <1> 	mov	edx,  [ebx+492] 
 15268 00004458 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster
 15269                              <1> 	;
 15270 0000445B EB12                <1> 	jmp	short retn_from_get_free_fat32_clusters
 15271                              <1> 
 15272                              <1> retn_gfc_get_fsinfo_stc:
 15273 0000445D F9                  <1> 	stc
 15274 0000445E C3                  <1> 	retn
 15275                              <1> 
 15276                              <1> loc_gfc_get_fat_free_clusters:
 15277                              <1> 	;mov	eax, 2
 15278 0000445F B002                <1> 	mov	al, 2
 15279                              <1> 	;mov	[FAT_CurrentCluster], eax
 15280                              <1> loc_gfc_loop_get_next_cluster:
 15281 00004461 E8CA4C0000          <1> 	call	get_next_cluster
 15282 00004466 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
 15283 00004468 21C0                <1> 	and	eax, eax
 15284 0000446A 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
 15285                              <1>  
 15286                              <1> retn_from_get_free_fat_clusters:
 15287 0000446C 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
 15288                              <1> retn_from_get_free_fat32_clusters:
 15289 0000446F 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 15290 00004473 F7E3                <1>       	mul	ebx
 15291                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
 15292                              <1> retn_get_free_sectors_calc:
 15293 00004475 C3                  <1> 	retn
 15294                              <1> 
 15295                              <1> loc_gfc_free_fat_clusters_cont:
 15296 00004476 09C0                <1> 	or	eax, eax
 15297 00004478 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
 15298 0000447A FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
 15299                              <1>    
 15300                              <1> loc_gfc_pass_inc_free_cluster_count:
 15301                              <1> 	;mov	eax, [FAT_CurrentCluster]
 15302 0000447D 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
 15303 0000447F 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
 15304 00004482 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
 15305 00004484 40                  <1> 	inc	eax
 15306                              <1> 	;mov	[FAT_CurrentCluster], eax
 15307 00004485 EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
 15308                              <1> 
 15309                              <1> floppy_drv_init:
 15310                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15311                              <1> 	; 24/07/2011
 15312                              <1> 	; 04/07/2009
 15313                              <1> 	; INPUT ->
 15314                              <1> 	;	DL = Drive number (0,1)
 15315                              <1> 	; OUTPUT ->
 15316                              <1> 	;	BL = drive name
 15317                              <1> 	;	BH = drive number
 15318                              <1> 	;	ESI = Logical DOS drv description table
 15319                              <1> 	;	EAX = Volume serial number
 15320                              <1>  
 15321 00004487 BE[4EBF0000]        <1> 	mov	esi, fd0_type ; 10/01/2016
 15322 0000448C BF00010900          <1> 	mov	edi, Logical_DOSDisks
 15323 00004491 08D2                <1> 	or	dl, dl
 15324 00004493 7407                <1> 	jz	short loc_drv_init_fd0_fd1
 15325 00004495 81C700010000        <1> 	add	edi, 100h
 15326 0000449B 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
 15327                              <1> loc_drv_init_fd0_fd1:
 15328 0000449C C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
 15329 000044A0 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
 15330                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
 15331 000044A3 7221                <1> 	jb	short read_fd_boot_sector_retn
 15332 000044A5 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
 15333                              <1> read_fd_boot_sector:
 15334 000044A8 30F6                <1> 	xor	dh, dh
 15335 000044AA B904000000          <1> 	mov	ecx, 4 ; Retry Count
 15336                              <1> read_fd_boot_sector_again:
 15337 000044AF 51                  <1> 	push 	ecx
 15338                              <1> 	;mov	cx, 1
 15339 000044B0 B101                <1> 	mov	cl, 1
 15340 000044B2 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 15341 000044B6 BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff
 15342 000044BB E80CE4FFFF          <1> 	call	int13h
 15343 000044C0 59                  <1> 	pop	ecx
 15344 000044C1 7304                <1> 	jnc	short use_fd_boot_sector_params
 15345 000044C3 E2EA                <1> 	loop	read_fd_boot_sector_again
 15346                              <1> 
 15347                              <1> read_fd_boot_sector_stc_retn:
 15348 000044C5 F9                  <1> 	stc
 15349                              <1> read_fd_boot_sector_retn:
 15350 000044C6 C3                  <1> 	retn
 15351                              <1> 
 15352                              <1> use_fd_boot_sector_params:
 15353                              <1> 	;mov	esi, DOSBootSectorBuff
 15354 000044C7 89DE                <1> 	mov	esi, ebx
 15355 000044C9 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 15356 000044D2 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
 15357 000044D4 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
 15358 000044DA 0F85A2000000        <1>         jne     use_fd_fatfs_boot_sector_params
 15359                              <1> 	;
 15360 000044E0 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
 15361 000044E3 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 15362                              <1> 	;
 15363                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 15364 000044E6 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 15365 000044E9 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
 15366                              <1> 	;
 15367 000044EC 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
 15368 000044EF 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
 15369 000044F2 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 15370 000044F6 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 15371 000044FA 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 15372 000044FD 6698                <1> 	cbw
 15373 000044FF 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 15374 00004503 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 15375                              <1> 	;cbw
 15376 00004506 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 15377                              <1> 	;
 15378 0000450A 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 15379 0000450D 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 15380 00004510 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
 15381 00004513 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
 15382 00004516 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 15383 00004519 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 15384 0000451C 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 15385 0000451F 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 15386 00004522 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
 15387 00004525 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 15388                              <1> 	;		
 15389 00004528 89FE                <1> 	mov	esi, edi
 15390 0000452A 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
 15391                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
 15392                              <1> read_fd_MAT_sector_again:
 15393                              <1> 	;mov	ebx, DOSBootSectorBuff
 15394                              <1> 	;mov	ecx, 1
 15395 0000452D B101                <1> 	mov	cl, 1
 15396 0000452F E88E6C0000          <1> 	call	chs_read
 15397 00004534 89DE                <1> 	mov	esi, ebx
 15398 00004536 7301                <1> 	jnc	short use_fdfs_mat_sector_params
 15399                              <1> 	;jmp	short read_fd_boot_sector_retn
 15400 00004538 C3                  <1> 	retn
 15401                              <1> use_fdfs_mat_sector_params:
 15402 00004539 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 15403 0000453C 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 15404 0000453F 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 15405 00004542 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 15406 00004545 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
 15407 00004548 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
 15408 0000454B 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 15409 0000454E 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 15410                              <1> 	;
 15411 00004551 89FE                <1> 	mov	esi, edi
 15412 00004553 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
 15413                              <1> read_fd_RDT_sector_again:
 15414                              <1> 	;mov	ebx, DOSBootSectorBuff
 15415                              <1> 	;mov	cx, 1
 15416 00004556 B101                <1> 	mov	cl, 1
 15417 00004558 E8656C0000          <1> 	call	chs_read
 15418 0000455D 89DE                <1> 	mov	esi, ebx
 15419 0000455F 7220                <1> 	jc	short read_fd_RDT_sector_retn
 15420                              <1> use_fdfs_RDT_sector_params:
 15421 00004561 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 15422 00004564 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 15423 00004567 57                  <1> 	push	edi
 15424                              <1> 	;mov	ecx, 16
 15425 00004568 B110                <1> 	mov	cl, 16	
 15426 0000456A 83C640              <1> 	add	esi, FS_RDT_VolumeName
 15427 0000456D 83C72C              <1> 	add	edi, LD_FS_VolumeName
 15428 00004570 F3A5                <1> 	rep	movsd ; 64 bytes
 15429 00004572 5E                  <1> 	pop	esi
 15430 00004573 C6460300            <1> 	mov	byte [esi+LD_FATType], 0
 15431 00004577 C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h  
 15432 0000457B E9AA000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
 15433                              <1> 
 15434                              <1> read_fd_RDT_sector_stc_retn:
 15435 00004580 F9                  <1> 	stc
 15436                              <1> read_fd_RDT_sector_retn:
 15437 00004581 C3                  <1> 	retn
 15438                              <1> 
 15439                              <1> use_fd_fatfs_boot_sector_params:
 15440 00004582 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 15441 00004586 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
 15442 00004588 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
 15443 0000458C 72F3                <1> 	jb	short read_fd_RDT_sector_retn
 15444 0000458E 57                  <1> 	push	edi
 15445 0000458F 83C706              <1> 	add	edi, LD_BPB
 15446                              <1> 	;mov	ecx, 16
 15447 00004592 B110                <1> 	mov	cl, 16
 15448 00004594 F3A5                <1> 	rep	movsd ; 64 bytes 
 15449 00004596 5E                  <1> 	pop	esi
 15450 00004597 31C0                <1> 	xor	eax, eax
 15451 00004599 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
 15452 0000459C 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
 15453 000045A0 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs] 
 15454 000045A3 F7E1                <1>   	mul	ecx
 15455                              <1> 	; edx = 0 !
 15456 000045A5 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
 15457 000045A9 66895660            <1> 	mov	[esi+LD_FATBegin], dx
 15458                              <1> 	;add	eax, edx
 15459 000045AD 6601D0              <1> 	add	ax, dx
 15460 000045B0 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 15461 000045B3 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 15462 000045B6 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
 15463                              <1> 	;shl	edx, 5 ; * 32 (Size of a directory entry)
 15464 000045BA 66C1E205            <1> 	shl	dx, 5
 15465                              <1> 	;add	edx, 511
 15466 000045BE 6681C2FF01          <1> 	add	dx, 511
 15467                              <1> 	;shr	edx, 9 ; edx = ((edx*32)+511) / 512
 15468 000045C3 66C1EA09            <1> 	shr	dx, 9
 15469 000045C7 015668              <1> 	add 	[esi+LD_DATABegin], edx
 15470                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 15471 000045CA 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
 15472 000045CE 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 15473 000045D1 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
 15474                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 15475 000045D4 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]  
 15476 000045D7 80F901              <1> 	cmp	cl, 1
 15477 000045DA 7605                <1> 	jna	short save_fd_fatfs_cluster_count
 15478                              <1> 	;sub	edx, edx
 15479 000045DC 6629D2              <1> 	sub	dx, dx ; 0
 15480 000045DF F7F1                <1> 	div	ecx
 15481                              <1> save_fd_fatfs_cluster_count:
 15482 000045E1 894678              <1> 	mov	[esi+LD_Clusters], eax
 15483                              <1> 
 15484                              <1>       ; Maximum Valid Cluster Number = EAX +1
 15485                              <1>       ; with 2 reserved clusters= EAX +2
 15486                              <1>  
 15487                              <1> reset_FAT_buffer_decriptors:
 15488 000045E4 29C0                <1> 	sub	eax, eax ; 0  
 15489 000045E6 A2[59CD0000]        <1> 	mov	[FAT_BuffValidData], al ; 0
 15490 000045EB A2[5ACD0000]        <1> 	mov	[FAT_BuffDrvName], al ; 0
 15491 000045F0 A3[5DCD0000]        <1> 	mov	[FAT_BuffSector], eax ; 0
 15492                              <1> 
 15493                              <1> read_fd_FAT_sectors:
 15494 000045F5 BB001C0900          <1>   	mov	ebx, FAT_Buffer
 15495 000045FA 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
 15496                              <1> 	;mov	ecx, 3
 15497 000045FE B103                <1> 	mov	cl, 3 ; 3 sectors
 15498 00004600 E8BD6B0000          <1> 	call	chs_read
 15499 00004605 7240                <1> 	jc	short read_fd_FAT_sectors_retn
 15500                              <1> use_fd_FAT_sectors:
 15501 00004607 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
 15502 0000460A 0441                <1> 	add	al, 'A' 
 15503 0000460C A2[5ACD0000]        <1> 	mov	[FAT_BuffDrvName], al 
 15504 00004611 C605[59CD0000]01    <1>  	mov	byte [FAT_BuffValidData], 1
 15505 00004618 E82B000000          <1> 	call	fd_init_calculate_free_clusters
 15506 0000461D 7228                <1> 	jc	short read_fd_FAT_sectors_retn
 15507                              <1>   
 15508                              <1> loc_use_fd_boot_sector_params_FAT:
 15509 0000461F C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
 15510 00004623 C6460401            <1> 	mov	byte [esi+LD_FSType], 1
 15511 00004627 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
 15512                              <1> loc_cont_use_fd_boot_sector_params:
 15513 0000462A 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
 15514 0000462D 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
 15515 00004630 88FB                <1> 	mov	bl, bh
 15516 00004632 80C341              <1> 	add	bl, 'A'
 15517 00004635 881E                <1> 	mov	byte [esi+LD_Name], bl
 15518 00004637 C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
 15519 0000463B C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
 15520 0000463F C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
 15521 00004643 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
 15522                              <1> 
 15523                              <1> read_fd_FAT_sectors_retn:
 15524 00004647 C3                  <1> 	retn   
 15525                              <1> 
 15526                              <1> fd_init_calculate_free_clusters:
 15527                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15528                              <1> 	; 04/07/2009
 15529                              <1> 	; INPUT ->
 15530                              <1> 	;     ESI = Logical DOS drive description table address
 15531                              <1> 	; OUTPUT ->
 15532                              <1> 	;    [ESI+LD_FreeSectors] will be set
 15533                              <1> 	
 15534 00004648 29C0                <1> 	sub	eax, eax
 15535 0000464A 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
 15536 0000464D B002                <1> 	mov	al, 2 ; eax = 2
 15537                              <1> 
 15538                              <1> fd_init_loop_get_next_cluster:
 15539 0000464F E830000000          <1> 	call	fd_init_get_next_cluster
 15540 00004654 722D                <1> 	jc	short fd_init_calculate_free_clusters_retn
 15541                              <1> 
 15542                              <1> fd_init_free_fat_clusters:
 15543                              <1> 	;cmp 	eax, 0
 15544                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
 15545                              <1> 	;and	eax, eax
 15546                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
 15547 00004656 6621C0              <1> 	and	ax, ax
 15548 00004659 7504                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
 15549                              <1> 	;inc	dword [esi+LD_FreeSectors]
 15550 0000465B 66FF4674            <1>         inc	word [esi+LD_FreeSectors]
 15551                              <1>     
 15552                              <1> fd_init_pass_inc_free_cluster_count:
 15553                              <1>   	;mov	eax, [FAT_CurrentCluster]
 15554 0000465F 66A1[55CD0000]      <1> 	mov	ax, [FAT_CurrentCluster]
 15555                              <1> 	;cmp	eax, [esi+LD_Clusters]
 15556 00004665 663B4678            <1> 	cmp	ax, [esi+LD_Clusters]
 15557 00004669 7704                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
 15558                              <1> 	;inc	eax
 15559 0000466B 6640                <1> 	inc	ax
 15560 0000466D EBE0                <1> 	jmp	short fd_init_loop_get_next_cluster
 15561                              <1> 
 15562                              <1> retn_from_fd_init_calculate_free_clusters:
 15563 0000466F 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
 15564 00004672 3C01                <1>   	cmp	al, 1
 15565 00004674 760D                <1> 	jna	short fd_init_calculate_free_clusters_retn
 15566                              <1> 	;movzx	eax, al
 15567 00004676 6698                <1> 	cbw
 15568                              <1> 	;mov	ecx, [esi+LD_FreeSectors]
 15569 00004678 668B4E74            <1> 	mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
 15570                              <1>   	;mul	ecx
 15571 0000467C 66F7E1              <1> 	mul	cx
 15572                              <1> 	;mov	[esi+LD_FreeSectors], eax
 15573 0000467F 66894674            <1> 	mov	[esi+LD_FreeSectors], ax
 15574                              <1> fd_init_calculate_free_clusters_retn:
 15575 00004683 C3                  <1> 	retn
 15576                              <1> 
 15577                              <1> fd_init_get_next_cluster:
 15578                              <1> 	; 04/02/2016
 15579                              <1> 	; 02/02/2016
 15580                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15581                              <1> 	; 04/07/2009
 15582                              <1> 	; INPUT ->
 15583                              <1> 	;    EAX = Current cluster
 15584                              <1> 	;    ESI = Logical DOS drive description table address
 15585                              <1> 	;    EDX = 0
 15586                              <1> 	; OUTPUT ->
 15587                              <1> 	;    EAX = Next cluster
 15588                              <1> 
 15589 00004684 A3[55CD0000]        <1> 	mov	[FAT_CurrentCluster], eax
 15590                              <1> fd_init_get_next_cluster_readnext:
 15591 00004689 29D2                <1> 	sub	edx, edx ; 0
 15592 0000468B BB00040000          <1>   	mov	ebx, 1024 ; 400h
 15593 00004690 F7F3                <1>   	div	ebx
 15594                              <1>   	; EAX = Count of 3 FAT sectors
 15595                              <1>   	; EDX = Buffer entry index
 15596 00004692 89C1                <1> 	mov	ecx, eax
 15597                              <1> 	;mov	eax, 3
 15598 00004694 B003                <1> 	mov	al, 3
 15599 00004696 F7E2                <1> 	mul	edx ; Multiply by 3
 15600 00004698 66D1E8              <1> 	shr	ax, 1 ; Divide by 2
 15601 0000469B 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
 15602 0000469D 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 15603 000046A3 89C8                <1> 	mov	eax, ecx
 15604                              <1> 	;mov	edx, 3
 15605 000046A5 66BA0300            <1> 	mov	dx, 3
 15606 000046A9 F7E2                <1> 	mul	edx 
 15607                              <1>   	; EAX = FAT Beginning Sector
 15608                              <1> 	; EDX = 0
 15609 000046AB 8A0E                <1> 	mov	cl, [esi+LD_Name]
 15610                              <1> 	;cmp	byte [FAT_BuffValidData], 0
 15611                              <1> 	;jna	short fd_init_load_FAT_sectors0
 15612 000046AD 3A0D[5ACD0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 15613 000046B3 751E                <1> 	jne	short fd_init_load_FAT_sectors0
 15614 000046B5 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 15615 000046BB 751C                <1> 	jne	short fd_init_load_FAT_sectors1
 15616                              <1> 	;mov	eax, [FAT_CurrentCluster]
 15617 000046BD A0[55CD0000]        <1> 	mov	al, [FAT_CurrentCluster]
 15618                              <1> 	;shr	eax, 1
 15619 000046C2 D0E8                <1> 	shr	al, 1
 15620 000046C4 668B03              <1> 	mov	ax, [ebx]
 15621 000046C7 7306                <1>   	jnc	short fd_init_gnc_even
 15622 000046C9 66C1E804            <1> 	shr	ax, 4
 15623                              <1> fd_init_gnc_clc_retn:
 15624 000046CD F8                  <1> 	clc
 15625 000046CE C3                  <1> 	retn
 15626                              <1> 
 15627                              <1> fd_init_gnc_even:
 15628 000046CF 80E40F              <1> 	and	ah, 0Fh
 15629 000046D2 C3                  <1> 	retn
 15630                              <1> 
 15631                              <1> fd_init_load_FAT_sectors0:
 15632 000046D3 880D[5ACD0000]      <1> 	mov 	[FAT_BuffDrvName], cl
 15633                              <1> fd_init_load_FAT_sectors1:
 15634 000046D9 C605[59CD0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15635 000046E0 A3[5DCD0000]        <1> 	mov	[FAT_BuffSector], eax
 15636 000046E5 034660              <1> 	add	eax, [esi+LD_FATBegin]
 15637 000046E8 BB001C0900          <1>  	mov	ebx, FAT_Buffer
 15638                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 15639 000046ED 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
 15640 000046F1 662B0D[5DCD0000]    <1> 	sub	cx, [FAT_BuffSector]
 15641                              <1>         ;cmp	ecx, 3
 15642 000046F8 6683F903            <1> 	cmp	cx, 3
 15643 000046FC 7605                <1> 	jna	short fdinit_pass_fix_sector_count_3
 15644                              <1> 	;mov	ecx, 3
 15645 000046FE B903000000          <1> 	mov	ecx, 3
 15646                              <1> fdinit_pass_fix_sector_count_3:  
 15647 00004703 E8BA6A0000          <1> 	call	chs_read
 15648 00004708 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
 15649 0000470A C605[59CD0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15650                              <1> 		; Drv not ready or read Error !
 15651 00004711 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
 15652                              <1> 	;xor	edx, edx
 15653 00004716 C3                  <1> 	retn
 15654                              <1> 
 15655                              <1> fd_init_FAT_sectors_no_load_error:
 15656 00004717 C605[59CD0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 15657 0000471E A1[55CD0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 15658 00004723 E961FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
 15659                              <1> 
 15660                              <1> get_FAT_volume_name:
 15661                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15662                              <1> 	; 12/09/2009
 15663                              <1> 	; INPUT ->
 15664                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
 15665                              <1> 	;       BL = 0
 15666                              <1> 	; OUTPUT ->
 15667                              <1> 	;	CF = 0 -> ESI = Volume name address
 15668                              <1> 	; 	CF = 1 -> Root volume name not found
 15669                              <1> 
 15670                              <1> 	;mov 	ah, 0FFh
 15671                              <1> 	;mov 	al, [Last_Dos_DiskNo]
 15672                              <1> 	;cmp 	al, bh
 15673                              <1> 	;jb     short loc_gfvn_dir_load_err
 15674                              <1> 
 15675 00004728 89DE                <1> 	mov	esi, ebx
 15676 0000472A 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
 15677 00004730 81C600010900        <1> 	add	esi, Logical_DOSDisks
 15678 00004736 8A06                <1> 	mov     al, [esi+LD_Name]
 15679 00004738 8A6603              <1> 	mov     ah, [esi+LD_FATType]
 15680 0000473B 80FC01              <1> 	cmp     ah, 1
 15681 0000473E 7210                <1> 	jb    	short loc_gfvn_dir_load_err
 15682 00004740 3C41                <1> 	cmp 	al, 'A'
 15683 00004742 720C                <1> 	jb      short loc_gfvn_dir_load_err
 15684 00004744 80FC02              <1> 	cmp 	ah, 2 
 15685 00004747 7708                <1> 	ja      short get_FAT32_root_cluster
 15686                              <1> 	
 15687 00004749 E83D4B0000          <1> 	call    load_FAT_root_directory
 15688 0000474E 730B                <1> 	jnc     short loc_get_volume_name
 15689                              <1> 
 15690                              <1> loc_gfvn_dir_load_err:
 15691 00004750 C3                  <1> 	retn
 15692                              <1> 
 15693                              <1> get_FAT32_root_cluster:
 15694 00004751 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 15695 00004754 E8BD4B0000          <1> 	call    load_FAT_sub_directory
 15696 00004759 7224                <1> 	jc	short loc_get_volume_name_retn
 15697                              <1> 
 15698                              <1> loc_get_volume_name:
 15699 0000475B BE00000800          <1>         mov     esi, Directory_Buffer
 15700 00004760 6631C9              <1> 	xor	cx, cx ; 0
 15701                              <1> check_root_volume_name:
 15702 00004763 8A06                <1> 	mov	al, [esi]
 15703 00004765 08C0                <1> 	or      al, al
 15704 00004767 7416                <1> 	jz      short loc_get_volume_name_retn
 15705 00004769 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
 15706 0000476D 7410                <1> 	je      short loc_get_volume_name_retn
 15707 0000476F 663B0D[6FCD0000]    <1> 	cmp     cx, [DirBuff_LastEntry]
 15708 00004776 7308                <1> 	jnb     short pass_check_root_volume_name
 15709 00004778 6641                <1> 	inc     cx
 15710 0000477A 83C620              <1> 	add     esi, 32
 15711 0000477D EBE4                <1> 	jmp     short check_root_volume_name
 15712                              <1> 
 15713                              <1> loc_get_volume_name_retn:
 15714 0000477F C3                  <1> 	retn
 15715                              <1>     
 15716                              <1> pass_check_root_volume_name:
 15717 00004780 803D[6BCD0000]03    <1> 	cmp	byte [DirBuff_FATType], 3
 15718 00004787 7230                <1> 	jb	short loc_get_volume_name_retn_xor
 15719                              <1> 
 15720 00004789 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 15721 0000478E BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15722 00004793 31C0                <1> 	xor	eax, eax
 15723 00004795 8A25[6ACD0000]      <1> 	mov	ah, [DirBuff_DRV]
 15724 0000479B 80EC41              <1> 	sub	ah, 'A' 
 15725 0000479E 01C6                <1> 	add	esi, eax
 15726 000047A0 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 15727 000047A5 E886490000          <1> 	call	get_next_cluster
 15728 000047AA 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
 15729                              <1>   	
 15730 000047AC 83F801              <1> 	cmp     eax, 1
 15731 000047AF F5                  <1> 	cmc
 15732 000047B0 C3                  <1> 	retn
 15733                              <1>   
 15734                              <1> loc_gfvn_load_FAT32_dir_cluster:
 15735 000047B1 E8604B0000          <1> 	call	load_FAT_sub_directory
 15736 000047B6 73A3                <1> 	jnc	short loc_get_volume_name
 15737 000047B8 C3                  <1> 	retn
 15738                              <1> 
 15739                              <1> loc_get_volume_name_retn_xor:
 15740 000047B9 31C0                <1> 	xor 	eax, eax
 15741 000047BB C3                  <1> 	retn
 15742                              <1> 
 15743                              <1> get_media_change_status:
 15744                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15745                              <1> 	; 09/09/2009
 15746                              <1> 	; INPUT:
 15747                              <1> 	;     DL = Drive number (physical)
 15748                              <1> 	; OUTPUT: clc & AH = 6 media changed
 15749                              <1> 	;     clc & AH = 0 media not changed         
 15750                              <1> 	;     stc -> Drive not ready or an error 
 15751                              <1>   
 15752 000047BC B416                <1> 	mov	ah, 16h
 15753 000047BE E809E1FFFF          <1>   	call	int13h
 15754 000047C3 80FC06              <1> 	cmp	ah, 06h
 15755 000047C6 7405                <1> 	je	short loc_gmc_status_retn
 15756 000047C8 08E4                <1> 	or	ah, ah
 15757 000047CA 7401                <1> 	jz	short loc_gmc_status_retn
 15758                              <1> loc_gmc_status_stc_retn:    
 15759 000047CC F9                  <1> 	stc
 15760                              <1> loc_gmc_status_retn:
 15761 000047CD C3                  <1> 	retn
 15762                                  %include 'trdosk3.s' ; 06/01/2016
 15763                              <1> ; ****************************************************************************
 15764                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk3.s
 15765                              <1> ; ----------------------------------------------------------------------------
 15766                              <1> ; Last Update: 14/04/2016
 15767                              <1> ; ----------------------------------------------------------------------------
 15768                              <1> ; Beginning: 06/01/2016
 15769                              <1> ; ----------------------------------------------------------------------------
 15770                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 15771                              <1> ; ----------------------------------------------------------------------------
 15772                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 15773                              <1> ; MAINPROG.ASM (09/11/2011)
 15774                              <1> ; ****************************************************************************
 15775                              <1> ; MAINPROG.ASM [ TRDOS KERNEL - COMMAND EXECUTER SECTION - MAIN PROGRAM ]
 15776                              <1> ; (c) 2004-2011  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/11/2011
 15777                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ] Last Update: 09/11/2011
 15778                              <1> ; DIR.ASM [ DIRECTORY FUNCTIONS ] Last Update: 09/10/2011
 15779                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 15780                              <1> 
 15781                              <1> change_current_drive:
 15782                              <1> 	; 02/02/2016
 15783                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15784                              <1> 	; 18/08/2011
 15785                              <1> 	; 09/09/2009
 15786                              <1> 	; INPUT:
 15787                              <1> 	;   DL = Logical DOS Drive Number
 15788                              <1> 	; OUTPUT:
 15789                              <1> 	;  cf=1 -> Not successful
 15790                              <1> 	;   EAX = Error code
 15791                              <1> 	;  cf=0 ->
 15792                              <1> 	;   EAX = 0 (successful)
 15793                              <1> 
 15794 000047CE 31DB                <1> 	xor	ebx, ebx
 15795 000047D0 88D7                <1> 	mov	bh, dl
 15796                              <1> 
 15797                              <1> 	;cmp	dl, 1
 15798                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
 15799                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
 15800                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
 15801                              <1> 
 15802                              <1> loc_ccdrv_initial_media_change_check:
 15803 000047D2 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15804 000047D7 01DE                <1> 	add	esi, ebx
 15805                              <1> loc_ccdrv_dos_drive_name_check:
 15806 000047D9 80FA02              <1> 	cmp	dl, 2
 15807 000047DC 720F                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
 15808                              <1> 
 15809 000047DE 8A06                <1> 	mov	al, [esi+LD_Name]
 15810 000047E0 2C41                <1> 	sub	al, 'A'
 15811 000047E2 38D0                <1> 	cmp	al, dl
 15812 000047E4 7407                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
 15813                              <1> 
 15814                              <1> loc_ccdrv_drive_not_ready_err:
 15815 000047E6 B815000000          <1> 	mov	eax, 15h ; Drive not ready
 15816                              <1> loc_change_current_drive_stc_retn:
 15817 000047EB F9                  <1> 	stc
 15818 000047EC C3                  <1> 	retn  
 15819                              <1> 
 15820                              <1> loc_ccdrv_dos_drive_name_check_ok:
 15821 000047ED 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
 15822 000047F0 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
 15823 000047F3 7450                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
 15824                              <1> 
 15825 000047F5 80FA01              <1> 	cmp	dl, 1
 15826 000047F8 7778                <1> 	ja	short loc_gmcs_init_drv_hd
 15827                              <1> 
 15828                              <1> loc_gmcs_init_drv_fd:
 15829 000047FA 08E4                <1> 	or	ah, ah 
 15830                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
 15831 000047FC 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
 15832                              <1> 
 15833 000047FE E8B9FFFFFF          <1> 	call	get_media_change_status
 15834 00004803 72E1                <1> 	jc	short loc_ccdrv_drive_not_ready_err
 15835                              <1> 
 15836 00004805 20E4                <1> 	and	ah, ah
 15837 00004807 7471                <1> 	jz	short loc_change_current_drv3
 15838                              <1> 
 15839 00004809 80F406              <1> 	xor	ah, 6
 15840 0000480C 75D8                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
 15841                              <1> 
 15842                              <1> loc_ccdrv_call_fd_init_check_vol_id:
 15843 0000480E E8410A0000          <1> 	call	get_volume_serial_number
 15844 00004813 7308                <1> 	jnc	short loc_ccdrv_check_vol_serial
 15845                              <1> 
 15846                              <1> loc_ccdrv_call_fd_init:
 15847 00004815 E86DFCFFFF          <1> 	call	floppy_drv_init
 15848 0000481A 7315                <1> 	jnc	short loc_reset_drv_fd_current_dir
 15849                              <1> 
 15850                              <1> loc_ccdrv_fdinit_fail_retn:
 15851 0000481C C3                  <1> 	retn
 15852                              <1> 
 15853                              <1> loc_ccdrv_check_vol_serial:
 15854 0000481D A3[38C50000]        <1> 	mov	[Current_VolSerial], eax
 15855                              <1> 	;mov	dl, bh
 15856 00004822 E860FCFFFF          <1> 	call	floppy_drv_init
 15857 00004827 72F3                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
 15858                              <1> 
 15859 00004829 3B05[38C50000]      <1> 	cmp	eax, [Current_VolSerial]
 15860 0000482F 7445                <1> 	je	short loc_change_current_drv2
 15861                              <1> 
 15862                              <1> loc_reset_drv_fd_current_dir:
 15863 00004831 31C0                <1> 	xor	eax, eax              
 15864 00004833 88467F              <1>         mov	[esi+LD_CDirLevel], al
 15865 00004836 89F7                <1> 	mov	edi, esi
 15866 00004838 81C780000000        <1> 	add	edi, LD_CurrentDirectory
 15867 0000483E B920000000          <1> 	mov	ecx, 32
 15868 00004843 F3AB                <1> 	rep	stosd   
 15869                              <1>  
 15870                              <1> loc_ccdrv_get_FAT_volume_name_0:
 15871 00004845 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15872 00004848 08C0                <1> 	or	al, al
 15873 0000484A 742A                <1> 	jz	short loc_change_current_drv2
 15874                              <1> 
 15875 0000484C 56                  <1> 	push	esi 
 15876 0000484D 3C02                <1> 	cmp	al, 2
 15877 0000484F 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
 15878                              <1>              
 15879                              <1> loc_ccdrv_get_FAT2_16_vol_name:
 15880 00004851 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
 15881 00004854 EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
 15882                              <1> 
 15883                              <1> loc_ccdrv_get_FAT32_vol_name:
 15884 00004856 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
 15885                              <1> loc_ccdrv_get_FAT_volume_name_1:
 15886 00004859 53                  <1> 	push	ebx
 15887 0000485A 56                  <1> 	push	esi
 15888 0000485B E8C8FEFFFF          <1> 	call	get_FAT_volume_name
 15889 00004860 5F                  <1> 	pop	edi
 15890 00004861 5B                  <1> 	pop	ebx
 15891                              <1> 	; BL = 0
 15892 00004862 720B                <1> 	jc	short loc_change_current_drv1
 15893 00004864 20C0                <1> 	and	al, al
 15894 00004866 7407                <1> 	jz	short loc_change_current_drv1
 15895                              <1> 
 15896                              <1> loc_ccdrv_move_FAT_volume_name:
 15897 00004868 B90B000000          <1> 	mov	ecx, 11
 15898 0000486D F3A4                <1> 	rep	movsb
 15899                              <1> 
 15900                              <1> loc_change_current_drv1:
 15901 0000486F 5E                  <1> 	pop	esi
 15902 00004870 EB04                <1> 	jmp	short loc_change_current_drv2
 15903                              <1> 
 15904                              <1> loc_gmcs_init_drv_hd:
 15905 00004872 08E4                <1> 	or	ah, ah
 15906 00004874 7404                <1> 	jz	short loc_change_current_drv3
 15907                              <1> 	; BL = 0, BH = Logical DOS drive number
 15908                              <1> loc_change_current_drv2:
 15909 00004876 C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
 15910                              <1> loc_change_current_drv3:
 15911 0000487A 883D[42C50000]      <1> 	mov	[Current_Drv], bh
 15912                              <1> 
 15913                              <1> 	;call	restore_current_directory
 15914                              <1> 	;retn
 15915                              <1> 
 15916                              <1> restore_current_directory:
 15917                              <1> 	; 11/02/2016
 15918                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15919                              <1> 	; 25/01/2010
 15920                              <1> 	; 12/10/2009
 15921                              <1> 	;
 15922                              <1> 	; INPUT:
 15923                              <1> 	;   ESI = Logical DOS Drive Description Table
 15924                              <1> 	;
 15925                              <1> 	; OUTPUT:
 15926                              <1> 	;   ESI = Logical DOS Drive Description Table
 15927                              <1> 	;   EDI = offset Current_Dir_Drv 
 15928                              <1> 
 15929 00004880 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15930 00004883 A2[41C50000]        <1> 	mov	[Current_FATType], al
 15931                              <1> 
 15932 00004888 8A26                <1> 	mov	ah, [esi+LD_Name] 
 15933 0000488A 8825[43C50000]      <1> 	mov	[Current_Dir_Drv], ah
 15934                              <1> 
 15935 00004890 20C0                <1> 	and	al, al
 15936 00004892 741D                <1> 	jz	short loc_restore_FS_current_directory
 15937                              <1> 
 15938                              <1> loc_restore_FAT_current_directory:
 15939 00004894 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 15940 00004897 8825[40C50000]      <1> 	mov	[Current_Dir_Level], ah
 15941 0000489D 08E4                <1> 	or	ah, ah
 15942 0000489F 7416                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
 15943                              <1> 
 15944 000048A1 0FB6D4              <1> 	movzx	edx, ah
 15945 000048A4 C0E204              <1> 	shl	dl, 4 ; * 16
 15946 000048A7 01F2                <1>         add	edx, esi
 15947 000048A9 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
 15948 000048AF EB2C                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
 15949                              <1> 
 15950                              <1> loc_restore_FS_current_directory:
 15951 000048B1 E89B4A0000          <1> 	call	load_current_FS_directory 
 15952 000048B6 C3                  <1> 	retn 
 15953                              <1> 
 15954                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
 15955 000048B7 3C03                <1> 	cmp	al, 3
 15956 000048B9 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
 15957                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
 15958 000048BB 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 15959 000048BE EB04                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
 15960                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
 15961 000048C0 30C0                <1> 	xor	al, al  ; xor eax, eax
 15962 000048C2 31D2                <1> 	xor	edx, edx
 15963                              <1> loc_ccdrv_check_rootdir_sign:
 15964 000048C4 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
 15965 000048CB 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
 15966                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
 15967 000048CD 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
 15968 000048D3 C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
 15969 000048DC 54                  <1>
 15970                              <1> 
 15971                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
 15972 000048DD A3[3CC50000]        <1> 	mov	[Current_Dir_FCluster], eax
 15973                              <1> 
 15974 000048E2 BF[A3CD0000]        <1> 	mov	edi, PATH_Array
 15975 000048E7 89F2                <1> 	mov	edx, esi
 15976 000048E9 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 15977 000048EF B920000000          <1> 	mov	ecx, 32
 15978 000048F4 F3A5                <1> 	rep	movsd
 15979                              <1> 
 15980 000048F6 E84A2A0000          <1> 	call	change_prompt_dir_string
 15981                              <1> 	
 15982 000048FB 89D6                <1> 	mov	esi, edx
 15983                              <1> 	
 15984 000048FD 29C0                <1>         sub	eax, eax
 15985                              <1>        ;sub	edx, edx
 15986 000048FF BF[43C50000]        <1> 	mov	edi, Current_Dir_Drv
 15987                              <1> 
 15988 00004904 A2[F6B40000]        <1> 	mov	[Restore_CDIR], al ; 0
 15989 00004909 C3                  <1> 	retn
 15990                              <1> 
 15991                              <1> dos_prompt:
 15992                              <1> 	; 30/01/2016
 15993                              <1> 	; 29/01/2016
 15994                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
 15995                              <1> 	; 15/09/2011
 15996                              <1> 	; 13/09/2009
 15997                              <1> 	; 2004-2005
 15998                              <1> 
 15999                              <1> loc_TRDOS_prompt:
 16000 0000490A BF[42C60000]        <1> 	mov	edi, TextBuffer
 16001 0000490F C6075B              <1> 	mov	byte [edi], "["
 16002 00004912 47                  <1> 	inc	edi
 16003 00004913 BE[49B50000]        <1> 	mov	esi, TRDOSPromptLabel
 16004                              <1> get_next_prompt_label_char:
 16005 00004918 803E20              <1> 	cmp	byte [esi], 20h
 16006 0000491B 7203                <1> 	jb	short pass_prompt_label
 16007 0000491D A4                  <1> 	movsb
 16008 0000491E EBF8                <1> 	jmp	short get_next_prompt_label_char
 16009                              <1> pass_prompt_label:
 16010 00004920 C6075D              <1> 	mov	byte [edi], "]"
 16011 00004923 47                  <1> 	inc	edi
 16012 00004924 C60720              <1> 	mov	byte [edi], 20h
 16013 00004927 47                  <1> 	inc	edi
 16014 00004928 BE[43C50000]        <1> 	mov	esi, Current_Dir_Drv
 16015 0000492D 66A5                <1> 	movsw
 16016 0000492F A4                  <1> 	movsb 
 16017                              <1> loc_prompt_current_directory:
 16018 00004930 803E20              <1> 	cmp	byte [esi], 20h
 16019 00004933 7203                <1> 	jb	short pass_prompt_current_directory
 16020 00004935 A4                  <1> 	movsb
 16021 00004936 EBF8                <1> 	jmp	short loc_prompt_current_directory  
 16022                              <1> pass_prompt_current_directory:
 16023 00004938 C6073E              <1> 	mov	byte [edi], '>'
 16024 0000493B 47                  <1> 	inc	edi
 16025 0000493C C60700              <1> 	mov	byte [edi], 0  
 16026 0000493F BE[42C60000]        <1> 	mov	esi, TextBuffer
 16027 00004944 E881F5FFFF          <1> 	call	print_msg
 16028                              <1>         
 16029                              <1> 	;sub	bl, bl ; video page = 0
 16030                              <1> 	;call	get_cpos ; get cursor position
 16031 00004949 668B15[98C40000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 16032 00004950 8815[A2C50000]      <1> 	mov	[CursorColumn], dl
 16033                              <1> 
 16034                              <1> 	; 30/01/2016 (to show cursor on the row, again)
 16035                              <1> 	; (Initial color attributes of video page 0 is 0)
 16036                              <1> 	; (see: 'StartPMP' in trdos386.s)
 16037                              <1> 	; 
 16038                              <1> 	;mov	edi, 0B8000h ; start of video page 0
 16039                              <1> 	;movzx	ecx, dl ; column	 
 16040                              <1> 	;mov	al, 80
 16041                              <1> 	;mul	dh
 16042                              <1> 	;add	ax, cx
 16043                              <1> 	;shl	ax, 1 ; character + attribute
 16044                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
 16045                              <1> 	;neg	cl
 16046                              <1> 	;add	cl, 80
 16047                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
 16048                              <1> 	;rep	stosw	
 16049                              <1> 
 16050                              <1> loc_rw_char:
 16051 00004956 E899000000          <1> 	call	rw_char
 16052                              <1> loc_move_command:
 16053 0000495B BE[F2C50000]        <1> 	mov	esi, CommandBuffer
 16054 00004960 89F7                <1> 	mov	edi, esi
 16055 00004962 31C9                <1> 	xor	ecx, ecx
 16056                              <1> first_command_char:
 16057 00004964 AC                  <1> 	lodsb
 16058 00004965 3C20                <1> 	cmp	al, 20h
 16059 00004967 772E                <1> 	ja	short pass_space_control
 16060 00004969 7241                <1> 	jb	short loc_move_cmd_arguments_ok
 16061 0000496B 81FE[41C60000]      <1> 	cmp	esi, CommandBuffer + 79
 16062 00004971 72F1                <1> 	jb	short first_command_char
 16063 00004973 EB37                <1> 	jmp	short loc_move_cmd_arguments_ok
 16064                              <1> 
 16065                              <1> next_command_char:
 16066 00004975 AC                  <1> 	lodsb
 16067 00004976 3C20                <1> 	cmp	al, 20h
 16068 00004978 771D                <1> 	ja	short pass_space_control
 16069 0000497A 7230                <1> 	jb	short loc_move_cmd_arguments_ok
 16070                              <1> 
 16071                              <1> loc_1st_cmd_arg: ; 30/01/2016
 16072 0000497C AC                  <1> 	lodsb
 16073 0000497D 3C20                <1> 	cmp	al, 20h
 16074 0000497F 74FB                <1> 	je	short loc_1st_cmd_arg
 16075 00004981 7229                <1> 	jb	short loc_move_cmd_arguments_ok
 16076                              <1> 	
 16077 00004983 C60700              <1>         mov     byte [edi], 0
 16078 00004986 47                  <1> 	inc	edi
 16079                              <1> 
 16080                              <1> loc_move_cmd_arguments:
 16081 00004987 AA                  <1> 	stosb
 16082 00004988 81FE[41C60000]      <1> 	cmp	esi, CommandBuffer + 79
 16083 0000498E 731C                <1> 	jnb	short loc_move_cmd_arguments_ok
 16084 00004990 AC                  <1>         lodsb
 16085 00004991 3C20                <1> 	cmp	al, 20h
 16086 00004993 73F2                <1> 	jnb	short loc_move_cmd_arguments
 16087 00004995 EB15                <1> 	jmp	short loc_move_cmd_arguments_ok
 16088                              <1> 
 16089                              <1> pass_space_control:
 16090 00004997 3C61                <1> 	cmp	al, 61h
 16091 00004999 7206                <1> 	jb	short pass_capitalize
 16092 0000499B 3C7A                <1> 	cmp	al, 7Ah
 16093 0000499D 7702                <1> 	ja	short pass_capitalize
 16094 0000499F 24DF                <1> 	and	al, 0DFh
 16095                              <1> pass_capitalize:
 16096 000049A1 AA                  <1> 	stosb   
 16097 000049A2 FEC1                <1> 	inc     cl
 16098 000049A4 81FE[41C60000]      <1>         cmp     esi, CommandBuffer + 79
 16099 000049AA 72C9                <1> 	jb      short next_command_char 
 16100                              <1> 
 16101                              <1> loc_move_cmd_arguments_ok:
 16102 000049AC C60700              <1>         mov     byte [edi], 0
 16103                              <1>        
 16104                              <1> call_command_intepreter:
 16105 000049AF E8DB080000          <1> 	call    command_interpreter
 16106                              <1> 
 16107 000049B4 B950000000          <1>         mov	ecx, 80
 16108                              <1> 	;mov	cx, 80
 16109 000049B9 BF[F2C50000]        <1> 	mov	edi, CommandBuffer
 16110 000049BE 30C0                <1> 	xor	al, al
 16111 000049C0 F3AA                <1> 	rep	stosb
 16112                              <1> 	;cmp	byte [Program_Exit], 0
 16113                              <1> 	;ja	short loc_terminate_trdos
 16114                              <1>         
 16115                              <1> 	; 16/01/2016
 16116 000049C2 803D[A6BE0000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
 16117 000049C9 741D                <1> 	je	short pass_set_txt_mode
 16118                              <1> 
 16119 000049CB E82ACBFFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
 16120                              <1> 
 16121                              <1> loc_check_active_page:
 16122 000049D0 30C0                <1> 	xor	al, al
 16123 000049D2 3805[A8C40000]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
 16124 000049D8 0F842CFFFFFF        <1>         je      loc_TRDOS_prompt 
 16125                              <1> 	; AL = 0 = video page 0
 16126 000049DE E8B1CBFFFF          <1> 	call	set_active_page
 16127 000049E3 E922FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
 16128                              <1> 
 16129                              <1> pass_set_txt_mode: 
 16130 000049E8 BE[56C10000]        <1> 	mov	esi, nextline
 16131 000049ED E8D8F4FFFF          <1> 	call	print_msg
 16132 000049F2 EBDC                <1> 	jmp     short loc_check_active_page
 16133                              <1> 
 16134                              <1> rw_char:
 16135                              <1> 	; 30/01/2016
 16136                              <1> 	; 29/01/2016
 16137                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 16138                              <1> 	; 2004-2005
 16139                              <1> 	
 16140                              <1> 	; DH = cursor row, DL = cursor column
 16141                              <1> 	; BL = 0 = video page number (active page)
 16142                              <1> 
 16143                              <1> readnextchar:
 16144 000049F4 30E4                <1> 	xor     ah, ah
 16145 000049F6 E8ECC1FFFF          <1> 	call	int16h
 16146 000049FB 20C0                <1> 	and	al, al
 16147 000049FD 7439                <1> 	jz	short loc_arrow    
 16148 000049FF 3CE0                <1> 	cmp	al, 0E0h          
 16149 00004A01 7435                <1> 	je	short loc_arrow
 16150 00004A03 3C08                <1> 	cmp	al, 08h             
 16151 00004A05 7549                <1> 	jne	short char_return
 16152                              <1> loc_back:
 16153 00004A07 3A15[A2C50000]      <1> 	cmp	dl, [CursorColumn]
 16154 00004A0D 76E5                <1> 	jna     short readnextchar
 16155                              <1> prev_column:
 16156 00004A0F FECA                <1> 	dec	dl
 16157                              <1> set_cursor_pos:
 16158 00004A11 6652                <1> 	push	dx
 16159 00004A13 30DB                <1> 	xor	bl, bl ; 0 = video page 0
 16160                              <1> 	; DH = Row, DL = Column
 16161 00004A15 E831CEFFFF          <1> 	call	_set_cpos ; 17/01/2016
 16162 00004A1A 665A                <1>         pop	dx
 16163 00004A1C 0FB6DA              <1> 	movzx	ebx, dl
 16164 00004A1F 2A1D[A2C50000]      <1> 	sub	bl, [CursorColumn] 
 16165 00004A25 B407                <1> 	mov	ah, 7 ; color attribute
 16166 00004A27 B020                <1> 	mov	al, 20h
 16167 00004A29 8883[F2C50000]      <1> 	mov	[CommandBuffer+ebx], al
 16168 00004A2F 28DB                <1> 	sub	bl, bl ; video page 0
 16169                              <1> 	;mov	cx, 1
 16170 00004A31 E850CDFFFF          <1> 	call	_write_c_current ; 17/01/2016
 16171                              <1> 	;mov	dx, [CURSOR_POSN]
 16172 00004A36 EBBC                <1> 	jmp	short readnextchar
 16173                              <1> loc_arrow:    
 16174 00004A38 80FC4B              <1> 	cmp	ah, 4Bh
 16175 00004A3B 74CA                <1> 	je	short loc_back
 16176 00004A3D 80FC53              <1> 	cmp	ah, 53h
 16177 00004A40 74C5                <1> 	je      short loc_back
 16178 00004A42 80FC4D              <1> 	cmp	ah, 4Dh
 16179 00004A45 75AD                <1> 	jne	short readnextchar
 16180 00004A47 80FA4F              <1> 	cmp	dl, 79
 16181 00004A4A 73A8                <1> 	jnb	short readnextchar
 16182 00004A4C FEC2                <1> 	inc	dl
 16183 00004A4E EBC1                <1> 	jmp	short set_cursor_pos
 16184                              <1> char_return:
 16185 00004A50 0FB6DA              <1> 	movzx	ebx, dl
 16186 00004A53 2A1D[A2C50000]      <1> 	sub	bl, [CursorColumn] 
 16187 00004A59 3C20                <1> 	cmp	al, 20h
 16188 00004A5B 7220                <1> 	jb	short loc_escape
 16189 00004A5D 8883[F2C50000]      <1> 	mov	[CommandBuffer+ebx], al
 16190 00004A63 28DB                <1> 	sub	bl, bl ; 0
 16191 00004A65 80FA4F              <1> 	cmp	dl, 79
 16192 00004A68 738A                <1> 	jnb	short readnextchar
 16193 00004A6A B407                <1> 	mov	ah, 7 ; color attribute
 16194 00004A6C E846CDFFFF          <1> 	call	WRITE_TTY
 16195 00004A71 668B15[98C40000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 16196 00004A78 E977FFFFFF          <1>         jmp     readnextchar
 16197                              <1> loc_escape:
 16198 00004A7D 3C1B                <1> 	cmp	al, 1Bh
 16199 00004A7F 741A                <1> 	je	short rw_char_retn
 16200                              <1> 	;
 16201 00004A81 3C0D                <1> 	cmp	al, 0Dh ; CR
 16202 00004A83 0F856BFFFFFF        <1>         jne     readnextchar
 16203 00004A89 30DB                <1> 	xor	bl, bl ; 0
 16204 00004A8B B407                <1> 	mov	ah, 7 ; attribute/color
 16205 00004A8D E825CDFFFF          <1> 	call	WRITE_TTY
 16206 00004A92 B407                <1> 	mov	ah, 7 ; attribute/color
 16207 00004A94 B00A                <1> 	mov	al, 0Ah ; LF
 16208 00004A96 E81CCDFFFF          <1> 	call	WRITE_TTY
 16209                              <1> rw_char_retn:
 16210 00004A9B C3                  <1> 	retn
 16211                              <1> 
 16212                              <1> show_date:
 16213                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16214                              <1>         ; 2004-2005
 16215                              <1> 
 16216                              <1> 	;mov	ah, 04h
 16217                              <1> 	;call	int1Ah
 16218 00004A9C E8A1F1FFFF          <1> 	call	RTC_40	; GET RTC DATE
 16219                              <1> 
 16220 00004AA1 88D0                <1> 	mov	al, dl
 16221 00004AA3 E836C1FFFF          <1>   	call	bcd_to_ascii
 16222 00004AA8 66A3[3EB60000]      <1> 	mov	[Day], ax
 16223                              <1> 
 16224 00004AAE 88F0                <1> 	mov	al, dh
 16225 00004AB0 E829C1FFFF          <1>   	call	bcd_to_ascii
 16226 00004AB5 66A3[41B60000]      <1> 	mov	[Month], ax
 16227                              <1> 
 16228 00004ABB 88E8                <1> 	mov	al, ch
 16229 00004ABD E81CC1FFFF          <1>   	call	bcd_to_ascii
 16230 00004AC2 66A3[44B60000]      <1> 	mov	[Century], ax
 16231                              <1> 
 16232 00004AC8 88C8                <1> 	mov	al, cl
 16233 00004ACA E80FC1FFFF          <1>   	call	bcd_to_ascii
 16234 00004ACF 66A3[46B60000]      <1> 	mov	word [Year], ax
 16235                              <1> 
 16236 00004AD5 BE[2EB60000]        <1> 	mov	esi, Msg_Show_Date
 16237 00004ADA E8EBF3FFFF          <1> 	call	print_msg
 16238                              <1> 
 16239 00004ADF C3                  <1> 	retn
 16240                              <1> 
 16241                              <1> set_date:
 16242                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16243                              <1>         ; 2004-2005
 16244                              <1> 
 16245 00004AE0 BE[12B60000]        <1> 	mov	esi, Msg_Enter_Date
 16246 00004AE5 E8E0F3FFFF          <1> 	call	print_msg
 16247                              <1> 
 16248                              <1> loc_enter_day_1:
 16249 00004AEA 30E4                <1> 	xor     ah, ah
 16250 00004AEC E8F6C0FFFF          <1> 	call	int16h
 16251                              <1> 	; AL = ASCII Code of the Character
 16252 00004AF1 3C0D                <1> 	cmp	al, 13
 16253 00004AF3 0F84B7010000        <1> 	je	loc_set_date_retn
 16254 00004AF9 3C1B                <1> 	cmp	al, 27
 16255 00004AFB 0F84AF010000        <1> 	je	loc_set_date_retn
 16256 00004B01 A2[3EB60000]        <1> 	mov	[Day], al
 16257 00004B06 3C30                <1> 	cmp	al, '0'
 16258 00004B08 0F82AD010000        <1> 	jb	loc_set_date_stc_0
 16259 00004B0E 3C33                <1> 	cmp	al, '3'
 16260 00004B10 0F87A5010000        <1> 	ja	loc_set_date_stc_0
 16261                              <1> 	;sub	bl, bl ; 0
 16262 00004B16 B407                <1> 	mov	ah, 7 ; attribute/color
 16263 00004B18 E89ACCFFFF          <1> 	call	WRITE_TTY
 16264                              <1> loc_enter_day_2:
 16265 00004B1D 30E4                <1> 	xor     ah, ah
 16266 00004B1F E8C3C0FFFF          <1> 	call	int16h
 16267                              <1> 	; AL = ASCII Code of the Character
 16268 00004B24 3C1B                <1> 	cmp	al, 27
 16269 00004B26 0F8484010000        <1>         je      loc_set_date_retn
 16270 00004B2C A2[3FB60000]        <1> 	mov	[Day+1], al
 16271 00004B31 3C30                <1> 	cmp	al, '0'
 16272 00004B33 0F828C010000        <1>         jb      loc_set_date_stc_1
 16273 00004B39 3C39                <1> 	cmp	al, '9'
 16274 00004B3B 0F8784010000        <1>         ja      loc_set_date_stc_1
 16275 00004B41 803D[3EB60000]33    <1> 	cmp	byte [Day], '3'
 16276 00004B48 7208                <1> 	jb	short pass_set_day_31
 16277 00004B4A 3C31                <1> 	cmp	al, '1'
 16278 00004B4C 0F8773010000        <1>         ja      loc_set_date_stc_1
 16279                              <1> pass_set_day_31:
 16280                              <1> 	;sub	bl, bl ; 0
 16281 00004B52 B407                <1> 	mov	ah, 7 ; attribute/color
 16282 00004B54 E85ECCFFFF          <1> 	call	WRITE_TTY
 16283                              <1> loc_enter_separator_1:
 16284 00004B59 28E4                <1> 	sub     ah, ah ; 0
 16285 00004B5B E887C0FFFF          <1> 	call	int16h
 16286                              <1> 	; AL = ASCII Code of the Character
 16287 00004B60 3C1B                <1> 	cmp	al, 27
 16288 00004B62 0F8448010000        <1>         je      loc_set_date_retn
 16289 00004B68 3C2D                <1> 	cmp	al, '-'
 16290 00004B6A 7408                <1> 	je	short pass_set_date_separator_1
 16291 00004B6C 3C2F                <1> 	cmp	al, '/'
 16292 00004B6E 0F856C010000        <1>         jne     loc_set_date_stc_2
 16293                              <1> pass_set_date_separator_1:
 16294                              <1> 	;xor	bl, bl ; 0
 16295 00004B74 B407                <1> 	mov	ah, 7 ; attribute/color
 16296 00004B76 E83CCCFFFF          <1> 	call	WRITE_TTY
 16297                              <1> loc_enter_month_1:
 16298 00004B7B 30E4                <1> 	xor     ah, ah ; 0
 16299 00004B7D E865C0FFFF          <1> 	call	int16h
 16300                              <1> 	; AL = ASCII Code of the Character
 16301 00004B82 3C1B                <1> 	cmp	al, 27
 16302 00004B84 0F8426010000        <1>         je      loc_set_date_retn
 16303 00004B8A A2[41B60000]        <1> 	mov	[Month], al
 16304 00004B8F 3C30                <1> 	cmp	al, '0'
 16305 00004B91 0F8264010000        <1>         jb      loc_set_date_stc_3
 16306 00004B97 3C31                <1> 	cmp	al, '1'
 16307 00004B99 0F875C010000        <1>         ja      loc_set_date_stc_3
 16308                              <1> 	;sub	bl, bl
 16309 00004B9F B407                <1> 	mov	ah, 7 ; attribute/color
 16310 00004BA1 E811CCFFFF          <1> 	call	WRITE_TTY
 16311                              <1> loc_enter_month_2:
 16312 00004BA6 30E4                <1> 	xor     ah, ah
 16313 00004BA8 E83AC0FFFF          <1> 	call	int16h
 16314                              <1> 	; AL = ASCII Code of the Character
 16315 00004BAD 3C1B                <1> 	cmp	al, 27
 16316 00004BAF 0F84FB000000        <1>         je      loc_set_date_retn
 16317 00004BB5 A2[42B60000]        <1> 	mov	[Month+1], al
 16318 00004BBA 3C30                <1> 	cmp	al, '0'
 16319 00004BBC 0F8254010000        <1>         jb      loc_set_date_stc_4
 16320 00004BC2 3C39                <1> 	cmp	al, '9'
 16321 00004BC4 0F874C010000        <1>         ja      loc_set_date_stc_4
 16322 00004BCA 803D[41B60000]31    <1> 	cmp	byte [Month], '1'
 16323 00004BD1 7208                <1> 	jb	short pass_set_month_12
 16324 00004BD3 3C32                <1> 	cmp	al, '2'
 16325 00004BD5 0F873B010000        <1>         ja      loc_set_date_stc_4
 16326                              <1> pass_set_month_12:
 16327                              <1> 	;sub	bl, bl
 16328 00004BDB B407                <1> 	mov	ah, 7 ; attribute/color
 16329 00004BDD E8D5CBFFFF          <1> 	call	WRITE_TTY
 16330                              <1> loc_enter_separator_2:
 16331 00004BE2 28E4                <1> 	sub     ah, ah
 16332 00004BE4 E8FEBFFFFF          <1> 	call	int16h
 16333                              <1> 	; AL = ASCII Code of the Character
 16334 00004BE9 3C1B                <1> 	cmp	al, 27
 16335 00004BEB 0F84BF000000        <1>         je      loc_set_date_retn
 16336 00004BF1 3C2D                <1> 	cmp	al, '-'
 16337 00004BF3 7408                <1> 	je	short pass_set_date_separator_2
 16338 00004BF5 3C2F                <1> 	cmp	al, '/'
 16339 00004BF7 0F8534010000        <1>         jne     loc_set_date_stc_5
 16340                              <1> pass_set_date_separator_2:
 16341                              <1> 	;xor	bl, bl
 16342 00004BFD B407                <1> 	mov	ah, 7 ; attribute/color
 16343 00004BFF E8B3CBFFFF          <1> 	call	WRITE_TTY
 16344                              <1> loc_enter_year_1:
 16345 00004C04 30E4                <1> 	xor    ah, ah
 16346 00004C06 E8DCBFFFFF          <1> 	call	int16h
 16347                              <1> 	; AL = ASCII Code of the Character
 16348 00004C0B 3C1B                <1> 	cmp	al, 27
 16349 00004C0D 0F849D000000        <1>         je      loc_set_date_retn
 16350 00004C13 A2[46B60000]        <1> 	mov	[Year], al
 16351 00004C18 3C30                <1> 	cmp	al, '0'
 16352 00004C1A 0F822C010000        <1>         jb      loc_set_date_stc_6
 16353 00004C20 3C39                <1> 	cmp	al, '9'
 16354 00004C22 0F8724010000        <1>         ja      loc_set_date_stc_6
 16355                              <1> 	;sub	bl, bl
 16356 00004C28 B407                <1> 	mov	ah, 7 ; attribute/color
 16357 00004C2A E888CBFFFF          <1> 	call	WRITE_TTY
 16358                              <1> loc_enter_year_2:
 16359 00004C2F 30E4                <1> 	xor	ah, ah
 16360 00004C31 E8B1BFFFFF          <1> 	call	int16h
 16361                              <1> 	; AL = ASCII Code of the Character
 16362 00004C36 3C1B                <1> 	cmp	al, 27
 16363 00004C38 7476                <1> 	je	short loc_set_date_retn
 16364 00004C3A A2[47B60000]        <1> 	mov	byte [Year+1], al
 16365 00004C3F 3C30                <1> 	cmp	al, '0'
 16366 00004C41 0F8220010000        <1>         jb      loc_set_date_stc_7
 16367 00004C47 3C39                <1> 	cmp	al, '9'
 16368 00004C49 0F8718010000        <1>         ja      loc_set_date_stc_7
 16369                              <1> 	;sub	bl, bl
 16370 00004C4F B407                <1> 	mov	ah, 7 ; attribute/color
 16371 00004C51 E861CBFFFF          <1> 	call	WRITE_TTY
 16372                              <1> loc_set_date_get_lchar_again:
 16373 00004C56 28E4                <1> 	sub	ah, ah ; 0
 16374 00004C58 E88ABFFFFF          <1> 	call	int16h
 16375                              <1> 	; AL = ASCII Code of the Character
 16376 00004C5D 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16377 00004C5F 7412                <1> 	je	short loc_set_date_progress
 16378 00004C61 3C1B                <1> 	cmp	al, 27 ; ESC key
 16379 00004C63 744B                <1> 	je	short loc_set_date_retn
 16380                              <1> 	;
 16381 00004C65 E82A010000          <1> 	call	check_for_backspace
 16382 00004C6A 75EA                <1> 	jne	short loc_set_date_get_lchar_again
 16383                              <1> 
 16384                              <1> loc_set_date_bs_8:
 16385 00004C6C E811010000          <1> 	call	write_backspace
 16386 00004C71 EBBC                <1> 	jmp	short loc_enter_year_2
 16387                              <1> 
 16388                              <1> loc_set_date_progress:
 16389                              <1> 	; Get Current Date
 16390                              <1> 	;mov	ah, 04h
 16391                              <1> 	;call	int1Ah
 16392 00004C73 E8CAEFFFFF          <1> 	call	RTC_40	; GET RTC DATE
 16393                              <1> 	; CH = century (in BCD)
 16394                              <1> 
 16395 00004C78 66A1[46B60000]      <1> 	mov	ax, [Year]
 16396 00004C7E 662D3030            <1> 	sub	ax, '00'
 16397 00004C82 C0E004              <1> 	shl	al, 4 ; * 16
 16398 00004C85 88C1                <1> 	mov	cl, al
 16399 00004C87 00E1                <1> 	add	cl, ah
 16400 00004C89 66A1[41B60000]      <1> 	mov	ax, [Month]
 16401 00004C8F 662D3030            <1> 	sub	ax, '00'
 16402 00004C93 C0E004              <1> 	shl	al, 4 ; * 16
 16403 00004C96 88C6                <1> 	mov	dh, al
 16404 00004C98 00E6                <1> 	add	dh, ah
 16405 00004C9A 66A1[3EB60000]      <1> 	mov	ax, [Day]
 16406 00004CA0 662D3030            <1> 	sub	ax, '00'
 16407 00004CA4 C0E004              <1> 	shl	al, 4 ; * 16
 16408 00004CA7 88C2                <1> 	mov	dl, al
 16409 00004CA9 00E2                <1> 	add	dl, ah
 16410                              <1> 
 16411                              <1> 	;mov	ah, 05h
 16412                              <1> 	;call	int1Ah
 16413 00004CAB E8BFEFFFFF          <1> 	call	RTC_50	; SET RTC DATE
 16414                              <1> 
 16415                              <1> loc_set_date_retn:
 16416 00004CB0 BE[56C10000]        <1> 	mov	esi, nextline
 16417 00004CB5 E810F2FFFF          <1> 	call	print_msg
 16418 00004CBA C3                  <1> 	retn
 16419                              <1> 
 16420                              <1> loc_set_date_stc_0:
 16421                              <1> 	;xor	bl, bl ; video page 0
 16422 00004CBB E8D5CBFFFF          <1> 	call	beeper ; BEEP !
 16423 00004CC0 E925FEFFFF          <1>         jmp     loc_enter_day_1
 16424                              <1> loc_set_date_stc_1:
 16425 00004CC5 E8CA000000          <1> 	call	check_for_backspace
 16426 00004CCA 740A                <1> 	je	short loc_set_date_bs_1
 16427                              <1> 	;xor	bl, bl ; video page 0
 16428 00004CCC E8C4CBFFFF          <1> 	call	beeper ; BEEP !
 16429 00004CD1 E947FEFFFF          <1>         jmp     loc_enter_day_2
 16430                              <1> loc_set_date_bs_1:
 16431 00004CD6 E8A7000000          <1> 	call	write_backspace
 16432 00004CDB E90AFEFFFF          <1>         jmp     loc_enter_day_1
 16433                              <1> loc_set_date_stc_2:
 16434 00004CE0 E8AF000000          <1> 	call	check_for_backspace
 16435 00004CE5 740A                <1> 	je	short loc_set_date_bs_2
 16436                              <1> 	;xor	bl, bl ; video page 0
 16437 00004CE7 E8A9CBFFFF          <1> 	call	beeper ; BEEP !
 16438 00004CEC E968FEFFFF          <1>         jmp     loc_enter_separator_1
 16439                              <1> loc_set_date_bs_2:
 16440 00004CF1 E88C000000          <1> 	call	write_backspace
 16441 00004CF6 E922FEFFFF          <1>         jmp     loc_enter_day_2
 16442                              <1> loc_set_date_stc_3:
 16443 00004CFB E894000000          <1> 	call	check_for_backspace	
 16444 00004D00 740A                <1> 	je short loc_set_date_bs_3
 16445                              <1> 	;xor	bl, bl ; video page 0
 16446 00004D02 E88ECBFFFF          <1> 	call	beeper ; BEEP !
 16447 00004D07 E96FFEFFFF          <1>         jmp     loc_enter_month_1
 16448                              <1> loc_set_date_bs_3:
 16449 00004D0C E871000000          <1> 	call	write_backspace
 16450 00004D11 E943FEFFFF          <1>         jmp     loc_enter_separator_1
 16451                              <1> loc_set_date_stc_4:
 16452 00004D16 E879000000          <1> 	call	check_for_backspace	
 16453 00004D1B 740A                <1> 	je	short loc_set_date_bs_4
 16454                              <1> 	;xor	bl, bl ; video page 0
 16455 00004D1D E873CBFFFF          <1> 	call	beeper ; BEEP !
 16456 00004D22 E97FFEFFFF          <1>         jmp     loc_enter_month_2
 16457                              <1> loc_set_date_bs_4:
 16458 00004D27 E856000000          <1> 	call	write_backspace
 16459 00004D2C E94AFEFFFF          <1>         jmp     loc_enter_month_1
 16460                              <1> loc_set_date_stc_5:
 16461 00004D31 E85E000000          <1> 	call	check_for_backspace
 16462 00004D36 740A                <1> 	je	short loc_set_date_bs_5
 16463                              <1> 	;xor	bl, bl ; video page 0
 16464 00004D38 E858CBFFFF          <1> 	call	beeper ; BEEP !
 16465 00004D3D E9A0FEFFFF          <1>         jmp     loc_enter_separator_2
 16466                              <1> loc_set_date_bs_5:
 16467 00004D42 E83B000000          <1> 	call	write_backspace
 16468 00004D47 E95AFEFFFF          <1>         jmp     loc_enter_month_2
 16469                              <1> loc_set_date_stc_6:
 16470 00004D4C E843000000          <1> 	call	check_for_backspace
 16471 00004D51 740A                <1>         je      short  loc_set_date_bs_6
 16472                              <1> 	;xor	bl, bl ; video page 0
 16473 00004D53 E83DCBFFFF          <1> 	call	beeper ; BEEP !
 16474 00004D58 E9A7FEFFFF          <1>         jmp     loc_enter_year_1
 16475                              <1> loc_set_date_bs_6:
 16476 00004D5D E820000000          <1> 	call	write_backspace
 16477 00004D62 E97BFEFFFF          <1>         jmp     loc_enter_separator_2
 16478                              <1> loc_set_date_stc_7:
 16479 00004D67 E828000000          <1> 	call	check_for_backspace
 16480 00004D6C 740A                <1> 	je	short loc_set_date_bs_7
 16481                              <1> 	;xor	bl, bl ; video page 0
 16482 00004D6E E822CBFFFF          <1> 	call	beeper ; BEEP !
 16483 00004D73 E9B7FEFFFF          <1>         jmp     loc_enter_year_2
 16484                              <1> loc_set_date_bs_7:
 16485 00004D78 E805000000          <1> 	call	write_backspace
 16486 00004D7D E982FEFFFF          <1>         jmp     loc_enter_year_1
 16487                              <1> 
 16488                              <1> write_backspace:
 16489                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16490 00004D82 B008                <1> 	mov	al, 08h ; BACKSPACE
 16491                              <1> 	;xor	bl, bl
 16492 00004D84 B407                <1> 	mov	ah, 7 ; attribute/color
 16493 00004D86 E82CCAFFFF          <1> 	call	WRITE_TTY
 16494 00004D8B B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
 16495                              <1> 	;xor	bl, bl
 16496 00004D8D B407                <1> 	mov	ah, 7 ; attribute/color
 16497                              <1> 	;call	_write_c_current
 16498                              <1> 	;retn
 16499 00004D8F E9F2C9FFFF          <1> 	jmp	_write_c_current
 16500                              <1> 
 16501                              <1> check_for_backspace:
 16502                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16503 00004D94 663D080E            <1> 	cmp	ax, 0E08h
 16504 00004D98 7410                <1> 	je	short cfbs_retn
 16505 00004D9A 663DE04B            <1> 	cmp	ax, 4BE0h
 16506 00004D9E 740A                <1> 	je	short cfbs_retn
 16507 00004DA0 663D004B            <1> 	cmp	ax, 4B00h
 16508 00004DA4 7404                <1> 	je	short cfbs_retn
 16509 00004DA6 663DE053            <1> 	cmp	ax, 53E0h
 16510                              <1> cfbs_retn:
 16511 00004DAA C3                  <1> 	retn
 16512                              <1> 
 16513                              <1> show_time:
 16514                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16515                              <1>         ; 2004-2005
 16516                              <1> 
 16517                              <1> 	;mov	ah, 02h
 16518                              <1> 	;call	int1Ah
 16519 00004DAB E821EEFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16520                              <1> 	
 16521 00004DB0 88E8                <1> 	mov	al, ch
 16522 00004DB2 E827BEFFFF          <1> 	call	bcd_to_ascii
 16523 00004DB7 66A3[6CB60000]      <1> 	mov	[Hour], ax
 16524                              <1> 
 16525 00004DBD 88C8                <1> 	mov	al, cl
 16526 00004DBF E81ABEFFFF          <1> 	call	bcd_to_ascii
 16527 00004DC4 66A3[6FB60000]      <1> 	mov	[Minute], ax
 16528                              <1> 
 16529 00004DCA 88F0                <1> 	mov	al, dh
 16530 00004DCC E80DBEFFFF          <1> 	call	bcd_to_ascii
 16531 00004DD1 66A3[72B60000]      <1> 	mov	[Second], ax
 16532                              <1> 
 16533 00004DD7 BE[5CB60000]        <1> 	mov	esi, Msg_Show_Time
 16534 00004DDC E8E9F0FFFF          <1> 	call	print_msg
 16535 00004DE1 C3                  <1> 	retn
 16536                              <1> 
 16537                              <1> set_time:
 16538                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16539                              <1>         ; 2004-2005
 16540                              <1> 
 16541 00004DE2 BE[4BB60000]        <1> 	mov 	esi, Msg_Enter_Time
 16542 00004DE7 E8DEF0FFFF          <1> 	call	print_msg
 16543                              <1> 
 16544                              <1> loc_enter_hour_1:
 16545 00004DEC 30E4                <1> 	xor     ah, ah
 16546 00004DEE E8F4BDFFFF          <1> 	call	int16h
 16547                              <1> 	; AL = ASCII Code of the Character
 16548 00004DF3 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16549 00004DF5 0F84AE010000        <1>         je      loc_set_time_retn
 16550 00004DFB 3C1B                <1> 	cmp	al, 27 ; ESC key
 16551 00004DFD 0F84A6010000        <1>         je      loc_set_time_retn
 16552 00004E03 A2[6CB60000]        <1> 	mov	[Hour], al
 16553 00004E08 3C30                <1> 	cmp	al, '0'
 16554 00004E0A 0F82A4010000        <1>         jb      loc_set_time_stc_0
 16555 00004E10 3C32                <1> 	cmp	al, '2'
 16556 00004E12 0F879C010000        <1>         ja      loc_set_time_stc_0
 16557                              <1> 	;sub	bl, bl ; 0
 16558 00004E18 B407                <1> 	mov	ah, 7 ; attribute/color
 16559 00004E1A E898C9FFFF          <1> 	call	WRITE_TTY
 16560                              <1> loc_enter_hour_2:
 16561 00004E1F 30E4                <1> 	xor     ah, ah
 16562 00004E21 E8C1BDFFFF          <1> 	call	int16h
 16563                              <1> 	; AL = ASCII Code of the Character
 16564 00004E26 3C1B                <1> 	cmp	al, 27
 16565 00004E28 0F847B010000        <1>         je      loc_set_time_retn
 16566 00004E2E A2[6DB60000]        <1> 	mov	[Hour+1], al
 16567 00004E33 3C30                <1> 	cmp	al, '0'
 16568 00004E35 0F8283010000        <1>         jb      loc_set_time_stc_1
 16569 00004E3B 3C39                <1> 	cmp	al, '9'
 16570 00004E3D 0F877B010000        <1> 	ja	loc_set_time_stc_1
 16571 00004E43 803D[6CB60000]32    <1>         cmp     byte [Hour], '2'
 16572 00004E4A 7208                <1> 	jb	short pass_set_time_24
 16573 00004E4C 3C34                <1> 	cmp	al, '4'
 16574 00004E4E 0F876A010000        <1>         ja      loc_set_time_stc_1
 16575                              <1> pass_set_time_24:
 16576                              <1> 	;sub	bl, bl ; 0
 16577 00004E54 B407                <1> 	mov	ah, 7 ; attribute/color
 16578 00004E56 E85CC9FFFF          <1> 	call	WRITE_TTY
 16579                              <1> loc_enter_time_separator_1:
 16580 00004E5B 28E4                <1> 	sub    ah, ah ; 0
 16581 00004E5D E885BDFFFF          <1> 	call	int16h
 16582                              <1> 	; AL = ASCII Code of the Character
 16583 00004E62 3C1B                <1> 	cmp	al, 27
 16584 00004E64 0F843F010000        <1>         je      loc_set_time_retn
 16585 00004E6A 3C3A                <1> 	cmp	al, ':'
 16586 00004E6C 0F8567010000        <1>         jne     loc_set_time_stc_2
 16587                              <1> 	;xor	bl, bl
 16588 00004E72 B407                <1> 	mov	ah, 7 ; attribute/color
 16589 00004E74 E83EC9FFFF          <1> 	call	WRITE_TTY
 16590                              <1> loc_enter_minute_1:
 16591 00004E79 30E4                <1> 	xor     ah, ah
 16592 00004E7B E867BDFFFF          <1> 	call	int16h
 16593                              <1> 	; AL = ASCII Code of the Character
 16594 00004E80 3C1B                <1> 	cmp	al, 27
 16595 00004E82 0F8421010000        <1>         je      loc_set_time_retn
 16596 00004E88 A2[6FB60000]        <1> 	mov	[Minute], al
 16597 00004E8D 3C30                <1> 	cmp	al, '0'
 16598 00004E8F 0F825F010000        <1>         jb      loc_set_time_stc_3
 16599 00004E95 3C35                <1> 	cmp	al, '5'
 16600 00004E97 0F8757010000        <1>         ja      loc_set_time_stc_3
 16601                              <1> 	;sub	bl, bl
 16602 00004E9D B407                <1> 	mov	ah, 7 ; attribute/color
 16603 00004E9F E813C9FFFF          <1> 	call	WRITE_TTY
 16604                              <1> loc_enter_minute_2:
 16605 00004EA4 30E4                <1> 	xor     ah, ah
 16606 00004EA6 E83CBDFFFF          <1> 	call	int16h
 16607                              <1> 	; AL = ASCII Code of the Character
 16608 00004EAB 3C1B                <1> 	cmp	al, 27
 16609 00004EAD 0F84F6000000        <1>         je      loc_set_time_retn
 16610 00004EB3 A2[70B60000]        <1> 	mov	[Minute+1], al
 16611 00004EB8 3C30                <1> 	cmp	al, '0'
 16612 00004EBA 0F824F010000        <1>         jb      loc_set_time_stc_4
 16613 00004EC0 3C39                <1> 	cmp	al, '9'
 16614 00004EC2 0F8747010000        <1>         ja      loc_set_time_stc_4
 16615                              <1> 	;sub	bl, bl
 16616 00004EC8 B407                <1> 	mov	ah, 7 ; attribute/color
 16617 00004ECA E8E8C8FFFF          <1> 	call	WRITE_TTY
 16618                              <1> loc_enter_time_separator_2:
 16619 00004ECF 66C705[72B60000]30- <1> 	mov	word [Second], 3030h
 16620 00004ED7 30                  <1>
 16621 00004ED8 28E4                <1> 	sub     ah, ah
 16622 00004EDA E808BDFFFF          <1> 	call	int16h
 16623                              <1> 	; AL = ASCII Code of the Character
 16624 00004EDF 3C0D                <1> 	cmp	al, 13
 16625 00004EE1 0F8485000000        <1>         je      loc_set_time_progress
 16626 00004EE7 3C1B                <1> 	cmp	al, 27
 16627 00004EE9 0F84BA000000        <1>         je      loc_set_time_retn
 16628 00004EEF 3C3A                <1> 	cmp	al, ':'
 16629 00004EF1 0F8533010000        <1>         jne     loc_set_time_stc_5
 16630                              <1> 	;xor	bl, bl
 16631 00004EF7 B407                <1> 	mov	ah, 7 ; attribute/color
 16632 00004EF9 E8B9C8FFFF          <1> 	call	WRITE_TTY
 16633                              <1> loc_enter_second_1:
 16634 00004EFE 30E4                <1> 	xor     ah, ah
 16635 00004F00 E8E2BCFFFF          <1> 	call	int16h
 16636                              <1> 	; AL = ASCII Code of the Character
 16637 00004F05 3C0D                <1> 	cmp	al, 13
 16638 00004F07 7463                <1> 	je	short loc_set_time_progress
 16639 00004F09 3C1B                <1> 	cmp	al, 27
 16640 00004F0B 0F8498000000        <1>         je      loc_set_time_retn
 16641 00004F11 A2[72B60000]        <1> 	mov	[Second], al
 16642 00004F16 3C30                <1> 	cmp	al, '0'
 16643 00004F18 0F8227010000        <1>         jb      loc_set_time_stc_6
 16644 00004F1E 3C35                <1> 	cmp	al, '5'
 16645 00004F20 0F871F010000        <1>         ja      loc_set_time_stc_6
 16646                              <1> 	;sub	bl, bl
 16647 00004F26 B407                <1> 	mov	ah, 7 ; attribute/color
 16648 00004F28 E88AC8FFFF          <1> 	call	WRITE_TTY
 16649                              <1> loc_enter_second_2:
 16650 00004F2D 30E4                <1> 	xor     ah, ah
 16651 00004F2F E8B3BCFFFF          <1> 	call	int16h
 16652                              <1> 	; AL = ASCII Code of the Character
 16653 00004F34 3C1B                <1> 	cmp	al, 27
 16654 00004F36 7471                <1> 	je	short loc_set_time_retn
 16655 00004F38 3C30                <1> 	cmp	al, '0'
 16656 00004F3A 0F8229010000        <1>         jb      loc_set_time_stc_7
 16657 00004F40 3C39                <1> 	cmp	al, '9'
 16658 00004F42 0F8721010000        <1>         ja      loc_set_time_stc_7
 16659                              <1> 	;sub	bl, bl
 16660 00004F48 B407                <1> 	mov	ah, 7 ; attribute/color
 16661 00004F4A E868C8FFFF          <1> 	call	WRITE_TTY
 16662                              <1> loc_set_time_get_lchar_again:
 16663 00004F4F 28E4                <1> 	sub	ah, ah ; 0
 16664 00004F51 E891BCFFFF          <1> 	call	int16h
 16665                              <1> 	; AL = ASCII Code of the Character
 16666 00004F56 3C0D                <1> 	cmp	al, 13
 16667 00004F58 7412                <1> 	je	short loc_set_time_progress
 16668 00004F5A 3C1B                <1> 	cmp	al, 27
 16669 00004F5C 744B                <1> 	je	short loc_set_time_retn
 16670                              <1> 	;
 16671 00004F5E E831FEFFFF          <1> 	call	check_for_backspace
 16672 00004F63 75EA                <1> 	jne	short loc_set_time_get_lchar_again
 16673                              <1> 
 16674                              <1> loc_set_time_bs_8:
 16675 00004F65 E818FEFFFF          <1> 	call	write_backspace
 16676 00004F6A EBC1                <1> 	jmp	short loc_enter_second_2
 16677                              <1> 
 16678                              <1> loc_set_time_progress:
 16679                              <1> 	; Get Current Time
 16680                              <1> 	;mov 	ah, 02h
 16681                              <1> 	;call	int1Ah
 16682 00004F6C E860ECFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16683                              <1> 	;DL = Daylight Savings Enable option (0-1)	
 16684                              <1> 
 16685 00004F71 66A1[6CB60000]      <1> 	mov	ax, [Hour]
 16686 00004F77 662D3030            <1> 	sub	ax, '00'
 16687 00004F7B C0E004              <1> 	shl	al, 4 ; * 16
 16688 00004F7E 88C5                <1> 	mov	ch, al
 16689 00004F80 00E5                <1> 	add	ch, ah
 16690 00004F82 66A1[6FB60000]      <1> 	mov	ax, [Minute]
 16691 00004F88 662D3030            <1> 	sub	ax, '00'
 16692 00004F8C C0E004              <1> 	shl	al, 4 ; * 16
 16693 00004F8F 88C1                <1> 	mov	cl, al
 16694 00004F91 00E1                <1> 	add	cl, ah
 16695 00004F93 66A1[72B60000]      <1> 	mov	ax, [Second]
 16696 00004F99 662D3030            <1> 	sub	ax, '00'
 16697 00004F9D C0E004              <1> 	shl	al, 4 ; * 16
 16698 00004FA0 88C6                <1> 	mov	dh, al
 16699 00004FA2 00E6                <1> 	add	dh, ah
 16700                              <1> 	
 16701                              <1> 	;mov	ah, 03h
 16702                              <1> 	;call	int1Ah
 16703 00004FA4 E857ECFFFF          <1> 	call	RTC_30	; SET RTC TIME
 16704                              <1> 
 16705                              <1> loc_set_time_retn:
 16706 00004FA9 BE[56C10000]        <1> 	mov 	esi, nextline
 16707 00004FAE E817EFFFFF          <1> 	call	print_msg
 16708 00004FB3 C3                  <1> 	retn
 16709                              <1> 
 16710                              <1> loc_set_time_stc_0:
 16711                              <1> 	;xor	bl, bl ; video page 0
 16712 00004FB4 E8DCC8FFFF          <1> 	call	beeper ; BEEP !
 16713 00004FB9 E92EFEFFFF          <1>         jmp     loc_enter_hour_1
 16714                              <1> loc_set_time_stc_1:
 16715 00004FBE E8D1FDFFFF          <1> 	call	check_for_backspace
 16716 00004FC3 740A                <1> 	je	short loc_set_time_bs_1
 16717                              <1> 	;xor	bl, bl ; video page 0
 16718 00004FC5 E8CBC8FFFF          <1> 	call	beeper ; BEEP !
 16719 00004FCA E950FEFFFF          <1>         jmp     loc_enter_hour_2
 16720                              <1> loc_set_time_bs_1:
 16721 00004FCF E8AEFDFFFF          <1> 	call	write_backspace
 16722 00004FD4 E913FEFFFF          <1>         jmp     loc_enter_hour_1
 16723                              <1> loc_set_time_stc_2:
 16724 00004FD9 E8B6FDFFFF          <1> 	call	check_for_backspace
 16725 00004FDE 740A                <1> 	je	short loc_set_time_bs_2
 16726                              <1> 	;xor	bl, bl ; video page 0
 16727 00004FE0 E8B0C8FFFF          <1> 	call	beeper ; BEEP !
 16728 00004FE5 E971FEFFFF          <1>         jmp     loc_enter_time_separator_1
 16729                              <1> loc_set_time_bs_2:
 16730 00004FEA E893FDFFFF          <1> 	call	write_backspace
 16731 00004FEF E92BFEFFFF          <1>         jmp     loc_enter_hour_2
 16732                              <1> loc_set_time_stc_3:
 16733 00004FF4 E89BFDFFFF          <1> 	call	check_for_backspace
 16734 00004FF9 740A                <1> 	je	short loc_set_time_bs_3
 16735                              <1> 	;xor	bl, bl ; video page 0
 16736 00004FFB E895C8FFFF          <1> 	call	beeper ; BEEP !6
 16737 00005000 E974FEFFFF          <1>         jmp     loc_enter_minute_1
 16738                              <1> loc_set_time_bs_3:
 16739 00005005 E878FDFFFF          <1> 	call	write_backspace
 16740 0000500A E94CFEFFFF          <1>         jmp     loc_enter_time_separator_1
 16741                              <1> loc_set_time_stc_4:
 16742 0000500F E880FDFFFF          <1> 	call	check_for_backspace
 16743 00005014 740A                <1> 	je	short loc_set_time_bs_4
 16744                              <1> 	;xor	bl, bl ; video page 0
 16745 00005016 E87AC8FFFF          <1> 	call	beeper ; BEEP !
 16746 0000501B E984FEFFFF          <1>         jmp     loc_enter_minute_2
 16747                              <1> loc_set_time_bs_4:
 16748 00005020 E85DFDFFFF          <1> 	call	write_backspace
 16749 00005025 E94FFEFFFF          <1>         jmp     loc_enter_minute_1
 16750                              <1> loc_set_time_stc_5:
 16751 0000502A E865FDFFFF          <1> 	call	check_for_backspace
 16752 0000502F 740A                <1> 	je	short loc_set_time_bs_5
 16753                              <1> 	;xor	bl, bl ; video page 0
 16754 00005031 E85FC8FFFF          <1> 	call	beeper ; BEEP !
 16755 00005036 E994FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16756                              <1> loc_set_time_bs_5:
 16757 0000503B E842FDFFFF          <1> 	call	write_backspace
 16758 00005040 E95FFEFFFF          <1>         jmp     loc_enter_minute_2
 16759                              <1> loc_set_time_stc_6:
 16760 00005045 E84AFDFFFF          <1> 	call	check_for_backspace
 16761 0000504A 7413                <1> 	je	short loc_set_time_bs_6
 16762                              <1> 	;xor	bl, bl ; video page 0
 16763 0000504C E844C8FFFF          <1> 	call	beeper ; BEEP !
 16764 00005051 66C705[72B60000]30- <1> 	mov	word [Second], 3030h
 16765 00005059 30                  <1>
 16766 0000505A E99FFEFFFF          <1>         jmp     loc_enter_second_1
 16767                              <1> loc_set_time_bs_6:
 16768 0000505F E81EFDFFFF          <1> 	call	write_backspace
 16769 00005064 E966FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16770                              <1> loc_set_time_stc_7:
 16771 00005069 E826FDFFFF          <1> 	call	check_for_backspace
 16772 0000506E 740A                <1> 	je	short loc_set_time_bs_7
 16773                              <1> 	;xor	bl, bl ; video page 0
 16774 00005070 E820C8FFFF          <1> 	call	beeper ; BEEP !
 16775 00005075 E9B3FEFFFF          <1>         jmp     loc_enter_second_2
 16776                              <1> loc_set_time_bs_7:
 16777 0000507A E803FDFFFF          <1> 	call	write_backspace
 16778 0000507F E97AFEFFFF          <1>         jmp     loc_enter_second_1
 16779                              <1> 
 16780                              <1> print_volume_info:
 16781                              <1> 	; 01/03/2016
 16782                              <1> 	; 08/02/2016
 16783                              <1> 	; 06/02/2016
 16784                              <1> 	; 04/02/2016
 16785                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16786                              <1> 	; 25/10/2009
 16787                              <1> 	;
 16788                              <1> 	; "Volume Serial No: "
 16789                              <1>  	;
 16790                              <1> 	; INPUT  : AL = DOS Drive Number
 16791                              <1> 	; OUTPUT : AH = FS Type
 16792                              <1> 	;          AL = DOS Drive Name
 16793                              <1> 	; CF = 0 -> OK
 16794                              <1> 	; CF = 1 -> Drive not ready 
 16795                              <1> 
 16796 00005084 88C4                <1> 	mov	ah, al
 16797 00005086 28C0                <1> 	sub	al, al
 16798 00005088 0FB7F0              <1> 	movzx	esi, ax	
 16799 0000508B 81C600010900        <1> 	add	esi, Logical_DOSDisks
 16800 00005091 8A06                <1> 	mov	al, [esi]
 16801 00005093 3C41                <1> 	cmp	al, 'A'  
 16802 00005095 7304                <1> 	jnb	short loc_pvi_set_vol_name
 16803 00005097 8A6604              <1> 	mov	ah, [esi+LD_FSType]
 16804 0000509A C3                  <1> 	retn
 16805                              <1> 
 16806                              <1> loc_pvi_set_vol_name:
 16807 0000509B A2[A6B60000]        <1> 	mov	[Vol_Drv_Name], al
 16808 000050A0 56                  <1> 	push	esi
 16809 000050A1 E858010000          <1> 	call	move_volume_name_and_serial_no ;;;
 16810 000050A6 7302                <1> 	jnc	short loc_pvi_mvn_ok
 16811 000050A8 5E                  <1> 	pop	esi
 16812 000050A9 C3                  <1> 	retn
 16813                              <1> 
 16814                              <1> loc_pvi_mvn_ok:
 16815 000050AA 8B3424              <1> 	mov	esi, [esp]
 16816 000050AD 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 16817 000050B1 7509                <1> 	jne	short loc_pvi_fat_vol_size
 16818 000050B3 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
 16819 000050B6 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16820 000050BA EB07                <1> 	jmp	short loc_vol_size_mul32
 16821                              <1> loc_pvi_fat_vol_size:
 16822 000050BC 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
 16823 000050BF 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16824                              <1> loc_vol_size_mul32:
 16825 000050C3 F7E3                <1> 	mul	ebx
 16826 000050C5 09D2                <1> 	or	edx, edx
 16827 000050C7 7507                <1> 	jnz	short loc_vol_size_in_kbytes
 16828                              <1> loc_vol_size_in_bytes:
 16829 000050C9 B9[84B60000]        <1> 	mov	ecx, VolSize_Bytes
 16830 000050CE EB0D                <1> 	jmp	short loc_write_vol_size_str
 16831                              <1> loc_vol_size_in_kbytes:
 16832 000050D0 66BB0004            <1> 	mov	bx, 1024
 16833 000050D4 F7F3                <1> 	div	ebx
 16834 000050D6 B9[77B60000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16835 000050DB 31D2                <1> 	xor	edx, edx ; 0
 16836                              <1> loc_write_vol_size_str:
 16837 000050DD 890D[7BCD0000]      <1> 	mov	[VolSize_Unit1], ecx
 16838                              <1> 	; 
 16839 000050E3 BF[91CD0000]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
 16840                              <1>         ;mov	byte [edi], 0
 16841 000050E8 B90A000000          <1> 	mov	ecx, 10
 16842                              <1> loc_write_vol_size_chr:
 16843 000050ED F7F1                <1> 	div	ecx
 16844 000050EF 80C230              <1> 	add	dl, '0'
 16845 000050F2 4F                  <1> 	dec	edi	
 16846 000050F3 8817                <1> 	mov	[edi], dl
 16847 000050F5 85C0                <1> 	test	eax, eax
 16848 000050F7 7404                <1> 	jz	short loc_write_vol_size_str_ok
 16849 000050F9 28D2                <1> 	sub	dl, dl ; 0
 16850 000050FB EBF0                <1> 	jmp	short loc_write_vol_size_chr
 16851                              <1> 
 16852                              <1> loc_write_vol_size_str_ok:
 16853 000050FD 893D[83CD0000]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
 16854                              <1> 	;
 16855 00005103 BF[8FB60000]        <1> 	mov	edi, Vol_FS_Name
 16856 00005108 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
 16857 0000510B 20C9                <1> 	and	cl, cl ; 0 ?
 16858 0000510D 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
 16859 0000510F 66C7075452          <1> 	mov	word [edi], 'TR'
 16860 00005114 C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
 16861                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16862 0000511B 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
 16863 0000511F 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
 16864 00005122 EB36                <1> 	jmp	short loc_vol_freespace_mul32
 16865                              <1> 
 16866                              <1> loc_write_vol_FAT_str_1:
 16867 00005124 66B83332            <1> 	mov	ax, '32' ; FAT32
 16868 00005128 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
 16869 0000512B 7708                <1> 	ja	short loc_write_vol_FAT_str_2
 16870 0000512D 66B83132            <1> 	mov	ax, '12' ; FAT12
 16871 00005131 7202                <1> 	jb	short loc_write_vol_FAT_str_2
 16872 00005133 B436                <1> 	mov	ah, '6'  ; FAT16
 16873                              <1> loc_write_vol_FAT_str_2:
 16874 00005135 C70746415420        <1> 	mov	dword [edi], 'FAT '
 16875 0000513B 66894704            <1> 	mov	word [edi+4], ax
 16876                              <1> 	;
 16877                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16878 0000513F 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
 16879 00005143 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 16880                              <1> 
 16881                              <1> loc_vol_freespace_recalc0:
 16882                              <1> 	; 01/03/2016
 16883 00005146 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
 16884 00005149 720F                <1> 	jb	short loc_vol_freespace_mul32
 16885                              <1> 	;inc	eax ; 0
 16886 0000514B 20C9                <1> 	and	cl, cl ; byte [esi+LD_FATType]
 16887 0000514D 740B                <1> 	jz	short loc_vol_freespace_mul32 	
 16888 0000514F 53                  <1> 	push	ebx
 16889 00005150 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free sectors
 16890 00005154 E853460000          <1> 	call	calculate_fat_freespace
 16891 00005159 5B                  <1> 	pop	ebx
 16892                              <1> 
 16893                              <1> loc_vol_freespace_mul32:
 16894 0000515A F7E3                <1> 	mul	ebx
 16895 0000515C 09D2                <1> 	or	edx, edx
 16896 0000515E 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
 16897                              <1> loc_vol_fspace_in_bytes:
 16898 00005160 B9[84B60000]        <1> 	mov	ecx, VolSize_Bytes
 16899 00005165 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
 16900                              <1> loc_vol_fspace_in_kbytes:
 16901 00005167 66BB0004            <1> 	mov	bx, 1024
 16902 0000516B F7F3                <1> 	div	ebx
 16903 0000516D B9[77B60000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16904 00005172 31D2                <1> 	xor	edx, edx ; 0
 16905                              <1> loc_write_vol_fspace_str:
 16906 00005174 890D[7FCD0000]      <1> 	mov	[VolSize_Unit2], ecx
 16907                              <1> 	;	
 16908 0000517A BF[A1CD0000]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
 16909                              <1>         ;mov	byte [edi], 0
 16910 0000517F B90A000000          <1> 	mov	ecx, 10
 16911                              <1> loc_write_vol_fspace_chr:
 16912 00005184 F7F1                <1> 	div	ecx
 16913 00005186 80C230              <1> 	add	dl, '0'
 16914 00005189 4F                  <1> 	dec	edi	
 16915 0000518A 8817                <1> 	mov	[edi], dl
 16916 0000518C 85C0                <1> 	test	eax, eax
 16917 0000518E 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
 16918 00005190 28D2                <1> 	sub	dl, dl ; 0
 16919 00005192 EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
 16920                              <1> 
 16921                              <1> loc_write_vol_fspace_str_ok:
 16922 00005194 893D[93CD0000]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
 16923                              <1> 	;
 16924 0000519A BE[8DB60000]        <1> 	mov	esi, Volume_in_drive
 16925 0000519F E826EDFFFF          <1> 	call	print_msg
 16926 000051A4 BE[CDB60000]        <1> 	mov	esi, Vol_Name
 16927 000051A9 E81CEDFFFF          <1> 	call	print_msg
 16928 000051AE BE[56C10000]        <1> 	mov	esi, nextline
 16929 000051B3 E812EDFFFF          <1> 	call	print_msg
 16930                              <1> 	;
 16931 000051B8 BE[2EB70000]        <1> 	mov	esi, Vol_Total_Sector_Header
 16932 000051BD E808EDFFFF          <1> 	call	print_msg
 16933 000051C2 8B35[83CD0000]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
 16934 000051C8 E8FDECFFFF          <1> 	call	print_msg
 16935 000051CD 8B35[7BCD0000]      <1> 	mov	esi, [VolSize_Unit1]
 16936 000051D3 E8F2ECFFFF          <1> 	call	print_msg
 16937                              <1> 	;
 16938 000051D8 BE[3FB70000]        <1> 	mov	esi, Vol_Free_Sectors_Header
 16939 000051DD E8E8ECFFFF          <1> 	call	print_msg
 16940 000051E2 8B35[93CD0000]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
 16941 000051E8 E8DDECFFFF          <1> 	call	print_msg
 16942 000051ED 8B35[7FCD0000]      <1> 	mov	esi, [VolSize_Unit2]
 16943 000051F3 E8D2ECFFFF          <1> 	call	print_msg
 16944                              <1> 	;
 16945 000051F8 5E                  <1> 	pop	esi
 16946                              <1> 	
 16947                              <1> 	;mov	ah, [esi+LD_FSType]
 16948                              <1> 	;mov	al, [esi+LD_FATType]
 16949 000051F9 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16950                              <1> 
 16951 000051FD C3                  <1> 	retn
 16952                              <1> 
 16953                              <1> move_volume_name_and_serial_no:
 16954                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
 16955                              <1> 	; this routine will be called by
 16956                              <1> 	; "print_volume_info" and "print_directory"
 16957                              <1> 	; INPUT ->
 16958                              <1> 	;	ESI = Logical DOS drv descripton table address
 16959                              <1> 	; OUTPUT ->
 16960                              <1> 	;	*Volume name will be moved to text area
 16961                              <1> 	;	*Volume serial number will be converted to
 16962                              <1> 	;	 text and will be moved to text area
 16963                              <1> 	;   cf = 1 -> invalid/unknown dos drive
 16964                              <1> 	;   cf = 0 -> ecx = 0
 16965                              <1> 	;
 16966                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
 16967                              <1> 
 16968 000051FE BF[CDB60000]        <1> 	mov 	edi, Vol_Name
 16969                              <1> 
 16970                              <1> 	;mov	ah, [esi+LD_FSType]
 16971                              <1> 	;mov	al, [esi+LD_FATType]
 16972 00005203 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16973 00005207 80FCA1              <1> 	cmp	ah, 0A1h
 16974 0000520A 7418                <1> 	je	short mvn_2
 16975 0000520C 08E4                <1> 	or	ah, ah
 16976 0000520E 7404                <1> 	jz	short mvn_0
 16977 00005210 08C0                <1> 	or	al, al
 16978 00005212 7504                <1> 	jnz	short mvn_1
 16979                              <1> mvn_0:
 16980 00005214 8A06                <1> 	mov	al, [esi]
 16981 00005216 F9                  <1> 	stc
 16982 00005217 C3                  <1> 	retn
 16983                              <1> mvn_1:
 16984 00005218 3C02                <1> 	cmp	al, 2
 16985 0000521A 7717                <1> 	ja	short mvn_3 
 16986                              <1> 	;or	al, al
 16987                              <1> 	;jz	short mvn_2
 16988 0000521C 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
 16989 0000521F 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
 16990 00005222 EB15                <1> 	jmp	short mvn_4
 16991                              <1> mvn_2:
 16992 00005224 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
 16993 00005227 83C62C              <1> 	add	esi, LD_FS_VolumeName
 16994 0000522A B910000000          <1> 	mov	ecx, 16
 16995 0000522F F3A5                <1> 	rep	movsd
 16996 00005231 EB10                <1> 	jmp	short mvn_5
 16997                              <1> mvn_3:
 16998 00005233 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
 16999 00005236 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
 17000                              <1> mvn_4:
 17001 00005239 B90B000000          <1> 	mov	ecx, 11
 17002 0000523E F3A4                <1> 	rep	movsb
 17003 00005240 C60700              <1> 	mov	byte [edi], 0
 17004                              <1> mvn_5:
 17005                              <1> 	;mov	[Current_VolSerial], eax  
 17006 00005243 E89FC7FFFF          <1> 	call	dwordtohex
 17007 00005248 8915[22B70000]      <1> 	mov	[Vol_Serial1], edx
 17008 0000524E A3[27B70000]        <1> 	mov	[Vol_Serial2], eax
 17009                              <1> 	; ecx = 0
 17010 00005253 C3                  <1> 	retn
 17011                              <1> 
 17012                              <1> get_volume_serial_number:
 17013                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
 17014                              <1> 	; 08/08/2010
 17015                              <1> 	;
 17016                              <1> 	; INPUT -> DL = Logical DOS Drive number
 17017                              <1> 	; OUTPUT -> EAX = Volume serial number
 17018                              <1> 	;          BL= FAT Type	    
 17019                              <1> 	;          BH = Logical DOS drv Number (DL input)
 17020                              <1> 	; cf = 1 -> Drive not ready
 17021                              <1> 
 17022 00005254 31DB                <1> 	xor	ebx, ebx
 17023 00005256 88D7                <1> 	mov	bh, dl
 17024 00005258 3815[F5B40000]      <1> 	cmp	[Last_DOS_DiskNo], dl
 17025 0000525E 7304                <1> 	jnb	short loc_gvsn_start
 17026                              <1> loc_gvsn_stc_retn:
 17027 00005260 31C0                <1> 	xor	eax, eax
 17028 00005262 F9                  <1> 	stc 
 17029 00005263 C3                  <1>         retn 
 17030                              <1> loc_gvsn_start:
 17031 00005264 56                  <1> 	push	esi
 17032 00005265 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17033 0000526A 01DE                <1> 	add	esi, ebx
 17034 0000526C 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 17035 0000526F 20DB                <1> 	and	bl, bl
 17036 00005271 740F                <1> 	jz	short loc_gvsn_fs
 17037 00005273 80FB02              <1> 	cmp	bl, 2
 17038 00005276 7705                <1> 	ja	short loc_gvsn_fat32
 17039                              <1> loc_gvsn_fat:
 17040 00005278 83C62D              <1> 	add	esi, LD_BPB + VolumeID
 17041 0000527B EB0E                <1> 	jmp	short loc_gvsn_return
 17042                              <1> loc_gvsn_fat32: 
 17043 0000527D 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
 17044 00005280 EB09                <1> 	jmp	short loc_gvsn_return 
 17045                              <1> loc_gvsn_fs:
 17046 00005282 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 17047 00005286 75D8                <1> 	jne	short loc_gvsn_stc_retn 
 17048 00005288 83C628              <1> 	add	esi, LD_FS_VolumeSerial
 17049                              <1> loc_gvsn_return:
 17050 0000528B 8B06                <1> 	mov	eax, [esi]
 17051 0000528D 5E                  <1> 	pop	esi
 17052 0000528E C3                  <1> 	retn
 17053                              <1> 
 17054                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
 17055                              <1> ; 09/11/2011
 17056                              <1> ; 29/01/2005
 17057                              <1> 
 17058                              <1> command_interpreter:
 17059                              <1> 	; 14/04/2016
 17060                              <1> 	; 04/03/2016
 17061                              <1> 	; 04/02/2016
 17062                              <1> 	; 03/02/2016
 17063                              <1> 	; 30/01/2016
 17064                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
 17065                              <1> 	; 15/09/2011         
 17066                              <1> 	; 29/01/2005
 17067                              <1>         
 17068                              <1> 	; Input: ecx = command word length (CL)
 17069                              <1> 	;	 CommandBuffer = Command string offset
 17070                              <1>  
 17071 0000528F C605[34CE0000]00    <1> 	mov	byte [Program_Exit],0
 17072 00005296 80F904              <1> 	cmp	cl, 4
 17073 00005299 0F87B9020000        <1>         ja      c_6
 17074 0000529F 0F8227010000        <1>         jb      c_2
 17075                              <1> c_4:
 17076                              <1> 
 17077                              <1> cmp_cmd_exit:
 17078 000052A5 BF[63B50000]        <1> 	mov	edi, Cmd_Exit
 17079 000052AA E8CA030000          <1> 	call	cmp_cmd	
 17080 000052AF 7208                <1> 	jc	short cmp_cmd_date
 17081                              <1> 
 17082 000052B1 C605[34CE0000]01    <1>         mov     byte [Program_Exit], 1
 17083 000052B8 C3                  <1>         retn
 17084                              <1> 
 17085                              <1> cmp_cmd_date:
 17086 000052B9 B104                <1> 	mov	cl, 4
 17087 000052BB BF[7FB50000]        <1> 	mov	edi, Cmd_Date
 17088 000052C0 E8B4030000          <1> 	call	cmp_cmd	
 17089 000052C5 720B                <1>         jc	short cmp_cmd_time
 17090                              <1> 	
 17091 000052C7 E8D0F7FFFF          <1> 	call	show_date
 17092 000052CC E80FF8FFFF          <1> 	call	set_date
 17093 000052D1 C3                  <1> 	retn
 17094                              <1> 
 17095                              <1> cmp_cmd_time:
 17096 000052D2 B104                <1> 	mov	cl, 4
 17097 000052D4 BF[84B50000]        <1> 	mov	edi, Cmd_Time
 17098 000052D9 E89B030000          <1>    	call	cmp_cmd	
 17099 000052DE 720B                <1> 	jc	short cmp_cmd_show
 17100                              <1> 
 17101 000052E0 E8C6FAFFFF          <1> 	call	show_time
 17102 000052E5 E8F8FAFFFF          <1> 	call	set_time
 17103 000052EA C3                  <1> 	retn
 17104                              <1> 
 17105                              <1> cmp_cmd_show:
 17106 000052EB B104                <1> 	mov	cl, 4
 17107 000052ED BF[95B50000]        <1> 	mov	edi, Cmd_Show
 17108 000052F2 E882030000          <1>    	call	cmp_cmd	
 17109 000052F7 0F83F1090000        <1>         jnc     show_file
 17110                              <1> 
 17111                              <1> cmp_cmd_echo:
 17112 000052FD B104                <1> 	mov	cl, 4
 17113 000052FF BF[DAB50000]        <1> 	mov	edi, Cmd_Echo
 17114 00005304 E870030000          <1>    	call	cmp_cmd	
 17115 00005309 721B                <1> 	jc	short cmp_cmd_copy
 17116                              <1> 
 17117                              <1> 	; 14/04/2016
 17118 0000530B 56                  <1> 	push	esi
 17119                              <1> cmd_echo_asciiz:
 17120 0000530C 46                  <1>         inc	esi
 17121 0000530D 8A06                <1> 	mov	al, [esi]
 17122 0000530F 3C20                <1> 	cmp	al, 20h
 17123 00005311 73F9                <1> 	jnb	short cmd_echo_asciiz
 17124 00005313 C60600              <1> 	mov	byte [esi], 0                 
 17125 00005316 5E                  <1> 	pop	esi  
 17126 00005317 E8AEEBFFFF          <1> 	call	print_msg
 17127 0000531C BE[03C20000]        <1> 	mov	esi, NextLine
 17128                              <1> 	;call	print_msg   
 17129                              <1> 	;retn
 17130 00005321 E9A4EBFFFF          <1> 	jmp	print_msg
 17131                              <1> 
 17132                              <1> cmp_cmd_copy:
 17133 00005326 B104                <1> 	mov	cl, 4
 17134 00005328 BF[B8B50000]        <1> 	mov	edi, Cmd_Copy
 17135 0000532D E847030000          <1>    	call	cmp_cmd	
 17136 00005332 0F83F8170000        <1> 	jnc	copy_file
 17137                              <1> 
 17138                              <1> cmp_cmd_move:
 17139 00005338 B104                <1> 	mov	cl, 4
 17140 0000533A BF[BDB50000]        <1> 	mov	edi, Cmd_Move
 17141 0000533F E835030000          <1>    	call	cmp_cmd	
 17142 00005344 0F838C160000        <1> 	jnc	move_file
 17143                              <1> 
 17144                              <1> cmp_cmd_path:
 17145 0000534A B104                <1> 	mov	cl, 4
 17146 0000534C BF[C2B50000]        <1> 	mov	edi, Cmd_Path
 17147 00005351 E823030000          <1>    	call	cmp_cmd	
 17148 00005356 0F832C1A0000        <1> 	jnc	set_get_path
 17149                              <1> 
 17150                              <1> cmp_cmd_beep:
 17151 0000535C B104                <1> 	mov	cl, 4
 17152 0000535E BF[F8B50000]        <1> 	mov	edi, Cmd_Beep
 17153 00005363 E811030000          <1>    	call	cmp_cmd	
 17154 00005368 0F8327C5FFFF        <1> 	jnc	beeper
 17155                              <1> 
 17156                              <1> cmp_cmd_find:
 17157 0000536E B104                <1> 	mov	cl, 4
 17158 00005370 BF[CCB50000]        <1> 	mov	edi, Cmd_Find
 17159 00005375 E8FF020000          <1>    	call	cmp_cmd	
 17160 0000537A 0F82E6020000        <1>         jc      loc_cmd_failed
 17161                              <1> 
 17162                              <1> 	;call	find_and_list_files
 17163 00005380 E9BA1F0000          <1> 	jmp	find_and_list_files
 17164                              <1> 	;retn
 17165                              <1> 
 17166                              <1> c_1:
 17167 00005385 AD                  <1> 	lodsd
 17168                              <1> cmp_cmd_help:
 17169 00005386 3C3F                <1> 	cmp	al, '?'
 17170 00005388 751D                <1>         jne     short cmp_cmd_remark
 17171                              <1> 
 17172 0000538A BE[55B50000]        <1> 	mov	esi, Command_List
 17173                              <1> cmd_help_next_w:
 17174 0000538F E836EBFFFF          <1> 	call	print_msg
 17175                              <1> 
 17176 00005394 803E20              <1> 	cmp	byte [esi], 20h ; 0
 17177 00005397 7232                <1> 	jb	short cmd_help_retn
 17178                              <1> 	
 17179 00005399 56                  <1> 	push	esi
 17180 0000539A BE[56C10000]        <1> 	mov	esi, nextline
 17181 0000539F E826EBFFFF          <1> 	call	print_msg
 17182 000053A4 5E                  <1> 	pop	esi
 17183 000053A5 EBE8                <1> 	jmp	short cmd_help_next_w	
 17184                              <1> 
 17185                              <1> cmp_cmd_remark:
 17186 000053A7 3C2A                <1> 	cmp	al, '*'
 17187 000053A9 0F85B7020000        <1>         jne     loc_cmd_failed
 17188 000053AF 46                  <1> 	inc	esi
 17189 000053B0 BF[A4C50000]        <1> 	mov	edi, Remark
 17190 000053B5 8A06                <1> 	mov	al, [esi]
 17191 000053B7 3C20                <1> 	cmp	al, 20h
 17192 000053B9 7707                <1> 	ja	short cmd_remark_write
 17193 000053BB 89FE                <1> 	mov	esi, edi ; Remark
 17194 000053BD E908EBFFFF          <1> 	jmp	print_msg
 17195                              <1> 
 17196                              <1> cmd_remark_write:
 17197 000053C2 AA                  <1> 	stosb
 17198 000053C3 AC                  <1> 	lodsb
 17199 000053C4 3C20                <1> 	cmp	al, 20h
 17200 000053C6 73FA                <1> 	jnb	short cmd_remark_write
 17201 000053C8 C60700              <1> 	mov	byte [edi], 0
 17202                              <1> 
 17203                              <1> cmd_help_retn:
 17204                              <1> cmd_remark_retn:
 17205                              <1> cd_retn:
 17206 000053CB C3                  <1> 	retn
 17207                              <1> 
 17208                              <1> c_2:
 17209 000053CC 80F902              <1> 	cmp	cl, 2
 17210 000053CF 0F87B1000000        <1>         ja      c_3
 17211 000053D5 BE[F2C50000]        <1> 	mov	esi, CommandBuffer
 17212 000053DA 72A9                <1> 	jb	short c_1
 17213                              <1> 
 17214                              <1> cmp_cmd_cd:
 17215 000053DC 66AD                <1> 	lodsw
 17216 000053DE 663D4344            <1> 	cmp	ax, 'CD'
 17217 000053E2 7553                <1> 	jne	short cmp_cmd_drive
 17218 000053E4 46                  <1>         inc	esi
 17219                              <1> cd_0:
 17220 000053E5 668B06              <1> 	mov	ax, [esi]	
 17221 000053E8 3C20                <1> 	cmp	al, 20h
 17222 000053EA 76DF                <1> 	jna	short cd_retn
 17223                              <1> 	; 10/02/2016
 17224 000053EC 80FC3A              <1> 	cmp	ah, ':'
 17225 000053EF 7504                <1> 	jne	short cd_1
 17226 000053F1 46                  <1> 	inc	esi
 17227 000053F2 46                  <1> 	inc	esi
 17228 000053F3 EB4B                <1> 	jmp	short cd_2
 17229                              <1> 
 17230                              <1> cd_1:	; change current directory
 17231                              <1> 	; 29/11/2009
 17232                              <1> 	; AH = CDh	; to separate 'CD' command from others
 17233                              <1> 			; for restoring current directory
 17234                              <1> 			; 0CDh sign is for saving cdir into 
 17235                              <1> 			; DOS drv description table cdir area
 17236                              <1> 	
 17237 000053F5 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
 17238                              <1> 
 17239 000053F7 E829200000          <1> 	call	change_current_directory
 17240 000053FC 0F83431F0000        <1>         jnc     change_prompt_dir_string
 17241                              <1> 
 17242                              <1> cd_error_messages:
 17243 00005402 3C03                <1> 	cmp	al, 3
 17244 00005404 740C                <1> 	je	short cd_path_not_found
 17245 00005406 3C15                <1> 	cmp	al, 15h 
 17246 00005408 745B                <1> 	je	short cd_drive_not_ready
 17247 0000540A 3C18                <1> 	cmp	al, 18h ; Bad request structure length 
 17248 0000540C 746C                <1> 	je	short cd_command_failed
 17249 0000540E 3C1A                <1> 	cmp	al, 1Ah ; Unknown media type, non-DOS disk
 17250 00005410 7468                <1>         je      short cd_command_failed
 17251                              <1> 
 17252                              <1> cd_path_not_found:
 17253 00005412 6650                <1> 	push	ax	
 17254 00005414 BE[01B80000]        <1> 	mov	esi, Msg_Dir_Not_Found
 17255 00005419 E8ACEAFFFF          <1> 	call	print_msg
 17256 0000541E 6658                <1> 	pop	ax
 17257 00005420 3A25[40C50000]      <1> 	cmp	ah, [Current_Dir_Level]
 17258 00005426 0F83191F0000        <1>         jnb     change_prompt_dir_string
 17259 0000542C 8825[40C50000]      <1> 	mov	[Current_Dir_Level], ah
 17260 00005432 E90E1F0000          <1>         jmp     change_prompt_dir_string   
 17261                              <1> 
 17262                              <1> cmp_cmd_drive: ; change current drive
 17263                              <1> 	; C:, D:, E: etc.
 17264 00005437 80FC3A              <1> 	cmp	ah, ':'
 17265 0000543A 0F8526020000        <1>         jne     loc_cmd_failed
 17266                              <1> 
 17267                              <1> cd_2:	; 'CD C:', 'CD D:' ...
 17268 00005440 803E20              <1> 	cmp	byte [esi], 20h
 17269 00005443 0F871D020000        <1>         ja      loc_cmd_failed
 17270                              <1> 
 17271 00005449 24DF                <1> 	and	al, 0DFh
 17272 0000544B 2C41                <1> 	sub	al, 'A'
 17273 0000544D 0F8213020000        <1>         jc      loc_cmd_failed
 17274                              <1> 
 17275 00005453 3A05[F5B40000]      <1>         cmp     al, [Last_DOS_DiskNo]
 17276 00005459 770A                <1>         ja	short cd_drive_not_ready
 17277                              <1> 	
 17278 0000545B 88C2                <1> 	mov	dl, al
 17279 0000545D E86CF3FFFF          <1> 	call 	change_current_drive
 17280 00005462 7201                <1> 	jc	short cd_drive_not_ready	
 17281 00005464 C3                  <1> 	retn
 17282                              <1> 
 17283                              <1> cd_drive_not_ready:
 17284 00005465 BE[BEB70000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17285 0000546A E85BEAFFFF          <1> 	call	print_msg
 17286                              <1> 
 17287                              <1> cd_fail_drive_restart:
 17288 0000546F 8A15[42C50000]      <1> 	mov	dl, [Current_Drv]
 17289                              <1> 	;call 	change_current_drive
 17290 00005475 E954F3FFFF          <1>         jmp     change_current_drive
 17291                              <1> 	;retn
 17292                              <1> 
 17293                              <1> cd_command_failed:
 17294 0000547A BE[9FB70000]        <1> 	mov	esi, Msg_Bad_Command
 17295 0000547F E846EAFFFF          <1> 	call	print_msg
 17296 00005484 EBE9                <1> 	jmp	short cd_fail_drive_restart
 17297                              <1> 
 17298                              <1> c_3:
 17299                              <1> cmp_cmd_dir:
 17300 00005486 BF[55B50000]        <1> 	mov	edi, Cmd_Dir
 17301 0000548B E8E9010000          <1> 	call	cmp_cmd	
 17302 00005490 0F8388020000        <1> 	jnc	print_directory_list
 17303                              <1> 
 17304                              <1> cmp_cmd_cls:
 17305 00005496 B103                <1> 	mov	cl, 3
 17306 00005498 BF[91B50000]        <1> 	mov	edi, Cmd_Cls
 17307 0000549D E8D7010000          <1> 	call	cmp_cmd	
 17308 000054A2 0F8339EAFFFF        <1>         jnc	clear_screen
 17309                              <1> 
 17310                              <1> cmp_cmd_ver:
 17311 000054A8 B103                <1> 	mov	cl, 3
 17312 000054AA BF[5FB50000]        <1> 	mov	edi, Cmd_Ver
 17313 000054AF E8C5010000          <1> 	call	cmp_cmd	
 17314 000054B4 720A                <1> 	jc	short cmp_cmd_mem
 17315                              <1> 
 17316 000054B6 BE[FDB40000]        <1> 	mov	esi, mainprog_Version
 17317                              <1> 	;call	print_msg
 17318 000054BB E90AEAFFFF          <1> 	jmp	print_msg
 17319                              <1> 	;retn
 17320                              <1> 
 17321                              <1> cmp_cmd_mem:
 17322 000054C0 B103                <1> 	mov	cl, 3
 17323 000054C2 BF[C7B50000]        <1> 	mov	edi, Cmd_Mem
 17324 000054C7 E8AD010000          <1> 	call	cmp_cmd	
 17325 000054CC 0F835FC4FFFF        <1> 	jnc	memory_info
 17326                              <1> 
 17327                              <1> cmp_cmd_del:
 17328 000054D2 B103                <1> 	mov	cl, 3
 17329 000054D4 BF[9AB50000]        <1> 	mov	edi, Cmd_Del
 17330 000054D9 E89B010000          <1> 	call	cmp_cmd	
 17331 000054DE 0F83320F0000        <1>         jnc     delete_file
 17332                              <1> 
 17333                              <1> cmp_cmd_set:
 17334 000054E4 B103                <1> 	mov	cl, 3
 17335 000054E6 BF[8DB50000]        <1> 	mov	edi, Cmd_Set
 17336 000054EB E889010000          <1> 	call	cmp_cmd	
 17337 000054F0 0F830A180000        <1>         jnc     set_get_env
 17338                              <1> 
 17339                              <1> cmp_cmd_run:
 17340 000054F6 B103                <1> 	mov	cl, 3
 17341 000054F8 BF[89B50000]        <1> 	mov	edi, Cmd_Run
 17342 000054FD E877010000          <1> 	call	cmp_cmd	
 17343 00005502 0F825E010000        <1>         jc      loc_cmd_failed
 17344                              <1> 
 17345 00005508 E8331E0000          <1> 	call	set_exec_arguments
 17346 0000550D 0F8253010000        <1>         jc      loc_cmd_failed
 17347                              <1> 
 17348 00005513 E8291E0000          <1> 	call	load_and_execute_file
 17349 00005518 0F8273010000        <1>         jc      loc_run_cmd_failed
 17350 0000551E C3                  <1> 	retn
 17351                              <1> 
 17352                              <1> c_5:
 17353                              <1> cmp_cmd_mkdir:
 17354 0000551F BF[B2B50000]        <1> 	mov	edi, Cmd_Mkdir
 17355 00005524 E850010000          <1> 	call	cmp_cmd	
 17356 00005529 0F837F0A0000        <1>         jnc     make_directory
 17357                              <1> 
 17358                              <1> cmp_cmd_rmdir:
 17359 0000552F B105                <1> 	mov	cl, 5
 17360 00005531 BF[ACB50000]        <1> 	mov	edi, Cmd_Rmdir
 17361 00005536 E83E010000          <1> 	call	cmp_cmd	
 17362 0000553B 0F838C0B0000        <1>         jnc     delete_directory
 17363                              <1> 
 17364                              <1> cmp_cmd_chdir:
 17365 00005541 B105                <1> 	mov	cl, 5
 17366 00005543 BF[F2B50000]        <1> 	mov	edi, Cmd_Chdir
 17367 00005548 E82C010000          <1> 	call	cmp_cmd	
 17368 0000554D 0F8213010000        <1> 	jc	loc_cmd_failed
 17369                              <1> 
 17370 00005553 E98DFEFFFF          <1> 	jmp	cd_0
 17371                              <1> 
 17372                              <1> c_6:
 17373 00005558 80F906              <1> 	cmp	cl, 6
 17374 0000555B 0F87DF000000        <1>         ja      c_8
 17375 00005561 72BC                <1> 	jb	short c_5
 17376                              <1> cmp_cmd_prompt:
 17377 00005563 BF[68B50000]        <1> 	mov	edi, Cmd_Prompt
 17378 00005568 E80C010000          <1> 	call	cmp_cmd	
 17379 0000556D 722E                <1>         jc	short cmp_cmd_volume
 17380                              <1> get_prompt_name_fchar:
 17381 0000556F AC                  <1> 	lodsb
 17382 00005570 3C20                <1> 	cmp	al, 20h
 17383 00005572 74FB                <1> 	je	short get_prompt_name_fchar
 17384 00005574 7712                <1> 	ja	short loc_change_prompt_label
 17385 00005576 BE[49B50000]        <1> 	mov	esi, TRDOSPromptLabel
 17386 0000557B C7065452444F        <1> 	mov	dword [esi], "TRDO"
 17387 00005581 66C746045300        <1>        	mov	word [esi+4], "S" 
 17388                              <1> loc_cmd_prompt_return:
 17389 00005587 C3                  <1> 	retn
 17390                              <1> loc_change_prompt_label:
 17391 00005588 66B90B00            <1> 	mov	cx, 11
 17392 0000558C BF[49B50000]        <1> 	mov	edi, TRDOSPromptLabel
 17393                              <1> put_char_new_prompt_label:
 17394 00005591 AA                  <1> 	stosb
 17395 00005592 AC                  <1> 	lodsb
 17396 00005593 3C20                <1> 	cmp	al, 20h
 17397 00005595 7202                <1> 	jb	short pass_put_new_prompt_label
 17398 00005597 E2F8                <1> 	loop	put_char_new_prompt_label
 17399                              <1> pass_put_new_prompt_label:
 17400 00005599 C60700              <1> 	mov	byte [edi], 0
 17401 0000559C C3                  <1> 	retn
 17402                              <1> 
 17403                              <1> cmp_cmd_volume:
 17404 0000559D B106                <1> 	mov	cl, 6
 17405 0000559F BF[6FB50000]        <1> 	mov	edi, Cmd_Volume
 17406 000055A4 E8D0000000          <1> 	call	cmp_cmd	
 17407 000055A9 7255                <1>         jc	short cmp_cmd_attrib
 17408                              <1> 
 17409                              <1> cmd_vol1:
 17410 000055AB AC                  <1> 	lodsb
 17411 000055AC 3C20                <1> 	cmp	al, 20h
 17412 000055AE 7707                <1> 	ja	short cmd_vol2
 17413 000055B0 A0[42C50000]        <1> 	mov	al, [Current_Drv]
 17414 000055B5 EB3D                <1> 	jmp	short cmd_vol4
 17415                              <1> cmd_vol2:
 17416 000055B7 3C41                <1> 	cmp	al, 'A'
 17417 000055B9 0F82A7000000        <1>         jb      loc_cmd_failed
 17418 000055BF 3C7A                <1> 	cmp	al, 'z'
 17419 000055C1 0F879F000000        <1>         ja      loc_cmd_failed
 17420 000055C7 3C5A                <1> 	cmp	al, 'Z'
 17421 000055C9 760A                <1> 	jna	short cmd_vol3
 17422 000055CB 3C61                <1> 	cmp	al, 'a'
 17423 000055CD 0F8293000000        <1>         jb      loc_cmd_failed
 17424 000055D3 24DF                <1> 	and	al, 0DFh
 17425                              <1> cmd_vol3:
 17426 000055D5 8A26                <1> 	mov	ah, [esi]
 17427 000055D7 80FC3A              <1> 	cmp	ah, ':'
 17428 000055DA 0F8586000000        <1>         jne     loc_cmd_failed
 17429 000055E0 2C41                <1> 	sub	al, 'A'
 17430 000055E2 3A05[F5B40000]      <1>         cmp     al, [Last_DOS_DiskNo]
 17431 000055E8 760A                <1> 	jna	short cmd_vol4
 17432                              <1> 
 17433 000055EA BE[BEB70000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17434 000055EF E9D6E8FFFF          <1> 	jmp	print_msg
 17435                              <1> 	
 17436                              <1> cmd_vol4:
 17437 000055F4 E88BFAFFFF          <1> 	call	print_volume_info
 17438 000055F9 0F8266FEFFFF        <1>         jc      cd_drive_not_ready
 17439 000055FF C3                  <1> 	retn
 17440                              <1> 
 17441                              <1> cmp_cmd_attrib:
 17442 00005600 B106                <1> 	mov	cl, 6
 17443 00005602 BF[9EB50000]        <1> 	mov	edi, Cmd_Attrib
 17444 00005607 E86D000000          <1> 	call	cmp_cmd	
 17445 0000560C 0F83240F0000        <1>         jnc     set_file_attributes
 17446                              <1> 
 17447                              <1> cmp_cmd_rename:
 17448 00005612 B106                <1> 	mov	cl, 6
 17449 00005614 BF[A5B50000]        <1> 	mov	edi, Cmd_Rename
 17450 00005619 E85B000000          <1> 	call	cmp_cmd	
 17451 0000561E 0F835A110000        <1>         jnc     rename_file
 17452                              <1> 
 17453                              <1> cmp_cmd_device:
 17454 00005624 B106                <1> 	mov	cl, 6
 17455 00005626 BF[E3B50000]        <1> 	mov	edi, Cmd_Device
 17456 0000562B E849000000          <1> 	call	cmp_cmd	
 17457 00005630 7234                <1>         jc	short loc_cmd_failed
 17458                              <1> 
 17459 00005632 C3                  <1> 	retn
 17460                              <1> 
 17461                              <1> c_7:
 17462                              <1> cmp_cmd_devlist:
 17463 00005633 BF[EAB50000]        <1> 	mov	edi, Cmd_DevList
 17464 00005638 E83C000000          <1> 	call	cmp_cmd	
 17465 0000563D 7227                <1>         jc	short loc_cmd_failed
 17466                              <1> 
 17467 0000563F C3                  <1> 	retn
 17468                              <1> 
 17469                              <1> c_8:
 17470 00005640 80F908              <1>         cmp	cl, 8
 17471 00005643 7721                <1> 	ja	short cmp_cmd_external
 17472 00005645 72EC                <1> 	jb	short c_7
 17473                              <1> 
 17474                              <1> cmp_cmd_longname:
 17475 00005647 BF[76B50000]        <1> 	mov	edi, Cmd_LongName
 17476 0000564C E828000000          <1> 	call	cmp_cmd	
 17477 00005651 0F8341060000        <1>         jnc     get_and_print_longname
 17478                              <1> 
 17479                              <1> cmp_cmd_readfile:
 17480 00005657 B108                <1> 	mov	cl, 8
 17481 00005659 BF[D1B50000]        <1> 	mov	edi, Cmd_ReadFile
 17482 0000565E E816000000          <1> 	call	cmp_cmd	
 17483 00005663 7201                <1>         jc	short loc_cmd_failed
 17484                              <1> 
 17485                              <1> loc_cmd_return:
 17486 00005665 C3                  <1> 	retn
 17487                              <1> 
 17488                              <1> cmp_cmd_external:
 17489                              <1> loc_cmd_failed:
 17490 00005666 803D[F2C50000]20    <1> 	cmp	byte [CommandBuffer], 20h
 17491 0000566D 76F6                <1> 	jna	short loc_cmd_return
 17492 0000566F BE[9FB70000]        <1> 	mov	esi, Msg_Bad_Command
 17493                              <1> ;	call	print_msg
 17494                              <1> ;loc_cmd_return:
 17495                              <1> ;	retn
 17496 00005674 E951E8FFFF          <1> 	jmp	print_msg
 17497                              <1> 
 17498                              <1> cmp_cmd:
 17499                              <1> 	 ; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
 17500 00005679 BE[F2C50000]        <1>          mov  esi, CommandBuffer
 17501                              <1>          ; edi = internal command word (ASCIIZ)
 17502                              <1> 	 ; ecx = command length (<=8)
 17503                              <1> cmp_cmd_1:
 17504 0000567E AC                  <1> 	lodsb
 17505 0000567F AE                  <1> 	scasb
 17506 00005680 750D                <1> 	jne	short cmp_cmd_3
 17507 00005682 E2FA                <1> 	loop	cmp_cmd_1
 17508 00005684 AC                  <1>  	lodsb
 17509 00005685 3C20                <1> 	cmp	al, 20h
 17510 00005687 7703                <1> 	ja	short cmp_cmd_2
 17511 00005689 30C0                <1> 	xor	al, al
 17512                              <1> 	; ZF = 1 -> internal command word matches
 17513 0000568B C3                  <1> 	retn
 17514                              <1> cmp_cmd_2:
 17515                              <1> 	; ZF = 0 (CF = 0) -> external command word 	
 17516 0000568C 58                  <1> 	pop	eax ; no return to the caller from here 
 17517 0000568D EBD7                <1> 	jmp	cmp_cmd_external	
 17518                              <1> cmp_cmd_3:
 17519 0000568F F9                  <1> 	stc
 17520                              <1> 	; CF = 1 -> internal command word does not match
 17521 00005690 C3                  <1> 	retn
 17522                              <1> 
 17523                              <1> loc_run_cmd_failed:
 17524                              <1> 	; 15/03/2016
 17525                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17526                              <1> 	; 07/12/2009 (CMD_INTR.ASM)	
 17527                              <1> 	; 29/11/2009
 17528                              <1> 
 17529 00005691 E855000000          <1> 	call	restore_cdir_after_cmd_fail
 17530                              <1> 
 17531                              <1> loc_run_cmd_failed_cmp_al:
 17532                              <1> 	; End of Restore_CDIR code (29/11/2009)
 17533                              <1> 
 17534 00005696 3C01                <1> 	cmp	al, 1
 17535 00005698 74CC                <1> 	je	loc_cmd_failed
 17536                              <1> loc_run_dir_not_found:
 17537 0000569A 3C03                <1> 	cmp	al, 3
 17538 0000569C 750A                <1> 	jne	short loc_run_file_notfound_msg
 17539                              <1> 	; Path not found (MS-DOS Error Code = 3)
 17540 0000569E BE[01B80000]        <1> 	mov	esi, Msg_Dir_Not_Found
 17541 000056A3 E922E8FFFF          <1> 	jmp	print_msg
 17542                              <1> 
 17543                              <1> loc_run_file_notfound_msg:
 17544 000056A8 3C02                <1> 	cmp	al, 2 ; File not found
 17545 000056AA 750A                <1> 	jne	short loc_run_file_drv_read_err
 17546                              <1> 
 17547                              <1> loc_print_file_notfound_msg: 
 17548 000056AC BE[18B80000]        <1>         mov     esi, Msg_File_Not_Found
 17549                              <1> 	;call	proc_printmsg
 17550                              <1> 	;retn
 17551 000056B1 E914E8FFFF          <1> 	jmp	print_msg
 17552                              <1> 
 17553                              <1> loc_run_file_drv_read_err:
 17554                              <1> 	; Err: 1Eh (Read fault)
 17555 000056B6 3C1E                <1> 	cmp	al, 1Eh ; Drive not ready or read error
 17556 000056B8 7404                <1> 	je	short loc_run_file_print_drv_read_err
 17557                              <1> 	;
 17558 000056BA 3C15                <1> 	cmp	al, 15h ; Drive not ready (or read error)
 17559 000056BC 750A                <1> 	jne	short loc_run_file_toobig
 17560                              <1> 
 17561                              <1> loc_run_file_print_drv_read_err:
 17562 000056BE BE[BEB70000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17563 000056C3 E902E8FFFF          <1> 	jmp	print_msg
 17564                              <1> 
 17565                              <1> loc_run_file_toobig:
 17566 000056C8 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
 17567 000056CA 750A                <1> 	jne	short loc_run_misc_error
 17568 000056CC BE[60B80000]        <1> 	mov	esi, Msg_Insufficient_Memory
 17569 000056D1 E9F4E7FFFF          <1> 	jmp	print_msg
 17570                              <1> 
 17571                              <1> 	; 15/03/2016
 17572                              <1> print_misc_error_msg:
 17573                              <1> loc_run_misc_error:
 17574                              <1> 	; AL = Error code
 17575 000056D6 E8CCC2FFFF          <1> 	call	bytetohex
 17576 000056DB 66A3[94B80000]      <1>         mov     [error_code_hex], ax
 17577                              <1> 	
 17578 000056E1 BE[77B80000]        <1> 	mov	esi, Msg_Error_Code 
 17579                              <1> 	;call	print_msg 
 17580                              <1> 	;retn
 17581                              <1> 
 17582 000056E6 E9DFE7FFFF          <1> 	jmp	print_msg
 17583                              <1> 
 17584                              <1> restore_cdir_after_cmd_fail:
 17585                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17586 000056EB 50                  <1> 	push	eax
 17587 000056EC 8A3D[A2CD0000]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
 17588                              <1> 				; of the 'run' command.
 17589 000056F2 3A3D[42C50000]      <1> 	cmp	bh, [Current_Drv]
 17590 000056F8 7409                <1> 	je	short loc_run_restore_cdir
 17591 000056FA 88FA                <1> 	mov	dl, bh
 17592 000056FC E8CDF0FFFF          <1> 	call	change_current_drive 
 17593 00005701 EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
 17594                              <1> 
 17595                              <1> loc_run_restore_cdir:
 17596 00005703 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17597 0000570A 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
 17598 0000570C 30DB                <1> 	xor	bl, bl
 17599 0000570E 0FB7F3              <1> 	movzx	esi, bx
 17600 00005711 81C600010900        <1> 	add	esi, Logical_DOSDisks
 17601 00005717 E864F1FFFF          <1> 	call	restore_current_directory
 17602                              <1> 
 17603                              <1> loc_run_err_pass_restore_cdir:
 17604 0000571C 58                  <1> 	pop	eax
 17605 0000571D C3                  <1> 	retn
 17606                              <1> 
 17607                              <1> print_directory_list:
 17608                              <1> 	; 10/02/2016
 17609                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17610                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
 17611                              <1> 	;
 17612 0000571E 66C705[E4CE0000]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
 17613 00005726 08                  <1>
 17614 00005727 A0[42C50000]        <1> 	mov	al, [Current_Drv]
 17615 0000572C A2[A2CD0000]        <1> 	mov	[RUN_CDRV], al
 17616                              <1> get_dfname_fchar:
 17617 00005731 AC                  <1> 	lodsb
 17618 00005732 3C20                <1> 	cmp	al, 20h
 17619 00005734 74FB                <1> 	je	short get_dfname_fchar
 17620 00005736 0F82A4000000        <1>         jb      loc_print_dir_call_all
 17621 0000573C 3C2D                <1> 	cmp	al, '-'
 17622 0000573E 7542                <1> 	jne	short loc_print_dir_call_flt
 17623                              <1> get_next_attr_char:
 17624 00005740 AC                  <1> 	lodsb
 17625 00005741 3C20                <1> 	cmp	al, 20h
 17626 00005743 74FB                <1> 	je	short get_next_attr_char
 17627 00005745 0F821BFFFFFF        <1>         jb      loc_cmd_failed
 17628 0000574B 24DF                <1> 	and	al, 0DFh
 17629 0000574D 3C44                <1> 	cmp	al, 'D' ; directories only ?
 17630 0000574F 7512                <1> 	jne	short pass_only_directories
 17631 00005751 AC                  <1> 	lodsb
 17632 00005752 3C20                <1> 	cmp	al, 20h
 17633 00005754 0F870CFFFFFF        <1>         ja      loc_cmd_failed
 17634 0000575A 800D[E4CE0000]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
 17635 00005761 EB18                <1> 	jmp	short get_dfname_fchar_attr
 17636                              <1> pass_only_directories:
 17637 00005763 3C46                <1> 	cmp	al, 'F'	; files only ?
 17638 00005765 0F85B0000000        <1>         jne     check_attr_s
 17639 0000576B AC                  <1> 	lodsb
 17640 0000576C 3C20                <1> 	cmp	al, 20h
 17641 0000576E 0F87F2FEFFFF        <1>         ja      loc_cmd_failed
 17642 00005774 800D[E5CE0000]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
 17643                              <1> get_dfname_fchar_attr:
 17644 0000577B AC                  <1> 	lodsb
 17645 0000577C 3C20                <1> 	cmp	al, 20h
 17646 0000577E 74FB                <1> 	je	short get_dfname_fchar_attr
 17647 00005780 725E                <1> 	jb	short loc_print_dir_call_all
 17648                              <1> 
 17649                              <1> loc_print_dir_call_flt:
 17650 00005782 4E                  <1> 	dec	esi
 17651 00005783 BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 17652 00005788 E8AC220000          <1> 	call	parse_path_name
 17653 0000578D 7308                <1>  	jnc	short loc_print_dir_change_drv_1
 17654 0000578F 3C01                <1> 	cmp	al, 1
 17655 00005791 0F87FAFEFFFF        <1>         ja      loc_run_cmd_failed
 17656                              <1> 
 17657                              <1> loc_print_dir_change_drv_1:
 17658 00005797 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 17659                              <1> loc_print_dir_change_drv_2:
 17660 0000579D 3A15[A2CD0000]      <1> 	cmp	dl, [RUN_CDRV]
 17661 000057A3 740B                <1> 	je	short loc_print_dir_change_directory 
 17662 000057A5 E824F0FFFF          <1> 	call	change_current_drive
 17663 000057AA 0F82E1FEFFFF        <1>         jc      loc_run_cmd_failed
 17664                              <1> loc_print_dir_change_directory:
 17665 000057B0 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
 17666 000057B7 761D                <1> 	jna	short pass_print_dir_change_directory
 17667                              <1> 
 17668 000057B9 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 17669 000057BF BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 17670 000057C4 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 17671 000057C6 E85A1C0000          <1> 	call	change_current_directory
 17672 000057CB 0F82C0FEFFFF        <1>         jc      loc_run_cmd_failed
 17673                              <1> 
 17674                              <1> loc_print_dir_change_prompt_dir_string:
 17675 000057D1 E86F1B0000          <1> 	call	change_prompt_dir_string
 17676                              <1> 
 17677                              <1> pass_print_dir_change_directory:
 17678 000057D6 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 17679 000057DB 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
 17680 000057DE 7706                <1> 	ja	short loc_print_dir_call
 17681                              <1> 
 17682                              <1> loc_print_dir_call_all:
 17683 000057E0 C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
 17684                              <1> loc_print_dir_call:
 17685 000057E6 E87E000000          <1> 	call	print_directory
 17686                              <1> 
 17687 000057EB 8A15[A2CD0000]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
 17688 000057F1 3A15[42C50000]      <1> 	cmp	dl, [Current_Drv]
 17689 000057F7 7406                <1> 	je	short loc_print_dir_call_restore_cdir_retn
 17690 000057F9 E8D0EFFFFF          <1> 	call	change_current_drive 
 17691 000057FE C3                  <1> 	retn
 17692                              <1> 
 17693                              <1> loc_print_dir_call_restore_cdir_retn:
 17694 000057FF 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17695 00005806 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
 17696                              <1> 
 17697 00005808 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17698 0000580D 31C0                <1> 	xor	eax, eax
 17699 0000580F 88D4                <1> 	mov	ah, dl
 17700 00005811 01C6                <1> 	add	esi, eax
 17701                              <1> 
 17702 00005813 E868F0FFFF          <1> 	call	restore_current_directory
 17703                              <1> 
 17704                              <1> pass_print_dir_call_restore_cdir_retn:
 17705 00005818 C3                  <1> 	retn
 17706                              <1> 
 17707                              <1> check_attr_s_cap:
 17708 00005819 24DF                <1> 	and	al, 0DFh
 17709                              <1> check_attr_s:
 17710 0000581B 3C53                <1> 	cmp	al, 'S'
 17711 0000581D 7514                <1> 	jne	short pass_attr_s
 17712 0000581F 800D[E4CE0000]04    <1> 	or	byte [AttributesMask], 4 ; system
 17713 00005826 AC                  <1> 	lodsb
 17714 00005827 3C20                <1> 	cmp	al, 20h
 17715 00005829 0F844CFFFFFF        <1>         je      get_dfname_fchar_attr
 17716 0000582F 72AF                <1> 	jb	short loc_print_dir_call_all
 17717 00005831 24DF                <1> 	and	al, 0DFh
 17718                              <1> pass_attr_s:
 17719 00005833 3C48                <1> 	cmp	al, 'H'
 17720 00005835 7514                <1> 	jne	short pass_attr_h
 17721 00005837 800D[E4CE0000]02    <1> 	or	byte [AttributesMask], 2 ; hidden
 17722                              <1> pass_attr_shr:
 17723 0000583E AC                  <1> 	lodsb
 17724 0000583F 3C20                <1> 	cmp	al, 20h
 17725 00005841 0F8434FFFFFF        <1>         je      get_dfname_fchar_attr
 17726 00005847 7297                <1> 	jb	short loc_print_dir_call_all
 17727 00005849 EBCE                <1> 	jmp	short check_attr_s_cap
 17728                              <1> 
 17729                              <1> pass_attr_h:
 17730 0000584B 3C52                <1> 	cmp	al, 'R'
 17731 0000584D 7509                <1> 	jne	short pass_attr_r
 17732 0000584F 800D[E4CE0000]01    <1> 	or	byte [AttributesMask], 1 ; read only
 17733 00005856 EBE6                <1> 	jmp	short pass_attr_shr
 17734                              <1> 
 17735                              <1> pass_attr_r:
 17736 00005858 3C41                <1> 	cmp	al, 'A'
 17737 0000585A 0F8506FEFFFF        <1>         jne     loc_cmd_failed
 17738 00005860 800D[E4CE0000]20    <1> 	or	byte [AttributesMask], 20h ; archive
 17739 00005867 EBD5                <1> 	jmp	short pass_attr_shr
 17740                              <1> 
 17741                              <1> print_directory:
 17742                              <1> 	; 11/02/2016
 17743                              <1> 	; 10/02/2016
 17744                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17745                              <1> 	; 30/10/2010 ('proc_print_directory')	
 17746                              <1> 	; 19/09/2009
 17747                              <1> 	; 2005 
 17748                              <1> 	; INPUT ->
 17749                              <1> 	;	ESI = Asciiz File/Dir Name Address
 17750                              <1> 
 17751 00005869 56                  <1> 	push	esi
 17752                              <1> 
 17753 0000586A 29C0                <1> 	sub	eax, eax
 17754                              <1> 
 17755 0000586C 66A3[70CF0000]      <1> 	mov	word [Dir_Count], ax ; 0
 17756 00005872 66A3[6ECF0000]      <1> 	mov 	word [File_Count], ax ; 0
 17757 00005878 A3[72CF0000]        <1> 	mov 	dword [Total_FSize], eax ; 0
 17758                              <1> 
 17759 0000587D E85FE6FFFF          <1> 	call    clear_screen
 17760                              <1> 	
 17761 00005882 31C9                <1> 	xor	ecx, ecx	
 17762 00005884 8A2D[42C50000]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
 17763 0000588A A0[43C50000]        <1> 	mov     al, [Current_Dir_Drv] 
 17764 0000588F A2[BCB60000]        <1> 	mov     [Dir_Drive_Name], al
 17765 00005894 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17766 00005899 01CE                <1> 	add	esi, ecx
 17767                              <1> 
 17768 0000589B E85EF9FFFF          <1> 	call	move_volume_name_and_serial_no
 17769 000058A0 7306                <1> 	jnc	short print_dir_strlen_check
 17770                              <1> 
 17771 000058A2 5E                  <1> 	pop	esi
 17772                              <1> 	;call	beeper
 17773                              <1> 	;retn
 17774 000058A3 E9EDBFFFFF          <1> 	jmp	beeper  ; beep ! and return
 17775                              <1> 
 17776                              <1> print_dir_strlen_check:
 17777 000058A8 BE[45C50000]        <1> 	mov	esi, Current_Dir_Root
 17778 000058AD BF[59B70000]        <1> 	mov	edi, Dir_Str_Root
 17779                              <1> 	
 17780                              <1> 	;xor	ecx, ecx
 17781 000058B2 8A0D[A1C50000]      <1>         mov     cl, [Current_Dir_StrLen]
 17782 000058B8 FEC1                <1> 	inc	cl
 17783 000058BA 80F940              <1> 	cmp	cl, 64
 17784 000058BD 760D                <1> 	jna	short pass_print_dir_strlen_shorting
 17785 000058BF 46                  <1> 	inc	esi
 17786 000058C0 01CE                <1> 	add	esi, ecx
 17787 000058C2 83EE40              <1> 	sub	esi, 64 
 17788 000058C5 47                  <1> 	inc	edi
 17789 000058C6 B82E2E2E20          <1> 	mov	eax, '... ' 
 17790 000058CB AB                  <1> 	stosd
 17791                              <1>  
 17792                              <1> pass_print_dir_strlen_shorting:
 17793 000058CC F3A4                <1> 	rep	movsb
 17794                              <1> 
 17795 000058CE BE[AFB60000]        <1> 	mov	esi, Dir_Drive_Str
 17796 000058D3 E8F2E5FFFF          <1> 	call	print_msg
 17797                              <1> 
 17798 000058D8 BE[0EB70000]        <1> 	mov	esi, Vol_Serial_Header
 17799 000058DD E8E8E5FFFF          <1> 	call	print_msg
 17800                              <1> 
 17801 000058E2 BE[4EB70000]        <1> 	mov	esi, Dir_Str_Header
 17802 000058E7 E8DEE5FFFF          <1> 	call	print_msg
 17803                              <1> 	
 17804 000058EC BE[54C10000]        <1> 	mov	esi, next2line
 17805 000058F1 E8D4E5FFFF          <1> 	call	print_msg
 17806                              <1> 
 17807                              <1> loc_print_dir_first_file:
 17808 000058F6 C605[85CF0000]10    <1> 	mov	byte [PrintDir_RowCounter], 16
 17809 000058FD 66A1[E4CE0000]      <1> 	mov	ax, [AttributesMask]
 17810 00005903 5E                  <1> 	pop	esi
 17811                              <1> 
 17812 00005904 E859020000          <1> 	call	find_first_file
 17813 00005909 0F826F010000        <1>         jc      loc_dir_ok
 17814                              <1> 	 
 17815                              <1> loc_dfname_use_this:
 17816                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
 17817 0000590F F6C310              <1> 	test	bl, 10h  ; Is it a directory?
 17818 00005912 741B                <1> 	jz	short loc_not_dir
 17819                              <1> 
 17820 00005914 66FF05[70CF0000]    <1> 	inc	word [Dir_Count]
 17821 0000591B 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
 17822 0000591D BE[9AB80000]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
 17823 00005922 BF[B1B80000]        <1> 	mov	edi, Dir_Or_FileSize
 17824                              <1> 	; move 10 bytes
 17825 00005927 A5                  <1> 	movsd
 17826 00005928 A5                  <1> 	movsd
 17827 00005929 66A5                <1> 	movsw	    	
 17828 0000592B 89D6                <1> 	mov	esi, edx
 17829 0000592D EB36                <1> 	jmp     short loc_dir_attribute
 17830                              <1> 
 17831                              <1> loc_not_dir:
 17832 0000592F 66FF05[6ECF0000]    <1> 	inc	word [File_Count]
 17833 00005936 0105[72CF0000]      <1> 	add	[Total_FSize], eax
 17834                              <1> 
 17835 0000593C B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
 17836 00005941 89CF                <1> 	mov	edi, ecx
 17837 00005943 81C7[B1B80000]      <1> 	add	edi, Dir_Or_FileSize
 17838                              <1> loc_dir_rdivide:
 17839 00005949 29D2                <1> 	sub	edx, edx
 17840 0000594B F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
 17841 0000594D 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
 17842 00005950 4F                  <1> 	dec	edi
 17843 00005951 8817                <1> 	mov     [edi], dl
 17844 00005953 21C0                <1> 	and	eax, eax
 17845 00005955 75F2                <1> 	jnz	short loc_dir_rdivide
 17846                              <1> 
 17847                              <1> loc_dir_fill_space:
 17848 00005957 81FF[B1B80000]      <1> 	cmp     edi, Dir_Or_FileSize
 17849 0000595D 7606                <1> 	jna     short loc_dir_attribute
 17850 0000595F 4F                  <1> 	dec     edi
 17851 00005960 C60720              <1> 	mov     byte [edi], 20h
 17852 00005963 EBF2                <1> 	jmp     short loc_dir_fill_space
 17853                              <1> 
 17854                              <1> loc_dir_attribute:
 17855 00005965 C705[BCB80000]2020- <1> 	mov	dword [File_Attribute], 20202020h
 17856 0000596D 2020                <1>
 17857                              <1> 
 17858 0000596F 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
 17859 00005972 7207                <1> 	jb	short loc_dir_pass_arch
 17860 00005974 C605[BFB80000]41    <1> 	mov	byte [File_Attribute+3], 'A'
 17861                              <1> 
 17862                              <1> loc_dir_pass_arch:
 17863 0000597B 80E307              <1> 	and	bl, 7
 17864 0000597E 7428                <1> 	jz	short loc_dir_file_name
 17865 00005980 88DF                <1> 	mov	bh, bl
 17866 00005982 80E303              <1> 	and	bl, 3
 17867 00005985 38DF                <1> 	cmp	bh, bl
 17868 00005987 7607                <1> 	jna	short loc_dir_pass_s
 17869 00005989 C605[BCB80000]53    <1> 	mov	byte [File_Attribute], 'S'
 17870                              <1> 
 17871                              <1> loc_dir_pass_s:
 17872 00005990 80E302              <1> 	and     bl,2
 17873 00005993 7407                <1> 	jz      short loc_dir_pass_h
 17874 00005995 C605[BDB80000]48    <1> 	mov     byte [File_Attribute+1], 'H'
 17875                              <1> loc_dir_pass_h:
 17876 0000599C 80E701              <1> 	and     bh,1
 17877 0000599F 7407                <1> 	jz      short loc_dir_file_name
 17878 000059A1 C605[BEB80000]52    <1> 	mov     byte [File_Attribute+2], 'R'
 17879                              <1> loc_dir_file_name:
 17880                              <1> 	;mov     bx, [esi+18h] ; Date
 17881                              <1> 	;mov     dx, [esi+16h] ; Time
 17882 000059A8 8B5E16              <1> 	mov	ebx, [esi+16h]
 17883 000059AB 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
 17884 000059AD BF[A4B80000]        <1> 	mov     edi, File_Name
 17885                              <1> 	; move 8 bytes
 17886 000059B2 A5                  <1> 	movsd
 17887 000059B3 A5                  <1> 	movsd
 17888 000059B4 C60720              <1> 	mov	byte [edi], 20h
 17889 000059B7 47                  <1> 	inc	edi
 17890                              <1> 	; move 3 bytes
 17891 000059B8 66A5                <1> 	movsw
 17892 000059BA A4                  <1> 	movsb
 17893 000059BB 89CE                <1> 	mov	esi, ecx
 17894                              <1> 
 17895                              <1> Dir_Time_start:
 17896                              <1> 	;mov	ax, dx		; Time
 17897 000059BD 6689D8              <1> 	mov	ax, bx
 17898 000059C0 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17899 000059C4 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
 17900 000059C8 D40A                <1> 	aam			; Q([AL]/10)->AH
 17901                              <1> 				; R([AL]/10)->AL
 17902                              <1> 				; [AL]+[AH]= Minute as BCD
 17903 000059CA 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17904 000059CE 86E0                <1> 	xchg	ah, al
 17905 000059D0 66A3[CFB80000]      <1> 	mov	[File_Minute], ax
 17906                              <1> 
 17907                              <1> 	;mov	al, dh
 17908 000059D6 88F8                <1> 	mov	al, bh
 17909 000059D8 C0E803              <1> 	shr	al, 3		; shift right 3 times
 17910 000059DB D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
 17911 000059DD 660D3030            <1> 	or	ax, '00'
 17912 000059E1 86E0                <1> 	xchg	ah, al
 17913 000059E3 66A3[CCB80000]      <1> 	mov     [File_Hour], ax
 17914                              <1> 
 17915 000059E9 C1EB10              <1> 	shr	ebx, 16		; BX = Date
 17916                              <1> 	
 17917                              <1> Dir_Date_start:
 17918 000059EC 6689D8              <1> 	mov	ax, bx		; Date
 17919 000059EF 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
 17920 000059F3 D40A                <1> 	aam			; Q([AL]/10)->AH
 17921                              <1> 				; R([AL]/10)->AL
 17922                              <1> 				; [AL]+[AH]= Day as BCD
 17923 000059F5 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17924 000059F9 86C4                <1> 	xchg	al, ah
 17925                              <1> 
 17926 000059FB 66A3[C1B80000]      <1> 	mov	[File_Day], ax
 17927                              <1> 
 17928 00005A01 6689D8              <1> 	mov	ax, bx
 17929 00005A04 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17930 00005A08 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
 17931 00005A0C D40A                <1> 	aam
 17932 00005A0E 660D3030            <1> 	or	ax, '00'
 17933 00005A12 86E0                <1> 	xchg	ah, al
 17934 00005A14 66A3[C4B80000]      <1> 	mov	[File_Month], ax
 17935                              <1> 
 17936 00005A1A 6689D8              <1> 	mov	ax, bx
 17937 00005A1D 66C1E809            <1> 	shr     ax, 9
 17938 00005A21 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
 17939 00005A25 6605BC07            <1> 	add	ax, 1980
 17940                              <1> 
 17941 00005A29 B10A                <1> 	mov	cl, 10
 17942 00005A2B F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
 17943 00005A2D 80CC30              <1> 	or	ah, '0'
 17944 00005A30 8825[CAB80000]      <1> 	mov	[File_Year+3], ah
 17945 00005A36 D40A                <1> 	aam
 17946 00005A38 86E0                <1> 	xchg	ah, al
 17947 00005A3A 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
 17948 00005A3D 8825[C9B80000]      <1> 	mov	[File_Year+2], ah
 17949 00005A43 D40A                <1> 	aam
 17950 00005A45 86C4                <1> 	xchg	al, ah
 17951 00005A47 660D3030            <1> 	or	ax, '00'
 17952 00005A4B 66A3[C7B80000]      <1> 	mov	[File_Year], ax
 17953                              <1> 
 17954                              <1> loc_show_line:
 17955 00005A51 56                  <1> 	push	esi
 17956 00005A52 BE[A4B80000]        <1> 	mov     esi, File_Name
 17957 00005A57 E86EE4FFFF          <1> 	call	print_msg
 17958 00005A5C BE[56C10000]        <1> 	mov	esi, nextline
 17959 00005A61 E864E4FFFF          <1> 	call	print_msg
 17960 00005A66 5E                  <1> 	pop	esi
 17961                              <1> 
 17962 00005A67 FE0D[85CF0000]      <1> 	dec	byte [PrintDir_RowCounter]
 17963 00005A6D 0F84D4000000        <1>         jz      pause_dir_scroll
 17964                              <1> 
 17965                              <1> loc_next_entry:
 17966 00005A73 E899010000          <1> 	call	find_next_file
 17967 00005A78 0F8391FEFFFF        <1>         jnc     loc_dfname_use_this
 17968                              <1> 
 17969                              <1> loc_dir_ok:
 17970 00005A7E B90A000000          <1> 	mov     ecx, 10
 17971 00005A83 66A1[70CF0000]      <1> 	mov	ax, [Dir_Count]
 17972 00005A89 BF[E5B80000]        <1> 	mov	edi, Decimal_Dir_Count
 17973 00005A8E 6639C8              <1> 	cmp	ax, cx ; 10
 17974 00005A91 7216                <1> 	jb	short pass_ddc
 17975 00005A93 47                  <1> 	inc	edi
 17976 00005A94 6683F864            <1> 	cmp	ax, 100
 17977 00005A98 720F                <1> 	jb	short pass_ddc
 17978 00005A9A 47                  <1> 	inc	edi
 17979 00005A9B 663DE803            <1> 	cmp	ax, 1000
 17980 00005A9F 7208                <1> 	jb	short pass_ddc
 17981 00005AA1 47                  <1> 	inc	edi
 17982 00005AA2 663D1027            <1> 	cmp	ax, 10000
 17983 00005AA6 7201                <1> 	jb	short pass_ddc
 17984 00005AA8 47                  <1> 	inc	edi
 17985                              <1> pass_ddc:
 17986 00005AA9 886F01              <1> 	mov     [edi+1], ch ; 0
 17987                              <1> loc_ddc_rediv:
 17988 00005AAC 31D2                <1> 	xor     edx, edx
 17989 00005AAE 66F7F1              <1> 	div     cx	; 10
 17990 00005AB1 80C230              <1> 	add     dl, '0'
 17991 00005AB4 8817                <1> 	mov     [edi], dl
 17992 00005AB6 4F                  <1> 	dec     edi
 17993 00005AB7 6609C0              <1> 	or	ax, ax
 17994 00005ABA 75F0                <1> 	jnz	short loc_ddc_rediv
 17995                              <1> 
 17996 00005ABC 66A1[6ECF0000]      <1> 	mov     ax, [File_Count]
 17997 00005AC2 BF[D4B80000]        <1> 	mov     edi, Decimal_File_Count
 17998 00005AC7 6639C8              <1> 	cmp     ax, cx ; 10
 17999 00005ACA 7216                <1> 	jb      short pass_dfc
 18000 00005ACC 47                  <1> 	inc     edi
 18001 00005ACD 6683F864            <1> 	cmp     ax, 100
 18002 00005AD1 720F                <1> 	jb      short pass_dfc
 18003 00005AD3 47                  <1> 	inc     edi
 18004 00005AD4 663DE803            <1> 	cmp     ax, 1000
 18005 00005AD8 7208                <1> 	jb      short pass_dfc
 18006 00005ADA 47                  <1> 	inc     edi
 18007 00005ADB 663D1027            <1> 	cmp     ax, 10000
 18008 00005ADF 7201                <1> 	jb      short pass_dfc
 18009 00005AE1 47                  <1> 	inc     edi
 18010                              <1> pass_dfc:
 18011                              <1> 	;mov    cx, 10
 18012 00005AE2 886F01              <1> 	mov     [edi+1], ch ; 00
 18013                              <1> loc_dfc_rediv:
 18014                              <1> 	;xor	dx, dx
 18015 00005AE5 30D2                <1> 	xor	dl, dl
 18016 00005AE7 66F7F1              <1> 	div	cx
 18017 00005AEA 80C230              <1> 	add	dl, '0'
 18018 00005AED 8817                <1> 	mov	[edi], dl
 18019 00005AEF 4F                  <1> 	dec	edi
 18020 00005AF0 6609C0              <1> 	or	ax, ax
 18021 00005AF3 75F0                <1> 	jnz	short loc_dfc_rediv
 18022                              <1> 
 18023 00005AF5 BF[84CF0000]        <1> 	mov     edi, TFS_Dec_End
 18024                              <1>         ;mov    byte [edi], 0
 18025 00005AFA A1[72CF0000]        <1> 	mov     eax, [Total_FSize]
 18026                              <1> 	;mov    ecx, 10
 18027                              <1> rediv_tfs_hex:
 18028                              <1> 	;sub	edx, edx
 18029 00005AFF 28D2                <1> 	sub	dl, dl
 18030 00005B01 F7F1                <1> 	div	ecx
 18031 00005B03 80C230              <1> 	add	dl, '0'
 18032 00005B06 4F                  <1> 	dec     edi
 18033 00005B07 8817                <1> 	mov     [edi], dl
 18034 00005B09 21C0                <1> 	and	eax, eax
 18035 00005B0B 75F2                <1> 	jnz	short rediv_tfs_hex
 18036                              <1> 	
 18037 00005B0D 893D[76CF0000]      <1> 	mov	[TFS_Dec_Begin], edi
 18038 00005B13 BE[D2B80000]        <1> 	mov	esi, Decimal_File_Count_Header
 18039 00005B18 E8ADE3FFFF          <1> 	call	print_msg
 18040 00005B1D BE[DAB80000]        <1> 	mov	esi, str_files
 18041 00005B22 E8A3E3FFFF          <1> 	call	print_msg
 18042 00005B27 BE[EBB80000]        <1> 	mov	esi, str_dirs
 18043 00005B2C E899E3FFFF          <1> 	call	print_msg
 18044 00005B31 8B35[76CF0000]      <1> 	mov	esi, [TFS_Dec_Begin]
 18045 00005B37 E88EE3FFFF          <1> 	call	print_msg
 18046 00005B3C BE[FCB80000]        <1> 	mov	esi, str_bytes
 18047 00005B41 E884E3FFFF          <1> 	call	print_msg
 18048                              <1> 
 18049 00005B46 C3                  <1> 	retn
 18050                              <1> 
 18051                              <1> pause_dir_scroll:
 18052 00005B47 28E4                <1> 	sub	ah, ah           
 18053 00005B49 E899B0FFFF          <1> 	call	int16h
 18054 00005B4E 3C1B                <1> 	cmp	al, 1Bh
 18055 00005B50 0F8428FFFFFF        <1>         je      loc_dir_ok
 18056 00005B56 C605[85CF0000]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
 18057 00005B5D E911FFFFFF          <1>         jmp     loc_next_entry
 18058                              <1> 
 18059                              <1> find_first_file:
 18060                              <1> 	; 11/02/2015
 18061                              <1> 	; 10/02/2016
 18062                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18063                              <1> 	; 09/10/2011
 18064                              <1> 	; 17/09/2009
 18065                              <1> 	; 2005
 18066                              <1> 	; INPUT ->
 18067                              <1> 	;	ESI = ASCIIZ File/Dir/Path Name Address
 18068                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
 18069                              <1> 	;	      bit 0 = Read Only
 18070                              <1> 	;	      bir 1 = Hidden
 18071                              <1> 	;	      bit 2 = System
 18072                              <1> 	;	      bit 3 = Volume Label
 18073                              <1> 	;	      bit 4 = Directory
 18074                              <1> 	;	      bit 5 = Archive
 18075                              <1> 	;	      bit 6 = Reserved, must be 0
 18076                              <1> 	;	      bit 7 = Reserved, must be 0
 18077                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
 18078                              <1> 	;
 18079                              <1> 	; OUTPUT ->
 18080                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 18081                              <1> 	;	CF = 0 ->
 18082                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
 18083                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
 18084                              <1> 	;	     EAX = File Size
 18085                              <1> 	;	      BL = Attributes of The File/Directory
 18086                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 18087                              <1> 	;             DX > 0 : Ambiguous filename chars are used
 18088                              <1> 	;
 18089                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 18090                              <1> 
 18091 00005B62 66A3[36CF0000]      <1> 	mov	[FindFile_AttributesMask], ax
 18092 00005B68 BF[38CF0000]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
 18093 00005B6D 31C0                <1> 	xor	eax, eax
 18094 00005B6F B90B000000          <1> 	mov	ecx, 11
 18095 00005B74 F3AB                <1> 	rep	stosd	; 44 bytes
 18096                              <1> 	;stosw		; +2 bytes 
 18097                              <1> 	    
 18098 00005B76 BF[28CF0000]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
 18099 00005B7B 39FE                <1> 	cmp	esi, edi
 18100 00005B7D 7408                <1> 	je	short loc_fff_mfn_ok
 18101 00005B7F 89FA                <1> 	mov	edx, edi 
 18102                              <1> 	 ; move 13 bytes
 18103 00005B81 A5                  <1> 	movsd
 18104 00005B82 A5                  <1> 	movsd
 18105 00005B83 A5                  <1> 	movsd
 18106 00005B84 AA                  <1> 	stosb
 18107 00005B85 89D6                <1> 	mov	esi, edx
 18108                              <1> loc_fff_mfn_ok:
 18109 00005B87 BF[D7CE0000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 18110 00005B8C E8DD1D0000          <1> 	call	convert_file_name
 18111 00005B91 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 18112                              <1> 
 18113 00005B93 66A1[36CF0000]      <1> 	mov	ax, [FindFile_AttributesMask]
 18114                              <1> 	;xor	ecx, ecx
 18115 00005B99 30C9                <1> 	xor	cl, cl  
 18116 00005B9B E8D91A0000          <1> 	call	locate_current_dir_file
 18117 00005BA0 726E                <1> 	jc	short loc_fff_retn
 18118                              <1> 	; EDI = Directory Entry
 18119                              <1> 	; EBX = Directory Buffer Entry Index/Number
 18120                              <1> 
 18121                              <1> loc_fff_fnf_ln_check:
 18122 00005BA2 30ED                <1> 	xor	ch, ch 
 18123 00005BA4 80F60F              <1> 	xor	dh, 0Fh
 18124 00005BA7 7408                <1> 	jz	short loc_fff_longname_yes
 18125 00005BA9 882D[35CF0000]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
 18126 00005BAF EB0C                <1> 	jmp	short loc_fff_longname_no
 18127                              <1> 
 18128                              <1> loc_fff_longname_yes:
 18129                              <1> 	;inc	byte [FindFile_LongNameYes]
 18130 00005BB1 8A0D[42CE0000]      <1> 	mov	cl, [LFN_EntryLength]  
 18131 00005BB7 880D[35CF0000]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
 18132                              <1> 
 18133                              <1> loc_fff_longname_no:
 18134                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
 18135 00005BBD 66891D[60CF0000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 18136 00005BC4 6689C2              <1> 	mov	dx, ax ; Ambigouos Filename chars used sign > 0
 18137                              <1> 
 18138 00005BC7 A0[42C50000]        <1> 	mov	al, [Current_Drv]
 18139 00005BCC A2[E6CE0000]        <1> 	mov	[FindFile_Drv], al 
 18140                              <1> 
 18141 00005BD1 A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster]
 18142 00005BD6 A3[58CF0000]        <1> 	mov	[FindFile_DirFirstCluster], eax
 18143                              <1> 
 18144 00005BDB A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 18145 00005BE0 A3[5CCF0000]        <1> 	mov	[FindFile_DirCluster], eax
 18146                              <1> 
 18147 00005BE5 66FF05[62CF0000]    <1> 	inc	word [FindFile_MatchCounter]
 18148                              <1> 
 18149 00005BEC 89FB                <1> 	mov	ebx, edi
 18150 00005BEE 89FE                <1> 	mov	esi, edi
 18151 00005BF0 BF[38CF0000]        <1> 	mov	edi, FindFile_DirEntry
 18152 00005BF5 89F8                <1> 	mov	eax, edi
 18153 00005BF7 B108                <1> 	mov	cl, 8
 18154 00005BF9 F3A5                <1> 	rep	movsd
 18155 00005BFB 89C6                <1> 	mov	esi, eax
 18156 00005BFD 89DF                <1> 	mov	edi, ebx
 18157                              <1> 
 18158 00005BFF A1[54CF0000]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
 18159                              <1> 
 18160 00005C04 8A1D[43CF0000]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes 
 18161 00005C0A 8A3D[35CF0000]      <1> 	mov	bh, [FindFile_LongNameYes]
 18162                              <1> 
 18163                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 18164                              <1> 	;mov	[FindFile_DirEntryNumber], cx
 18165                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
 18166                              <1> 	; ecx = 0
 18167                              <1> 
 18168                              <1> loc_fff_retn:
 18169 00005C10 C3                  <1> 	retn
 18170                              <1> 
 18171                              <1> find_next_file:
 18172                              <1> 	; 10/02/2016
 18173                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18174                              <1> 	; 06/02/2011
 18175                              <1> 	; 17/09/2009
 18176                              <1> 	; 2005
 18177                              <1> 	; INPUT ->
 18178                              <1> 	;	NONE, Find First File Parameters
 18179                              <1> 	; OUTPUT ->
 18180                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 18181                              <1> 	;	CF = 0 -> 
 18182                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
 18183                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
 18184                              <1> 	;	    EAX = File Size
 18185                              <1> 	;	      BL = Attributes of The File/Directory
 18186                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 18187                              <1> 	;             DX > 0 : Ambiguous filename chars are used 
 18188                              <1> 	;
 18189                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 18190                              <1> 
 18191 00005C11 66833D[62CF0000]00  <1> 	cmp	word [FindFile_MatchCounter], 0
 18192 00005C19 7707                <1> 	ja	short loc_start_search_next_file
 18193                              <1> 
 18194                              <1> loc_fnf_stc_retn:
 18195 00005C1B F9                  <1> 	stc
 18196                              <1> loc_fnf_ax12h_retn:
 18197 00005C1C B812000000          <1> 	mov	eax, 12h ; 18, No More files
 18198                              <1> ;loc_fnf_retn:
 18199 00005C21 C3                  <1> 	retn
 18200                              <1> 
 18201                              <1> loc_start_search_next_file:
 18202 00005C22 668B1D[60CF0000]    <1> 	mov	bx, [FindFile_DirEntryNumber]
 18203 00005C29 6643                <1> 	inc	bx
 18204 00005C2B 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 18205 00005C32 7719                <1> 	ja	short loc_cont_search_next_file
 18206                              <1> 
 18207                              <1> loc_fnf_search:
 18208 00005C34 BE[D7CE0000]        <1> 	mov	esi, Dir_Entry_Name
 18209 00005C39 66A1[36CF0000]      <1> 	mov	ax, [FindFile_AttributesMask]
 18210 00005C3F 6631C9              <1> 	xor	cx, cx
 18211 00005C42 E8341B0000          <1> 	call	find_directory_entry
 18212 00005C47 0F8355FFFFFF        <1>         jnc     loc_fff_fnf_ln_check
 18213                              <1> 
 18214                              <1> loc_cont_search_next_file:
 18215 00005C4D 31DB                <1> 	xor	ebx, ebx
 18216 00005C4F 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 18217 00005C55 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18218 00005C5A 01DE                <1> 	add	esi, ebx
 18219                              <1> 
 18220 00005C5C 803D[40C50000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 18221 00005C63 7608                <1> 	jna	short loc_fnf_check_FAT_type
 18222 00005C65 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 18223 00005C69 72B1                <1> 	jb	short loc_fnf_ax12h_retn
 18224 00005C6B EB06                <1> 	jmp	short loc_fnf_check_next_cluster
 18225                              <1>  
 18226                              <1> loc_fnf_check_FAT_type:
 18227 00005C6D 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 18228 00005C71 72A9                <1> 	jb	short loc_fnf_ax12h_retn
 18229                              <1> 
 18230                              <1> loc_fnf_check_next_cluster:
 18231 00005C73 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 18232 00005C78 E8B3340000          <1> 	call	get_next_cluster
 18233 00005C7D 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
 18234 00005C7F 09C0                <1> 	or	eax, eax
 18235 00005C81 7498                <1> 	jz	short loc_fnf_stc_retn
 18236                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 18237 00005C83 F5                  <1>  	cmc	;stc
 18238                              <1> loc_fnf_retn:
 18239 00005C84 C3                  <1> 	retn
 18240                              <1> 
 18241                              <1> loc_fnf_load_next_dir_cluster:
 18242 00005C85 E88C360000          <1> 	call	load_FAT_sub_directory
 18243 00005C8A 72F8                <1> 	jc	short loc_fnf_retn
 18244 00005C8C 6631DB              <1> 	xor	bx, bx
 18245 00005C8F 66891D[60CF0000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 18246 00005C96 EB9C                <1> 	jmp	short loc_fnf_search
 18247                              <1> 
 18248                              <1> get_and_print_longname:
 18249                              <1> 	; 13/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18250                              <1> 	; 24/01/2010
 18251                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
 18252                              <1> get_longname_fchar:
 18253 00005C98 803E20              <1> 	cmp	byte [esi], 20h
 18254 00005C9B 7701                <1> 	ja	short loc_find_longname
 18255                              <1> 	;jb	short loc_longname_retn
 18256                              <1> 	;inc	esi
 18257                              <1> 	;je	short get_longname_fchar
 18258                              <1> ;loc_longname_retn:
 18259 00005C9D C3                  <1> 	retn
 18260                              <1> loc_find_longname:
 18261 00005C9E E83F1E0000          <1> 	call	find_longname
 18262 00005CA3 7320                <1> 	jnc	short loc_print_longname
 18263                              <1> 	
 18264 00005CA5 08C0                <1> 	or	al, al
 18265 00005CA7 7412                <1> 	jz	short loc_longname_not_found
 18266                              <1> 	  
 18267 00005CA9 3C15                <1> 	cmp	al, 15h
 18268 00005CAB 0F84B4F7FFFF        <1> 	je	cd_drive_not_ready
 18269                              <1> 
 18270                              <1> loc_ln_file_dir_not_found:
 18271 00005CB1 BE[2AB80000]        <1> 	mov	esi, Msg_File_Directory_Not_Found
 18272                              <1> 	;call	print_msg	
 18273                              <1>         ;retn
 18274 00005CB6 E90FE2FFFF          <1> 	jmp	print_msg
 18275                              <1> 
 18276                              <1> loc_longname_not_found:
 18277 00005CBB BE[49B80000]        <1>         mov     esi, Msg_LongName_Not_Found
 18278                              <1> 	;call	print_msg	
 18279                              <1>         ;retn
 18280 00005CC0 E905E2FFFF          <1> 	jmp	print_msg
 18281                              <1> 
 18282                              <1> loc_print_longname:
 18283                              <1> 	;mov	esi, LongFileName
 18284 00005CC5 BF[42C60000]        <1> 	mov	edi, TextBuffer
 18285 00005CCA 57                  <1> 	push	edi 
 18286 00005CCB 3C00                <1> 	cmp	al, 0
 18287 00005CCD 7708                <1> 	ja	short loc_print_longname_1
 18288                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
 18289 00005CCF AC                  <1> 	lodsb
 18290 00005CD0 AA                  <1> 	stosb  
 18291 00005CD1 08C0                <1> 	or	al, al
 18292 00005CD3 75FA                <1> 	jnz	short loc_print_FS_longname
 18293 00005CD5 EB07                <1> 	jmp	short loc_print_longname_2
 18294                              <1> 	;
 18295                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
 18296 00005CD7 66AD                <1> 	lodsw
 18297 00005CD9 AA                  <1> 	stosb  
 18298 00005CDA 08C0                <1> 	or	al, al
 18299 00005CDC 75F9                <1> 	jnz	short loc_print_longname_1
 18300                              <1> 	;
 18301                              <1> loc_print_longname_2:	
 18302 00005CDE 5E                  <1> 	pop	esi
 18303 00005CDF E8E6E1FFFF          <1> 	call	print_msg
 18304 00005CE4 BE[56C10000]        <1>   	mov	esi, nextline
 18305                              <1> 	;call	print_msg
 18306                              <1> 	;retn
 18307 00005CE9 E9DCE1FFFF          <1> 	jmp	print_msg	
 18308                              <1> 
 18309                              <1> show_file:
 18310                              <1> 	; 18/02/2016
 18311                              <1> 	; 17/02/2016
 18312                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18313                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
 18314                              <1> 	; 08/11/2009
 18315                              <1> 
 18316                              <1> loc_show_parse_path_name:
 18317 00005CEE BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 18318 00005CF3 E8411D0000          <1> 	call	parse_path_name
 18319 00005CF8 0F8268F9FFFF        <1> 	jc	loc_cmd_failed
 18320                              <1> 
 18321                              <1> loc_show_check_filename_exists:
 18322 00005CFE BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 18323 00005D03 803E20              <1> 	cmp	byte [esi], 20h
 18324 00005D06 0F865AF9FFFF        <1> 	jna	loc_cmd_failed
 18325                              <1> 
 18326                              <1> 	; 15/02/2016 (invalid file name check)
 18327 00005D0C E805020000          <1> 	call	check_filename 	
 18328 00005D11 730A                <1> 	jnc	short loc_show_change_drv
 18329                              <1> 
 18330 00005D13 BE[12B90000]        <1> 	mov	esi, Msg_invalid_name_chars
 18331 00005D18 E9ADE1FFFF          <1> 	jmp	print_msg
 18332                              <1>    
 18333                              <1> loc_show_change_drv:
 18334 00005D1D 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 18335 00005D23 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 18336 00005D29 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 18337 00005D2F 38F2                <1> 	cmp	dl, dh
 18338 00005D31 740B                <1> 	je	short loc_show_change_directory
 18339 00005D33 E896EAFFFF          <1> 	call	change_current_drive
 18340                              <1> 	;jc	loc_file_rw_cmd_failed
 18341 00005D38 0F8253F9FFFF        <1> 	jc	loc_run_cmd_failed
 18342                              <1> 
 18343                              <1> loc_show_change_directory:
 18344 00005D3E 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18345 00005D45 7618                <1> 	jna	short loc_findload_showfile
 18346                              <1> 
 18347 00005D47 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 18348 00005D4D BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 18349 00005D52 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18350 00005D54 E8CC160000          <1> 	call	change_current_directory
 18351                              <1> 	;jc	loc_file_rw_cmd_failed
 18352 00005D59 0F8232F9FFFF        <1> 	jc	loc_run_cmd_failed
 18353                              <1> 
 18354                              <1> ;loc_show_change_prompt_dir_string:
 18355                              <1> 	;call	change_prompt_dir_string
 18356                              <1> 
 18357                              <1> loc_findload_showfile:
 18358                              <1> 	; 15/02/2016
 18359 00005D5F BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 18360 00005D64 BF[D7CE0000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 18361 00005D69 E8001C0000          <1> 	call	convert_file_name
 18362 00005D6E 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 18363                              <1> 
 18364 00005D70 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
 18365                              <1> 	; Directory attribute : 10h
 18366                              <1> 	; Volume name attribute: 8h
 18367 00005D72 B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
 18368                              <1> 	;
 18369 00005D74 6631C9              <1> 	xor	cx, cx  
 18370 00005D77 E8FD180000          <1> 	call	locate_current_dir_file
 18371                              <1> 	;jc	loc_file_rw_cmd_failed
 18372 00005D7C 0F820FF9FFFF        <1> 	jc	loc_run_cmd_failed
 18373                              <1> 
 18374                              <1> loc_show_load_file:
 18375                              <1> 	; EDI = Directory Entry
 18376 00005D82 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
 18377 00005D86 C1E010              <1> 	shl	eax, 16
 18378 00005D89 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
 18379 00005D8D A3[90CF0000]        <1> 	mov	[Show_Cluster], eax
 18380 00005D92 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
 18381 00005D95 21C0                <1> 	and	eax, eax ; Empty file !
 18382 00005D97 0F8491000000        <1>         jz      end_of_show_file 
 18383 00005D9D A3[94CF0000]        <1> 	mov	[Show_FileSize], eax
 18384 00005DA2 31C0                <1> 	xor	eax, eax
 18385 00005DA4 A3[98CF0000]        <1> 	mov	[Show_FilePointer], eax ; 0
 18386 00005DA9 66A3[9CCF0000]      <1> 	mov	[Show_ClusterPointer], ax ; 0
 18387 00005DAF 29DB                <1> 	sub	ebx, ebx
 18388 00005DB1 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 18389 00005DB7 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18390 00005DBC 01DE                <1> 	add	esi, ebx
 18391 00005DBE 8935[8CCF0000]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
 18392                              <1> 
 18393 00005DC4 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0	
 18394 00005DC8 7713                <1> 	ja	short loc_show_calculate_cluster_size
 18395                              <1> 	; Singlix FS
 18396                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
 18397 00005DCA 8B15[90CF0000]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)	
 18398 00005DD0 8915[88CF0000]      <1> 	mov	[Show_FDT], edx
 18399 00005DD6 31C0                <1> 	xor	eax, eax
 18400 00005DD8 A3[90CF0000]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
 18401                              <1> 				    ; (next time it will be 1)			
 18402                              <1> loc_show_calculate_cluster_size:
 18403 00005DDD 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
 18404                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS	
 18405 00005DE1 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
 18406                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 18407 00005DE4 F7E3                <1> 	mul	ebx	
 18408                              <1> 
 18409                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
 18410                              <1> 	;ja	short end_of_show_file	
 18411 00005DE6 66A3[9ECF0000]      <1> 	mov	[Show_ClusterSize], ax
 18412                              <1> 
 18413                              <1> loc_start_show_file:
 18414 00005DEC BE[56C10000]        <1> 	mov	esi, nextline
 18415 00005DF1 E8D4E0FFFF          <1> 	call	print_msg
 18416                              <1> 
 18417 00005DF6 A1[90CF0000]        <1> 	mov	eax, [Show_Cluster]
 18418 00005DFB C605[A0CF0000]17    <1> 	mov	byte [Show_RowCount], 23
 18419                              <1> 
 18420                              <1> 	; 17/02/2016
 18421 00005E02 8B35[8CCF0000]      <1> 	mov	esi, [Show_LDDDT]
 18422                              <1> 
 18423                              <1> loc_show_next_cluster:
 18424                              <1> 	; 15/02/2016
 18425 00005E08 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
 18426                              <1> 	; ESI = Logical DOS drv description table address
 18427 00005E0D E842350000          <1> 	call	read_cluster
 18428                              <1> 	;jc	loc_file_rw_cmd_failed
 18429 00005E12 0F8279F8FFFF        <1> 	jc	loc_run_cmd_failed
 18430                              <1> 
 18431 00005E18 31DB                <1> 	xor 	ebx, ebx
 18432                              <1> loc_show_next_byte:
 18433 00005E1A 803D[A0CF0000]00    <1> 	cmp	byte [Show_RowCount], 0
 18434 00005E21 7521                <1> 	jne	short pass_show_wait_for_key
 18435 00005E23 30E4                <1> 	xor	ah, ah
 18436 00005E25 E8BDADFFFF          <1> 	call	int16h
 18437 00005E2A 3C1B                <1> 	cmp	al, 1Bh
 18438 00005E2C 750F                <1> 	jne	short pass_exit_show
 18439                              <1> end_of_show_file:
 18440                              <1> pass_show_file:
 18441 00005E2E BE[56C10000]        <1> 	mov	esi, nextline
 18442 00005E33 E892E0FFFF          <1> 	call	print_msg
 18443 00005E38 E949010000          <1> 	jmp	loc_file_rw_restore_retn
 18444                              <1> 
 18445                              <1> pass_exit_show:
 18446 00005E3D C605[A0CF0000]14    <1> 	mov	byte [Show_RowCount], 20
 18447                              <1> pass_show_wait_for_key:
 18448 00005E44 81C300000700        <1> 	add	ebx, Cluster_Buffer
 18449 00005E4A 8A03                <1> 	mov	al, [ebx]
 18450 00005E4C 0FB61D[A8C40000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18451 00005E53 3C0D                <1> 	cmp	al, 0Dh
 18452 00005E55 0F858A000000        <1>         jne     loc_show_check_tab_space
 18453 00005E5B FE0D[A0CF0000]      <1> 	dec	byte [Show_RowCount]
 18454                              <1> pass_show_dec_rowcount:
 18455 00005E61 B407                <1> 	mov	ah, 7 ; (light gray character color, black background)
 18456 00005E63 E84FB9FFFF          <1> 	call	WRITE_TTY
 18457                              <1> loc_show_check_eof:
 18458 00005E68 FF05[98CF0000]      <1> 	inc	dword [Show_FilePointer]
 18459 00005E6E A1[98CF0000]        <1> 	mov	eax, [Show_FilePointer]
 18460 00005E73 3B05[94CF0000]      <1> 	cmp	eax, [Show_FileSize]
 18461 00005E79 73B3                <1> 	jnb	short end_of_show_file
 18462 00005E7B 66FF05[9CCF0000]    <1> 	inc	word [Show_ClusterPointer]
 18463 00005E82 0FB71D[9CCF0000]    <1> 	movzx	ebx, word [Show_ClusterPointer]
 18464                              <1> 
 18465                              <1> 	; 17/02/2016
 18466                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
 18467 00005E89 66F7C3FF01          <1>         test    bx, 1FFh ;  1 to 511
 18468 00005E8E 758A                <1> 	jnz	short loc_show_next_byte
 18469                              <1> 
 18470                              <1> 	; 16/02/2016
 18471 00005E90 8B35[8CCF0000]      <1> 	mov	esi, [Show_LDDDT]
 18472                              <1> 	;
 18473 00005E96 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 18474 00005E9A 7719                <1> 	ja	short loc_show_check_fat_cluster_size
 18475                              <1> 
 18476                              <1> 	; Singlix FS
 18477                              <1> 	; 1 sector, more... (cluster size = 1 sector)
 18478 00005E9C A1[90CF0000]        <1> 	mov	eax, [Show_Cluster]
 18479 00005EA1 40                  <1> 	inc	eax
 18480 00005EA2 A3[90CF0000]        <1> 	mov	[Show_Cluster], eax
 18481                              <1> 
 18482 00005EA7 6621DB              <1> 	and	bx, bx ; 65536 -> 0
 18483 00005EAA 0F856AFFFFFF        <1>         jnz	loc_show_next_byte
 18484 00005EB0 E953FFFFFF          <1> 	jmp     loc_show_next_cluster
 18485                              <1> 	 
 18486                              <1> loc_show_check_fat_cluster_size:
 18487                              <1> 	; 17/02/2016
 18488 00005EB5 663B1D[9ECF0000]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
 18489 00005EBC 0F8258FFFFFF        <1>         jb	loc_show_next_byte
 18490 00005EC2 66C705[9CCF0000]00- <1> 	mov	word [Show_ClusterPointer], 0
 18491 00005ECA 00                  <1>
 18492                              <1> 
 18493 00005ECB A1[90CF0000]        <1> 	mov	eax, [Show_Cluster]
 18494                              <1> 	;mov	esi, [Show_LDDDT]
 18495                              <1> loc_show_get_next_cluster:
 18496 00005ED0 E85B320000          <1> 	call	get_next_cluster
 18497                              <1> 	;jc	loc_file_rw_cmd_failed
 18498 00005ED5 0F82B6F7FFFF        <1> 	jc	loc_run_cmd_failed
 18499                              <1> loc_show_update_ccluster:
 18500 00005EDB A3[90CF0000]        <1> 	mov	[Show_Cluster], eax			
 18501 00005EE0 E923FFFFFF          <1>         jmp     loc_show_next_cluster
 18502                              <1> 
 18503                              <1> loc_show_check_tab_space:
 18504 00005EE5 3C09                <1> 	cmp	al, 09h
 18505 00005EE7 0F8574FFFFFF        <1>         jne     pass_show_dec_rowcount
 18506                              <1> loc_show_put_tab_space:
 18507                              <1> 	;movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18508 00005EED E88BB6FFFF          <1> 	call	get_cpos
 18509                              <1> 	; dl = cursor column
 18510 00005EF2 80E207              <1> 	and	dl, 7 ; 18/02/2016
 18511                              <1> loc_show_put_space_chars:
 18512                              <1> 	;mov	al, 20h ; space
 18513                              <1> 	;mov 	ah, 7	; color attribute
 18514 00005EF5 66B82007            <1> 	mov	ax, 0720h ; 
 18515 00005EF9 0FB61D[A8C40000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18516 00005F00 6652                <1> 	push	dx
 18517 00005F02 E8B0B8FFFF          <1> 	call	WRITE_TTY
 18518 00005F07 665A                <1> 	pop	dx
 18519                              <1> 	; 18/02/2016
 18520 00005F09 80FA07              <1> 	cmp	dl, 7
 18521 00005F0C 0F8356FFFFFF        <1> 	jnb	loc_show_check_eof
 18522 00005F12 FEC2                <1> 	inc	dl
 18523 00005F14 EBDF                <1> 	jmp	short loc_show_put_space_chars
 18524                              <1> 
 18525                              <1> check_filename:
 18526                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18527                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
 18528                              <1> 	; 10/07/2010
 18529                              <1> 	; Derived from 'proc_check_filename'
 18530                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18531                              <1> 	;
 18532                              <1> 	; INPUT -> 
 18533                              <1> 	;	ESI = Dot File Name Location
 18534                              <1> 	; OUTPUT ->
 18535                              <1> 	;	cf = 1 -> error code in AL
 18536                              <1> 	;	     AL = 0Bh -> Invalid file name   
 18537                              <1> 	;	cf = 0 -> valid file name
 18538                              <1> 	; 
 18539                              <1> 	;(EAX, ECX, EDI will be changed)
 18540                              <1> 
 18541                              <1> check_invalid_filename_chars:
 18542                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18543                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
 18544                              <1> 	; 10/02/2010
 18545                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
 18546                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18547                              <1> 	;
 18548                              <1> 	; INPUT -> 
 18549                              <1> 	;	ESI = ASCIIZ FileName
 18550                              <1> 	; OUTPUT ->
 18551                              <1> 	;	cf = 1 -> invalid
 18552                              <1> 	;	cf = 0 -> valid
 18553                              <1> 	; 
 18554                              <1> 	;(EAX, ECX, ESI, EDI will be changed)
 18555                              <1>   
 18556 00005F16 56                  <1> 	push	esi
 18557                              <1> 
 18558 00005F17 BF[FEB50000]        <1>         mov     edi, invalid_fname_chars
 18559 00005F1C AC                  <1> 	lodsb
 18560                              <1> check_filename_next_char:
 18561 00005F1D B914000000          <1> 	mov	ecx, sizeInvFnChars
 18562 00005F22 BF[FEB50000]        <1> 	mov	edi, invalid_fname_chars
 18563                              <1> loc_scan_invalid_filename_char:
 18564 00005F27 AE                  <1> 	scasb 
 18565 00005F28 741F                <1> 	je	short loc_invalid_filename_stc 
 18566 00005F2A E2FB                <1> 	loop	loc_scan_invalid_filename_char
 18567 00005F2C AC                  <1> 	lodsb
 18568 00005F2D 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
 18569 00005F2F 77EC                <1> 	ja	short check_filename_next_char
 18570                              <1> 
 18571                              <1> check_filename_dot:
 18572 00005F31 8B3424              <1> 	mov	esi, [esp]
 18573                              <1> 
 18574 00005F34 B421                <1> 	mov	ah, 21h
 18575 00005F36 B908000000          <1> 	mov	ecx, 8
 18576                              <1> loc_check_filename_next_char:
 18577 00005F3B AC                  <1> 	lodsb
 18578 00005F3C 3C2E                <1> 	cmp	al, 2Eh
 18579 00005F3E 7511                <1> 	jne	short pass_check_fn_dot_check
 18580                              <1> loc_check_filename_ext_0:
 18581 00005F40 AC                  <1> 	lodsb
 18582 00005F41 38E0                <1> 	cmp	al, ah ; 21h
 18583 00005F43 7205                <1> 	jb	short loc_invalid_filename
 18584 00005F45 3C2E                <1> 	cmp	al, 2Eh
 18585 00005F47 7519                <1> 	jne	short loc_check_filename_ext_1
 18586                              <1> 
 18587                              <1> loc_invalid_filename_stc:
 18588                              <1> loc_check_fn_stc_rtn:
 18589 00005F49 F9                  <1> 	stc
 18590                              <1> loc_invalid_filename:
 18591 00005F4A B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 18592                              <1> 	; Invalid file name chars
 18593                              <1> loc_check_fn_rtn:
 18594 00005F4F 5E                  <1> 	pop	esi
 18595 00005F50 C3                  <1> 	retn
 18596                              <1> 
 18597                              <1> pass_check_fn_dot_check:
 18598 00005F51 38E0                <1> 	cmp	al, ah ; 21h
 18599 00005F53 7224                <1> 	jb	short loc_check_fn_clc_rtn
 18600 00005F55 E2E4                <1> 	loop	loc_check_filename_next_char
 18601 00005F57 AC                  <1> 	lodsb
 18602 00005F58 38E0                <1> 	cmp	al, ah ; 21h
 18603 00005F5A 721D                <1> 	jb	short loc_check_fn_clc_rtn
 18604 00005F5C 3C2E                <1> 	cmp	al, 2Eh
 18605 00005F5E 75E9                <1> 	jne	short loc_check_fn_stc_rtn
 18606 00005F60 EBDE                <1> 	jmp	short loc_check_filename_ext_0
 18607                              <1> 
 18608                              <1> loc_check_filename_ext_1:
 18609 00005F62 AC                  <1> 	lodsb
 18610 00005F63 38E0                <1> 	cmp	al, ah ; 21h
 18611 00005F65 7212                <1> 	jb	short loc_check_fn_clc_rtn
 18612 00005F67 3C2E                <1> 	cmp	al, 2Eh
 18613 00005F69 74DE                <1> 	je	short loc_check_fn_stc_rtn
 18614 00005F6B AC                  <1> 	lodsb
 18615 00005F6C 38E0                <1> 	cmp	al, ah ; 21h
 18616 00005F6E 7209                <1> 	jb	short loc_check_fn_clc_rtn
 18617 00005F70 3C2E                <1> 	cmp	al, 2Eh
 18618 00005F72 74D5                <1> 	je	short loc_check_fn_stc_rtn
 18619 00005F74 AC                  <1> 	lodsb
 18620 00005F75 38E0                <1> 	cmp	al, ah ; 21h
 18621 00005F77 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
 18622                              <1> 
 18623                              <1> loc_check_fn_clc_rtn:
 18624 00005F79 5E                  <1> 	pop	esi
 18625 00005F7A F8                  <1> 	clc
 18626 00005F7B C3                  <1> 	retn
 18627                              <1> 
 18628                              <1> loc_print_deleted_message:
 18629 00005F7C BE[E7B90000]        <1> 	mov	esi, Msg_Deleted
 18630 00005F81 E844DFFFFF          <1> 	call	print_msg
 18631                              <1> 
 18632                              <1> 	;clc
 18633                              <1> 
 18634                              <1> loc_file_rw_restore_retn:
 18635                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18636                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
 18637                              <1> loc_file_rw_cmd_failed:
 18638 00005F86 9C                  <1> 	pushf 
 18639 00005F87 E85FF7FFFF          <1> 	call	restore_cdir_after_cmd_fail	
 18640 00005F8C 9D                  <1> 	popf
 18641 00005F8D 720D                <1> 	jc	short loc_file_rw_check_write_fault
 18642 00005F8F C3                  <1> 	retn
 18643                              <1> 
 18644                              <1> loc_permission_denied:
 18645                              <1> 	; 27/02/2016
 18646 00005F90 BE[F4B90000]        <1> 	mov	esi, Msg_Permission_Denied
 18647 00005F95 E830DFFFFF          <1> 	call	print_msg
 18648 00005F9A EBEA                <1> 	jmp	short loc_file_rw_restore_retn
 18649                              <1> 
 18650                              <1> loc_file_rw_check_write_fault:
 18651 00005F9C 3C1D                <1> 	cmp	al, 1Dh ; Write Fault
 18652 00005F9E 0F85F2F6FFFF        <1>         jne     loc_run_cmd_failed_cmp_al
 18653 00005FA4 BE[DFB70000]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
 18654                              <1> 	;call	print_msg
 18655                              <1> 	;retn
 18656 00005FA9 E91CDFFFFF          <1> 	jmp	print_msg
 18657                              <1> 
 18658                              <1> make_directory:
 18659                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18660                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
 18661                              <1> 	; 14/08/2010
 18662                              <1> 	; 10/07/2010
 18663                              <1> 	; 29/11/2009
 18664                              <1> 	;
 18665                              <1> get_mkdir_fchar:
 18666                              <1> 	; esi = directory name
 18667 00005FAE 803E20              <1> 	cmp	byte [esi], 20h
 18668 00005FB1 7701                <1>         ja	short loc_mkdir_parse_path_name
 18669                              <1> 
 18670                              <1> loc_mkdir_nodirname_retn:
 18671 00005FB3 C3                  <1> 	retn
 18672                              <1> 
 18673                              <1> loc_mkdir_parse_path_name:
 18674 00005FB4 BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 18675 00005FB9 E87B1A0000          <1>         call    parse_path_name
 18676 00005FBE 0F82A2F6FFFF        <1> 	jc	loc_cmd_failed
 18677                              <1> 
 18678                              <1> loc_mkdir_check_dirname_exists:
 18679 00005FC4 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 18680 00005FC9 803E20              <1> 	cmp	byte [esi], 20h
 18681 00005FCC 0F8694F6FFFF        <1> 	jna	loc_cmd_failed
 18682 00005FD2 8935[A4CF0000]      <1> 	mov	[DelFile_FNPointer], esi
 18683 00005FD8 E839FFFFFF          <1> 	call	check_filename
 18684 00005FDD 7259                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
 18685                              <1> 
 18686                              <1> loc_mkdir_drv:
 18687 00005FDF 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 18688 00005FE5 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 18689                              <1> 	
 18690 00005FEB 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 18691 00005FF1 38F2                <1> 	cmp	dl, dh
 18692 00005FF3 7407                <1> 	je	short loc_mkdir_change_directory
 18693                              <1> 
 18694 00005FF5 E8D4E7FFFF          <1> 	call	change_current_drive
 18695 00005FFA 728A                <1> 	jc	loc_file_rw_cmd_failed
 18696                              <1> 
 18697                              <1> loc_mkdir_change_directory:
 18698 00005FFC 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18699 00006003 7614                <1> 	jna	short loc_mkdir_find_directory
 18700                              <1> 
 18701 00006005 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 18702 0000600B BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 18703 00006010 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18704 00006012 E80E140000          <1> 	call	change_current_directory
 18705 00006017 722E                <1> 	jc	short loc_mkdir_check_error_code
 18706                              <1> 
 18707                              <1> ;loc_mkdir_change_prompt_dir_string:
 18708                              <1> 	;call	change_prompt_dir_string
 18709                              <1> 
 18710                              <1> loc_mkdir_find_directory:
 18711                              <1> 	;mov	esi, FindFile_Name
 18712 00006019 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18713                              <1> 	;xor	eax, eax
 18714 0000601F 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
 18715 00006022 E83BFBFFFF          <1> 	call	find_first_file
 18716 00006027 721E                <1> 	jc	short loc_mkdir_check_error_code
 18717                              <1> 
 18718                              <1> loc_mkdir_directory_found:
 18719 00006029 BE[3FB90000]        <1> 	mov	esi, Msg_Name_Exists
 18720 0000602E E897DEFFFF          <1> 	call	print_msg
 18721                              <1> 
 18722 00006033 E94EFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18723                              <1> 
 18724                              <1> loc_mkdir_invalid_dir_name_chars:
 18725 00006038 BE[12B90000]        <1> 	mov	esi, Msg_invalid_name_chars
 18726 0000603D E888DEFFFF          <1> 	call	print_msg
 18727                              <1> 
 18728 00006042 E93FFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18729                              <1> 
 18730                              <1> loc_mkdir_check_error_code:
 18731 00006047 3C02                <1> 	cmp	al, 2
 18732                              <1> 	;je	short loc_mkdir_directory_not_found
 18733 00006049 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
 18734 0000604B F9                  <1> 	stc
 18735 0000604C E935FFFFFF          <1>         jmp     loc_file_rw_cmd_failed
 18736                              <1> 
 18737                              <1> loc_mkdir_directory_not_found:
 18738                              <1> loc_mkdir_ask_for_yes_no:
 18739 00006051 BE[60B90000]        <1> 	mov	esi, Msg_DoYouWantMkdir
 18740 00006056 E86FDEFFFF          <1> 	call	print_msg
 18741 0000605B 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18742 00006061 E864DEFFFF          <1> 	call	print_msg
 18743 00006066 BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 18744 0000606B E85ADEFFFF          <1> 	call	print_msg
 18745                              <1> 
 18746 00006070 C605[89B90000]20    <1> 	mov	byte [Y_N_nextline], 20h
 18747                              <1> 
 18748                              <1> loc_mkdir_ask_again:
 18749 00006077 30E4                <1> 	xor	ah, ah
 18750 00006079 E869ABFFFF          <1> 	call	int16h
 18751 0000607E 3C1B                <1> 	cmp	al, 1Bh
 18752                              <1> 	;je	short loc_do_not_make_directory
 18753 00006080 7447                <1> 	je	short loc_mkdir_y_n_escape
 18754 00006082 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
 18755 00006084 3C59                <1> 	cmp	al, 'Y' ; 'yes'
 18756 00006086 7404                <1> 	je	short loc_mkdir_yes_make_directory
 18757 00006088 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18758 0000608A 75EB                <1> 	jne	short loc_mkdir_ask_again
 18759                              <1> 
 18760                              <1> loc_do_not_make_directory:
 18761                              <1> loc_mkdir_yes_make_directory:
 18762 0000608C A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 18763 00006091 6650                <1> 	push	ax
 18764 00006093 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 18765 00006098 E82DDEFFFF          <1> 	call	print_msg
 18766 0000609D 6658                <1> 	pop	ax
 18767                              <1> 	;cmp	al, 'Y' ; 'yes'
 18768                              <1> 	;cmc
 18769                              <1>         ;jnc	loc_file_rw_restore_retn
 18770 0000609F 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18771 000060A1 0F84DFFEFFFF        <1>         je	loc_file_rw_restore_retn  
 18772                              <1> 
 18773                              <1> loc_mkdir_call_make_sub_directory:
 18774 000060A7 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18775 000060AD B110                <1> 	mov	cl, 10h ; Directory attributes 
 18776 000060AF E8841A0000          <1> 	call	make_sub_directory
 18777                              <1> loc_rename_file_ok: ; 06/03/2016
 18778 000060B4 0F82CCFEFFFF        <1>         jc	loc_file_rw_cmd_failed
 18779                              <1> move_source_file_to_destination_OK:
 18780 000060BA BE[8DB90000]        <1> 	mov	esi, Msg_OK
 18781 000060BF E806DEFFFF          <1> 	call	print_msg
 18782 000060C4 E9BDFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18783                              <1> 
 18784                              <1> loc_mkdir_y_n_escape:
 18785 000060C9 B04E                <1> 	mov	al, 'N' ; 'no'
 18786 000060CB EBBF                <1> 	jmp	short loc_do_not_make_directory
 18787                              <1> 
 18788                              <1> delete_directory:
 18789                              <1> 	; 06/03/2016
 18790                              <1> 	; 01/03/2016
 18791                              <1> 	; 29/02/2016
 18792                              <1> 	; 28/02/2016
 18793                              <1> 	; 27/02/2016
 18794                              <1> 	; 26/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18795                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
 18796                              <1> 	; 05/06/2010
 18797                              <1> 	;
 18798                              <1> get_rmdir_fchar:
 18799                              <1> 	; esi = directory name
 18800 000060CD 803E20              <1> 	cmp	byte [esi], 20h
 18801 000060D0 7701                <1>         ja	short loc_rmdir_parse_path_name
 18802                              <1> 
 18803                              <1> loc_rmdir_nodirname_retn:
 18804 000060D2 C3                  <1> 	retn
 18805                              <1> 
 18806                              <1> loc_rmdir_parse_path_name:
 18807 000060D3 BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 18808 000060D8 E85C190000          <1> 	call	parse_path_name
 18809 000060DD 0F8283F5FFFF        <1> 	jc	loc_cmd_failed
 18810                              <1> 
 18811                              <1> loc_rmdir_check_dirname_exists:
 18812 000060E3 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 18813 000060E8 803E20              <1> 	cmp	byte [esi], 20h
 18814 000060EB 0F8675F5FFFF        <1> 	jna	loc_cmd_failed
 18815 000060F1 8935[A4CF0000]      <1> 	mov	[DelFile_FNPointer], esi 
 18816                              <1> 
 18817                              <1> loc_rmdir_drv:
 18818 000060F7 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 18819 000060FD 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 18820                              <1> 
 18821 00006103 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 18822 00006109 38F2                <1> 	cmp	dl, dh
 18823 0000610B 740B                <1> 	je	short loc_rmdir_change_directory
 18824                              <1> 
 18825 0000610D E8BCE6FFFF          <1> 	call	change_current_drive
 18826 00006112 0F826EFEFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18827                              <1> 
 18828                              <1> loc_rmdir_change_directory:
 18829 00006118 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18830 0000611F 7614                <1> 	jna	short loc_rmdir_find_directory
 18831                              <1> 
 18832 00006121 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 18833 00006127 BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 18834 0000612C 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18835 0000612E E8F2120000          <1> 	call	change_current_directory
 18836 00006133 7211                <1> 	jc	short loc_rmdir_check_error_code
 18837                              <1> 
 18838                              <1> ;loc_rmdir_change_prompt_dir_string:
 18839                              <1> 	;call	change_prompt_dir_string
 18840                              <1> 
 18841                              <1> loc_rmdir_find_directory:
 18842                              <1> 	;mov	esi, FindFile_Name
 18843 00006135 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18844 0000613B 66B81008            <1> 	mov	ax, 0810h ; Only directories
 18845 0000613F E81EFAFFFF          <1> 	call	find_first_file
 18846 00006144 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
 18847                              <1> 
 18848                              <1> loc_rmdir_check_error_code:
 18849 00006146 3C02                <1> 	cmp	al, 2
 18850 00006148 740B                <1> 	je	short loc_rmdir_directory_not_found
 18851 0000614A F9                  <1> 	stc
 18852 0000614B E936FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18853                              <1> 
 18854                              <1> loc_rmdir_ambgfn_check:
 18855 00006150 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 18856 00006153 740F                <1> 	jz	short loc_rmdir_directory_found
 18857                              <1> 
 18858                              <1> loc_rmdir_directory_not_found:
 18859 00006155 BE[01B80000]        <1> 	mov	esi, Msg_Dir_Not_Found
 18860 0000615A E86BDDFFFF          <1> 	call	print_msg
 18861                              <1> 
 18862 0000615F E922FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18863                              <1> 
 18864                              <1> loc_rmdir_directory_found:
 18865 00006164 80E307              <1> 	and	bl, 07h ; Attributes
 18866 00006167 0F8523FEFFFF        <1> 	jnz	loc_permission_denied
 18867                              <1> 
 18868                              <1> loc_rmdir_save_lnel: ; 28/02/2016
 18869                              <1>        ;mov	bh, [LongName_EntryLength]
 18870 0000616D 883D[AECF0000]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 18871                              <1> 	; edi = Directory Entry Offset (DirBuff)
 18872                              <1> 	; esi = Directory Entry (FFF Structure)
 18873                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
 18874                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
 18875                              <1>         ;shl	eax, 16
 18876                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
 18877                              <1> 	; ROOT Dir First Cluster = 0
 18878                              <1>         ;cmp	eax, 2
 18879                              <1> 	;jb	loc_update_direntry_1
 18880                              <1> 
 18881                              <1> pass_rmdir_fc_check:
 18882 00006173 57                  <1> 	push	edi ; * (29/02/2016)
 18883                              <1> 
 18884 00006174 BE[93B90000]        <1> 	mov	esi, Msg_DoYouWantRmDir
 18885 00006179 E84CDDFFFF          <1> 	call	print_msg
 18886 0000617E 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18887 00006184 E841DDFFFF          <1> 	call	print_msg
 18888 00006189 BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 18889 0000618E E837DDFFFF          <1> 	call	print_msg
 18890                              <1> 
 18891                              <1> loc_rmdir_ask_again:
 18892 00006193 30E4                <1> 	xor	ah, ah
 18893 00006195 E84DAAFFFF          <1> 	call	int16h
 18894 0000619A 3C1B                <1> 	cmp	al, 1Bh
 18895                              <1> 	;je	short loc_do_not_delete_directory
 18896 0000619C 0F8498000000        <1>         je      loc_rmdir_y_n_escape ; 06/03/2016
 18897 000061A2 24DF                <1> 	and	al, 0DFh
 18898 000061A4 A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 18899 000061A9 3C59                <1> 	cmp	al, 'Y'
 18900 000061AB 7404                <1> 	je	short loc_rmdir_yes_delete_directory
 18901 000061AD 3C4E                <1> 	cmp	al, 'N'
 18902 000061AF 75E2                <1> 	jne	short loc_rmdir_ask_again
 18903                              <1> 
 18904                              <1> loc_do_not_delete_directory:
 18905                              <1> loc_rmdir_yes_delete_directory:
 18906 000061B1 A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 18907 000061B6 6650                <1> 	push	ax
 18908 000061B8 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 18909 000061BD E808DDFFFF          <1> 	call	print_msg
 18910 000061C2 6658                <1> 	pop	ax
 18911 000061C4 5F                  <1> 	pop	edi ; * (29/02/2016)
 18912                              <1> 	;cmp	al, 'Y' ; 'yes'
 18913                              <1> 	;cmc
 18914                              <1>         ;jnc	loc_file_rw_restore_retn
 18915 000061C5 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18916 000061C7 0F84B9FDFFFF        <1>         je	loc_file_rw_restore_retn  
 18917                              <1> 
 18918                              <1> loc_rmdir_delete_short_name_check_dir_empty:
 18919                              <1> 	; EDI = Directory buffer entry offset/address 
 18920 000061CD 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 18921 000061D1 C1E010              <1>         shl	eax, 16
 18922 000061D4 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 18923                              <1> 
 18924 000061D8 A3[A8CF0000]        <1> 	mov 	[DelFile_FCluster], eax
 18925                              <1> 
 18926                              <1> 	;mov	bx, [DirBuff_EntryCounter]
 18927 000061DD 668B1D[60CF0000]    <1> 	mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
 18928 000061E4 66891D[ACCF0000]    <1> 	mov	[DelFile_EntryCounter], bx
 18929                              <1> 
 18930 000061EB 29DB                <1>     	sub	ebx, ebx
 18931 000061ED 8A3D[E6CE0000]      <1> 	mov	bh, [FindFile_Drv]
 18932 000061F3 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18933 000061F8 01DE                <1> 	add	esi, ebx
 18934                              <1> 
 18935 000061FA 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
 18936 00006200 743F                <1> 	je	short loc_rmdir_delete_fs_directory
 18937                              <1> 
 18938                              <1> 	;cmp	byte [esi+LD_FATType], 1
 18939                              <1> 	;jnb	short loc_rmdir_get__last_cluster_0
 18940                              <1> 	;mov	eax, 0Bh ; Invalid Format
 18941                              <1> 	;jmp	loc_file_rw_cmd_failed
 18942                              <1>   
 18943                              <1> ;loc_rmdir_get_last_cluster_0:
 18944 00006202 8B15[71CD0000]      <1> 	mov	edx, [DirBuff_Cluster]
 18945 00006208 8915[D8CF0000]      <1> 	mov	[RmDir_ParentDirCluster], edx
 18946                              <1> 
 18947 0000620E 893D[D4CF0000]      <1> 	mov	[RmDir_DirEntryOffset], edi
 18948                              <1> 
 18949                              <1> 	; 01/03/2016
 18950 00006214 C705[61CD0000]0000- <1> 	mov	dword [FAT_ClusterCounter], 0 ; Reset
 18951 0000621C 0000                <1>
 18952                              <1> 
 18953                              <1> loc_rmdir_get_last_cluster:
 18954 0000621E E808370000          <1> 	call	get_last_cluster
 18955 00006223 0F82B8000000        <1>         jc      loc_rmdir_cmd_failed
 18956                              <1> 	
 18957 00006229 3B05[A8CF0000]      <1> 	cmp	eax, [DelFile_FCluster]
 18958 0000622F 752F                <1> 	jne	short loc_rmdir_multi_dir_clusters
 18959                              <1> 
 18960 00006231 C605[D3CF0000]00    <1> 	mov	byte [RmDir_MultiClusters], 0
 18961 00006238 EB2D                <1> 	jmp	short pass_rmdir_multi_dir_clusters
 18962                              <1> 
 18963                              <1> loc_rmdir_y_n_escape:
 18964 0000623A B04E                <1> 	mov	al, 'N' ; 'no'
 18965 0000623C E970FFFFFF          <1>         jmp     loc_do_not_delete_directory
 18966                              <1> 
 18967                              <1> loc_rmdir_delete_fs_directory:
 18968 00006241 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 18969 00006245 0F8545FDFFFF        <1> 	jne	loc_permission_denied
 18970                              <1> 
 18971 0000624B E8F2100000          <1> 	call	delete_fs_directory
 18972 00006250 0F8326FDFFFF        <1> 	jnc	loc_print_deleted_message
 18973                              <1> 
 18974 00006256 09C0                <1> 	or	eax, eax
 18975 00006258 745D                <1> 	jz	loc_rmdir_directory_not_empty_2         
 18976 0000625A F9                  <1> 	stc
 18977 0000625B E926FDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18978                              <1>  
 18979                              <1> loc_rmdir_multi_dir_clusters:
 18980 00006260 C605[D3CF0000]01    <1> 	mov	byte [RmDir_MultiClusters], 1
 18981                              <1> 
 18982                              <1> pass_rmdir_multi_dir_clusters:
 18983 00006267 A3[DCCF0000]        <1> 	mov 	[RmDir_DirLastCluster], eax
 18984 0000626C 890D[E0CF0000]      <1> 	mov	[RmDir_PreviousCluster], ecx
 18985                              <1> 
 18986                              <1> loc_rmdir_load_fat_sub_directory:
 18987 00006272 E89F300000          <1> 	call	load_FAT_sub_directory
 18988 00006277 7268                <1> 	jc	loc_rmdir_cmd_failed
 18989                              <1> 
 18990                              <1> loc_rmdir_find_last_dir_entry:
 18991 00006279 56                  <1> 	push	esi
 18992 0000627A BE[CACE0000]        <1> 	mov	esi, Dir_File_Name
 18993 0000627F C6062A              <1> 	mov	byte [esi], '*'
 18994 00006282 C646082A            <1> 	mov	byte [esi+8], '*'
 18995 00006286 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
 18996                              <1> loc_rmdir_find_last_dir_entry_next:
 18997 00006288 66B80008            <1> 	mov	ax, 0800h ; Except volume/long names
 18998 0000628C 6631C9              <1> 	xor	cx, cx ; 0 = Find a valid file or dir name
 18999 0000628F E8E7140000          <1> 	call	find_directory_entry
 19000 00006294 7271                <1> 	jc	short loc_rmdir_empty_dir_cluster
 19001 00006296 83FB01              <1> 	cmp	ebx, 1
 19002 00006299 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
 19003                              <1> loc_rmdir_dot_entry_check:
 19004 0000629B 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
 19005 0000629E 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
 19006 000062A0 08DB                <1> 	or	bl, bl
 19007 000062A2 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
 19008 000062A4 807F0120            <1> 	cmp	byte [edi+1], 20h
 19009 000062A8 EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
 19010                              <1> 
 19011                              <1> loc_rmdir_dotdot_entry_check:
 19012 000062AA 66817F012E20        <1> 	cmp	word [edi+1], '. '
 19013                              <1> pass_rmdir_dot_entry_check:	
 19014 000062B0 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
 19015 000062B2 FEC3                <1> 	inc	bl
 19016 000062B4 EBD2                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next 
 19017                              <1> 
 19018                              <1> 
 19019                              <1> loc_rmdir_directory_not_empty_1:
 19020 000062B6 58                  <1> 	pop	eax ; pushed esi 
 19021                              <1> 
 19022                              <1> loc_rmdir_directory_not_empty_2:
 19023 000062B7 BE[B4B90000]        <1> 	mov	esi, Msg_Dir_Not_Empty
 19024 000062BC E809DCFFFF          <1> 	call	print_msg
 19025                              <1> 	; 01/03/2016
 19026 000062C1 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 19027 000062C6 09C0                <1> 	or	eax, eax ; 0 ?
 19028 000062C8 0F84B8FCFFFF        <1> 	jz	loc_file_rw_restore_retn
 19029                              <1> 	; ESI = Logical DOS Drive Description Table address	
 19030                              <1> 
 19031 000062CE 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
 19032                              <1> 	           ; BL = 1 -> add free clusters
 19033 000062D2 E8D5340000          <1> 	call	calculate_fat_freespace
 19034 000062D7 09C9                <1> 	or	ecx, ecx
 19035 000062D9 0F84A7FCFFFF        <1>         jz      loc_file_rw_restore_retn ; ecx = 0 -> OK
 19036                              <1> 	; ecx > 0 -> Error (Recalculation is neeeded)
 19037 000062DF EB0E                <1> 	jmp	short loc_rmdir_cmd_return
 19038                              <1> 
 19039                              <1> 
 19040                              <1> loc_rmdir_cmd_failed:
 19041 000062E1 833D[61CD0000]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
 19042 000062E8 0F8298FCFFFF        <1> 	jb	loc_file_rw_cmd_failed	
 19043 000062EE F9                  <1> 	stc
 19044                              <1> loc_rmdir_cmd_return:
 19045                              <1> 	; 01/03/2016
 19046 000062EF 9C                  <1> 	pushf
 19047                              <1> 	; ESI = Logical DOS Drive Description Table address	
 19048 000062F0 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
 19049                              <1> 	           ; BL = 0 -> Recalculate free cluster count
 19050 000062F4 50                  <1> 	push	eax
 19051 000062F5 E8B2340000          <1> 	call	calculate_fat_freespace	
 19052 000062FA 58                  <1> 	pop	eax
 19053 000062FB 9D                  <1> 	popf
 19054 000062FC 0F8284FCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19055 00006302 E97FFCFFFF          <1> 	jmp	loc_file_rw_restore_retn
 19056                              <1> 
 19057                              <1> 
 19058                              <1> loc_rmdir_empty_dir_cluster:
 19059 00006307 5E                  <1> 	pop	esi
 19060                              <1> 
 19061                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
 19062 00006308 803D[D3CF0000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 19063 0000630F 761D                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
 19064                              <1> 
 19065 00006311 A1[E0CF0000]        <1> 	mov	eax, [RmDir_PreviousCluster]
 19066                              <1> 	;xor	ecx, ecx
 19067 00006316 49                  <1> 	dec	ecx ; FFFFFFFFh
 19068 00006317 E83E310000          <1> 	call	update_cluster
 19069 0000631C 7310                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
 19070                              <1> 
 19071                              <1> loc_rmdir_unlink_stc_retn:
 19072                              <1> 	; 01/03/2016
 19073 0000631E 83F801              <1> 	cmp	eax, 1  ; eax = 0 -> end of cluster chain
 19074 00006321 F5                  <1> 	cmc 
 19075 00006322 72BD                <1> 	jc	short loc_rmdir_cmd_failed
 19076 00006324 EB1D                <1> 	jmp	short loc_rmdir_save_fat_buffer 
 19077                              <1> 	
 19078                              <1> loc_rmdir_unlink_stc_retn_0Bh:
 19079 00006326 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 19080 0000632B F9                  <1> 	stc
 19081 0000632C EBB3                <1> 	jmp	short loc_rmdir_cmd_failed
 19082                              <1>  
 19083                              <1> loc_rmdir_unlink_dir_last_cluster:
 19084 0000632E A1[DCCF0000]        <1> 	mov	eax, [RmDir_DirLastCluster]
 19085 00006333 31C9                <1> 	xor	ecx, ecx ; 0
 19086 00006335 E820310000          <1> 	call	update_cluster
 19087 0000633A 73EA                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh
 19088                              <1> 	; Because of it is the last cluster
 19089                              <1> 	; 'update_cluster' must return with eocc error 
 19090 0000633C 09C0                <1> 	or	eax, eax
 19091 0000633E 7403                <1> 	jz	short loc_rmdir_save_fat_buffer ; eocc	
 19092 00006340 F9                  <1> 	stc
 19093 00006341 EB9E                <1>         jmp     short loc_rmdir_cmd_failed
 19094                              <1> 	 
 19095                              <1> loc_rmdir_save_fat_buffer:
 19096 00006343 803D[59CD0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 19097 0000634A 7525                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
 19098 0000634C E8C6330000          <1> 	call	save_fat_buffer
 19099 00006351 728E                <1> 	jc	short loc_rmdir_cmd_failed
 19100                              <1> 
 19101                              <1> 	; 01/03/2016
 19102 00006353 803D[D3CF0000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 19103 0000635A 7615                <1> 	jna	short loc_rmdir_calculate_FAT_freespace
 19104                              <1> 
 19105 0000635C A1[A8CF0000]        <1> 	mov	eax, [DelFile_FCluster]
 19106 00006361 E9B8FEFFFF          <1>         jmp     loc_rmdir_get_last_cluster
 19107                              <1> 
 19108                              <1> loc_rmdir_delete_short_name_invalid_data:
 19109 00006366 B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
 19110 0000636B F9                  <1> 	stc
 19111 0000636C E970FFFFFF          <1>         jmp     loc_rmdir_cmd_failed
 19112                              <1> 
 19113                              <1> loc_rmdir_calculate_FAT_freespace:
 19114 00006371 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 19115 00006376 66BB01FF            <1> 	mov	bx, 0FF01h
 19116                              <1> 	; BL = 1 -> Add EAX to free space count
 19117                              <1> 	; BH = FFh ->
 19118                              <1> 	; ESI = Logical DOS Drive Description Table address
 19119 0000637A E82D340000          <1> 	call	calculate_fat_freespace
 19120                              <1> 
 19121 0000637F 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
 19122 00006381 7409                <1> 	jz 	short loc_rmdir_delete_short_name_continue
 19123                              <1> 
 19124                              <1> loc_rmdir_recalculate_FAT_freespace:
 19125 00006383 66BB00FF            <1>         mov     bx, 0FF00h ; BL = 0 -> Recalculate free space
 19126 00006387 E820340000          <1> 	call	calculate_fat_freespace
 19127                              <1> 	          
 19128                              <1> loc_rmdir_delete_short_name_continue:
 19129 0000638C A1[D8CF0000]        <1> 	mov	eax, [RmDir_ParentDirCluster]
 19130 00006391 83F802              <1> 	cmp	eax, 2
 19131 00006394 730D                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
 19132 00006396 E8F02E0000          <1> 	call	load_FAT_root_directory
 19133 0000639B 0F82E5FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19134 000063A1 EB0B                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
 19135                              <1> 
 19136                              <1> loc_rmdir_del_short_name_load_sub_dir:	
 19137 000063A3 E86E2F0000          <1> 	call	load_FAT_sub_directory
 19138 000063A8 0F82D8FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19139                              <1> 
 19140                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
 19141 000063AE 0FB73D[D4CF0000]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
 19142 000063B5 81C700000800        <1> 	add	edi, Directory_Buffer
 19143                              <1> 
 19144 000063BB 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 19145 000063BF C1E010              <1> 	shl	eax, 16
 19146 000063C2 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 19147                              <1>         ; Not necessary... 
 19148 000063C6 3B05[A8CF0000]      <1> 	cmp	eax, [DelFile_FCluster]
 19149 000063CC 7598                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
 19150                              <1> 	;
 19151 000063CE C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
 19152                              <1> 	; 27/02/2016
 19153                              <1> 	; TRDOS v1 has a bug here! it does not set
 19154                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
 19155                              <1> 	; 'save_directory_buffer' would not save the change ! 
 19156 000063D1 C605[6CCD0000]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
 19157                              <1> 	;
 19158 000063D8 E8C01A0000          <1> 	call	save_directory_buffer
 19159 000063DD 0F82A3FBFFFF        <1> 	jc	loc_file_rw_cmd_failed 
 19160                              <1> 
 19161                              <1> loc_rmdir_del_long_name:
 19162 000063E3 0FB615[AECF0000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 19163 000063EA 08D2                <1> 	or	dl, dl
 19164 000063EC 7414                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
 19165                              <1>              
 19166 000063EE 0FB705[ACCF0000]    <1> 	movzx	eax, word [DelFile_EntryCounter]
 19167 000063F5 29D0                <1> 	sub	eax, edx
 19168 000063F7 0F8289FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19169                              <1>  
 19170                              <1>  	; EAX = Directory Entry Number of the long name last entry
 19171 000063FD E8FB1B0000          <1> 	call	delete_longname
 19172                              <1> 	;jc	short loc_file_rw_cmd_failed
 19173                              <1> 
 19174                              <1> loc_rmdir_update_parent_dir_lmdt:
 19175 00006402 E8311B0000          <1> 	call	update_parent_dir_lmdt
 19176                              <1> 	;jc	short loc_file_rw_cmd_failed
 19177                              <1> 
 19178                              <1> loc_rmdir_ok:
 19179 00006407 BE[8DB90000]        <1> 	mov	esi, Msg_OK
 19180 0000640C E8B9DAFFFF          <1> 	call	print_msg
 19181 00006411 E970FBFFFF          <1> 	jmp	loc_file_rw_restore_retn
 19182                              <1> 
 19183                              <1> 
 19184                              <1> delete_file:
 19185                              <1> 	; 29/02/2016
 19186                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 19187                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
 19188                              <1> 	; 28/02/2010
 19189                              <1> 
 19190                              <1> get_delfile_fchar:
 19191                              <1> 	; esi = file name
 19192 00006416 803E20              <1> 	cmp	byte [esi], 20h
 19193 00006419 7701                <1>         ja	short loc_delfile_parse_path_name
 19194                              <1> 
 19195                              <1> loc_delfile_nofilename_retn:
 19196 0000641B C3                  <1> 	retn
 19197                              <1> 
 19198                              <1> loc_delfile_parse_path_name:
 19199 0000641C BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 19200 00006421 E813160000          <1> 	call	parse_path_name
 19201 00006426 0F823AF2FFFF        <1> 	jc	loc_cmd_failed
 19202                              <1> 
 19203                              <1> loc_delfile_check_filename_exists:
 19204 0000642C BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19205 00006431 803E20              <1> 	cmp	byte [esi], 20h
 19206 00006434 0F862CF2FFFF        <1> 	jna	loc_cmd_failed
 19207 0000643A 8935[A4CF0000]      <1> 	mov	[DelFile_FNPointer], esi 
 19208                              <1> 
 19209                              <1> loc_delfile_drv:
 19210 00006440 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 19211 00006446 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 19212 0000644C 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 19213 00006452 38F2                <1> 	cmp	dl, dh
 19214 00006454 740B                <1> 	je	short loc_delfile_change_directory
 19215                              <1> 
 19216 00006456 E873E3FFFF          <1> 	call	change_current_drive
 19217 0000645B 0F8225FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19218                              <1> 
 19219                              <1> loc_delfile_change_directory:
 19220 00006461 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 19221 00006468 7618                <1> 	jna	short loc_delfile_find
 19222                              <1> 
 19223 0000646A FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 19224 00006470 BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 19225 00006475 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19226 00006477 E8A90F0000          <1> 	call	change_current_directory
 19227 0000647C 0F8204FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19228                              <1> 
 19229                              <1> ;loc_delfile_change_prompt_dir_string:
 19230                              <1> 	;call	change_prompt_dir_string
 19231                              <1> 
 19232                              <1> loc_delfile_find:
 19233                              <1> 	;mov	esi, FindFile_Name
 19234 00006482 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 19235 00006488 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 19236 0000648C E8D1F6FFFF          <1> 	call	find_first_file
 19237 00006491 0F82EFFAFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19238                              <1> 
 19239                              <1> loc_delfile_ambgfn_check:
 19240 00006497 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19241 0000649A 740B                <1> 	jz	short loc_delfile_found
 19242                              <1> 
 19243                              <1> loc_file_not_found:
 19244 0000649C B802000000          <1> 	mov	eax, 2 ; File not found sign
 19245 000064A1 F9                  <1> 	stc
 19246 000064A2 E9DFFAFFFF          <1> 	jmp	loc_file_rw_cmd_failed   
 19247                              <1> 
 19248                              <1> loc_delfile_found:
 19249 000064A7 80E307              <1> 	and	bl, 07h ; Attributes
 19250 000064AA 0F85E0FAFFFF        <1>         jnz     loc_permission_denied
 19251                              <1> 
 19252                              <1> ;loc_delfile_found_save_lnel:
 19253                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 19254                              <1> 
 19255                              <1> loc_delfile_ask_for_delete:
 19256 000064B0 57                  <1> 	push	edi ; * (29/02/2016)
 19257                              <1> 
 19258 000064B1 BE[CBB90000]        <1> 	mov	esi, Msg_DoYouWantDelete
 19259 000064B6 E80FDAFFFF          <1> 	call	print_msg
 19260 000064BB 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 19261 000064C1 E804DAFFFF          <1> 	call	print_msg
 19262 000064C6 BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 19263 000064CB E8FAD9FFFF          <1> 	call	print_msg
 19264                              <1> 
 19265                              <1> loc_delfile_ask_again:
 19266 000064D0 30E4                <1> 	xor	ah, ah
 19267 000064D2 E810A7FFFF          <1> 	call	int16h
 19268 000064D7 3C1B                <1> 	cmp	al, 1Bh
 19269                              <1> 	;je	short loc_do_not_delete_file
 19270 000064D9 7457                <1> 	je	short loc_delfile_y_n_escape ; 06/03/2016
 19271 000064DB 24DF                <1> 	and	al, 0DFh
 19272 000064DD A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 19273 000064E2 3C59                <1> 	cmp	al, 'Y'
 19274 000064E4 7404                <1> 	je	short loc_yes_delete_file
 19275 000064E6 3C4E                <1> 	cmp	al, 'N'
 19276 000064E8 75E6                <1> 	jne	short loc_delfile_ask_again
 19277                              <1> 
 19278                              <1> loc_do_not_delete_file:
 19279                              <1> loc_yes_delete_file:
 19280 000064EA A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 19281 000064EF 6650                <1> 	push	ax
 19282 000064F1 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 19283 000064F6 E8CFD9FFFF          <1> 	call	print_msg
 19284 000064FB 6658                <1> 	pop	ax
 19285 000064FD 5F                  <1> 	pop	edi ; * (29/02/2016)
 19286                              <1> 	;cmp	al, 'Y' ; 'yes'
 19287                              <1> 	;cmc
 19288                              <1>         ;jnc	loc_file_rw_restore_retn
 19289 000064FE 3C4E                <1> 	cmp	al, 'N' ; 'no'
 19290 00006500 0F8480FAFFFF        <1>         je	loc_file_rw_restore_retn  
 19291                              <1> 
 19292                              <1> loc_delete_file:
 19293 00006506 8A3D[E6CE0000]      <1> 	mov	bh, [FindFile_Drv]
 19294                              <1> 	;mov	bl, [DelFile_LNEL]
 19295 0000650C 8A1D[35CF0000]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
 19296                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 19297 00006512 668B0D[60CF0000]    <1> 	mov	cx, [FindFile_DirEntryNumber]
 19298                              <1> 	; (*) EDI = Directory buffer entry offset/address 
 19299 00006519 E8C91C0000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
 19300 0000651E 0F8358FAFFFF        <1> 	jnc	loc_print_deleted_message
 19301                              <1> 
 19302 00006524 3C05                <1> 	cmp	al, 05h
 19303 00006526 0F8464FAFFFF        <1> 	je	loc_permission_denied
 19304 0000652C F9                  <1> 	stc
 19305 0000652D E954FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19306                              <1> 
 19307                              <1> loc_delfile_y_n_escape:
 19308 00006532 B04E                <1> 	mov	al, 'N' ; 'no'
 19309 00006534 EBB4                <1> 	jmp	short loc_do_not_delete_file
 19310                              <1> 
 19311                              <1> set_file_attributes:
 19312                              <1> 	; 06/03/2016
 19313                              <1> 	; 04/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19314                              <1> 	; 10/07/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_attrib')
 19315                              <1> 	; 23/05/2010 
 19316                              <1> 	; 17/12/2000 (P2000.ASM)
 19317                              <1> 
 19318                              <1> 	; esi = file or directory name
 19319 00006536 6631C0              <1> 	xor	ax, ax
 19320 00006539 66A3[1CBA0000]      <1> 	mov	[Attr_Chars], ax
 19321 0000653F A2[FCCF0000]        <1> 	mov	[Attributes], al
 19322                              <1> 
 19323                              <1> get_attrib_fchar:
 19324                              <1> 	; esi = file name
 19325 00006544 8A06                <1> 	mov	al, [esi]
 19326 00006546 3C20                <1> 	cmp	al, 20h
 19327 00006548 7623                <1> 	jna	short loc_attr_file_nofilename_retn
 19328                              <1> 
 19329                              <1> loc_scan_attrib_params:
 19330 0000654A 3C2D                <1> 	cmp	al, '-'
 19331 0000654C 0F871C010000        <1> 	ja	loc_attr_file_parse_path_name
 19332 00006552 7408                <1> 	je	short loc_attr_space
 19333                              <1> 
 19334 00006554 3C2B                <1> 	cmp	al, '+'
 19335 00006556 0F850AF1FFFF        <1> 	jne	loc_cmd_failed
 19336                              <1> 
 19337                              <1> loc_attr_space:
 19338 0000655C 8A6601              <1> 	mov	ah, [esi+1]
 19339 0000655F 80FC20              <1>  	cmp	ah, 20h
 19340 00006562 770A                <1> 	ja	short pass_attr_space
 19341 00006564 0F82FCF0FFFF        <1> 	jb	loc_cmd_failed
 19342 0000656A 46                  <1> 	inc	esi
 19343 0000656B EBEF                <1> 	jmp	short loc_attr_space
 19344                              <1> 
 19345                              <1> loc_attr_file_nofilename_retn:
 19346 0000656D C3                  <1> 	retn
 19347                              <1> 
 19348                              <1> pass_attr_space:
 19349 0000656E 80E4DF              <1> 	and	ah, 0DFh
 19350 00006571 80FC53              <1> 	cmp	ah, 'S'
 19351 00006574 0F87ECF0FFFF        <1> 	ja	loc_cmd_failed
 19352 0000657A 7204                <1> 	jb	short pass_attr_system
 19353 0000657C B404                <1> 	mov	ah, 04h   ; System
 19354 0000657E EB21                <1> 	jmp	short pass_attr_archive
 19355                              <1> 
 19356                              <1> pass_attr_system:
 19357 00006580 80FC48              <1> 	cmp	ah, 'H'
 19358 00006583 7706                <1> 	ja	short pass_attr_hidden
 19359 00006585 7213                <1> 	jb	short pass_attr_read_only
 19360 00006587 B402                <1> 	mov	ah, 02h    ; Hidden
 19361 00006589 EB16                <1> 	jmp	short pass_attr_archive
 19362                              <1> 
 19363                              <1> pass_attr_hidden:
 19364 0000658B 80FC52              <1> 	cmp	ah, 'R'
 19365 0000658E 0F87D2F0FFFF        <1> 	ja	loc_cmd_failed
 19366 00006594 7204                <1> 	jb	short pass_attr_read_only ; Read only
 19367 00006596 B401                <1> 	mov	ah, 01h
 19368 00006598 EB07                <1> 	jmp	short pass_attr_archive
 19369                              <1> 
 19370                              <1> pass_attr_read_only:
 19371 0000659A 80FC41              <1> 	cmp	ah, 'A'
 19372 0000659D 753B                <1> 	jne	short loc_chk_attr_enter
 19373 0000659F B420                <1> 	mov	ah, 20h    ; Archive
 19374                              <1> 
 19375                              <1> pass_attr_archive:
 19376 000065A1 3C2D                <1> 	cmp	al, '-'
 19377 000065A3 7508                <1> 	jne	short pass_reducing_attributes
 19378 000065A5 0825[1CBA0000]      <1> 	or	[Attr_Chars], ah
 19379 000065AB EB06                <1> 	jmp	short loc_change_attributes_inc
 19380                              <1> 
 19381                              <1> pass_reducing_attributes:
 19382 000065AD 0825[1DBA0000]      <1> 	or	[Attr_Chars+1], ah
 19383                              <1> 
 19384                              <1> loc_change_attributes_inc:
 19385 000065B3 46                  <1> 	inc	esi
 19386 000065B4 8A6601              <1> 	mov	ah, [esi+1]
 19387 000065B7 80FC20              <1> 	cmp	ah, 20h
 19388 000065BA 7227                <1> 	jb	short pass_change_attr
 19389 000065BC 74F5                <1> 	je	short loc_change_attributes_inc
 19390 000065BE 80FC2D              <1> 	cmp	ah, '-'
 19391 000065C1 770D                <1> 	ja	short loc_chk_next_attr_char1
 19392 000065C3 7405                <1> 	je	short loc_chk_next_attr_char0
 19393 000065C5 80FC2B              <1> 	cmp	ah, '+'
 19394 000065C8 7506                <1> 	jne	short loc_chk_next_attr_char1
 19395                              <1> 
 19396                              <1> loc_chk_next_attr_char0:
 19397 000065CA 46                  <1> 	inc	esi
 19398 000065CB 668B06              <1> 	mov	ax, [esi]
 19399 000065CE EB9E                <1> 	jmp	short pass_attr_space
 19400                              <1> 
 19401                              <1> loc_chk_next_attr_char1:
 19402 000065D0 803E2D              <1> 	cmp	byte [esi], '-'
 19403 000065D3 7799                <1> 	ja	short pass_attr_space
 19404 000065D5 E988000000          <1>         jmp     loc_attr_file_check_fname_fchar
 19405                              <1> 
 19406                              <1> loc_chk_attr_enter:
 19407 000065DA 80FC0D              <1> 	cmp	ah, 0Dh
 19408 000065DD 0F8583F0FFFF        <1> 	jne	loc_cmd_failed
 19409                              <1> 
 19410                              <1> pass_change_attr:
 19411 000065E3 A0[1CBA0000]        <1> 	mov	al, [Attr_Chars]
 19412 000065E8 F6D0                <1> 	not	al
 19413 000065EA 2005[FCCF0000]      <1> 	and	[Attributes], al
 19414 000065F0 A0[1DBA0000]        <1> 	mov	al, [Attr_Chars+1]
 19415 000065F5 0805[FCCF0000]      <1> 	or	[Attributes], al
 19416                              <1> 
 19417                              <1> loc_show_attributes:
 19418 000065FB BE[56C10000]        <1> 	mov	esi, nextline
 19419 00006600 E8C5D8FFFF          <1> 	call	print_msg
 19420                              <1> 
 19421                              <1> loc_show_attributes_no_nextline:
 19422 00006605 C705[1CBA0000]4E4F- <1> 	mov	dword [Attr_Chars], 'NORM'
 19423 0000660D 524D                <1>
 19424 0000660F 66C705[20BA0000]41- <1> 	mov	word [Attr_Chars+4], 'AL'
 19425 00006617 4C                  <1>
 19426 00006618 BE[1CBA0000]        <1> 	mov	esi, Attr_Chars
 19427 0000661D A0[FCCF0000]        <1> 	mov	al, [Attributes]
 19428 00006622 A804                <1> 	test	al, 04h
 19429 00006624 7406                <1> 	jz	short pass_put_attr_s
 19430 00006626 66C7065300          <1> 	mov	word [esi], 0053h     ; S
 19431 0000662B 46                  <1> 	inc	esi
 19432                              <1> 
 19433                              <1> pass_put_attr_s:
 19434 0000662C A802                <1> 	test	al, 02h
 19435 0000662E 7406                <1> 	jz	short pass_put_attr_h
 19436 00006630 66C7064800          <1> 	mov	word [esi], 0048h     ; H
 19437 00006635 46                  <1> 	inc	esi
 19438                              <1> 
 19439                              <1> pass_put_attr_h:
 19440 00006636 A801                <1> 	test	al, 01h
 19441 00006638 7406                <1> 	jz	short pass_put_attr_r
 19442 0000663A 66C7065200          <1> 	mov	word [esi], 0052h     ; R
 19443 0000663F 46                  <1> 	inc	esi
 19444                              <1> 
 19445                              <1> pass_put_attr_r:
 19446 00006640 3C20                <1> 	cmp	al, 20h
 19447 00006642 7205                <1> 	jb	short pass_put_attr_a
 19448 00006644 66C7064100          <1> 	mov	word [esi], 0041h     ; A
 19449                              <1> 
 19450                              <1> pass_put_attr_a:
 19451 00006649 BE[0FBA0000]        <1> 	mov	esi, Str_Attributes
 19452 0000664E E877D8FFFF          <1> 	call	print_msg
 19453 00006653 BE[56C10000]        <1> 	mov	esi, nextline
 19454 00006658 E86DD8FFFF          <1> 	call	print_msg
 19455 0000665D E924F9FFFF          <1> 	jmp	loc_file_rw_restore_retn 
 19456                              <1> 
 19457                              <1> loc_attr_file_check_fname_fchar:
 19458 00006662 46                  <1> 	inc	esi
 19459 00006663 803E20              <1> 	cmp	byte [esi], 20h
 19460 00006666 74FA                <1> 	je	short loc_attr_file_check_fname_fchar
 19461 00006668 0F8275FFFFFF        <1>         jb      pass_change_attr
 19462                              <1> 		   
 19463                              <1> loc_attr_file_parse_path_name:
 19464 0000666E BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 19465 00006673 E8C1130000          <1> 	call	parse_path_name
 19466 00006678 0F82E8EFFFFF        <1> 	jc	loc_cmd_failed
 19467                              <1> 
 19468                              <1> loc_attr_file_check_filename_exists:
 19469 0000667E BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19470 00006683 803E20              <1> 	cmp	byte [esi], 20h
 19471 00006686 0F86DAEFFFFF        <1> 	jna	loc_cmd_failed
 19472 0000668C 8935[A4CF0000]      <1> 	mov	[DelFile_FNPointer], esi 
 19473                              <1> 
 19474                              <1> loc_attr_file_drv:
 19475 00006692 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 19476 00006698 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 19477                              <1> 
 19478 0000669E 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 19479 000066A4 38F2                <1> 	cmp	dl, dh
 19480 000066A6 740B                <1> 	je	short loc_attr_file_change_directory
 19481                              <1> 
 19482 000066A8 E821E1FFFF          <1> 	call	change_current_drive
 19483 000066AD 0F82D3F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19484                              <1> 
 19485                              <1> loc_attr_file_change_directory:
 19486 000066B3 803D[E7CE0000]20    <1>         cmp     byte [FindFile_Directory], 20h
 19487 000066BA 7618                <1> 	jna	short loc_attr_file_find
 19488                              <1> 
 19489 000066BC FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 19490                              <1> 	
 19491 000066C2 BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 19492 000066C7 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19493 000066C9 E8570D0000          <1> 	call	change_current_directory
 19494 000066CE 0F82B2F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19495                              <1> 
 19496                              <1> ;loc_attr_file_change_prompt_dir_string:
 19497                              <1> 	;call	change_prompt_dir_string
 19498                              <1> 
 19499                              <1> loc_attr_file_find:
 19500                              <1> 	;mov	esi, FindFile_Name
 19501 000066D4 8B35[A4CF0000]      <1> 	mov	esi, [DelFile_FNPointer]
 19502 000066DA 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
 19503 000066DE E87FF4FFFF          <1> 	call	find_first_file
 19504 000066E3 0F829DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19505                              <1> 
 19506                              <1> loc_attr_file_ambgfn_check:
 19507 000066E9 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19508                              <1> 	;	(Note: It was BX in TRDOS v1)
 19509                              <1> 	;jz	short loc_attr_file_found
 19510 000066EC 0F85AAFDFFFF        <1>         jnz     loc_file_not_found ; 06/03/2016 
 19511                              <1> 
 19512                              <1> 	;mov	eax, 2 ; File not found sign
 19513                              <1> 	;stc
 19514                              <1> 	;jmp	loc_file_rw_cmd_failed   
 19515                              <1> 
 19516                              <1> loc_attr_file_found:
 19517                              <1> 	; EDI = Directory buffer entry offset/address
 19518                              <1> 	; BL = File (or Directory) Attributes 
 19519                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
 19520                              <1> 	; mov	bl, [EDI+0Bh]
 19521                              <1> 	
 19522 000066F2 66833D[1CBA0000]00  <1> 	cmp	word [Attr_Chars], 0
 19523 000066FA 770B                <1> 	ja	short loc_attr_file_change_attributes
 19524 000066FC 881D[FCCF0000]      <1> 	mov	[Attributes], bl
 19525 00006702 E9F4FEFFFF          <1> 	jmp	loc_show_attributes
 19526                              <1> 
 19527                              <1> loc_attr_file_change_attributes:
 19528 00006707 A0[1CBA0000]        <1> 	mov	al, [Attr_Chars]
 19529 0000670C F6D0                <1> 	not	al
 19530 0000670E 20C3                <1> 	and	bl, al
 19531 00006710 A0[1DBA0000]        <1> 	mov	al, [Attr_Chars+1]
 19532 00006715 08C3                <1> 	or	bl, al
 19533                              <1> 
 19534 00006717 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
 19535 0000671D 741D                <1> 	je	short loc_attr_file_fs_check
 19536                              <1> 
 19537 0000671F 881D[FCCF0000]      <1> 	mov	[Attributes], bl
 19538 00006725 885F0B              <1> 	mov	[edi+0Bh], bl    ; Attributes (New!)
 19539                              <1> 
 19540                              <1> 	; 04/03/2016
 19541                              <1> 	; TRDOS v1 has a bug here! it does not set
 19542                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
 19543                              <1> 	; 'save_directory_buffer' would not save the new attributes ! 
 19544                              <1> 	
 19545 00006728 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 19546                              <1> 
 19547 0000672F E869170000          <1> 	call 	save_directory_buffer
 19548 00006734 0F824CF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19549                              <1> 
 19550 0000673A EB33                <1> 	jmp	short loc_print_attr_changed_message
 19551                              <1> 
 19552                              <1> loc_attr_file_fs_check:
 19553 0000673C 29C0                <1> 	sub	eax, eax
 19554 0000673E 8A25[6ACD0000]      <1>         mov     ah, [DirBuff_DRV]
 19555 00006744 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 19556 00006749 01C6                <1>         add     esi, eax
 19557 0000674B 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
 19558 0000674F 7309                <1> 	jnc	short loc_attr_file_change_fs_file_attributes
 19559 00006751 66B80D00            <1> 	mov	ax, 0Dh ; Invalid Data
 19560 00006755 E92CF8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19561                              <1> 
 19562                              <1> loc_attr_file_change_fs_file_attributes:
 19563                              <1> 	; BL = New MS-DOS File Attributes
 19564 0000675A 88D8                <1> 	mov	al, bl ; File/Directory Attributes
 19565 0000675C 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign	  
 19566 0000675E E89C050000          <1> 	call	change_fs_file_attributes
 19567 00006763 0F821DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19568                              <1> 
 19569 00006769 881D[FCCF0000]      <1> 	mov	[Attributes], bl 
 19570                              <1> 
 19571                              <1> loc_print_attr_changed_message:
 19572 0000676F BE[0ABA0000]        <1> 	mov	esi, Msg_New
 19573 00006774 E851D7FFFF          <1> 	call	print_msg
 19574 00006779 E987FEFFFF          <1> 	jmp	loc_show_attributes_no_nextline
 19575                              <1> 
 19576                              <1> rename_file:
 19577                              <1> 	; 08/03/2016
 19578                              <1> 	; 06/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19579                              <1> 	; 20/11/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_rename')
 19580                              <1> 	; 16/11/2010 
 19581                              <1> 
 19582                              <1> get_rename_source_fchar:
 19583                              <1> 	; esi = file name
 19584 0000677E 803E20              <1> 	cmp	byte [esi], 20h
 19585 00006781 7614                <1>         jna	short loc_rename_nofilename_retn
 19586                              <1> 
 19587 00006783 8935[20D00000]      <1> 	mov	[SourceFilePath], esi
 19588                              <1> 
 19589                              <1> rename_scan_source_file:
 19590 00006789 46                  <1> 	inc	esi
 19591 0000678A 803E20              <1> 	cmp	byte [esi], 20h
 19592 0000678D 7409                <1> 	je	short rename_scan_destination_file_1
 19593                              <1> 	;jb	short loc_rename_nofilename_retn
 19594 0000678F 0F82D1EEFFFF        <1> 	jb	loc_cmd_failed
 19595 00006795 EBF2                <1> 	jmp	short rename_scan_source_file
 19596                              <1> 
 19597                              <1> loc_rename_nofilename_retn: ; 08/03/2016
 19598 00006797 C3                  <1> 	retn
 19599                              <1> 
 19600                              <1> rename_scan_destination_file_1:
 19601 00006798 C60600              <1> 	mov	byte [esi], 0
 19602                              <1> 
 19603                              <1> rename_scan_destination_file_2:
 19604 0000679B 46                  <1> 	inc	esi  
 19605 0000679C 803E20              <1> 	cmp	byte [esi], 20h
 19606 0000679F 74FA                <1> 	je	short rename_scan_destination_file_2
 19607                              <1> 	;jb	short loc_rename_nofilename_retn
 19608 000067A1 0F82BFEEFFFF        <1> 	jb	loc_cmd_failed
 19609                              <1> 
 19610 000067A7 8935[24D00000]      <1> 	mov	[DestinationFilePath], esi
 19611                              <1> 
 19612                              <1> rename_scan_destination_file_3:
 19613 000067AD 46                  <1> 	inc	esi  
 19614 000067AE 803E20              <1> 	cmp	byte [esi], 20h
 19615 000067B1 77FA                <1> 	ja	short rename_scan_destination_file_3
 19616                              <1> 
 19617 000067B3 C60600              <1> 	mov	byte [esi], 0
 19618                              <1> 
 19619                              <1> loc_rename_save_current_drive:
 19620 000067B6 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 19621 000067BC 8835[A2CD0000]      <1> 	mov	byte [RUN_CDRV], dh
 19622                              <1> 
 19623                              <1> loc_rename_sf_parse_path_name:
 19624 000067C2 8B35[20D00000]      <1> 	mov	esi, [SourceFilePath] 
 19625 000067C8 BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 19626 000067CD E867120000          <1> 	call	parse_path_name
 19627 000067D2 0F828EEEFFFF        <1> 	jc	loc_cmd_failed
 19628                              <1> 
 19629                              <1> loc_rename_sf_check_filename_exists:
 19630 000067D8 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19631 000067DD 803E20              <1> 	cmp	byte [esi], 20h
 19632 000067E0 0F8680EEFFFF        <1> 	jna	loc_cmd_failed
 19633                              <1> 
 19634                              <1> 	;mov	[DelFile_FNPointer], esi 
 19635                              <1> 
 19636                              <1> loc_rename_sf_drv:
 19637                              <1> 	;mov	dh, [Current_Drv]
 19638                              <1> 	;mov	[RUN_CDRV], dh
 19639                              <1> 
 19640 000067E6 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 19641 000067EC 38F2                <1> 	cmp	dl, dh ; dh = [Current_Drv]
 19642 000067EE 740B                <1> 	je	short rename_sf_change_directory
 19643                              <1> 
 19644 000067F0 E8D9DFFFFF          <1> 	call	change_current_drive
 19645 000067F5 0F828BF7FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19646                              <1> 
 19647                              <1> rename_sf_change_directory:
 19648 000067FB 803D[E7CE0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 19649 00006802 7618                <1> 	jna	short rename_sf_find
 19650                              <1> 
 19651 00006804 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 19652 0000680A BE[E7CE0000]        <1> 	mov	esi, FindFile_Directory
 19653 0000680F 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19654 00006811 E80F0C0000          <1> 	call	change_current_directory
 19655 00006816 0F826AF7FFFF        <1>  	jc	loc_file_rw_cmd_failed
 19656                              <1> 
 19657                              <1> ;rename_sf_change_prompt_dir_string:
 19658                              <1> 	;call	change_prompt_dir_string
 19659                              <1> 
 19660                              <1> rename_sf_find:
 19661                              <1> 	;mov	esi, [DelFile_FNPointer]
 19662 0000681C BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19663                              <1> 
 19664 00006821 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
 19665 00006825 E838F3FFFF          <1> 	call	find_first_file
 19666 0000682A 0F8256F7FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19667                              <1> 
 19668                              <1> loc_rename_sf_ambgfn_check:
 19669 00006830 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19670                              <1> 	;	(Note: It was BX in TRDOS v1)
 19671                              <1> 	;jz	short loc_rename_sf_found
 19672 00006833 0F8563FCFFFF        <1> 	jnz	loc_file_not_found
 19673                              <1> 
 19674                              <1> 	;mov	eax, 2 ; File not found sign
 19675                              <1> 	;stc
 19676                              <1> 	;jmp	loc_file_rw_cmd_failed   
 19677                              <1> 
 19678                              <1> loc_rename_sf_found:
 19679                              <1> 	; EDI = Directory buffer entry offset/address
 19680                              <1> 	; BL = File (or Directory) Attributes 
 19681                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
 19682                              <1> 	; mov	bl, [EDI+0Bh]
 19683                              <1> 
 19684 00006839 F6C307              <1> 	test	bl, 07h ; Attributes, S-H-R
 19685 0000683C 0F854EF7FFFF        <1> 	jnz	loc_permission_denied
 19686                              <1> 	
 19687 00006842 BE[E6CE0000]        <1>         mov     esi, FindFile_Drv
 19688 00006847 BF[28D00000]        <1>         mov     edi, SourceFile_Drv
 19689 0000684C B920000000          <1> 	mov	ecx, 32
 19690 00006851 F3A5                <1> 	rep	movsd
 19691                              <1> 
 19692                              <1> loc_rename_df_parse_path_name:
 19693 00006853 8B35[24D00000]      <1> 	mov	esi, [DestinationFilePath]
 19694 00006859 BF[E6CE0000]        <1> 	mov	edi, FindFile_Drv
 19695 0000685E E8D6110000          <1> 	call	parse_path_name
 19696 00006863 7219                <1> 	jc	short loc_rename_df_cmd_failed
 19697                              <1> 
 19698                              <1> 	;mov	dh, [RUN_CDRV]
 19699 00006865 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 19700                              <1> 
 19701                              <1> 	; 'rename' command is valid only for same dos drive and same dir!
 19702                              <1> 	; ('move' command must be used if source file and destination file
 19703                              <1> 	; directories are not same!) 
 19704 0000686B 8A15[E6CE0000]      <1> 	mov	dl, [FindFile_Drv]
 19705 00006871 38F2                <1> 	cmp	dl, dh ; are source and destination drives different ?!
 19706 00006873 7509                <1> 	jne	short loc_rename_df_cmd_failed ; yes! 
 19707                              <1> 
 19708                              <1> rename_df_check_dirname_exists:
 19709 00006875 803D[E7CE0000]00    <1> 	cmp	byte [FindFile_Directory], 0
 19710 0000687C 760B                <1> 	jna	short rename_df_check_filename_exists
 19711                              <1> 
 19712                              <1> 	; different source file and destination file directories !
 19713                              <1> loc_rename_df_cmd_failed:
 19714                              <1> loc_rename_df_found:
 19715 0000687E B801000000          <1> 	mov	eax, 1 ; TRDOS 'Bad command or file name' error
 19716 00006883 F9                  <1> 	stc
 19717 00006884 E9FDF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19718                              <1> 	  
 19719                              <1> rename_df_check_filename_exists:
 19720 00006889 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19721 0000688E E883F6FFFF          <1> 	call	check_filename
 19722 00006893 0F829FF7FFFF        <1> 	jc	loc_mkdir_invalid_dir_name_chars
 19723                              <1> 
 19724                              <1> 	;mov	[DelFile_FNPointer], esi 
 19725                              <1> 	;cmp	byte [esi], 20h
 19726                              <1> 	;ja	short loc_rename_df_find
 19727                              <1> 
 19728                              <1> 	;mov	dh, [Current_Drv] ; dh has not been changed
 19729                              <1> 
 19730                              <1> rename_df_drv_check_writable:
 19731 00006899 0FB6F6              <1> 	movzx	esi, dh
 19732                              <1> 	;movzx	esi, byte [Current_Drv]
 19733 0000689C 81C600010900        <1> 	add	esi, Logical_DOSDisks
 19734                              <1> 
 19735 000068A2 88F2                <1> 	mov	dl, dh ; dl = [Current_Drv]
 19736 000068A4 8A7601              <1> 	mov	dh, [esi+LD_DiskType]
 19737                              <1> 
 19738 000068A7 80FE01              <1> 	cmp	dh, 1 ; 0 = Invalid
 19739 000068AA 7310                <1> 	jnb	short rename_df_compare_sf_df_name
 19740                              <1> 
 19741 000068AC B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected
 19742 000068B1 8B1D[24D00000]      <1> 	mov	ebx, [DestinationFilePath] 
 19743 000068B7 E9CAF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19744                              <1> 
 19745                              <1> rename_df_compare_sf_df_name:
 19746 000068BC BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19747 000068C1 BF[6AD00000]        <1> 	mov	edi, SourceFile_Name
 19748 000068C6 B90C000000          <1> 	mov	ecx, 12
 19749                              <1> rename_df_compare_sf_df_name_next: 
 19750 000068CB AC                  <1> 	lodsb
 19751 000068CC AE                  <1> 	scasb
 19752 000068CD 7506                <1> 	jne	short loc_rename_df_find
 19753 000068CF 08C0                <1> 	or	al, al
 19754 000068D1 74AB                <1> 	jz	short loc_rename_df_cmd_failed
 19755 000068D3 E2F6                <1> 	loop	rename_df_compare_sf_df_name_next 
 19756                              <1> 
 19757                              <1> loc_rename_df_find:
 19758                              <1> 	;mov	esi, [DelFile_FNPointer]
 19759 000068D5 BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 19760                              <1> 
 19761 000068DA 6631C0              <1> 	xor	ax, ax ; Any
 19762 000068DD E880F2FFFF          <1> 	call	find_first_file
 19763 000068E2 739A                <1> 	jnc	short loc_rename_df_found
 19764                              <1> 
 19765                              <1> loc_rename_df_check_error_code:
 19766                              <1> 	;cmp	eax, 2
 19767 000068E4 3C02                <1> 	cmp	al, 2 ; Not found error
 19768 000068E6 7406                <1> 	je	short rename_df_move_find_struct_to_dest
 19769 000068E8 F9                  <1> 	stc
 19770 000068E9 E998F6FFFF          <1> 	jmp loc_file_rw_cmd_failed
 19771                              <1> 
 19772                              <1> ;loc_rename_df_found:
 19773                              <1> ;	mov	eax, 1 ;Bad command or file name error
 19774                              <1> ;	stc
 19775                              <1> ;	jmp	loc_file_rw_cmd_failed
 19776                              <1> 
 19777                              <1> rename_df_move_find_struct_to_dest:
 19778 000068EE BE[E6CE0000]        <1>         mov     esi, FindFile_Drv
 19779 000068F3 BF[A8D00000]        <1>         mov     edi, DestinationFile_Drv
 19780 000068F8 B920000000          <1> 	mov	ecx, 32
 19781 000068FD F3A5                <1> 	rep	movsd
 19782                              <1> 
 19783                              <1> loc_rename_df_process_q_sf:
 19784                              <1> 	;mov	ecx, 12
 19785 000068FF B10C                <1> 	mov	cl, 12
 19786 00006901 BE[6AD00000]        <1>  	mov	esi, SourceFile_Name
 19787 00006906 BF[4BBA0000]        <1> 	mov	edi, Rename_OldName
 19788                              <1> rename_df_process_q_nml_1_sf:
 19789 0000690B AC                  <1> 	lodsb
 19790 0000690C 3C20                <1>         cmp	al, 20h
 19791 0000690E 7603                <1>         jna	short rename_df_process_q_nml_2_sf
 19792 00006910 AA                  <1> 	stosb
 19793 00006911 E2F8                <1> 	loop	rename_df_process_q_nml_1_sf
 19794                              <1> 
 19795                              <1> rename_df_process_q_nml_2_sf:
 19796 00006913 C60700              <1> 	mov	byte [edi], 0
 19797                              <1> 
 19798                              <1> loc_rename_df_process_q_df:
 19799                              <1> 	;mov	ecx, 12
 19800 00006916 B10C                <1> 	mov	cl, 12
 19801 00006918 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 19802 0000691D BF[5CBA0000]        <1> 	mov	edi, Rename_NewName
 19803                              <1> rename_df_process_q_nml_1_df:
 19804 00006922 AC                  <1> 	lodsb
 19805 00006923 3C20                <1> 	cmp	al, 20h
 19806 00006925 7603                <1> 	jna	short loc_rename_df_process_q_nml_2_df
 19807 00006927 AA                  <1> 	stosb
 19808 00006928 E2F8                <1> 	loop	rename_df_process_q_nml_1_df
 19809                              <1> 
 19810                              <1> loc_rename_df_process_q_nml_2_df:
 19811 0000692A C60700              <1> 	mov	byte [edi], 0
 19812                              <1> 
 19813                              <1> loc_rename_confirmation_question:
 19814 0000692D BE[23BA0000]        <1> 	mov	esi, Msg_DoYouWantRename
 19815 00006932 E893D5FFFF          <1> 	call	print_msg
 19816                              <1> 
 19817 00006937 A0[85D00000]        <1> 	mov	al, [SourceFile_DirEntry+11] ; Attributes
 19818 0000693C 2410                <1> 	and	al, 10h
 19819 0000693E 750C                <1> 	jnz	short rename_confirmation_question_dir
 19820                              <1> 
 19821                              <1> rename_confirmation_question_file:
 19822 00006940 BE[3ABA0000]        <1> 	mov	esi, Rename_File
 19823 00006945 E880D5FFFF          <1> 	call	print_msg 
 19824 0000694A EB0A                <1> 	jmp	short rename_confirmation_question_as 
 19825                              <1> 
 19826                              <1> rename_confirmation_question_dir:
 19827 0000694C BE[40BA0000]        <1> 	mov	esi, Rename_Directory
 19828 00006951 E874D5FFFF          <1> 	call	print_msg
 19829                              <1> 
 19830                              <1> rename_confirmation_question_as:
 19831 00006956 BE[4BBA0000]        <1> 	mov	esi, Rename_OldName
 19832 0000695B E86AD5FFFF          <1> 	call	print_msg
 19833 00006960 BE[58BA0000]        <1> 	mov	esi, Msg_File_rename_as
 19834 00006965 E860D5FFFF          <1> 	call	print_msg
 19835 0000696A BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 19836 0000696F E856D5FFFF          <1> 	call	print_msg
 19837                              <1> 
 19838                              <1> loc_rename_ask_again:
 19839 00006974 30E4                <1> 	xor	ah, ah
 19840 00006976 E86CA2FFFF          <1> 	call	int16h
 19841 0000697B 3C1B                <1> 	cmp	al, 1Bh
 19842 0000697D 740F                <1> 	je	short loc_do_not_rename_file
 19843 0000697F 24DF                <1> 	and	al, 0DFh
 19844 00006981 A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 19845 00006986 3C59                <1> 	cmp	al, 'Y'
 19846 00006988 7404                <1> 	je	short loc_yes_rename_file
 19847 0000698A 3C4E                <1> 	cmp	al, 'N'
 19848 0000698C 75E6                <1> 	jne	short loc_rename_ask_again
 19849                              <1> 
 19850                              <1> loc_do_not_rename_file:
 19851                              <1> loc_yes_rename_file:
 19852 0000698E A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 19853 00006993 6650                <1> 	push	ax
 19854 00006995 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 19855 0000699A E82BD5FFFF          <1> 	call	print_msg
 19856 0000699F 6658                <1> 	pop	ax
 19857                              <1> 	;cmp	al, 'Y' ; 'yes'
 19858                              <1> 	;cmc
 19859                              <1>         ;jnc	loc_file_rw_restore_retn
 19860 000069A1 3C4E                <1> 	cmp	al, 'N' ; 'no'
 19861 000069A3 0F84DDF5FFFF        <1>         je	loc_file_rw_restore_retn  
 19862                              <1> 
 19863 000069A9 BE[5CBA0000]        <1> 	mov	esi, Rename_NewName
 19864 000069AE 668B0D[A2D00000]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
 19865 000069B5 66A1[8ED00000]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
 19866 000069BB 66C1E010            <1> 	shl	ax, 16
 19867 000069BF 66A1[94D00000]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
 19868                              <1> 
 19869 000069C5 0FB61D[77D00000]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]  
 19870 000069CC E8B2180000          <1>    	call	rename_directory_entry
 19871 000069D1 E9DEF6FFFF          <1> 	jmp	loc_rename_file_ok	
 19872                              <1> ;loc_rename_file_ok:
 19873                              <1> ;	jc	loc_run_cmd_failed
 19874                              <1> ;	mov	esi, Msg_OK
 19875                              <1> ;	call	proc_printmsg
 19876                              <1> ;	jmp	loc_file_rw_restore_retn
 19877                              <1> 
 19878                              <1> move_file:
 19879                              <1> 	; 11/03/2016
 19880                              <1> 	; 09/03/2016
 19881                              <1> 	; 08/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19882                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_move')
 19883                              <1> 	; 23/04/2011
 19884                              <1> 
 19885                              <1> get_move_source_fchar:
 19886                              <1> 	; esi = file name
 19887 000069D6 803E20              <1> 	cmp	byte [esi], 20h
 19888 000069D9 7614                <1>         jna	short loc_move_nofilename_retn
 19889                              <1> 
 19890 000069DB 8935[20D00000]      <1> 	mov	[SourceFilePath], esi
 19891                              <1> 
 19892                              <1> move_scan_source_file:
 19893 000069E1 46                  <1> 	inc	esi
 19894 000069E2 803E20              <1> 	cmp	byte [esi], 20h
 19895 000069E5 7409                <1>         je      short move_scan_destination_1
 19896                              <1> 	;jb	short loc_move_nofilename_retn
 19897 000069E7 0F8279ECFFFF        <1> 	jb	loc_cmd_failed
 19898 000069ED EBF2                <1> 	jmp	short move_scan_source_file
 19899                              <1> 
 19900                              <1> loc_move_nofilename_retn:
 19901 000069EF C3                  <1> 	retn
 19902                              <1> 
 19903                              <1> move_scan_destination_1:
 19904 000069F0 C60600              <1> 	mov	byte [esi], 0
 19905                              <1> 
 19906                              <1> move_scan_destination_2:
 19907 000069F3 46                  <1> 	inc	esi  
 19908 000069F4 803E20              <1> 	cmp	byte [esi], 20h
 19909 000069F7 74FA                <1> 	je	short move_scan_destination_2
 19910                              <1> 	;jb	short loc_move_nofilename_retn
 19911 000069F9 0F8267ECFFFF        <1> 	jb	loc_cmd_failed
 19912                              <1> 
 19913 000069FF 8935[24D00000]      <1> 	mov	[DestinationFilePath], esi
 19914                              <1> 
 19915                              <1> move_scan_destination_3:
 19916 00006A05 46                  <1> 	inc	esi  
 19917 00006A06 803E20              <1> 	cmp	byte [esi], 20h
 19918 00006A09 77FA                <1> 	ja	short move_scan_destination_3
 19919 00006A0B C60600              <1> 	mov	byte [esi], 0
 19920                              <1> 
 19921                              <1> loc_move_scan_destination_OK:
 19922 00006A0E 8B35[20D00000]      <1> 	mov	esi, [SourceFilePath]
 19923 00006A14 8B3D[24D00000]      <1> 	mov	edi, [DestinationFilePath]
 19924                              <1> 
 19925 00006A1A B001                <1> 	mov	al, 1  ; move procedure Phase 1
 19926 00006A1C E8DF180000          <1> 	call	move_source_file_to_destination_file
 19927 00006A21 7328                <1> 	jnc	short move_source_file_to_destination_question
 19928                              <1> 
 19929                              <1> loc_move_cmd_failed_1:
 19930 00006A23 08C0                <1> 	or	al, al
 19931 00006A25 0F843BECFFFF        <1> 	jz	loc_cmd_failed 
 19932 00006A2B 3C11                <1> 	cmp	al, 11h
 19933 00006A2D 740D                <1> 	je	short loc_msg_not_same_device   
 19934 00006A2F 3C05                <1> 	cmp	al, 05h
 19935 00006A31 0F855AECFFFF        <1> 	jne	loc_run_cmd_failed
 19936                              <1> 
 19937 00006A37 E954F5FFFF          <1> 	jmp	loc_permission_denied
 19938                              <1> 
 19939                              <1> 	;mov	esi, Msg_Permission_denied
 19940                              <1> 	;call	print_msg
 19941                              <1> 	;jmp	loc_file_rw_restore_retn
 19942                              <1> 
 19943                              <1> loc_msg_not_same_device:
 19944 00006A3C BE[69BA0000]        <1> 	mov	esi, msg_not_same_drv 
 19945 00006A41 E884D4FFFF          <1> 	call	print_msg
 19946 00006A46 E93BF5FFFF          <1> 	jmp	loc_file_rw_restore_retn
 19947                              <1> 
 19948                              <1> move_source_file_to_destination_question:
 19949 00006A4B A0[28D00000]        <1>         mov     al, [SourceFile_Drv]
 19950 00006A50 0441                <1> 	add	al, 'A'
 19951 00006A52 A2[CBBA0000]        <1> 	mov	[msg_source_file_drv], al
 19952 00006A57 A0[A8D00000]        <1>         mov     al, [DestinationFile_Drv]
 19953 00006A5C 0441                <1> 	add	al, 'A'
 19954 00006A5E A2[EABA0000]        <1> 	mov	[msg_destination_file_drv], al
 19955                              <1> 
 19956 00006A63 57                  <1> 	push	edi ; *
 19957                              <1> 
 19958 00006A64 BE[AFBA0000]        <1> 	mov	esi, msg_source_file
 19959 00006A69 E85CD4FFFF          <1> 	call	print_msg
 19960 00006A6E BE[29D00000]        <1> 	mov	esi, SourceFile_Directory
 19961 00006A73 803E20              <1> 	cmp	byte [esi], 20h
 19962 00006A76 7605                <1> 	jna	short msftdfq_sfn
 19963 00006A78 E84DD4FFFF          <1> 	call	print_msg
 19964                              <1> msftdfq_sfn:
 19965 00006A7D BE[6AD00000]        <1> 	mov	esi, SourceFile_Name
 19966 00006A82 E843D4FFFF          <1> 	call	print_msg
 19967 00006A87 BE[CEBA0000]        <1> 	mov	esi, msg_destination_file
 19968 00006A8C E839D4FFFF          <1> 	call	print_msg
 19969 00006A91 BE[A9D00000]        <1> 	mov	esi, DestinationFile_Directory
 19970 00006A96 803E20              <1> 	cmp	byte [esi], 20h
 19971 00006A99 7605                <1> 	jna	short msftdfq_dfn
 19972 00006A9B E82AD4FFFF          <1> 	call	print_msg
 19973                              <1> msftdfq_dfn:
 19974 00006AA0 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 19975 00006AA5 E820D4FFFF          <1> 	call	print_msg
 19976 00006AAA BE[EDBA0000]        <1> 	mov	esi, msg_copy_nextline
 19977 00006AAF E816D4FFFF          <1> 	call	print_msg
 19978 00006AB4 BE[EDBA0000]        <1> 	mov	esi, msg_copy_nextline
 19979 00006AB9 E80CD4FFFF          <1> 	call	print_msg
 19980                              <1> 
 19981                              <1> loc_move_ask_for_new_file_yes_no:
 19982 00006ABE BE[7BBA0000]        <1> 	mov	esi, Msg_DoYouWantMoveFile
 19983 00006AC3 E802D4FFFF          <1> 	call	print_msg
 19984 00006AC8 BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 19985 00006ACD E8F8D3FFFF          <1> 	call	print_msg
 19986                              <1> loc_move_ask_for_new_file_again:
 19987 00006AD2 30E4                <1> 	xor	ah, ah
 19988 00006AD4 E80EA1FFFF          <1> 	call	int16h
 19989 00006AD9 3C1B                <1> 	cmp	al, 1Bh
 19990                              <1> 	;je	short loc_do_not_move_file
 19991 00006ADB 744F                <1> 	je	short loc_move_y_n_escape
 19992 00006ADD 24DF                <1> 	and	al, 0DFh
 19993 00006ADF A2[89B90000]        <1>         mov     [Y_N_nextline], al
 19994 00006AE4 3C59                <1> 	cmp	al, 'Y'
 19995 00006AE6 7404                <1> 	je	short loc_yes_move_file
 19996 00006AE8 3C4E                <1> 	cmp	al, 'N'
 19997 00006AEA 75E6                <1> 	jne	short loc_move_ask_for_new_file_again
 19998                              <1> 
 19999                              <1> loc_do_not_move_file:
 20000                              <1> loc_yes_move_file:
 20001 00006AEC A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 20002 00006AF1 6650                <1> 	push	ax
 20003 00006AF3 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 20004 00006AF8 E8CDD3FFFF          <1> 	call	print_msg
 20005 00006AFD 6658                <1> 	pop	ax
 20006 00006AFF 5F                  <1> 	pop	edi ; *
 20007                              <1> 	;cmp	al, 'Y' ; 'yes'
 20008                              <1> 	;cmc
 20009                              <1>         ;jnc	loc_file_rw_restore_retn
 20010 00006B00 3C4E                <1> 	cmp	al, 'N' ; 'no'
 20011 00006B02 0F847EF4FFFF        <1>         je	loc_file_rw_restore_retn
 20012                              <1> 
 20013                              <1> loc_move_yes_move_file:
 20014 00006B08 B002                <1> 	mov	al, 2 ; move procedure Phase 2
 20015 00006B0A E8F1170000          <1> 	call	move_source_file_to_destination_file
 20016                              <1> 	;jc	short loc_move_cmd_failed_2
 20017 00006B0F 0F83A5F5FFFF        <1>         jnc     move_source_file_to_destination_OK
 20018                              <1> 
 20019                              <1> ;move_source_file_to_destination_OK:
 20020                              <1> ;	mov	esi, Msg_OK
 20021                              <1> ;	call	print_msg
 20022                              <1> ;	jmp	loc_file_rw_restore_retn
 20023                              <1> 
 20024                              <1> loc_move_cmd_failed_2:
 20025 00006B15 3C27                <1> 	cmp	al, 27h
 20026 00006B17 0F8574EBFFFF        <1> 	jne	loc_run_cmd_failed
 20027                              <1> 
 20028 00006B1D BE[94BA0000]        <1> 	mov	esi, msg_insufficient_disk_space
 20029 00006B22 E8A3D3FFFF          <1> 	call	print_msg
 20030                              <1> 
 20031 00006B27 E95AF4FFFF          <1> 	jmp	loc_file_rw_restore_retn
 20032                              <1> 
 20033                              <1> loc_move_y_n_escape:
 20034 00006B2C B04E                <1> 	mov	al, 'N' ; 'no'
 20035 00006B2E EBBC                <1> 	jmp	short loc_do_not_move_file
 20036                              <1> 
 20037                              <1> copy_file:
 20038                              <1> 	; 24/03/2016
 20039                              <1> 	; 21/03/2016
 20040                              <1> 	; 15/03/2016 (TRDOS 386 =  TRDOS v2.0)
 20041                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_copy')
 20042                              <1> 	; 01/08/2010
 20043                              <1> 
 20044                              <1> get_copy_source_fchar:
 20045                              <1> 	; esi = file name
 20046 00006B30 803E20              <1> 	cmp	byte [esi], 20h
 20047 00006B33 7614                <1>         jna     short loc_copy_nofilename_retn
 20048                              <1> 
 20049 00006B35 8935[20D00000]      <1> 	mov	[SourceFilePath], esi
 20050                              <1> 
 20051                              <1> copy_scan_source_file:
 20052 00006B3B 46                  <1> 	inc	esi  
 20053 00006B3C 803E20              <1> 	cmp	byte [esi], 20h
 20054 00006B3F 7409                <1> 	je	short copy_scan_destination_1
 20055                              <1> 	;jb	short loc_copy_nofilename_retn
 20056 00006B41 0F821FEBFFFF        <1> 	jb	loc_cmd_failed
 20057 00006B47 EBF2                <1> 	jmp	short copy_scan_source_file
 20058                              <1> 
 20059                              <1> loc_copy_nofilename_retn:
 20060 00006B49 C3                  <1> 	retn
 20061                              <1> 
 20062                              <1> copy_scan_destination_1:
 20063 00006B4A C60600              <1> 	mov	byte [esi], 0
 20064                              <1> 
 20065                              <1> copy_scan_destination_2:
 20066 00006B4D 46                  <1> 	inc	esi  
 20067 00006B4E 803E20              <1> 	cmp	byte [esi], 20h
 20068 00006B51 74FA                <1> 	je	short copy_scan_destination_2
 20069                              <1> 	;jb	short loc_copy_nofilename_retn
 20070 00006B53 0F820DEBFFFF        <1> 	jb	loc_cmd_failed
 20071                              <1> 
 20072 00006B59 8935[24D00000]      <1> 	mov	[DestinationFilePath], esi
 20073                              <1> 
 20074                              <1> copy_scan_destination_3:
 20075 00006B5F 46                  <1> 	inc	esi  
 20076 00006B60 803E20              <1> 	cmp	byte [esi], 20h
 20077 00006B63 77FA                <1> 	ja	short copy_scan_destination_3
 20078 00006B65 C60600              <1> 	mov	byte [esi], 0
 20079                              <1> 
 20080                              <1> loc_copy_save_current_drive:
 20081 00006B68 8A35[42C50000]      <1> 	mov	dh, [Current_Drv]
 20082 00006B6E 8835[A2CD0000]      <1> 	mov	[RUN_CDRV], dh
 20083                              <1> 
 20084                              <1> copy_source_file_to_destination_phase_1:
 20085 00006B74 8B35[20D00000]      <1> 	mov	esi, [SourceFilePath]
 20086 00006B7A 8B3D[24D00000]      <1> 	mov	edi, [DestinationFilePath]
 20087                              <1> 
 20088 00006B80 B001                <1> 	mov	al, 1  ; copy procedure Phase 1
 20089 00006B82 E8041A0000          <1> 	call	copy_source_file_to_destination_file
 20090 00006B87 732B                <1> 	jnc	short copy_source_file_to_destination_question
 20091                              <1> 
 20092                              <1> loc_copy_cmd_failed_1:
 20093                              <1> 	; 18/03/2016 (restore current drive and directory)
 20094 00006B89 08C0                <1> 	or	al, al
 20095 00006B8B 7507                <1> 	jnz	short loc_copy_cmd_failed_2
 20096                              <1> 
 20097 00006B8D FEC0                <1>         inc     al ; mov al, 1 ; Bad command or file name !
 20098 00006B8F E9FDEAFFFF          <1> 	jmp	loc_run_cmd_failed
 20099                              <1> 
 20100                              <1> loc_copy_cmd_failed_2:
 20101 00006B94 3C27                <1> 	cmp	al, 27h ; Insufficient disk space 
 20102 00006B96 740D                <1> 	je	short loc_file_write_insuff_disk_space_msg
 20103                              <1>  
 20104 00006B98 3C05                <1> 	cmp	al, 05h
 20105 00006B9A 0F85F1EAFFFF        <1> 	jne	loc_run_cmd_failed
 20106                              <1> 	
 20107 00006BA0 E9EBF3FFFF          <1> 	jmp	loc_permission_denied
 20108                              <1> 
 20109                              <1> loc_file_write_insuff_disk_space_msg:
 20110 00006BA5 BE[94BA0000]        <1> 	mov	esi, msg_insufficient_disk_space
 20111 00006BAA E81BD3FFFF          <1> 	call	print_msg
 20112 00006BAF E9D2F3FFFF          <1>         jmp     loc_file_rw_restore_retn 
 20113                              <1> 
 20114                              <1> copy_source_file_to_destination_question:
 20115 00006BB4 57                  <1> 	push	edi ; *
 20116                              <1> 
 20117                              <1> 	; dh = source file attributes
 20118                              <1> 	; dl > 0 -> destination file found
 20119 00006BB5 20D2                <1> 	and	dl, dl            
 20120 00006BB7 7449                <1> 	jz	short copy_source_file_to_destination_pass_owrq
 20121                              <1> 
 20122                              <1> loc_copy_ask_for_owr_yes_no:
 20123 00006BB9 BE[F0BA0000]        <1> 	mov	esi, Msg_DoYouWantOverWriteFile
 20124 00006BBE E807D3FFFF          <1> 	call	print_msg
 20125 00006BC3 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 20126 00006BC8 E8FDD2FFFF          <1> 	call	print_msg
 20127 00006BCD BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 20128 00006BD2 E8F3D2FFFF          <1> 	call	print_msg
 20129                              <1> 
 20130                              <1> loc_copy_ask_for_owr_again:
 20131 00006BD7 30E4                <1> 	xor	ah, ah
 20132 00006BD9 E809A0FFFF          <1> 	call	int16h
 20133 00006BDE 3C1B                <1> 	cmp	al, 1Bh
 20134                              <1>         ;je     loc_do_not_copy_file
 20135 00006BE0 7419                <1>         je      short loc_copy_y_n_escape
 20136 00006BE2 24DF                <1> 	and	al, 0DFh
 20137 00006BE4 A2[89B90000]        <1>         mov     [Y_N_nextline], al
 20138 00006BE9 3C59                <1> 	cmp	al, 'Y'
 20139 00006BEB 0F84B1000000        <1>         je      loc_yes_copy_file
 20140 00006BF1 3C4E                <1> 	cmp	al, 'N'
 20141 00006BF3 0F84A9000000        <1>         je      loc_do_not_copy_file
 20142 00006BF9 EBDC                <1> 	jmp	short loc_copy_ask_for_owr_again
 20143                              <1> 
 20144                              <1> loc_copy_y_n_escape:
 20145 00006BFB B04E                <1> 	mov	al, 'N' ; 'no'
 20146 00006BFD E9A0000000          <1>         jmp     loc_do_not_copy_file
 20147                              <1> 
 20148                              <1> copy_source_file_to_destination_pass_owrq:
 20149 00006C02 A0[28D00000]        <1> 	mov     al, [SourceFile_Drv]
 20150 00006C07 0441                <1> 	add	al, 'A'
 20151 00006C09 A2[CBBA0000]        <1> 	mov	[msg_source_file_drv], al
 20152 00006C0E A0[A8D00000]        <1>         mov     al, [DestinationFile_Drv]
 20153 00006C13 0441                <1> 	add	al, 'A'
 20154 00006C15 A2[EABA0000]        <1> 	mov	[msg_destination_file_drv], al
 20155                              <1> 
 20156 00006C1A BE[AFBA0000]        <1> 	mov	esi, msg_source_file
 20157 00006C1F E8A6D2FFFF          <1> 	call	print_msg
 20158 00006C24 BE[29D00000]        <1> 	mov	esi, SourceFile_Directory
 20159 00006C29 803E20              <1> 	cmp	byte [esi], 20h
 20160 00006C2C 7605                <1> 	jna	short csftdfq_sfn
 20161 00006C2E E897D2FFFF          <1> 	call	print_msg
 20162                              <1> csftdfq_sfn:
 20163 00006C33 BE[6AD00000]        <1> 	mov	esi, SourceFile_Name
 20164 00006C38 E88DD2FFFF          <1> 	call	print_msg
 20165 00006C3D BE[CEBA0000]        <1> 	mov	esi, msg_destination_file
 20166 00006C42 E883D2FFFF          <1> 	call	print_msg
 20167 00006C47 BE[A9D00000]        <1> 	mov	esi, DestinationFile_Directory
 20168 00006C4C 803E20              <1> 	cmp	byte [esi], 20h
 20169 00006C4F 7605                <1> 	jna	short csftdfq_dfn
 20170 00006C51 E874D2FFFF          <1> 	call	print_msg
 20171                              <1> csftdfq_dfn:
 20172 00006C56 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 20173 00006C5B E86AD2FFFF          <1> 	call	print_msg
 20174 00006C60 BE[EDBA0000]        <1> 	mov	esi, msg_copy_nextline
 20175 00006C65 E860D2FFFF          <1> 	call	print_msg
 20176 00006C6A BE[EDBA0000]        <1> 	mov	esi, msg_copy_nextline
 20177 00006C6F E856D2FFFF          <1> 	call	print_msg
 20178                              <1> 
 20179                              <1> loc_copy_ask_for_new_file_yes_no:
 20180 00006C74 BE[0FBB0000]        <1> 	mov	esi, Msg_DoYouWantCopyFile
 20181 00006C79 E84CD2FFFF          <1> 	call	print_msg
 20182 00006C7E BE[7FB90000]        <1> 	mov	esi, Msg_YesNo
 20183 00006C83 E842D2FFFF          <1> 	call	print_msg
 20184                              <1> 
 20185                              <1> loc_copy_ask_for_new_file_again:
 20186 00006C88 30E4                <1> 	xor	ah, ah
 20187 00006C8A E8589FFFFF          <1> 	call	int16h
 20188 00006C8F 3C1B                <1> 	cmp	al, 1Bh
 20189 00006C91 740F                <1> 	je	short loc_do_not_copy_file
 20190 00006C93 24DF                <1> 	and	al, 0DFh
 20191 00006C95 A2[89B90000]        <1>         mov     [Y_N_nextline], al
 20192 00006C9A 3C59                <1> 	cmp	al, 'Y'
 20193 00006C9C 7404                <1> 	je	short loc_yes_copy_file
 20194 00006C9E 3C4E                <1> 	cmp	al, 'N'
 20195 00006CA0 75E6                <1> 	jne	short loc_copy_ask_for_new_file_again
 20196                              <1> 
 20197                              <1> loc_do_not_copy_file:
 20198                              <1> loc_yes_copy_file:
 20199 00006CA2 A2[89B90000]        <1> 	mov	[Y_N_nextline], al
 20200 00006CA7 6650                <1> 	push	ax
 20201 00006CA9 BE[89B90000]        <1> 	mov	esi, Y_N_nextline
 20202 00006CAE E817D2FFFF          <1> 	call	print_msg
 20203 00006CB3 6658                <1> 	pop	ax
 20204 00006CB5 5F                  <1> 	pop	edi ; *
 20205                              <1> 	;cmp	al, 'Y' ; 'yes'
 20206                              <1> 	;cmc
 20207                              <1>         ;jnc	loc_file_rw_restore_retn
 20208 00006CB6 3C4E                <1> 	cmp	al, 'N' ; 'no'
 20209 00006CB8 0F84C8F2FFFF        <1>         je	loc_file_rw_restore_retn
 20210                              <1> 
 20211                              <1> copy_source_file_to_destination_pass_q:
 20212 00006CBE B002                <1> 	mov	al, 2  ; copy procedure Phase 2
 20213 00006CC0 E8C6180000          <1> 	call	copy_source_file_to_destination_file
 20214                              <1> 	;jc	short loc_file_write_check_disk_space_err
 20215                              <1> 
 20216                              <1> 	; 24/03/2016
 20217 00006CC5 6651                <1> 	push	cx
 20218 00006CC7 BE[EDBA0000]        <1> 	mov	esi, msg_copy_nextline
 20219 00006CCC E8F9D1FFFF          <1> 	call	print_msg
 20220                              <1> 	;pop	cx
 20221 00006CD1 6658                <1> 	pop	ax
 20222                              <1> 
 20223                              <1> 	;or	cl, cl
 20224 00006CD3 08C0                <1> 	or	al, al
 20225 00006CD5 7419                <1> 	jz	short copy_source_file_to_destination_OK
 20226                              <1> 	
 20227                              <1> 	; 18/03/2016
 20228                              <1> 	;cmp	cl, 1Dh ; write error
 20229 00006CD7 3C1D                <1> 	cmp	al, 1Dh
 20230 00006CD9 7506                <1> 	jne	short copy_source_file_to_destination_not_OK
 20231                              <1> 	;
 20232                              <1> 	;mov	al, cl ; error number (write fault!)
 20233 00006CDB F9                  <1> 	stc
 20234 00006CDC E9A5F2FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 20235                              <1> 
 20236                              <1> copy_source_file_to_destination_not_OK:
 20237 00006CE1 BE[28BB0000]        <1> 	mov	esi, Msg_read_file_error_before_EOF
 20238 00006CE6 E8DFD1FFFF          <1> 	call	print_msg
 20239 00006CEB E996F2FFFF          <1> 	jmp	loc_file_rw_restore_retn	      
 20240                              <1>  
 20241                              <1> copy_source_file_to_destination_OK:
 20242 00006CF0 BE[8DB90000]        <1> 	mov	esi, Msg_OK
 20243 00006CF5 E8D0D1FFFF          <1> 	call	print_msg
 20244                              <1> 
 20245 00006CFA E987F2FFFF          <1> 	jmp	loc_file_rw_restore_retn
 20246                              <1> 
 20247                              <1> ;loc_file_write_check_disk_space_err:
 20248                              <1> 	;cmp	al, 27h ; Insufficient disk space 
 20249                              <1> 	;je	loc_file_write_insuff_disk_space_msg
 20250                              <1>         ;jb	loc_file_rw_cmd_failed
 20251                              <1> 
 20252                              <1> 	;call	print_misc_error_msg ; 15/03/2016
 20253                              <1>         ;jmp	loc_file_rw_restore_retn 
 20254                              <1> 
 20255                              <1> change_fs_file_attributes:
 20256                              <1> 	; 04/03/2016 ; Temporary
 20257                              <1> 	; AL = File or directory attributes
 20258                              <1> 	; AH = 0 -> Attributes are in MS-DOS format
 20259                              <1> 	; AH > 0 -> Attributes are in SINGLIX format
 20260                              <1> 	;push	ebx
 20261                              <1> 	; ... do somethings here ...
 20262                              <1> 	;pop	ebx
 20263                              <1> 	; BL = File or directory attributes
 20264 00006CFF C3                  <1> 	retn
 20265                              <1> 
 20266                              <1> set_get_env:
 20267                              <1> 	; 11/04/2016 (TRDOS 386 =  TRDOS v2.0)
 20268                              <1> 	; 02/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_set')
 20269                              <1> 	; 2005 - 28/08/2011 
 20270                              <1> get_setenv_fchar:
 20271                              <1> 	; esi = environment variable/string
 20272 00006D00 8A06                <1> 	mov	al, [esi]
 20273 00006D02 3C20                <1> 	cmp	al, 20h
 20274 00006D04 771E                <1> 	ja	short loc_find_env
 20275                              <1> 
 20276 00006D06 BE00300900          <1> 	mov	esi, Env_Page
 20277                              <1> loc_print_setline:
 20278 00006D0B 803E00              <1> 	cmp	byte [esi], 0
 20279 00006D0E 7613                <1> 	jna	short loc_setenv_retn
 20280 00006D10 E8B5D1FFFF          <1> 	call	print_msg
 20281 00006D15 56                  <1> 	push	esi
 20282 00006D16 BE[56C10000]        <1> 	mov	esi, nextline
 20283 00006D1B E8AAD1FFFF          <1> 	call	print_msg 
 20284 00006D20 5E                  <1> 	pop	esi
 20285 00006D21 EBE8                <1> 	jmp	short loc_print_setline   
 20286                              <1> 
 20287                              <1> loc_setenv_retn: 
 20288 00006D23 C3                  <1> 	retn
 20289                              <1> 
 20290                              <1> loc_find_env:
 20291 00006D24 3C3D                <1> 	cmp	al, '='
 20292 00006D26 0F843AE9FFFF        <1> 	je	loc_cmd_failed
 20293                              <1> 
 20294 00006D2C 56                  <1> 	push	esi
 20295                              <1> loc_repeat_env_equal_check:
 20296 00006D2D 46                  <1> 	inc	esi
 20297 00006D2E 803E3D              <1> 	cmp	byte [esi], '='
 20298 00006D31 7431                <1> 	je	short pass_env_equal_check
 20299 00006D33 803E20              <1> 	cmp	byte [esi], 20h
 20300 00006D36 73F5                <1> 	jnb	short loc_repeat_env_equal_check
 20301 00006D38 C60600              <1> 	mov	byte [esi], 0 
 20302 00006D3B 5E                  <1> 	pop	esi
 20303 00006D3C BF[42C60000]        <1> 	mov	edi, TextBuffer ; out buffer
 20304 00006D41 B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
 20305 00006D46 30C0                <1> 	xor	al, al ; 0 -> use [ESI]
 20306 00006D48 E89E000000          <1> 	call	get_environment_string
 20307 00006D4D 72D4                <1> 	jc	short loc_setenv_retn
 20308                              <1> 
 20309 00006D4F BE[42C60000]        <1> 	mov	esi, TextBuffer
 20310 00006D54 E871D1FFFF          <1> 	call	print_msg
 20311 00006D59 BE[56C10000]        <1> 	mov	esi, nextline
 20312 00006D5E E867D1FFFF          <1> 	call	print_msg
 20313                              <1> 
 20314 00006D63 C3                  <1> 	retn 
 20315                              <1>               
 20316                              <1> pass_env_equal_check:
 20317 00006D64 46                  <1> 	inc	esi
 20318 00006D65 803E20              <1> 	cmp	byte [esi], 20h
 20319 00006D68 73FA                <1> 	jnb	short pass_env_equal_check
 20320 00006D6A C60600              <1> 	mov	byte [esi], 0	
 20321                              <1> 
 20322                              <1> loc_call_set_env_string:
 20323 00006D6D 5E                  <1> 	pop	esi
 20324 00006D6E E83B010000          <1> 	call	set_environment_string
 20325 00006D73 73AE                <1> 	jnc	short loc_setenv_retn
 20326                              <1> 
 20327                              <1> loc_set_cmd_failed:
 20328 00006D75 3C08                <1> 	cmp	al, 08h
 20329 00006D77 0F85E9E8FFFF        <1> 	jne	loc_cmd_failed
 20330                              <1> 
 20331 00006D7D BE[68BB0000]        <1> 	mov	esi, Msg_No_Set_Space
 20332 00006D82 E843D1FFFF          <1> 	call	print_msg
 20333                              <1> 
 20334 00006D87 C3                  <1> 	retn
 20335                              <1> 
 20336                              <1> set_get_path:
 20337                              <1> 	; 11/04/2016 (TRDOS 386 =  TRDOS v2.0)
 20338                              <1> 	; 03/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_path')
 20339                              <1> 	; 2005
 20340                              <1> get_path_fchar:
 20341                              <1>  	; esi = path
 20342 00006D88 803E20              <1> 	cmp	byte [esi], 20h
 20343 00006D8B 7737                <1> 	ja	short loc_set_path
 20344                              <1> 
 20345 00006D8D BE00300900          <1> 	mov	esi, Env_Page
 20346                              <1> loc_print_path:
 20347 00006D92 803E00              <1> 	cmp	byte [esi], 0
 20348 00006D95 762C                <1> 	jna	short loc_path_retn
 20349                              <1> 
 20350 00006D97 BE[C2B50000]        <1> 	mov	esi, Cmd_Path ; 'PATH' address
 20351 00006D9C BF[42C60000]        <1> 	mov	edi, TextBuffer ; oout buffer
 20352 00006DA1 30C0                <1> 	xor	al, al  ; use [ESI]
 20353 00006DA3 B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
 20354 00006DA8 E83E000000          <1> 	call	get_environment_string
 20355 00006DAD 7214                <1> 	jc	short loc_path_retn
 20356                              <1> 
 20357 00006DAF BE[42C60000]        <1> 	mov	esi, TextBuffer
 20358 00006DB4 E811D1FFFF          <1> 	call	print_msg
 20359 00006DB9 BE[56C10000]        <1> 	mov	esi, nextline
 20360 00006DBE E807D1FFFF          <1> 	call	print_msg   
 20361                              <1> 
 20362                              <1> loc_path_retn: 
 20363 00006DC3 C3                  <1> 	retn
 20364                              <1> 
 20365                              <1> loc_set_path:
 20366 00006DC4 56                  <1> 	push	esi 
 20367                              <1> loc_set_path_find_end:
 20368 00006DC5 46                  <1> 	inc	esi
 20369 00006DC6 803E20              <1> 	cmp	byte [esi], 20h
 20370 00006DC9 73FA                <1> 	jnb	short loc_set_path_find_end
 20371 00006DCB C60600              <1> 	mov	byte [esi], 0 
 20372                              <1> loc_set_path_header: 
 20373 00006DCE 5E                  <1> 	pop	esi	  
 20374 00006DCF 4E                  <1> 	dec	esi
 20375 00006DD0 C6063D              <1> 	mov	byte [esi], '='
 20376 00006DD3 4E                  <1> 	dec	esi
 20377 00006DD4 C60648              <1> 	mov	byte [esi], 'H'
 20378 00006DD7 4E                  <1> 	dec	esi
 20379 00006DD8 C60654              <1> 	mov	byte [esi], 'T'
 20380 00006DDB 4E                  <1> 	dec	esi
 20381 00006DDC C60641              <1> 	mov	byte [esi], 'A'
 20382 00006DDF 4E                  <1> 	dec	esi
 20383 00006DE0 C60650              <1> 	mov	byte [esi], 'P'   
 20384                              <1> 
 20385                              <1> loc_path_call_set_env_string:
 20386 00006DE3 E8C6000000          <1> 	call	set_environment_string
 20387 00006DE8 728B                <1>         jc	short loc_set_cmd_failed
 20388                              <1> 
 20389 00006DEA C3                  <1> 	retn              
 20390                              <1> 
 20391                              <1> get_environment_string:
 20392                              <1> 	; 12/04/2016
 20393                              <1> 	; 11/04/2016
 20394                              <1> 	; 05/04/2016 (TRDOS 386 =  TRDOS v2.0)
 20395                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
 20396                              <1> 	; 28/08/2011
 20397                              <1> 	; INPUT->
 20398                              <1> 	;	EDI = Output buffer
 20399                              <1> 	;	CX = Buffer length (<= ENV_PAGE_SIZE)
 20400                              <1> 	;
 20401                              <1> 	;	AL > 0 = AL = String sequence number
 20402                              <1> 	;	AL = 0 -> ESI = ASCIIZ Set word 
 20403                              <1> 	;		(environment variable)
 20404                              <1> 	; OUTPUT ->
 20405                              <1> 	;	ESI is not changed
 20406                              <1> 	;	EDI is not changed
 20407                              <1> 	;	EAX = String length (with zero tail)
 20408                              <1> 	;	EDX = Environment variables page address
 20409                              <1> 	;	CF = 1 -> Not found (EAX not valid)
 20410                              <1> 	;
 20411                              <1> 	; (Modified registers: EAX, EDX) 
 20412                              <1> 
 20413 00006DEB BA00300900          <1> 	mov	edx, Env_Page
 20414 00006DF0 803A00              <1> 	cmp	byte [edx], 0
 20415 00006DF3 7474                <1> 	jz	short get_env_string_with_word_stc_retn
 20416                              <1> 
 20417 00006DF5 66890D[AAD10000]    <1> 	mov	[env_var_length], cx
 20418                              <1> 
 20419 00006DFC 51                  <1> 	push	ecx ; *
 20420 00006DFD 56                  <1> 	push	esi ; **
 20421                              <1> 
 20422 00006DFE 08C0                <1> 	or	al, al
 20423 00006E00 7449                <1> 	jz	short get_env_string_with_word
 20424                              <1> 
 20425                              <1> get_env_string_with_seq_number:
 20426 00006E02 B101                <1> 	mov	cl, 1
 20427 00006E04 88C5                <1> 	mov	ch, al
 20428 00006E06 31C0                <1> 	xor	eax, eax
 20429 00006E08 89D6                <1> 	mov	esi, edx ; Env_Page
 20430                              <1> 
 20431                              <1> get_env_string_seq_number_check:
 20432 00006E0A 38CD                <1> 	cmp	ch, cl
 20433 00006E0C 7726                <1> 	ja	short get_env_string_seq_number_next
 20434                              <1> 
 20435                              <1> get_env_string_move_to_buff:
 20436 00006E0E 57                  <1> 	push	edi ; ***
 20437                              <1> 
 20438 00006E0F 29D2                <1> 	sub	edx, edx
 20439                              <1> 
 20440                              <1> get_env_string_seq_number_repeat1:
 20441 00006E11 42                  <1> 	inc	edx
 20442 00006E12 AC                  <1> 	lodsb
 20443 00006E13 AA                  <1> 	stosb
 20444                              <1> 
 20445 00006E14 66FF0D[AAD10000]    <1> 	dec	word [env_var_length]
 20446 00006E1B 7508                <1> 	jnz	short get_env_string_seq_number_repeat3
 20447                              <1> 
 20448                              <1> get_env_string_seq_number_repeat2:
 20449 00006E1D 20C0                <1> 	and	al, al
 20450 00006E1F 7408                <1> 	jz	short get_env_string_seq_number_ok
 20451 00006E21 42                  <1> 	inc	edx
 20452 00006E22 AC                  <1> 	lodsb
 20453 00006E23 EBF8                <1> 	jmp	short get_env_string_seq_number_repeat2
 20454                              <1> 
 20455                              <1> get_env_string_seq_number_repeat3:
 20456 00006E25 08C0                <1> 	or	al, al
 20457 00006E27 75E8                <1> 	jnz	short get_env_string_seq_number_repeat1
 20458                              <1> 
 20459                              <1> get_env_string_seq_number_ok:
 20460 00006E29 5F                  <1> 	pop	edi ; ***
 20461 00006E2A 89D0                <1> 	mov	eax, edx ; Length of the environment string
 20462                              <1> 			 ; (ASCIIZ, includes ZERO tail)
 20463 00006E2C BA00300900          <1> 	mov	edx, Env_Page
 20464                              <1> 
 20465                              <1> get_env_string_stc_retn:
 20466 00006E31 5E                  <1> 	pop	esi ; **
 20467 00006E32 59                  <1> 	pop	ecx ; *
 20468 00006E33 C3                  <1> 	retn   
 20469                              <1> 	
 20470                              <1> get_env_string_seq_number_next:
 20471 00006E34 AC                  <1> 	lodsb
 20472 00006E35 08C0                <1> 	or	al, al
 20473 00006E37 75FB                <1> 	jnz	short get_env_string_seq_number_next
 20474                              <1> 
 20475 00006E39 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; +512 (+4096)
 20476 00006E3F F5                  <1> 	cmc
 20477 00006E40 72EF                <1> 	jc	short get_env_string_stc_retn
 20478                              <1> 
 20479 00006E42 AC                  <1> 	lodsb
 20480 00006E43 3C01                <1> 	cmp	al, 1
 20481 00006E45 72EA                <1> 	jb	short get_env_string_stc_retn
 20482 00006E47 FEC1                <1> 	inc	cl
 20483 00006E49 EBBF                <1> 	jmp	short get_env_string_seq_number_check
 20484                              <1> 
 20485                              <1> get_env_string_with_word:
 20486 00006E4B 31C9                <1> 	xor	ecx, ecx
 20487                              <1> 
 20488                              <1> get_env_string_calc_word_length:
 20489 00006E4D AC                  <1> 	lodsb 
 20490 00006E4E 3C20                <1> 	cmp	al, 20h
 20491 00006E50 7211                <1> 	jb	short get_env_string_calc_word_length_ok
 20492                              <1> 	;inc	cx
 20493 00006E52 FEC1                <1> 	inc	cl
 20494                              <1> 
 20495 00006E54 3C61                <1> 	cmp	al, 'a'
 20496 00006E56 72F5                <1> 	jb	short get_env_string_calc_word_length
 20497 00006E58 3C7A                <1> 	cmp	al, 'z'
 20498 00006E5A 77F1                <1> 	ja	short get_env_string_calc_word_length
 20499 00006E5C 24DF                <1> 	and	al, 0DFh
 20500 00006E5E 8846FF              <1> 	mov	[esi-1], al
 20501 00006E61 EBEA                <1> 	jmp	short get_env_string_calc_word_length
 20502                              <1> 	
 20503                              <1> get_env_string_calc_word_length_ok:
 20504 00006E63 08C9                <1> 	or	cl, cl
 20505 00006E65 7506                <1> 	jnz	short get_env_string_calc_word_length_save
 20506                              <1>      
 20507 00006E67 5E                  <1> 	pop	esi ; **
 20508                              <1> 
 20509                              <1> get_env_string_stc_retn1:
 20510 00006E68 59                  <1> 	pop	ecx ; *
 20511                              <1>         
 20512                              <1> get_env_string_with_word_stc_retn:
 20513 00006E69 31C0                <1> 	xor	eax, eax  
 20514 00006E6B F9                  <1> 	stc
 20515 00006E6C C3                  <1> 	retn
 20516                              <1>   
 20517                              <1> get_env_string_calc_word_length_save:
 20518 00006E6D 871C24              <1> 	xchg	ebx, [esp] ; **
 20519 00006E70 89DE                <1> 	mov	esi, ebx 
 20520                              <1> 		; Start of the env string (to be searched)
 20521                              <1> 
 20522 00006E72 57                  <1> 	push	edi ; ***
 20523 00006E73 89D7                <1> 	mov	edi, edx ; Env_Page
 20524                              <1> 
 20525                              <1> get_env_string_compare:
 20526 00006E75 57                  <1> 	push	edi ; ****
 20527 00006E76 51                  <1> 	push	ecx ; ***** ; Variable name length
 20528                              <1> 
 20529                              <1> get_env_string_compare_rep:
 20530 00006E77 AC                  <1> 	lodsb
 20531 00006E78 AE                  <1> 	scasb
 20532 00006E79 7511                <1> 	jne	short get_env_string_compare_next1
 20533 00006E7B E2FA                <1> 	loop	get_env_string_compare_rep
 20534                              <1> 	
 20535 00006E7D 803F3D              <1> 	cmp	byte [edi], '='
 20536 00006E80 750A                <1> 	jne	short get_env_string_compare_next1
 20537                              <1>  
 20538 00006E82 59                  <1> 	pop	ecx ; *****
 20539 00006E83 5F                  <1> 	pop	edi ; ****
 20540 00006E84 89FE                <1> 	mov	esi, edi
 20541 00006E86 5F                  <1> 	pop	edi ; ***
 20542 00006E87 871C24              <1> 	xchg	ebx, [esp] ; **
 20543 00006E8A EB82                <1> 	jmp	short get_env_string_move_to_buff
 20544                              <1> 
 20545                              <1> get_env_string_compare_next1:
 20546 00006E8C 89FE                <1> 	mov	esi, edi
 20547 00006E8E 59                  <1> 	pop	ecx ; *****
 20548 00006E8F 5F                  <1> 	pop	edi ; ****
 20549                              <1> get_env_string_compare_next2:
 20550 00006E90 81FEFF310900        <1> 	cmp	esi, Env_Page + Env_Page_Size - 1 ; +511 (+4095)
 20551 00006E96 7310                <1> 	jnb	short get_env_string_compare_not_ok
 20552 00006E98 20C0                <1> 	and	al, al
 20553 00006E9A AC                  <1> 	lodsb
 20554 00006E9B 75F3                <1> 	jnz	short get_env_string_compare_next2
 20555 00006E9D 08C0                <1> 	or	al, al
 20556 00006E9F 7407                <1> 	jz	short get_env_string_compare_not_ok
 20557 00006EA1 4E                  <1> 	dec	esi ; 12/04/2016
 20558 00006EA2 89F7                <1> 	mov	edi, esi
 20559 00006EA4 89DE                <1> 	mov	esi, ebx
 20560 00006EA6 EBCD                <1> 	jmp	short get_env_string_compare
 20561                              <1> 
 20562                              <1> get_env_string_compare_not_ok:
 20563 00006EA8 5F                  <1> 	pop	edi ; ***
 20564 00006EA9 89DE                <1> 	mov	esi, ebx
 20565 00006EAB 5B                  <1> 	pop	ebx ; **
 20566 00006EAC EBBA                <1> 	jmp	short get_env_string_stc_retn1
 20567                              <1> 
 20568                              <1> set_environment_string:
 20569                              <1> 	; 13/04/2016
 20570                              <1> 	; 12/04/2016
 20571                              <1> 	; 11/04/2016
 20572                              <1> 	; 06/04/2016
 20573                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
 20574                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
 20575                              <1> 	; 29/08/2011
 20576                              <1> 	; 29/08/2011
 20577                              <1> 	; INPUT->
 20578                              <1> 	;	ESI = ASCIIZ environment string
 20579                              <1> 	; OUTPUT ->
 20580                              <1> 	;	ESI is not changed
 20581                              <1> 	;	CF = 1 -> Could not set, 
 20582                              <1> 	;	     insufficient environment space
 20583                              <1> 	;
 20584                              <1> 	; (EAX, EDX will be changed) 
 20585                              <1> 	;
 20586                              <1> 	;    (EAX = Start address of the env string if > 0)	
 20587                              <1> 	;    (EDX = Environment string length)	
 20588                              <1> 
 20589 00006EAE 56                  <1> 	push 	esi ; *
 20590                              <1> 
 20591 00006EAF 31C0                <1> 	xor	eax, eax
 20592                              <1> 
 20593                              <1> set_env_chk_validation1:
 20594 00006EB1 FEC4                <1> 	inc	ah ; variable (string) length
 20595 00006EB3 AC                  <1> 	lodsb
 20596 00006EB4 3C3D                <1> 	cmp	al, '='
 20597 00006EB6 7415                <1> 	je	short set_env_chk_validation2
 20598 00006EB8 3C20                <1> 	cmp	al, 20h
 20599 00006EBA 720F                <1> 	jb	short set_env_string_stc
 20600                              <1> 
 20601                              <1> 	; 06/04/2016
 20602 00006EBC 3C61                <1> 	cmp	al, 'a'
 20603 00006EBE 72F1                <1> 	jb	short set_env_chk_validation1
 20604 00006EC0 3C7A                <1> 	cmp	al, 'z'
 20605 00006EC2 77ED                <1> 	ja	short set_env_chk_validation1
 20606 00006EC4 2C20                <1> 	sub	al, 'a'-'A'
 20607 00006EC6 8846FF              <1> 	mov	[esi-1], al
 20608 00006EC9 EBE6                <1> 	jmp	short set_env_chk_validation1
 20609                              <1> 
 20610                              <1> set_env_string_stc:
 20611 00006ECB 5E                  <1> 	pop	esi ; *
 20612                              <1> 	;stc
 20613 00006ECC C3                  <1> 	retn 
 20614                              <1> 	   
 20615                              <1> set_env_chk_validation2:
 20616 00006ECD 51                  <1> 	push	ecx ; **
 20617 00006ECE 53                  <1> 	push	ebx ; *** 
 20618 00006ECF 57                  <1> 	push	edi ; ****
 20619                              <1> 
 20620                              <1> 	; 12/04/2016
 20621 00006ED0 8B5C240C            <1> 	mov	ebx, [esp+12]
 20622                              <1> 
 20623                              <1> set_env_chk_validation2w:
 20624 00006ED4 89F7                <1> 	mov	edi, esi
 20625 00006ED6 4F                  <1> 	dec	edi
 20626                              <1> 
 20627 00006ED7 807FFF20            <1> 	cmp	byte [edi-1], 20h
 20628 00006EDB 771A                <1> 	ja	short set_env_chk_validation2z
 20629                              <1> 	
 20630 00006EDD 56                  <1> 	push	esi
 20631 00006EDE 89FE                <1> 	mov	esi, edi
 20632 00006EE0 4E                  <1> 	dec	esi
 20633                              <1> 
 20634                              <1> set_env_chk_validation2x:
 20635 00006EE1 4E                  <1> 	dec	esi
 20636                              <1> 
 20637 00006EE2 39DE                <1> 	cmp	esi, ebx
 20638 00006EE4 7207                <1> 	jb	short set_env_chk_validation2y
 20639                              <1> 
 20640 00006EE6 4F                  <1> 	dec	edi
 20641                              <1> 
 20642 00006EE7 8A06                <1> 	mov	al, [esi]
 20643 00006EE9 8807                <1> 	mov	[edi], al
 20644                              <1> 
 20645 00006EEB EBF4                <1> 	jmp	short set_env_chk_validation2x
 20646                              <1> 
 20647                              <1> set_env_chk_validation2y:
 20648 00006EED 5E                  <1> 	pop	esi
 20649                              <1> 
 20650                              <1> 	;mov	byte [ebx], 20h
 20651                              <1> 	
 20652 00006EEE 43                  <1> 	inc 	ebx
 20653 00006EEF 895C240C            <1> 	mov	[esp+12], ebx
 20654                              <1> 
 20655 00006EF3 FECC                <1> 	dec 	ah ; 13/04/2016
 20656                              <1> 
 20657 00006EF5 EBDD                <1> 	jmp	short set_env_chk_validation2w
 20658                              <1> 	
 20659                              <1> set_env_chk_validation2z:	
 20660 00006EF7 BA00300900          <1> 	mov	edx, Env_Page
 20661 00006EFC 89D7                <1> 	mov	edi, edx
 20662                              <1> 
 20663                              <1> set_env_chk_validation3:
 20664 00006EFE AC                  <1> 	lodsb
 20665 00006EFF 3C20                <1> 	cmp	al, 20h
 20666 00006F01 74FB                <1> 	je	short set_env_chk_validation3
 20667                              <1> 
 20668 00006F03 9C                  <1> 	pushf
 20669                              <1> 
 20670                              <1> 	; 12/04/2016
 20671                              <1> set_env_chk_validation3n:
 20672 00006F04 3C61                <1> 	cmp	al, 'a'
 20673 00006F06 720C                <1> 	jb	short set_env_chk_validation3c
 20674 00006F08 3C7A                <1> 	cmp	al, 'z'
 20675 00006F0A 7705                <1> 	ja	short set_env_chk_validation3x
 20676 00006F0C 2C20                <1> 	sub	al, 'a'-'A'
 20677 00006F0E 8846FF              <1> 	mov	[esi-1], al
 20678                              <1> 
 20679                              <1> set_env_chk_validation3x:
 20680 00006F11 AC                  <1> 	lodsb
 20681 00006F12 EBF0                <1> 	jmp	short set_env_chk_validation3n
 20682                              <1> 
 20683                              <1> set_env_chk_validation3c:
 20684 00006F14 3C20                <1> 	cmp	al, 20h
 20685 00006F16 73F9                <1> 	jnb	short set_env_chk_validation3x
 20686                              <1> 		
 20687 00006F18 803F00              <1> 	cmp	byte [edi], 0
 20688 00006F1B 7731                <1> 	ja	short set_env_chk_validation4
 20689                              <1> 
 20690 00006F1D 9D                  <1> 	popf
 20691 00006F1E 7228                <1> 	jb	short set_env_string_nothing
 20692                              <1> 
 20693 00006F20 B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)
 20694                              <1> 
 20695 00006F25 89DE                <1> 	mov	esi, ebx ; 12/04/2016
 20696                              <1> 
 20697                              <1> set_env_string_copy_to_envb:
 20698 00006F27 AC                  <1> 	lodsb
 20699 00006F28 3C20                <1> 	cmp	al, 20h
 20700 00006F2A 720A                <1> 	jb	short set_env_string_copy_to_envb_z
 20701 00006F2C AA                  <1> 	stosb
 20702 00006F2D E2F8                <1> 	loop	set_env_string_copy_to_envb
 20703                              <1> 
 20704                              <1> 	; 11/04/2016
 20705 00006F2F 89D7                <1> 	mov	edi, edx ; Env_Page
 20706 00006F31 B900020000          <1> 	mov	ecx, Env_Page_Size 
 20707                              <1> 
 20708                              <1> set_env_string_copy_to_envb_z:
 20709 00006F36 52                  <1> 	push	edx  ; Start address of the variable
 20710 00006F37 BA00020000          <1> 	mov	edx, Env_Page_Size
 20711 00006F3C 29CA                <1> 	sub	edx, ecx ; variable (string) length
 20712                              <1> 
 20713 00006F3E 28C0                <1> 	sub	al, al ; 0
 20714 00006F40 F3AA                <1>  	rep	stosb ; clear remain bytes of the env page
 20715                              <1> 
 20716 00006F42 58                  <1> 	pop	eax  ; Start address of the variable
 20717                              <1> 
 20718                              <1> set_env_string_allocate_envb_retn:  ; stc or clc return
 20719 00006F43 5F                  <1> 	pop	edi ; ****
 20720 00006F44 5B                  <1> 	pop	ebx ; ***
 20721 00006F45 59                  <1> 	pop	ecx ; **
 20722 00006F46 5E                  <1> 	pop	esi ; *	
 20723 00006F47 C3                  <1> 	retn
 20724                              <1> 
 20725                              <1> set_env_string_nothing:
 20726 00006F48 31C0                <1> 	xor	eax, eax
 20727 00006F4A 31D2                <1> 	xor	edx, edx ; 11/04/2016
 20728 00006F4C EBF5                <1> 	jmp	short set_env_string_allocate_envb_retn
 20729                              <1> 
 20730                              <1> set_env_chk_validation4:
 20731                              <1> 	; 11/04/2016
 20732 00006F4E 9D                  <1> 	popf
 20733                              <1> 
 20734 00006F4F 89D6                <1> 	mov	esi, edx  ; Env_Page
 20735                              <1> 
 20736                              <1> set_env_chk_validation5:	
 20737 00006F51 89DF                <1> 	mov	edi, ebx  ; ASCIIZ environment string address	
 20738 00006F53 0FB6CC              <1> 	movzx	ecx, ah ; Variable (string) length (with '=')
 20739                              <1> 
 20740                              <1> set_env_chk_validation5_loop:
 20741 00006F56 AC                  <1> 	lodsb
 20742 00006F57 AE                  <1> 	scasb
 20743 00006F58 750A                <1> 	jne	short set_env_chk_validation6
 20744 00006F5A E2FA                <1> 	loop	set_env_chk_validation5_loop
 20745                              <1> 
 20746 00006F5C 3C3D                <1> 	cmp	al, '='
 20747 00006F5E 0F8483000000        <1>         je      set_env_change_variable
 20748                              <1> 
 20749                              <1> set_env_chk_validation6:
 20750 00006F64 08C0                <1> 	or	al, al ; 0
 20751 00006F66 7403                <1> 	jz	short set_env_chk_validation7
 20752                              <1> 
 20753 00006F68 AC                  <1> 	lodsb
 20754 00006F69 EBF9                <1> 	jmp	short set_env_chk_validation6
 20755                              <1> 
 20756                              <1> set_env_chk_validation7:
 20757 00006F6B 88E1                <1> 	mov	cl, ah
 20758 00006F6D 01F1                <1> 	add	ecx, esi
 20759 00006F6F 81F9FF310900        <1> 	cmp	ecx, Env_Page + Env_Page_Size - 1 
 20760                              <1> 		; 511 (4095) 
 20761                              <1> 		; strlen + '=' + 0
 20762 00006F75 72DA                <1> 	jb	short set_env_chk_validation5
 20763                              <1> 
 20764                              <1> set_env_chk_validation8: ; variable not found
 20765 00006F77 0FB6F4              <1> 	movzx	esi, ah  ; variable name length (with '=') 
 20766 00006F7A 01DE                <1> 	add	esi, ebx ; position just after of the '='
 20767                              <1> 
 20768                              <1> set_env_chk_validation8_loop:
 20769 00006F7C AC                  <1> 	lodsb
 20770 00006F7D 3C20                <1> 	cmp	al, 20h
 20771 00006F7F 74FB                <1> 	je	short set_env_chk_validation8_loop	
 20772 00006F81 72C5                <1> 	jb	short set_env_string_nothing
 20773                              <1> 
 20774                              <1> set_env_chk_validation9:
 20775 00006F83 AC                  <1> 	lodsb
 20776 00006F84 3C20                <1> 	cmp	al, 20h
 20777 00006F86 73FB                <1> 	jnb	short set_env_chk_validation9
 20778                              <1> 
 20779                              <1> 	; End of ASCIIZ environment string
 20780                              <1> 
 20781                              <1> set_env_add_variable:
 20782 00006F88 29DE                <1> 	sub	esi, ebx ; variable+definition length
 20783                              <1> 	
 20784 00006F8A 56                  <1> 	push	esi ; *****
 20785                              <1> 
 20786 00006F8B 89D6                <1> 	mov	esi, edx ; Environment page address
 20787                              <1> 
 20788 00006F8D B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)	
 20789                              <1> 
 20790                              <1> set_env_add_variable_loop:
 20791 00006F92 AC                  <1> 	lodsb
 20792 00006F93 20C0                <1> 	and	al, al		
 20793 00006F95 7406                <1> 	jz	short set_env_add_variable_chk1 ; 0
 20794 00006F97 E2F9                <1> 	loop	set_env_add_variable_loop
 20795                              <1> 
 20796                              <1> 	; 11/04/2016
 20797 00006F99 884EFF              <1> 	mov	[esi-1], cl ; 0
 20798 00006F9C 41                  <1> 	inc	ecx
 20799                              <1> 	
 20800                              <1> set_env_add_variable_chk1: 
 20801 00006F9D 49                  <1> 	dec	ecx
 20802 00006F9E 7408                <1> 	jz	short set_env_add_variable_nspc
 20803 00006FA0 AC                  <1> 	lodsb
 20804 00006FA1 08C0                <1> 	or 	al, al
 20805 00006FA3 740C                <1> 	jz	short set_env_add_variable_chk2 ; 00
 20806 00006FA5 49                  <1> 	dec	ecx
 20807 00006FA6 75EA                <1> 	jnz	short set_env_add_variable_loop
 20808                              <1> 
 20809                              <1> set_env_add_variable_nspc: ; no space on environment page
 20810 00006FA8 58                  <1> 	pop	eax ; *****
 20811 00006FA9 B808000000          <1> 	mov	eax, 08h ; No space for new environment string
 20812 00006FAE F9                  <1> 	stc
 20813 00006FAF EB92                <1>         jmp     short set_env_string_allocate_envb_retn
 20814                              <1> 
 20815                              <1> set_env_add_variable_chk2:
 20816 00006FB1 8B0C24              <1> 	mov	ecx, [esp] ; *****
 20817 00006FB4 4E                  <1> 	dec	esi ; beginning address of the new variable
 20818 00006FB5 89F0                <1> 	mov	eax, esi
 20819 00006FB7 01C8                <1> 	add	eax, ecx ; string length (with CR)
 20820 00006FB9 81C200020000        <1> 	add	edx, Env_Page_Size ; 512 (4096)
 20821 00006FBF 39D0                <1> 	cmp	eax, edx 
 20822 00006FC1 77E5                <1> 	ja	short set_env_add_variable_nspc
 20823 00006FC3 49                  <1> 	dec	ecx ; except CR at the end
 20824 00006FC4 89CA                <1> 	mov	edx, ecx ; 12/04/2016
 20825 00006FC6 89F7                <1> 	mov	edi, esi
 20826 00006FC8 893C24              <1> 	mov	[esp], edi ; ***** ; Start address of new variable
 20827 00006FCB 89DE                <1> 	mov	esi, ebx ; ASCIIZ environment string address
 20828 00006FCD F3A4                <1> 	rep	movsb
 20829 00006FCF 28C0                <1> 	sub	al, al
 20830 00006FD1 AA                  <1> 	stosb
 20831 00006FD2 58                  <1> 	pop	eax ; ***** ; Beginning address of new variable			
 20832 00006FD3 81FF00320900        <1>         cmp     edi, Env_Page + Env_Page_Size ; 12/04/2016
 20833 00006FD9 0F8364FFFFFF        <1>         jnb     set_env_string_allocate_envb_retn ; OK !
 20834 00006FDF 880F                <1> 	mov	[edi], cl ; 0
 20835 00006FE1 F8                  <1> 	clc	; 13/04/2016
 20836 00006FE2 E95CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
 20837                              <1> 
 20838                              <1> set_env_change_variable:
 20839                              <1> 	; 06/04/2016
 20840                              <1> 	; esi = Variable's address in environment page (after '=')
 20841                              <1> 	; edi = ASCIIZ environment string address (after '=')
 20842                              <1> 
 20843                              <1> 	; ah = variable length from start to the '='
 20844 00006FE7 8825[AAD10000]      <1> 	mov	[env_var_length], ah
 20845                              <1> 
 20846 00006FED 28C9                <1> 	sub	cl, cl ; ecx = 0
 20847                              <1> 
 20848 00006FEF 57                  <1> 	push	edi ; *****
 20849                              <1> 
 20850 00006FF0 89F7                <1> 	mov	edi, esi ; 11/04/2016
 20851                              <1> 
 20852                              <1> set_env_change_variable_calc1:
 20853 00006FF2 AC                  <1> 	lodsb
 20854 00006FF3 08C0                <1> 	or	al, al
 20855 00006FF5 7403                <1> 	jz	short set_env_change_variable_calc2
 20856                              <1> 
 20857 00006FF7 41                  <1> 	inc	ecx ; length of environment string (after the '=')
 20858                              <1> 
 20859 00006FF8 EBF8                <1> 	jmp	short set_env_change_variable_calc1	
 20860                              <1> 
 20861                              <1> set_env_change_variable_calc2:
 20862 00006FFA 8B3424              <1> 	mov	esi, [esp] ; ASCIIZ environment string address
 20863                              <1> 	
 20864 00006FFD 29D2                <1> 	sub	edx, edx
 20865                              <1> 
 20866                              <1> set_env_change_variable_calc3:
 20867 00006FFF AC                  <1> 	lodsb
 20868 00007000 3C20                <1> 	cmp	al, 20h
 20869 00007002 7203                <1> 	jb	short set_env_change_variable_calc4
 20870                              <1> 
 20871 00007004 42                  <1> 	inc	edx ; length of ASCIIZ string (after the '=')
 20872                              <1> 	
 20873 00007005 EBF8                <1> 	jmp	short set_env_change_variable_calc3
 20874                              <1> 	
 20875                              <1> set_env_change_variable_calc4:
 20876 00007007 C646FF00            <1> 	mov	byte [esi-1], 0  ; put ZERO instead of CR
 20877                              <1> 	
 20878 0000700B 5E                  <1> 	pop	esi ; ***** ; ASCIIZ string address (after '=')
 20879                              <1> 
 20880                              <1> 	; EDI = Old variable's address (after '=')
 20881                              <1> 	
 20882                              <1> 	; compare the new string with the old string
 20883 0000700C 39CA                <1> 	cmp	edx, ecx
 20884 0000700E 7717                <1> 	ja	short set_env_change_variable_calc5 ; longer
 20885 00007010 0F828F000000        <1>         jb      set_env_change_variable_calc9 ; shorter
 20886                              <1> 	
 20887                              <1> 	;same length (simple copy)
 20888 00007016 0FB6C4              <1> 	movzx	eax, ah
 20889 00007019 01C2                <1> 	add	edx, eax
 20890 0000701B F7D8                <1> 	neg	eax
 20891 0000701D 01F8                <1> 	add	eax, edi
 20892                              <1> 	; EAX = Start address of the variable
 20893                              <1> 	; EDX = Variable length (without ZERO at the end of variable)
 20894                              <1> 
 20895 0000701F F3A4                <1> 	rep	movsb
 20896 00007021 F8                  <1> 	clc	; 13/04/2016
 20897 00007022 E91CFFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
 20898                              <1> 
 20899                              <1> set_env_change_variable_calc5:
 20900                              <1> 	; 11/04/2016
 20901 00007027 52                  <1> 	push	edx ; *****
 20902 00007028 29CA                <1> 	sub	edx, ecx ; difference ; (the new string is longer)
 20903 0000702A 89F3                <1> 	mov 	ebx, esi
 20904 0000702C 89FE                <1> 	mov	esi, edi
 20905                              <1> 
 20906                              <1> set_env_change_variable_calc6:
 20907 0000702E AC                  <1> 	lodsb 
 20908 0000702F 20C0                <1> 	and	al, al
 20909 00007031 75FB                <1> 	jnz	short set_env_change_variable_calc6
 20910                              <1> 
 20911 00007033 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
 20912 00007039 0F8369FFFFFF        <1>         jnb     set_env_add_variable_nspc
 20913                              <1> 
 20914 0000703F 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
 20915 00007041 89F7                <1> 	mov	edi, esi  ; next variable's address 
 20916                              <1> 
 20917 00007043 AC                  <1> 	lodsb
 20918 00007044 08C0                <1> 	or	al, al
 20919 00007046 7416                <1> 	jz	short set_env_change_variable_calc8 ; 00
 20920                              <1> 
 20921                              <1> set_env_change_variable_calc7:
 20922 00007048 AC                  <1> 	lodsb
 20923 00007049 20C0                <1> 	and	al, al
 20924 0000704B 75FB                <1> 	jnz	short set_env_change_variable_calc7
 20925                              <1> 
 20926 0000704D 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
 20927 00007053 0F834FFFFFFF        <1>         jnb     set_env_add_variable_nspc
 20928                              <1> 
 20929 00007059 AC                  <1> 	lodsb
 20930 0000705A 08C0                <1> 	or	al, al
 20931 0000705C 75EA                <1> 	jnz	short set_env_change_variable_calc7
 20932                              <1> 
 20933                              <1> set_env_change_variable_calc8:
 20934 0000705E 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
 20935                              <1> 
 20936 0000705F 01F2                <1> 	add	edx, esi ; final position of the last 0
 20937                              <1> 
 20938 00007061 81FA00320900        <1> 	cmp	edx, Env_Page + Env_Page_Size ; 512 (4096)
 20939 00007067 0F833BFFFFFF        <1>         jnb     set_env_add_variable_nspc
 20940                              <1> 
 20941 0000706D 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
 20942                              <1> 
 20943 0000706F 89F1                <1> 	mov	ecx, esi 
 20944 00007071 29F9                <1> 	sub	ecx, edi ; count of bytes to move forward
 20945                              <1> 
 20946                              <1> 	; 13/04/2016
 20947 00007073 C60200              <1> 	mov	byte [edx], 0
 20948 00007076 89D7                <1> 	mov	edi, edx
 20949 00007078 29F2                <1> 	sub	edx, esi ; difference (additional byte count)
 20950 0000707A 4F                  <1> 	dec	edi ; the last zero address (first byte of the 00)
 20951 0000707B 89FE                <1> 	mov	esi, edi
 20952 0000707D 29D6                <1> 	sub	esi, edx ; - displacement
 20953                              <1> 	
 20954 0000707F FA                  <1> 	cli	; disable interrupts
 20955 00007080 FD                  <1> 	std	; backward
 20956                              <1> 
 20957 00007081 F3A4                <1> 	rep	movsb ; move ECX bytes from DS:ESI to ES:EDI
 20958                              <1> 
 20959 00007083 FC                  <1> 	cld	; forward (default)
 20960 00007084 FB                  <1> 	sti	; enable interrupts
 20961                              <1> 	
 20962 00007085 89C7                <1> 	mov	edi, eax
 20963 00007087 59                  <1> 	pop	ecx ; ***** ; byte count (after '=')
 20964 00007088 89CA                <1> 	mov	edx, ecx
 20965 0000708A 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
 20966 0000708C 89FB                <1> 	mov	ebx, edi
 20967                              <1> 
 20968 0000708E F3A4                <1> 	rep	movsb
 20969                              <1> 
 20970 00007090 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
 20971                              <1> 
 20972 00007092 0FB605[AAD10000]    <1> 	movzx	eax, byte [env_var_length]
 20973 00007099 01C2                <1> 	add	edx, eax ; variable length (total)
 20974 0000709B F7D8                <1> 	neg	eax
 20975 0000709D 01D8                <1> 	add	eax, ebx ; start address of the variable
 20976 0000709F F8                  <1> 	clc	; 13/04/2016
 20977 000070A0 E99EFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
 20978                              <1> 
 20979                              <1> set_env_change_variable_calc9:
 20980                              <1> 	; 11/04/2016
 20981 000070A5 21D2                <1> 	and	edx, edx ; is empty ?
 20982 000070A7 753B                <1> 	jnz	short set_env_change_variable_calc15
 20983                              <1> 	
 20984 000070A9 0FB6DC              <1> 	movzx	ebx, ah
 20985 000070AC F7DB                <1> 	neg	ebx
 20986 000070AE 01FB                <1> 	add	ebx, edi
 20987                              <1> 
 20988                              <1> 	; EBX = Start address of the variable (in env page)
 20989                              <1> 	; EDX = Variable length = 0
 20990                              <1> 	
 20991 000070B0 89FE                <1> 	mov	esi, edi
 20992                              <1> 
 20993                              <1> set_env_change_variable_calc10:
 20994 000070B2 AC                  <1> 	lodsb
 20995 000070B3 08C0                <1> 	or	al, al
 20996 000070B5 75FB                <1> 	jnz	short set_env_change_variable_calc10
 20997                              <1> 
 20998 000070B7 B9FF310900          <1> 	mov	ecx, Env_Page + Env_Page_Size - 1
 20999                              <1> 
 21000 000070BC 39CE                <1> 	cmp	esi, ecx ; +511 (+4095)
 21001 000070BE 7604                <1> 	jna	short set_env_change_variable_calc11
 21002                              <1> 
 21003 000070C0 89CE                <1> 	mov	esi, ecx
 21004 000070C2 8806                <1> 	mov	[esi], al ; 0
 21005                              <1> 
 21006                              <1> set_env_change_variable_calc11:
 21007 000070C4 89DF                <1> 	mov	edi, ebx ; old variable's start address
 21008                              <1> 
 21009                              <1> set_env_change_variable_calc12:
 21010 000070C6 AC                  <1> 	lodsb
 21011 000070C7 AA                  <1> 	stosb
 21012 000070C8 20C0                <1> 	and	al, al
 21013 000070CA 75FA                <1> 	jnz	short set_env_change_variable_calc12
 21014 000070CC 39CE                <1> 	cmp	esi, ecx
 21015 000070CE 7706                <1> 	ja	short set_env_change_variable_calc13
 21016 000070D0 AC                  <1> 	lodsb
 21017 000070D1 AA                  <1> 	stosb
 21018 000070D2 20C0                <1> 	and	al, al
 21019 000070D4 75F0                <1> 	jnz	short set_env_change_variable_calc12	
 21020                              <1> 
 21021                              <1> set_env_change_variable_calc13:
 21022 000070D6 29F9                <1> 	sub	ecx, edi
 21023 000070D8 7203                <1> 	jb	short set_env_change_variable_calc14
 21024 000070DA 41                  <1> 	inc	ecx ; 1-512 (1-4096)
 21025 000070DB F3AA                <1> 	rep	stosb ; al = 0	
 21026                              <1> 
 21027                              <1> set_env_change_variable_calc14:
 21028 000070DD 29C0                <1> 	sub	eax, eax ; Start address of the variable
 21029                              <1> 	; EAX = 0 -> Variable is removed
 21030                              <1> 	; EDX = Variable length = 0	
 21031                              <1> 
 21032 000070DF E95FFEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
 21033                              <1> 	    
 21034                              <1> set_env_change_variable_calc15:	
 21035 000070E4 52                  <1> 	push	edx ; *****
 21036 000070E5 F7DA                <1> 	neg	edx
 21037 000070E7 01CA                <1> 	add	edx, ecx ; difference (the old string is longer)
 21038 000070E9 89F3                <1> 	mov 	ebx, esi
 21039 000070EB 89FE                <1> 	mov	esi, edi
 21040                              <1> 
 21041                              <1> set_env_change_variable_calc16:
 21042 000070ED AC                  <1> 	lodsb 
 21043 000070EE 20C0                <1> 	and	al, al
 21044 000070F0 75FB                <1> 	jnz	short set_env_change_variable_calc16
 21045                              <1> 
 21046 000070F2 B900320900          <1> 	mov	ecx, Env_Page + Env_Page_Size
 21047                              <1> 
 21048 000070F7 39CE                <1> 	cmp	esi, ecx ; +512 (+4096)
 21049 000070F9 7605                <1> 	jna	short set_env_change_variable_calc17
 21050                              <1> 
 21051 000070FB 89CE                <1> 	mov	esi, ecx
 21052 000070FD 8846FF              <1> 	mov	[esi-1], al ; 0
 21053                              <1> 
 21054                              <1> set_env_change_variable_calc17:
 21055 00007100 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
 21056 00007102 89F7                <1> 	mov	edi, esi  ; next variable's address 
 21057                              <1> 
 21058 00007104 AC                  <1> 	lodsb
 21059 00007105 08C0                <1> 	or	al, al
 21060 00007107 741D                <1> 	jz	short set_env_change_variable_calc20
 21061                              <1> 
 21062                              <1> set_env_change_variable_calc18:
 21063 00007109 AC                  <1> 	lodsb
 21064 0000710A 20C0                <1> 	and	al, al
 21065 0000710C 75FB                <1> 	jnz	short set_env_change_variable_calc18
 21066                              <1> 
 21067 0000710E 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size
 21068 00007114 720B                <1> 	jb	short set_env_change_variable_calc19
 21069 00007116 740E                <1> 	je	short set_env_change_variable_calc20
 21070                              <1> 
 21071 00007118 BEFF310900          <1> 	mov	esi, Env_Page + Env_Page_Size - 1
 21072 0000711D 8806                <1> 	mov	[esi], al ; 0
 21073 0000711F EB06                <1> 	jmp	short set_env_change_variable_calc21
 21074                              <1> 
 21075                              <1> set_env_change_variable_calc19:
 21076 00007121 AC                  <1> 	lodsb
 21077 00007122 08C0                <1> 	or	al, al
 21078 00007124 75E3                <1> 	jnz	short set_env_change_variable_calc18
 21079                              <1> 
 21080                              <1> set_env_change_variable_calc20:
 21081 00007126 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
 21082                              <1> 
 21083                              <1> set_env_change_variable_calc21:
 21084                              <1> 	; edx = difference (byte count)
 21085                              <1> 	
 21086 00007127 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
 21087                              <1> 
 21088 00007129 89F1                <1> 	mov	ecx, esi 
 21089 0000712B 29F9                <1> 	sub	ecx, edi ; count of bytes to move backward
 21090                              <1> 
 21091 0000712D 89FE                <1> 	mov	esi, edi ; next variable's address
 21092 0000712F 29D7                <1> 	sub	edi, edx ; (displacement)
 21093                              <1> 	
 21094 00007131 F3A4                <1> 	rep	movsb
 21095                              <1> 
 21096 00007133 880F                <1> 	mov	[edi], cl ; 0 ; 00 ; end of environment variables
 21097                              <1> 
 21098 00007135 89C7                <1> 	mov	edi, eax
 21099 00007137 5A                  <1> 	pop	edx ; ***** ; byte count (after '=')
 21100 00007138 89D1                <1> 	mov	ecx, edx
 21101 0000713A 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
 21102 0000713C 89FB                <1> 	mov	ebx, edi
 21103                              <1> 	
 21104 0000713E F3A4                <1> 	rep	movsb
 21105                              <1> 
 21106 00007140 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
 21107                              <1> 
 21108 00007142 0FB605[AAD10000]    <1> 	movzx	eax, byte [env_var_length]
 21109 00007149 01C2                <1> 	add	edx, eax ; variable length (total)
 21110 0000714B F7D8                <1> 	neg	eax
 21111 0000714D 01D8                <1> 	add	eax, ebx ; start address of the variable
 21112 0000714F F8                  <1> 	clc	; 13/04/2016
 21113 00007150 E9EEFDFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
 21114                              <1> 
 21115                              <1> 
 21116                              <1> mainprog_startup_configuration:
 21117                              <1> 	; 14/04/2016 (TRDOS 386 = TRDOS v2.0)
 21118                              <1> 	; 17/09/2011 (TRDOS v1, MAINPROG.ASM)
 21119                              <1> 	;
 21120                              <1> loc_load_mainprog_cfg_file:
 21121 00007155 BE[3CB50000]        <1> 	mov	esi, MainProgCfgFile
 21122 0000715A 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 21123 0000715E E8FFE9FFFF          <1> 	call	find_first_file
 21124 00007163 7256                <1> 	jc	short loc_load_mainprog_cfg_exit
 21125                              <1> 
 21126                              <1> 	;or	eax, eax
 21127                              <1> 	;jz	short loc_load_mainprog_cfg_exit
 21128                              <1> 
 21129                              <1> loc_start_mainprog_configuration:
 21130                              <1> 	; ESI = FindFile_DirEntry Location
 21131                              <1> 	; EAX = File Size
 21132                              <1> 
 21133 00007165 A3[30C50000]        <1> 	mov	[MainProgCfg_FileSize], eax
 21134                              <1> 
 21135 0000716A 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
 21136 0000716E C1E210              <1> 	shl	edx, 16
 21137 00007171 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
 21138 00007175 8915[5ED10000]      <1> 	mov	[csftdf_sf_cluster], edx
 21139                              <1> 
 21140 0000717B 89C1                <1> 	mov	ecx, eax
 21141 0000717D 29C0                <1> 	sub	eax, eax
 21142                              <1> 
 21143                              <1> 	; TRDOS 386 (TRDOS v2.0)
 21144                              <1> 	; Allocate contiguous memory block for loading the file
 21145                              <1> 	
 21146                              <1> 	; eax = 0 (Allocate memory from the beginning)
 21147                              <1> 	; ecx = File (Allocation) size in bytes
 21148                              <1> 	
 21149 0000717F E86FC7FFFF          <1> 	call	allocate_memory_block
 21150 00007184 7235                <1> 	jc	short loc_load_mainprog_cfg_exit
 21151                              <1> 
 21152 00007186 A3[56D10000]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
 21153 0000718B 890D[5AD10000]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
 21154                              <1> 
 21155 00007191 31DB                <1> 	xor	ebx, ebx
 21156                              <1> 	;mov	[csftdf_sf_rbytes], ebx ; 0, reset
 21157                              <1> 
 21158 00007193 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv] ; [FindFile_Drv]
 21159 00007199 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 21160 0000719E 01DE                <1> 	add	esi, ebx
 21161                              <1> 
 21162 000071A0 8B1D[56D10000]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
 21163                              <1> 
 21164 000071A6 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 21165 000071AA 7710                <1>         ja	short loc_mcfg_load_fat_file
 21166                              <1> 
 21167 000071AC C705[66D10000]0000- <1> 	mov	dword [csftdf_r_size], 65536
 21168 000071B4 0100                <1>
 21169 000071B6 E983010000          <1>         jmp     loc_mcfg_load_fs_file
 21170                              <1> 
 21171                              <1> loc_load_mainprog_cfg_exit:
 21172 000071BB C3                  <1> 	retn 
 21173                              <1> 
 21174                              <1> loc_mcfg_load_fat_file:
 21175 000071BC 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
 21176 000071C0 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 21177 000071C4 F7E1                <1> 	mul	ecx
 21178 000071C6 A3[66D10000]        <1> 	mov	[csftdf_r_size], eax
 21179                              <1> 
 21180                              <1> loc_mcfg_load_fat_file_next:
 21181 000071CB E804010000          <1> 	call	mcfg_read_fat_file_sectors
 21182 000071D0 0F82E8000000        <1>         jc      mcfg_deallocate_mem
 21183                              <1> 
 21184 000071D6 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 21185 000071D8 74F1                <1> 	jz	short loc_mcfg_load_fat_file_next
 21186                              <1> 
 21187                              <1> loc_mcfg_load_fat_file_ok:
 21188 000071DA 8B35[56D10000]      <1> 	mov	esi, [csftdf_sf_mem_addr]
 21189 000071E0 8935[34C50000]      <1> 	mov	[MainProgCfg_LineOffset], esi
 21190                              <1> 	
 21191 000071E6 A1[30C50000]        <1> 	mov	eax, [MainProgCfg_FileSize]
 21192 000071EB 89C2                <1> 	mov	edx, eax
 21193 000071ED 01F2                <1> 	add	edx, esi
 21194                              <1> 
 21195                              <1> loc_mcfg_process_next_line_check:
 21196 000071EF 89C1                <1> 	mov	ecx, eax
 21197                              <1> 
 21198 000071F1 803E2A              <1> 	cmp	byte [esi], "*" ; Remark sign
 21199 000071F4 7503                <1> 	jne	short loc_mcfg_process_next_line
 21200 000071F6 46                  <1> 	inc	esi
 21201 000071F7 EB17                <1> 	jmp	short loc_move_mainprog_cfg_nl1
 21202                              <1> 
 21203                              <1> loc_mcfg_process_next_line:
 21204 000071F9 83F94F              <1> 	cmp	ecx, 79
 21205 000071FC 7605                <1> 	jna	short loc_start_mainprog_cfg_process
 21206                              <1> 	
 21207 000071FE B94F000000          <1> 	mov	ecx, 79 
 21208                              <1> 
 21209                              <1> loc_start_mainprog_cfg_process:
 21210 00007203 BF[F2C50000]        <1> 	mov	edi, CommandBuffer
 21211                              <1> 
 21212                              <1> loc_move_mainprog_cfg_line:
 21213 00007208 AC                  <1> 	lodsb
 21214 00007209 3C20                <1> 	cmp	al, 20h
 21215 0000720B 720C                <1> 	jb	short loc_move_mainprog_cfg_nl2
 21216 0000720D AA                  <1> 	stosb
 21217 0000720E E2F8                <1> 	loop	loc_move_mainprog_cfg_line
 21218                              <1> 
 21219                              <1> loc_move_mainprog_cfg_nl1:
 21220 00007210 39D6                <1> 	cmp	esi, edx ; + configuration file size
 21221 00007212 7312                <1> 	jnb	short loc_end_of_mainprog_cfg_line
 21222 00007214 AC                  <1> 	lodsb
 21223 00007215 3C20                <1> 	cmp	al, 20h
 21224 00007217 73F7                <1> 	jnb	short loc_move_mainprog_cfg_nl1
 21225                              <1> 
 21226                              <1> loc_move_mainprog_cfg_nl2:
 21227 00007219 39D6                <1> 	cmp	esi, edx
 21228 0000721B 7309                <1> 	jnb	short loc_end_of_mainprog_cfg_line
 21229 0000721D 8A06                <1> 	mov	al, [esi]
 21230 0000721F 3C20                <1> 	cmp	al, 20h
 21231 00007221 7703                <1>  	ja	short loc_end_of_mainprog_cfg_line
 21232 00007223 46                  <1> 	inc	esi
 21233 00007224 EBF3                <1> 	jmp	short loc_move_mainprog_cfg_nl2	               
 21234                              <1> 
 21235                              <1> loc_end_of_mainprog_cfg_line:
 21236 00007226 C60700              <1> 	mov	byte [edi], 0
 21237                              <1> 
 21238 00007229 8935[34C50000]      <1> 	mov	[MainProgCfg_LineOffset], esi
 21239                              <1> 	
 21240                              <1> loc_move_mainprog_cfg_command:
 21241 0000722F BE[F2C50000]        <1> 	mov	esi, CommandBuffer
 21242 00007234 89F7                <1> 	mov	edi, esi
 21243 00007236 31DB                <1> 	xor	ebx, ebx
 21244                              <1> 	;xor	ecx, ecx
 21245 00007238 30C9                <1> 	xor	cl, cl
 21246                              <1> 
 21247                              <1> loc_move_mcfg_first_cmd_char:
 21248 0000723A 8A041E              <1> 	mov	al, [esi+ebx]
 21249 0000723D FEC3                <1> 	inc	bl 
 21250 0000723F 3C20                <1> 	cmp	al, 20h
 21251 00007241 7712                <1> 	ja	short loc_move_mcfg_cmd_capitalizing
 21252 00007243 7237                <1> 	jb	short loc_move_mcfg_cmd_arguments_ok
 21253 00007245 80FB4F              <1> 	cmp	bl, 79
 21254 00007248 72F0                <1> 	jb	short loc_move_mcfg_first_cmd_char
 21255 0000724A EB30                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
 21256                              <1> 
 21257                              <1> loc_move_mcfg_next_cmd_char:
 21258 0000724C 8A041E              <1> 	mov	al, [esi+ebx]
 21259 0000724F FEC3                <1> 	inc	bl
 21260 00007251 3C20                <1> 	cmp	al, 20h
 21261 00007253 7614                <1> 	jna	short loc_move_mcfg_cmd_ok
 21262                              <1> 
 21263                              <1> loc_move_mcfg_cmd_capitalizing:
 21264 00007255 3C61                <1> 	cmp	al, 61h ; 'a'
 21265 00007257 7206                <1> 	jb	short loc_move_mcfg_cmd_caps_ok
 21266 00007259 3C7A                <1> 	cmp	al, 7Ah ; 'z'
 21267 0000725B 7702                <1> 	ja	short loc_move_mcfg_cmd_caps_ok
 21268 0000725D 24DF                <1> 	and	al, 0DFh ; sub	al, 'a'-'A'
 21269                              <1> 
 21270                              <1> loc_move_mcfg_cmd_caps_ok:
 21271 0000725F AA                  <1> 	stosb 
 21272 00007260 FEC1                <1> 	inc	cl
 21273 00007262 80FB4F              <1> 	cmp	bl, 79
 21274 00007265 72E5                <1> 	jb	short loc_move_mcfg_next_cmd_char
 21275 00007267 EB13                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
 21276                              <1> 
 21277                              <1> loc_move_mcfg_cmd_ok:
 21278 00007269 30C0                <1> 	xor	al, al ; 0
 21279                              <1> 
 21280                              <1> loc_move_mcfg_cmd_arguments:
 21281 0000726B 8807                <1> 	mov	[edi], al
 21282 0000726D 47                  <1> 	inc	edi
 21283 0000726E 80FB4F              <1> 	cmp	bl, 79
 21284 00007271 7309                <1> 	jnb	short loc_move_mcfg_cmd_arguments_ok
 21285 00007273 8A041E              <1> 	mov	al, [esi+ebx]
 21286 00007276 FEC3                <1> 	inc	bl
 21287 00007278 3C20                <1> 	cmp	al, 20h
 21288 0000727A 73EF                <1> 	jnb	short loc_move_mcfg_cmd_arguments
 21289                              <1> 	
 21290                              <1> loc_move_mcfg_cmd_arguments_ok:
 21291 0000727C C60700              <1> 	mov	byte [edi], 0
 21292                              <1>        
 21293                              <1> loc_mcfg_process_cmd_interpreter:
 21294 0000727F E80BE0FFFF          <1> 	call    command_interpreter
 21295                              <1> 
 21296 00007284 A1[30C50000]        <1> 	mov	eax, [MainProgCfg_FileSize]
 21297 00007289 89C2                <1> 	mov	edx, eax
 21298 0000728B 8B35[34C50000]      <1> 	mov	esi, [MainProgCfg_LineOffset]
 21299 00007291 01F2                <1> 	add	edx, esi
 21300 00007293 0305[56D10000]      <1> 	add	eax, [csftdf_sf_mem_addr]
 21301 00007299 29F0                <1> 	sub	eax, esi
 21302 0000729B 0F874EFFFFFF        <1>         ja      loc_mcfg_process_next_line_check
 21303                              <1> 
 21304 000072A1 E818000000          <1> 	call	mcfg_deallocate_mem
 21305                              <1>  
 21306 000072A6 B94F000000          <1>  	mov	ecx, 79 ; 80 ?
 21307 000072AB BF[F2C50000]        <1> 	mov	edi, CommandBuffer
 21308 000072B0 30C0                <1> 	xor	al, al
 21309 000072B2 F3AA                <1> 	rep	stosb
 21310                              <1> 
 21311 000072B4 BE[56C10000]        <1> 	mov	esi, nextline
 21312                              <1> 	;call	print_msg
 21313                              <1> 	;retn
 21314 000072B9 E90CCCFFFF          <1> 	jmp	print_msg
 21315                              <1> 
 21316                              <1> mcfg_deallocate_mem:
 21317 000072BE A1[56D10000]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
 21318 000072C3 8B0D[5AD10000]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
 21319                              <1> 	;call	deallocate_memory_block
 21320                              <1> 	;retn
 21321 000072C9 E926C8FFFF          <1> 	jmp	deallocate_memory_block
 21322                              <1> 
 21323                              <1> mcfg_read_file_sectors:
 21324                              <1> 	; 14/04/2016
 21325 000072CE 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 21326 000072D2 7669                <1>         jna	short mcfg_read_fs_file_sectors
 21327                              <1> 
 21328                              <1> mcfg_read_fat_file_sectors:
 21329                              <1> 	; return:
 21330                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
 21331                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
 21332                              <1> 	;   CF = 1 -> read error (error code in AL)	
 21333                              <1> 
 21334                              <1> mcfg_read_fat_file_secs_0:
 21335 000072D4 8B15[30C50000]      <1> 	mov	edx, [MainProgCfg_FileSize]
 21336 000072DA 2B15[6ED10000]      <1> 	sub	edx, [csftdf_sf_rbytes]
 21337 000072E0 3B15[66D10000]      <1> 	cmp	edx, [csftdf_r_size]	
 21338 000072E6 7306                <1> 	jnb	short mcfg_read_fat_file_secs_1
 21339 000072E8 8915[66D10000]      <1> 	mov	[csftdf_r_size], edx
 21340                              <1> 		
 21341                              <1> mcfg_read_fat_file_secs_1:
 21342 000072EE A1[66D10000]        <1> 	mov	eax, [csftdf_r_size]
 21343 000072F3 29D2                <1> 	sub	edx, edx
 21344 000072F5 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
 21345 000072F9 01C8                <1> 	add	eax, ecx
 21346 000072FB 48                  <1> 	dec	eax
 21347 000072FC F7F1                <1> 	div	ecx
 21348 000072FE 89C1                <1> 	mov	ecx, eax ; sector count
 21349 00007300 A1[5ED10000]        <1> 	mov	eax, [csftdf_sf_cluster]
 21350                              <1> 
 21351                              <1> 	; EBX = memory block address (current)
 21352                              <1> 	
 21353 00007305 E854200000          <1> 	call	read_fat_file_sectors
 21354 0000730A 7230                <1> 	jc	short mcfg_read_fat_file_secs_3
 21355                              <1> 
 21356                              <1> 	; EBX = next memory address
 21357                              <1> 
 21358 0000730C A1[6ED10000]        <1> 	mov	eax, [csftdf_sf_rbytes]
 21359 00007311 0305[66D10000]      <1> 	add	eax, [csftdf_r_size]
 21360 00007317 8B15[30C50000]      <1> 	mov	edx, [MainProgCfg_FileSize]
 21361 0000731D 39D0                <1> 	cmp	eax, edx
 21362 0000731F 731B                <1> 	jnb	short mcfg_read_fat_file_secs_3 ; edx > 0
 21363 00007321 A3[6ED10000]        <1> 	mov	[csftdf_sf_rbytes], eax
 21364                              <1> 
 21365 00007326 53                  <1> 	push	ebx ; *
 21366                              <1> 	; get next cluster (csftdf_r_size! bytes)
 21367 00007327 A1[5ED10000]        <1> 	mov	eax, [csftdf_sf_cluster]
 21368 0000732C E8FF1D0000          <1> 	call	get_next_cluster
 21369 00007331 5B                  <1> 	pop	ebx ; *
 21370 00007332 7301                <1> 	jnc	short mcfg_read_fat_file_secs_2
 21371                              <1> 
 21372                              <1> 	;mov	eax, 15h ; Read error !
 21373 00007334 C3                  <1> 	retn
 21374                              <1> 
 21375                              <1> mcfg_read_fat_file_secs_2:
 21376 00007335 29D2                <1> 	sub	edx, edx ; 0
 21377 00007337 A3[5ED10000]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
 21378                              <1> 
 21379                              <1> mcfg_read_fat_file_secs_3:
 21380 0000733C C3                  <1> 	retn
 21381                              <1> 
 21382                              <1> 
 21383                              <1> mcfg_read_fs_file_sectors:
 21384 0000733D C3                  <1> 	retn
 21385                              <1> 
 21386                              <1> loc_mcfg_load_fs_file:
 21387 0000733E C3                  <1> 	retn
 21388                              <1> 
 21389                              <1> find_and_list_files:
 21390 0000733F C3                  <1> 	retn
 21391                              <1> set_exec_arguments:
 21392 00007340 C3                  <1> 	retn
 21393                              <1> load_and_execute_file:
 21394 00007341 C3                  <1> 	retn
 21395                              <1> delete_fs_directory:
 21396 00007342 31C0                <1> 	xor	eax, eax
 21397 00007344 C3                  <1> 	retn
 21398                                  %include 'trdosk4.s' ; 24/01/2016
 21399                              <1> ; ****************************************************************************
 21400                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - Directory Functions : trdosk4.s
 21401                              <1> ; ----------------------------------------------------------------------------
 21402                              <1> ; Last Update: 04/04/2016
 21403                              <1> ; ----------------------------------------------------------------------------
 21404                              <1> ; Beginning: 24/01/2016
 21405                              <1> ; ----------------------------------------------------------------------------
 21406                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 21407                              <1> ; ----------------------------------------------------------------------------
 21408                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 21409                              <1> ; DIR.ASM (09/10/2011)
 21410                              <1> ; ****************************************************************************
 21411                              <1> 
 21412                              <1> ; DIR.ASM  [ TRDOS KERNEL - COMMAND EXECUTER SECTION - DIRECTORY FUNCTIONS ]
 21413                              <1> ; (c) 2004-2010  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/10/2011
 21414                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 21415                              <1> 
 21416                              <1> change_prompt_dir_string:
 21417                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 21418                              <1> 	; 27/03/2011
 21419                              <1> 	; 09/10/2009
 21420                              <1> 	; INPUT/OUTPUT => none
 21421                              <1> 	; this procedure changes current directory string/text  
 21422                              <1> 	; 2005
 21423                              <1> 
 21424 00007345 BF[46C50000]        <1> 	mov	edi, Current_Directory
 21425 0000734A 8A25[40C50000]      <1> 	mov	ah, [Current_Dir_Level]
 21426 00007350 BE[A3CD0000]        <1> 	mov	esi, PATH_Array
 21427 00007355 E807000000          <1> 	call	set_current_directory_string
 21428 0000735A 880D[A1C50000]      <1> 	mov	[Current_Dir_StrLen], cl
 21429                              <1> 
 21430 00007360 C3                  <1> 	retn
 21431                              <1> 
 21432                              <1> set_current_directory_string:
 21433                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 21434                              <1> 	; 27/03/2011
 21435                              <1> 	; 09/10/2009
 21436                              <1> 	; INPUT:
 21437                              <1> 	;    ESI = Path Array Address 
 21438                              <1> 	;    EDI = Current Directory String Buffer
 21439                              <1> 	;    AH = Current Directory Level
 21440                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
 21441                              <1> 	;    EDI will be same with input
 21442                              <1> 	;    ECX = Current Directory String Length 
 21443                              <1> 
 21444 00007361 57                  <1> 	push    edi
 21445 00007362 80FC00              <1> 	cmp     ah, 0
 21446 00007365 7652                <1> 	jna	short pass_write_path
 21447 00007367 83C610              <1> 	add	esi, 16
 21448 0000736A 89F3                <1> 	mov	ebx, esi
 21449                              <1> loc_write_path:
 21450 0000736C B908000000          <1> 	mov	ecx, 8
 21451                              <1> path_write_dirname1:
 21452 00007371 AC                  <1> 	lodsb
 21453 00007372 3C20                <1> 	cmp	al, 20h
 21454 00007374 7612                <1> 	jna	short pass_write_dirname1
 21455 00007376 AA                  <1> 	stosb
 21456 00007377 81FF[A0C50000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 21457 0000737D 733A                <1> 	jnb	short pass_write_path
 21458 0000737F E2F0                <1> 	loop	path_write_dirname1
 21459 00007381 803E20              <1> 	cmp	byte [esi], 20h
 21460 00007384 7624                <1> 	jna	short pass_write_dirname2
 21461 00007386 EB0A                <1> 	jmp     short loc_put_dot_cont_ext
 21462                              <1> pass_write_dirname1:
 21463 00007388 89DE                <1> 	mov	esi, ebx
 21464 0000738A 83C608              <1> 	add	esi, 8
 21465 0000738D 803E20              <1> 	cmp	byte [esi], 20h
 21466 00007390 7618                <1> 	jna	short pass_write_dirname2
 21467                              <1> loc_put_dot_cont_ext:
 21468 00007392 C6072E              <1> 	mov	byte [edi], "."
 21469                              <1> 	;mov	ecx, 3
 21470 00007395 B103                <1> 	mov	cl, 3
 21471                              <1> loc_check_dir_name_ext:
 21472 00007397 AC                  <1> 	lodsb
 21473 00007398 47                  <1> 	inc	edi
 21474 00007399 3C20                <1> 	cmp	al, 20h
 21475 0000739B 760D                <1> 	jna	short pass_write_dirname2
 21476 0000739D 8807                <1> 	mov	[edi], al
 21477 0000739F 81FF[A0C50000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 21478 000073A5 7312                <1> 	jnb	short pass_write_path
 21479 000073A7 E2EE                <1> 	loop    loc_check_dir_name_ext
 21480 000073A9 47                  <1> 	inc	edi
 21481                              <1> pass_write_dirname2:
 21482 000073AA FECC                <1> 	dec	ah
 21483 000073AC 740B                <1> 	jz      short pass_write_path
 21484 000073AE 83C310              <1> 	add	ebx, 16
 21485 000073B1 89DE                <1> 	mov	esi, ebx
 21486 000073B3 C6072F              <1> 	mov	byte [edi],"/"
 21487 000073B6 47                  <1> 	inc	edi
 21488 000073B7 EBB3                <1> 	jmp	short loc_write_path
 21489                              <1> pass_write_path:
 21490 000073B9 C60700              <1> 	mov	byte [edi], 0
 21491 000073BC 47                  <1> 	inc	edi
 21492 000073BD 89F9                <1> 	mov	ecx, edi
 21493 000073BF 5F                  <1> 	pop	edi
 21494 000073C0 29F9                <1> 	sub	ecx, edi
 21495                              <1> 	; ECX = Current Directory String Length
 21496 000073C2 C3                  <1> 	retn
 21497                              <1> 
 21498                              <1> get_current_directory:
 21499                              <1> 	; 14/02/2016
 21500                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 21501                              <1> 	; 27/03/2011
 21502                              <1> 	;
 21503                              <1> 	; INPUT-> ESI = Current Directory Buffer
 21504                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
 21505                              <1> 	;              (0= Default/Current Drive)
 21506                              <1> 	;           
 21507                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
 21508                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
 21509                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
 21510                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
 21511                              <1> 	;            CX/CL = Current Directory String Length
 21512                              <1> 	;	     DL = Drive Number (0 based)
 21513                              <1> 	;            (If input is 0, output is current drv number) 
 21514                              <1> 	;            DH = same with input 
 21515                              <1> 	;   cf = 0 -> AL = 0
 21516                              <1> 	;   cf = 1 -> error code in AL 
 21517                              <1>               
 21518                              <1> loc_get_current_drive_0:
 21519 000073C3 80FA00              <1> 	cmp	dl, 0
 21520 000073C6 7708                <1> 	ja	short loc_get_current_drive_1
 21521 000073C8 8A15[42C50000]      <1> 	mov	dl, [Current_Drv]
 21522 000073CE EB17                <1> 	jmp	short loc_get_current_drive_2
 21523                              <1> loc_get_current_drive_1:
 21524 000073D0 FECA                <1> 	dec 	dl
 21525 000073D2 3A15[F5B40000]      <1> 	cmp	dl, [Last_DOS_DiskNo]
 21526 000073D8 760D                <1> 	jna	short loc_get_current_drive_2
 21527 000073DA B80F000000          <1> 	mov	eax, 0Fh ; Invalid drive
 21528 000073DF F5                  <1> 	cmc 	; stc
 21529 000073E0 C3                  <1> 	retn
 21530                              <1> 
 21531                              <1> loc_get_current_drive_not_ready_retn:
 21532 000073E1 5E                  <1> 	pop	esi
 21533                              <1> 	;mov	eax, 15h
 21534 000073E2 66B81500            <1> 	mov	ax, 15h ; Drive not ready
 21535 000073E6 C3                  <1> 	retn  
 21536                              <1>  
 21537                              <1> loc_get_current_drive_2:
 21538 000073E7 31C0                <1> 	xor	eax, eax
 21539 000073E9 88D4                <1> 	mov	ah, dl
 21540 000073EB 56                  <1> 	push	esi
 21541 000073EC BE00010900          <1> 	mov	esi, Logical_DOSDisks
 21542 000073F1 01C6                <1> 	add	esi, eax
 21543 000073F3 8A06                <1> 	mov	al, [esi+LD_Name] 
 21544 000073F5 3C41                <1> 	cmp	al, 'A'
 21545 000073F7 72E8                <1> 	jb	short loc_get_current_drive_not_ready_retn
 21546                              <1> 
 21547 000073F9 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 21548 000073FC 08E4                <1> 	or	ah, ah
 21549 000073FE 7506                <1> 	jnz	short loc_get_current_drive_3
 21550                              <1> 
 21551                              <1> 	;xor	ah, ah ; mov ah, 0
 21552 00007400 8826                <1> 	mov	[esi], ah
 21553 00007402 31C9                <1> 	xor	ecx, ecx
 21554 00007404 EB1C                <1> 	jmp	short loc_get_current_drive_4
 21555                              <1> 
 21556                              <1> loc_get_current_drive_3:
 21557 00007406 BF[A3CD0000]        <1>         mov     edi, PATH_Array
 21558 0000740B 57                  <1> 	push	edi
 21559 0000740C 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 21560 00007412 B920000000          <1> 	mov	ecx, 32
 21561 00007417 F3A5                <1> 	rep	movsd
 21562 00007419 5E                  <1> 	pop	esi ; Path Array Address
 21563 0000741A 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset) 
 21564                              <1> 	;
 21565 0000741B E841FFFFFF          <1> 	call	set_current_directory_string
 21566 00007420 89FE                <1> 	mov	esi, edi
 21567                              <1> 
 21568                              <1> loc_get_current_drive_4:
 21569 00007422 30C0                <1> 	xor	al, al
 21570 00007424 C3                  <1> 	retn
 21571                              <1> 
 21572                              <1> change_current_directory:
 21573                              <1> 	; 19/02/2016
 21574                              <1> 	; 11/02/2016
 21575                              <1> 	; 10/02/2016
 21576                              <1> 	; 08/02/2016
 21577                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 21578                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)	
 21579                              <1> 	; 04/10/2009
 21580                              <1> 	; 2005
 21581                              <1> 	; INPUT -> 
 21582                              <1> 	;	ESI = Directory string
 21583                              <1> 	;	ah = CD command (CDh = save current dir string)
 21584                              <1> 	; OUTPUT -> 
 21585                              <1> 	; 	EDI = DOS Drive Description Table
 21586                              <1> 	; 	cf = 1 -> error
 21587                              <1> 	;	   EAX = Error code
 21588                              <1> 	;	cf = 0 -> succesful
 21589                              <1> 	;	   ESI = PATH_Array
 21590                              <1> 	;	   EAX = Current Directory First Cluster
 21591                              <1> 	;
 21592                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 21593                              <1> 	
 21594 00007425 8825[31CE0000]      <1> 	mov	[CD_COMMAND], ah
 21595 0000742B 803E2F              <1> 	cmp	byte [esi], '/'
 21596 0000742E 7505                <1> 	jne	short loc_ccd_cdir_level
 21597 00007430 46                  <1> 	inc	esi
 21598 00007431 30C0                <1> 	xor	al, al
 21599 00007433 EB05                <1> 	jmp	short loc_ccd_parse_path_name
 21600                              <1> loc_ccd_cdir_level:
 21601 00007435 A0[40C50000]        <1> 	mov	al, [Current_Dir_Level]
 21602                              <1> loc_ccd_parse_path_name:
 21603 0000743A 88C4                <1> 	mov	ah, al
 21604 0000743C BF[A3CD0000]        <1> 	mov	edi, PATH_Array
 21605                              <1> 
 21606                              <1> ; Reset directory levels > cdir level
 21607                              <1> 	; is this required !?
 21608                              <1> 	;
 21609                              <1> 	; Relations:
 21610                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
 21611                              <1> 	; proc_parse_dir_name,
 21612                              <1> 	; proc_change_current_directory (this procedure)
 21613                              <1> 	; proc_change_prompt_dir_string 
 21614                              <1>  
 21615 00007441 0FB6C8              <1> 	movzx	ecx, al
 21616 00007444 FEC1                <1> 	inc	cl
 21617 00007446 C0E104              <1> 	shl	cl, 4
 21618 00007449 01CF                <1> 	add	edi, ecx
 21619 0000744B B107                <1> 	mov	cl, 7
 21620 0000744D 28C1                <1> 	sub	cl, al
 21621 0000744F C0E102              <1> 	shl	cl, 2
 21622 00007452 89C3                <1> 	mov	ebx, eax
 21623 00007454 31C0                <1> 	xor	eax, eax ; 0
 21624 00007456 F3AB                <1> 	rep	stosd
 21625 00007458 89D8                <1> 	mov	eax, ebx
 21626                              <1> 
 21627 0000745A BF[A3CD0000]        <1> 	mov	edi, PATH_Array
 21628                              <1> 
 21629 0000745F 803E20              <1> 	cmp	byte [esi], 20h
 21630 00007462 F5                  <1> 	cmc
 21631 00007463 7305                <1> 	jnc	short pass_ccd_parse_dir_name
 21632                              <1> 
 21633                              <1> 		; ESI = Path name
 21634                              <1> 		; AL = CCD_Level
 21635 00007465 E872010000          <1>         call    parse_dir_name
 21636                              <1> 		; AL = CCD_Level 
 21637                              <1> 		; AH = Last_Dir_Level
 21638                              <1> 		; (EDI = PATH_Array)
 21639                              <1> 
 21640                              <1> pass_ccd_parse_dir_name:
 21641 0000746A 9C                  <1> 	pushf
 21642                              <1> 
 21643                              <1> 	;mov	[CCD_Level], al
 21644                              <1>         ;mov	[Last_Dir_Level], ah
 21645 0000746B 66A3[27CE0000]      <1> 	mov	[CCD_Level], ax
 21646                              <1> 
 21647 00007471 31DB                <1> 	xor	ebx, ebx
 21648 00007473 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 21649 00007479 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 21650 0000747E 01DE                <1> 	add	esi, ebx
 21651                              <1> 
 21652 00007480 9D                  <1> 	popf 
 21653 00007481 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
 21654                              <1> 
 21655 00007483 8935[23CE0000]      <1> 	mov	[CCD_DriveDT], esi
 21656                              <1> 
 21657 00007489 3C07                <1> 	cmp	al, 7
 21658 0000748B 7209                <1> 	jb	short loc_ccd_load_child_dir
 21659                              <1> 
 21660                              <1> loc_ccd_bad_path_name_retn:
 21661 0000748D 87F7                <1> 	xchg	esi, edi
 21662                              <1> 	; DOS Error Code 
 21663 0000748F B818000000          <1> 	mov	eax, 18h ; Bad request structure length 
 21664 00007494 F9                  <1> 	stc
 21665                              <1> loc_ccd_retn_p:
 21666 00007495 C3                  <1> 	retn
 21667                              <1> 
 21668                              <1> loc_ccd_load_child_dir:
 21669                              <1> 	; AL = CCD_Level
 21670 00007496 08C0                <1> 	or	al, al
 21671 00007498 7468                <1> 	jz	short loc_ccd_load_root_dir
 21672                              <1> 
 21673 0000749A 6689C1              <1> 	mov	cx, ax
 21674 0000749D C0E004              <1> 	shl	al, 4
 21675 000074A0 0FB6F0              <1> 	movzx	esi, al
 21676 000074A3 01FE                <1>      	add	esi, edi  ; offset PATH_Array
 21677                              <1> 
 21678 000074A5 8B460C              <1> 	mov	eax, [esi+12]
 21679 000074A8 38E9                <1> 	cmp	cl, ch
 21680 000074AA 0F84FA000000        <1>         je      loc_ccd_load_sub_directory
 21681 000074B0 A3[3CC50000]        <1> 	mov	[Current_Dir_FCluster], eax
 21682                              <1> 
 21683                              <1> loc_ccd_load_child_dir_next:
 21684 000074B5 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
 21685                              <1> 
 21686                              <1>  	; Directory attribute : 10h
 21687 000074B8 B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
 21688                              <1> 	;mov	ah, 11001000b ; C8h
 21689                              <1> 	; Volume name attribute: 8h
 21690 000074BA B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
 21691                              <1> 
 21692 000074BC 6631C9              <1> 	xor	cx, cx  
 21693 000074BF E8B5010000          <1> 	call	locate_current_dir_file
 21694 000074C4 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
 21695                              <1> 
 21696                              <1> 	 ; 19/02/2016
 21697                              <1> 	;mov	edi, [CCD_DriveDT]
 21698 000074C6 8A25[27CE0000]      <1> 	mov	ah, [CCD_Level]
 21699 000074CC 803D[31CE0000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 21700 000074D3 7509                <1> 	jne	short loc_ccd_load_child_dir_err
 21701                              <1> 	; It is better to save recent successful part 
 21702                              <1> 	; of the (requested) path as current directory.
 21703                              <1> 	; (Otherwise the path would be reset to back
 21704                              <1> 	; on the next 'CD' command.)
 21705 000074D5 88E1                <1> 	mov	cl, ah
 21706 000074D7 50                  <1> 	push	eax
 21707 000074D8 E8E3000000          <1> 	call	loc_ccd_save_current_dir
 21708 000074DD 58                  <1> 	pop	eax
 21709                              <1> loc_ccd_load_child_dir_err:            
 21710 000074DE 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
 21711 000074E0 7202                <1> 	jb	short loc_ccd_path_not_found_retn
 21712 000074E2 F9                  <1> 	stc
 21713 000074E3 C3                  <1> 	retn
 21714                              <1> 
 21715                              <1> loc_ccd_path_not_found_retn:
 21716 000074E4 B003                <1> 	mov	al, 3	; Path not found
 21717 000074E6 C3                  <1> 	retn
 21718                              <1> 
 21719                              <1> loc_ccd_load_FAT_root_dir:
 21720 000074E7 803D[41C50000]02    <1> 	cmp	byte [Current_FATType], 2
 21721 000074EE 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
 21722                              <1> 
 21723                              <1> 	;mov	esi, [CCD_DriveDT]
 21724                              <1> 	;push	esi
 21725 000074F0 E8961D0000          <1> 	call	load_FAT_root_directory
 21726                              <1> 	;pop	edi ; Dos Drv Description Table
 21727                              <1> 
 21728 000074F5 89F7                <1> 	mov	edi, esi
 21729 000074F7 BE[A3CD0000]        <1> 	mov	esi, PATH_Array
 21730 000074FC 7297                <1> 	jc	short loc_ccd_retn_p
 21731                              <1> 
 21732 000074FE 31C0                <1> 	xor	eax, eax
 21733 00007500 EB78                <1>         jmp	short loc_ccd_set_cdfc
 21734                              <1> 
 21735                              <1> loc_ccd_load_root_dir:
 21736 00007502 803D[41C50000]01    <1> 	cmp	byte [Current_FATType], 1
 21737 00007509 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
 21738                              <1> 
 21739                              <1> loc_ccd_load_FS_root_dir:
 21740 0000750B E8421E0000          <1> 	call	load_FS_root_directory
 21741 00007510 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
 21742                              <1> 
 21743                              <1> loc_ccd_load_FS_sub_directory_next:
 21744 00007512 E83C1E0000          <1> 	call	load_FS_sub_directory
 21745 00007517 EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr  
 21746                              <1> 
 21747                              <1> loc_ccd_set_dir_cluster_ptr:
 21748                              <1> 	; EDI = Directory Entry
 21749 00007519 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 21750 0000751D C1E010              <1> 	shl	eax, 16
 21751 00007520 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 21752                              <1> 
 21753 00007524 8B35[23CE0000]      <1> 	mov	esi, [CCD_DriveDT]
 21754 0000752A 803D[41C50000]01    <1> 	cmp	byte [Current_FATType], 1
 21755 00007531 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
 21756                              <1> 	;push	esi
 21757 00007533 E8DE1D0000          <1> 	call	load_FAT_sub_directory
 21758                              <1> 	;pop	edi ; Dos Drv Description Table
 21759                              <1> 
 21760                              <1> pass_ccd_set_dir_cluster_ptr:
 21761                              <1> 	;mov	edi, esi
 21762 00007538 BE[A3CD0000]        <1> 	mov	esi, PATH_Array
 21763 0000753D 7264                <1> 	jc	short loc_ccd_retn_c
 21764                              <1> 
 21765 0000753F A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 21766                              <1> 
 21767 00007544 FE05[27CE0000]      <1> 	inc	byte [CCD_Level]
 21768 0000754A 0FB61D[27CE0000]    <1> 	movzx	ebx, byte [CCD_Level]
 21769 00007551 C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)   
 21770 00007554 01DE                <1> 	add	esi, ebx ; 19/02/2016
 21771 00007556 89460C              <1> 	mov	[esi+12], eax
 21772 00007559 EB1F                <1> 	jmp	short loc_ccd_set_cdfc
 21773                              <1> 
 21774                              <1> loc_ccd_load_FAT32_root_dir:
 21775 0000755B BE[A3CD0000]        <1> 	mov	esi, PATH_Array
 21776 00007560 8B460C              <1> 	mov	eax, [esi+12]
 21777 00007563 8B35[23CE0000]      <1> 	mov	esi, [CCD_DriveDT]
 21778                              <1>  
 21779                              <1> loc_ccd_load_FAT_sub_directory:
 21780                              <1> 	;push	esi
 21781 00007569 E8A81D0000          <1> 	call	load_FAT_sub_directory
 21782                              <1> 	;pop	edi ; Dos Drv Description Table
 21783                              <1> 
 21784                              <1> pass_ccd_load_FAT_sub_directory:
 21785                              <1> 	;mov	edi, esi
 21786 0000756E BE[A3CD0000]        <1> 	mov	esi, PATH_Array
 21787 00007573 722E                <1> 	jc	short loc_ccd_retn_c
 21788                              <1> 
 21789 00007575 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 21790                              <1> 
 21791                              <1> loc_ccd_set_cdfc:
 21792 0000757A 8A0D[27CE0000]      <1> 	mov	cl, [CCD_Level]
 21793 00007580 880D[40C50000]      <1> 	mov	[Current_Dir_Level], cl
 21794 00007586 A3[3CC50000]        <1> 	mov	[Current_Dir_FCluster], eax
 21795                              <1> 
 21796 0000758B 8A2D[28CE0000]      <1> 	mov	ch, [Last_Dir_Level]
 21797 00007591 38E9                <1> 	cmp	cl, ch 
 21798 00007593 0F821CFFFFFF        <1> 	jb	loc_ccd_load_child_dir_next
 21799                              <1> 	
 21800 00007599 803D[31CE0000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 21801 000075A0 741E                <1> 	je	short loc_ccd_save_current_dir
 21802                              <1> 
 21803                              <1>         ; jne -> don't save, restore (the previous cdir) later !
 21804                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
 21805                              <1> 
 21806 000075A2 F8                  <1> 	clc
 21807                              <1> 
 21808                              <1> loc_ccd_retn_c:
 21809 000075A3 8B3D[23CE0000]      <1> 	mov	edi, [CCD_DriveDT]
 21810 000075A9 C3                  <1> 	retn
 21811                              <1> 
 21812                              <1> loc_ccd_load_sub_directory:
 21813 000075AA 8B35[23CE0000]      <1> 	mov	esi, [CCD_DriveDT]
 21814 000075B0 803D[41C50000]01    <1> 	cmp	byte [Current_FATType], 1
 21815 000075B7 73B0                <1> 	jnb	short loc_ccd_load_FAT_sub_directory 
 21816 000075B9 E8951D0000          <1> 	call	load_FS_sub_directory
 21817 000075BE EBAE                <1> 	jmp	short pass_ccd_load_FAT_sub_directory 
 21818                              <1> 
 21819                              <1> loc_ccd_save_current_dir:
 21820 000075C0 BE[A3CD0000]        <1> 	mov	esi, PATH_Array ; 19/02/2016
 21821 000075C5 8B3D[23CE0000]      <1> 	mov	edi, [CCD_DriveDT]
 21822 000075CB 57                  <1> 	push	edi
 21823 000075CC 83C77F              <1>         add     edi, LD_CDirLevel
 21824 000075CF 880F                <1> 	mov	[edi], cl
 21825 000075D1 47                  <1> 	inc	edi ; LD_CurrentDirectory 
 21826 000075D2 56                  <1> 	push	esi
 21827                              <1> 	;mov	ecx, 32  ; always < 65536 (in this procedure)
 21828 000075D3 66B92000            <1> 	mov	cx, 32
 21829 000075D7 F3A5                <1> 	rep	movsd
 21830                              <1> 	; Current directory has been saved to 
 21831                              <1> 	; the DOS drive description table, cdir area !
 21832 000075D9 5E                  <1> 	pop	esi  ; PATH_Array
 21833 000075DA 5F                  <1> 	pop	edi  ; Dos Drv Description Table
 21834                              <1> 
 21835 000075DB C3                  <1> 	retn
 21836                              <1> 
 21837                              <1> parse_dir_name:
 21838                              <1> 	; 11/02/2016
 21839                              <1> 	; 10/02/2016
 21840                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 21841                              <1> 	; 18/09/2011
 21842                              <1> 	; 17/10/2009
 21843                              <1> 	; INPUT ->
 21844                              <1> 	;	ESI = ASCIIZ Directory String Address
 21845                              <1> 	;	AL = Current Directory Level
 21846                              <1> 	;	EDI = Destination Adress
 21847                              <1> 	;	     (8 levels, each one 12+4 byte)
 21848                              <1> 	; OUTPUT ->
 21849                              <1> 	;	EDI = Dir Entry Formatted Array
 21850                              <1> 	;	     with zero cluster pointer at the last level
 21851                              <1> 	;	AH = Last Dir Level
 21852                              <1> 	;	AL = Current Dir Level
 21853                              <1> 	;
 21854                              <1> 	; (esi, ebx, ecx will be changed) 
 21855                              <1> 
 21856                              <1> 	;mov	[PATH_Array_Ptr], edi
 21857 000075DC 88C4                <1> 	mov	ah, al
 21858 000075DE 66A3[C8CE0000]      <1> 	mov	[PATH_CDLevel], ax
 21859                              <1> repeat_ppdn_check_slash:
 21860 000075E4 AC                  <1> 	lodsb
 21861 000075E5 3C2F                <1> 	cmp	al, '/'
 21862 000075E7 74FB                <1> 	je	short repeat_ppdn_check_slash
 21863 000075E9 3C21                <1> 	cmp	al, 21h
 21864 000075EB 7219                <1> 	jb	short loc_ppdn_retn
 21865 000075ED 57                  <1> 	push	edi
 21866                              <1> loc_ppdn_get_dir_name:
 21867 000075EE B90C000000          <1> 	mov	ecx, 12
 21868 000075F3 BF[CACE0000]        <1> 	mov	edi, Dir_File_Name
 21869                              <1> repeat_ppdn_get_dir_name:
 21870 000075F8 AA                  <1> 	stosb
 21871 000075F9 AC                  <1> 	lodsb
 21872 000075FA 3C2F                <1> 	cmp	al, '/'
 21873 000075FC 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
 21874 000075FE 3C20                <1> 	cmp	al, 20h
 21875 00007600 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
 21876 00007602 E2F4                <1> 	loop	repeat_ppdn_get_dir_name
 21877 00007604 5F                  <1> 	pop	edi
 21878 00007605 F9                  <1> 	stc
 21879                              <1> loc_ppdn_retn:
 21880 00007606 C3                  <1> 	retn
 21881                              <1> 
 21882                              <1> loc_ppdn_end_of_path_scan:
 21883 00007607 4E                  <1> 	dec	esi
 21884                              <1> loc_check_level_dot_conv_dir_name:
 21885 00007608 31C0                <1> 	xor	eax, eax
 21886 0000760A AA                  <1> 	stosb
 21887 0000760B 89F3                <1> 	mov	ebx, esi
 21888 0000760D BE[CACE0000]        <1> 	mov	esi, Dir_File_Name
 21889 00007612 AC                  <1> 	lodsb
 21890                              <1> repeat_ppdn_name_check_dot:
 21891 00007613 3C2E                <1> 	cmp	al, '.'
 21892 00007615 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
 21893                              <1> repeat_ppdn_name_dot_dot:
 21894 00007617 AC                  <1> 	lodsb
 21895 00007618 3C2E                <1> 	cmp	al, '.'
 21896 0000761A 743E                <1> 	je	short loc_ppdn_dot_dot
 21897 0000761C 3C21                <1> 	cmp	al, 21h
 21898 0000761E 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
 21899                              <1> loc_ppdn_convert_sub_dir_name:
 21900 00007620 8A25[C9CE0000]      <1> 	mov	ah, [PATH_Level]
 21901 00007626 80FC07              <1> 	cmp	ah, 7
 21902 00007629 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
 21903 0000762B FEC4                <1> 	inc	ah  
 21904 0000762D 8825[C9CE0000]      <1> 	mov	[PATH_Level], ah
 21905 00007633 BE[CACE0000]        <1> 	mov	esi, Dir_File_Name
 21906                              <1> 	;mov	edi, [PATH_Array_Ptr]
 21907 00007638 B010                <1> 	mov	al, 16
 21908 0000763A F6E4                <1> 	mul	ah
 21909 0000763C 8B3C24              <1> 	mov	edi, [esp]
 21910                              <1> 	;push	edi 
 21911 0000763F 01C7                <1> 	add	edi, eax
 21912 00007641 E828030000          <1> 	call	convert_file_name
 21913                              <1> 	;pop	edi
 21914                              <1> pass_ppdn_convert_sub_dir_name:
 21915 00007646 89DE                <1> 	mov	esi, ebx
 21916                              <1> repeat_ppdn_check_last_slash:
 21917 00007648 AC                  <1> 	lodsb
 21918 00007649 3C2F                <1> 	cmp	al, '/'
 21919 0000764B 74FB                <1> 	je	short repeat_ppdn_check_last_slash
 21920 0000764D 3C21                <1> 	cmp	al, 21h
 21921 0000764F 739D                <1> 	jnb	short loc_ppdn_get_dir_name
 21922                              <1> end_of_parse_dir_name:
 21923 00007651 5F                  <1> 	pop	edi
 21924 00007652 F5                  <1> 	cmc  
 21925                              <1> 	;mov	al, [PATH_CDLevel]
 21926                              <1> 	;mov	ah, [PATH_Level]
 21927 00007653 66A1[C8CE0000]      <1> 	mov	ax, [PATH_CDLevel]
 21928 00007659 C3                  <1> 	retn
 21929                              <1> 
 21930                              <1> loc_ppdn_dot_dot:
 21931 0000765A AC                  <1> 	lodsb
 21932 0000765B 3C21                <1> 	cmp	al, 21h
 21933 0000765D 73F2                <1> 	jnb	short end_of_parse_dir_name 
 21934                              <1> loc_ppdn_dot_dot_prev_level:
 21935 0000765F 66A1[C8CE0000]      <1> 	mov	ax, [PATH_CDLevel]
 21936 00007665 80EC01              <1> 	sub	ah, 1
 21937 00007668 80D400              <1> 	adc	ah, 0
 21938 0000766B 38E0                <1> 	cmp	al, ah
 21939 0000766D 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
 21940 0000766F 88E0                <1> 	mov	al, ah
 21941                              <1> pass_ppdn_set_al_to_ah:
 21942 00007671 66A3[C8CE0000]      <1> 	mov	[PATH_CDLevel], ax
 21943 00007677 EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
 21944                              <1> 
 21945                              <1> locate_current_dir_file:
 21946                              <1> 	; 14/02/2016
 21947                              <1> 	; 13/02/2016
 21948                              <1> 	; 10/02/2016
 21949                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 21950                              <1> 	; 14/08/2010
 21951                              <1> 	; 19/09/2009
 21952                              <1>         ; 2005
 21953                              <1> 	; INPUT ->
 21954                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 21955                              <1> 	;	AL = Attributes Mask 
 21956                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 21957                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 21958                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 21959                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 21960                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 21961                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 21962                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 21963                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 21964                              <1> 	;	     proper entry (which fits with Atributes Masks)
 21965                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
 21966                              <1> 	;	? = Any One Char
 21967                              <1> 	;	* = Every Chars
 21968                              <1> 	; OUTPUT ->
 21969                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
 21970                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 21971                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 21972                              <1> 	;	DL = Attributes
 21973                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 21974                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 21975                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 21976                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 21977                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 21978                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
 21979                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 21980                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 21981                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 21982                              <1> 	;	CF = 0 -> 
 21983                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
 21984                              <1> 
 21985                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
 21986                              <1> 
 21987 00007679 8935[2BCE0000]      <1> 	mov	[CDLF_FNAddress], esi
 21988 0000767F 66A3[29CE0000]      <1> 	mov	[CDLF_AttributesMask], ax
 21989 00007685 66890D[2FCE0000]    <1> 	mov	[CDLF_DEType], cx
 21990                              <1> 
 21991 0000768C 31DB                <1> 	xor	ebx, ebx
 21992 0000768E 881D[40CE0000]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
 21993                              <1> 
 21994 00007694 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 21995 0000769A 381D[6CCD0000]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
 21996 000076A0 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
 21997 000076A2 8A1D[6ACD0000]      <1>         mov     bl, [DirBuff_DRV]
 21998 000076A8 80EB41              <1> 	sub	bl, 'A'
 21999 000076AB 38DF                <1> 	cmp	bh, bl
 22000 000076AD 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
 22001 000076AF 8B15[71CD0000]      <1> 	mov	edx, [DirBuff_Cluster]
 22002 000076B5 3B15[3CC50000]      <1> 	cmp	edx, [Current_Dir_FCluster]
 22003 000076BB 7412                <1> 	je	short loc_cdir_locatefile_search
 22004                              <1> 
 22005                              <1> loc_lcdf_reload_current_dir1:
 22006 000076BD 30DB                <1> 	xor	bl, bl
 22007                              <1> loc_lcdf_reload_current_dir2:
 22008 000076BF 89DE                <1> 	mov	esi, ebx
 22009 000076C1 81C600010900        <1>         add     esi, Logical_DOSDisks
 22010 000076C7 E872000000          <1> 	call	reload_current_directory 
 22011 000076CC 735B                <1> 	jnc	short loc_locatefile_search_again 
 22012 000076CE C3                  <1> 	retn  
 22013                              <1> 
 22014                              <1> loc_cdir_locatefile_search:
 22015 000076CF 31DB                <1> 	xor	ebx, ebx
 22016 000076D1 E8A5000000          <1> 	call	find_directory_entry
 22017 000076D6 7349                <1> 	jnc	short loc_cdir_locate_file_retn
 22018                              <1> 
 22019                              <1> loc_locatefile_check_stc_reason:
 22020 000076D8 08ED                <1> 	or	ch, ch
 22021 000076DA 7444                <1> 	jz	short loc_cdir_locate_file_stc_retn
 22022                              <1> 
 22023                              <1> loc_locatefile_check_next_entryblock:
 22024 000076DC 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 22025 000076E2 28DB                <1> 	sub	bl, bl
 22026 000076E4 0FB7F3              <1> 	movzx	esi, bx
 22027 000076E7 81C600010900        <1>         add     esi, Logical_DOSDisks
 22028                              <1> 
 22029 000076ED 803D[40C50000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 22030 000076F4 760A                <1> 	jna	short loc_locatefile_check_FAT_type
 22031                              <1>             
 22032 000076F6 803D[41C50000]01    <1> 	cmp	byte [Current_FATType], 1
 22033 000076FD 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
 22034 000076FF C3                  <1> 	retn  
 22035                              <1> 
 22036                              <1> loc_locatefile_check_FAT_type:
 22037 00007700 803D[41C50000]03    <1> 	cmp	byte [Current_FATType], 3
 22038 00007707 7218                <1> 	jb	short loc_cdir_locate_file_retn
 22039                              <1> 
 22040                              <1> loc_locatefile_load_subdir_cluster:
 22041 00007709 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 22042 0000770E E81D1A0000          <1> 	call	get_next_cluster
 22043 00007713 730D                <1> 	jnc	short loc_locatefile_next_cluster
 22044 00007715 09C0                <1> 	or	eax, eax
 22045 00007717 7507                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
 22046 00007719 F9                  <1> 	stc
 22047                              <1> loc_locatefile_file_notfound:
 22048 0000771A B802000000          <1> 	mov	eax, 2 ; File/Directory/VolName not found
 22049 0000771F C3                  <1> 	retn
 22050                              <1> 
 22051                              <1> loc_locatefile_drive_not_ready_read_err:
 22052                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 22053                              <1> loc_cdir_locate_file_stc_retn:
 22054 00007720 F5                  <1> 	cmc ;stc
 22055                              <1> loc_cdir_locate_file_retn:
 22056 00007721 C3                  <1> 	retn
 22057                              <1> 
 22058                              <1> loc_locatefile_next_cluster:
 22059 00007722 E8EF1B0000          <1> 	call	load_FAT_sub_directory
 22060                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
 22061 00007727 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
 22062                              <1> 
 22063                              <1> loc_locatefile_search_again:
 22064 00007729 8B35[2BCE0000]      <1> 	mov	esi, [CDLF_FNAddress] 
 22065 0000772F 66A1[29CE0000]      <1> 	mov	ax, [CDLF_AttributesMask]
 22066 00007735 668B0D[2FCE0000]    <1> 	mov	cx, [CDLF_DEType] 
 22067 0000773C EB91                <1> 	jmp	short loc_cdir_locatefile_search
 22068                              <1> 
 22069                              <1> reload_current_directory:
 22070                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 22071                              <1> 	; 13/06/2010
 22072                              <1> 	; 22/09/2009
 22073                              <1>         ;
 22074                              <1> 	; INPUT ->
 22075                              <1> 	;	ESI = Dos drive description table address
 22076                              <1> 	
 22077                              <1> 	;mov	al, [esi+LD_FATType]
 22078 0000773E A0[41C50000]        <1> 	mov	al, [Current_FATType]
 22079 00007743 3C02                <1> 	cmp	al, 2
 22080 00007745 7729                <1> 	ja	short loc_reload_FAT_sub_directory
 22081 00007747 8A25[40C50000]      <1> 	mov	ah, [Current_Dir_Level]
 22082 0000774D 08C0                <1> 	or	al, al
 22083 0000774F 740A                <1> 	jz	short loc_reload_FS_directory
 22084 00007751 08E4                <1> 	or	ah, ah
 22085 00007753 751B                <1> 	jnz	short loc_reload_FAT_sub_directory
 22086                              <1> loc_reload_FAT_12_16_root_directory:
 22087 00007755 E8311B0000          <1> 	call	load_FAT_root_directory
 22088 0000775A C3                  <1> 	retn
 22089                              <1> loc_reload_FS_directory:
 22090 0000775B 20E4                <1> 	and	ah, ah
 22091 0000775D 7506                <1> 	jnz	short loc_reload_FS_sub_directory 
 22092                              <1> loc_reload_FS_root_directory: 
 22093 0000775F E8EE1B0000          <1> 	call	load_FS_root_directory
 22094 00007764 C3                  <1> 	retn
 22095                              <1> loc_reload_FS_sub_directory:
 22096 00007765 A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster]
 22097 0000776A E8E41B0000          <1> 	call	load_FS_sub_directory
 22098 0000776F C3                  <1> 	retn 
 22099                              <1> loc_reload_FAT_sub_directory:
 22100 00007770 A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster]
 22101 00007775 E89C1B0000          <1> 	call	load_FAT_sub_directory
 22102 0000777A C3                  <1> 	retn
 22103                              <1> 
 22104                              <1> find_directory_entry:
 22105                              <1> 	; 14/02/2016
 22106                              <1> 	; 13/02/2016
 22107                              <1> 	; 10/02/2016
 22108                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 22109                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
 22110                              <1> 	; 19/09/2009
 22111                              <1> 	; 2005
 22112                              <1> 	; INPUT ->
 22113                              <1> 	;	ESI = Sub Dir or File Name Address
 22114                              <1> 	;	AL = Attributes Mask 
 22115                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 22116                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 22117                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 22118                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 22119                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 22120                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 22121                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 22122                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 22123                              <1> 	;            proper entry (which fits with Atributes Masks)
 22124                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
 22125                              <1> 	;	? = Any One Char
 22126                              <1> 	;	* = Every Chars
 22127                              <1> 	;	EBX = Current Dir Entry (BX)
 22128                              <1> 	;
 22129                              <1> 	; OUTPUT -> 
 22130                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
 22131                              <1> 	;	ESI = Sub Dir or File Name Address
 22132                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 22133                              <1> 	;	DL = Attributes
 22134                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 22135                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 22136                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 22137                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 22138                              <1> 	;	EBX = CurrentDirEntry (BX)
 22139                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 22140                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
 22141                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 22142                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 22143                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 22144                              <1> 	;
 22145                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)	 
 22146                              <1> 
 22147 0000777B 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 22148 00007782 0F8739010000        <1>         ja      loc_ffde_stc_retn_255
 22149                              <1> 
 22150                              <1> 	;mov    [DirBuff_CurrentEntry], bx  
 22151                              <1> 
 22152 00007788 BF00000800          <1>   	mov	edi, Directory_Buffer
 22153 0000778D 66A3[3CCE0000]      <1> 	mov	[FDE_AttrMask], ax
 22154                              <1> 
 22155 00007793 29C0                <1> 	sub	eax, eax
 22156                              <1>             
 22157                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
 22158 00007795 66A3[3ECE0000]      <1> 	mov	[AmbiguousFileName], ax ; 0
 22159                              <1> 
 22160 0000779B 6689D8              <1> 	mov	ax, bx
 22161 0000779E 66C1E005            <1> 	shl	ax, 5 ; ; * 32 ; Directory entry size
 22162 000077A2 01C7                <1> 	add     edi, eax
 22163                              <1> 
 22164 000077A4 08ED                <1> 	or	ch, ch
 22165 000077A6 0F852C010000        <1>         jnz     loc_find_free_deleted_entry_0
 22166                              <1> 
 22167 000077AC 08C9                <1> 	or      cl, cl
 22168 000077AE 0F850D010000        <1>         jnz     loc_ffde_stc_retn_255
 22169                              <1>  
 22170                              <1> check_find_dir_entry:
 22171 000077B4 66A1[3CCE0000]      <1> 	mov	ax, [FDE_AttrMask]
 22172 000077BA 8A2F                <1> 	mov	ch, [edi]
 22173 000077BC 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
 22174 000077BF 0F86FF000000        <1> 	jna	loc_find_direntry_stc_retn 
 22175 000077C5 56                  <1> 	push	esi
 22176 000077C6 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 22177 000077C9 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
 22178 000077CC 746D                <1> 	je	short loc_find_dir_next_entry_prevdeleted
 22179                              <1> 
 22180 000077CE 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
 22181 000077D1 7505                <1> 	jne     short loc_check_attributes_mask
 22182 000077D3 E8ED010000          <1> 	call	save_longname_sub_component
 22183                              <1> 
 22184                              <1> loc_check_attributes_mask:
 22185 000077D8 88C6                <1> 	mov	dh, al
 22186 000077DA 20D6                <1> 	and	dh, dl    
 22187 000077DC 38F0                <1> 	cmp	al, dh
 22188 000077DE 0F85BA000000        <1>         jne     loc_find_dir_next_entry
 22189 000077E4 20D4                <1> 	and	ah, dl
 22190 000077E6 0F85B2000000        <1>         jnz     loc_find_dir_next_entry
 22191 000077EC 80FA0F              <1> 	cmp	dl, 0Fh
 22192 000077EF 751A                <1> 	jne	short pass_direntry_attr_check
 22193                              <1> 
 22194 000077F1 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
 22195 000077F3 0F85A5000000        <1>         jne     loc_find_dir_next_entry
 22196                              <1> 
 22197 000077F9 5E                  <1> 	pop	esi
 22198 000077FA 6631C0              <1> 	xor	ax, ax
 22199 000077FD 8A35[40CE0000]      <1> 	mov	dh, [PreviousAttr]
 22200 00007803 66891D[6DCD0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 22201 0000780A C3                  <1> 	retn
 22202                              <1> 
 22203                              <1> pass_direntry_attr_check:
 22204 0000780B 89FD                <1> 	mov	ebp, edi ; 14/02/2016
 22205 0000780D B908000000          <1> 	mov	ecx, 8
 22206                              <1> loc_lodsb_find_dir:
 22207 00007812 AC                  <1> 	lodsb
 22208 00007813 3C2A                <1> 	cmp	al, '*'
 22209 00007815 7508                <1> 	jne	short pass_fde_ambiguous1_check
 22210 00007817 FE05[3FCE0000]      <1>         inc     byte [AmbiguousFileName+1]
 22211 0000781D EB28                <1> 	jmp	short loc_check_direntry_extension
 22212                              <1> 
 22213                              <1> pass_fde_ambiguous1_check:
 22214 0000781F 3C3F                <1> 	cmp	al, '?'
 22215 00007821 750D                <1> 	jne	short pass_fde_ambiguous2_check
 22216 00007823 FE05[3ECE0000]      <1> 	inc	byte [AmbiguousFileName]
 22217 00007829 803F20              <1> 	cmp	byte [edi], 20h
 22218 0000782C 764E                <1> 	jna	short loc_find_dir_next_entry_ebp
 22219 0000782E EB14                <1> 	jmp	short loc_scasb_find_dir_inc_di
 22220                              <1> 
 22221                              <1> pass_fde_ambiguous2_check:
 22222 00007830 3C20                <1> 	cmp	al, 20h
 22223 00007832 750C                <1> 	jne	short loc_scasb_find_dir
 22224 00007834 803F20              <1> 	cmp	byte [edi], 20h
 22225 00007837 7543                <1> 	jne	short loc_find_dir_next_entry_ebp
 22226 00007839 EB0C                <1> 	jmp	short loc_check_direntry_extension
 22227                              <1> 
 22228                              <1> loc_find_dir_next_entry_prevdeleted:
 22229 0000783B 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
 22230 0000783E EB5E                <1> 	jmp	short loc_find_dir_next_entry
 22231                              <1> 
 22232                              <1> loc_scasb_find_dir:
 22233 00007840 3A07                <1> 	cmp	al, [edi]
 22234 00007842 7538                <1> 	jne	short loc_find_dir_next_entry_ebp
 22235                              <1> loc_scasb_find_dir_inc_di:
 22236 00007844 47                  <1> 	inc	edi
 22237 00007845 E2CB                <1> 	loop	loc_lodsb_find_dir
 22238                              <1> 
 22239                              <1> loc_check_direntry_extension:
 22240 00007847 BE08000000          <1> 	mov	esi, 8
 22241 0000784C 89F7                <1> 	mov	edi, esi ; 8
 22242 0000784E 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
 22243 00007851 01EF                <1> 	add	edi, ebp
 22244 00007853 B103                <1> 	mov	cl, 3
 22245                              <1> loc_lodsb_find_dir_ext:
 22246 00007855 AC                  <1> 	lodsb
 22247 00007856 3C2A                <1> 	cmp	al, '*'
 22248 00007858 7508                <1> 	jne	short pass_fde_ambiguous3_check
 22249 0000785A FE05[3FCE0000]      <1> 	inc	byte [AmbiguousFileName+1]
 22250 00007860 EB1E                <1> 	jmp	short loc_find_dir_proper_direntry
 22251                              <1> 
 22252                              <1> pass_fde_ambiguous3_check:
 22253 00007862 3C3F                <1> 	cmp	al, '?'
 22254 00007864 750D                <1> 	jne	short pass_fde_ambiguous4_check
 22255 00007866 FE05[3ECE0000]      <1> 	inc	byte [AmbiguousFileName]
 22256 0000786C 803F20              <1> 	cmp	byte [edi], 20h
 22257 0000786F 760B                <1> 	jna	short loc_find_dir_next_entry_ebp
 22258 00007871 EB49                <1> 	jmp	short loc_scasb_find_dir_ext_inc_di
 22259                              <1> 
 22260                              <1> pass_fde_ambiguous4_check:
 22261 00007873 3C20                <1> 	cmp	al, 20h
 22262 00007875 7541                <1> 	jne	short loc_scasb_find_dir_ext
 22263 00007877 803F20              <1> 	cmp	byte [edi], 20h
 22264 0000787A 7404                <1> 	je	short loc_find_dir_proper_direntry
 22265                              <1> 
 22266                              <1> loc_find_dir_next_entry_ebp:
 22267 0000787C 89EF                <1> 	mov	edi, ebp ; 14/02/2016
 22268 0000787E EB1E                <1> 	jmp	short loc_find_dir_next_entry
 22269                              <1> 
 22270                              <1> loc_find_dir_proper_direntry:
 22271 00007880 30C9                <1> 	xor	cl, cl
 22272                              <1> loc_find_dir_proper_direntry_1:
 22273 00007882 5E                  <1> 	pop	esi
 22274 00007883 89EF                <1>         mov     edi, ebp
 22275 00007885 8A2F                <1> 	mov	ch, [edi]
 22276 00007887 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
 22277 0000788A 66A1[3ECE0000]      <1> 	mov	ax, [AmbiguousFileName]
 22278                              <1> loc_find_dir_proper_direntry_2:
 22279 00007890 8A35[40CE0000]      <1> 	mov     dh, [PreviousAttr]
 22280 00007896 66891D[6DCD0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 22281 0000789D C3                  <1> 	retn
 22282                              <1> 
 22283                              <1> loc_find_dir_next_entry:
 22284 0000789E 8815[40CE0000]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
 22285                              <1> loc_find_dir_next_entry_1:
 22286 000078A4 5E                  <1> 	pop	esi
 22287 000078A5 83C720              <1> 	add	edi, 32
 22288                              <1> 	;inc	word [DirBuff_EntryCounter]
 22289 000078A8 6643                <1> 	inc	bx
 22290 000078AA 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 22291 000078B1 770E                <1> 	ja	short loc_ffde_stc_retn_255
 22292 000078B3 E9FCFEFFFF          <1>         jmp     check_find_dir_entry 
 22293                              <1> 
 22294                              <1> loc_scasb_find_dir_ext:
 22295 000078B8 3A07                <1> 	cmp	al, [edi]
 22296 000078BA 75C0                <1> 	jne	short loc_find_dir_next_entry_ebp
 22297                              <1> loc_scasb_find_dir_ext_inc_di:
 22298 000078BC 47                  <1> 	inc	edi
 22299 000078BD E296                <1> 	loop    loc_lodsb_find_dir_ext
 22300 000078BF EBC1                <1> 	jmp	short loc_find_dir_proper_direntry_1
 22301                              <1> 
 22302                              <1> loc_ffde_stc_retn_255:
 22303                              <1> 	;mov	cx, 0FFFFh
 22304 000078C1 31C9                <1> 	xor	ecx, ecx
 22305 000078C3 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 22306                              <1> 	;xor	eax, eax
 22307                              <1> loc_find_direntry_stc_retn:
 22308                              <1> loc_check_ffde_retn_1:
 22309                              <1> 	;mov	ax, 2
 22310 000078C4 B802000000          <1> 	mov	eax, 2 ; File Not Found
 22311 000078C9 8A35[40CE0000]      <1> 	mov	dh, [PreviousAttr]
 22312 000078CF 66891D[6DCD0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 22313 000078D6 F9                  <1> 	stc
 22314 000078D7 C3                  <1> 	retn
 22315                              <1> 
 22316                              <1> loc_find_free_deleted_entry_0:
 22317 000078D8 66A1[3CCE0000]      <1> 	mov	ax, [FDE_AttrMask]
 22318 000078DE 8A2F                <1> 	mov	ch, [edi]
 22319 000078E0 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 22320 000078E3 08C9                <1> 	or	cl, cl 
 22321 000078E5 7407                <1> 	jz	short loc_check_ffde_0_repeat
 22322                              <1> 	;cmp	cl, 0E5h
 22323                              <1> 	;je	short pass_loc_check_ffde_0_err
 22324 000078E7 80F9FF              <1> 	cmp	cl, 0FFh
 22325 000078EA 7432                <1> 	je	short loc_find_free_deleted_entry_1
 22326 000078EC EB4D                <1> 	jmp	short pass_loc_check_ffde_0_err
 22327                              <1> 
 22328                              <1> loc_check_ffde_0_repeat:
 22329 000078EE 08ED                <1> 	or	ch, ch
 22330 000078F0 7511                <1> 	jnz	short loc_check_ffde_0_next
 22331                              <1> 
 22332                              <1> loc_check_ffde_retn_2:
 22333 000078F2 6629C0              <1> 	sub	ax, ax
 22334 000078F5 8A35[40CE0000]      <1> 	mov	dh, [PreviousAttr]
 22335 000078FB 66891D[6DCD0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 22336 00007902 C3                  <1> 	retn
 22337                              <1>  
 22338                              <1> loc_check_ffde_0_next:
 22339 00007903 6643                <1> 	inc	bx
 22340 00007905 83C720              <1> 	add	edi, 32
 22341                              <1> 	;inc	word [DirBuff_EntryCounter]
 22342                              <1> 	 
 22343 00007908 663B1D[6FCD0000]    <1>         cmp	bx, [DirBuff_LastEntry]
 22344 0000790F 77B0                <1> 	ja	short loc_ffde_stc_retn_255
 22345 00007911 8815[40CE0000]      <1> 	mov	[PreviousAttr], dl
 22346 00007917 8A2F                <1> 	mov	ch, [edi]
 22347 00007919 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
 22348 0000791C EBD0                <1> 	jmp	short loc_check_ffde_0_repeat
 22349                              <1> 
 22350                              <1> loc_find_free_deleted_entry_1:
 22351 0000791E 28D2                <1> 	sub	dl, dl      
 22352                              <1> loc_find_free_deleted_entry_2:
 22353 00007920 20ED                <1> 	and	ch, ch  
 22354 00007922 74CE                <1> 	jz	short loc_check_ffde_retn_2
 22355 00007924 80FDE5              <1> 	cmp	ch, 0E5h
 22356 00007927 74C9                <1> 	je	short loc_check_ffde_retn_2
 22357 00007929 6643                <1> 	inc	bx
 22358 0000792B 83C720              <1> 	add	edi, 32
 22359 0000792E 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 22360 00007935 778A                <1> 	ja	short loc_ffde_stc_retn_255
 22361 00007937 8A2F                <1> 	mov	ch, [edi]
 22362 00007939 EBE5                <1> 	jmp	short loc_find_free_deleted_entry_2
 22363                              <1> 
 22364                              <1> pass_loc_check_ffde_0_err:
 22365 0000793B 38CD                <1> 	cmp	ch, cl
 22366 0000793D 741F                <1> 	je	short loc_check_ffde_attrib 
 22367                              <1> 
 22368 0000793F 6643                <1> 	inc	bx
 22369 00007941 83C720              <1> 	add	edi, 32
 22370 00007944 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 22371 0000794B 0F8770FFFFFF        <1>         ja      loc_ffde_stc_retn_255
 22372 00007951 8815[40CE0000]      <1> 	mov	[PreviousAttr], dl
 22373 00007957 8A2F                <1> 	mov	ch, [edi]
 22374 00007959 8A570B              <1> 	mov	dl, [edi+0Bh]
 22375 0000795C EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
 22376                              <1> 
 22377                              <1> loc_check_ffde_attrib:
 22378 0000795E 88C6                <1> 	mov	dh, al
 22379 00007960 20D6                <1> 	and	dh, dl    
 22380 00007962 38F0                <1> 	cmp	al, dh
 22381 00007964 759D                <1> 	jne	short loc_check_ffde_0_next
 22382 00007966 20D4                <1> 	and	ah, dl
 22383 00007968 7599                <1> 	jnz	short loc_check_ffde_0_next
 22384 0000796A 30C9                <1> 	xor	cl, cl 
 22385 0000796C EB84                <1>         jmp     loc_check_ffde_retn_2
 22386                              <1> 
 22387                              <1> convert_file_name:
 22388                              <1> 	; 06/03/2016
 22389                              <1> 	; 11/02/2016
 22390                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 22391                              <1> 	; 06/10/2009
 22392                              <1> 	; 2005
 22393                              <1> 	;
 22394                              <1> 	; INPUT  ->
 22395                              <1> 	;	ESI = Dot File Name Location
 22396                              <1> 	;	EDI = Dir Entry Format File Name Location
 22397                              <1> 	; OUTPUT ->
 22398                              <1> 	;	EDI = Dir Entry Format File Name Location
 22399                              <1> 	;	ESI = Dot File Name Location (capitalized)
 22400                              <1> 	;
 22401                              <1> 	; (ECX, AL will be changed) 
 22402                              <1>      
 22403 0000796E 56                  <1> 	push	esi  
 22404 0000796F 57                  <1> 	push	edi
 22405                              <1> 
 22406 00007970 B90B000000          <1> 	mov	ecx, 11
 22407 00007975 B020                <1> 	mov	al, 20h
 22408 00007977 F3AA                <1> 	rep	stosb
 22409                              <1> 
 22410 00007979 8B3C24              <1> 	mov	edi, [esp]
 22411                              <1> 
 22412 0000797C B10C                <1> 	mov	cl, 12 ; file name length (max.)
 22413                              <1> 	; 06/03/2016
 22414                              <1> 	; Directory entry name limit (11 bytes) check for
 22415                              <1> 	; 'rename_directory_entry' procedure.
 22416                              <1> 	; (EDI points to Directory Entry)
 22417                              <1> 	; (If the file name would not contain a dot
 22418                              <1> 	; and file name length would be 12, this would cause to
 22419                              <1> 	; overwrite the attributes byte of the directory entry.)
 22420                              <1> 	;
 22421 0000797E B50B                <1> 	mov	ch, 11 ; directory entry's name length
 22422                              <1> loc_check_first_dot:
 22423 00007980 8A06                <1> 	mov	al, [esi]
 22424 00007982 3C2E                <1> 	cmp	al, 2Eh
 22425 00007984 750C                <1> 	jne	short pass_check_first_dot
 22426 00007986 8807                <1> 	mov	[edi], al
 22427 00007988 47                  <1> 	inc	edi
 22428 00007989 46                  <1> 	inc	esi
 22429 0000798A FEC9                <1> 	dec	cl
 22430 0000798C 75F2                <1> 	jnz	short loc_check_first_dot
 22431                              <1> 	;;(ecx <= 12)
 22432                              <1> 	;;loop	loc_check_first_dot 
 22433 0000798E EB30                <1> 	jmp	short stop_convert_file
 22434                              <1> 
 22435                              <1> loc_get_fchar:
 22436 00007990 8A06                <1> 	mov	al, [esi]
 22437                              <1> pass_check_first_dot:
 22438 00007992 3C61                <1> 	cmp	al, 61h ; 'a'
 22439 00007994 7208                <1> 	jb	short pass_name_capitalize
 22440 00007996 3C7A                <1> 	cmp	al, 7Ah ; 'z'
 22441 00007998 7704                <1> 	ja	short pass_name_capitalize
 22442 0000799A 24DF                <1> 	and	al, 0DFh
 22443 0000799C 8806                <1> 	mov	[esi], al
 22444                              <1> pass_name_capitalize:
 22445 0000799E 3C21                <1> 	cmp	al, 21h
 22446 000079A0 721E                <1> 	jb	short stop_convert_file
 22447 000079A2 3C2E                <1> 	cmp	al, 2Eh ; '.'
 22448 000079A4 750C                <1> 	jne	short pass_dot_space
 22449                              <1> add_dot_space: 
 22450 000079A6 80F904              <1> 	cmp	cl, 4
 22451 000079A9 760E                <1> 	jna	short inc_and_loop
 22452 000079AB 47                  <1> 	inc	edi
 22453 000079AC FECD                <1> 	dec	ch ; 06/03/2016
 22454 000079AE FEC9                <1> 	dec	cl
 22455 000079B0 EBF4                <1> 	jmp	short add_dot_space
 22456                              <1> 	
 22457                              <1> 	;mov	al, 4
 22458                              <1> 	;cmp	cl, al
 22459                              <1> 	;jna	short inc_and_loop
 22460                              <1> 	;sub	cl, al
 22461                              <1> 	;add	edi, ecx
 22462                              <1> 	;mov	cl, al
 22463                              <1> 	;jmp	short inc_and_loop	
 22464                              <1> 
 22465                              <1> pass_dot_space:
 22466 000079B2 8807                <1> 	mov	[edi], al
 22467                              <1> loc_after_double_dot:
 22468                              <1> 	; 06/03/2016
 22469 000079B4 FECD                <1> 	dec	ch ; count down for 11 bytes dir entry limit
 22470 000079B6 740A                <1> 	jz	short stop_convert_file_x
 22471 000079B8 47                  <1> 	inc	edi
 22472                              <1> inc_and_loop:
 22473 000079B9 FEC9                <1> 	dec	cl ; count down for 12 bytes filename limit 
 22474 000079BB 7403                <1> 	jz	short stop_convert_file	
 22475 000079BD 46                  <1> 	inc	esi
 22476                              <1> 	;;(ecx <= 12)
 22477                              <1> 	;;loop	loc_get_fchar
 22478 000079BE EBD0                <1> 	jmp	short loc_get_fchar
 22479                              <1> 
 22480                              <1> stop_convert_file:
 22481                              <1> 	; 06/03/2016
 22482 000079C0 30ED                <1> 	xor	ch, ch
 22483                              <1> 	; ECX < 256 ; 'find_first_file' -> xor cl, cl
 22484                              <1> stop_convert_file_x:
 22485 000079C2 5F                  <1> 	pop	edi
 22486 000079C3 5E                  <1> 	pop	esi
 22487 000079C4 C3                  <1> 	retn
 22488                              <1>  
 22489                              <1> save_longname_sub_component:
 22490                              <1> 	; 13/02/2016
 22491                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 22492                              <1> 	; 28/02/2010
 22493                              <1> 	; 17/10/2009
 22494                              <1> 	; INPUT ->
 22495                              <1> 	;	EDI = Directory Entry    
 22496                              <1> 	;     	// This procedure is called
 22497                              <1> 	;	// from 'find_directory_entry' procedure.
 22498                              <1> 	;	// If the last entry returns with
 22499                              <1> 	;	// a non-zero LongnameFound value and
 22500                              <1> 	;	// if LFN_CheckSum value is equal to
 22501                              <1> 	;	// the next shortname checksum,
 22502                              <1> 	;	// long name is valid.
 22503                              <1> 	;	// If a longname is longer than 65 bytes,
 22504                              <1> 	;	// it is invalid for trdos. (>45h)
 22505                              <1>  
 22506 000079C5 57                  <1> 	push	edi
 22507 000079C6 56                  <1> 	push	esi
 22508                              <1> 	;push	ebx
 22509                              <1> 	;push	ecx
 22510                              <1> 	;push	edx
 22511 000079C7 50                  <1> 	push	eax
 22512                              <1>            
 22513 000079C8 29C9                <1> 	sub	ecx, ecx
 22514                              <1> 	;sub	eax, eax
 22515 000079CA B11A                <1> 	mov	cl, 26
 22516                              <1> 
 22517 000079CC 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
 22518 000079CF 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
 22519 000079D1 722B                <1> 	jb	short pass_pslnsc_last_long_entry
 22520                              <1> 
 22521 000079D3 88C4                <1> 	mov	ah, al
 22522 000079D5 80EC40              <1> 	sub	ah, 40h
 22523 000079D8 8825[42CE0000]      <1> 	mov	[LFN_EntryLength], ah
 22524                              <1> 	
 22525 000079DE 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
 22526                              <1>  		; Max 130 byte length is usable in TRDOS
 22527                              <1> ; 26*5 = 130
 22528 000079E0 7753                <1> 	ja	short loc_pslnsc_retn
 22529                              <1> 
 22530 000079E2 2407                <1> 	and	al, 07h ; 0Fh
 22531 000079E4 A2[41CE0000]        <1> 	mov	[LongNameFound], al
 22532                              <1> 
 22533 000079E9 FEC8                <1> 	dec	al
 22534                              <1> 	;mov	cl, 26
 22535 000079EB F6E1                <1> 	mul	cl
 22536                              <1> 
 22537 000079ED 89C6                <1> 	mov	esi, eax
 22538 000079EF 01CE                <1> 	add	esi, ecx
 22539                              <1> 		; to make is an ASCIZZ string
 22540                              <1> 		; with ax+26 bytes length
 22541 000079F1 81C6[44CE0000]      <1> 	add	esi, LongFileName
 22542 000079F7 66C7060000          <1> 	mov	word [esi], 0   
 22543 000079FC EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2 
 22544                              <1> 
 22545                              <1> pass_pslnsc_last_long_entry:
 22546 000079FE 3C04                <1> 	cmp	al, 04h
 22547 00007A00 7733                <1> 	ja	short loc_pslnsc_retn
 22548 00007A02 FE0D[41CE0000]      <1> 	dec	byte [LongNameFound]
 22549 00007A08 3A05[41CE0000]      <1> 	cmp	al, [LongNameFound]
 22550 00007A0E 7525                <1> 	jne	short loc_pslnsc_retn
 22551                              <1> 
 22552                              <1> loc_pslsc_move_ldir_name1:
 22553 00007A10 FEC8                <1> 	dec	al
 22554                              <1> 	;mov	cl, 26
 22555 00007A12 F6E1                <1> 	mul	cl
 22556                              <1> 
 22557                              <1> loc_pslsc_move_ldir_name2:
 22558 00007A14 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
 22559 00007A17 880D[43CE0000]      <1> 	mov	[LFN_CheckSum], cl 
 22560 00007A1D 89FE                <1> 	mov	esi, edi ; LDIR_Order
 22561 00007A1F BF[44CE0000]        <1> 	mov	edi, LongFileName
 22562 00007A24 01C7                <1> 	add	edi, eax
 22563 00007A26 46                  <1> 	inc	esi
 22564 00007A27 B105                <1> 	mov	cl, 5 ; chars 1 to 5
 22565 00007A29 F366A5              <1> 	rep	movsw
 22566 00007A2C 83C603              <1> 	add	esi, 3
 22567 00007A2F A5                  <1> 	movsd	; char 6 & 7 
 22568 00007A30 A5                  <1> 	movsd	; char 8 & 9
 22569 00007A31 A5                  <1> 	movsd	; char 10 & 11
 22570 00007A32 46                  <1> 	inc	esi
 22571 00007A33 46                  <1> 	inc	esi 
 22572 00007A34 A5                  <1> 	movsd   ; char 12 & 13 
 22573                              <1> 
 22574                              <1> loc_pslnsc_retn:
 22575 00007A35 58                  <1>  	pop	eax
 22576                              <1> 	;pop	edx
 22577                              <1> 	;pop	ecx
 22578                              <1> 	;pop	ebx
 22579 00007A36 5E                  <1> 	pop	esi  
 22580 00007A37 5F                  <1> 	pop	edi
 22581                              <1>  
 22582 00007A38 C3                  <1>     	retn
 22583                              <1> 
 22584                              <1> parse_path_name:
 22585                              <1> 	; 10/02/2016
 22586                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
 22587                              <1> 	; 10/009/2011 ('proc_parse_pathname')
 22588                              <1> 	; 27/11/2009
 22589                              <1> 	; 05/12/2004
 22590                              <1> 	;
 22591                              <1> 	; INPUT ->
 22592                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
 22593                              <1> 	;       EDI = Destination Address
 22594                              <1> 	;	      (which is TR-DOS FindFile data buffer)
 22595                              <1> 	; OUTPUT ->
 22596                              <1> 	;	CF = 1 -> Error
 22597                              <1> 	;	     EAX = Error Code (AL)
 22598                              <1> 	;
 22599                              <1> 	; (Modified registers: eax, ecx, esi, edi) 
 22600                              <1> 	
 22601                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer 
 22602 00007A39 57                  <1> 	push	edi
 22603 00007A3A B914000000          <1> 	mov	ecx, 20  ; 80 bytes
 22604 00007A3F 31C0                <1> 	xor	eax, eax
 22605 00007A41 F3AB                <1> 	rep	stosd 
 22606 00007A43 5F                  <1> 	pop	edi
 22607                              <1> 
 22608 00007A44 668B06              <1> 	mov	ax, [esi]
 22609 00007A47 80FC3A              <1> 	cmp	ah, ':'
 22610 00007A4A 741C                <1> 	je	short loc_ppn_change_drive
 22611 00007A4C A0[42C50000]        <1> 	mov	al, [Current_Drv]
 22612 00007A51 EB33                <1> 	jmp	short pass_ppn_change_drive
 22613                              <1> 
 22614                              <1> pass_ppn_cdir:
 22615 00007A53 8B35[66CF0000]      <1> 	mov	esi, [First_Path_Pos]
 22616 00007A59 AC                  <1> 	lodsb
 22617                              <1> loc_ppn_get_filename:
 22618 00007A5A 83C741              <1> 	add	edi, 65 ; FindFile_Name location
 22619                              <1> 	; TRDOS Filename length must not be more than 12 bytes
 22620                              <1> 	;mov	ecx, 12
 22621 00007A5D B10C                <1> 	mov	cl, 12
 22622                              <1> loc_ppn_get_fnchar_next:
 22623 00007A5F AA                  <1> 	stosb
 22624 00007A60 AC                  <1> 	lodsb
 22625 00007A61 3C21                <1> 	cmp	al, 21h
 22626 00007A63 7274                <1> 	jb	short loc_ppn_clc_return 
 22627 00007A65 E2F8                <1>         loop    loc_ppn_get_fnchar_next
 22628                              <1> loc_ppn_return:
 22629 00007A67 C3                  <1> 	retn
 22630                              <1> 
 22631                              <1> loc_ppn_change_drive:
 22632 00007A68 24DF                <1> 	and	al, 0DFh
 22633 00007A6A 2C41                <1> 	sub	al, 'A'; A:
 22634 00007A6C 726F                <1> 	jc	short loc_ppn_invalid_drive
 22635 00007A6E 3805[F5B40000]      <1> 	cmp	[Last_DOS_DiskNo], al
 22636 00007A74 7267                <1> 	jb	short loc_ppn_invalid_drive
 22637                              <1> 
 22638 00007A76 46                  <1> 	inc	esi
 22639 00007A77 46                  <1> 	inc	esi
 22640 00007A78 8A26                <1> 	mov	ah, [esi]
 22641 00007A7A 80FC21              <1> 	cmp	ah, 21h
 22642 00007A7D 7307                <1> 	jnb	short pass_ppn_change_drive
 22643                              <1> 
 22644                              <1> loc_ppn_cmd_failed:
 22645                              <1> 	; File or directory name is not existing
 22646 00007A7F 8807                <1> 	mov	[edi], al ; Drv 
 22647 00007A81 66B80100            <1> 	mov	ax, 1 ; eax = 1
 22648                              <1> 	; TR-DOS Error Code 1h = Bad Command Argument
 22649                              <1> 	; MS-DOS Error Code 1h : Invalid Function Number
 22650                              <1> 	;stc
 22651                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
 22652 00007A85 C3                  <1> 	retn
 22653                              <1> 
 22654                              <1> pass_ppn_change_drive:
 22655 00007A86 8935[66CF0000]      <1> 	mov	[First_Path_Pos], esi
 22656 00007A8C C705[6ACF0000]0000- <1> 	mov	dword [Last_Slash_Pos], 0
 22657 00007A94 0000                <1>
 22658 00007A96 AA                  <1> 	stosb
 22659 00007A97 8A06                <1> 	mov	al, [esi]
 22660                              <1> loc_scan_ppn_dslash:
 22661 00007A99 3C2F                <1> 	cmp	al, '/'
 22662 00007A9B 7506                <1>   	jne	short loc_scan_next_slash_pos
 22663 00007A9D 8935[6ACF0000]      <1> 	mov	[Last_Slash_Pos], esi
 22664                              <1> loc_scan_next_slash_pos:
 22665 00007AA3 46                  <1> 	inc	esi
 22666 00007AA4 8A06                <1> 	mov	al, [esi]
 22667 00007AA6 3C20                <1> 	cmp	al, 20h
 22668 00007AA8 77EF                <1> 	ja	short loc_scan_ppn_dslash
 22669 00007AAA 833D[6ACF0000]00    <1> 	cmp	dword [Last_Slash_Pos], 0
 22670 00007AB1 76A0                <1> 	jna	short pass_ppn_cdir
 22671                              <1> 	
 22672 00007AB3 8B0D[6ACF0000]      <1> 	mov	ecx, [Last_Slash_Pos]
 22673 00007AB9 8B35[66CF0000]      <1> 	mov	esi, [First_Path_Pos]
 22674 00007ABF 29F1                <1> 	sub	ecx, esi
 22675 00007AC1 41                  <1> 	inc	ecx
 22676                              <1> 	;cmp	ecx, 64
 22677 00007AC2 80F940              <1> 	cmp	cl, 64
 22678 00007AC5 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
 22679                              <1> 
 22680 00007AC7 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 byte)
 22681 00007AC9 F3A4                <1> 	rep	movsb
 22682                              <1> 	;mov	[edi], cl ; 0, End of Dir String
 22683 00007ACB 8B35[6ACF0000]      <1> 	mov	esi, [Last_Slash_Pos]
 22684 00007AD1 46                  <1> 	inc	esi
 22685 00007AD2 89C7                <1> 	mov	edi, eax
 22686 00007AD4 AC                  <1> 	lodsb
 22687 00007AD5 3C21                <1> 	cmp	al, 21h
 22688 00007AD7 7381                <1> 	jnb	short loc_ppn_get_filename
 22689                              <1> loc_ppn_clc_return:
 22690                              <1> 	;clc
 22691 00007AD9 31C0                <1> 	xor	eax, eax
 22692 00007ADB C3                  <1> 	retn
 22693                              <1> 
 22694                              <1> loc_ppn_invalid_drive_stc:
 22695 00007ADC F5                  <1> 	cmc	 ; stc
 22696                              <1> loc_ppn_invalid_drive:
 22697                              <1> 	; cf = 1
 22698                              <1> 	; The Drive Letter/Char < "A" or > "Z"
 22699 00007ADD 66B80F00            <1> 	mov	ax, 0Fh
 22700                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
 22701                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
 22702 00007AE1 C3                  <1> 	retn
 22703                              <1> 
 22704                              <1> find_longname:
 22705                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 22706                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
 22707                              <1> 	; 17/10/2009
 22708                              <1> 	
 22709                              <1> 	; INPUT -> 
 22710                              <1> 	;	ESI = DOS short file name address
 22711                              <1> 	; 	for example: "filename.ext"
 22712                              <1> 	;
 22713                              <1> 	; OUTPUT ->
 22714                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
 22715                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
 22716                              <1> 	;	AL = 0 & CF=1 -> longname not found
 22717                              <1> 	;	     the file/directory has no longname
 22718                              <1> 	; 	cf = 0 -> AL = FAT Type 
 22719                              <1>  
 22720                              <1> 	; 17/10/2009
 22721                              <1> 	; ASCIIZ string will be returned
 22722                              <1> 	; as LongFileName
 22723                              <1> 	; clearing/reset is not needed
 22724                              <1> 	;mov	ecx, 33
 22725                              <1> 	;mov	edi, LongFileName
 22726                              <1> 	;sub	ax, ax ; 0
 22727                              <1> 	;rep	stosw
 22728                              <1> 
 22729                              <1> 	;mov	byte [LongNameFound], 0
 22730                              <1> 
 22731                              <1> 	; ESI = ASCIIZ file/directory name address
 22732                              <1> 	;   AL = Attributes AND mask 
 22733                              <1> 	;	(Result of AND must be equal to AL)
 22734                              <1> 	;   AH = Negative attributes mask 
 22735                              <1> 	;	(Result of AND must be ZERO)
 22736 00007AE2 66B80008            <1> 	mov	ax, 0800h 
 22737                              <1> 		; it must not be volume name or longname
 22738 00007AE6 E877E0FFFF          <1> 	call	find_first_file
 22739 00007AEB 7216                <1> 	jc	short loc_fln_retn
 22740                              <1>  
 22741                              <1> loc_fln_check_FAT_Type:
 22742 00007AED 803D[41C50000]01    <1> 	cmp	byte [Current_FATType], 1
 22743 00007AF4 7306                <1> 	jnb	short loc_fln_check_longname_yes_sign
 22744                              <1> 
 22745 00007AF6 E839000000          <1> 	call	get_fs_longname
 22746 00007AFB C3                  <1> 	retn
 22747                              <1> 
 22748                              <1> loc_fln_check_longname_yes_sign:
 22749 00007AFC 08FF                <1> 	or	bh, bh
 22750 00007AFE 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
 22751                              <1> loc_fln_longname_not_found_retn:
 22752 00007B00 31C0                <1> 	xor	eax, eax 
 22753                              <1> 	; cf = 1 & al = 0 -> longname not found
 22754 00007B02 F9                  <1> 	stc
 22755                              <1> loc_fln_retn:
 22756 00007B03 C3                  <1> 	retn
 22757                              <1> 
 22758                              <1> loc_fln_check_longnamefound_number:
 22759                              <1> 	; 'LongNameFound' is set by
 22760                              <1>         ; by 'save_longname_sub_component'
 22761                              <1> 	; which is called from
 22762                              <1> 	; 'find_directory_entry' 
 22763                              <1> 	; which is called from 
 22764                              <1> 	; 'find_first_file'
 22765                              <1> 	; It must 1 if the longname is valid
 22766 00007B04 803D[41CE0000]01    <1>         cmp     byte [LongNameFound], 1
 22767 00007B0B 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
 22768                              <1>              
 22769                              <1> loc_fln_calculate_checksum: 
 22770 00007B0D E813000000          <1> 	call	calculate_checksum
 22771                              <1> 	; AL = shortname checksum
 22772                              <1> 
 22773                              <1> loc_fln_longname_validation:
 22774                              <1> 	; 'LFN_CheckSum' has been set already
 22775                              <1> 	; by 'save_longname_sub_component'
 22776                              <1> 	; which is called from
 22777                              <1> 	; 'find_directory_entry' 
 22778                              <1> 	; which is called from 
 22779                              <1> 	; 'find_first_file'
 22780 00007B12 3805[43CE0000]      <1> 	cmp	[LFN_CheckSum], al
 22781 00007B18 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
 22782                              <1> 
 22783 00007B1A BE[44CE0000]        <1> 	mov	esi, LongFileName
 22784 00007B1F A0[41C50000]        <1> 	mov	al, [Current_FATType]
 22785 00007B24 C3                  <1> 	retn
 22786                              <1> 
 22787                              <1> calculate_checksum:
 22788                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 22789                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
 22790                              <1>         ;    
 22791                              <1> 	; INPUT ->
 22792                              <1> 	;	ESI = 11 byte DOS File Name location
 22793                              <1> 	;	(in DOS Directory Entry Format)
 22794                              <1> 	; OUTPUT ->
 22795                              <1> 	;	 AL = 8 bit checksum (CRC) value
 22796                              <1> 	;
 22797                              <1> 	; (Modified registers: EAX, ECX, ESI)
 22798                              <1> 
 22799                              <1> 	; Erdogan Tan [ 17-10-2009 ]
 22800                              <1> 	;  'ror al, 1' instruction
 22801                              <1> 
 22802                              <1> 	; Erdogan Tan [ 20-06-2004 ]
 22803                              <1> 	; This 8086 assembly code is an original code
 22804                              <1> 	; which is adapted from C code in
 22805                              <1> 	; Microsoft FAT32 File System Specification
 22806                              <1> 	; Version 1.03, December 6, 2000
 22807                              <1> 	; Page 28
 22808                              <1> 
 22809 00007B25 30C0                <1> 	xor	al, al
 22810 00007B27 B90B000000          <1> 	mov	ecx, 11
 22811                              <1> loc_next_sum:
 22812                              <1> 	;xor	ah, ah
 22813                              <1> 	;test	al, 1
 22814                              <1> 	;jz	short pass_ah_80h
 22815                              <1> 	;mov	ah, 80h
 22816                              <1> ;pass_ah_80h:
 22817                              <1> 	;shr	al, 1
 22818 00007B2C D0C8                <1> 	ror	al, 1 ; 17/10/2009  
 22819 00007B2E 0206                <1> 	add	al, [esi]
 22820 00007B30 46                  <1> 	inc	esi
 22821                              <1> 	;add	al, ah
 22822 00007B31 E2F9                <1> 	loop	loc_next_sum
 22823 00007B33 C3                  <1> 	retn
 22824                              <1> 
 22825                              <1> get_fs_longname:
 22826                              <1> 	; temporary (13/02/2016)
 22827 00007B34 31C0                <1> 	xor eax, eax
 22828 00007B36 F9                  <1> 	stc
 22829 00007B37 C3                  <1> 	retn
 22830                              <1> 
 22831                              <1> make_sub_directory:
 22832                              <1> 	; 03/03/2016
 22833                              <1> 	; 02/03/2016
 22834                              <1> 	; 27/02/2026
 22835                              <1> 	; 26/02/2016
 22836                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 22837                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
 22838                              <1> 	; 10/07/2010
 22839                              <1> 	; INPUT ->
 22840                              <1> 	; 	ESI = ASCIIZ Directory Name
 22841                              <1> 	;	CL = Directory Attributes
 22842                              <1> 	; OUTPUT ->
 22843                              <1> 	;	EAX = New sub dir's first cluster
 22844                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
 22845                              <1> 	;	CF = 1 -> error code in AL (EAX)
 22846                              <1> 
 22847                              <1> 	;test	cl, 10h  ; directory
 22848                              <1> 	;jz	short loc_make_directory_access_denied
 22849                              <1> 	;test	cl, 08h ; volume name
 22850                              <1> 	;jnz	short loc_make_directory_access_denied
 22851                              <1> 
 22852 00007B38 80E107              <1> 	and	cl, 07h
 22853 00007B3B 880D[C0CF0000]      <1> 	mov	byte [mkdir_attrib], cl
 22854                              <1> 
 22855 00007B41 56                  <1> 	push	esi
 22856 00007B42 31DB                <1> 	xor	ebx, ebx
 22857 00007B44 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 22858 00007B4A BE00010900          <1> 	mov	esi, Logical_DOSDisks
 22859 00007B4F 01DE                <1> 	add	esi, ebx
 22860 00007B51 5B                  <1> 	pop	ebx
 22861                              <1> 
 22862                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
 22863                              <1> 	; LD_DiskType = 0 for write protection (read only) 
 22864 00007B52 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
 22865 00007B56 730B                <1> 	jnb	short loc_mkdir_check_file_sytem
 22866 00007B58 B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
 22867 00007B5D BA00000000          <1> 	mov	edx, 0
 22868                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
 22869                              <1> 	;ESI = Logical DOS drive description table address
 22870 00007B62 C3                  <1> 	retn
 22871                              <1> 
 22872                              <1> ;loc_make_directory_access_denied:
 22873                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
 22874                              <1> 	;stc
 22875                              <1> 	;retn
 22876                              <1> 
 22877                              <1> loc_mkdir_check_file_sytem:
 22878 00007B63 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 22879 00007B67 730B                <1> 	jnb	short loc_mkdir_check_free_sectors
 22880                              <1> 
 22881                              <1> loc_make_fs_directory:
 22882 00007B69 A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster]
 22883                              <1> 	; EAX = Parent directory DDT Address
 22884                              <1> 	; ESI = Logical DOS Drive DT Address
 22885                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
 22886 00007B6E E8B8150000          <1> 	call	make_fs_directory
 22887 00007B73 C3                  <1> 	retn
 22888                              <1> 
 22889                              <1> loc_mkdir_check_free_sectors:
 22890 00007B74 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
 22891 00007B78 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 22892 00007B7B 39C1                <1> 	cmp	ecx, eax
 22893 00007B7D 7255                <1> 	jb	short loc_mkdir_insufficient_disk_space
 22894                              <1> 
 22895                              <1> loc_make_fat_directory:
 22896 00007B7F 891D[B0CF0000]      <1> 	mov	[mkdir_DirName_Offset], ebx
 22897 00007B85 890D[BCCF0000]      <1> 	mov	[mkdir_FreeSectors], ecx
 22898                              <1> 
 22899                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
 22900 00007B8B A2[C2CF0000]        <1> 	mov	byte [mkdir_SecPerClust], al
 22901                              <1> 
 22902                              <1> loc_mkdir_gffc_1:
 22903 00007B90 E8F2170000          <1> 	call	get_first_free_cluster
 22904 00007B95 722A                <1> 	jc	short loc_mkdir_gffc_retn
 22905                              <1> 
 22906                              <1> ;loc_mkdir_gffc_1_cont: 
 22907                              <1> 	;cmp	eax, 2
 22908                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 22909                              <1> 
 22910                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
 22911 00007B97 A3[B4CF0000]        <1> 	mov	[mkdir_FFCluster], eax
 22912                              <1> 
 22913                              <1> loc_mkdir_locate_ffe:
 22914                              <1> 	; Current directory fcluster <> Directory buffer cluster
 22915                              <1> 	; Current directory will be reloaded by
 22916                              <1> 	; 'locate_current_dir_file' procedure
 22917                              <1> 	;
 22918                              <1> 	; ESI = Logical DOS Drive Description Table Address 
 22919                              <1> 	;push	esi ; 27/02/2016
 22920 00007B9C 31C0                <1> 	xor	eax, eax
 22921 00007B9E 89C1                <1>         mov	ecx, eax
 22922 00007BA0 6649                <1> 	dec	cx ; FFFFh  
 22923                              <1> 	; CX = FFFFh -> find first deleted or free entry
 22924                              <1> 	; ESI would be ASCIIZ filename address if the call
 22925                              <1> 	; would not be for first free or deleted dir entry
 22926 00007BA2 E8D2FAFFFF          <1> 	call	locate_current_dir_file
 22927 00007BA7 734C                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
 22928                              <1> 	;pop	esi 
 22929                              <1> 	; ESI = Logical DOS Drive Description Table Address 
 22930 00007BA9 83F802              <1> 	cmp	eax, 2  ; cmp al, 2 ; File/Dir not found !
 22931 00007BAC 752B                <1> 	jne	short loc_mkdir_stc_return
 22932                              <1> 
 22933                              <1> loc_mkdir_add_new_cluster:
 22934 00007BAE 3805[41C50000]      <1> 	cmp	byte [Current_FATType], al ; 2
 22935                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
 22936 00007BB4 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
 22937 00007BB6 803D[40C50000]01    <1> 	cmp	byte [Current_Dir_Level], 1
 22938                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
 22939 00007BBD 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
 22940                              <1> 
 22941 00007BBF B00C                <1> 	mov	al, 12 ; No more files 
 22942                              <1> loc_mkdir_gffc_retn:
 22943 00007BC1 C3                  <1> 	retn
 22944                              <1> 
 22945                              <1> loc_mkdir_add_new_cluster_check_fsc:
 22946 00007BC2 8B0D[BCCF0000]      <1> 	mov	ecx, [mkdir_FreeSectors]
 22947                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
 22948 00007BC8 A0[C2CF0000]        <1> 	mov	al, [mkdir_SecPerClust]
 22949 00007BCD 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
 22950 00007BD0 39C1                <1> 	cmp	ecx, eax
 22951 00007BD2 7350                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
 22952                              <1> 
 22953                              <1> loc_mkdir_insufficient_disk_space:
 22954                              <1> 	;mov	edx, ecx
 22955                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
 22956 00007BD4 66B82700            <1> 	mov	ax, 27h ; MSDOS err => insufficient disk space
 22957                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
 22958                              <1>         ; ESI -> Dos drive description table address
 22959                              <1> 	;; ecx = edx
 22960                              <1> 	;
 22961 00007BD8 C3                  <1> 	retn
 22962                              <1> 
 22963                              <1> loc_mkdir_stc_return:
 22964 00007BD9 F9                  <1> 	stc
 22965 00007BDA C3                  <1> 	retn 
 22966                              <1> 
 22967                              <1> loc_mkdir_gffc_2:
 22968 00007BDB E8A7170000          <1> 	call	get_first_free_cluster
 22969 00007BE0 72DF                <1> 	jc	short loc_mkdir_gffc_retn
 22970                              <1> 
 22971                              <1> ;loc_mkdir_gffc_1_cont: 
 22972                              <1> 	;cmp	eax, 2
 22973                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 22974                              <1> 
 22975                              <1> ;loc_mkdir_gffc_2_save_fcluster:  
 22976 00007BE2 A3[B4CF0000]        <1> 	mov	[mkdir_FFCluster], eax
 22977                              <1> 
 22978 00007BE7 A1[B8CF0000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 22979                              <1> 
 22980 00007BEC E825170000          <1> 	call	load_FAT_sub_directory 
 22981 00007BF1 72CE                <1> 	jc	short loc_mkdir_gffc_retn
 22982                              <1> 
 22983 00007BF3 31FF                <1> 	xor	edi, edi
 22984                              <1> loc_mkdir_set_ff_dir_entry_1:
 22985                              <1> 	; 27/02/2016
 22986 00007BF5 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
 22987                              <1> 	; EDI = Directory Entry Address
 22988 00007BF6 8B35[B0CF0000]      <1> 	mov	esi, [mkdir_DirName_Offset]
 22989 00007BFC A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 22990                              <1> 
 22991 00007C01 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
 22992                              <1> 			; CH = 0 -> File size is 0
 22993 00007C05 0A0D[C0CF0000]      <1> 	or	cl, [mkdir_attrib] ; S, H, R  
 22994 00007C0B E8B0010000          <1> 	call	make_directory_entry
 22995                              <1> 
 22996 00007C10 5E                  <1> 	pop	esi
 22997                              <1> 
 22998 00007C11 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 22999 00007C18 E880020000          <1> 	call	save_directory_buffer
 23000 00007C1D 0F83DA000000        <1>         jnc     loc_mkdir_set_ff_dir_entry_2
 23001                              <1> 
 23002                              <1> loc_mkdir_return:
 23003 00007C23 C3                  <1> 	retn
 23004                              <1> 
 23005                              <1> loc_mkdir_add_new_subdir_cluster:
 23006 00007C24 8B15[71CD0000]      <1> 	mov	edx, [DirBuff_Cluster]
 23007 00007C2A 8915[B8CF0000]      <1> 	mov	[mkdir_LastDirCluster], edx       
 23008                              <1> 
 23009 00007C30 A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23010 00007C35 E8DC160000          <1> 	call	load_FAT_sub_directory 
 23011 00007C3A 72E7                <1> 	jc	short loc_mkdir_return
 23012                              <1> 	; eax = 0
 23013                              <1> 	; ecx =  directory buffer sector count (<= 128)
 23014                              <1> 
 23015                              <1> pass_mkdir_add_new_subdir_cluster:
 23016 00007C3C 29FF                <1> 	sub	edi, edi ; 0
 23017                              <1> 	;mov	al, 128 ; double word
 23018                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
 23019                              <1> 	;mov	ecx, eax
 23020                              <1> 	;shl	cx, 7 ; 128 * sector count	
 23021 00007C3E 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
 23022 00007C42 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
 23023 00007C46 66F7E1              <1> 	mul	cx ; max = 128*(512/4) -> 16384 (stosd)
 23024 00007C49 6689C1              <1> 	mov	cx, ax
 23025 00007C4C 6629C0              <1> 	sub	ax, ax ; 0
 23026 00007C4F F3AB                <1> 	rep	stosd ; clear directory buffer
 23027                              <1> 
 23028 00007C51 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 23029 00007C58 E840020000          <1> 	call	save_directory_buffer 
 23030 00007C5D 72C4                <1> 	jc	short loc_mkdir_return
 23031                              <1> 
 23032                              <1> loc_mkdir_save_added_cluster:
 23033 00007C5F A1[B8CF0000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 23034 00007C64 8B0D[B4CF0000]      <1> 	mov	ecx, [mkdir_FFCluster]
 23035                              <1> 	; 01/03/2016
 23036 00007C6A 31D2                <1> 	xor	edx, edx
 23037 00007C6C 8915[61CD0000]      <1> 	mov	[FAT_ClusterCounter], edx ; 0 ; reset
 23038 00007C72 E8E3170000          <1> 	call	update_cluster
 23039 00007C77 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
 23040 00007C79 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 23041 00007C7B 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
 23042                              <1> 
 23043                              <1> loc_mkdir_save_fat_buffer_0:
 23044 00007C7D A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23045 00007C82 A3[B8CF0000]        <1> 	mov	[mkdir_LastDirCluster], eax
 23046                              <1> 
 23047 00007C87 31C9                <1> 	xor	ecx, ecx
 23048 00007C89 49                  <1> 	dec	ecx ; FFFFFFFFh
 23049                              <1> 	; ESI = Logical DOS Drive Description Table address 
 23050 00007C8A E8CB170000          <1> 	call	update_cluster
 23051 00007C8F 731A                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
 23052 00007C91 09C0                <1> 	or	eax, eax
 23053 00007C93 7416                <1> 	jz	short loc_mkdir_save_fat_buffer_1
 23054                              <1> 
 23055                              <1> loc_mkdir_save_fat_buffer_stc_retn:
 23056                              <1> 	; 01/03/2016
 23057 00007C95 803D[61CD0000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 23058 00007C9C 720C                <1> 	jb	short loc_mkdir_save_fat_buffer_retn
 23059                              <1> 
 23060 00007C9E 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
 23061                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
 23062 00007CA2 50                  <1> 	push	eax
 23063 00007CA3 E8041B0000          <1> 	call	calculate_fat_freespace
 23064 00007CA8 58                  <1> 	pop	eax
 23065 00007CA9 F9                  <1> 	stc
 23066                              <1> loc_mkdir_save_fat_buffer_retn:
 23067 00007CAA C3                  <1> 	retn
 23068                              <1> 
 23069                              <1> loc_mkdir_save_fat_buffer_1:
 23070                              <1> 	; byte [FAT_BuffValidData] = 2 
 23071 00007CAB E8671A0000          <1> 	call	save_fat_buffer
 23072 00007CB0 72E3                <1> 	jc	short loc_mkdir_save_fat_buffer_stc_retn
 23073                              <1> 
 23074                              <1> 	; 01/03/2016
 23075 00007CB2 803D[61CD0000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 23076 00007CB9 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_2
 23077                              <1> 
 23078                              <1> 	; ESI = Logical DOS Drive Description Table address 
 23079 00007CBB A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 23080 00007CC0 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 23081 00007CC4 E8E31A0000          <1> 	call	calculate_fat_freespace
 23082                              <1> 
 23083                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 23084                              <1> 	;jnz	short loc_mkdir_save_fat_buffer_2
 23085                              <1> 
 23086                              <1> 	; ecx > 0 -> Recalculation is needed
 23087 00007CC9 09C9                <1> 	or	ecx, ecx 
 23088 00007CCB 7409                <1> 	jz	short loc_mkdir_save_fat_buffer_2
 23089                              <1> 
 23090 00007CCD 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 23091 00007CD1 E8D61A0000          <1> 	call	calculate_fat_freespace
 23092                              <1> 
 23093                              <1> loc_mkdir_save_fat_buffer_2:
 23094 00007CD6 C605[C3CF0000]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
 23095 00007CDD E9C4000000          <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
 23096                              <1> 
 23097                              <1> loc_mkdir_update_sub_dir_cluster:
 23098 00007CE2 A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23099 00007CE7 29C9                <1> 	sub	ecx, ecx ; 0
 23100                              <1> 	; 01/03/2016
 23101 00007CE9 890D[61CD0000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; Reset
 23102 00007CEF 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 23103                              <1> 
 23104                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
 23105 00007CF0 E865170000          <1> 	call	update_cluster
 23106 00007CF5 7379                <1> 	jnc	short loc_mkdir_save_fat_buffer_3
 23107 00007CF7 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 23108 00007CF9 7475                <1> 	jz	short loc_mkdir_save_fat_buffer_3
 23109                              <1> 	; 01/03/2016
 23110 00007CFB EB98                <1> 	jmp	short loc_mkdir_save_fat_buffer_stc_retn
 23111                              <1> 
 23112                              <1> loc_mkdir_set_ff_dir_entry_2:
 23113                              <1> 	; ESI = Logical DOS Drive Description Table address  
 23114 00007CFD A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23115                              <1> 	; Load disk sectors as a directory cluster
 23116 00007D02 E80F160000          <1> 	call	load_FAT_sub_directory 
 23117 00007D07 7266                <1> 	jc	short retn_make_fat_directory
 23118                              <1> 	
 23119                              <1> 	; eax = 0
 23120                              <1> 	; ecx =  directory buffer sector count (<= 128)
 23121                              <1> 
 23122 00007D09 BF40000800          <1> 	mov	edi, Directory_Buffer + 64 ; 26/02/2016
 23123                              <1> 
 23124                              <1> 	; 02/03/2016
 23125 00007D0E 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
 23126 00007D12 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
 23127 00007D16 F7E1                <1> 	mul 	ecx
 23128 00007D18 89C1                <1> 	mov	ecx, eax
 23129 00007D1A 6629C0              <1> 	sub	ax, ax
 23130 00007D1D F3AB                <1> 	rep	stosd
 23131                              <1> 
 23132                              <1> 	;;mov	al, 128 ; double word
 23133                              <1> 	;;mul	ecx ; ecx =  directory buffer sector count
 23134                              <1> 	;;mov	ecx, eax
 23135                              <1> 	;shl	cx, 7 ; 128 * sector count	
 23136                              <1> 	;;sub	eax, eax
 23137                              <1> 	;;sub	al, al ; 0
 23138                              <1> 	;rep	stosd ; clear directory buffer
 23139                              <1> 
 23140 00007D1F BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
 23141                              <1> 	
 23142 00007D24 56                  <1> 	push	esi
 23143                              <1> 
 23144 00007D25 BE[C4CF0000]        <1> 	mov	esi, mkdir_Name
 23145 00007D2A 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
 23146                              <1> 
 23147 00007D2F A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23148 00007D34 66B91000            <1> 	mov	cx, 10h ; CL = Directory attribute
 23149                              <1> 			; CH = 0 -> File size is 0
 23150 00007D38 E883000000          <1> 	call	make_directory_entry
 23151                              <1> 
 23152 00007D3D BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
 23153                              <1> 
 23154                              <1> 	; 03/03/2016
 23155                              <1> 	; Following modification has been done according to 
 23156                              <1> 	; 'Microsoft Extensible Firmware Initiative
 23157                              <1> 	; FAT32 File System Specification' document,
 23158                              <1> 	; 'FAT: General Overview of On-Disk FormatPage 25'.
 23159                              <1> 	; "Finally, you set DIR_FstClusLO and DIR_FstClusHI
 23160                              <1> 	; for the dotdot entry (the second entry) to the
 23161                              <1> 	; first cluster number of the directory in which you 
 23162                              <1> 	; just created the directory (value is 0 if this directory
 23163                              <1> 	; is the root directory even for FAT32 volumes)."
 23164                              <1> 	; (Correctness of this modification has been verified
 23165                              <1> 	;  by using Windows 98 'scandisk.exe'.)
 23166                              <1> 
 23167 00007D42 29C0                <1> 	sub	eax, eax
 23168 00007D44 3805[40C50000]      <1> 	cmp	byte [Current_Dir_Level], al ; 0
 23169 00007D4A 7605                <1> 	jna	short loc_mkdir_set_ff_dir_entry_3
 23170 00007D4C A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
 23171                              <1> loc_mkdir_set_ff_dir_entry_3:
 23172 00007D51 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
 23173                              <1> 
 23174                              <1> 	;mov	cx, 10h
 23175 00007D57 E864000000          <1> 	call	make_directory_entry
 23176                              <1> 
 23177 00007D5C 5E                  <1> 	pop	esi
 23178                              <1> 
 23179 00007D5D C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 23180 00007D64 E834010000          <1> 	call	save_directory_buffer
 23181 00007D69 0F8373FFFFFF        <1>         jnc     loc_mkdir_update_sub_dir_cluster
 23182                              <1>  
 23183                              <1> retn_make_fat_directory:
 23184 00007D6F C3                  <1> 	retn
 23185                              <1> 
 23186                              <1> loc_mkdir_save_fat_buffer_3:
 23187                              <1> 	; 01/03/2016
 23188                              <1> 	; byte [FAT_BuffValidData] = 2 
 23189 00007D70 E8A2190000          <1> 	call	save_fat_buffer
 23190 00007D75 0F821AFFFFFF        <1>         jc      loc_mkdir_save_fat_buffer_stc_retn
 23191                              <1> 
 23192 00007D7B 803D[61CD0000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 23193 00007D82 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_4
 23194                              <1> 
 23195                              <1> 	; ESI = Logical DOS Drive Description Table address 
 23196 00007D84 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 23197 00007D89 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 23198 00007D8D E81A1A0000          <1> 	call	calculate_fat_freespace
 23199                              <1> 
 23200                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 23201                              <1>         ;jnz    short loc_mkdir_save_fat_buffer_4
 23202                              <1> 
 23203                              <1> 	; ecx > 0 -> Recalculation is needed
 23204 00007D92 09C9                <1> 	or	ecx, ecx 
 23205 00007D94 7409                <1>         jz      short loc_mkdir_save_fat_buffer_4
 23206                              <1> 
 23207 00007D96 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
 23208 00007D9A E80D1A0000          <1> 	call	calculate_fat_freespace
 23209                              <1> 
 23210                              <1> loc_mkdir_save_fat_buffer_4:	
 23211 00007D9F C605[C3CF0000]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
 23212                              <1> 
 23213                              <1> loc_mkdir_upd_parent_dir_lmdt:
 23214 00007DA6 E88D010000          <1> 	call	update_parent_dir_lmdt
 23215                              <1> 
 23216                              <1> 	; 01/03/2016
 23217 00007DAB 803D[C3CF0000]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
 23218 00007DB2 0F8723FEFFFF        <1>         ja      loc_mkdir_gffc_2
 23219                              <1> 
 23220                              <1> loc_mkdir_retn_new_dir_cluster:
 23221 00007DB8 A1[B4CF0000]        <1> 	mov	eax, [mkdir_FFCluster]
 23222 00007DBD 31D2                <1> 	xor	edx, edx
 23223                              <1> loc_mkdir_retn:
 23224 00007DBF C3                  <1> 	retn
 23225                              <1> 
 23226                              <1> make_directory_entry:
 23227                              <1> 	; 02/03/2016
 23228                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 23229                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
 23230                              <1> 	; 17/07/2010
 23231                              <1> 	; INPUT ->
 23232                              <1> 	; 	EDI = Directory Entry Address
 23233                              <1> 	;	ESI = Dot File Name Location
 23234                              <1> 	;	EAX = First Cluster
 23235                              <1> 	;	File Size = 0 (Must be set later)
 23236                              <1> 	;	CL = Attributes
 23237                              <1> 	;	CH = 0 (File size = 0) 
 23238                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
 23239                              <1> 	; OUTPUT -> 
 23240                              <1> 	;	EDI = Directory Entry Address
 23241                              <1> 	;	ESI = Dot File Name Location (Capitalized)
 23242                              <1> 	;	If CH input = 0, File Size = 0
 23243                              <1> 	;	Otherwise file size is as dword [EBX] (*)
 23244                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
 23245                              <1> 	;	EBX = same
 23246                              <1> 	;	ECX = same
 23247                              <1> 
 23248 00007DC0 51                  <1> 	push	ecx
 23249                              <1> 
 23250 00007DC1 884F0B              <1> 	mov	[edi+11], cl ; Attributes
 23251 00007DC4 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
 23252 00007DC8 C1E810              <1> 	shr	eax, 16
 23253 00007DCB 66894714            <1> 	mov	[edi+20], ax ; FClusterHw, 20
 23254 00007DCF 6631C0              <1> 	xor	ax, ax 
 23255 00007DD2 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
 23256                              <1> 			     ; CrtTimeTenth, 13
 23257 00007DD6 08ED                <1> 	or	ch, ch
 23258 00007DD8 7402                <1> 	jz	short loc_make_direntry_set_filesize
 23259                              <1> 
 23260 00007DDA 8B03                <1> 	mov	eax, [ebx]
 23261                              <1>         
 23262                              <1> loc_make_direntry_set_filesize:
 23263 00007DDC 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
 23264                              <1> 	
 23265 00007DDF E88AFBFFFF          <1> 	call	convert_file_name
 23266                              <1> 	;EDI = Dir Entry Format File Name Location
 23267                              <1> 	;ESI = Dot File Name Location (capitalized)
 23268                              <1> 
 23269 00007DE4 E816000000          <1> 	call	convert_current_date_time
 23270                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 23271                              <1>         ; 	    AX = Time in dos dir entry format
 23272 00007DE9 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
 23273 00007DED 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
 23274 00007DF1 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
 23275 00007DF5 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
 23276 00007DF9 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
 23277 00007DFD 59                  <1> 	pop	ecx
 23278                              <1> 
 23279 00007DFE C3                  <1> 	retn
 23280                              <1> 
 23281                              <1> convert_current_date_time:
 23282                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 23283                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
 23284                              <1> 	; converts date&time to dos dir entry format
 23285                              <1> 	; INPUT -> none
 23286                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 23287                              <1> 	;           AX = Time in dos dir entry format
 23288                              <1>  
 23289 00007DFF B404                <1> 	mov	ah, 04h ; Return Current Date
 23290 00007E01 E85EBDFFFF          <1> 	call	int1Ah 
 23291                              <1> 
 23292 00007E06 88E8                <1> 	mov	al, ch ; <- century BCD
 23293 00007E08 240F                <1> 	and	al, 0Fh
 23294 00007E0A 88EC                <1> 	mov	ah, ch
 23295 00007E0C C0EC04              <1> 	shr	ah, 4
 23296 00007E0F D50A                <1> 	aad
 23297 00007E11 88C5                <1> 	mov	ch, al ; -> century 
 23298                              <1> 
 23299 00007E13 88C8                <1> 	mov	al, cl ; <- year BCD
 23300 00007E15 240F                <1> 	and	al, 0Fh
 23301 00007E17 88CC                <1> 	mov	ah, cl
 23302 00007E19 C0EC04              <1> 	shr	ah, 4
 23303 00007E1C D50A                <1> 	aad
 23304 00007E1E 88C1                <1> 	mov	cl, al ; -> year
 23305                              <1> 
 23306 00007E20 88E8                <1> 	mov	al, ch
 23307 00007E22 B464                <1> 	mov	ah, 100
 23308 00007E24 F6E4                <1> 	mul	ah
 23309 00007E26 30ED                <1> 	xor	ch, ch
 23310 00007E28 6601C8              <1> 	add	ax, cx
 23311 00007E2B 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
 23312 00007E2F 6689C1              <1> 	mov	cx, ax
 23313                              <1> 
 23314 00007E32 88F0                <1> 	mov	al, dh ; <- month in bcd
 23315 00007E34 240F                <1> 	and	al, 0Fh
 23316 00007E36 88F4                <1> 	mov	ah, dh
 23317 00007E38 C0EC04              <1> 	shr	ah, 4
 23318 00007E3B D50A                <1> 	aad
 23319 00007E3D 88C6                <1> 	mov	dh, al ; -> month
 23320                              <1> 
 23321 00007E3F 88D0                <1> 	mov	al, dl ; <- day BCD
 23322 00007E41 240F                <1> 	and	al, 0Fh
 23323 00007E43 88D4                <1> 	mov	ah, dl
 23324 00007E45 C0EC04              <1> 	shr	ah, 4
 23325 00007E48 D50A                <1> 	aad
 23326 00007E4A 88C2                <1> 	mov	dl, al ; -> day
 23327                              <1> 
 23328 00007E4C 88C8                <1> 	mov	al, cl ; count of years from 1980
 23329 00007E4E 66C1E004            <1> 	shl	ax, 4
 23330 00007E52 08F0                <1> 	or	al, dh ; month of year, 1 to 12
 23331 00007E54 66C1E005            <1> 	shl	ax, 5
 23332 00007E58 08D0                <1> 	or	al, dl ; day of year, 1 to 31
 23333                              <1> 	
 23334 00007E5A 6650                <1> 	push	ax ; push date
 23335                              <1> 
 23336 00007E5C B402                <1> 	mov	ah, 02h ; Return Current Time
 23337 00007E5E E801BDFFFF          <1> 	call	int1Ah
 23338                              <1> 
 23339 00007E63 88E8                <1> 	mov	al, ch ; <- hours BCD
 23340 00007E65 240F                <1> 	and	al, 0Fh
 23341 00007E67 88EC                <1> 	mov	ah, ch
 23342 00007E69 C0EC04              <1> 	shr	ah, 4
 23343 00007E6C D50A                <1> 	aad
 23344 00007E6E 88C5                <1> 	mov	ch, al ; -> hours
 23345                              <1> 
 23346 00007E70 88C8                <1> 	mov	al, cl ; <- minutes BCD
 23347 00007E72 240F                <1> 	and	al, 0Fh
 23348 00007E74 88CC                <1> 	mov	ah, cl
 23349 00007E76 C0EC04              <1> 	shr	ah, 4
 23350 00007E79 D50A                <1> 	aad
 23351 00007E7B 88C1                <1> 	mov	cl, al ; -> minutes
 23352                              <1> 
 23353 00007E7D 88F0                <1> 	mov	al, dh ; <- seconds BCD
 23354 00007E7F 240F                <1> 	and	al, 0Fh
 23355 00007E81 88F4                <1> 	mov	ah, dh
 23356 00007E83 C0EC04              <1> 	shr	ah, 4
 23357 00007E86 D50A                <1> 	aad
 23358 00007E88 88C6                <1> 	mov	dh, al ; -> seconds
 23359                              <1> 
 23360 00007E8A 88E8                <1> 	mov	al, ch ; hours
 23361 00007E8C 66C1E006            <1> 	shl	ax, 6
 23362 00007E90 08C8                <1> 	or	al, cl ; minutes
 23363 00007E92 66C1E005            <1> 	shl	ax, 5
 23364 00007E96 D0EE                <1> 	shr	dh, 1 ; 2 seconds
 23365                              <1> 	; There is a bug in TRDOS v1 here !
 23366                              <1> 	; it was 'or al, dl' ! 
 23367 00007E98 08F0                <1> 	or	al, dh ; seconds
 23368                              <1> 
 23369 00007E9A 665A                <1> 	pop	dx ; pop date
 23370                              <1> 	
 23371 00007E9C C3                  <1> 	retn
 23372                              <1> 
 23373                              <1> save_directory_buffer:
 23374                              <1> 	; 23/03/2016
 23375                              <1> 	; 26/02/2016
 23376                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 23377                              <1> 	; 01/08/2011
 23378                              <1> 	; 14/03/2010
 23379                              <1> 	; INPUT ->
 23380                              <1> 	; 	 none
 23381                              <1> 	; OUTPUT ->
 23382                              <1> 	;  cf = 0 -> write OK...
 23383                              <1> 	;  cf = 1 -> error code in AL (EAX)
 23384                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
 23385                              <1> 	;  EBX = Directory Buffer Address
 23386                              <1> 	;
 23387                              <1> 	;  (EAX, ECX, EDX will be modified)
 23388                              <1>  
 23389 00007E9D BB00000800          <1> 	mov	ebx, Directory_Buffer
 23390 00007EA2 803D[6CCD0000]02    <1> 	cmp	byte [DirBuff_ValidData], 2
 23391 00007EA9 7403                <1> 	je	short loc_save_dir_buffer
 23392 00007EAB 31C0                <1> 	xor	eax, eax
 23393 00007EAD C3                  <1> 	retn            
 23394                              <1> 
 23395                              <1> loc_save_dir_buffer:
 23396 00007EAE 56                  <1> 	push	esi
 23397 00007EAF 31DB                <1> 	xor	ebx, ebx 
 23398 00007EB1 8A3D[6ACD0000]      <1>         mov     bh, [DirBuff_DRV]
 23399 00007EB7 80EF41              <1> 	sub	bh, 'A'
 23400 00007EBA BE00010900          <1>         mov     esi, Logical_DOSDisks
 23401 00007EBF 01DE                <1> 	add	esi, ebx
 23402 00007EC1 668B4E03            <1>         mov     cx, [esi+LD_FATType]
 23403                              <1> 	; CH = FS Type (A1h for FS)
 23404                              <1> 	; CL = FAT Type (0 for FS)
 23405 00007EC5 08C9                <1> 	or	cl, cl
 23406 00007EC7 7433                <1> 	jz	short loc_save_dir_buff_stc_retn
 23407                              <1> 
 23408                              <1> loc_save_dir_buffer_check_cluster_no:    
 23409 00007EC9 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 23410 00007ECE 28FF                <1> 	sub	bh, bh ; ebx = 0
 23411 00007ED0 09C0                <1> 	or	eax, eax
 23412 00007ED2 7540                <1> 	jnz	short loc_save_sub_dir_buffer
 23413 00007ED4 8A25[6BCD0000]      <1> 	mov	ah, [DirBuff_FATType]
 23414 00007EDA FEC3                <1> 	inc	bl ;  bl = 1
 23415 00007EDC 38DC                <1> 	cmp	ah, bl
 23416 00007EDE 721D                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 23417 00007EE0 FEC3                <1> 	inc	bl ; bl = 2
 23418 00007EE2 38E3                <1> 	cmp	bl, ah
 23419 00007EE4 7217                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 23420                              <1> 
 23421                              <1> loc_save_root_dir_buffer:
 23422 00007EE6 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
 23423 00007EEA 6683C30F            <1> 	add	bx, 15
 23424 00007EEE 66C1EB04            <1> 	shr	bx, 4 ; 16 dir entries per sector
 23425 00007EF2 6609DB              <1> 	or	bx, bx
 23426 00007EF5 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
 23427                              <1> 	;mov	ecx, ebx 
 23428 00007EF7 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
 23429 00007EFA EB23                <1> 	jmp	short loc_write_directory_to_disk
 23430                              <1> 
 23431                              <1> loc_save_dir_buff_stc_retn:
 23432 00007EFC F9                  <1> 	stc
 23433                              <1> loc_save_dir_buff_inv_data_retn:
 23434 00007EFD B00D                <1> 	mov	al, 0Dh ; Invalid data !
 23435 00007EFF C605[6CCD0000]00    <1> 	mov	byte [DirBuff_ValidData], 0
 23436 00007F06 EB05                <1> 	jmp	short loc_save_dir_buff_retn 
 23437                              <1> 
 23438                              <1> loc_write_directory_to_disk_err:
 23439                              <1> 	; 23/03/2016
 23440 00007F08 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error 
 23441                              <1> 
 23442                              <1> loc_save_dir_buff_retn:
 23443 00007F0D BB00000800          <1> 	mov	ebx, Directory_Buffer
 23444 00007F12 5E                  <1> 	pop	esi
 23445 00007F13 C3                  <1> 	retn
 23446                              <1>  
 23447                              <1> loc_save_sub_dir_buffer:
 23448                              <1> 	; ebx  = 0
 23449 00007F14 83E802              <1> 	sub	eax, 2
 23450 00007F17 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 23451 00007F1A F7E3                <1> 	mul	ebx
 23452 00007F1C 034668              <1>         add     eax, [esi+LD_DATABegin]
 23453                              <1>  	;mov	ecx, ebx
 23454                              <1> 
 23455                              <1> loc_write_directory_to_disk:
 23456 00007F1F 89D9                <1>  	mov	ecx, ebx
 23457 00007F21 BB00000800          <1> 	mov	ebx, Directory_Buffer
 23458 00007F26 E882320000          <1> 	call	disk_write
 23459 00007F2B 72DB                <1> 	jc	short loc_write_directory_to_disk_err
 23460                              <1> 
 23461                              <1> loc_save_dir_buff_validate_retn:
 23462 00007F2D C605[6CCD0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 23463 00007F34 31C0                <1> 	xor	eax, eax
 23464                              <1> 	; 26/02/2016
 23465 00007F36 EBD5                <1> 	jmp	short loc_save_dir_buff_retn
 23466                              <1> 
 23467                              <1> update_parent_dir_lmdt:
 23468                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 23469                              <1> 	; 01/08/2011
 23470                              <1> 	; 16/10/2010 
 23471                              <1> 	; 
 23472                              <1> 	; INPUT -> 
 23473                              <1> 	;	none
 23474                              <1>  	; OUTPUT ->
 23475                              <1> 	;	(last modification date & time of the parent dir
 23476                              <1> 	;	will be changed/updated)
 23477                              <1> 	;
 23478                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
 23479                              <1> 
 23480 00007F38 29C0                <1> 	sub	eax, eax
 23481 00007F3A 8A25[40C50000]      <1> 	mov	ah, [Current_Dir_Level]
 23482 00007F40 A0[41C50000]        <1> 	mov	al, [Current_FATType]
 23483 00007F45 3C01                <1> 	cmp	al, 1
 23484 00007F47 723A                <1> 	jb	short loc_UPDLMDT_proc_retn
 23485                              <1>     
 23486                              <1> loc_update_parent_dir_lm_date_time:
 23487 00007F49 08E4                <1> 	or	ah, ah
 23488 00007F4B 7436                <1> 	jz	short loc_UPDLMDT_proc_retn
 23489                              <1> 
 23490 00007F4D 56                  <1> 	push	esi ; *
 23491 00007F4E 8825[E4CF0000]      <1> 	mov	[UPDLMDT_CDirLevel], ah
 23492 00007F54 8B15[3CC50000]      <1> 	mov	edx, [Current_Dir_FCluster]
 23493 00007F5A 8915[E5CF0000]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
 23494                              <1> 
 23495 00007F60 FECC                <1> 	dec	ah
 23496 00007F62 B90C000000          <1> 	mov	ecx, 12
 23497 00007F67 BE[A3CD0000]        <1>         mov     esi, PATH_Array
 23498                              <1> 
 23499 00007F6C 8825[40C50000]      <1> 	mov	[Current_Dir_Level], ah
 23500 00007F72 08E4                <1> 	or	ah, ah
 23501 00007F74 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
 23502 00007F76 803D[41C50000]02    <1> 	cmp	byte [Current_FATType], 2
 23503 00007F7D 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
 23504 00007F7F 28C0                <1> 	sub	al, al ; eax = 0
 23505 00007F81 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
 23506                              <1> 
 23507                              <1> loc_UPDLMDT_proc_retn:
 23508 00007F83 C3                  <1> 	retn
 23509                              <1>          
 23510                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
 23511 00007F84 B010                <1> 	mov	al, 16
 23512 00007F86 F6E4                <1> 	mul	ah 
 23513 00007F88 01C6                <1> 	add	esi, eax
 23514                              <1> 
 23515                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:  
 23516 00007F8A 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
 23517                              <1> 
 23518                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
 23519 00007F8D A3[3CC50000]        <1> 	mov	[Current_Dir_FCluster], eax
 23520                              <1> 
 23521 00007F92 83C610              <1> 	add	esi, 16
 23522 00007F95 66BF[CACE]          <1> 	mov	di, Dir_File_Name  
 23523 00007F99 F3A4                <1> 	rep	movsb
 23524                              <1> 	
 23525 00007F9B BE00010900          <1> 	mov	esi, Logical_DOSDisks
 23526 00007FA0 29DB                <1> 	sub	ebx, ebx
 23527 00007FA2 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 23528 00007FA8 01DE                <1> 	add	esi, ebx
 23529 00007FAA E88FF7FFFF          <1> 	call	reload_current_directory
 23530 00007FAF 7232                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 23531                              <1> 
 23532                              <1> loc_update_parent_dir_lmdt_locate_dir: 
 23533 00007FB1 BE[CACE0000]        <1> 	mov	esi, Dir_File_Name        
 23534 00007FB6 6631C9              <1> 	xor	cx, cx
 23535 00007FB9 66B81008            <1> 	mov	ax, 0810h ; Only directories
 23536 00007FBD E8B7F6FFFF          <1>         call    locate_current_dir_file
 23537                              <1> 	; EDI = DirBuff Directory Entry Address
 23538 00007FC2 721F                <1> 	jc short loc_update_parent_dir_lmdt_restore_cdirlevel
 23539                              <1> 
 23540 00007FC4 E836FEFFFF          <1> 	call	convert_current_date_time
 23541 00007FC9 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
 23542 00007FCD 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
 23543 00007FD1 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
 23544                              <1> 
 23545 00007FD5 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 23546 00007FDC E8BCFEFFFF          <1> 	call	save_directory_buffer
 23547 00007FE1 7200                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 23548                              <1> 	;xor	al, al 
 23549                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
 23550                              <1>  	;current directory level restoration
 23551 00007FE3 8A25[E4CF0000]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
 23552 00007FE9 8825[40C50000]      <1> 	mov	[Current_Dir_Level], ah
 23553 00007FEF 8B15[E5CF0000]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
 23554 00007FF5 8915[3CC50000]      <1> 	mov	[Current_Dir_FCluster], edx
 23555                              <1> 
 23556 00007FFB 5E                  <1> 	pop	esi ; *
 23557 00007FFC C3                  <1> 	retn
 23558                              <1> 
 23559                              <1> delete_longname:
 23560                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 23561                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
 23562                              <1> 	; 14/03/2010
 23563                              <1> 	; INPUT ->
 23564                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
 23565                              <1> 	; OUTPUT ->
 23566                              <1> 	;	cf = 0 -> OK  (EAX = 0)
 23567                              <1> 	; 	cf = 1 -> error code in EAX (AL)
 23568                              <1> 	;
 23569                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 23570                              <1> 
 23571 00007FFD 66A3[10D00000]      <1> 	mov	[DLN_EntryNumber], ax
 23572 00008003 C605[12D00000]40    <1>         mov     byte [DLN_40h], 40h
 23573                              <1> 
 23574 0000800A E858000000          <1> 	call	locate_current_dir_entry
 23575 0000800F 7308                <1> 	jnc	short loc_dln_check_attributes
 23576 00008011 C3                  <1> 	retn
 23577                              <1> 
 23578                              <1> loc_dln_longname_not_found:
 23579 00008012 B802000000          <1> 	mov	eax, 2
 23580 00008017 F9                  <1> 	stc
 23581 00008018 C3                  <1> 	retn
 23582                              <1> 
 23583                              <1> loc_dln_check_attributes:
 23584 00008019 B00F                <1> 	mov	al, 0Fh  ; long name
 23585 0000801B 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
 23586 0000801E 38C4                <1> 	cmp	ah, al
 23587 00008020 75F0                <1> 	jne	short loc_dln_longname_not_found
 23588 00008022 8A27                <1> 	mov	ah, [edi]
 23589 00008024 2A25[12D00000]      <1> 	sub	ah, [DLN_40h]
 23590 0000802A 76E6                <1> 	jna	short loc_dln_longname_not_found         
 23591 0000802C 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
 23592 0000802F 77E1                <1> 	ja	short loc_dln_longname_not_found
 23593                              <1>              
 23594 00008031 C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
 23595 00008034 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
 23596 0000803B C605[12D00000]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
 23597                              <1> 	  
 23598                              <1> loc_dln_delete_next_ln_entry:
 23599 00008042 80FC01              <1> 	cmp	ah, 1
 23600 00008045 7616                <1> 	jna	short loc_dln_longname_retn
 23601                              <1> loc_dln_delete_next_ln_entry_0:
 23602 00008047 66FF05[10D00000]    <1> 	inc	word [DLN_EntryNumber]
 23603 0000804E 0FB705[10D00000]    <1> 	movzx	eax, word [DLN_EntryNumber] 
 23604 00008055 E80D000000          <1> 	call	locate_current_dir_entry
 23605 0000805A 73BD                <1> 	jnc	short loc_dln_check_attributes
 23606                              <1> 
 23607                              <1> loc_dln_longname_stc_retn:
 23608 0000805C C3                  <1> 	retn 
 23609                              <1> 	   
 23610                              <1> loc_dln_longname_retn:
 23611                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 23612                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
 23613 0000805D E83BFEFFFF          <1> 	call	save_directory_buffer
 23614 00008062 72F8                <1> 	jc	short loc_dln_longname_stc_retn
 23615                              <1> 
 23616                              <1> loc_dln_longname_retn_xor_eax:
 23617 00008064 31C0                <1> 	xor	eax, eax
 23618 00008066 C3                  <1> 	retn
 23619                              <1> 
 23620                              <1> locate_current_dir_entry:
 23621                              <1> 	; 23/03/2016
 23622                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 23623                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
 23624                              <1> 	; 07/03/2010
 23625                              <1> 	; INPUT ->
 23626                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536) 
 23627                              <1> 	; OUTPUT ->
 23628                              <1> 	;	EDI = Directory Entry Address
 23629                              <1> 	; 	EAX = Cluster Number of Directory Buffer
 23630                              <1> 	;	EBX = Directory Buffer Entry Offset
 23631                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
 23632                              <1> 	;   	If CF = 0 and CL = 2 then
 23633                              <1> 	;	   directory buffer modified and
 23634                              <1> 	;	   must be written to disk.
 23635                              <1> 	; 	If CF = 0  and CL = 1 then
 23636                              <1> 	;	   dir buffer has been written to disk, already.
 23637                              <1> 	;	CF = 1 -> Error code in EAX (AL)
 23638                              <1> 	;
 23639                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 23640                              <1> 
 23641                              <1> loc_locate_current_dir_entry:
 23642 00008067 56                  <1> 	push	esi
 23643 00008068 89C1                <1> 	mov	ecx, eax
 23644 0000806A BA20000000          <1> 	mov	edx, 32
 23645 0000806F F7E2                <1> 	mul	edx 
 23646 00008071 A3[1CD00000]        <1> 	mov	[LCDE_ByteOffset], eax
 23647 00008076 31DB                <1> 	xor	ebx, ebx
 23648 00008078 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 23649 0000807E A0[6ACD0000]        <1>         mov     al, [DirBuff_DRV]
 23650 00008083 2C41                <1> 	sub	al, 'A'
 23651 00008085 BE00010900          <1>         mov     esi, Logical_DOSDisks
 23652 0000808A 01DE                <1> 	add	esi, ebx
 23653 0000808C 38C7                <1> 	cmp	bh, al
 23654 0000808E 0F8592000000        <1>         jne     loc_lcde_reload_current_directory
 23655                              <1> loc_lcde_cdl_check:
 23656 00008094 803D[40C50000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 23657 0000809B 772A                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
 23658                              <1> 	; 27/02/2016
 23659                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 23660                              <1> 	; (Root Directory Entries for FAT32 = 0)
 23661 0000809D 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 23662 000080A1 7324                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
 23663                              <1> 
 23664                              <1> loc_lcde_cdl_check_FAT12_16:
 23665 000080A3 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
 23666 000080A7 6648                <1> 	dec	ax
 23667                              <1> 	;xor	dx, dx  
 23668 000080A9 6639C8              <1> 	cmp	ax, cx ; cx = Directory Entry (Index) Number
 23669 000080AC 720E                <1> 	jb	short loc_lcde_stc_12h_retn
 23670 000080AE 66890D[14D00000]    <1> 	mov	[LCDE_EntryIndex], cx
 23671 000080B5 31C0                <1> 	xor	eax, eax
 23672 000080B7 E993000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
 23673                              <1> 
 23674                              <1> loc_lcde_stc_12h_retn:
 23675 000080BC 5E                  <1> 	pop	esi
 23676 000080BD 89CB                <1> 	mov	ebx, ecx
 23677 000080BF 89D1                <1> 	mov	ecx, edx
 23678 000080C1 B812000000          <1> 	mov	eax, 12h ; No more files
 23679 000080C6 C3                  <1> 	retn 
 23680                              <1> 
 23681                              <1> loc_lcde_calc_dirbuff_cluster_offset:
 23682 000080C7 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 23683 000080CA 30FF                <1> 	xor	bh, bh
 23684 000080CC 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
 23685 000080D0 66F7E3              <1> 	mul	bx
 23686 000080D3 6609D2              <1>  	or	dx, dx ; If bytes per cluster > 32KB it is invalid
 23687 000080D6 755D                <1> 	jnz	short loc_lcde_invalid_format
 23688                              <1> 	;mov	ecx, eax
 23689 000080D8 6689C1              <1> 	mov	cx, ax ; BYTES PER CLUSTER
 23690 000080DB A1[1CD00000]        <1> 	mov	eax, [LCDE_ByteOffset]
 23691                              <1> 	;sub	edx, edx
 23692 000080E0 F7F1                <1> 	div	ecx
 23693 000080E2 3DFFFF0000          <1> 	cmp	eax, 65535
 23694 000080E7 774C                <1> 	ja	short loc_lcde_invalid_format
 23695                              <1> 
 23696                              <1> 	; cluster sequence number of directory (< 65536)
 23697 000080E9 66A3[16D00000]      <1> 	mov	[LCDE_ClusterSN], ax 
 23698                              <1> 
 23699 000080EF 6689D0              <1> 	mov	ax, dx ; byte offset in cluster (directory buffer)
 23700 000080F2 66BB2000            <1> 	mov	bx, 32 ; ; 1 dir entry = 32 bytes
 23701 000080F6 6629D2              <1>         sub     dx, dx  ; 0
 23702 000080F9 66F7F3              <1> 	div	bx 
 23703 000080FC 66A3[14D00000]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
 23704                              <1> 				      ; (in directory buffer/cluster)	  
 23705                              <1> loc_lcde_get_current_sub_dir_fcluster:
 23706 00008102 A1[3CC50000]        <1> 	mov	eax, [Current_Dir_FCluster]
 23707                              <1> 
 23708                              <1> loc_lcde_get_next_cluster:
 23709 00008107 66833D[16D00000]00  <1> 	cmp	word [LCDE_ClusterSN], 0
 23710 0000810F 763E                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
 23711 00008111 A3[18D00000]        <1> 	mov	[LCDE_Cluster], eax
 23712 00008116 E815100000          <1> 	call	get_next_cluster
 23713 0000811B 7220                <1> 	jc	short loc_lcde_check_gnc_error
 23714 0000811D 66FF0D[16D00000]    <1>   	dec	word [LCDE_ClusterSN]
 23715 00008124 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
 23716                              <1> 
 23717                              <1> loc_lcde_reload_current_directory:
 23718 00008126 51                  <1> 	push	ecx
 23719 00008127 E812F6FFFF          <1> 	call	reload_current_directory
 23720 0000812C 59                  <1> 	pop	ecx
 23721 0000812D 0F8361FFFFFF        <1>         jnc     loc_lcde_cdl_check
 23722 00008133 5E                  <1> 	pop	esi
 23723 00008134 C3                  <1> 	retn
 23724                              <1> 
 23725                              <1> loc_lcde_invalid_format:
 23726 00008135 B80B000000          <1> 	mov	eax, 0Bh ; MSDOS Error code: Invalid Format
 23727                              <1> 	;mov	eax, 0Dh ; MSDOS Error code: Invalid Data
 23728                              <1> loc_lcde_drive_not_ready_read_err:
 23729 0000813A F9                  <1> 	stc
 23730 0000813B 5E                  <1> 	pop	esi 
 23731 0000813C C3                  <1> 	retn  
 23732                              <1> 
 23733                              <1> loc_lcde_check_gnc_error:
 23734 0000813D 09C0                <1> 	or	eax, eax
 23735 0000813F 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
 23736 00008141 66FF0D[16D00000]    <1> 	dec	word [LCDE_ClusterSN]
 23737 00008148 75EB                <1> 	jnz	short loc_lcde_invalid_format 
 23738 0000814A A1[18D00000]        <1> 	mov	eax, [LCDE_Cluster]
 23739                              <1> 
 23740                              <1> loc_lcde_check_dir_buffer_cluster:
 23741 0000814F 3B05[71CD0000]      <1> 	cmp	eax, [DirBuff_Cluster]
 23742 00008155 755C                <1> 	jne	short loc_lcde_load_dir_cluster
 23743 00008157 803D[6CCD0000]00    <1> 	cmp	byte [DirBuff_ValidData], 0
 23744 0000815E 7727                <1> 	ja	short lcde_check_dir_buffer_cluster_next
 23745 00008160 803D[40C50000]00    <1> 	cmp	byte [Current_Dir_Level], 0    
 23746 00008167 775F                <1> 	ja	short loc_lcde_load_dir_cluster_0
 23747                              <1> 	; 27/02/2016
 23748                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 23749 00008169 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 23750 0000816D 7359                <1> 	jnb	short loc_lcde_load_dir_cluster_0
 23751                              <1> 	;
 23752 0000816F 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
 23753 00008173 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
 23754 00008177 66C1E904            <1> 	shr	cx, 4 ; 1 sector contains 16 dir entries	
 23755                              <1> 
 23756 0000817B 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
 23757 0000817E EB54                <1> 	jmp	short loc_lcde_load_dir_cluster_1 
 23758                              <1> 
 23759                              <1> loc_lcde_validate_dirBuff:
 23760 00008180 C605[6CCD0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 23761                              <1> 
 23762                              <1> lcde_check_dir_buffer_cluster_next:
 23763 00008187 0FB71D[14D00000]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
 23764 0000818E 663B1D[6FCD0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 23765 00008195 779E                <1> 	ja	short loc_lcde_invalid_format 
 23766 00008197 B820000000          <1> 	mov	eax, 32
 23767 0000819C F7E3                <1> 	mul	ebx
 23768                              <1> 	;or	edx, edx
 23769                              <1> 	;jnz	short loc_lcde_invalid_format
 23770                              <1> 
 23771 0000819E BF00000800          <1> 	mov	edi, Directory_Buffer  
 23772 000081A3 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
 23773                              <1> 
 23774                              <1> loc_lcde_dir_buffer_last_check:
 23775 000081A5 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 23776 000081AA 0FB60D[6CCD0000]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
 23777                              <1> 
 23778                              <1> loc_lcde_retn:
 23779 000081B1 5E                  <1> 	pop	esi
 23780 000081B2 C3                  <1> 	retn
 23781                              <1> 
 23782                              <1> loc_lcde_load_dir_cluster:
 23783                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 23784                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
 23785 000081B3 50                  <1> 	push	eax
 23786 000081B4 E8E4FCFFFF          <1> 	call	save_directory_buffer
 23787 000081B9 58                  <1> 	pop	eax
 23788 000081BA 72F5                <1> 	jc	short loc_lcde_retn
 23789                              <1> 
 23790                              <1> loc_lcde_load_dir_cluster_n2:
 23791 000081BC C605[6CCD0000]00    <1> 	mov	byte [DirBuff_ValidData], 0
 23792 000081C3 A3[71CD0000]        <1> 	mov	[DirBuff_Cluster], eax
 23793                              <1> 
 23794                              <1> loc_lcde_load_dir_cluster_0:
 23795 000081C8 83E802              <1> 	sub	eax, 2
 23796 000081CB 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 23797 000081CF F7E1                <1> 	mul	ecx
 23798 000081D1 034668              <1>         add     eax, [esi+LD_DATABegin]
 23799                              <1> 
 23800                              <1> loc_lcde_load_dir_cluster_1:
 23801 000081D4 BB00000800          <1> 	mov	ebx, Directory_Buffer
 23802                              <1> 	; ecx = sector count
 23803 000081D9 E8DE2F0000          <1> 	call	disk_read
 23804 000081DE 73A0                <1> 	jnc	short loc_lcde_validate_dirBuff
 23805                              <1> 
 23806                              <1> 	; 23/03/2016
 23807 000081E0 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
 23808 000081E5 EBCA                <1> 	jmp	short loc_lcde_retn
 23809                              <1> 
 23810                              <1> 
 23811                              <1> remove_file:
 23812                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 23813                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
 23814                              <1> 	; 09/08/2010
 23815                              <1> 	; INPUT ->
 23816                              <1> 	;	EDI = Directory Buffer Entry Address
 23817                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 23818                              <1> 	;	 BL = Longname Entry Length
 23819                              <1> 	;	 BH = Logical DOS Drive Number 
 23820                              <1> 
 23821 000081E7 29C0                <1> 	sub	eax, eax
 23822 000081E9 88FC                <1> 	mov	ah, bh
 23823 000081EB BE00010900          <1> 	mov	esi, Logical_DOSDisks
 23824 000081F0 01C6                <1> 	add	esi, eax
 23825                              <1> 
 23826 000081F2 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 23827 000081F6 7312                <1> 	jnb	short loc_del_fat_file 
 23828                              <1>               
 23829 000081F8 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 23830 000081FC 7406                <1> 	je	short loc_del_fs_file
 23831                              <1> 
 23832                              <1> loc_del_file_invalid_format:
 23833 000081FE 30E4                <1> 	xor	ah, ah
 23834 00008200 B00B                <1> 	mov	al, 0Bh ; Invalid Format
 23835 00008202 F9                  <1> 	stc 
 23836 00008203 C3                  <1> 	retn
 23837                              <1> 
 23838                              <1> loc_del_fs_file:
 23839 00008204 E8200F0000          <1> 	call	delete_fs_file
 23840 00008209 C3                  <1> 	retn
 23841                              <1> 
 23842                              <1> loc_del_fat_file:
 23843 0000820A E808000000          <1> 	call	delete_directory_entry
 23844 0000820F 7205                <1> 	jc	short loc_del_file_err_retn 
 23845                              <1> 
 23846                              <1> loc_delfile_unlink_cluster_chain:
 23847 00008211 E834170000          <1> 	call	truncate_cluster_chain
 23848                              <1> 	;jc	short loc_del_file_err_retn
 23849                              <1> 
 23850                              <1> loc_delfile_return:
 23851                              <1> loc_del_file_err_retn:
 23852 00008216 C3                  <1> 	retn
 23853                              <1> 
 23854                              <1> delete_directory_entry:
 23855                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 23856                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
 23857                              <1> 	; 10/04/2011 
 23858                              <1> 	; INPUT ->
 23859                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
 23860                              <1> 	;	EDI = Directory Buffer Entry Address
 23861                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 23862                              <1> 	;	 BL = Longname Entry Length
 23863                              <1> 	; OUTPUT ->
 23864                              <1> 	; 	ESI = Logical dos drive descripton table address 
 23865                              <1> 	;	EAX = First cluster to be truncated/unlinked
 23866                              <1> 	;       CF = 1 -> Error code in EAX (AL)
 23867                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
 23868                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
 23869                              <1> 	;
 23870                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
 23871                              <1> 
 23872 00008217 881D[AECF0000]      <1> 	mov	[DelFile_LNEL], bl
 23873 0000821D 66890D[ACCF0000]    <1> 	mov	[DelFile_EntryCounter], cx
 23874                              <1> 
 23875 00008224 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 23876 00008228 C1E010              <1> 	shl	eax, 16
 23877 0000822B 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 23878                              <1> 
 23879 0000822F A3[A8CF0000]        <1> 	mov	[DelFile_FCluster], eax
 23880                              <1> 
 23881                              <1> loc_del_short_name:
 23882 00008234 C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
 23883                              <1> 
 23884 00008237 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 23885 0000823E E85AFCFFFF          <1> 	call	save_directory_buffer
 23886 00008243 723D                <1> 	jc	short loc_delete_direntry_err_return
 23887                              <1>  
 23888                              <1> loc_del_long_name:
 23889 00008245 0FB615[AECF0000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 23890 0000824C 08D2                <1> 	or	dl, dl
 23891 0000824E 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
 23892                              <1> 
 23893 00008250 8835[AECF0000]      <1> 	mov	byte [DelFile_LNEL], dh ; 0              
 23894                              <1>   
 23895 00008256 0FB705[ACCF0000]    <1> 	movzx	eax,  word [DelFile_EntryCounter]
 23896 0000825D 29D0                <1> 	sub	eax, edx
 23897                              <1> 	;jnc	short loc_del_long_name_continue
 23898 0000825F 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date   
 23899                              <1> 
 23900                              <1> ;loc_del_direntry_inv_data_return:
 23901                              <1> ;	mov	eax, 0Dh ; Invalid data
 23902                              <1> ;	retn
 23903                              <1> 
 23904                              <1> loc_del_long_name_continue: 
 23905                              <1> 	; AX = Directory Entry Number of the long name last entry
 23906 00008261 E897FDFFFF          <1> 	call	delete_longname
 23907                              <1> 	;jc	short loc_delete_direntry_err_return
 23908                              <1> 
 23909                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
 23910 00008266 801D[AECF0000]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
 23911                              <1> 
 23912 0000826D E8C6FCFFFF          <1> 	call	update_parent_dir_lmdt
 23913 00008272 B700                <1> 	mov	bh, 0
 23914 00008274 80D700              <1> 	adc	bh, 0
 23915                              <1> 
 23916 00008277 8A1D[AECF0000]      <1> 	mov	bl, byte [DelFile_LNEL]
 23917                              <1>  
 23918                              <1> loc_delete_direntry_return:
 23919 0000827D A1[A8CF0000]        <1> 	mov	eax, [DelFile_FCluster]
 23920                              <1> loc_delete_direntry_err_return:
 23921 00008282 C3                  <1> 	retn
 23922                              <1> 
 23923                              <1> rename_directory_entry:
 23924                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
 23925                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_rename_directory_entry')
 23926                              <1> 	; 19/11/2010
 23927                              <1> 	; INPUT -> (Current Directory)
 23928                              <1> 	;	CX = Directory Entry Number
 23929                              <1> 	;      EAX = First Cluster number of file or directory
 23930                              <1> 	;      EBX = Longname Length (dir entry count) (< 256)
 23931                              <1> 	;      ESI = New file (or directory) name (no path).
 23932                              <1> 	;           (ASCIIZ string)  
 23933                              <1> 	; OUTPUT -> 
 23934                              <1> 	;      CF = 0 -> successfull
 23935                              <1> 	;      CF = 1 -> error code in EAX (AL)
 23936                              <1> 	;
 23937                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 23938                              <1> 
 23939 00008283 803D[41C50000]00    <1> 	cmp	byte [Current_FATType], 0
 23940 0000828A 7706                <1> 	ja	short loc_rename_directory_entry
 23941                              <1> 
 23942 0000828C E8990E0000          <1> 	call	rename_fs_file_or_directory
 23943 00008291 C3                  <1> 	retn 
 23944                              <1> 	
 23945                              <1> loc_rename_directory_entry:
 23946 00008292 881D[AECF0000]      <1> 	mov	[DelFile_LNEL], bl
 23947 00008298 66890D[ACCF0000]    <1> 	mov	[DelFile_EntryCounter], cx
 23948 0000829F A3[A8CF0000]        <1> 	mov	[DelFile_FCluster], eax
 23949                              <1> 
 23950 000082A4 0FB7C1              <1> 	movzx	eax, cx
 23951 000082A7 E8BBFDFFFF          <1> 	call	locate_current_dir_entry
 23952 000082AC 7308                <1> 	jnc	short loc_rename_direntry_check_fcluster
 23953                              <1> 
 23954                              <1> loc_rename_direntry_pop_retn:
 23955 000082AE C3                  <1> 	retn
 23956                              <1> 
 23957                              <1> loc_rename_direntry_pop_invd_retn:
 23958 000082AF F9                  <1> 	stc
 23959                              <1> loc_rename_direntry_invd_retn:
 23960 000082B0 B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
 23961                              <1> loc_rename_retn:
 23962 000082B5 C3                  <1> 	retn 
 23963                              <1> 
 23964                              <1> loc_rename_direntry_check_fcluster:
 23965 000082B6 668B5714            <1> 	mov	dx, [edi+20] ; First Cluster HW
 23966 000082BA 66C1E210            <1> 	shl	dx, 16
 23967 000082BE 668B571A            <1> 	mov	dx, [edi+26] ; First Cluster LW
 23968 000082C2 3B15[A8CF0000]      <1> 	cmp	edx, [DelFile_FCluster]
 23969 000082C8 75E5                <1> 	jne	short loc_rename_direntry_pop_invd_retn
 23970                              <1> 	; ESI = New file (or directory) name. (ASCIIZ string)
 23971                              <1> 	; 06/03/2016
 23972                              <1> 	; TRDOS v2 - NOTE: 'convert_file_name' procedure
 23973                              <1> 	; has been modified for eliminating following situation.
 23974                              <1> 	; 
 23975                              <1> 	; TRDOS v1 - NOTE: If file/dir name is more than 11 bytes
 23976                              <1> 	; without a dot, attributes (edi+11) byte will be overwritten !
 23977                              <1> 	; (Dot file name input must be proper for 11 byte dir entry
 23978                              <1> 	;  type file name output.) 
 23979 000082CA E89FF6FFFF          <1> 	call	convert_file_name
 23980                              <1> 
 23981 000082CF C605[6CCD0000]02    <1>         mov     byte [DirBuff_ValidData], 2
 23982 000082D6 E8C2FBFFFF          <1> 	call	save_directory_buffer
 23983 000082DB 72D8                <1> 	jc	short loc_rename_retn
 23984                              <1> 
 23985                              <1> loc_rename_direntry_del_ln:
 23986 000082DD 0FB615[AECF0000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 23987 000082E4 08D2                <1> 	or	dl, dl
 23988 000082E6 7410                <1> 	jz	short loc_rename_direntry_update_parent_dir_lm_date
 23989                              <1> 
 23990 000082E8 0FB705[ACCF0000]    <1> 	movzx	eax, word [DelFile_EntryCounter]
 23991 000082EF 29D0                <1> 	sub	eax, edx
 23992 000082F1 72BD                <1> 	jc	short loc_rename_direntry_invd_retn
 23993                              <1> 
 23994                              <1> loc_rename_direntry_del_ln_continue: 
 23995                              <1> 	; EAX = Directory Entry Number of the long name last entry
 23996 000082F3 E805FDFFFF          <1> 	call	delete_longname
 23997                              <1> 
 23998                              <1> loc_rename_direntry_update_parent_dir_lm_date:
 23999 000082F8 E83BFCFFFF          <1> 	call	update_parent_dir_lmdt
 24000 000082FD 31C0                <1> 	xor	eax, eax 
 24001 000082FF C3                  <1> 	retn
 24002                              <1> 
 24003                              <1> move_source_file_to_destination_file:
 24004                              <1> 	; 11/03/2016
 24005                              <1> 	; 10/03/2016 (TRDOS 386 = TRDOS v2.0)
 24006                              <1> 	; 01/08/2011 (FILE.ASM)
 24007                              <1> 	; 04/08/2010
 24008                              <1> 	;
 24009                              <1> 	;   Phase 1 -> Check destination file, 
 24010                              <1> 	;              'not found' is required
 24011                              <1> 	;   Phase 2 -> Check source file
 24012                              <1> 	;              'found' and proper attributes is required
 24013                              <1> 	;   Phase 3 -> Make destination directory entry,
 24014                              <1> 	;           add new dir cluster or section if it is required
 24015                              <1> 	;   Phase 4 -> Delete source directory entry.
 24016                              <1> 	;       cf = 1 causes to return before the phase 4.
 24017                              <1> 	;    (source file protection against any possible errors)    
 24018                              <1> 	;
 24019                              <1> 	; 08/05/2011 major modification
 24020                              <1> 	;            -> destination file deleting is removed   
 24021                              <1> 	;            for msdos move/rename compatibility.
 24022                              <1> 	;            (Access denied error will return if
 24023                              <1> 	;            the destination file is found...)
 24024                              <1> 	; INPUT ->
 24025                              <1> 	;	 ESI = Source File Pathname (Asciiz)
 24026                              <1> 	;        EDI = Destination File Pathname (Asciiz)
 24027                              <1> 	;        AL = 0 --> Interrupt (System call)
 24028                              <1> 	;        AL > 0 --> Command Interpreter (Question)
 24029                              <1> 	;        AL = 1 --> Question Phase
 24030                              <1> 	;        AL = 2 --> Progress Phase        
 24031                              <1> 	; OUTPUT -> 
 24032                              <1> 	;	 cf = 0 -> OK
 24033                              <1> 	;        EAX = Destination directory first cluster
 24034                              <1> 	;        ESI = Logical DOS drive description table 
 24035                              <1> 	;        EBX = Destination file structure offset
 24036                              <1> 	;        CX = 0 (CX > 0 --> calculate free space error)
 24037                              <1> 	;        cf = 1 -> Error code in EAX (AL) 
 24038                              <1> 	;
 24039                              <1> 	;  (EDX, ECX, EBX, ESI, EDI will be changed)
 24040                              <1> 
 24041 00008300 3C02                <1> 	cmp	al, 2
 24042 00008302 0F846D010000        <1> 	je	msftdf_df2_check_directory
 24043 00008308 A2[28D10000]        <1> 	mov	[move_cmd_phase], al
 24044                              <1> 
 24045                              <1> msftdf_parse_sf_path:
 24046                              <1> 	; ESI = ASCIIZ pathname (Source)
 24047 0000830D 57                  <1> 	push	edi 
 24048 0000830E BF[28D00000]        <1> 	mov	edi, SourceFile_Drv
 24049 00008313 E821F7FFFF          <1> 	call	parse_path_name
 24050 00008318 5E                  <1> 	pop	esi
 24051 00008319 7211                <1> 	jc	short msftdf_psf_retn
 24052                              <1> 
 24053                              <1> msftdf_parse_df_path:
 24054                              <1> 	; ESI = ASCIIZ pathname	(Destination)
 24055 0000831B BF[A8D00000]        <1> 	mov	edi, DestinationFile_Drv
 24056 00008320 E814F7FFFF          <1> 	call	parse_path_name
 24057 00008325 7306                <1> 	jnc	short msftdf_check_sf_drv
 24058                              <1> 
 24059 00008327 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
 24060 00008329 7602                <1> 	jna	short msftdf_check_sf_drv
 24061                              <1> 
 24062                              <1> msftdf_stc_retn:
 24063 0000832B F9                  <1> 	stc
 24064                              <1> msftdf_psf_retn:
 24065 0000832C C3                  <1> 	retn 
 24066                              <1> 
 24067                              <1> msftdf_check_sf_drv:
 24068 0000832D A0[28D00000]        <1> 	mov	al, [SourceFile_Drv]
 24069                              <1> 
 24070                              <1> msftdf_check_df_drv:
 24071 00008332 8A15[A8D00000]      <1> 	mov	dl, [DestinationFile_Drv]
 24072                              <1> 
 24073                              <1> msftdf_compare_sf_df_drv:
 24074 00008338 29DB                <1> 	sub	ebx, ebx
 24075 0000833A 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 24076 00008340 38C2                <1> 	cmp	dl, al
 24077 00008342 7409                <1> 	je	short msftdf_check_sf_df_drv_ok
 24078                              <1> 
 24079                              <1> msftdf_not_same_drv:
 24080                              <1>         ; DL = source file's drive number
 24081 00008344 88C6                <1> 	mov	dh, al ; destination file's drive number
 24082 00008346 B811000000          <1> 	mov	eax, 11h ; Not the same drive
 24083 0000834B F9                  <1> 	stc
 24084 0000834C C3                  <1> 	retn 
 24085                              <1> 
 24086                              <1> msftdf_check_sf_df_drv_ok:
 24087 0000834D 8815[29D10000]      <1> 	mov	[msftdf_sf_df_drv], dl
 24088                              <1> 
 24089 00008353 29C0                <1>         sub	eax, eax
 24090 00008355 88D4                <1> 	mov	ah, dl
 24091 00008357 0500010900          <1> 	add	eax, Logical_DOSDisks
 24092 0000835C A3[2AD10000]        <1> 	mov	[msftdf_drv_offset], eax
 24093                              <1> 
 24094 00008361 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
 24095 00008363 7407                <1> 	je	short msftdf_df_check_directory
 24096                              <1> 
 24097                              <1> msftdf_change_drv:
 24098 00008365 E864C4FFFF          <1> 	call 	change_current_drive
 24099 0000836A 725B                <1> 	jc	short msftdf_df_error_retn
 24100                              <1> 	  
 24101                              <1> msftdf_check_destination_file:
 24102                              <1> msftdf_df_check_directory:
 24103 0000836C BE[A9D00000]        <1> 	mov	esi, DestinationFile_Directory
 24104 00008371 803E20              <1> 	cmp	byte [esi], 20h
 24105 00008374 760F                <1> 	jna	short msftdf_df_find_1
 24106                              <1> 
 24107                              <1> msftdf_df_change_directory:
 24108 00008376 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24109 0000837C 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 24110 0000837E E8A2F0FFFF          <1> 	call	change_current_directory
 24111 00008383 7242                <1> 	jc	short msftdf_df_error_retn
 24112                              <1> 
 24113                              <1> ;msftdf_df_change_prompt_dir_string:
 24114                              <1> ;	call 	change_prompt_dir_string
 24115                              <1> 
 24116                              <1> msftdf_df_find_1:
 24117 00008385 BE[EAD00000]        <1>         mov     esi, DestinationFile_Name
 24118 0000838A 803E20              <1> 	cmp	byte [esi], 20h
 24119 0000838D 761F                <1> 	jna	short msftdf_df_copy_sf_name
 24120                              <1> 
 24121                              <1> msftdf_df_find_2:
 24122 0000838F 6631C0              <1> 	xor	ax, ax ; DestinationFile_AttributesMask -> any/zero
 24123 00008392 E8CBD7FFFF          <1> 	call	find_first_file
 24124 00008397 737F                <1> 	jnc	short msftdf_permission_denied_retn
 24125                              <1> 
 24126                              <1> msftdf_df_check_error_code:
 24127                              <1> 	;cmp	eax, 2 ; File not found error
 24128 00008399 3C02                <1> 	cmp	al, 2
 24129 0000839B 7529                <1> 	jne	short msftdf_df_stc_retn
 24130                              <1>               
 24131                              <1> msftdf_convert_df_direntry_name:
 24132 0000839D BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 24133 000083A2 BF[FAD00000]        <1> 	mov	edi, DestinationFile_DirEntry
 24134 000083A7 E8C2F5FFFF          <1> 	call	convert_file_name
 24135 000083AC EB1A                <1>   	jmp	short msftdf_restore_current_dir_1
 24136                              <1> 
 24137                              <1> msftdf_df_copy_sf_name:
 24138 000083AE 89F7                <1> 	mov	edi, esi
 24139 000083B0 57                  <1> 	push	edi 
 24140 000083B1 BE[6AD00000]        <1>         mov     esi, SourceFile_Name
 24141 000083B6 B90C000000          <1> 	mov	ecx, 12
 24142                              <1> msftdf_df_copy_sf_name_loop:
 24143 000083BB AC                  <1> 	lodsb
 24144 000083BC AA                  <1>         stosb
 24145 000083BD 08C0                <1> 	or	al, al
 24146 000083BF 7402                <1> 	jz	short msftdf_df_copy_sf_name_ok	
 24147 000083C1 E2F8                <1>         loop    msftdf_df_copy_sf_name_loop
 24148                              <1> msftdf_df_copy_sf_name_ok:	
 24149 000083C3 5E                  <1> 	pop	esi  
 24150 000083C4 EBC9                <1> 	jmp	short msftdf_df_find_2
 24151                              <1> 
 24152                              <1> msftdf_df_stc_retn:
 24153 000083C6 F9                  <1> 	stc
 24154                              <1> msftdf_restore_cdir_failed:
 24155                              <1> msftdf_df_error_retn:
 24156 000083C7 C3                  <1> 	retn
 24157                              <1> 
 24158                              <1> msftdf_restore_current_dir_1:
 24159 000083C8 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 24160 000083CF 760D                <1> 	jna	short msftdf_sf_check_directory
 24161 000083D1 8B35[2AD10000]      <1> 	mov	esi, [msftdf_drv_offset] 
 24162 000083D7 E8A4C4FFFF          <1> 	call	restore_current_directory
 24163 000083DC 72E9                <1> 	jc	short msftdf_restore_cdir_failed
 24164                              <1> 
 24165                              <1> msftdf_sf_check_directory:
 24166 000083DE BE[29D00000]        <1> 	mov	esi, SourceFile_Directory
 24167 000083E3 803E20              <1> 	cmp	byte [esi], 20h
 24168 000083E6 760F                <1> 	jna	short msftdf_sf_find
 24169                              <1> msftdf_sf_change_directory:
 24170 000083E8 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24171 000083EE 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 24172 000083F0 E830F0FFFF          <1> 	call	change_current_directory
 24173 000083F5 7227                <1> 	jc	short msftdf_return
 24174                              <1> 
 24175                              <1> ;msftdf_sf_change_prompt_dir_string:
 24176                              <1> ;	call	change_prompt_dir_string
 24177                              <1> 
 24178                              <1> msftdf_sf_find:
 24179 000083F7 BE[6AD00000]        <1>         mov     esi, SourceFile_Name  ; Offset 66
 24180 000083FC 66B80018            <1> 	mov	ax, 1800h ; Only files
 24181 00008400 E85DD7FFFF          <1> 	call	find_first_file
 24182 00008405 7217                <1> 	jc	short msftdf_return
 24183                              <1> 
 24184                              <1> msftdf_sf_ambgfn_check:
 24185 00008407 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 24186 0000840A 7407                <1> 	jz	short msftdf_sf_found
 24187                              <1> 
 24188                              <1> msftdf_ambiguous_file_name_error:
 24189 0000840C B802000000          <1> 	mov	eax, 2 ; File not found error
 24190 00008411 F9                  <1> 	stc
 24191 00008412 C3                  <1> 	retn
 24192                              <1> 
 24193                              <1> msftdf_sf_found:
 24194 00008413 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
 24195 00008416 7416                <1> 	jz	short msftdf_save_sf_structure
 24196                              <1> 
 24197                              <1> msftdf_permission_denied_retn:
 24198 00008418 B805000000          <1> 	mov	eax, 05h ; Access (Permission) denied !
 24199 0000841D F9                  <1> 	stc
 24200                              <1> msftdf_rest_cdir_err_retn:
 24201                              <1> msftdf_return:
 24202 0000841E C3                  <1> 	retn
 24203                              <1> 
 24204                              <1> msftdf_phase_1_return:
 24205 0000841F 31C0                <1> 	xor	eax, eax
 24206 00008421 A2[28D10000]        <1> 	mov	[move_cmd_phase], al ; 0
 24207 00008426 FEC0                <1> 	inc	al ; mov al, 1
 24208 00008428 BB[75840000]        <1> 	mov	ebx, msftdf_df2_check_directory
 24209                              <1> 	;mov	edx, 0FFFFFFFFh 
 24210 0000842D C3                  <1> 	retn
 24211                              <1> 
 24212                              <1> msftdf_save_sf_structure:
 24213 0000842E BE[38CF0000]        <1> 	mov	esi, FindFile_DirEntry
 24214 00008433 BF[7AD00000]        <1> 	mov	edi, SourceFile_DirEntry
 24215 00008438 B908000000          <1> 	mov	ecx, 8
 24216 0000843D F3A5                <1> 	rep	movsd
 24217                              <1> 
 24218                              <1> msftdf_df_copy_sf_parameters:
 24219 0000843F BE0B000000          <1> 	mov	esi, 11
 24220 00008444 89F7                <1> 	mov	edi, esi
 24221 00008446 81C6[7AD00000]      <1> 	add	esi, SourceFile_DirEntry
 24222 0000844C 81C7[FAD00000]      <1> 	add	edi, DestinationFile_DirEntry
 24223                              <1> 	;mov	ecx, 21
 24224 00008452 B115                <1> 	mov	cl, 21
 24225 00008454 F3A4                <1> 	rep	movsb
 24226                              <1> 
 24227                              <1> msftdf_restore_current_dir_2:
 24228 00008456 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 24229 0000845D 760D                <1> 	jna	short msftdf_df2_check_move_cmd_phase
 24230 0000845F 8B35[2AD10000]      <1>  	mov	esi, [msftdf_drv_offset]
 24231 00008465 E816C4FFFF          <1> 	call	restore_current_directory
 24232 0000846A 72B2                <1> 	jc	short msftdf_rest_cdir_err_retn
 24233                              <1> 
 24234                              <1> msftdf_df2_check_move_cmd_phase:
 24235 0000846C 803D[28D10000]01    <1> 	cmp	byte [move_cmd_phase], 1
 24236 00008473 74AA                <1> 	je	short msftdf_phase_1_return
 24237                              <1> 
 24238                              <1> msftdf_df2_check_directory:
 24239 00008475 BE[A9D00000]        <1> 	mov	esi, DestinationFile_Directory
 24240 0000847A 803E20              <1> 	cmp	byte [esi], 20h
 24241 0000847D 760F                <1> 	jna	short msftdf_make_dfde_locate_ffe_on_directory
 24242                              <1> msftdf_df2_change_directory:
 24243 0000847F FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24244 00008485 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 24245 00008487 E899EFFFFF          <1> 	call	change_current_directory
 24246 0000848C 7290                <1> 	jc	short msftdf_return
 24247                              <1> 
 24248                              <1> ;msftdf_df2_change_prompt_dir_string:
 24249                              <1> ;	call	change_prompt_dir_string
 24250                              <1> 
 24251                              <1> msftdf_make_dfde_locate_ffe_on_directory:
 24252                              <1> 	; Current directory fcluster <> Directory buffer cluster
 24253                              <1> 	; Current directory will be reloaded by
 24254                              <1> 	; 'locate_current_dir_file' procedure
 24255                              <1> 	;
 24256                              <1> 	;xor	ax, ax
 24257 0000848E 31C0                <1> 	xor	eax, eax
 24258 00008490 89C1                <1> 	mov	ecx, eax
 24259 00008492 6649                <1> 	dec	cx ; FFFFh  
 24260                              <1> 		; CX = FFFFh -> find first deleted or free entry
 24261                              <1> 		; ESI would be ASCIIZ filename address if the call
 24262                              <1> 		; would not be for first free or deleted dir entry  
 24263 00008494 E8E0F1FFFF          <1> 	call	locate_current_dir_file
 24264 00008499 733F                <1> 	jnc	msftdf_make_dfde_set_ff_dir_entry
 24265                              <1> 	
 24266                              <1> 	;cmp	eax, 2
 24267 0000849B 3C02                <1>         cmp	al, 2
 24268 0000849D 7537                <1> 	jne	short msftdf_error_retn
 24269                              <1> 
 24270                              <1> msftdf_add_new_dir_entry_check_fs:
 24271 0000849F 8B35[2AD10000]      <1> 	mov	esi, [msftdf_drv_offset]
 24272 000084A5 A1[71CD0000]        <1> 	mov 	eax, [DirBuff_Cluster]
 24273 000084AA 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 24274 000084AE 7711                <1> 	ja	short msftdf_add_new_subdir_cluster
 24275                              <1> 
 24276                              <1> msftdf_add_new_fs_subdir_section:
 24277                              <1> 	;CL=0, CH=E5h --> deleted entry, CH=0 --> free entry
 24278                              <1>         ;xor	cx, cx
 24279 000084B0 30ED                <1> 	xor	ch, ch ; cx = 0 --> add a new subdir section
 24280 000084B2 E8750C0000          <1> 	call	add_new_fs_section
 24281 000084B7 721E                <1>         jc	short msftdf_dsfde_error_retn
 24282                              <1> 	;mov	[createfile_LastDirCluster], eax
 24283                              <1> 
 24284 000084B9 E8950E0000          <1> 	call	load_FS_sub_directory 
 24285                              <1> 	;mov	ebx, Directory_Buffer 
 24286 000084BE 7318                <1> 	jnc	short msftdf_add_new_fs_subdir_section_ok
 24287 000084C0 C3                  <1> 	retn	 
 24288                              <1> 
 24289                              <1> msftdf_add_new_subdir_cluster:
 24290 000084C1 E863150000          <1> 	call	add_new_cluster
 24291 000084C6 720F                <1> 	jc	short msftdf_dsfde_error_retn
 24292                              <1> 	
 24293                              <1> 	;mov	[createfile_LastDirCluster], eax
 24294                              <1> 
 24295 000084C8 E8490E0000          <1> 	call	load_FAT_sub_directory
 24296 000084CD 7309                <1> 	jnc	short msftdf_add_new_subdir_cluster_ok
 24297                              <1> 	; EBX = Directory buffer address
 24298                              <1> 
 24299                              <1> msftdf_ansdc_update_parent_dir_lmdt:
 24300                              <1> msftdf_make_dfde_err_upd_pdir_lmdt:
 24301 000084CF 50                  <1> 	push	eax
 24302 000084D0 E863FAFFFF          <1> 	call	update_parent_dir_lmdt
 24303 000084D5 58                  <1> 	pop	eax
 24304                              <1> 
 24305                              <1> msftdf_error_retn:
 24306 000084D6 F9                  <1> 	stc
 24307                              <1> msftdf_dsfde_restore_cdir_failed:
 24308                              <1> msftdf_dsfde_error_retn:
 24309 000084D7 C3                  <1> 	retn
 24310                              <1> 
 24311                              <1> msftdf_add_new_fs_subdir_section_ok:
 24312                              <1> msftdf_add_new_subdir_cluster_ok:
 24313 000084D8 89DF                <1> 	mov	edi, ebx ; Directory buffer address
 24314                              <1> 
 24315                              <1> msftdf_make_dfde_set_ff_dir_entry:
 24316 000084DA 8B15[3CC50000]      <1> 	mov	edx, [Current_Dir_FCluster]
 24317 000084E0 8915[8ED10000]      <1> 	mov	[createfile_FFCluster], edx
 24318                              <1> 	; EDI = Directory entry offset
 24319 000084E6 BE[FAD00000]        <1> 	mov	esi, DestinationFile_DirEntry
 24320 000084EB B908000000          <1> 	mov	ecx, 8
 24321 000084F0 F3A5                <1> 	rep	movsd
 24322                              <1> 
 24323 000084F2 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 24324 000084F9 E89FF9FFFF          <1> 	call	save_directory_buffer
 24325 000084FE 72CF                <1> 	jc	short msftdf_make_dfde_err_upd_pdir_lmdt
 24326                              <1> 
 24327                              <1> msftdf_make_dfde_update_pdir_lmdt:
 24328 00008500 E833FAFFFF          <1> 	call	update_parent_dir_lmdt
 24329                              <1> 
 24330                              <1> msftdf_dsfde_restore_current_dir_1:
 24331 00008505 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 24332 0000850C 760D                <1> 	jna	short msftdf_dsfde_check_directory
 24333 0000850E 8B35[2AD10000]      <1>  	mov	esi, [msftdf_drv_offset]
 24334 00008514 E867C3FFFF          <1> 	call	restore_current_directory
 24335 00008519 72BC                <1> 	jc	short msftdf_dsfde_restore_cdir_failed
 24336                              <1> 
 24337                              <1> msftdf_dsfde_check_directory:
 24338 0000851B BE[29D00000]        <1> 	mov	esi, SourceFile_Directory
 24339 00008520 803E20              <1> 	cmp	byte [esi], 20h
 24340 00008523 760F                <1> 	jna	short msftdf_dsfde_find_file
 24341                              <1> 
 24342                              <1> msftdf_dsfde_change_directory:
 24343 00008525 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24344 0000852B 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
 24345 0000852D E8F3EEFFFF          <1> 	call	change_current_directory
 24346 00008532 72A3                <1> 	jc	short msftdf_dsfde_error_retn
 24347                              <1> 
 24348                              <1> ;msftdf_dsfde_sf_change_prompt_dir_string:
 24349                              <1> ;	call	change_prompt_dir_string
 24350                              <1> 
 24351                              <1> msftdf_dsfde_find_file:
 24352 00008534 BE[6AD00000]        <1> 	mov	esi, SourceFile_Name  ; Offset 66
 24353 00008539 668B460E            <1> 	mov	ax, [esi+14] ; 80 -> SourceFile_AttributesMask
 24354 0000853D E820D6FFFF          <1> 	call	find_first_file
 24355 00008542 7293                <1> 	jc	short msftdf_dsfde_error_retn
 24356                              <1> 
 24357                              <1> msftdf_dsfde_delete_direntry:
 24358 00008544 8B35[2AD10000]      <1> 	mov	esi, [msftdf_drv_offset]
 24359                              <1> 	
 24360 0000854A 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 24361 0000854E 770A                <1> 	ja	short msftdf_delete_FAT_direntry
 24362                              <1> 	
 24363 00008550 30DB                <1> 	xor	bl, bl
 24364                              <1> 	; BL = 0 -> File
 24365                              <1> 	; EDI -> Directory buffer entry offset/address 
 24366 00008552 E8D60B0000          <1> 	call	delete_fs_directory_entry
 24367 00008557 7315                <1> 	jnc	short msftdf_dsfde_restore_current_dir_2
 24368 00008559 C3                  <1> 	retn
 24369                              <1> 
 24370                              <1> msftdf_delete_FAT_direntry:	
 24371 0000855A 8A1D[35CF0000]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
 24372 00008560 668B0D[60CF0000]    <1> 	mov	cx, [FindFile_DirEntryNumber]
 24373                              <1> 	; ESI = Logical DOS drive description table address
 24374                              <1> 	; EDI = Directory buffer entry offset/address 
 24375 00008567 E8ABFCFFFF          <1> 	call	delete_directory_entry
 24376 0000856C 721C                <1> 	jc	short msftdf_retn
 24377                              <1> 
 24378                              <1> msftdf_dsfde_restore_current_dir_2:
 24379 0000856E 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 24380 00008575 7607                <1> 	jna	short msftdf_new_dir_fcluster_retn
 24381                              <1> 	;mov	esi, [msftdf_drv_offset]
 24382 00008577 E804C3FFFF          <1> 	call	restore_current_directory
 24383 0000857C 720C                <1> 	jc	short msftdf_retn
 24384                              <1> 
 24385                              <1> msftdf_new_dir_fcluster_retn:
 24386 0000857E 31C9                <1> 	xor	ecx, ecx 
 24387 00008580 A1[8ED10000]        <1> 	mov	eax, [createfile_FFCluster]
 24388 00008585 BB[A8D00000]        <1> 	mov	ebx, DestinationFile_Drv
 24389                              <1> 
 24390                              <1> msftdf_retn:
 24391 0000858A C3                  <1> 	retn
 24392                              <1> 
 24393                              <1> 
 24394                              <1> copy_source_file_to_destination_file:
 24395                              <1> 	; 31/03/2016
 24396                              <1> 	; 30/03/2016
 24397                              <1> 	; 24/03/2016, 25/03/2016, 28/03/2016
 24398                              <1> 	; 21/03/2016, 22/03/2016, 23/03/2016
 24399                              <1> 	; 16/03/2016, 17/03/2016, 18/03/2016
 24400                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
 24401                              <1> 	; 02/09/2011 (FILE.ASM 'copy_source_file_to_destination_file')
 24402                              <1> 	; 01/08/2010 - 18/05/2011
 24403                              <1> 	;
 24404                              <1> 	;   Command Interpreter phase 1 enter ->
 24405                              <1> 	;           AL = 1 -> Caller is command interpreter
 24406                              <1> 	;           AL = 2 -> The second call, re-enter/continue
 24407                              <1> 	;   Phase 1 -> Check source file
 24408                              <1> 	;              'found' is required
 24409                              <1> 	;   Phase 2 -> Check destination file, 
 24410                              <1> 	;              save 'found' or 'not found' status
 24411                              <1> 	;              'permission denied' error will be return
 24412                              <1> 	;              if attributes have not for ordinary file 
 24413                              <1> 	;              without readonly attribute
 24414                              <1> 	;   Command Interpreter phase 1 return ->
 24415                              <1> 	;              DH = Source file attributes
 24416                              <1> 	;              DL = Destination file found status
 24417                              <1> 	;              EAX = 0 
 24418                              <1> 	;   Command Interpeter phase 2 enter ->
 24419                              <1> 	;              AL = 2 -> Continue from the last position
 24420                              <1> 	;              AH = 
 24421                              <1> 	;   Phase 3 -> Load source file or use read/write cluster method
 24422                              <1> 	;   Phase 4 -> Create destination file if it is not found
 24423                              <1> 	;   Phase 5 -> Open destination file
 24424                              <1> 	;   Phase 6 -> Read from source and write to destination
 24425                              <1> 	;   Phase 7 -> Unload source file, if it is loaded at memory
 24426                              <1> 	;       cf = 1 causes to return before the phase 7
 24427                              <1> 	;              but loaded file will be unloaded
 24428                              <1> 	;	       (allocated memory block will be deallocated) 
 24429                              <1> 	;
 24430                              <1> 	; INPUT -> 
 24431                              <1> 	;	 ESI = Source File Pathname (Asciiz)
 24432                              <1> 	;        EDI = Destination File Pathname (Asciiz)
 24433                              <1> 	;        AL = 0 --> Interrupt (System call)
 24434                              <1> 	;        AL > 0 --> Command Interpreter (Question)
 24435                              <1> 	;        AL = 1 --> Question Phase
 24436                              <1> 	;        AL = 2 --> Progress Phase        
 24437                              <1> 	;
 24438                              <1> 	; OUTPUT -> 
 24439                              <1> 	;	cf = 0 -> OK
 24440                              <1> 	;	EAX = Destination file first cluster
 24441                              <1> 	;
 24442                              <1> 	;        CL > 0 if there is file reading error before EOF
 24443                              <1> 	;	        (incomplete copy) 
 24444                              <1> 	;        CH > 0 if file is (full) loaded at memory
 24445                              <1> 	;
 24446                              <1> 	;	cf = 1 -> Error code in AL (EAX) 
 24447                              <1> 	;
 24448                              <1> 	; (EBX, ECX, ESI, EDI register contents will be changed)           
 24449                              <1> 
 24450                              <1> 
 24451 0000858B 3C02                <1> 	cmp	al, 2
 24452 0000858D 0F844C020000        <1> 	je	csftdf2_check_cdrv
 24453                              <1> 
 24454                              <1> ; Phase 1
 24455                              <1> 
 24456 00008593 A2[4ED10000]        <1> 	mov	byte [copy_cmd_phase], al
 24457                              <1> 
 24458 00008598 57                  <1> 	push	edi ; *
 24459                              <1> 
 24460                              <1> csftdf_parse_sf_path:
 24461 00008599 BF[28D00000]        <1> 	mov	edi, SourceFile_Drv
 24462 0000859E E896F4FFFF          <1> 	call	parse_path_name
 24463 000085A3 721C                <1> 	jc	short csftdf_parse_sf_path_failed
 24464                              <1> 
 24465                              <1> csftdf_parse_df_path:	
 24466 000085A5 5E                  <1> 	pop	esi ; * (pushed edi) 
 24467                              <1> 
 24468                              <1> csftdf_sf_check_filename_exists:
 24469 000085A6 803D[6AD00000]21    <1> 	cmp	byte [SourceFile_Name], 21h
 24470 000085AD 7215                <1> 	jb	short csftdf_sf_file_not_found_error
 24471                              <1> 
 24472 000085AF BF[A8D00000]        <1> 	mov	edi, DestinationFile_Drv
 24473 000085B4 E880F4FFFF          <1> 	call	parse_path_name
 24474 000085B9 7310                <1> 	jnc	short csftdf_check_sf_cdrv
 24475                              <1> 	
 24476 000085BB 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
 24477 000085BD 760C                <1> 	jna	short csftdf_check_sf_cdrv
 24478                              <1> 
 24479                              <1> csftdf_parse_df_path_failed:
 24480 000085BF F9                  <1> 	stc 
 24481                              <1> csftdf_sf_error_retn: 
 24482 000085C0 C3                  <1> 	retn
 24483                              <1> 
 24484                              <1> csftdf_parse_sf_path_failed:	
 24485 000085C1 5F                  <1> 	pop	edi ; *
 24486 000085C2 EBFC                <1> 	jmp	short csftdf_sf_error_retn
 24487                              <1> 
 24488                              <1> csftdf_sf_file_not_found_error:
 24489 000085C4 B802000000          <1> 	mov	eax, 2 ; File not found 
 24490 000085C9 EBF5                <1> 	jmp	short csftdf_sf_error_retn
 24491                              <1> 
 24492                              <1> csftdf_check_sf_cdrv:
 24493 000085CB 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 24494                              <1> 
 24495 000085D1 883D[51D10000]      <1> 	mov	[csftdf_cdrv], bh ; 23/03/2016
 24496                              <1> 
 24497 000085D7 8A15[28D00000]      <1> 	mov	dl, [SourceFile_Drv]
 24498 000085DD 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
 24499 000085DF 7407                <1> 	je	short csftdf_sf_check_directory
 24500                              <1> 
 24501 000085E1 E8E8C1FFFF          <1> 	call	change_current_drive
 24502 000085E6 72D8                <1> 	jc	short csftdf_sf_error_retn
 24503                              <1> 
 24504                              <1> csftdf_sf_check_directory:
 24505 000085E8 BE[29D00000]        <1> 	mov	esi, SourceFile_Directory
 24506 000085ED 803E20              <1> 	cmp	byte [esi], 20h
 24507 000085F0 760F                <1> 	jna	short csftdf_find_sf
 24508                              <1> 
 24509                              <1> csftdf_sf_change_directory:
 24510 000085F2 FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24511 000085F8 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 24512 000085FA E826EEFFFF          <1> 	call	change_current_directory
 24513 000085FF 72BF                <1> 	jc	short csftdf_sf_error_retn
 24514                              <1> 
 24515                              <1> ;csftdf_sf_change_prompt_dir_string:
 24516                              <1> ;	call	change_prompt_dir_string
 24517                              <1> 
 24518                              <1> csftdf_find_sf:
 24519 00008601 BE[6AD00000]        <1> 	mov	esi, SourceFile_Name
 24520 00008606 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 24521 0000860A E853D5FFFF          <1> 	call	find_first_file
 24522 0000860F 72AF                <1> 	jc	short csftdf_sf_error_retn
 24523                              <1> 
 24524                              <1> csftdf_sf_ambgfn_check:
 24525 00008611 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 24526 00008614 7407                <1> 	jz	short csftdf_sf_found
 24527                              <1> 
 24528                              <1> csftdf_ambiguous_file_name_error:
 24529 00008616 B802000000          <1> 	mov	eax, 2 ; File not found error
 24530 0000861B F9                  <1> 	stc
 24531 0000861C C3                  <1> 	retn
 24532                              <1> 
 24533                              <1> csftdf_sf_found:
 24534 0000861D A3[52D10000]        <1> 	mov	[csftdf_filesize], eax
 24535                              <1> 
 24536 00008622 09C0                <1> 	or	eax, eax
 24537 00008624 7507                <1> 	jnz	short csftdf_set_source_file_direnry
 24538                              <1> 
 24539                              <1> csftdf_sf_file_size_zero:
 24540 00008626 B80E000000          <1> 	mov	eax, 0Eh ; TRDOS zero length error
 24541 0000862B F9                  <1> 	stc
 24542 0000862C C3                  <1> 	retn
 24543                              <1> 
 24544                              <1> csftdf_set_source_file_direnry:
 24545 0000862D BE[38CF0000]        <1> 	mov	esi, FindFile_DirEntry
 24546 00008632 BF[7AD00000]        <1> 	mov	edi, SourceFile_DirEntry
 24547 00008637 B908000000          <1> 	mov	ecx, 8
 24548 0000863C F3A5                <1> 	rep	movsd
 24549                              <1> 
 24550                              <1> csftdf_sf_restore_cdrv:
 24551                              <1> 	; 22/03/2016
 24552 0000863E 8A15[51D10000]      <1> 	mov	dl, [csftdf_cdrv]
 24553 00008644 3A15[42C50000]      <1> 	cmp	dl, [Current_Drv]
 24554 0000864A 7407                <1> 	je	short csftdf_sf_restore_cdir
 24555 0000864C E87DC1FFFF          <1> 	call	change_current_drive 
 24556 00008651 724F                <1> 	jc	short csftdf_df_error_retn ; 30/03/2016
 24557                              <1> 
 24558                              <1> csftdf_sf_restore_cdir:
 24559 00008653 803D[F6B40000]00    <1> 	cmp	byte [Restore_CDIR], 0
 24560 0000865A 7612                <1> 	jna	short csftdf_df_check_filename_exists
 24561 0000865C 29C0                <1> 	sub	eax, eax
 24562 0000865E BE00010900          <1> 	mov	esi, Logical_DOSDisks
 24563 00008663 88D4                <1> 	mov	ah, dl ; byte [csftdf_cdrv]
 24564 00008665 01C6                <1> 	add	esi, eax
 24565 00008667 E814C2FFFF          <1> 	call	restore_current_directory
 24566 0000866C 7234                <1> 	jc	short csftdf_df_error_retn
 24567                              <1>   
 24568                              <1> csftdf_df_check_filename_exists:
 24569 0000866E 803D[EAD00000]20    <1> 	cmp	byte [DestinationFile_Name], 20h
 24570 00008675 7716                <1> 	ja	short csftdf_check_df_cdrv
 24571                              <1> 
 24572                              <1> csftdf_copy_sf_name:
 24573 00008677 BF[EAD00000]        <1> 	mov	edi, DestinationFile_Name
 24574 0000867C BE[6AD00000]        <1> 	mov	esi, SourceFile_Name
 24575 00008681 B10C                <1> 	mov	cl, 12
 24576                              <1> 
 24577                              <1> csftdf_df_copy_sf_name_loop:
 24578 00008683 AC                  <1> 	lodsb
 24579 00008684 AA                  <1> 	stosb
 24580 00008685 08C0                <1> 	or	al, al
 24581 00008687 7404                <1> 	jz	short csftdf_check_df_cdrv             
 24582 00008689 FEC9                <1> 	dec	cl
 24583 0000868B 75F6                <1> 	jnz	csftdf_df_copy_sf_name_loop
 24584                              <1> 
 24585                              <1> csftdf_check_df_cdrv:
 24586 0000868D 8A15[A8D00000]      <1> 	mov	dl, [DestinationFile_Drv]
 24587 00008693 3A15[42C50000]      <1> 	cmp	dl, [Current_Drv]
 24588 00008699 7408                <1> 	je	short csftdf_df_check_directory
 24589                              <1> 
 24590 0000869B E82EC1FFFF          <1> 	call	change_current_drive
 24591 000086A0 7301                <1> 	jnc	short csftdf_df_check_directory
 24592                              <1> 
 24593                              <1> csftdf_df_error_retn:
 24594 000086A2 C3                  <1> 	retn
 24595                              <1> 
 24596                              <1> csftdf_df_check_directory:
 24597 000086A3 BE[A9D00000]        <1> 	mov	esi, DestinationFile_Directory
 24598 000086A8 803E20              <1>         cmp     byte [esi], 20h
 24599 000086AB 760F                <1> 	jna	short csftdf_find_df
 24600                              <1> 
 24601                              <1> csftdf_df_change_directory:
 24602 000086AD FE05[F6B40000]      <1> 	inc	byte [Restore_CDIR]
 24603 000086B3 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
 24604 000086B5 E86BEDFFFF          <1> 	call	change_current_directory
 24605 000086BA 72E6                <1> 	jc	short csftdf_df_error_retn
 24606                              <1> 
 24607                              <1> ;csftdf_df_change_prompt_dir_string:
 24608                              <1> ;	call	change_prompt_dir_string
 24609                              <1> 
 24610                              <1> csftdf_find_df:
 24611                              <1> 	; 23/03/2016
 24612 000086BC 29DB                <1> 	sub	ebx, ebx
 24613 000086BE 8A3D[A8D00000]      <1> 	mov	bh,  [DestinationFile_Drv]
 24614 000086C4 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 24615 000086CA 891D[7ED10000]      <1> 	mov	[csftdf_df_drv_dt], ebx
 24616                              <1> 
 24617 000086D0 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 24618 000086D5 6631C0              <1> 	xor	ax, ax 
 24619                              <1> 		; DestinationFile_AttributesMask -> any/zero
 24620 000086D8 E885D4FFFF          <1> 	call	find_first_file
 24621 000086DD 7218                <1> 	jc	short csftdf_df_check_error_code
 24622                              <1> 
 24623                              <1> csftdf_df_ambgfn_check:
 24624 000086DF 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 24625 000086E2 7511                <1> 	jnz	short csftdf_df_error_stc_retn
 24626                              <1> 	
 24627                              <1> csftdf_df_found:
 24628 000086E4 C605[50D10000]01    <1> 	mov	byte [DestinationFileFound], 1
 24629 000086EB 80E11F              <1> 	and	cl, 1Fh ; Attributes, D-V-S-H-R
 24630 000086EE 7451                <1> 	jz	short csftdf_df_save_first_cluster
 24631                              <1> 
 24632                              <1> csftdf_df_permission_denied_retn:	 
 24633 000086F0 B805000000          <1> 	mov	eax, 05h ; Access/Permisson denied.
 24634                              <1> csftdf_df_error_stc_retn:
 24635 000086F5 F9                  <1> 	stc
 24636 000086F6 C3                  <1> 	retn
 24637                              <1> 
 24638                              <1> csftdf_df_check_error_code:
 24639                              <1> 	;cmp	eax, 2
 24640 000086F7 3C02                <1> 	cmp	al, 2
 24641 000086F9 75FA                <1> 	jne	short csftdf_df_error_stc_retn
 24642                              <1> 
 24643                              <1> 	; 21/03/2016
 24644                              <1> 	; (Capitalized file name)
 24645 000086FB BE[28CF0000]        <1> 	mov	esi, FindFile_Name
 24646 00008700 BF[EAD00000]        <1> 	mov	edi, DestinationFile_Name
 24647 00008705 A5                  <1> 	movsd
 24648 00008706 A5                  <1> 	movsd	
 24649 00008707 A5                  <1> 	movsd
 24650                              <1> 	;movsb
 24651                              <1> 
 24652 00008708 C605[50D10000]00    <1> 	mov	byte [DestinationFileFound], 0
 24653                              <1> 
 24654                              <1> csftdf_check_disk_free_size_0:
 24655 0000870F A1[96D00000]        <1> 	mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
 24656                              <1> 
 24657                              <1> csftdf_check_disk_free_size_1:
 24658                              <1> 	;sub	ebx, ebx
 24659                              <1> 	;mov 	esi, Logical_DOSDisks
 24660                              <1> 	;mov	bh,  [DestinationFile_Drv]
 24661                              <1> 	;add	esi, ebx
 24662                              <1> 	
 24663 00008714 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
 24664                              <1> 
 24665 0000871A 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
 24666 0000871E 01C8                <1> 	add	eax, ecx
 24667 00008720 48                  <1> 	dec	eax  ; file size (additional bytes) + 511 (round up)
 24668                              <1> csftdf_check_disk_free_size_3: ; 16/03/2016
 24669 00008721 29D2                <1> 	sub	edx, edx
 24670 00008723 F7F1                <1> 	div	ecx ; bytes per sector
 24671                              <1> 
 24672                              <1> csftdf_check_disk_free_size:
 24673 00008725 3B4674              <1> 	cmp	eax, [esi+LD_FreeSectors]
 24674 00008728 0F8294000000        <1>         jb      csftdf_check_disk_free_size_ok
 24675 0000872E 770A                <1> 	ja	short csftdf_df_insufficient_disk_space
 24676                              <1> 
 24677 00008730 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0 ; FS needs FDT sector also.
 24678 00008734 0F8788000000        <1>         ja      csftdf_check_disk_free_size_ok 
 24679                              <1> 
 24680                              <1> csftdf_df_insufficient_disk_space:
 24681 0000873A B827000000          <1> 	mov	eax, 27h ; insufficient disk space
 24682 0000873F EBB4                <1> 	jmp	short csftdf_df_error_stc_retn
 24683                              <1> 
 24684                              <1> csftdf_df_save_first_cluster:
 24685                              <1> 	; ESI = FindFile_DirEntry (for the old destination file)
 24686                              <1> 	; EAX = Old destination file size
 24687                              <1> 	; 24/03/2016
 24688                              <1> 	; EDI = Directory entry address (within Dir Buffer boundaries)
 24689 00008741 81EF00000800        <1> 	sub	edi, Directory_Buffer  ; (<65536)
 24690 00008747 66C1EF05            <1> 	shr	di, 5 ; Convert entry offset to entry index/number
 24691 0000874B 66893D[22D10000]    <1> 	mov	[DestinationFile_DirEntryNumber], di ; (<2048)
 24692                              <1> 
 24693                              <1> csftdf_df_check_sf_df_fcluster:
 24694 00008752 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
 24695 00008756 C1E210              <1> 	shl	edx, 16
 24696 00008759 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
 24697 0000875D 8915[62D10000]      <1> 	mov	[csftdf_df_cluster], edx
 24698                              <1> csftdf_df_check_sf_df_fcluster_1:
 24699 00008763 668B15[8ED00000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
 24700 0000876A C1E210              <1> 	shl	edx, 16
 24701 0000876D 668B15[94D00000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
 24702 00008774 3B15[62D10000]      <1> 	cmp	edx, [csftdf_df_cluster]
 24703 0000877A 7512                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
 24704                              <1> csftdf_df_check_sf_df_drv:
 24705 0000877C 8A15[28D00000]      <1> 	mov	dl, [SourceFile_Drv]
 24706 00008782 3A15[A8D00000]      <1> 	cmp	dl, [DestinationFile_Drv]
 24707 00008788 7504                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
 24708                              <1> 
 24709                              <1> 	; source and destination files are same !
 24710                              <1> 	; (they have same first cluster value on same logical disk)
 24711                              <1> 
 24712 0000878A 31C0                <1> 	xor	eax, eax ; mov eax, 0 -> Bad command or file name !
 24713 0000878C F9                  <1> 	stc
 24714 0000878D C3                  <1> 	retn 
 24715                              <1>    
 24716                              <1> csftdf_df_check_sf_df_fcluster_ok:
 24717                              <1> csftdf_df_move_findfile_struct:
 24718                              <1> 	; mov	esi, FindFile_DirEntry
 24719 0000878E BF[FAD00000]        <1> 	mov	edi, DestinationFile_DirEntry
 24720 00008793 B908000000          <1> 	mov	ecx, 8
 24721 00008798 F3A5                <1> 	rep	movsd
 24722                              <1> 	
 24723                              <1> csftdf_check_disk_free_size_2:
 24724 0000879A 89C2                <1> 	mov	edx, eax ; Old destination file size
 24725                              <1> 
 24726                              <1> 	;mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
 24727 0000879C A1[52D10000]        <1> 	mov	eax, [csftdf_filesize] ; 23/03/2016
 24728                              <1> 
 24729                              <1> 	;;sub	ecx, ecx ; 0
 24730                              <1> 	;mov 	esi, Logical_DOSDisks
 24731                              <1> 	;mov	ch,  [DestinationFile_Drv]
 24732                              <1> 	;add	esi, ecx
 24733                              <1> 	;
 24734                              <1> 	;mov	[csftdf_df_drv_dt], esi
 24735                              <1> 
 24736 000087A1 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
 24737                              <1> 
 24738 000087A7 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
 24739 000087AB 01CA                <1> 	add	edx, ecx ; + 512
 24740 000087AD 01C8                <1> 	add	eax, ecx ; + 512
 24741 000087AF 4A                  <1> 	dec	edx ; old file size + 511 (round up)
 24742 000087B0 48                  <1> 	dec	eax ; new file size + 511 (round up)
 24743 000087B1 F7D9                <1> 	neg	ecx ; -512 ; 0FFFFFE00h
 24744 000087B3 21CA                <1> 	and	edx, ecx ; = old sector count * 512 
 24745 000087B5 21C8                <1> 	and	eax, ecx ; = new sector count * 512 
 24746                              <1> 
 24747 000087B7 29D0                <1> 	sub	eax, edx ; new file size - old file size (on disk)
 24748 000087B9 7607                <1> 	jna	short csftdf_check_disk_free_size_ok
 24749                              <1> 
 24750 000087BB F7D9                <1> 	neg	ecx ; 512 (bytes per sector) ; 200h
 24751                              <1> 	; check free space for additional sectors
 24752                              <1> 	; eax = number of additional sectors * bytes per sector
 24753                              <1> 	; esi = Logical DOS drive number (of destination disk)
 24754 000087BD E95FFFFFFF          <1>         jmp     csftdf_check_disk_free_size_3
 24755                              <1>  
 24756                              <1> csftdf_check_disk_free_size_ok:
 24757                              <1> 	; 18/03/2016
 24758                              <1> csftdf_df_check_copy_cmd_phase:
 24759 000087C2 A0[4ED10000]        <1> 	mov	al, [copy_cmd_phase]
 24760 000087C7 3C01                <1> 	cmp	al, 1
 24761 000087C9 7514                <1> 	jne	short csftdf2_check_cdrv
 24762                              <1> 	
 24763 000087CB 31C0                <1> 	xor	eax, eax
 24764 000087CD A2[4ED10000]        <1> 	mov	[copy_cmd_phase], al ; 0
 24765                              <1> 
 24766 000087D2 8A15[50D10000]      <1> 	mov	dl, [DestinationFileFound]            
 24767 000087D8 8A35[85D00000]      <1> 	mov	dh, [SourceFile_DirEntry+11] ; Attributes
 24768                              <1>  
 24769                              <1> csftdf_return:	
 24770 000087DE C3                  <1> 	retn
 24771                              <1> 
 24772                              <1> ; Phase 2
 24773                              <1> 
 24774                              <1> csftdf2_check_cdrv:
 24775                              <1> 	; 18/03/2016
 24776                              <1> 	; Here, destination drive and directory are ready !
 24777                              <1> 	; (checking/restoring is not needed)
 24778                              <1> 	; (Since at the end of the phase 1)
 24779                              <1> 
 24780                              <1> ;	mov	dl, [DestinationFile_Drv]
 24781                              <1> ;	cmp	dl, [Current_Drv]
 24782                              <1> ;	je	short csftdf2_df_check_directory
 24783                              <1> ;
 24784                              <1> ;	call	change_current_drive
 24785                              <1> ;	jc	short csftdf2_read_error
 24786                              <1> ;
 24787                              <1> ;csftdf2_df_check_directory:
 24788                              <1> ;	mov	esi, DestinationFile_Directory  
 24789                              <1> ;	cmp	byte [esi], 20h
 24790                              <1> ;	jna	short csftdf2_df_check_found_or_not
 24791                              <1> ;
 24792                              <1> ;csftdf2_df_change_directory:
 24793                              <1> ;	inc	byte [Restore_CDIR]
 24794                              <1> ;	xor	ah, ah ; CD_COMMAND sign -> 0 
 24795                              <1> ;	call	change_current_directory
 24796                              <1> ;	jc	short csftdf2_stc_return
 24797                              <1> ;
 24798                              <1> ;;csftdf2_df_change_prompt_dir_string:
 24799                              <1> ;;	call	change_prompt_dir_string
 24800                              <1> 
 24801                              <1> csftdf2_df_check_found_or_not:
 24802                              <1> 	; 21/03/2016
 24803 000087DF 803D[50D10000]00    <1> 	cmp	byte [DestinationFileFound], 0 
 24804 000087E6 7739                <1> 	ja	short csftdf2_set_sf_percentage
 24805                              <1> 
 24806                              <1> csftdf2_create_file:
 24807 000087E8 BE[EAD00000]        <1> 	mov	esi, DestinationFile_Name
 24808 000087ED A1[52D10000]        <1> 	mov	eax, [csftdf_filesize]
 24809 000087F2 30C9                <1> 	xor	cl, cl ; 0
 24810                              <1> 
 24811 000087F4 31DB                <1> 	xor	ebx, ebx ; 0
 24812 000087F6 4B                  <1> 	dec	ebx ; 0FFFFFFFFh 
 24813                              <1> 
 24814                              <1> 	; INPUT ->
 24815                              <1> 	; 	EAX -> File Size
 24816                              <1> 	; 	ESI = ASCIIZ File name
 24817                              <1> 	;	 CL = File attributes
 24818                              <1> 	;	EBX = FFFFFFFFh -> empty file sign for FAT fs
 24819                              <1> 	;	EBX <> FFFFFFFFh -> use file size for FAT fs 
 24820                              <1> 	;
 24821                              <1> 	; OUTPUT ->
 24822                              <1> 	;	EAX = New file's first cluster
 24823                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
 24824                              <1> 	;	EBX = CreateFile_Size address
 24825                              <1> 	;	ECX = Sectors per cluster (<256)
 24826                              <1> 	;	EDX = Directory Entry Index/Number (<65536)
 24827                              <1> 	;		
 24828                              <1> 	;	cf = 1 -> error code in AL (EAX)
 24829                              <1> 
 24830 000087F7 E8EC050000          <1> 	call	create_file
 24831                              <1> 	;pop	esi
 24832 000087FC 0F82A3050000        <1>         jc      csftdf2_rw_error
 24833                              <1> 
 24834                              <1> csftdf2_create_file_OK:
 24835 00008802 A3[62D10000]        <1> 	mov	[csftdf_df_cluster], eax
 24836                              <1> 	
 24837                              <1> 	; 24/03/2016
 24838 00008807 668915[22D10000]    <1> 	mov	[DestinationFile_DirEntryNumber], dx 
 24839                              <1> 
 24840                              <1> 	; 21/03/2016
 24841 0000880E BE00000800          <1> 	mov	esi, Directory_Buffer
 24842 00008813 C1E205              <1> 	shl	edx, 5 ; 32 * index number
 24843 00008816 01D6                <1> 	add	esi, edx
 24844 00008818 BF[FAD00000]        <1> 	mov	edi, DestinationFile_DirEntry	
 24845 0000881D B108                <1> 	mov	cl, 8 ; 32 bytes
 24846 0000881F F3A5                <1> 	rep	movsd
 24847                              <1> 
 24848                              <1> csftdf2_set_sf_percentage:
 24849                              <1> 	; 17/03/2016
 24850 00008821 31C0                <1> 	xor	eax, eax	
 24851 00008823 A2[76D10000]        <1> 	mov 	[csftdf_percentage], al ; 0, reset
 24852                              <1> 
 24853 00008828 A3[6ED10000]        <1> 	mov	[csftdf_sf_rbytes], eax ; 0, reset
 24854 0000882D A3[72D10000]        <1> 	mov	[csftdf_df_wbytes], eax ; 0, reset
 24855                              <1> 
 24856 00008832 8A25[28D00000]      <1> 	mov	ah, [SourceFile_Drv]	
 24857 00008838 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 24858 0000883D 01C6                <1> 	add	esi, eax
 24859                              <1> 	
 24860 0000883F 8935[7AD10000]      <1> 	mov	[csftdf_sf_drv_dt], esi ; 23/03/2016
 24861                              <1> 
 24862 00008845 668B15[8ED00000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
 24863 0000884C C1E210              <1> 	shl	edx, 16
 24864 0000884F 668B15[94D00000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
 24865 00008856 8915[5ED10000]      <1> 	mov	[csftdf_sf_cluster], edx
 24866                              <1> 
 24867                              <1> 	; 16/03/2016
 24868                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
 24869                              <1> 	;	related calculations) has same offset
 24870                              <1> 	;	values from LD_BPB as in FAT file system.
 24871                              <1> 	;	[esi+LD_BPB+SecPerClust] is 1 for Singlix FS.
 24872                              <1> 	;	
 24873 0000885C 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 24874 00008860 880D[A6D00000]      <1> 	mov	[SourceFile_SecPerClust], cl
 24875                              <1> 
 24876                              <1> 	; 17/03/2016
 24877 00008866 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
 24878 00008869 7707                <1> 	ja	short csftdf2_set_sf_percent_rsize1
 24879                              <1> 
 24880 0000886B B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
 24881 00008870 EB06                <1> 	jmp	short csftdf2_set_sf_percent_rsize2	
 24882                              <1>  
 24883                              <1> csftdf2_set_sf_percent_rsize1:
 24884 00008872 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
 24885 00008876 F7E1                <1> 	mul	ecx
 24886                              <1> 	;sub	edx, edx
 24887                              <1> csftdf2_set_sf_percent_rsize2:
 24888 00008878 A3[66D10000]        <1> 	mov	[csftdf_r_size], eax
 24889                              <1> 
 24890                              <1> csftdf2_set_df_percentage:
 24891                              <1> 	;sub	eax, eax
 24892                              <1> 	;mov	ah, [DestinationFile_Drv]	
 24893                              <1> 	;mov	edi, Logical_DOSDisks
 24894                              <1> 	;add	edi, eax
 24895                              <1> 	;mov	[csftdf_df_drv_dt], edi ; 17/03/2016
 24896                              <1> 
 24897 0000887D 8B3D[7ED10000]      <1> 	mov	edi, [csftdf_df_drv_dt] ; 23/03/2016
 24898                              <1> 
 24899                              <1> 	; 16/03/2016
 24900                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
 24901                              <1> 	;	related calculations) has same offset
 24902                              <1> 	;	values from LD_BPB as in FAT file system.
 24903                              <1> 	;	[edi+LD_BPB+SecPerClust] is 1 for Singlix FS.
 24904                              <1> 	;	
 24905                              <1> 	;movzx	ecx, byte [edi+LD_BPB+SecPerClust]
 24906 00008883 8A4F13              <1> 	mov	cl, [edi+LD_BPB+SecPerClust]
 24907 00008886 880D[26D10000]      <1> 	mov	[DestinationFile_SecPerClust], cl
 24908                              <1> 
 24909                              <1> 	; 17/03/2016
 24910 0000888C 386F03              <1> 	cmp	[edi+LD_FATType], ch ; 0
 24911 0000888F 7707                <1> 	ja	short csftdf2_set_df_percent_wsize1
 24912                              <1> 	
 24913 00008891 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
 24914 00008896 EB06                <1> 	jmp	short csftdf2_set_df_percent_wsize2	
 24915                              <1> 
 24916                              <1> csftdf2_set_df_percent_wsize1:
 24917 00008898 0FB74711            <1> 	movzx	eax, word [edi+LD_BPB+BytesPerSec]
 24918 0000889C F7E1                <1> 	mul	ecx
 24919                              <1> 	;sub	edx, edx
 24920                              <1> csftdf2_set_df_percent_wsize2:
 24921 0000889E A3[6AD10000]        <1> 	mov	[csftdf_w_size], eax
 24922                              <1> 
 24923 000088A3 A1[52D10000]        <1> 	mov	eax, [csftdf_filesize]
 24924                              <1> 
 24925 000088A8 3D00000100          <1> 	cmp	eax, 65536 ; 64KB	; small file
 24926 000088AD 721F                <1> 	jb	short csftdf2_load_file ; do not display percentage
 24927                              <1> 	
 24928                              <1> csftdf2_reset_wf_percent_ptr_chk_64k:
 24929 000088AF B201                <1> 	mov	dl, 1 ; 25/03/2016
 24930                              <1> 
 24931 000088B1 3D00000400          <1> 	cmp	eax, 65536*4 ; 256KB
 24932 000088B6 7310                <1> 	jnb	short csftdf2_enable_percentage_display ; big file
 24933                              <1> 
 24934                              <1> 	; 64-128KB file size for floppy disks
 24935 000088B8 3815[28D00000]      <1> 	cmp	byte [SourceFile_Drv], dl ; 1 ; read from floppy disk ?
 24936 000088BE 7608                <1> 	jna	short csftdf2_enable_percentage_display
 24937                              <1> 
 24938 000088C0 3815[A8D00000]      <1> 	cmp	byte [DestinationFile_Drv], dl ; 1 ; write to floppy disk ?
 24939 000088C6 7706                <1> 	ja	short csftdf2_load_file
 24940                              <1> 
 24941                              <1> csftdf2_enable_percentage_display:	
 24942 000088C8 8815[76D10000]      <1> 	mov	[csftdf_percentage], dl ; 1	
 24943                              <1> 	
 24944                              <1> csftdf2_load_file:
 24945                              <1> 	; 19/03/2016
 24946                              <1> 	; 18/03/2016
 24947                              <1> 	; 17/03/2016
 24948 000088CE B40F                <1> 	mov	ah, 0Fh
 24949 000088D0 E8738BFFFF          <1> 	call	int10h
 24950 000088D5 881D[77D10000]      <1> 	mov	[csftdf_videopage], bl ; active video page
 24951 000088DB B403                <1> 	mov	ah, 03h
 24952 000088DD E8668BFFFF          <1> 	call	int10h
 24953 000088E2 668915[78D10000]    <1> 	mov	[csftdf_cursorpos], dx
 24954                              <1> 
 24955 000088E9 29C0                <1> 	sub	eax, eax
 24956 000088EB A2[4FD10000]        <1> 	mov	[csftdf_rw_err], al ; 0 
 24957                              <1> 
 24958                              <1> ; ///
 24959                              <1> csftdf_sf_amb: ; 15/03/2016
 24960 000088F0 8B0D[52D10000]      <1> 	mov	ecx, [csftdf_filesize]	; 23/03/2016
 24961                              <1> 
 24962                              <1> 	; TRDOS 386 (TRDOS v2.0)
 24963                              <1> 	; Allocate contiguous memory block for loading the file
 24964                              <1> 	
 24965                              <1> 	;mov	ecx, [SourceFile_DirEntry+DirEntry_FileSize]
 24966                              <1> 	
 24967                              <1> 	;sub	eax, eax ; First free memory aperture
 24968                              <1> 	
 24969                              <1> 	; eax = 0 (Allocate memory from the beginning)
 24970                              <1> 	; ecx = File (Allocation) size in bytes
 24971                              <1> 	
 24972 000088F6 E8F8AFFFFF          <1> 	call	allocate_memory_block
 24973 000088FB 7304                <1> 	jnc	short loc_check_sf_save_loading_parms
 24974                              <1> 
 24975 000088FD 29C0                <1> 	sub	eax, eax
 24976 000088FF 29C9                <1> 	sub	ecx, ecx
 24977                              <1> 	
 24978                              <1> loc_check_sf_save_loading_parms:
 24979 00008901 A3[56D10000]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
 24980 00008906 890D[5AD10000]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
 24981                              <1> ; ///   
 24982                              <1> 	; 19/03/2016
 24983 0000890C 8B35[7AD10000]      <1> 	mov	esi, [csftdf_sf_drv_dt] ; logical dos drv desc. tbl.
 24984                              <1> 
 24985                              <1> 	; 17/03/2016
 24986 00008912 09C0                <1> 	or	eax, eax ; contiguous free memory block address 
 24987 00008914 0F845B010000        <1>         jz      csftdf2_read_sf_cluster
 24988                              <1> 
 24989                              <1> 	; 18/03/2016
 24990 0000891A 8B1D[56D10000]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
 24991                              <1> 
 24992 00008920 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 24993 00008924 0F8605020000        <1>         jna     csftdf2_load_fs_file
 24994                              <1> 
 24995                              <1> csftdf2_load_fat_file:
 24996 0000892A 53                  <1> 	push	ebx ; *
 24997                              <1> 
 24998                              <1> csftdf2_load_fat_file_next:
 24999 0000892B BE[4BBB0000]        <1> 	mov	esi, msg_reading
 25000 00008930 E895B5FFFF          <1> 	call	print_msg
 25001                              <1> 
 25002 00008935 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25003 0000893C 7605                <1> 	jna	short csftdf2_load_fat_file_1
 25004                              <1> 	
 25005 0000893E E87C000000          <1> 	call	csftdf2_print_percentage ; 19/03/2016
 25006                              <1> 
 25007                              <1> csftdf2_load_fat_file_1:
 25008 00008943 8B35[7AD10000]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
 25009 00008949 5B                  <1> 	pop	ebx ; *
 25010                              <1> 
 25011                              <1> csftdf2_load_fat_file_2:
 25012 0000894A E8B8000000          <1> 	call	csftdf2_read_fat_file_sectors ; 19/03/2016
 25013 0000894F 0F8250040000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
 25014                              <1> 
 25015 00008955 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 25016 00008957 7520                <1> 	jnz	short csftdf2_load_fat_file_ok
 25017                              <1> 
 25018 00008959 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25019 00008960 76E8                <1> 	jna	short csftdf2_load_fat_file_2
 25020                              <1> 
 25021 00008962 53                  <1> 	push	ebx ; *	
 25022                              <1> 
 25023                              <1> 	; Set cursor position
 25024                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 25025 00008963 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25026 00008969 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25027 00008970 B402                <1> 	mov	ah, 2
 25028 00008972 E8D18AFFFF          <1> 	call	int10h
 25029 00008977 EBB2                <1> 	jmp	short csftdf2_load_fat_file_next
 25030                              <1> 	
 25031                              <1> csftdf2_load_fat_file_ok:
 25032 00008979 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25033 00008980 0F8651020000        <1>         jna     csftdf2_save_file ; 25/03/2016
 25034                              <1> 	
 25035                              <1> 	; "Reading... 100%"
 25036 00008986 BF[63BB0000]        <1> 	mov	edi, percentagestr
 25037 0000898B B031                <1> 	mov	al, '1'
 25038 0000898D AA                  <1> 	stosb
 25039 0000898E B030                <1> 	mov	al, '0'
 25040 00008990 AA                  <1> 	stosb
 25041 00008991 AA                  <1> 	stosb
 25042                              <1> 
 25043 00008992 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25044 00008998 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25045 0000899F B402                <1> 	mov	ah, 2
 25046 000089A1 E8A28AFFFF          <1> 	call	int10h
 25047                              <1> 
 25048 000089A6 BE[4BBB0000]        <1> 	mov	esi, msg_reading
 25049 000089AB E81AB5FFFF          <1> 	call	print_msg
 25050                              <1> 	
 25051 000089B0 BE[63BB0000]        <1> 	mov	esi, percentagestr
 25052 000089B5 E810B5FFFF          <1> 	call	print_msg
 25053                              <1> 
 25054 000089BA E918020000          <1>         jmp     csftdf2_save_file ; 25/03/2016
 25055                              <1> 
 25056                              <1> csftdf2_print_percentage:
 25057                              <1> 	; 19/03/2016
 25058                              <1> 	; 18/03/2016
 25059 000089BF B020                <1> 	mov	al, 20h
 25060 000089C1 BF[63BB0000]        <1> 	mov	edi, percentagestr
 25061 000089C6 AA                  <1> 	stosb
 25062 000089C7 AA                  <1> 	stosb
 25063 000089C8 A1[6ED10000]        <1> 	mov	eax, [csftdf_sf_rbytes]
 25064 000089CD BA64000000          <1> 	mov	edx, 100
 25065 000089D2 F7E2                <1> 	mul	edx
 25066 000089D4 8B0D[52D10000]      <1> 	mov	ecx, [csftdf_filesize]	
 25067 000089DA F7F1                <1> 	div	ecx
 25068 000089DC B10A                <1> 	mov	cl, 10
 25069 000089DE F6F1                <1> 	div	cl
 25070 000089E0 80C430              <1> 	add	ah, '0'
 25071 000089E3 8827                <1> 	mov	[edi], ah
 25072 000089E5 20C0                <1> 	and	al, al
 25073 000089E7 740A                <1> 	jz	short csftdf2_print_percent_1
 25074 000089E9 4F                  <1> 	dec	edi
 25075 000089EA 6698                <1> 	cbw
 25076 000089EC F6F1                <1> 	div	cl
 25077 000089EE 80C430              <1> 	add	ah, '0'
 25078 000089F1 8827                <1> 	mov	[edi], ah
 25079                              <1> 	;and	al, al
 25080                              <1> 	;jz	short csftdf2_print_percent_1
 25081                              <1> 	;dec	edi
 25082                              <1> 	;mov	[edi], '1' ; 100%		
 25083                              <1> 
 25084                              <1> csftdf2_print_percent_1:
 25085 000089F3 BE[63BB0000]        <1> 	mov	esi, percentagestr
 25086                              <1> 	;call	print_msg
 25087                              <1> 	;retn
 25088 000089F8 E9CDB4FFFF          <1> 	jmp	print_msg
 25089                              <1> 
 25090                              <1> csftdf2_read_file_sectors:
 25091                              <1> 	; 19/03/2016
 25092 000089FD 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 25093 00008A01 0F8627070000        <1>         jna     csftdf2_read_fs_file_sectors
 25094                              <1> 
 25095                              <1> csftdf2_read_fat_file_sectors:
 25096                              <1> 	; 19/03/2016
 25097                              <1> 	; 18/03/2016
 25098                              <1> 	; return:
 25099                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
 25100                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
 25101                              <1> 	;   CF = 1 -> read error (error code in AL)	
 25102                              <1> 
 25103                              <1> csftdf2_read_fat_file_secs_0:
 25104 00008A07 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25105 00008A0D 2B15[6ED10000]      <1> 	sub	edx, [csftdf_sf_rbytes]
 25106 00008A13 3B15[66D10000]      <1> 	cmp	edx, [csftdf_r_size]	
 25107 00008A19 7306                <1> 	jnb	short csftdf2_read_fat_file_secs_1
 25108 00008A1B 8915[66D10000]      <1> 	mov	[csftdf_r_size], edx
 25109                              <1> 		
 25110                              <1> csftdf2_read_fat_file_secs_1:
 25111 00008A21 A1[66D10000]        <1> 	mov	eax, [csftdf_r_size]
 25112 00008A26 29D2                <1> 	sub	edx, edx
 25113 00008A28 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
 25114 00008A2C 01C8                <1> 	add	eax, ecx
 25115 00008A2E 48                  <1> 	dec	eax
 25116 00008A2F F7F1                <1> 	div	ecx
 25117 00008A31 89C1                <1> 	mov	ecx, eax ; sector count
 25118 00008A33 A1[5ED10000]        <1> 	mov	eax, [csftdf_sf_cluster]
 25119                              <1> 
 25120                              <1> 	; EBX = memory block address (current)
 25121                              <1> 	
 25122 00008A38 E821090000          <1> 	call	read_fat_file_sectors
 25123 00008A3D 7235                <1> 	jc	short csftdf2_read_fat_file_secs_3
 25124                              <1> 
 25125                              <1> 	; EBX = next memory address
 25126                              <1> 
 25127 00008A3F A1[6ED10000]        <1> 	mov	eax, [csftdf_sf_rbytes]
 25128 00008A44 0305[66D10000]      <1> 	add	eax, [csftdf_r_size]
 25129 00008A4A 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25130 00008A50 39D0                <1> 	cmp	eax, edx
 25131 00008A52 7320                <1> 	jnb	short csftdf2_read_fat_file_secs_3 ; edx > 0
 25132 00008A54 A3[6ED10000]        <1> 	mov	[csftdf_sf_rbytes], eax
 25133                              <1> 
 25134 00008A59 53                  <1> 	push	ebx ; *
 25135                              <1> 	; get next cluster (csftdf_r_size! bytes)
 25136 00008A5A A1[5ED10000]        <1> 	mov	eax, [csftdf_sf_cluster]
 25137 00008A5F E8CC060000          <1> 	call	get_next_cluster
 25138 00008A64 5B                  <1> 	pop	ebx ; *
 25139 00008A65 7306                <1> 	jnc	short csftdf2_read_fat_file_secs_2
 25140                              <1> 
 25141 00008A67 B815000000          <1> 	mov	eax, 15h ; Read error !
 25142 00008A6C C3                  <1> 	retn
 25143                              <1> 
 25144                              <1> csftdf2_read_fat_file_secs_2:
 25145 00008A6D 29D2                <1> 	sub	edx, edx ; 0
 25146 00008A6F A3[5ED10000]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
 25147                              <1> 
 25148                              <1> csftdf2_read_fat_file_secs_3:
 25149 00008A74 C3                  <1> 	retn
 25150                              <1> 
 25151                              <1> csftdf2_read_sf_cluster:
 25152                              <1> 	; 19/03/2016
 25153 00008A75 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
 25154                              <1> 
 25155 00008A7A 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25156 00008A81 760D                <1> 	jna	short csftdf2_read_sf_clust_2
 25157                              <1> 
 25158 00008A83 53                  <1> 	push	ebx ; *	
 25159                              <1> 
 25160                              <1> csftdf2_read_sf_clust_next:
 25161 00008A84 E836FFFFFF          <1> 	call	csftdf2_print_percentage
 25162                              <1> 
 25163                              <1> csftdf2_read_sf_clust_0:
 25164 00008A89 8B35[7AD10000]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
 25165                              <1> csftdf2_read_sf_clust_1:
 25166 00008A8F 5B                  <1> 	pop	ebx ; *
 25167                              <1> 
 25168                              <1> csftdf2_read_sf_clust_2:
 25169 00008A90 89DA                <1> 	mov	edx, ebx
 25170 00008A92 0315[66D10000]      <1> 	add	edx, [csftdf_r_size]
 25171 00008A98 81FA00000800        <1> 	cmp	edx, Cluster_Buffer + 65536
 25172 00008A9E 772F                <1> 	ja	short csftdf2_write_df_cluster
 25173                              <1> 
 25174 00008AA0 E858FFFFFF          <1> 	call	csftdf2_read_file_sectors ; 19/03/2016
 25175 00008AA5 0F8280020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
 25176                              <1> 
 25177 00008AAB 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 25178 00008AAD 7520                <1> 	jnz	short csftdf2_write_df_cluster
 25179                              <1> 
 25180 00008AAF 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25181 00008AB6 76D8                <1> 	jna	short csftdf2_read_sf_clust_2
 25182                              <1> 
 25183 00008AB8 53                  <1> 	push	ebx ; *	
 25184                              <1> 
 25185                              <1> 	; Set cursor position
 25186                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 25187 00008AB9 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25188 00008ABF 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25189 00008AC6 B402                <1> 	mov	ah, 2
 25190 00008AC8 E87B89FFFF          <1> 	call	int10h
 25191 00008ACD EBB5                <1> 	jmp	short csftdf2_read_sf_clust_next
 25192                              <1> 
 25193                              <1> csftdf2_write_df_cluster:
 25194                              <1> 	; 19/03/2016
 25195 00008ACF 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt]	
 25196 00008AD5 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
 25197                              <1> 
 25198                              <1> csftdf2_write_df_clust_next:
 25199 00008ADA E855000000          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
 25200 00008ADF 0F8246020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
 25201                              <1> 
 25202 00008AE5 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 25203 00008AE7 750A                <1> 	jnz	short csftdf2_rw_f_clust_ok
 25204                              <1> 
 25205 00008AE9 81FB00000800        <1> 	cmp	ebx, Cluster_Buffer + 65536
 25206 00008AEF 72E9                <1> 	jb	short csftdf2_write_df_clust_next
 25207                              <1> 	
 25208 00008AF1 EB82                <1> 	jmp	short csftdf2_read_sf_cluster
 25209                              <1>  
 25210                              <1> csftdf2_rw_f_clust_ok:
 25211 00008AF3 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25212 00008AFA 0F86B2010000        <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
 25213                              <1> 
 25214                              <1> 	; "100%"
 25215 00008B00 BF[63BB0000]        <1> 	mov	edi, percentagestr
 25216 00008B05 B031                <1> 	mov	al, '1'
 25217 00008B07 AA                  <1> 	stosb
 25218 00008B08 B030                <1> 	mov	al, '0'
 25219 00008B0A AA                  <1> 	stosb
 25220 00008B0B AA                  <1> 	stosb
 25221                              <1> 
 25222 00008B0C 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25223 00008B12 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25224 00008B19 B402                <1> 	mov	ah, 2
 25225 00008B1B E82889FFFF          <1> 	call	int10h
 25226                              <1> 
 25227 00008B20 BE[63BB0000]        <1> 	mov	esi, percentagestr
 25228 00008B25 E8A0B3FFFF          <1> 	call	print_msg
 25229                              <1> 
 25230 00008B2A E983010000          <1>         jmp     csftdf2_save_fat_file_4
 25231                              <1> 
 25232                              <1> csftdf2_load_fs_file:
 25233                              <1> 	; temporary - 18/03/2016
 25234 00008B2F E96F020000          <1>         jmp     csftdf2_read_error
 25235                              <1> 
 25236                              <1> csftdf2_write_file_sectors:
 25237                              <1> 	; 19/03/2016
 25238 00008B34 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 25239 00008B38 0F86F1050000        <1>         jna     csftdf2_write_fs_file_sectors
 25240                              <1> 
 25241                              <1> csftdf2_write_fat_file_sectors:
 25242                              <1> 	; 19/03/2016
 25243                              <1> 	; 18/03/2016
 25244                              <1> 	; return:
 25245                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
 25246                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
 25247                              <1> 	;   CF = 1 -> write error (error code in AL)	
 25248                              <1> 
 25249                              <1> csftdf2_write_fat_file_secs_0:
 25250 00008B3E 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25251 00008B44 2B15[72D10000]      <1> 	sub	edx, [csftdf_df_wbytes]
 25252 00008B4A 3B15[6AD10000]      <1> 	cmp	edx, [csftdf_w_size]	
 25253 00008B50 7306                <1> 	jnb	short csftdf2_write_fat_file_secs_1
 25254 00008B52 8915[6AD10000]      <1> 	mov	[csftdf_w_size], edx		
 25255                              <1> 
 25256                              <1> csftdf2_write_fat_file_secs_1:
 25257 00008B58 A1[6AD10000]        <1> 	mov	eax, [csftdf_w_size]
 25258 00008B5D 29D2                <1> 	sub	edx, edx
 25259 00008B5F 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
 25260 00008B63 01C8                <1> 	add	eax, ecx
 25261 00008B65 48                  <1> 	dec	eax
 25262 00008B66 F7F1                <1> 	div	ecx
 25263 00008B68 89C1                <1> 	mov	ecx, eax ; sector count
 25264 00008B6A A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster]
 25265                              <1> 
 25266                              <1> 	; EBX = memory block address (current)	
 25267                              <1> 
 25268 00008B6F E8A10F0000          <1> 	call	write_fat_file_sectors
 25269 00008B74 7259                <1> 	jc	short csftdf2_write_fat_file_secs_4
 25270                              <1> 
 25271                              <1> 	; EBX = next memory address
 25272                              <1> 
 25273 00008B76 A1[72D10000]        <1> 	mov	eax, [csftdf_df_wbytes]
 25274 00008B7B 0305[6AD10000]      <1> 	add	eax, [csftdf_w_size]
 25275 00008B81 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25276 00008B87 39D0                <1> 	cmp	eax, edx
 25277 00008B89 7344                <1> 	jnb	short csftdf2_write_fat_file_secs_4
 25278 00008B8B A3[72D10000]        <1> 	mov	[csftdf_df_wbytes], eax
 25279                              <1> 	;
 25280 00008B90 A3[16D10000]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
 25281                              <1> 
 25282 00008B95 53                  <1> 	push	ebx ; *
 25283                              <1> 
 25284 00008B96 803D[50D10000]01    <1> 	cmp	byte [DestinationFileFound], 1
 25285 00008B9D 7210                <1> 	jb	short csftdf2_write_fat_file_secs_2
 25286                              <1> 
 25287                              <1> 	; get next cluster (csftdf_w_size! bytes)
 25288 00008B9F A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster]
 25289 00008BA4 E887050000          <1> 	call	get_next_cluster
 25290 00008BA9 731C                <1> 	jnc	short csftdf2_write_fat_file_secs_3
 25291                              <1> 
 25292 00008BAB 21C0                <1> 	and	eax, eax ; end of cluster chain!?
 25293 00008BAD 7521                <1> 	jnz	short csftdf2_write_fat_file_secs_5 ; disk error !
 25294                              <1> 
 25295                              <1> csftdf2_write_fat_file_secs_2:
 25296 00008BAF A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 25297 00008BB4 E8700E0000          <1> 	call	add_new_cluster		
 25298 00008BB9 7215                <1> 	jc	short csftdf2_write_fat_file_secs_5
 25299                              <1> 
 25300                              <1> 	; NOTE: Destination file size may be bigger than
 25301                              <1> 	; source file size when the last reading fails after here.
 25302                              <1> 	; (The last -empty- cluster of destination file must be 
 25303                              <1> 	; truncated and LMDT must be current date&time for partial
 25304                              <1> 	; copy result!) 
 25305 00008BBB 8B15[6AD10000]      <1> 	mov	edx, [csftdf_w_size] ; bytes per cluster
 25306 00008BC1 0115[16D10000]      <1> 	add	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 25307                              <1> 
 25308                              <1> csftdf2_write_fat_file_secs_3:
 25309 00008BC7 5B                  <1> 	pop	ebx ; *
 25310 00008BC8 29D2                <1> 	sub	edx, edx ; 0
 25311 00008BCA A3[62D10000]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
 25312                              <1> 
 25313                              <1> csftdf2_write_fat_file_secs_4:
 25314 00008BCF C3                  <1> 	retn
 25315                              <1> 
 25316                              <1> csftdf2_write_fat_file_secs_5:
 25317 00008BD0 5B                  <1> 	pop	ebx ; *
 25318 00008BD1 B81D000000          <1> 	mov	eax, 1Dh ; Write error !
 25319 00008BD6 C3                  <1> 	retn
 25320                              <1> 
 25321                              <1> csftdf2_save_file:
 25322                              <1> 	; 25/03/2016
 25323                              <1> 	; 19/03/2016
 25324                              <1> 	; 18/03/2016
 25325 00008BD7 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; logical dos drv desc. tbl.
 25326                              <1> 
 25327 00008BDD 8B1D[56D10000]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
 25328                              <1> 
 25329 00008BE3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 25330 00008BE7 0F86F4010000        <1>         jna     csftdf2_save_fs_file
 25331                              <1> 
 25332                              <1> csftdf2_save_fat_file:
 25333 00008BED 53                  <1> 	push	ebx; *
 25334                              <1> 
 25335 00008BEE 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25336 00008BF5 7724                <1> 	ja	short csftdf2_save_fat_file_0
 25337                              <1> 
 25338                              <1> 	; Set cursor position
 25339                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 25340 00008BF7 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25341 00008BFD 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25342 00008C04 B402                <1> 	mov	ah, 2
 25343 00008C06 E83D88FFFF          <1> 	call	int10h
 25344                              <1> 	
 25345 00008C0B BE[57BB0000]        <1> 	mov	esi, msg_writing
 25346 00008C10 E8B5B2FFFF          <1> 	call	print_msg
 25347                              <1> 
 25348                              <1> csftdf2_save_fat_file_next:
 25349 00008C15 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 25/03/2016
 25350                              <1> 
 25351                              <1> csftdf2_save_fat_file_0:
 25352 00008C1B 5B                  <1> 	pop	ebx ; *
 25353                              <1> 
 25354                              <1> csftdf2_save_fat_file_1:
 25355 00008C1C E813FFFFFF          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016	
 25356 00008C21 0F827E010000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
 25357                              <1> 
 25358 00008C27 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 25359 00008C29 756D                <1>         jnz     short csftdf2_save_fat_file_3 ; 25/03/2016
 25360                              <1> 
 25361 00008C2B 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25362 00008C32 76E8                <1> 	jna	short csftdf2_save_fat_file_1
 25363                              <1> 
 25364 00008C34 B020                <1> 	mov	al, 20h
 25365 00008C36 BF[63BB0000]        <1> 	mov	edi, percentagestr
 25366 00008C3B AA                  <1> 	stosb
 25367 00008C3C AA                  <1> 	stosb
 25368 00008C3D A1[72D10000]        <1> 	mov	eax, [csftdf_df_wbytes]
 25369 00008C42 BA64000000          <1> 	mov	edx, 100
 25370 00008C47 F7E2                <1> 	mul	edx
 25371 00008C49 8B0D[52D10000]      <1> 	mov	ecx, [csftdf_filesize]	
 25372 00008C4F F7F1                <1> 	div	ecx
 25373 00008C51 B10A                <1> 	mov	cl, 10
 25374 00008C53 F6F1                <1> 	div	cl
 25375 00008C55 80C430              <1> 	add	ah, '0'
 25376 00008C58 8827                <1> 	mov	[edi], ah
 25377 00008C5A 20C0                <1> 	and	al, al
 25378 00008C5C 740A                <1> 	jz	short csftdf2_save_fat_file_2
 25379 00008C5E 4F                  <1> 	dec	edi
 25380 00008C5F 6698                <1> 	cbw
 25381 00008C61 F6F1                <1> 	div	cl
 25382 00008C63 80C430              <1> 	add	ah, '0'
 25383 00008C66 8827                <1> 	mov	[edi], ah
 25384                              <1> 	;and	al, al
 25385                              <1> 	;jz	short csftdf2_save_fat_file_2
 25386                              <1> 	;dec	edi
 25387                              <1> 	;mov	[edi], '1' ; 100%		
 25388                              <1> 
 25389                              <1> csftdf2_save_fat_file_2:
 25390 00008C68 53                  <1> 	push	ebx ; *
 25391                              <1> 
 25392 00008C69 E802000000          <1> 	call	csftdf2_print_wr_percentage ; 25/03/2016
 25393                              <1> 
 25394 00008C6E EBA5                <1>         jmp     csftdf2_save_fat_file_next
 25395                              <1> 
 25396                              <1> csftdf2_print_wr_percentage:
 25397                              <1> 	; Set cursor position
 25398                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 25399 00008C70 8A1D[77D10000]      <1> 	mov	bl, [csftdf_videopage]
 25400 00008C76 668B15[78D10000]    <1> 	mov	dx, [csftdf_cursorpos]
 25401 00008C7D B402                <1> 	mov	ah, 2
 25402 00008C7F E8C487FFFF          <1> 	call	int10h
 25403                              <1> 
 25404 00008C84 BE[57BB0000]        <1> 	mov	esi, msg_writing
 25405 00008C89 E83CB2FFFF          <1> 	call	print_msg
 25406                              <1> 
 25407 00008C8E BE[63BB0000]        <1> 	mov	esi, percentagestr
 25408                              <1> 	;call	print_msg
 25409                              <1> 	;retn
 25410 00008C93 E932B2FFFF          <1> 	jmp	print_msg
 25411                              <1> 
 25412                              <1> csftdf2_save_fat_file_3:
 25413 00008C98 803D[76D10000]00    <1> 	cmp	byte [csftdf_percentage], 0
 25414 00008C9F 7611                <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
 25415                              <1> 
 25416                              <1> 	; "100%"
 25417 00008CA1 BF[63BB0000]        <1> 	mov	edi, percentagestr
 25418 00008CA6 B031                <1> 	mov	al, '1'
 25419 00008CA8 AA                  <1> 	stosb
 25420 00008CA9 B030                <1> 	mov	al, '0'
 25421 00008CAB AA                  <1> 	stosb
 25422 00008CAC AA                  <1> 	stosb
 25423                              <1> 
 25424 00008CAD E8BEFFFFFF          <1> 	call	csftdf2_print_wr_percentage
 25425                              <1> 
 25426                              <1> csftdf2_save_fat_file_4:
 25427 00008CB2 803D[50D10000]00    <1> 	cmp	byte [DestinationFileFound], 0
 25428 00008CB9 7647                <1> 	jna	short csftdf2_save_fat_file_6
 25429                              <1> 
 25430 00008CBB 8B35[7ED10000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 31/03/2016	
 25431                              <1> 
 25432 00008CC1 A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 25433 00008CC6 E865040000          <1> 	call	get_next_cluster
 25434 00008CCB 7235                <1> 	jc	short csftdf2_save_fat_file_6 ; eocc! or disk error!
 25435                              <1> 
 25436 00008CCD A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 25437                              <1> 	;xor	ecx, ecx
 25438                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 25439                              <1> 	;dec	ecx ; 0FFFFFFFFh
 25440                              <1> 	;shr	ecx, 4 ; 28 bit ; 0FFFFFFFh
 25441 00008CD2 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
 25442 00008CD7 E87E070000          <1> 	call	update_cluster
 25443 00008CDC 7224                <1> 	jc	short csftdf2_save_fat_file_6 ; really last cluster!?
 25444                              <1> 
 25445 00008CDE A3[62D10000]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
 25446                              <1> 	
 25447                              <1> 	; byte [FAT_BuffValidData] = 2 
 25448 00008CE3 E82F0A0000          <1> 	call	save_fat_buffer
 25449 00008CE8 730E                <1> 	jnc	short csftdf2_save_fat_file_5
 25450                              <1> 	
 25451 00008CEA 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25452 00008CF0 8915[16D10000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 25453 00008CF6 EB58                <1> 	jmp	short csftdf2_save_fat_file_err3
 25454                              <1> 
 25455                              <1> csftdf2_save_fat_file_5:
 25456 00008CF8 A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster]
 25457                              <1> 
 25458                              <1> 	; EAX = First cluster to be truncated/unlinked
 25459                              <1> 	; ESI = Logical dos drive description table address
 25460 00008CFD E8480C0000          <1> 	call	truncate_cluster_chain
 25461                              <1> 
 25462                              <1> csftdf2_save_fat_file_6:
 25463                              <1> 	; 28/03/2016
 25464 00008D02 BE[85D00000]        <1> 	mov	esi, SourceFile_DirEntry+DirEntry_Attr ; +11 to + 18
 25465 00008D07 BF[05D10000]        <1> 	mov	edi, DestinationFile_DirEntry+DirEntry_Attr ; +11 to + 18
 25466 00008D0C A4                  <1> 	movsb ; +11
 25467 00008D0D A5                  <1> 	movsd ; +12 .. +15
 25468 00008D0E 66A5                <1> 	movsw ; +16 .. +17
 25469                              <1> 		; + 18
 25470 00008D10 83C604              <1> 	add	esi, 4
 25471 00008D13 83C704              <1> 	add	edi, 4
 25472 00008D16 A5                  <1> 	movsd	; DirEntry_WrtTime ; +22 .. +25
 25473                              <1> 
 25474 00008D17 8B15[52D10000]      <1> 	mov	edx, [csftdf_filesize]
 25475 00008D1D 8915[16D10000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 25476                              <1> 
 25477 00008D23 E8D7F0FFFF          <1> 	call	convert_current_date_time
 25478                              <1> 	; DX = Date in dos dir entry format
 25479                              <1> 	; AX = Time in dos dir entry format
 25480 00008D28 EB4D                <1> 	jmp	short csftdf2_save_fat_file_7
 25481                              <1> 
 25482                              <1> csftdf2_save_fat_file_err1:
 25483 00008D2A 5B                  <1> 	pop	ebx ; *	
 25484                              <1> csftdf2_save_fat_file_err2:
 25485 00008D2B A1[72D10000]        <1> 	mov	eax, [csftdf_df_wbytes]
 25486 00008D30 8B15[16D10000]      <1> 	mov	edx, [DestinationFile_DirEntry+DirEntry_FileSize]
 25487 00008D36 39C2                <1> 	cmp	edx, eax
 25488 00008D38 7616                <1> 	jna	short csftdf2_save_fat_file_err3
 25489 00008D3A A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster] ; last (empty) cluster
 25490                              <1> 	; ESI = Logical dos drive description table address
 25491 00008D3F E8060C0000          <1> 	call	truncate_cluster_chain
 25492 00008D44 720A                <1> 	jc	short csftdf2_save_fat_file_err3
 25493 00008D46 A1[72D10000]        <1> 	mov	eax, [csftdf_df_wbytes]	
 25494 00008D4B A3[16D10000]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
 25495                              <1> csftdf2_save_fat_file_err3:
 25496 00008D50 E8AAF0FFFF          <1> 	call	convert_current_date_time
 25497                              <1> 	; DX = Date in dos dir entry format
 25498                              <1> 	; AX = Time in dos dir entry format
 25499 00008D55 C605[07D10000]00    <1> 	mov	byte [DestinationFile_DirEntry+DirEntry_CrtTimeTenth], 0
 25500 00008D5C 66A3[08D10000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtTime], ax
 25501 00008D62 668915[0AD10000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtDate], dx		
 25502 00008D69 66A3[10D10000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtTime], ax
 25503 00008D6F 668915[12D10000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtDate], dx
 25504 00008D76 F9                  <1> 	stc
 25505                              <1> csftdf2_save_fat_file_7:
 25506 00008D77 9C                  <1> 	pushf
 25507 00008D78 668915[0CD10000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_LastAccDate], dx
 25508 00008D7F BE[FAD00000]        <1> 	mov	esi, DestinationFile_DirEntry
 25509 00008D84 BF00000800          <1> 	mov	edi, Directory_Buffer
 25510 00008D89 0FB70D[22D10000]    <1> 	movzx	ecx, word [DestinationFile_DirEntryNumber] ; (<2048)
 25511 00008D90 66C1E105            <1> 	shl	cx, 5 ; 32 * directory entry number
 25512 00008D94 01CF                <1> 	add	edi, ecx
 25513                              <1> 	;mov	ecx, 8
 25514 00008D96 66B90800            <1> 	mov	cx, 8
 25515 00008D9A F3A5                <1> 	rep	movsd
 25516 00008D9C 9D                  <1> 	popf
 25517 00008D9D 730B                <1> 	jnc	short csftdf2_write_file_OK
 25518                              <1> 	 		
 25519                              <1> csftdf2_write_error:
 25520                              <1> 	; 18/03/2016
 25521 00008D9F B01D                <1> 	mov	al, 1Dh ; write error
 25522 00008DA1 EB02                <1> 	jmp	short csftdf2_rw_error
 25523                              <1> 
 25524                              <1> 	; 16/03/2016
 25525                              <1> csftdf2_read_error:
 25526 00008DA3 B015                <1> 	mov	al, 15h ; ; Drive not ready or read error!
 25527                              <1> csftdf2_rw_error:
 25528 00008DA5 A2[4FD10000]        <1> 	mov	[csftdf_rw_err], al 
 25529                              <1> 
 25530                              <1> csftdf2_write_file_OK:
 25531                              <1> 	; 18/03/2016
 25532 00008DAA C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 25533 00008DB1 E8E7F0FFFF          <1> 	call	save_directory_buffer
 25534                              <1> 
 25535                              <1>  	; Update last modification date&time of destination
 25536                              <1> 	; file's (parent) directory
 25537 00008DB6 E87DF1FFFF          <1> 	call	update_parent_dir_lmdt
 25538                              <1> 	;
 25539 00008DBB A1[56D10000]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
 25540                              <1> 
 25541 00008DC0 21C0                <1> 	and	eax, eax
 25542 00008DC2 750E                <1> 	jnz	short csftdf2_dealloc_mblock
 25543                              <1> 
 25544 00008DC4 88C5                <1> 	mov	ch, al ; 0 (Cluster r/w, not full loading)
 25545                              <1> csftdf2_dealloc_retn:
 25546 00008DC6 8A0D[4FD10000]      <1> 	mov	cl, [csftdf_rw_err]
 25547 00008DCC A1[62D10000]        <1> 	mov	eax, [csftdf_df_cluster]
 25548 00008DD1 C3                  <1> 	retn
 25549                              <1> 
 25550                              <1> csftdf2_dealloc_mblock:
 25551 00008DD2 8B0D[5AD10000]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
 25552 00008DD8 E817ADFFFF          <1> 	call	deallocate_memory_block
 25553 00008DDD B5FF                <1>         mov     ch, 0FFh ; (File was full loaded at memory)
 25554 00008DDF EBE5                <1> 	jmp	short csftdf2_dealloc_retn
 25555                              <1> 
 25556                              <1> csftdf2_save_fs_file:
 25557                              <1> 	; temporary - (21/03/2016)
 25558 00008DE1 B81D000000          <1> 	mov	eax, 1Dh ; write error
 25559 00008DE6 F9                  <1> 	stc
 25560 00008DE7 C3                  <1> 	retn
 25561                              <1> 
 25562                              <1> create_file:
 25563                              <1> 	; 31/03/2016
 25564                              <1> 	; 24/03/2016
 25565                              <1> 	; 23/03/2016
 25566                              <1> 	; 21/03/2016
 25567                              <1> 	; 20/03/2016
 25568                              <1> 	; 19/03/2016 (TRDOS 396 = TRDOS v2.0)
 25569                              <1> 	; 03/09/2011 (FILE.ASM, 'proc_create_file')
 25570                              <1> 	; 09/08/2010
 25571                              <1> 	;
 25572                              <1> 	; INPUT ->
 25573                              <1> 	; 	EAX = File Size
 25574                              <1> 	; 	ESI = ASCIIZ File Name
 25575                              <1> 	; 	CL = File Attributes 
 25576                              <1> 	;	EBX = FFFFFFFFh -> create empty file 
 25577                              <1> 	;			 (only for FAT fs) 
 25578                              <1> 	; OUTPUT ->
 25579                              <1> 	;     CF = 0 ->
 25580                              <1> 	;	EAX = New file's first cluster
 25581                              <1> 	; 	ESI = Logical Dos Drv Descr. Table Addr.
 25582                              <1> 	; 	EBX = offset CreateFile_Size
 25583                              <1> 	; 	ECX = Sectors per cluster (<256) 
 25584                              <1> 	; 	EDX = Directory entry index/number (<65536)
 25585                              <1> 	;     CF = 1 -> error code in AL
 25586                              <1> 
 25587                              <1> ;	test	cl, 18h (directory or volume name)
 25588                              <1> ;	jnz	short loc_createfile_access_denied
 25589 00008DE8 80E107              <1> 	and	cl, 07h ; S, H, R
 25590 00008DEB 880D[9ED10000]      <1>         mov     [createfile_attrib], cl 
 25591                              <1> 
 25592 00008DF1 89D9                <1> 	mov	ecx, ebx
 25593 00008DF3 89F3                <1> 	mov	ebx, esi ; ASCIIZ File Name address
 25594 00008DF5 29D2                <1> 	sub	edx, edx
 25595 00008DF7 8A35[42C50000]      <1>         mov     dh, [Current_Drv]
 25596 00008DFD BE00010900          <1>         mov     esi, Logical_DOSDisks
 25597 00008E02 01D6                <1> 	add	esi, edx
 25598                              <1> 
 25599 00008E04 8815[A9D10000]      <1> 	mov	[createfile_UpdatePDir], dl ; 0 ; 31/03/2016 
 25600                              <1> 
 25601                              <1> 	; LD_DiskType = 0 for write protection (read only) 
 25602 00008E0A 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
 25603 00008E0E 730A                <1> 	jnb	short loc_createfile_check_file_sytem
 25604 00008E10 B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
 25605 00008E15 66BA0000            <1> 	mov	dx, 0
 25606                              <1> 	; err retn: EDX = 0, EBX = File name offset
 25607                              <1> 	; ESI -> Dos drive description table address	
 25608 00008E19 C3                  <1> 	retn
 25609                              <1> 
 25610                              <1> ;loc_createfile_access_denied:
 25611                              <1> ;	mov	eax, 05h ; access denied (invalid attributes input)
 25612                              <1> ;	stc
 25613                              <1> ;	retn
 25614                              <1> 
 25615                              <1> loc_createfile_check_file_sytem:
 25616 00008E1A 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 25617 00008E1E 730A                <1> 	jnb	short loc_createfile_chk_empty_FAT_file_sign1
 25618                              <1> 
 25619 00008E20 A3[8AD10000]        <1> 	mov	[createfile_size], eax
 25620                              <1> 	; ESI = Logical Dos Drive Description Table address
 25621                              <1> 	; EBX = ASCIIZ File Name address
 25622 00008E25 E9FE020000          <1> 	jmp	create_fs_file
 25623                              <1> 
 25624                              <1> loc_createfile_chk_empty_FAT_file_sign1:
 25625                              <1> 	; ECX = FFFFFFFFh -> create empty file if drive has FAT fs
 25626 00008E2A 41                  <1> 	inc	ecx
 25627 00008E2B 7506                <1> 	jnz	short loc_createfile_chk_empty_FAT_file_sign2
 25628 00008E2D 890D[8AD10000]      <1> 	mov	[createfile_size], ecx ; 0 ; empty file
 25629                              <1> 
 25630                              <1> loc_createfile_chk_empty_FAT_file_sign2:
 25631                              <1> 	; 23/03/2016
 25632 00008E33 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec]
 25633 00008E37 66890D[A6D10000]    <1> 	mov	[createfile_BytesPerSec], cx
 25634                              <1> 	
 25635                              <1> 	; EBX = ASCIIZ File Name address
 25636 00008E3E 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
 25637 00008E42 8815[9FD10000]      <1> 	mov	[createfile_SecPerClust], dl
 25638 00008E48 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 25639 00008E4B 39D1                <1> 	cmp	ecx, edx ; byte [createfile_SecPerClust]
 25640 00008E4D 7306                <1> 	jnb	short loc_create_fat_file
 25641                              <1> 	  
 25642                              <1> loc_createfile_insufficient_disk_space:
 25643 00008E4F B827000000          <1> 	mov	eax, 27h
 25644                              <1> loc_createfile_gffc_retn:
 25645 00008E54 C3                  <1> 	retn
 25646                              <1> 
 25647                              <1> loc_create_fat_file:
 25648 00008E55 891D[82D10000]      <1> 	mov	[createfile_Name_Offset], ebx
 25649 00008E5B 890D[86D10000]      <1> 	mov	[createfile_FreeSectors], ecx
 25650                              <1> 
 25651                              <1> loc_createfile_gffc_1:
 25652 00008E61 E821050000          <1> 	call	get_first_free_cluster
 25653 00008E66 72EC                <1> 	jc	short loc_createfile_gffc_retn
 25654                              <1> 
 25655 00008E68 A3[8ED10000]        <1> 	mov	[createfile_FFCluster], eax
 25656                              <1> 
 25657                              <1> loc_createfile_locate_ffe_on_directory:
 25658                              <1> 	; Current directory fcluster <> Directory buffer cluster
 25659                              <1> 	; Current directory will be reloaded by
 25660                              <1> 	; 'locate_current_dir_file' procedure
 25661                              <1> 	;
 25662                              <1> 	; ESI = Logical Dos Drv Desc. Table Adress
 25663 00008E6D 56                  <1> 	push	esi ; *
 25664 00008E6E 31C0                <1> 	xor	eax, eax
 25665                              <1> 
 25666 00008E70 A3[61CD0000]        <1> 	mov	dword [FAT_ClusterCounter], eax ; 0
 25667                              <1> 	; 21/03/2016
 25668 00008E75 A2[A8D10000]        <1> 	mov	byte [createfile_wfc], al ; 0 
 25669                              <1> 
 25670 00008E7A 89C1                <1>  	mov	ecx, eax
 25671 00008E7C 6649                <1> 	dec	cx ; FFFFh  
 25672                              <1> 	; CX = FFFFh -> find first deleted or free entry
 25673                              <1> 	; ESI would be ASCIIZ filename Address if the call
 25674                              <1> 	; would not be for first free or deleted dir entry  
 25675 00008E7E E8F6E7FFFF          <1> 	call	locate_current_dir_file
 25676 00008E83 0F83EE000000        <1> 	jnc	loc_createfile_set_ff_dir_entry
 25677 00008E89 5E                  <1> 	pop	esi ; *
 25678                              <1> 	 ; ESI = Logical DOS Drv. Description Table Address 
 25679 00008E8A 83F802              <1> 	cmp	eax, 2
 25680 00008E8D 7402                <1> 	je	short loc_createfile_add_new_cluster
 25681                              <1> loc_createfile_locate_file_stc_retn:
 25682 00008E8F F9                  <1> 	stc
 25683 00008E90 C3                  <1> 	retn
 25684                              <1> 
 25685                              <1> loc_createfile_add_new_cluster:
 25686 00008E91 803D[41C50000]02    <1> 	cmp	byte [Current_FATType], 2
 25687                              <1> 	;cmp	byte [esi+LD_FATType], 2
 25688 00008E98 770C                <1> 	ja	short loc_createfile_add_new_cluster_check_fsc
 25689 00008E9A 803D[40C50000]01    <1> 	cmp	byte [Current_Dir_Level], 1
 25690                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
 25691 00008EA1 7303                <1> 	jnb	short loc_createfile_add_new_cluster_check_fsc
 25692                              <1> 	
 25693                              <1> 	;mov	eax, 12
 25694 00008EA3 B00C                <1> 	mov	al, 12 ; No more files 
 25695                              <1> 
 25696                              <1> loc_createfile_anc_retn:
 25697 00008EA5 C3                  <1> 	retn
 25698                              <1> 
 25699                              <1> loc_createfile_add_new_cluster_check_fsc:
 25700 00008EA6 8B0D[86D10000]      <1> 	mov	ecx, [createfile_FreeSectors]
 25701 00008EAC 0FB605[9FD10000]    <1> 	movzx	eax, byte [createfile_SecPerClust]
 25702 00008EB3 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
 25703 00008EB6 39C1                <1> 	cmp	ecx, eax
 25704 00008EB8 7295                <1>         jb	short loc_createfile_insufficient_disk_space
 25705                              <1> 
 25706                              <1> loc_createfile_add_new_subdir_cluster:
 25707 00008EBA 8B15[71CD0000]      <1> 	mov	edx, [DirBuff_Cluster]
 25708 00008EC0 8915[92D10000]      <1> 	mov	[createfile_LastDirCluster], edx	
 25709                              <1> 
 25710 00008EC6 A1[8ED10000]        <1> 	mov	eax, [createfile_FFCluster]
 25711 00008ECB E846040000          <1> 	call	load_FAT_sub_directory 
 25712 00008ED0 72D3                <1> 	jc	short loc_createfile_anc_retn
 25713                              <1> 
 25714                              <1> pass_createfile_add_new_subdir_cluster:
 25715                              <1> 	;movzx	eax, word [esi+LD_BPB+BytesPerSec]
 25716 00008ED2 0FB705[A6D10000]    <1> 	movzx	eax, word [createfile_BytesPerSec] ; 23/03/2016
 25717 00008ED9 F7E1                <1> 	mul	ecx ; ecx = directory buffer sector count
 25718 00008EDB 89C1                <1> 	mov	ecx, eax
 25719 00008EDD C1E902              <1> 	shr	ecx, 2 ; dword count
 25720 00008EE0 29C0                <1> 	sub	eax, eax ; 0
 25721 00008EE2 F3AB                <1> 	rep	stosd 
 25722                              <1> 	;
 25723 00008EE4 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 25724 00008EEB E8ADEFFFFF          <1> 	call	save_directory_buffer
 25725 00008EF0 72B3                <1> 	jc	short loc_createfile_anc_retn
 25726                              <1> 
 25727                              <1> loc_createfile_save_added_subdir_cluster:
 25728 00008EF2 A1[92D10000]        <1> 	mov	eax, [createfile_LastDirCluster]
 25729 00008EF7 8B0D[8ED10000]      <1> 	mov	ecx, [createfile_FFCluster]
 25730 00008EFD E858050000          <1> 	call	update_cluster
 25731 00008F02 7304                <1> 	jnc	short loc_createfile_save_fat_buffer_0
 25732 00008F04 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 25733 00008F06 751A                <1> 	jnz	short loc_createfile_save_fat_buffer_stc_retn
 25734                              <1> 
 25735                              <1> loc_createfile_save_fat_buffer_0:
 25736 00008F08 A1[8ED10000]        <1> 	mov	eax, [createfile_FFCluster]
 25737 00008F0D A3[92D10000]        <1> 	mov	[createfile_LastDirCluster], eax
 25738 00008F12 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh ; 28 bit
 25739 00008F17 E83E050000          <1> 	call	update_cluster
 25740 00008F1C 7306                <1> 	jnc	short loc_createfile_save_fat_buffer_1
 25741 00008F1E 09C0                <1> 	or	eax, eax ; Was it free cluster
 25742 00008F20 7402                <1> 	jz	short loc_createfile_save_fat_buffer_1
 25743                              <1> 
 25744                              <1> loc_createfile_save_fat_buffer_stc_retn:
 25745 00008F22 F9                  <1> 	stc
 25746                              <1> loc_createfile_save_fat_buffer_retn:
 25747                              <1> loc_createfile_gffc_2_stc_retn:
 25748 00008F23 C3                  <1> 	retn
 25749                              <1> 
 25750                              <1> loc_createfile_save_fat_buffer_1:
 25751                              <1> 	; byte [FAT_BuffValidData] = 2 
 25752 00008F24 E8EE070000          <1> 	call	save_fat_buffer
 25753 00008F29 72F8                <1> 	jc	short loc_createfile_save_fat_buffer_retn
 25754                              <1> 
 25755 00008F2B 803D[61CD0000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 25756 00008F32 7222                <1> 	jb	short loc_createfile_save_fat_buffer_2
 25757                              <1> 
 25758                              <1> 	; ESI = Logical DOS Drive Description Table address 
 25759 00008F34 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 25760                              <1> 
 25761 00008F39 C605[61CD0000]00    <1> 	mov	byte [FAT_ClusterCounter], 0 ; 21/03/2016
 25762                              <1> 
 25763 00008F40 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 25764 00008F44 E863080000          <1> 	call	calculate_fat_freespace
 25765                              <1> 
 25766                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 25767                              <1> 	;jnz	short loc_createfile_save_fat_buffer_2
 25768                              <1> 
 25769                              <1> 	; ecx > 0 -> Recalculation is needed
 25770 00008F49 09C9                <1> 	or	ecx, ecx 
 25771 00008F4B 7409                <1> 	jz	short loc_createfile_save_fat_buffer_2
 25772                              <1> 
 25773 00008F4D 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 25774 00008F51 E856080000          <1> 	call	calculate_fat_freespace
 25775                              <1> 
 25776                              <1> loc_createfile_save_fat_buffer_2:
 25777                              <1> 	;call	update_parent_dir_lmdt
 25778                              <1> 
 25779                              <1> loc_createfile_gffc_2:
 25780 00008F56 E82C040000          <1> 	call	get_first_free_cluster
 25781 00008F5B 72C6                <1> 	jc	short loc_createfile_gffc_2_stc_retn
 25782                              <1> 
 25783 00008F5D A3[8ED10000]        <1> 	mov	[createfile_FFCluster], eax
 25784                              <1> 
 25785 00008F62 A1[92D10000]        <1> 	mov	eax, [createfile_LastDirCluster]
 25786                              <1> 	
 25787 00008F67 E8AA030000          <1> 	call	load_FAT_sub_directory 
 25788 00008F6C 72B5                <1> 	jc	short loc_createfile_gffc_2_stc_retn
 25789                              <1> 
 25790 00008F6E BF00000800          <1> 	mov	edi, Directory_Buffer
 25791                              <1> 
 25792 00008F73 6629DB              <1> 	sub	bx, bx ; directory entry index/number = 0
 25793                              <1> 
 25794 00008F76 56                  <1> 	push	esi ; * ; 23/03/2016
 25795                              <1> 
 25796                              <1> loc_createfile_set_ff_dir_entry:
 25797 00008F77 66891D[A0D10000]    <1> 	mov	[createfile_DirIndex], bx
 25798                              <1> 
 25799                              <1>         ; EDI = Directory entry address
 25800 00008F7E 8B35[82D10000]      <1> 	mov	esi, [createfile_Name_Offset]
 25801 00008F84 A1[8ED10000]        <1> 	mov	eax, [createfile_FFCluster]
 25802 00008F89 A3[96D10000]        <1> 	mov	[createfile_Cluster], eax ; 24/03/2016
 25803 00008F8E B5FF                <1> 	mov	ch, 0FFh
 25804 00008F90 8A0D[9ED10000]      <1>         mov	cl, [createfile_attrib] ; file attributes
 25805                              <1> 	; CH > 0 -> File size is in EBX
 25806 00008F96 BB[8AD10000]        <1> 	mov	ebx, createfile_size
 25807                              <1>   
 25808 00008F9B E820EEFFFF          <1> 	call	make_directory_entry
 25809                              <1> 	
 25810 00008FA0 5E                  <1> 	pop	esi ; * ; ESI = Logical Dos Drv Desc. Table address
 25811                              <1> 
 25812 00008FA1 C605[6CCD0000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 25813 00008FA8 E8F0EEFFFF          <1> 	call	save_directory_buffer
 25814 00008FAD 7221                <1> 	jc	short loc_createfile_set_ff_dir_entry_retn
 25815                              <1> 
 25816 00008FAF C605[A9D10000]01    <1> 	mov	byte [createfile_UpdatePDir], 1 ; 31/03/2016 
 25817                              <1> 
 25818                              <1> loc_createfile_get_set_write_file_cluster:
 25819 00008FB6 A1[8AD10000]        <1> 	mov	eax, [createfile_size]
 25820 00008FBB 09C0                <1> 	or	eax, eax
 25821 00008FBD 7570                <1> 	jnz	short loc_createfile_get_set_wfc_cont
 25822 00008FBF 40                  <1> 	inc	eax
 25823                              <1> 	; 23/03/2016
 25824 00008FC0 0FB61D[9FD10000]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
 25825                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
 25826 00008FC7 0FB70D[A6D10000]    <1>         movzx   ecx, word [createfile_BytesPerSec] ; 512
 25827 00008FCE EB7C                <1> 	jmp	loc_createfile_set_cluster_count 
 25828                              <1> 
 25829                              <1> loc_createfile_set_ff_dir_entry_retn:
 25830 00008FD0 C3                  <1> 	retn
 25831                              <1> 
 25832                              <1> loc_createfile_write_fcluster_to_disk:
 25833 00008FD1 034668              <1> 	add	eax, [esi+LD_DATABegin] ; convert to physical address
 25834 00008FD4 BB00000700          <1> 	mov	ebx, Cluster_Buffer
 25835                              <1> 	; ESI = Logical DOS Drv. Desc. Tbl. address
 25836                              <1> 	; EAX = Disk address
 25837                              <1> 	; EBX = Sector Buffer
 25838                              <1> 	; ECX = sectors per cluster
 25839 00008FD9 E8CF210000          <1> 	call	disk_write
 25840 00008FDE 7211                <1> 	jc	short loc_createfile_dsk_wr_err
 25841                              <1> 
 25842                              <1> loc_createfile_update_fat_cluster:
 25843                              <1> 	; 21/03/2016	
 25844 00008FE0 803D[A8D10000]00    <1> 	cmp	byte [createfile_wfc], 0 
 25845 00008FE7 7712                <1> 	ja	short loc_createfile_update_fat_cluster_n1
 25846                              <1> 
 25847 00008FE9 FE05[A8D10000]      <1> 	inc	byte [createfile_wfc] ; 1
 25848 00008FEF EB24                <1> 	jmp	short loc_createfile_update_fat_cluster_n2
 25849                              <1> 
 25850                              <1> loc_createfile_dsk_wr_err:
 25851                              <1> 	; 23/03/2016
 25852 00008FF1 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
 25853 00008FF6 E9BD000000          <1> 	jmp	loc_createfile_stc_retn
 25854                              <1> 
 25855                              <1> loc_createfile_update_fat_cluster_n1:
 25856 00008FFB A1[9AD10000]        <1> 	mov	eax, [createfile_PCluster]
 25857 00009000 8B0D[96D10000]      <1> 	mov	ecx, [createfile_Cluster]
 25858 00009006 E84F040000          <1> 	call	update_cluster
 25859 0000900B 7308                <1> 	jnc	short loc_createfile_update_fat_cluster_n2
 25860 0000900D 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 25861 0000900F 0F85A3000000        <1> 	jnz	loc_createfile_stc_retn
 25862                              <1> 
 25863                              <1> loc_createfile_update_fat_cluster_n2:
 25864 00009015 A1[96D10000]        <1>         mov	eax, [createfile_Cluster]
 25865 0000901A B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
 25866 0000901F E836040000          <1> 	call	update_cluster
 25867 00009024 734E                <1> 	jnc	short loc_createfile_save_fat_buffer_3
 25868 00009026 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 25869 00009028 744A                <1> 	jz	short loc_createfile_save_fat_buffer_3
 25870                              <1> 
 25871                              <1> loc_createfile_upd_fat_fcluster_stc_retn:
 25872 0000902A E989000000          <1> 	jmp	loc_createfile_stc_retn
 25873                              <1> 
 25874                              <1> loc_createfile_get_set_wfc_cont:
 25875                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512	
 25876 0000902F 0FB70D[A6D10000]    <1> 	movzx	ecx, word [createfile_BytesPerSec] ; 512
 25877 00009036 01C8                <1> 	add	eax, ecx
 25878 00009038 48                  <1> 	dec	eax  ; add eax, 511
 25879 00009039 29D2                <1> 	sub	edx, edx
 25880 0000903B F7F1                <1> 	div	ecx
 25881 0000903D 0FB61D[9FD10000]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
 25882 00009044 01D8                <1> 	add	eax, ebx
 25883 00009046 48                  <1> 	dec	eax  ; add eax, SecPerClust - 1
 25884 00009047 6631D2              <1> 	xor	dx, dx
 25885 0000904A F7F3                <1> 	div	ebx
 25886                              <1> 
 25887                              <1> loc_createfile_set_cluster_count:
 25888 0000904C A3[A2D10000]        <1> 	mov 	[createfile_CCount], eax
 25889                              <1> 	
 25890 00009051 BF00000700          <1> 	mov	edi, Cluster_Buffer
 25891 00009056 89C8                <1> 	mov	eax, ecx ; Bytes per Sector
 25892 00009058 F7E3                <1> 	mul	ebx ; Sectors per Cluster 
 25893                              <1> 	; EAX = Bytes per Cluster
 25894 0000905A 89C1                <1> 	mov	ecx, eax
 25895 0000905C C1E902              <1> 	shr	ecx, 2 ; dword count
 25896 0000905F 31C0                <1> 	xor	eax, eax
 25897 00009061 F3AB                <1> 	rep	stosd ; clear cluster buffer
 25898                              <1> 
 25899 00009063 A1[96D10000]        <1> 	mov	eax, [createfile_Cluster] ; 24/03/2016
 25900                              <1> 
 25901 00009068 89D9                <1> 	mov	ecx, ebx
 25902                              <1> 
 25903                              <1> loc_createfile_get_set_wf_fclust_cont:
 25904 0000906A 83E802              <1> 	sub	eax, 2
 25905 0000906D F7E1                <1> 	mul	ecx
 25906                              <1> 	; EAX = Logical DOS disk address (offset)
 25907 0000906F E95DFFFFFF          <1>         jmp     loc_createfile_write_fcluster_to_disk
 25908                              <1> 
 25909                              <1> loc_createfile_save_fat_buffer_3:
 25910                              <1> 	; byte [FAT_BuffValidData] = 2
 25911 00009074 E89E060000          <1> 	call	save_fat_buffer
 25912 00009079 723D                <1> 	jc	loc_createfile_stc_retn
 25913                              <1> 
 25914                              <1> 	; 21/03/2016
 25915 0000907B 803D[61CD0000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 25916 00009082 721B                <1> 	jb	short loc_createfile_save_fat_buffer_4
 25917                              <1> 
 25918                              <1> 	; ESI = Logical DOS Drive Description Table address 
 25919 00009084 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 25920 00009089 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 25921 0000908D E81A070000          <1> 	call	calculate_fat_freespace
 25922                              <1> 
 25923                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 25924                              <1> 	;jnz	short loc_createfile_save_fat_buffer_4
 25925                              <1> 
 25926                              <1> 	; ecx > 0 -> Recalculation is needed
 25927 00009092 09C9                <1> 	or	ecx, ecx 
 25928 00009094 7409                <1> 	jz	short loc_createfile_save_fat_buffer_4
 25929                              <1> 
 25930 00009096 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 25931 0000909A E80D070000          <1> 	call	calculate_fat_freespace
 25932                              <1> 
 25933                              <1> loc_createfile_save_fat_buffer_4:
 25934 0000909F FF0D[A2D10000]      <1> 	dec	dword [createfile_CCount]
 25935                              <1> 	;jz	short loc_createfile_upd_dir_modif_date_time
 25936 000090A5 743F                <1> 	jz	short loc_createfile_stc_retn_cc ; 31/03/2016
 25937                              <1> 
 25938                              <1> loc_createfile_get_set_write_next_cluster:
 25939 000090A7 E8DB020000          <1> 	call	get_first_free_cluster
 25940 000090AC 720A                <1> 	jc	short loc_createfile_stc_retn
 25941                              <1> 
 25942                              <1> loc_createfile_get_set_write_next_cluster_1:
 25943 000090AE 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
 25944 000090B1 7213                <1> 	jb	short loc_createfile_get_set_write_next_cluster_2
 25945                              <1> 
 25946                              <1> loc_createfile_wnc_insufficient_disk_space:	
 25947 000090B3 B827000000          <1> 	mov	eax, 27h ; Insufficient disk space
 25948                              <1> 
 25949                              <1> loc_createfile_stc_retn:
 25950 000090B8 803D[A8D10000]01    <1> 	cmp	byte [createfile_wfc], 1
 25951 000090BF 7324                <1> 	jnb	short loc_createfile_err_retn
 25952 000090C1 C3                  <1> 	retn
 25953                              <1> 
 25954                              <1> loc_createfile_wnc_inv_format_retn:
 25955                              <1> 	;mov	eax, 0Bh
 25956 000090C2 B00B                <1> 	mov	al, 0Bh ; Invalid format
 25957 000090C4 EBF2                <1> 	jmp	short loc_createfile_stc_retn
 25958                              <1> 	         
 25959                              <1> loc_createfile_get_set_write_next_cluster_2:
 25960 000090C6 83F802              <1> 	cmp	eax, 2
 25961 000090C9 72F7                <1> 	jb	short loc_createfile_wnc_inv_format_retn
 25962                              <1> 
 25963                              <1> loc_createfile_get_set_write_next_cluster_3:
 25964 000090CB 8B0D[96D10000]      <1> 	mov	ecx, [createfile_Cluster]
 25965 000090D1 A3[96D10000]        <1> 	mov	[createfile_Cluster], eax
 25966 000090D6 890D[9AD10000]      <1> 	mov	[createfile_PCluster], ecx
 25967 000090DC 0FB60D[9FD10000]    <1> 	movzx	ecx, byte [createfile_SecPerClust]
 25968 000090E3 EB85                <1> 	jmp	short loc_createfile_get_set_wf_fclust_cont
 25969                              <1> 
 25970                              <1> loc_createfile_err_retn:
 25971 000090E5 F9                  <1> 	stc
 25972                              <1> 
 25973                              <1> ;loc_createfile_upd_dir_modif_date_time:
 25974                              <1> loc_createfile_stc_retn_cc: ; 31/03/2016
 25975 000090E6 9C                  <1> 	pushf	; cpu is here for an error return or completion 
 25976 000090E7 50                  <1> 	push	eax ; error code if cf = 1
 25977                              <1> 
 25978                              <1> 	;call	update_parent_dir_lmdt
 25979                              <1> 
 25980                              <1> ;loc_createfile_stc_retn_cc:
 25981 000090E8 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 25982 000090ED 09C0                <1> 	or	eax, eax
 25983 000090EF 741A                <1> 	jz	short loc_createfile_stc_retn_pop_eax
 25984 000090F1 8A3D[42C50000]      <1> 	mov	bh, [Current_Drv]
 25985 000090F7 B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
 25986                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
 25987                              <1> 	; (If EAX value is negative, Free Cluster Count will be decreased)
 25988 000090F9 E8AE060000          <1>   	call	calculate_fat_freespace
 25989                              <1>         ; ESI = Logical DOS Drive Description Table Address 
 25990                              <1>         ;jc	short loc_createfile_stc_retn_pop_eax_cf
 25991 000090FE 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
 25992 00009100 7409                <1> 	jz	short loc_createfile_stc_retn_pop_eax
 25993                              <1> 
 25994                              <1> loc_createfile_stc_retn_recalc_FAT_freespace:
 25995 00009102 66BB00FF            <1> 	mov	bx, 0FF00h ; bh = 0FFh -> 
 25996                              <1> 	; ESI = Logical DOS Drv DT Addr
 25997                              <1> 	; BL = 0 -> Recalculate 
 25998 00009106 E8A1060000          <1> 	call	calculate_fat_freespace
 25999                              <1> 
 26000                              <1> loc_createfile_stc_retn_pop_eax:
 26001 0000910B 58                  <1> 	pop	eax
 26002 0000910C 9D                  <1> 	popf
 26003 0000910D 7218                <1> 	jc	short loc_createfile_retn
 26004                              <1> 
 26005                              <1> loc_createfile_retn_fcluster:
 26006 0000910F A1[8ED10000]        <1> 	mov	eax, [createfile_FFCluster]
 26007 00009114 BB[8AD10000]        <1> 	mov	ebx, createfile_size
 26008                              <1> 	;movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 26009 00009119 0FB60D[9FD10000]    <1> 	movzx	ecx, byte [createfile_SecPerClust] ; 23/03/2016
 26010 00009120 0FB715[A0D10000]    <1> 	movzx	edx, word [createfile_DirIndex]
 26011                              <1> 
 26012                              <1> loc_createfile_retn:
 26013 00009127 C3                  <1> 	retn
 26014                              <1> 
 26015                              <1> create_fs_file:
 26016                              <1> 	; temporary (21/03/2016)
 26017 00009128 C3                  <1> 	retn
 26018                              <1> 
 26019                              <1> delete_fs_file:
 26020                              <1> 	; temporary (28/02/2016)
 26021 00009129 C3                  <1> 	retn
 26022                              <1> 
 26023                              <1> rename_fs_file_or_directory:
 26024 0000912A C3                  <1> 	retn
 26025                              <1> 
 26026                              <1> make_fs_directory:
 26027                              <1> 	; temporary (21/02/2016)
 26028 0000912B C3                  <1> 	retn
 26029                              <1> 
 26030                              <1> add_new_fs_section:
 26031                              <1> 	; temporary (11/03/2016)
 26032 0000912C C3                  <1> 	retn
 26033                              <1> 
 26034                              <1> delete_fs_directory_entry:
 26035                              <1> 	; temporary (11/03/2016)
 26036 0000912D C3                  <1> 	retn
 26037                              <1> 
 26038                              <1> csftdf2_read_fs_file_sectors:
 26039                              <1> 	; temporary (19/03/2016)
 26040 0000912E C3                  <1> 	retn
 26041                              <1> 
 26042                              <1> csftdf2_write_fs_file_sectors:
 26043                              <1> 	; temporary (19/03/2016)
 26044 0000912F C3                  <1> 	retn
 26045                                  %include 'trdosk5.s' ; 24/01/2016
 26046                              <1> ; ****************************************************************************
 26047                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - File System Procedures : trdosk5s
 26048                              <1> ; ----------------------------------------------------------------------------
 26049                              <1> ; Last Update: 24/03/2016
 26050                              <1> ; ----------------------------------------------------------------------------
 26051                              <1> ; Beginning: 24/01/2016
 26052                              <1> ; ----------------------------------------------------------------------------
 26053                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 26054                              <1> ; ----------------------------------------------------------------------------
 26055                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 26056                              <1> ; DRV_FAT.ASM (21/08/2011)
 26057                              <1> ; ****************************************************************************
 26058                              <1> ; DRV_FAT.ASM (c) 2005-2011 Erdogan TAN [ 07/07/2009 ] Last Update: 21/08/2011
 26059                              <1> 
 26060                              <1> get_next_cluster:
 26061                              <1> 	; 23/03/2016
 26062                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26063                              <1> 	; 05/07/2011
 26064                              <1> 	; 07/07/2009
 26065                              <1> 	; 2005
 26066                              <1> 	; INPUT ->
 26067                              <1> 	;	EAX = Cluster Number (32 bit)
 26068                              <1> 	;	ESI = Logical DOS Drive Parameters Table
 26069                              <1> 	; OUTPUT ->
 26070                              <1> 	;	cf = 0 -> No Error, EAX valid
 26071                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 26072                              <1> 	;	cf = 1 & EAX > 0 -> Error
 26073                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
 26074                              <1> 	;	EAX = Next Cluster Number (32 bit)
 26075                              <1> 	;
 26076                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26077                              <1> 
 26078 00009130 A3[55CD0000]        <1> 	mov	[FAT_CurrentCluster], eax
 26079                              <1> check_next_cluster_fat_type:
 26080 00009135 29D2                <1> 	sub	edx, edx ; 0
 26081 00009137 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 26082 0000913B 7250                <1> 	jb	short get_FAT12_next_cluster
 26083 0000913D 0F87AF000000        <1>         ja      get_FAT32_next_cluster
 26084                              <1> get_FAT16_next_cluster:
 26085 00009143 BB00030000          <1> 	mov	ebx, 300h ;768
 26086 00009148 F7F3                <1> 	div	ebx
 26087                              <1> 	; EAX = Count of 3 FAT sectors
 26088                              <1> 	; EDX = Cluster Offset (< 768)
 26089 0000914A 66D1E2              <1> 	shl	dx, 1 ; Multiply by 2
 26090 0000914D 89D3                <1> 	mov	ebx, edx ; Byte Offset
 26091 0000914F 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 26092 00009155 66BA0300            <1> 	mov	dx, 3
 26093 00009159 F7E2                <1> 	mul	edx  
 26094                              <1> 	; EAX = FAT Sector (<= 256)
 26095                              <1> 	; EDX = 0
 26096 0000915B 8A0E                <1> 	mov	cl, [esi+LD_Name]
 26097 0000915D 803D[59CD0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 26098 00009164 0F86CC000000        <1>         jna     load_FAT_sectors0
 26099 0000916A 3A0D[5ACD0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 26100 00009170 0F85C0000000        <1>         jne     load_FAT_sectors0
 26101 00009176 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26102 0000917C 0F85BA000000        <1>         jne     load_FAT_sectors1
 26103                              <1> 	;movzx	eax, word [ebx]
 26104 00009182 668B03              <1> 	mov	ax, [ebx]
 26105                              <1> 	; 01/02/2016
 26106                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
 26107                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
 26108                              <1> 	; (how can i do a such mistake!?)
 26109                              <1> 	;cmp	al, 0F7h
 26110                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 26111                              <1> 	;cmp	ah, 0FFh
 26112                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 26113 00009185 6683F8F7            <1> 	cmp	ax, 0FFF7h
 26114 00009189 725A                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 26115                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
 26116 0000918B EB56                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 26117                              <1> 
 26118                              <1> get_FAT12_next_cluster:
 26119 0000918D BB00040000          <1> 	mov	ebx, 400h ;1024
 26120 00009192 F7F3                <1> 	div	ebx
 26121                              <1> 	; EAX = Count of 3 FAT sectors
 26122                              <1> 	; EDX = Cluster Offset (< 1024)
 26123 00009194 6650                <1> 	push	ax
 26124 00009196 66B80300            <1> 	mov	ax, 3	
 26125 0000919A 66F7E2              <1> 	mul	dx    	; Multiply by 3
 26126 0000919D 66D1E8              <1> 	shr	ax, 1	; Divide by 2
 26127 000091A0 6689C3              <1>         mov	bx, ax 	; Byte Offset
 26128 000091A3 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 26129 000091A9 6658                <1> 	pop	ax
 26130 000091AB 66BA0300            <1> 	mov	dx, 3
 26131 000091AF F7E2                <1> 	mul	edx 
 26132                              <1> 	; EAX = FAT Sector (<= 12)
 26133                              <1> 	; EDX = 0
 26134 000091B1 8A0E                <1> 	mov	cl, [esi+LD_Name]
 26135 000091B3 803D[59CD0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 26136 000091BA 767A                <1> 	jna	short load_FAT_sectors0
 26137 000091BC 3A0D[5ACD0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 26138 000091C2 7572                <1> 	jne	short load_FAT_sectors0
 26139 000091C4 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26140 000091CA 7570                <1> 	jne	short load_FAT_sectors1
 26141 000091CC A1[55CD0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 26142 000091D1 66D1E8              <1> 	shr	ax, 1
 26143                              <1> 	;movzx	eax, word [ebx]
 26144 000091D4 668B03              <1> 	mov	ax, [ebx]
 26145 000091D7 7314                <1> 	jnc	short get_FAT12_nc_even
 26146 000091D9 66C1E804            <1> 	shr	ax, 4
 26147                              <1> loc_gnc_fat12_eoc_check:
 26148                              <1> 	;cmp	al, 0F7h
 26149                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 26150                              <1> 	;cmp	ah, 0Fh
 26151                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 26152 000091DD 663DF70F            <1> 	cmp	ax, 0FF7h
 26153 000091E1 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 26154                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
 26155                              <1> 
 26156                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
 26157 000091E3 31C0                <1> 	xor	eax, eax ; 0
 26158                              <1> loc_pass_gnc_FAT16_eoc_check:
 26159                              <1> loc_pass_gnc_FAT32_eoc_check:
 26160 000091E5 8B0D[55CD0000]      <1> 	mov	ecx, [FAT_CurrentCluster]
 26161 000091EB F5                  <1> 	cmc
 26162 000091EC C3                  <1> 	retn
 26163                              <1> 
 26164                              <1> get_FAT12_nc_even:
 26165 000091ED 80E40F              <1> 	and	ah, 0Fh
 26166 000091F0 EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
 26167                              <1> 
 26168                              <1> get_FAT32_next_cluster:
 26169 000091F2 BB80010000          <1> 	mov	ebx, 180h ;384
 26170 000091F7 F7F3                <1> 	div	ebx
 26171                              <1> 	; EAX = Count of 3 FAT sectors
 26172                              <1> 	; EDX = Cluster Offset (< 384)
 26173 000091F9 66C1E202            <1> 	shl	dx, 2	; Multiply by 4
 26174 000091FD 89D3                <1> 	mov	ebx, edx ; Byte Offset
 26175 000091FF 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 26176 00009205 66BA0300            <1> 	mov	dx, 3
 26177 00009209 F7E2                <1> 	mul	edx	
 26178                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
 26179                              <1> 	; 	for 32KB cluster size:
 26180                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512 	
 26181                              <1> 	; EDX = 0
 26182 0000920B 8A0E                <1> 	mov	cl, [esi+LD_Name]
 26183 0000920D 803D[59CD0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 26184 00009214 7620                <1> 	jna	short load_FAT_sectors0
 26185 00009216 3A0D[5ACD0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 26186 0000921C 7518                <1> 	jne	short load_FAT_sectors0
 26187 0000921E 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
 26188 00009224 7516                <1> 	jne	short load_FAT_sectors1
 26189 00009226 8B03                <1> 	mov	eax, [ebx]
 26190 00009228 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
 26191 0000922D 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
 26192 00009232 72B1                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
 26193                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
 26194 00009234 EBAD                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 26195                              <1> 
 26196                              <1> load_FAT_sectors0:
 26197 00009236 880D[5ACD0000]      <1> 	mov	[FAT_BuffDrvName], cl
 26198                              <1> load_FAT_sectors1:
 26199 0000923C A3[5DCD0000]        <1> 	mov	[FAT_BuffSector], eax
 26200 00009241 89C3                <1> 	mov	ebx, eax
 26201 00009243 034660              <1>         add     eax, [esi+LD_FATBegin]
 26202 00009246 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 26203 0000924A 7706                <1>         ja      short load_FAT_sectors3
 26204 0000924C 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 26205 00009250 EB03                <1> 	jmp	short load_FAT_sectors4
 26206                              <1> load_FAT_sectors3:
 26207 00009252 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
 26208                              <1> load_FAT_sectors4:
 26209 00009255 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
 26210 00009257 83F903              <1>         cmp     ecx, 3
 26211 0000925A 7605                <1>         jna     short load_FAT_sectors5
 26212 0000925C B903000000          <1> 	mov	ecx, 3
 26213                              <1> load_FAT_sectors5:
 26214 00009261 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 26215 00009266 E8511F0000          <1> 	call	disk_read
 26216 0000926B 730D                <1> 	jnc	short load_FAT_sectors_ok
 26217                              <1> 	; 23/03/2016
 26218 0000926D B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 26219 00009272 C605[59CD0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 26220 00009279 C3                  <1> 	retn
 26221                              <1> load_FAT_sectors_ok:
 26222 0000927A C605[59CD0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 26223 00009281 A1[55CD0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 26224 00009286 E9AAFEFFFF          <1>         jmp     check_next_cluster_fat_type
 26225                              <1> 
 26226                              <1> load_FAT_root_directory:
 26227                              <1> 	; 07/02/2016
 26228                              <1> 	; 02/02/2016
 26229                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26230                              <1> 	; 21/05/2011
 26231                              <1> 	; 22/08/2009
 26232                              <1> 	;
 26233                              <1> 	; INPUT ->
 26234                              <1> 	;	ESI = Logical DOS Drive Description Table
 26235                              <1> 	; OUTPUT ->
 26236                              <1> 	;	cf = 1 -> Root directory could not be loaded
 26237                              <1> 	;	    EAX > 0 -> Error number
 26238                              <1> 	;	cf = 0 -> EAX = 0
 26239                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 26240                              <1> 	;	EBX = Directory buffer address
 26241                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 26242                              <1> 	;
 26243                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26244                              <1> 
 26245                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
 26246                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
 26247                              <1> 
 26248 0000928B 8A1E                <1> 	mov	bl, [esi+LD_Name]
 26249 0000928D 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 26250                              <1> 
 26251                              <1> 	;mov	[DirBuff_DRV], bl
 26252                              <1> 	;mov	[DirBuff_FATType], bh
 26253 00009290 66891D[6ACD0000]    <1> 	mov	[DirBuff_DRV], bx
 26254                              <1> 	
 26255                              <1> 	;cmp	bh, 2
 26256                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
 26257                              <1> 
 26258 00009297 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
 26259                              <1> 
 26260                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
 26261                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
 26262                              <1> 
 26263 0000929B 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
 26264 000092A0 7414                <1> 	je	short lrd_mov_ecx_32
 26265 000092A2 89D0                <1> 	mov	eax, edx
 26266 000092A4 6683C00F            <1> 	add	ax, 15 ; round up 
 26267 000092A8 66C1E804            <1> 	shr	ax, 4  ; 16 entries per sector (512/32)
 26268 000092AC 89C1                <1> 	mov	ecx, eax ; Root directory size in sectors
 26269 000092AE 66C1E009            <1> 	shl	ax, 9 ; Root directory size in bytes
 26270 000092B2 664A                <1> 	dec	dx    ; Last entry number of root dir
 26271                              <1> 	; cx = Dir Buffer sector count             
 26272 000092B4 EB0B                <1> 	jmp	short lrd_check_dir_buffer
 26273                              <1> 
 26274                              <1> lrd_mov_ecx_32:
 26275 000092B6 B920000000          <1> 	mov	ecx, 32
 26276 000092BB 664A                <1> 	dec	dx ; 511
 26277 000092BD 66B80040            <1> 	mov	ax, 32*512 
 26278                              <1>  
 26279                              <1> lrd_check_dir_buffer:
 26280 000092C1 29DB                <1> 	sub	ebx, ebx ; 0
 26281 000092C3 881D[6CCD0000]      <1> 	mov	[DirBuff_ValidData], bl ; 0
 26282 000092C9 668915[6FCD0000]    <1> 	mov	[DirBuff_LastEntry], dx
 26283 000092D0 891D[71CD0000]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
 26284 000092D6 66A3[75CD0000]      <1> 	mov	[DirBuffer_Size], ax
 26285                              <1> 
 26286 000092DC 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
 26287                              <1> read_directory:
 26288 000092DF BB00000800          <1> 	mov	ebx, Directory_Buffer
 26289 000092E4 51                  <1> 	push	ecx ; Directory buffer sector count
 26290 000092E5 53                  <1> 	push	ebx
 26291 000092E6 E8D11E0000          <1> 	call	disk_read
 26292 000092EB 5B                  <1> 	pop	ebx
 26293 000092EC 720B                <1> 	jc	short load_DirBuff_error
 26294                              <1> 
 26295                              <1> validate_DirBuff_and_return:
 26296 000092EE 59                  <1> 	pop	ecx ; Number of loaded sectors
 26297 000092EF C605[6CCD0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 26298 000092F6 31C0                <1> 	xor	eax, eax ; 0 = no error
 26299 000092F8 C3                  <1> 	retn
 26300                              <1> 
 26301                              <1> load_DirBuff_error:
 26302 000092F9 89C8                <1> 	mov	eax, ecx ; remaining sectors
 26303 000092FB 59                  <1> 	pop	ecx ; sector count
 26304 000092FC 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
 26305 000092FE B815000000          <1> 	mov	eax, 15h ; DRV NOT READY OR READ ERROR !
 26306 00009303 F9                  <1> 	stc
 26307 00009304 C3                  <1>         retn
 26308                              <1> 
 26309                              <1> load_FAT32_root_directory:
 26310                              <1> 	; 02/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26311                              <1> 	;
 26312                              <1> 	; INPUT ->
 26313                              <1> 	;	ESI = Logical DOS Drive Description Table
 26314                              <1> 	; OUTPUT ->
 26315                              <1> 	;	cf = 1 -> Root directory could not be loaded
 26316                              <1> 	;	    EAX > 0 -> Error number
 26317                              <1> 	;	cf = 0 -> EAX = 0
 26318                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 26319                              <1> 	;	EBX = Directory buffer address
 26320                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 26321                              <1> 	;
 26322                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26323                              <1> 
 26324                              <1> 
 26325 00009305 8A1E                <1> 	mov	bl, [esi+LD_Name]
 26326 00009307 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 26327                              <1> 
 26328                              <1> 	;mov	[DirBuff_DRV], bl
 26329                              <1> 	;mov	[DirBuff_FATType], bh
 26330 0000930A 66891D[6ACD0000]    <1> 	mov	[DirBuff_DRV], bx
 26331                              <1> 
 26332                              <1> load_FAT32_root_dir0:
 26333 00009311 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 26334 00009314 EB0C                <1> 	jmp	short load_FAT_sub_dir0
 26335                              <1> 	
 26336                              <1> load_FAT_sub_directory:
 26337                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26338                              <1> 	; 05/07/2011
 26339                              <1> 	; 23/08/2009
 26340                              <1> 	;
 26341                              <1> 	; INPUT ->
 26342                              <1> 	;	ESI = Logical DOS Drive Description Table
 26343                              <1> 	;	EAX = Cluster Number
 26344                              <1> 	; OUTPUT ->
 26345                              <1> 	;	cf = 1 -> Sub directory could not be loaded
 26346                              <1> 	;	    EAX > 0 -> Error number
 26347                              <1> 	;	cf = 0 -> EAX = 0
 26348                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 26349                              <1> 	;	EBX = Directory buffer address
 26350                              <1> 	;
 26351                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 26352                              <1> 	;
 26353                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26354                              <1> 
 26355 00009316 8A1E                <1> 	mov	bl, [esi+LD_Name]
 26356 00009318 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 26357                              <1> 
 26358                              <1> 	;mov	[DirBuff_DRV], bl
 26359                              <1> 	;mov	[DirBuff_FATType], bh
 26360 0000931B 66891D[6ACD0000]    <1> 	mov	[DirBuff_DRV], bx
 26361                              <1> 
 26362                              <1> load_FAT_sub_dir0:
 26363 00009322 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 26364                              <1> 
 26365 00009326 882D[6CCD0000]      <1> 	mov	[DirBuff_ValidData], ch ; 0
 26366 0000932C A3[71CD0000]        <1> 	mov	[DirBuff_Cluster], eax
 26367                              <1> 
 26368 00009331 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
 26369 00009335 F7E1                <1> 	mul	ecx
 26370 00009337 C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
 26371 0000933A 6648                <1> 	dec	ax ; last entry
 26372 0000933C 66A3[6FCD0000]      <1> 	mov	[DirBuff_LastEntry], ax
 26373                              <1> 
 26374 00009342 A1[71CD0000]        <1> 	mov	eax, [DirBuff_Cluster]
 26375 00009347 83E802              <1> 	sub	eax, 2
 26376 0000934A F7E1                <1> 	mul	ecx
 26377 0000934C 034668              <1> 	add	eax, [esi+LD_DATABegin]
 26378                              <1> 	; ecx = sector per cluster (dir buffer size = 32 sectors)
 26379 0000934F EB8E                <1> 	jmp	short read_directory
 26380                              <1> 
 26381                              <1> ; DRV_FS.ASM
 26382                              <1> 
 26383                              <1> load_current_FS_directory:
 26384 00009351 C3                  <1> 	retn
 26385                              <1> load_FS_root_directory:
 26386 00009352 C3                  <1> 	retn
 26387                              <1> load_FS_sub_directory:
 26388 00009353 C3                  <1> 	retn
 26389                              <1> 
 26390                              <1> read_cluster:
 26391                              <1> 	; 18/03/2016
 26392                              <1> 	; 16/03/2016
 26393                              <1> 	; 17/02/2016
 26394                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26395                              <1> 	;
 26396                              <1> 	; INPUT ->
 26397                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
 26398                              <1> 	;	ESI = Logical DOS Drive Description Table address
 26399                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
 26400                              <1> 	;	Only for SINGLIX FS:
 26401                              <1> 	;	EDX = File Number (The 1st FDT address) 
 26402                              <1> 	; OUTPUT ->
 26403                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
 26404                              <1> 	;	    EAX > 0 -> Error number
 26405                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
 26406                              <1> 	;
 26407                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26408                              <1> 	
 26409 00009354 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
 26410                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 26411                              <1> 
 26412                              <1> read_file_sectors: ; 16/03/2016
 26413 00009358 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 26414 0000935C 761C                <1> 	jna	short read_fs_cluster
 26415                              <1> 
 26416                              <1> read_fat_file_sectors: ; 18/03/2016
 26417 0000935E 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
 26418 00009361 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
 26419 00009365 F7E2                <1> 	mul	edx
 26420 00009367 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
 26421                              <1> 
 26422                              <1> 	; EAX = Disk sector address
 26423                              <1> 	; ECX = Sector count
 26424                              <1> 	; EBX = Buffer address
 26425                              <1> 	; (EDX = 0)
 26426                              <1> 	; ESI = Logical DOS drive description table address	
 26427                              <1> 
 26428 0000936A E84D1E0000          <1> 	call	disk_read
 26429 0000936F 7306                <1> 	jnc	short rclust_retn
 26430                              <1> 	
 26431 00009371 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
 26432 00009376 C3                  <1> 	retn
 26433                              <1> 
 26434                              <1> rclust_retn:
 26435 00009377 29C0                <1> 	sub	eax, eax ; 0
 26436 00009379 C3                  <1> 	retn
 26437                              <1> 
 26438                              <1> read_fs_cluster:
 26439                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26440                              <1> 	; Singlix FS
 26441                              <1> 	
 26442                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
 26443                              <1> 	
 26444                              <1> 	; EDX = File number is the first File Descriptor Table address 
 26445                              <1> 	;	of the file. (Absolute address of the FDT).
 26446                              <1> 	
 26447                              <1> 	; eax = sector index (0 for the first sector)
 26448                              <1> 	; edx = FDT0 address
 26449                              <1> 		; 64 KB buffer = 128 sectors (limit) 
 26450 0000937A B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
 26451 0000937F E801000000          <1> 	call	read_fs_sectors
 26452 00009384 C3                  <1> 	retn
 26453                              <1> 
 26454                              <1> read_fs_sectors:
 26455                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26456 00009385 F9                  <1> 	stc
 26457 00009386 C3                  <1> 	retn
 26458                              <1> 
 26459                              <1> get_first_free_cluster:
 26460                              <1> 	; 02/03/2016
 26461                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26462                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
 26463                              <1> 	; 10/07/2010
 26464                              <1> 	; INPUT ->
 26465                              <1> 	;	ESI = Logical DOS Drive Description Table address
 26466                              <1> 	; OUTPUT ->
 26467                              <1> 	;	cf = 1 -> Error code in AL (EAX)
 26468                              <1> 	;	cf = 0 -> 
 26469                              <1> 	;	  EAX = Cluster number 
 26470                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
 26471                              <1> 	;	If the drive has FAT32 fs:
 26472                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
 26473                              <1> 
 26474 00009387 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
 26475 0000938A 40                  <1> 	inc	eax ; add eax, 1
 26476 0000938B A3[F4CF0000]        <1> 	mov	[gffc_last_free_cluster], eax
 26477                              <1> 
 26478 00009390 31DB                <1> 	xor	ebx, ebx ; 0 ; 02/03/2016
 26479                              <1> 
 26480 00009392 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 26481 00009396 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
 26482                              <1> 
 26483                              <1> loc_gffc_get_first_fat32_free_cluster:
 26484                              <1> 	; 02/03/2016
 26485 00009398 E834060000          <1> 	call	get_fat32_fsinfo_sector_parms
 26486 0000939D 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0 
 26487                              <1> 
 26488                              <1> loc_gffc_check_fsinfo_parms:
 26489                              <1> 	;;mov	ebx, DOSBootSectorBuff
 26490                              <1> 	;cmp	dword [ebx], 41615252h
 26491                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 26492                              <1> 	;cmp	dword [ebx+484], 61417272h
 26493                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 26494                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
 26495                              <1> 	;EAX = First free cluster 
 26496                              <1> 	;(from FAT32 FSInfo sector)
 26497 0000939F 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
 26498 000093A1 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
 26499 000093A4 7205                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
 26500                              <1> 
 26501                              <1> 	; Start from the 1st cluster of the FAT(32) file system
 26502                              <1> loc_gffc_get_first_fat_free_cluster0:
 26503 000093A6 B802000000          <1> 	mov	eax, 2
 26504                              <1> 	;xor	edx, edx
 26505                              <1> 
 26506                              <1> loc_gffc_get_first_fat_free_cluster1:
 26507 000093AB 53                  <1> 	push	ebx ; 02/03/2016 
 26508                              <1> 
 26509                              <1> loc_gffc_get_first_fat_free_cluster2:   
 26510 000093AC A3[F0CF0000]        <1> 	mov	[gffc_first_free_cluster], eax
 26511 000093B1 A3[ECCF0000]        <1> 	mov	[gffc_next_free_cluster], eax
 26512                              <1> 
 26513                              <1> 	; EBX = FAT32 FSINFO sector buffer address
 26514                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
 26515                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
 26516                              <1> 
 26517                              <1> loc_gffc_get_first_fat_free_cluster3:
 26518 000093B6 E875FDFFFF          <1> 	call	get_next_cluster
 26519 000093BB 7307                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster4
 26520 000093BD 09C0                <1> 	or	eax, eax
 26521 000093BF 740B                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
 26522 000093C1 5B                  <1> 	pop	ebx ; 02/03/2016
 26523 000093C2 F5                  <1> 	cmc 	; stc
 26524 000093C3 C3                  <1> 	retn
 26525                              <1> 
 26526                              <1> loc_gffc_get_first_fat_free_cluster4:
 26527 000093C4 21C0                <1> 	and	eax, eax ; next cluster value
 26528 000093C6 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
 26529 000093C8 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
 26530 000093CA EB22                <1> 	jmp	short loc_gffc_check_for_set
 26531                              <1>  
 26532                              <1> loc_gffc_first_free_fat_cluster_next:
 26533 000093CC A1[ECCF0000]        <1> 	mov	eax, [gffc_next_free_cluster]
 26534 000093D1 3B05[F4CF0000]      <1> 	cmp	eax, [gffc_last_free_cluster]
 26535 000093D7 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
 26536                              <1> pass_gffc_last_cluster_eax_check:
 26537 000093D9 40                  <1> 	inc	eax ; add eax, 1
 26538 000093DA A3[ECCF0000]        <1> 	mov	[gffc_next_free_cluster], eax
 26539 000093DF EBD5                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster3
 26540                              <1> 
 26541                              <1> retn_stc_from_get_first_free_cluster:
 26542 000093E1 A1[F0CF0000]        <1> 	mov	eax, [gffc_first_free_cluster]
 26543 000093E6 83F802              <1> 	cmp	eax, 2
 26544 000093E9 7709                <1> 	ja	short loc_gffc_check_previous_clusters
 26545 000093EB 29C0                <1> 	sub	eax, eax
 26546 000093ED 48                  <1> 	dec	eax ; FFFFFFFFh
 26547                              <1> 
 26548                              <1> loc_gffc_check_for_set:
 26549                              <1> 	; 02/03/2016
 26550 000093EE 5B                  <1> 	pop	ebx
 26551                              <1> 
 26552                              <1> 	; EBX = FAT32 FSINFO sector buffer address
 26553                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
 26554                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
 26555                              <1> 
 26556 000093EF 09DB                <1> 	or	ebx, ebx
 26557 000093F1 750E                <1> 	jnz	short loc_gffc_set_ffree_fat32_cluster
 26558                              <1> 
 26559                              <1> 	;cmp	byte [esi+LD_FATType], 3
 26560                              <1> 	;jnb	short loc_gffc_set_ffree_fat32_cluster
 26561                              <1> 
 26562                              <1> 	;xor	ebx, ebx ; 0
 26563                              <1> 
 26564                              <1> loc_gffc_retn:
 26565 000093F3 C3                  <1> 	retn
 26566                              <1> 
 26567                              <1> loc_gffc_check_previous_clusters:
 26568 000093F4 48                  <1> 	dec	eax ; sub eax, 1
 26569 000093F5 A3[F4CF0000]        <1> 	mov	[gffc_last_free_cluster], eax 
 26570 000093FA B802000000          <1> 	mov	eax, 2
 26571                              <1> 	;xor	edx, edx
 26572 000093FF EBAB                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
 26573                              <1> 
 26574                              <1> loc_gffc_set_ffree_fat32_cluster:
 26575                              <1> 	;call	set_first_free_cluster
 26576                              <1> 	;retn
 26577                              <1> 	;jmp	short set_first_free_cluster	
 26578                              <1> 
 26579                              <1> set_first_free_cluster:
 26580                              <1> 	; 23/03/2016
 26581                              <1> 	; 02/03/2016
 26582                              <1> 	; 29/02/2016
 26583                              <1> 	; 26/02/2016
 26584                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26585                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
 26586                              <1> 	; 11/07/2010
 26587                              <1> 	; INPUT -> 
 26588                              <1> 	;	ESI = Logical DOS Drive Description Table address
 26589                              <1> 	;	EAX = First free cluster
 26590                              <1> 	;	EBX = FSINFO sector buffer address
 26591                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
 26592                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
 26593                              <1> 	; OUTPUT->
 26594                              <1> 	;	ESI = Logical DOS Drive Description Table address
 26595                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
 26596                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
 26597                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
 26598                              <1> 	;	CF = 0 -> first free cluster is successfully updated 
 26599                              <1> 
 26600                              <1> 	;cmp	byte [esi+LD_FATType], 3
 26601                              <1> 	;jb	short loc_sffc_invalid_drive
 26602                              <1> 
 26603                              <1> 	; Save First Free Cluster value for 'update_cluster'
 26604 00009401 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster	
 26605                              <1> 
 26606                              <1> 	;or	ebx, ebx
 26607                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
 26608                              <1> 
 26609 00009404 813B52526141        <1> 	cmp     dword [ebx], 41615252h
 26610 0000940A 7540                <1> 	jne	short loc_sffc_read_fsinfo_sector
 26611 0000940C 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 26612 00009415 61                  <1>
 26613 00009416 7534                <1> 	jne	short loc_sffc_read_fsinfo_sector
 26614                              <1> 
 26615 00009418 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
 26616 0000941E 741F                <1> 	je	short loc_sffc_retn
 26617                              <1> 
 26618                              <1> loc_sffc_write_fsinfo_sector:
 26619                              <1> 	; EBX = FSINFO sector buffer
 26620                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
 26621 00009420 8983EC010000        <1> 	mov	[ebx+492], eax
 26622 00009426 A1[04D00000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC] 
 26623 0000942B B901000000          <1> 	mov	ecx, 1
 26624 00009430 53                  <1> 	push	ebx
 26625 00009431 E8771D0000          <1> 	call	disk_write
 26626 00009436 7208                <1> 	jc      short loc_sffc_read_fsinfo_sector_err1
 26627 00009438 5B                  <1> 	pop	ebx
 26628                              <1> 
 26629 00009439 8B83EC010000        <1> 	mov	eax, [ebx+492] ; First (Next) Free Cluster
 26630                              <1> 
 26631                              <1> loc_sffc_retn:
 26632 0000943F C3                  <1> 	retn
 26633                              <1> 
 26634                              <1> ;loc_sffc_invalid_drive:
 26635                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
 26636                              <1> ;	push	edx
 26637                              <1> 
 26638                              <1> loc_sffc_read_fsinfo_sector_err1:
 26639 00009440 BB00000000          <1> 	mov	ebx, 0
 26640                              <1> 	; 23/03/2016
 26641 00009445 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
 26642                              <1> 
 26643                              <1> loc_sffc_read_fsinfo_sector_err2:
 26644 0000944A 5A                  <1> 	pop	edx
 26645 0000944B C3                  <1> 	retn
 26646                              <1> 	
 26647                              <1> loc_sffc_read_fsinfo_sector:
 26648 0000944C 50                  <1> 	push	eax
 26649                              <1> 
 26650 0000944D E87F050000          <1> 	call	get_fat32_fsinfo_sector_parms
 26651 00009452 72F6                <1> 	jc	short loc_sffc_read_fsinfo_sector_err2
 26652                              <1> 
 26653 00009454 58                  <1> 	pop	eax
 26654                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
 26655                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
 26656                              <1> 	; (edx = old value)
 26657 00009455 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value) 
 26658 00009457 75C7                <1> 	jne	short loc_sffc_write_fsinfo_sector
 26659                              <1> 
 26660 00009459 C3                  <1> 	retn	
 26661                              <1> 
 26662                              <1> update_cluster:
 26663                              <1> 	; 02/03/2016
 26664                              <1> 	; 01/03/2016
 26665                              <1> 	; 29/02/2016
 26666                              <1> 	; 27/02/2016
 26667                              <1> 	; 26/02/2016
 26668                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26669                              <1> 	; 11/08/2011  
 26670                              <1> 	; 09/02/2005
 26671                              <1> 	; INPUT ->
 26672                              <1> 	;	EAX = Cluster Number
 26673                              <1> 	;	ECX = New Cluster Value
 26674                              <1> 	;	ESI = Logical Dos Drive Parameters Table
 26675                              <1> 	;
 26676                              <1> 	;	/// dword [FAT_ClusterCounter] ///
 26677                              <1> 	;
 26678                              <1> 	; OUTPUT ->
 26679                              <1> 	;	cf = 0 -> No Error, EAX is valid
 26680                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 26681                              <1> 	; 	cf = 1 & EAX > 0 -> Error
 26682                              <1> 	;		(ECX -> any value)
 26683                              <1> 	; 	EAX = Next Cluster
 26684                              <1> 	;	ECX = New Cluster Value
 26685                              <1> 	;
 26686                              <1> 	;	/// [FAT_ClusterCounter] is updated,
 26687                              <1> 	;	/// decreased when a free cluster is assigned,
 26688                              <1> 	;	/// increased if an assigned cluster is freed.	
 26689                              <1> 	;		
 26690                              <1> 	;
 26691                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
 26692                              <1> 	
 26693 0000945A A3[55CD0000]        <1> 	mov	[FAT_CurrentCluster], eax
 26694 0000945F 890D[F8CF0000]      <1> 	mov	[ClusterValue], ecx
 26695                              <1> 
 26696                              <1> loc_update_cluster_check_fat_buffer:
 26697 00009465 8A1E                <1> 	mov	bl, [esi+LD_Name]
 26698 00009467 381D[5ACD0000]      <1> 	cmp	[FAT_BuffDrvName], bl
 26699 0000946D 741A                <1> 	je	short loc_update_cluster_check_fat_type
 26700 0000946F 803D[59CD0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 26701 00009476 0F84C2000000        <1>         je      loc_uc_save_fat_buffer
 26702                              <1> 
 26703                              <1> loc_uc_reset_fat_buffer_validation:
 26704 0000947C C605[59CD0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 26705                              <1> 
 26706                              <1> loc_uc_check_fat_type_reset_drvname:
 26707 00009483 881D[5ACD0000]      <1> 	mov	[FAT_BuffDrvName], bl
 26708                              <1> 
 26709                              <1> loc_update_cluster_check_fat_type:
 26710 00009489 29D2                <1> 	sub	edx, edx ; 26/02/2016
 26711 0000948B 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 26712 0000948E 83F802              <1> 	cmp	eax, 2
 26713 00009491 0F82BE000000        <1>         jb      update_cluster_inv_data
 26714 00009497 80FB02              <1> 	cmp	bl, 2 
 26715 0000949A 0F877A010000        <1>         ja      update_fat32_cluster
 26716                              <1> 	;cmp	bl, 1
 26717                              <1> 	;jb	short update_cluster_inv_data
 26718 000094A0 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 26719 000094A3 41                  <1> 	inc	ecx  
 26720 000094A4 890D[65CD0000]      <1> 	mov	[LastCluster], ecx
 26721 000094AA 39C8                <1> 	cmp	eax, ecx ; dword [LastCluster]
 26722 000094AC 0F87A6000000        <1>         ja      return_uc_fat_stc
 26723                              <1> 	; TRDOS v1 has a FATal bug here ! 
 26724                              <1> 		; or bl, bl ; cmp bl, 0
 26725                              <1> 		; jz short update_fat12_cluster
 26726                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
 26727                              <1> 	; ('A:' disks of TRDOS v1 operating system project
 26728                              <1> 	; had 'singlix fs', so, I could not differ this mistake
 26729                              <1> 	; on a drive 'A:')
 26730 000094B2 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
 26731 000094B5 0F86A2000000        <1>         jna     update_fat12_cluster 
 26732                              <1> 
 26733                              <1> update_fat16_cluster:
 26734                              <1> pass_uc_fat16_errc:
 26735                              <1> 	;sub	edx, edx
 26736 000094BB BB00030000          <1> 	mov	ebx, 300h ;768
 26737 000094C0 F7F3                <1> 	div	ebx
 26738                              <1> 	; EAX = Count of 3 FAT sectors
 26739                              <1> 	; DX = Cluster offset in FAT buffer
 26740 000094C2 6689D3              <1> 	mov	bx, dx  
 26741 000094C5 66D1E3              <1> 	shl	bx, 1 ; Multiply by 2
 26742 000094C8 66BA0300            <1> 	mov	dx, 3
 26743 000094CC F7E2                <1> 	mul	edx  
 26744                              <1> 	; EAX = FAT Sector
 26745                              <1> 	; EDX = 0
 26746                              <1> 	; EBX = Byte offset in FAT buffer
 26747 000094CE 8A0D[59CD0000]      <1> 	mov	cl, [FAT_BuffValidData]
 26748 000094D4 80F902              <1> 	cmp	cl, 2
 26749 000094D7 750A                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
 26750                              <1> 
 26751                              <1> loc_uc_check_fat16_buff_sector_save:
 26752 000094D9 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26753 000094DF 755D                <1> 	jne	short loc_uc_save_fat_buffer
 26754 000094E1 EB15                <1> 	jmp	short loc_update_fat16_cell
 26755                              <1> 
 26756                              <1> loc_uc_check_fat16_buff_sector_load:
 26757 000094E3 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 26758 000094E6 0F85FB010000        <1>         jne     loc_uc_load_fat_sectors
 26759 000094EC 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26760 000094F2 0F85EF010000        <1>         jne     loc_uc_load_fat_sectors
 26761                              <1> 
 26762                              <1> loc_update_fat16_cell:
 26763                              <1> loc_update_fat16_buffer:
 26764 000094F8 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 26765                              <1> 	;movzx	eax, word [ebx]
 26766 000094FE 668B03              <1> 	mov	ax, [ebx]
 26767                              <1> 	; 01/03/2016
 26768 00009501 89C2                <1> 	mov	edx, eax ; old value of the cluster
 26769 00009503 A3[55CD0000]        <1> 	mov	[FAT_CurrentCluster], eax
 26770 00009508 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 26771 0000950E 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 26772                              <1> 
 26773 00009511 C605[59CD0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 26774                              <1> 	
 26775 00009518 6683F802            <1> 	cmp	ax, 2
 26776 0000951C 723A                <1> 	jb	short return_uc_fat_stc
 26777 0000951E 3B05[65CD0000]      <1> 	cmp	eax, [LastCluster]
 26778 00009524 7732                <1> 	ja	short return_uc_fat_stc
 26779                              <1> 
 26780                              <1> loc_fat_buffer_updated:
 26781                              <1> 	; 01/03/2016
 26782 00009526 F8                  <1> 	clc
 26783                              <1> loc_fat_buffer_stc_1:
 26784 00009527 9C                  <1> 	pushf
 26785 00009528 21C9                <1> 	and	ecx, ecx
 26786 0000952A 7506                <1> 	jnz	short loc_fat_buffer_updated_1
 26787                              <1> 
 26788                              <1> 	; 01/03/2016 
 26789                              <1> 	; new value of the cluster = 0 (free)
 26790                              <1> 	; increase free(d) cluster count
 26791 0000952C FF05[61CD0000]      <1> 	inc	dword [FAT_ClusterCounter]
 26792                              <1> 
 26793                              <1> loc_fat_buffer_updated_1: ; new value of the cluster > 0
 26794 00009532 09D2                <1> 	or	edx, edx ; 02/03/2016
 26795 00009534 7506                <1> 	jnz	short loc_fat_buffer_updated_2
 26796                              <1> 	; old value of the cluster = 0 (it was free cluster)
 26797                              <1> 	; decrease free(d) cluster count
 26798 00009536 FF0D[61CD0000]      <1> 	dec	dword [FAT_ClusterCounter] ; it may be negative number
 26799                              <1> 
 26800                              <1> loc_fat_buffer_updated_2:
 26801 0000953C 9D                  <1> 	popf
 26802 0000953D C3                  <1> 	retn
 26803                              <1> 
 26804                              <1> loc_uc_save_fat_buffer:
 26805                              <1> 	; byte [FAT_BuffValidData] = 2 
 26806 0000953E E8D4010000          <1> 	call	save_fat_buffer
 26807 00009543 0F8297010000        <1>         jc      loc_fat_sectors_rw_error2
 26808                              <1> 	;mov	byte [FAT_BuffValidData], 1
 26809 00009549 A1[55CD0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 26810                              <1> 	;mov	ecx, [ClusterValue]
 26811                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
 26812 0000954E 8A1E                <1> 	mov	bl, [esi+LD_Name] ; 01/03/2016
 26813 00009550 E927FFFFFF          <1>         jmp     loc_uc_reset_fat_buffer_validation
 26814                              <1> 
 26815                              <1> update_cluster_inv_data:
 26816                              <1> 	;mov	eax, 0Dh
 26817 00009555 B00D                <1> 	mov	al, 0Dh  ; Invalid Data
 26818 00009557 C3                  <1> 	retn 
 26819                              <1> 
 26820                              <1> return_uc_fat_stc:
 26821                              <1> 	; 01/03/2016
 26822 00009558 31C0                <1> 	xor	eax, eax
 26823 0000955A F9                  <1> 	stc
 26824 0000955B EBCA                <1> 	jmp	short loc_fat_buffer_stc_1
 26825                              <1> 
 26826                              <1> update_fat12_cluster:
 26827                              <1> pass_uc_fat12_errc:
 26828                              <1> 	;sub	edx, edx
 26829 0000955D BB00040000          <1> 	mov	ebx, 400h ;1024
 26830 00009562 F7F3                <1> 	div	ebx
 26831                              <1> 	; EAX = Count of 3 FAT sectors
 26832                              <1> 	; DX = Cluster offset in FAT buffer
 26833 00009564 66B90300            <1> 	mov	cx, 3
 26834 00009568 6689C3              <1> 	mov	bx, ax
 26835 0000956B 6689C8              <1> 	mov	ax, cx ; 3
 26836 0000956E 66F7E2              <1> 	mul	dx     ; Multiply by 3
 26837 00009571 66D1E8              <1> 	shr	ax, 1  ; Divide by 2
 26838 00009574 6693                <1> 	xchg	bx, ax
 26839                              <1> 	; EAX = Count of 3 FAT sectors
 26840                              <1> 	; EBX = Byte Offset in FAT buffer   
 26841 00009576 66F7E1              <1> 	mul	cx  ; 3 * AX
 26842                              <1> 	; EAX = FAT Beginning Sector
 26843                              <1> 	; EDX = 0
 26844 00009579 8A0D[59CD0000]      <1> 	mov	cl, [FAT_BuffValidData]
 26845                              <1> 	; TRDOS v1 has a FATal bug here ! 
 26846                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
 26847                              <1> 	;  while 'jne' is existing !)
 26848 0000957F 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
 26849 00009582 750A                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
 26850                              <1> 
 26851                              <1> loc_uc_check_fat12_buff_sector_save:
 26852 00009584 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26853 0000958A 75B2                <1>         jne     short loc_uc_save_fat_buffer
 26854 0000958C EB15                <1> 	jmp	short loc_update_fat12_cell
 26855                              <1> 
 26856                              <1> loc_uc_check_fat12_buff_sector_load:
 26857 0000958E 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
 26858 00009591 0F8550010000        <1>         jne     loc_uc_load_fat_sectors
 26859 00009597 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26860 0000959D 0F8544010000        <1>         jne     loc_uc_load_fat_sectors
 26861                              <1> 
 26862                              <1> loc_update_fat12_cell:
 26863 000095A3 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 26864 000095A9 668B0D[55CD0000]    <1> 	mov	cx, [FAT_CurrentCluster]
 26865 000095B0 66D1E9              <1> 	shr	cx, 1
 26866 000095B3 668B03              <1> 	mov	ax, [ebx]
 26867 000095B6 6689C2              <1> 	mov	dx, ax
 26868 000095B9 7344                <1> 	jnc	short uc_fat12_nc_even
 26869                              <1> 
 26870 000095BB 6683E00F            <1> 	and	ax, 0Fh
 26871 000095BF 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 26872 000095C5 66C1E104            <1> 	shl	cx, 4
 26873 000095C9 6609C1              <1> 	or	cx, ax
 26874 000095CC 6689D0              <1> 	mov	ax, dx
 26875 000095CF 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
 26876 000095D2 66C1E804            <1> 	shr	ax, 4 ; al(bit4..7)+ah(bit0..7)
 26877                              <1> 
 26878                              <1> update_fat12_buffer:
 26879 000095D6 A3[55CD0000]        <1> 	mov	[FAT_CurrentCluster], eax
 26880 000095DB 89C2                <1> 	mov	edx, eax ; 01/03/2016
 26881 000095DD C605[59CD0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 26882 000095E4 6683F802            <1> 	cmp	ax, 2
 26883 000095E8 0F826AFFFFFF        <1>         jb      return_uc_fat_stc
 26884 000095EE 3B05[65CD0000]      <1> 	cmp	eax, [LastCluster]
 26885 000095F4 0F875EFFFFFF        <1>         ja      return_uc_fat_stc
 26886 000095FA E927FFFFFF          <1>         jmp     loc_fat_buffer_updated
 26887                              <1> 
 26888                              <1> uc_fat12_nc_even:
 26889 000095FF 662500F0            <1> 	and	ax, 0F000h
 26890 00009603 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 26891 00009609 80E50F              <1> 	and	ch, 0Fh
 26892 0000960C 6609C1              <1> 	or	cx, ax
 26893 0000960F 6689D0              <1> 	mov	ax, dx
 26894 00009612 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 26895 00009615 80E40F              <1> 	and	ah, 0Fh ; al(bit0..7)+ah(bit0..3)
 26896 00009618 EBBC                <1> 	jmp	short update_fat12_buffer
 26897                              <1> 
 26898                              <1> update_fat32_cluster:
 26899 0000961A 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 26900 0000961D 41                  <1> 	inc	ecx
 26901 0000961E 890D[65CD0000]      <1> 	mov	[LastCluster], ecx
 26902                              <1> 
 26903 00009624 39C8                <1> 	cmp	eax, ecx
 26904 00009626 0F872CFFFFFF        <1>         ja      return_uc_fat_stc
 26905                              <1> 
 26906                              <1> pass_uc_fat32_errc:
 26907                              <1> 	;sub	edx, edx
 26908 0000962C BB80010000          <1> 	mov	ebx, 180h ;384
 26909 00009631 F7F3                <1> 	div	ebx
 26910                              <1> 	; EAX = Count of 3 FAT sectors
 26911                              <1> 	; DX = Cluster offset in FAT buffer
 26912 00009633 89D3                <1> 	mov	ebx, edx
 26913 00009635 C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
 26914 00009638 BA03000000          <1> 	mov	edx, 3	
 26915 0000963D F7E2                <1> 	mul	edx
 26916                              <1> 	; EBX = Cluster Offset in FAT buffer
 26917                              <1> 	; EAX = FAT Sector
 26918                              <1> 	; EDX = 0
 26919 0000963F 8A0D[59CD0000]      <1> 	mov	cl, [FAT_BuffValidData]
 26920 00009645 80F902              <1> 	cmp	cl, 2
 26921 00009648 750E                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
 26922                              <1> 
 26923                              <1> loc_uc_check_fat32_buff_sector_save:
 26924 0000964A 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26925 00009650 0F85E8FEFFFF        <1>         jne     loc_uc_save_fat_buffer
 26926 00009656 EB11                <1> 	jmp	short loc_update_fat32_cell
 26927                              <1> 
 26928                              <1> loc_uc_check_fat32_buff_sector_load:
 26929 00009658 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 26930 0000965B 0F8586000000        <1>         jne     loc_uc_load_fat_sectors
 26931 00009661 3B05[5DCD0000]      <1> 	cmp	eax, [FAT_BuffSector]
 26932 00009667 757E                <1>         jne     loc_uc_load_fat_sectors
 26933                              <1> 
 26934                              <1> loc_update_fat32_cell:
 26935                              <1> loc_update_fat32_buffer:
 26936 00009669 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 26937 0000966F 8B03                <1> 	mov	eax, [ebx]
 26938 00009671 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
 26939                              <1> 	
 26940 00009676 8B15[55CD0000]      <1> 	mov	edx, [FAT_CurrentCluster] ; 01/03/2016
 26941                              <1> 
 26942 0000967C A3[55CD0000]        <1> 	mov 	[FAT_CurrentCluster], eax
 26943 00009681 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue]
 26944 00009687 890B                <1> 	mov	[ebx], ecx ; 29/02/2016 
 26945                              <1> 
 26946 00009689 C605[59CD0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 26947                              <1> 
 26948                              <1> 	; 01/03/2016
 26949 00009690 21C0                <1> 	and	eax, eax ; was it free cluster ?
 26950 00009692 7514                <1> 	jnz	short loc_upd_fat32_c0
 26951                              <1> 
 26952                              <1> 	;or	ecx, ecx ; it will be left free ?!
 26953                              <1> 	;jz	short loc_upd_fat32_c3
 26954                              <1> 
 26955 00009694 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
 26956 00009697 7520                <1> 	jne	short loc_upd_fat32_c3
 26957                              <1> 
 26958 00009699 3B15[65CD0000]      <1> 	cmp	edx, [LastCluster]
 26959 0000969F 7207                <1> 	jb	short loc_upd_fat32_c0
 26960                              <1> 
 26961 000096A1 BA02000000          <1> 	mov	edx, 2 ; rewind !
 26962 000096A6 EB0E                <1> 	jmp	short loc_upd_fat32_c2
 26963                              <1> 
 26964                              <1> loc_upd_fat32_c0:
 26965 000096A8 FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set it to next cluster		
 26966 000096AB EB0C                <1> 	jmp	short loc_upd_fat32_c3
 26967                              <1> 
 26968                              <1> loc_upd_fat32_c1:
 26969 000096AD 09C9                <1> 	or	ecx, ecx ; will it be free cluster ?
 26970 000096AF 7508                <1> 	jnz	short loc_upd_fat32_c3
 26971                              <1> 
 26972 000096B1 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
 26973 000096B4 7303                <1> 	jnb	short loc_upd_fat32_c3
 26974                              <1> 
 26975                              <1> loc_upd_fat32_c2:	
 26976 000096B6 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx			
 26977                              <1> 
 26978                              <1> loc_upd_fat32_c3:
 26979 000096B9 89C2                <1> 	mov	edx, eax
 26980                              <1> 
 26981                              <1> loc_upd_fat32_c4:
 26982 000096BB 83F802              <1> 	cmp	eax, 2
 26983 000096BE 0F8294FEFFFF        <1>         jb      return_uc_fat_stc
 26984                              <1> 
 26985                              <1> pass_uc_fat32_c_zero_check_2:
 26986 000096C4 3B05[65CD0000]      <1> 	cmp	eax, [LastCluster]
 26987 000096CA 0F8788FEFFFF        <1>         ja      return_uc_fat_stc
 26988                              <1> 	
 26989 000096D0 E951FEFFFF          <1> 	jmp     loc_fat_buffer_updated
 26990                              <1> 
 26991                              <1> loc_fat_sectors_rw_error1:
 26992                              <1> 	;mov	byte [FAT_BuffValidData], 0
 26993                              <1> 	; 23/03/2016
 26994 000096D5 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 26995 000096DA 8825[59CD0000]      <1> 	mov	[FAT_BuffValidData], ah ; 0
 26996                              <1> 
 26997                              <1> loc_fat_sectors_rw_error2:
 26998                              <1> 	;mov	eax, error code
 26999                              <1> 	;mov	edx, 0
 27000 000096E0 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue]
 27001 000096E6 C3                  <1> 	retn
 27002                              <1> 
 27003                              <1> loc_uc_load_fat_sectors:
 27004 000096E7 A3[5DCD0000]        <1> 	mov	[FAT_BuffSector], eax
 27005                              <1> 
 27006                              <1> load_uc_fat_sectors_zero:
 27007 000096EC 034660              <1> 	add	eax, [esi+LD_FATBegin]
 27008 000096EF BB001C0900          <1> 	mov	ebx, FAT_Buffer
 27009 000096F4 B903000000          <1> 	mov	ecx, 3
 27010 000096F9 E8BE1A0000          <1> 	call	disk_read
 27011 000096FE 72D5                <1> 	jc	short loc_fat_sectors_rw_error1
 27012                              <1> 
 27013 00009700 C605[59CD0000]01    <1>         mov     byte [FAT_BuffValidData], 1
 27014 00009707 A1[55CD0000]        <1> 	mov 	eax, [FAT_CurrentCluster]
 27015 0000970C 8B0D[F8CF0000]      <1> 	mov	ecx, [ClusterValue]
 27016 00009712 E972FDFFFF          <1>         jmp     loc_update_cluster_check_fat_type
 27017                              <1> 
 27018                              <1> save_fat_buffer:
 27019                              <1> 	; 01/03/2016
 27020                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27021                              <1> 	; 11/08/2011
 27022                              <1> 	; 09/02/2005 
 27023                              <1> 	; INPUT ->
 27024                              <1> 	;	None
 27025                              <1> 	; OUTPUT ->
 27026                              <1> 	;	cf = 0 -> OK.
 27027                              <1> 	;	cf = 1 -> error code in AL (EAX)
 27028                              <1> 	;
 27029                              <1> 	;	EBX = FAT_Buffer address
 27030                              <1> 	;
 27031                              <1> 	; (EAX, EDX, ECX will be modified)
 27032                              <1> 
 27033                              <1> 	;cmp	byte [FAT_BuffValidData], 2 
 27034                              <1> 	;je	short loc_save_fat_buff
 27035                              <1> 
 27036                              <1> ;loc_save_fat_buffer_retn:
 27037                              <1> ;	xor	eax, eax
 27038                              <1> ;	retn
 27039                              <1> 
 27040                              <1> loc_save_fat_buff:
 27041 00009717 31D2                <1> 	xor	edx, edx
 27042 00009719 8A35[5ACD0000]      <1> 	mov	dh, [FAT_BuffDrvName]
 27043 0000971F 80FE41              <1> 	cmp	dh, 'A'
 27044 00009722 722E                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
 27045 00009724 80EE41              <1> 	sub	dh, 'A'
 27046 00009727 56                  <1> 	push	esi ; *
 27047 00009728 BE00010900          <1>         mov     esi, Logical_DOSDisks
 27048 0000972D 01D6                <1> 	add	esi, edx
 27049                              <1> 	
 27050 0000972F 8A5603              <1> 	mov	dl, [esi+LD_FATType]
 27051 00009732 20D2                <1> 	and	dl, dl
 27052 00009734 741B                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn 
 27053                              <1> 
 27054 00009736 A1[5DCD0000]        <1> 	mov	eax, [FAT_BuffSector]
 27055 0000973B 80FA02              <1> 	cmp	dl, 2
 27056 0000973E 770A                <1> 	ja	short loc_save_fat32_buff
 27057                              <1> 
 27058                              <1> loc_save_fat_12_16_buff:
 27059                              <1> 	; 01/03/2016
 27060                              <1> 	; TRDOS v1 has a FATal bug here!
 27061                              <1> 	; Correct code: mov dx, word ptr [FAT_BuffSector]+2
 27062                              <1> 	; (DX:AX in TRDOS v1 -> EAX in TRDOS v2)
 27063                              <1> 	;
 27064 00009740 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs] 
 27065 00009744 29C1                <1> 	sub	ecx, eax
 27066                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
 27067                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
 27068 00009746 7609                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
 27069 00009748 EB15                <1> 	jmp	short loc_save_fat_buffer_check_rs3
 27070                              <1> 
 27071                              <1> loc_save_fat32_buff:
 27072 0000974A 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
 27073 0000974D 29C1                <1> 	sub	ecx, eax
 27074 0000974F 770E                <1> 	ja	short loc_save_fat_buffer_check_rs3
 27075                              <1> 
 27076                              <1> loc_save_fat_buffer_inv_data_pop_retn:
 27077 00009751 5E                  <1> 	pop	esi ; *
 27078                              <1> loc_save_fat_buffer_inv_data_retn:
 27079 00009752 B80D000000          <1> 	mov	eax, 0Dh ; Invalid DATA
 27080 00009757 C3                  <1> 	retn
 27081                              <1> 
 27082                              <1> loc_save_fat_buff_remain_sectors_3:
 27083 00009758 B903000000          <1> 	mov	ecx, 3
 27084 0000975D EB05                <1> 	jmp	short loc_save_fat_buff_continue
 27085                              <1> 
 27086                              <1> loc_save_fat_buffer_check_rs3:
 27087 0000975F 83F903              <1> 	cmp	ecx, 3
 27088 00009762 77F4                <1> 	ja	short loc_save_fat_buff_remain_sectors_3
 27089                              <1> 
 27090                              <1> loc_save_fat_buff_continue:
 27091 00009764 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 27092 00009769 034660              <1> 	add	eax, [esi+LD_FATBegin]
 27093 0000976C 51                  <1> 	push	ecx
 27094 0000976D E83B1A0000          <1> 	call	disk_write
 27095 00009772 59                  <1> 	pop	ecx
 27096 00009773 722B                <1> 	jc	short loc_save_FAT_buff_write_err
 27097                              <1> 	
 27098 00009775 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 27099 00009779 7605                <1> 	jna	short loc_calc_2nd_fat12_16_addr
 27100                              <1> 
 27101                              <1> loc_calc_2nd_fat32_addr:
 27102 0000977B 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
 27103 0000977E EB04                <1> 	jmp	short loc_calc_2nd_fat_addr
 27104                              <1> 
 27105                              <1> loc_calc_2nd_fat12_16_addr:
 27106 00009780 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
 27107                              <1> 
 27108                              <1> loc_calc_2nd_fat_addr:
 27109 00009784 034660              <1> 	add	eax, [esi+LD_FATBegin]
 27110 00009787 0305[5DCD0000]      <1> 	add	eax, [FAT_BuffSector]
 27111 0000978D BB001C0900          <1> 	mov	ebx, FAT_Buffer
 27112                              <1> 	; ecx = 1 to 3
 27113 00009792 E8161A0000          <1> 	call	disk_write
 27114 00009797 7207                <1> 	jc	short loc_save_FAT_buff_write_err
 27115                              <1>  	; Valid  buffer (1 = valid but do not save)
 27116 00009799 C605[59CD0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 27117                              <1> 
 27118                              <1> loc_save_FAT_buff_write_err:
 27119 000097A0 5E                  <1> 	pop	esi ; *
 27120 000097A1 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 27121                              <1> 	; 23/03/2016
 27122 000097A6 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
 27123 000097AB C3                  <1> 	retn
 27124                              <1> 
 27125                              <1> calculate_fat_freespace:
 27126                              <1> 	; 23/03/2016
 27127                              <1> 	; 02/03/2016
 27128                              <1> 	; 01/03/2016
 27129                              <1> 	; 29/02/2016
 27130                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27131                              <1> 	; 30/04/2011
 27132                              <1> 	; 03/04/2010
 27133                              <1> 	; 2005
 27134                              <1> 	; INPUT ->
 27135                              <1> 	;	EAX = Cluster count to be added or subtracted
 27136                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
 27137                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
 27138                              <1> 	; 	BL: 
 27139                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
 27140                              <1> 	; OUTPUT ->
 27141                              <1> 	;	EAX = Free Space in sectors
 27142                              <1> 	;	ESI = Logical Dos Drive Description Table address
 27143                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
 27144                              <1> 	;	BL = Type of operation (same with input value of BL)
 27145                              <1> 	;	ECX = 0 -> valid
 27146                              <1> 	;	ECX > 0 -> error or invalid
 27147                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
 27148                              <1> 	;			          sign due to r/w error   
 27149                              <1> 
 27150 000097AC 66891D[FECF0000]    <1> 	mov	[CFS_OPType], bx
 27151 000097B3 A3[00D00000]        <1> 	mov	[CFS_CC], eax
 27152                              <1> 	
 27153 000097B8 80FFFF              <1> 	cmp	bh, 0FFh
 27154 000097BB 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
 27155                              <1> 
 27156                              <1> loc_calculate_freespace_get_drive_dt_offset:     
 27157 000097BD 31C0                <1> 	xor	eax, eax
 27158 000097BF 88FC                <1>         mov     ah, bh
 27159 000097C1 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 27160 000097C6 01C6                <1>         add     esi, eax
 27161                              <1> 
 27162                              <1> pass_calculate_freespace_get_drive_dt_offset:
 27163 000097C8 08DB                <1> 	or	bl, bl
 27164 000097CA 7435                <1> 	jz	short loc_reset_fcc
 27165                              <1> 	
 27166                              <1> loc_get_free_sectors:
 27167 000097CC 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 27168                              <1> 
 27169                              <1> 	;xor	ecx, ecx
 27170                              <1> 	;dec	ecx ; 0FFFFFFFFh
 27171                              <1> 	;cmp	eax, ecx ; 29/02/2016
 27172                              <1> 	;je	short loc_get_free_sectors_retn ; recalculation is needed!
 27173                              <1> 	
 27174                              <1> 	; 23/03/2016
 27175 000097CF 8B4E70              <1> 	mov	ecx, [esi+LD_TotalSectors]
 27176 000097D2 39C1                <1> 	cmp	ecx, eax ; Total sectors must be greater than Free sectors !
 27177 000097D4 7707                <1> 	ja	short loc_get_free_sectors_check_optype
 27178                              <1> 	
 27179 000097D6 31C0                <1> 	xor	eax, eax
 27180 000097D8 48                  <1> 	dec	eax ; 0FFFFFFFFh  ; recalculation is needed!
 27181 000097D9 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; reset (for recalculation)
 27182                              <1> 		
 27183                              <1> loc_get_free_sectors_retn:
 27184 000097DC C3                  <1> 	retn
 27185                              <1> 	
 27186                              <1> loc_get_free_sectors_check_optype:
 27187 000097DD 80FB03              <1> 	cmp	bl, 3
 27188 000097E0 7203                <1> 	jb	short loc_set_fcc
 27189                              <1> 
 27190 000097E2 29C9                <1> 	sub	ecx, ecx ; 0
 27191                              <1> 
 27192 000097E4 C3                  <1> 	retn	
 27193                              <1> 
 27194                              <1> loc_set_fcc:
 27195 000097E5 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 27196 000097E9 0F87DF000000        <1>         ja      loc_update_FAT32_fs_info_fcc
 27197                              <1> 
 27198                              <1> 	;mov	eax, [esi+LD_FreeSectors]
 27199 000097EF 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 27200 000097F3 29D2                <1> 	sub	edx, edx
 27201 000097F5 F7F1                <1> 	div	ecx
 27202                              <1> 	;or	dx, dx 
 27203                              <1> 	;	; DX -> Remain sectors < SecPerClust
 27204                              <1> 	;	; DX > 0 -> invalid free sector count
 27205                              <1> 	;jnz	short loc_reset_fcc 
 27206                              <1> 
 27207                              <1> ;pass_set_fcc_div32:
 27208 000097F7 A3[77CD0000]        <1> 	mov	[FreeClusterCount], eax
 27209 000097FC E988000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
 27210                              <1> 
 27211                              <1> loc_reset_fcc:
 27212 00009801 31C0                <1> 	xor	eax, eax
 27213 00009803 A3[77CD0000]        <1> 	mov	[FreeClusterCount], eax ; 0
 27214 00009808 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
 27215 0000980B 42                  <1> 	inc	edx
 27216 0000980C 8915[65CD0000]      <1> 	mov	[LastCluster], edx
 27217                              <1> 
 27218 00009812 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 27219 00009816 7647                <1> 	jna	short loc_count_free_fat_clusters_0  
 27220                              <1> 
 27221 00009818 48                  <1> 	dec	eax ; FFFFFFFFh
 27222 00009819 A3[08D00000]        <1> 	mov	[CFS_FAT32FC], eax
 27223                              <1> 
 27224                              <1> 	; 29/02/2016
 27225 0000981E 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
 27226 00009821 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
 27227                              <1> 	
 27228 00009824 B802000000          <1> 	mov 	eax, 2
 27229                              <1> 
 27230                              <1> loc_count_fc_next_cluster_0:
 27231 00009829 50                  <1> 	push	eax
 27232 0000982A E801F9FFFF          <1> 	call	get_next_cluster
 27233 0000982F 7310                <1> 	jnc	short loc_check_fat32_ff_cluster
 27234 00009831 09C0                <1> 	or	eax, eax
 27235 00009833 741E                <1> 	jz	short pass_inc_cfs_fcc_0
 27236                              <1> 
 27237                              <1> loc_put_fcc_unknown_sign:
 27238 00009835 58                  <1> 	pop	eax
 27239                              <1> 	; "Free count is Unknown" sign
 27240                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
 27241                              <1> 
 27242                              <1> 	; 29/02/2016
 27243                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
 27244                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
 27245 00009836 8B15[08D00000]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
 27246                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
 27247 0000983C 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
 27248                              <1> 	
 27249 0000983F EB7D                <1>         jmp     loc_put_fcc_invalid_sign
 27250                              <1> 
 27251                              <1> loc_check_fat32_ff_cluster:
 27252 00009841 09C0                <1> 	or	eax, eax
 27253 00009843 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
 27254 00009845 58                  <1> 	pop	eax
 27255 00009846 A3[08D00000]        <1> 	mov	[CFS_FAT32FC], eax
 27256                              <1> 	;mov	dword [FreeClusterCount], 1
 27257 0000984B FF05[77CD0000]      <1> 	inc	dword [FreeClusterCount]
 27258 00009851 EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
 27259                              <1> 
 27260                              <1> pass_inc_cfs_fcc_0:
 27261 00009853 58                  <1> 	pop	eax
 27262                              <1> 
 27263                              <1> pass_inc_cfs_fcc_0c:
 27264 00009854 40                  <1> 	inc	eax ; add eax, 1
 27265 00009855 3B05[65CD0000]      <1> 	cmp	eax, [LastCluster]
 27266 0000985B 76CC                <1> 	jna 	short loc_count_fc_next_cluster_0
 27267 0000985D EB6F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
 27268                              <1> 
 27269                              <1> loc_count_free_fat_clusters_0:
 27270                              <1> 	;mov	eax, 2
 27271 0000985F B002                <1> 	mov	al, 2
 27272                              <1> 
 27273                              <1> loc_count_fc_next_cluster:
 27274 00009861 50                  <1> 	push	eax
 27275 00009862 E8C9F8FFFF          <1> 	call	get_next_cluster
 27276 00009867 720C                <1> 	jc	short loc_count_fcc_stc
 27277                              <1> 
 27278                              <1> loc_count_free_clusters_1:
 27279 00009869 21C0                <1> 	and	eax, eax
 27280 0000986B 750C                <1> 	jnz	short pass_inc_cfs_fcc
 27281                              <1> 
 27282 0000986D FF05[77CD0000]      <1> 	inc	dword [FreeClusterCount]
 27283 00009873 EB04                <1> 	jmp	short pass_inc_cfs_fcc
 27284                              <1> 
 27285                              <1> loc_count_fcc_stc:
 27286 00009875 09C0                <1> 	or	eax, eax
 27287 00009877 75BC                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
 27288                              <1> 
 27289                              <1> pass_inc_cfs_fcc:
 27290 00009879 58                  <1> 	pop	eax
 27291                              <1> 
 27292                              <1> pass_inc_cfs_fcc_1:
 27293 0000987A 40                  <1> 	inc	eax ; add eax, 1
 27294 0000987B 3B05[65CD0000]      <1> 	cmp	eax, [LastCluster]
 27295 00009881 76DE                <1> 	jna	short loc_count_fc_next_cluster
 27296                              <1> 
 27297                              <1> loc_set_free_sectors:
 27298 00009883 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 27299 00009887 7745                <1> 	ja	short loc_update_FAT32_fs_info_fcc
 27300                              <1> 
 27301                              <1> loc_set_free_sectors_FAT12_FAT16:
 27302 00009889 803D[FECF0000]00    <1> 	cmp	byte [CFS_OPType], 0
 27303 00009890 761C                <1> 	jna	short pass_FAT_add_sub_fcc
 27304 00009892 A1[00D00000]        <1> 	mov	eax, [CFS_CC]
 27305 00009897 803D[FECF0000]01    <1> 	cmp	byte [CFS_OPType], 1
 27306 0000989E 7708                <1> 	ja	short pass_FAT_add_fcc
 27307 000098A0 0105[77CD0000]      <1> 	add 	[FreeClusterCount], eax
 27308 000098A6 EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
 27309                              <1> 
 27310                              <1> pass_FAT_add_fcc:
 27311 000098A8 2905[77CD0000]      <1> 	sub	[FreeClusterCount], eax
 27312                              <1> 
 27313                              <1> pass_FAT_add_sub_fcc:
 27314 000098AE 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 27315 000098B2 8B15[77CD0000]      <1> 	mov	edx, [FreeClusterCount]
 27316 000098B8 F7E2                <1> 	mul	edx
 27317                              <1> 
 27318 000098BA 31C9                <1> 	xor	ecx, ecx 
 27319 000098BC EB05                <1> 	jmp	short loc_cfs_retn_params
 27320                              <1> 
 27321                              <1> loc_put_fcc_invalid_sign:
 27322 000098BE 29C0                <1>        	sub	eax, eax ; 0
 27323 000098C0 48                  <1> 	dec	eax ; FFFFFFFFh
 27324                              <1> loc_fat32_ffc_recalc_needed:
 27325 000098C1 89C1                <1> 	mov	ecx, eax
 27326                              <1> 
 27327                              <1> loc_cfs_retn_params:
 27328 000098C3 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
 27329 000098C6 0FB71D[FECF0000]    <1> 	movzx	ebx, word [CFS_OPType]
 27330 000098CD C3                  <1> 	retn
 27331                              <1> 
 27332                              <1> loc_update_FAT32_fs_info_fcc:
 27333                              <1> loc_check_fcc_FSINFO_op:
 27334                              <1> 	; 29/02/2016
 27335                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
 27336                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
 27337 000098CE 803D[FECF0000]01    <1> 	cmp	byte [CFS_OPType], 1
 27338 000098D5 7221                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
 27339 000098D7 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
 27340                              <1> loc_check_fcc_FSINFO_op2: ; subtract
 27341 000098D9 F71D[00D00000]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
 27342                              <1> loc_check_fcc_FSINFO_op1:
 27343                              <1> 	; 01/03/2016
 27344 000098DF 31D2                <1> 	xor	edx, edx ; 0
 27345 000098E1 4A                  <1> 	dec	edx ; 0FFFFFFFFh
 27346 000098E2 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved]
 27347 000098E5 39D0                <1> 	cmp	eax, edx
 27348 000098E7 73D5                <1> 	jnb	short loc_put_fcc_invalid_sign
 27349 000098E9 0305[00D00000]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
 27350 000098EF 72CD                <1> 	jc	short loc_put_fcc_invalid_sign
 27351                              <1> 	
 27352 000098F1 A3[77CD0000]        <1> 	mov	[FreeClusterCount], eax
 27353 000098F6 EB0E                <1> 	jmp	short loc_cfs_write_FSINFO_sector
 27354                              <1> 
 27355                              <1> loc_cfs_FAT32_get_rcalc_parms:
 27356 000098F8 8B15[08D00000]      <1> 	mov	edx, [CFS_FAT32FC]
 27357 000098FE A1[77CD0000]        <1> 	mov	eax, [FreeClusterCount]
 27358 00009903 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
 27359                              <1> loc_cfs_write_FSINFO_sector:
 27360 00009906 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
 27361                              <1> 	; 01/03/2016
 27362 00009909 E89A000000          <1> 	call	set_fat32_fsinfo_sector_parms
 27363 0000990E 72AE                <1>         jc      short loc_put_fcc_invalid_sign
 27364                              <1> 
 27365                              <1> loc_set_FAT32_free_sectors:
 27366                              <1> 	; 29/02/2016
 27367                              <1> 	;mov	eax, [FreeClusterCount]
 27368                              <1> 	;mov	ecx, eax
 27369                              <1> 	;cmp	eax, 0FFFFFFFFh ; Invalid !
 27370                              <1> 	;je	short loc_cfs_retn_params
 27371                              <1> 	;
 27372 00009910 8B0D[77CD0000]      <1> 	mov	ecx, [FreeClusterCount]
 27373 00009916 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 27374 0000991A F7E1                <1> 	mul	ecx
 27375                              <1> 	; 29/02/2016
 27376 0000991C 31C9                <1> 	xor	ecx, ecx ; 0
 27377 0000991E 09D2                <1> 	or	edx, edx ; 0 ?
 27378 00009920 759C                <1>         jnz     loc_put_fcc_invalid_sign
 27379 00009922 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
 27380 00009925 7697                <1>         jna     short loc_put_fcc_invalid_sign
 27381                              <1> 	;
 27382                              <1> loc_set_FAT32_free_sectors_ok:
 27383 00009927 31D2                <1> 	xor	edx, edx ; 0
 27384 00009929 EB98                <1>         jmp     short loc_cfs_retn_params 
 27385                              <1> 	;
 27386                              <1> 
 27387                              <1> get_last_cluster:
 27388                              <1> 	; 27/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27389                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
 27390                              <1> 	; 06/06/2010
 27391                              <1> 	; INPUT ->
 27392                              <1> 	;	EAX = First Cluster Number
 27393                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
 27394                              <1> 	; OUTPUT ->
 27395                              <1> 	;	cf = 0 -> No Error, EAX is valid
 27396                              <1> 	;	cf = 1 -> EAX > 0 -> Error
 27397                              <1> 	;	EAX = Last Cluster Number
 27398                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
 27399                              <1> 	;
 27400                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 27401                              <1> 
 27402 0000992B 89C1                <1> 	mov	ecx, eax	
 27403                              <1> 
 27404                              <1> loc_glc_get_next_cluster_1:
 27405 0000992D 890D[0CD00000]      <1> 	mov	[glc_prevcluster], ecx
 27406                              <1> 
 27407                              <1> loc_glc_get_next_cluster_2:
 27408 00009933 E8F8F7FFFF          <1> 	call	get_next_cluster
 27409                              <1> 	; ecx = current/previous cluster 
 27410                              <1> 	; eax = next/last cluster
 27411 00009938 73F3                <1> 	jnc	short loc_glc_get_next_cluster_1
 27412                              <1> 
 27413 0000993A 09C0                <1> 	or	eax, eax
 27414 0000993C 7509                <1> 	jnz	short loc_glc_stc_retn
 27415                              <1> 
 27416                              <1> 	; ecx = previous cluster
 27417 0000993E 89C8                <1>         mov	eax, ecx
 27418                              <1> 
 27419                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
 27420                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
 27421                              <1> 
 27422                              <1> loc_glc_prev_cluster_retn:
 27423 00009940 8B0D[0CD00000]      <1> 	mov	ecx, [glc_prevcluster] 
 27424 00009946 C3                  <1> 	retn
 27425                              <1> 
 27426                              <1> loc_glc_stc_retn:
 27427 00009947 F5                  <1> 	cmc	;stc
 27428 00009948 EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
 27429                              <1> 
 27430                              <1> truncate_cluster_chain:
 27431                              <1> 	; 01/03/2016
 27432                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27433                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
 27434                              <1> 	; 11/09/2010
 27435                              <1> 	; INPUT ->
 27436                              <1> 	;	ESI = Logical dos drive description table address
 27437                              <1> 	;	EAX = First cluster to be truncated/unlinked 
 27438                              <1> 	; OUTPUT ->
 27439                              <1> 	;	ESI = Logical dos drive description table address
 27440                              <1> 	; 	ECX = Count of truncated/removed clusters
 27441                              <1> 	; 	CF = 0 -> EAX = Free sectors
 27442                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 27443                              <1> 
 27444                              <1> 	; NOTE: This procedure does not update lm date&time ! 
 27445                              <1> 
 27446                              <1> loc_truncate_cc:	
 27447 0000994A 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
 27448                              <1> 	;mov	byte [FAT_BuffValidData], 0
 27449 0000994C 890D[61CD0000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 27450                              <1> 
 27451                              <1> loc_tcc_unlink_clusters:
 27452 00009952 E803FBFFFF          <1> 	call	update_cluster
 27453                              <1> 	; EAX = Next Cluster
 27454                              <1> 	; ECX = Cluster Value
 27455                              <1> 	; Note:
 27456                              <1> 	; Returns count of unlinked clusters in
 27457                              <1> 	; dword ptr FAT_ClusterCounter
 27458 00009957 73F9                <1> 	jnc short loc_tcc_unlink_clusters
 27459                              <1> 
 27460                              <1> pass_tcc_unlink_clusters:
 27461 00009959 A2[13D00000]        <1> 	mov	byte [TCC_FATErr], al
 27462 0000995E 803D[59CD0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 27463 00009965 750E                <1> 	jne	short loc_tcc_calculate_FAT_freespace
 27464 00009967 E8ABFDFFFF          <1> 	call	save_fat_buffer
 27465 0000996C 7307                <1> 	jnc	short loc_tcc_calculate_FAT_freespace
 27466 0000996E A2[13D00000]        <1> 	mov	byte [TCC_FATErr], al ; Error
 27467                              <1> 	;mov	byte [FAT_BuffValidData], 0
 27468                              <1> 
 27469                              <1> 	; 01/03/2016
 27470 00009973 EB12                <1> 	jmp	short loc_tcc_recalculate_FAT_freespace
 27471                              <1> 
 27472                              <1> loc_tcc_calculate_FAT_freespace:
 27473 00009975 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter] ; signed (+-) number
 27474 0000997A 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
 27475                              <1> 			   ; BL = 1 -> add cluster
 27476 0000997E E829FEFFFF          <1> 	call	calculate_fat_freespace
 27477 00009983 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
 27478 00009985 7409                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
 27479                              <1> 
 27480                              <1> loc_tcc_recalculate_FAT_freespace:
 27481 00009987 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate !
 27482 0000998B E81CFEFFFF          <1> 	call	calculate_fat_freespace
 27483                              <1>               
 27484                              <1> loc_tcc_calculate_FAT_freespace_err:
 27485                              <1> pass_truncate_cc_recalc_FAT_freespace:
 27486 00009990 8B0D[61CD0000]      <1> 	mov	ecx, [FAT_ClusterCounter]
 27487                              <1> 
 27488 00009996 803D[13D00000]00    <1> 	cmp	byte [TCC_FATErr], 0
 27489 0000999D 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
 27490                              <1> 
 27491                              <1> loc_tcc_unlink_clusters_error:
 27492 0000999F 0FB605[13D00000]    <1> 	movzx	eax, byte [TCC_FATErr]
 27493 000099A6 F9                  <1> 	stc
 27494                              <1> loc_tcc_unlink_clusters_retn:
 27495 000099A7 C3                  <1> 	retn
 27496                              <1> 
 27497                              <1> set_fat32_fsinfo_sector_parms:
 27498                              <1> 	; 23/03/2016
 27499                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27500                              <1> 	; INPUT ->
 27501                              <1> 	;	ESI = Logical dos drive description table address
 27502                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
 27503                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First Free Cluster 
 27504                              <1> 	; OUTPUT ->
 27505                              <1> 	;	ESI = Logical dos drive description table address
 27506                              <1> 	; 	CF = 0 -> OK..
 27507                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 27508                              <1> 	;
 27509                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 27510                              <1> 
 27511 000099A8 E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
 27512 000099AD 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
 27513                              <1> 
 27514 000099AF 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
 27515 000099B2 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
 27516                              <1> 
 27517                              <1>         ;mov	ebx, DOSBootSectorBuff
 27518 000099B5 8983E8010000        <1> 	mov	[ebx+488], eax
 27519 000099BB 8993EC010000        <1> 	mov	[ebx+492], edx	
 27520                              <1> 
 27521 000099C1 A1[04D00000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 27522 000099C6 B901000000          <1> 	mov	ecx, 1
 27523 000099CB E8DD170000          <1> 	call	disk_write
 27524                              <1> 	;jnc     short update_fat32_fsinfo_sector_retn
 27525                              <1> 
 27526                              <1> 	; 23/03/2016
 27527                              <1> 	;mov	eax, 1Dh ; Drive not ready or write error
 27528                              <1> 
 27529                              <1> update_fat32_fsinfo_sector_retn:
 27530 000099D0 C3                  <1> 	retn
 27531                              <1> 
 27532                              <1> get_fat32_fsinfo_sector_parms:
 27533                              <1> 	; 23/03/2016
 27534                              <1> 	; 01/03/2016
 27535                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 27536                              <1> 	; INPUT ->
 27537                              <1> 	;	ESI = Logical dos drive description table address
 27538                              <1> 	; OUTPUT ->
 27539                              <1> 	;	ESI = Logical dos drive description table address
 27540                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
 27541                              <1> 	;	CF = 0 -> OK..
 27542                              <1> 	;	   EAX = FsInfo sector address
 27543                              <1> 	;	   ECX = Free cluster count
 27544                              <1> 	;	   EDX = First free cluster 	
 27545                              <1> 	;	CF = 1 -> Error code in AL (EAX)
 27546                              <1> 	;	   EBX = 0
 27547                              <1> 	;	
 27548                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
 27549                              <1>         ;
 27550                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 27551                              <1> 
 27552 000099D1 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
 27553 000099D5 03466C              <1> 	add	eax, [esi+LD_StartSector]
 27554 000099D8 A3[04D00000]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
 27555                              <1> 	
 27556 000099DD BB[55CB0000]        <1>         mov     ebx, DOSBootSectorBuff
 27557 000099E2 B901000000          <1> 	mov	ecx, 1
 27558 000099E7 E8D0170000          <1> 	call	disk_read
 27559 000099EC 7232                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
 27560                              <1> 
 27561 000099EE BB[55CB0000]        <1> 	mov	ebx, DOSBootSectorBuff
 27562                              <1> 
 27563 000099F3 813B52526141        <1> 	cmp	dword [ebx], 41615252h
 27564 000099F9 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 27565                              <1> 
 27566 000099FB 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 27567 00009A04 61                  <1>
 27568 00009A05 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 27569                              <1> 
 27570 00009A07 A1[04D00000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 27571 00009A0C 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
 27572 00009A12 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
 27573                              <1> 
 27574 00009A18 C3                  <1> 	retn
 27575                              <1> 
 27576                              <1> loc_read_FAT32_fsinfo_sec_stc:
 27577 00009A19 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format!
 27578 00009A1E EB05                <1> 	jmp	short loc_read_FAT32_fsinfo_sec_stc_retn
 27579                              <1> 
 27580                              <1> loc_read_FAT32_fsinfo_sec_err:
 27581                              <1> 	; 23/03/2016
 27582 00009A20 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 27583                              <1> 
 27584                              <1> loc_read_FAT32_fsinfo_sec_stc_retn:
 27585 00009A25 29DB                <1> 	sub	ebx, ebx ; 0
 27586 00009A27 F9                  <1> 	stc
 27587 00009A28 C3                  <1> 	retn
 27588                              <1> 
 27589                              <1> add_new_cluster:
 27590                              <1> 	; 24/03/2016
 27591                              <1> 	; 18/03/2016
 27592                              <1> 	; 11/03/2016 (TRDOS 386 =  TRDOS v2.0)
 27593                              <1> 	; 30/07/2011 (DRV_FAT.ASM)
 27594                              <1> 	; 11/09/2010
 27595                              <1> 	; INPUT ->
 27596                              <1> 	;	ESI = Logical dos drv desc. table address
 27597                              <1> 	;	EAX = Last cluster
 27598                              <1> 	; OUTPUT ->
 27599                              <1> 	;	ESI = Logical dos drv desc. table address
 27600                              <1> 	;	EAX = New Last cluster (next cluster)
 27601                              <1> 	;	cf = 1 -> error code in EAX (AL)
 27602                              <1> 	;	cf = 1 -> DX = sectors per cluster
 27603                              <1> 	;	ECX = Free sectors
 27604                              <1> 	; NOTE:
 27605                              <1> 	; This procedure does not update lm date&time !
 27606                              <1> 	;
 27607                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, EDI)
 27608                              <1> 	;
 27609                              <1> 
 27610 00009A29 A3[2ED10000]        <1> 	mov	[FAT_anc_LCluster], eax
 27611                              <1> 	
 27612 00009A2E E854F9FFFF          <1> 	call	get_first_free_cluster
 27613 00009A33 720B                <1> 	jc	short loc_add_new_cluster_retn
 27614                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
 27615                              <1> 
 27616 00009A35 89C2                <1> 	mov	edx, eax
 27617                              <1> 
 27618 00009A37 42                  <1> 	inc	edx
 27619                              <1> 	;jnz	short loc_add_new_cluster_check_ffc_eax
 27620 00009A38 7516                <1> 	jnz	short loc_add_new_cluster_save_fcc
 27621                              <1> 
 27622                              <1> loc_add_new_cluster_no_disk_space_retn:
 27623 00009A3A B827000000          <1> 	mov	eax, 27h ; MSDOS err => insufficient disk space
 27624                              <1> loc_add_new_cluster_stc_retn:
 27625 00009A3F F9                  <1> 	stc
 27626                              <1> loc_add_new_cluster_retn:
 27627 00009A40 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
 27628 00009A44 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 27629                              <1> 	;xor	edx, edx
 27630                              <1> 	;stc
 27631 00009A47 C3                  <1> 	retn
 27632                              <1> 
 27633                              <1> loc_anc_invalid_format_stc_retn:
 27634 00009A48 F9                  <1> 	stc
 27635                              <1> loc_add_new_cluster_invalid_format_retn:
 27636 00009A49 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 27637 00009A4E EBF0                <1> 	jmp	short loc_add_new_cluster_retn 
 27638                              <1> 
 27639                              <1> ;loc_add_new_cluster_check_ffc_eax:
 27640                              <1> ;	cmp	eax, 2
 27641                              <1> ;	jb	short loc_add_new_cluster_invalid_format_retn
 27642                              <1> 
 27643                              <1> loc_add_new_cluster_save_fcc:  
 27644 00009A50 A3[32D10000]        <1> 	mov	[FAT_anc_FFCluster], eax
 27645                              <1> 
 27646 00009A55 83E802              <1> 	sub	eax, 2
 27647 00009A58 0FB65E13            <1>         movzx   ebx, byte [esi+LD_BPB+SecPerClust]
 27648 00009A5C F7E3                <1> 	mul	ebx
 27649 00009A5E 09D2                <1> 	or	edx, edx
 27650 00009A60 75E6                <1> 	jnz	short loc_anc_invalid_format_stc_retn
 27651                              <1> 
 27652                              <1> loc_add_new_cluster_allocate_cluster:
 27653                              <1> 	; 18/03/2016
 27654 00009A62 92                  <1> 	xchg	edx, eax ; eax = 0
 27655 00009A63 3805[69CD0000]      <1> 	cmp	[ClusterBuffer_Valid], al ; 0
 27656 00009A69 7607                <1> 	jna	short loc_anc_clear_cluster_buffer
 27657                              <1> 	; 'copy' command, 
 27658                              <1> 	; writing destination file clust after reading source file clust
 27659 00009A6B A2[69CD0000]        <1> 	mov	[ClusterBuffer_Valid], al ; 0 ; reset
 27660 00009A70 EB0C                <1> 	jmp	short loc_add_new_cluster_write_nc_to_disk
 27661                              <1> 
 27662                              <1> loc_anc_clear_cluster_buffer:
 27663                              <1> 	; 11/03/2016
 27664                              <1> 	; Clear buffer
 27665 00009A72 BF00000700          <1> 	mov	edi, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
 27666 00009A77 89D9                <1> 	mov	ecx, ebx ; sector count
 27667 00009A79 C1E107              <1> 	shl	ecx, 7 ; 1 sector = 512 bytes -> 128 double words
 27668                              <1> 	;xor	eax, eax ; 0
 27669 00009A7C F3AB                <1> 	rep	stosd
 27670                              <1> 
 27671                              <1> loc_add_new_cluster_write_nc_to_disk:
 27672                              <1> 	; 11/03/2016
 27673                              <1> 	;xchg	eax, edx ; edx = 0, eax = sector offset
 27674 00009A7E 89D0                <1> 	mov	eax, edx
 27675 00009A80 034668              <1>         add     eax, [esi+LD_DATABegin]
 27676 00009A83 72C4                <1> 	jc	short loc_add_new_cluster_invalid_format_retn 
 27677                              <1> 		
 27678 00009A85 89D9                <1> 	mov	ecx, ebx ; ECX = sectors per cluster (<256)
 27679 00009A87 BB00000700          <1> 	mov	ebx, Cluster_Buffer
 27680 00009A8C E81C170000          <1> 	call	disk_write
 27681 00009A91 7307                <1> 	jnc	short loc_add_new_cluster_update_fat_nlc
 27682                              <1> 	
 27683 00009A93 B81D000000          <1> 	mov	eax, 1Dh ; Write Error
 27684 00009A98 EBA5                <1> 	jmp	short loc_add_new_cluster_stc_retn
 27685                              <1> 
 27686                              <1> loc_add_new_cluster_update_fat_nlc:
 27687 00009A9A A1[32D10000]        <1> 	mov	eax, [FAT_anc_FFCluster]
 27688 00009A9F 31C9                <1> 	xor	ecx, ecx
 27689 00009AA1 890D[61CD0000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 27690 00009AA7 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 27691 00009AA8 E8ADF9FFFF          <1> 	call	update_cluster
 27692 00009AAD 7304                <1> 	jnc	short loc_add_new_cluster_update_fat_plc
 27693 00009AAF 09C0                <1> 	or	eax, eax ;EAX = 0 -> cluster value is 0 or eocc
 27694 00009AB1 758C                <1> 	jnz	short loc_add_new_cluster_stc_retn
 27695                              <1> 
 27696                              <1> loc_add_new_cluster_update_fat_plc:
 27697 00009AB3 A1[2ED10000]        <1> 	mov	eax, [FAT_anc_LCluster]
 27698 00009AB8 8B0D[32D10000]      <1> 	mov	ecx, [FAT_anc_FFCluster]
 27699 00009ABE E897F9FFFF          <1> 	call	update_cluster
 27700 00009AC3 7314                <1> 	jnc	short loc_add_new_cluster_save_fat_buffer
 27701 00009AC5 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 27702 00009AC7 7410                <1> 	jz	short loc_add_new_cluster_save_fat_buffer
 27703                              <1> 
 27704                              <1> loc_anc_save_fat_buffer_err_retn:
 27705                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
 27706                              <1> 	;jb	short loc_add_new_cluster_retn
 27707                              <1> 
 27708 00009AC9 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
 27709                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
 27710 00009ACD 50                  <1> 	push	eax
 27711 00009ACE E8D9FCFFFF          <1> 	call	calculate_fat_freespace
 27712 00009AD3 58                  <1> 	pop	eax
 27713 00009AD4 E966FFFFFF          <1>         jmp     loc_add_new_cluster_stc_retn
 27714                              <1> 
 27715                              <1> loc_add_new_cluster_save_fat_buffer:
 27716                              <1> 	;cmp	byte [FAT_BuffValidData], 2
 27717                              <1> 	;jne	short loc_add_new_cluster_calc_FAT_freespace 
 27718                              <1> 	;Byte [FAT_BuffValidData] =  2 
 27719 00009AD9 E839FCFFFF          <1> 	call	save_fat_buffer
 27720 00009ADE 72E9                <1> 	jc	short loc_anc_save_fat_buffer_err_retn
 27721                              <1> 
 27722                              <1> loc_add_new_cluster_calc_FAT_freespace:
 27723                              <1> 	;mov	eax, 1 ; Only one Cluster
 27724 00009AE0 A1[61CD0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 27725 00009AE5 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI -> Dos drv desc. table
 27726                              <1> 		; BL = 1 -> add cluster
 27727 00009AE9 B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
 27728                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
 27729                              <1> 	; (Free Cluster Count is decreased when EAX value is negative)
 27730 00009AEB E8BCFCFFFF          <1>         call    calculate_fat_freespace
 27731                              <1> 	;ECX = 0 -> no error, ECX > 0 -> error or invalid return
 27732 00009AF0 21C9                <1> 	and	ecx, ecx ; ECX = 0 -> valid free sector count
 27733 00009AF2 7409                <1> 	jz	short loc_add_new_cluster_return_cluster_number
 27734                              <1> 
 27735                              <1> loc_add_new_cluster_recalc_FAT_freespace:
 27736 00009AF4 66BB00FF            <1> 	mov	bx, 0FF00h  ; recalculate free space
 27737 00009AF8 E8AFFCFFFF          <1>         call    calculate_fat_freespace
 27738                              <1> 	; cf = 0
 27739                              <1> loc_add_new_cluster_return_cluster_number:
 27740 00009AFD 89C1                <1> 	mov	ecx, eax ; Free sector count
 27741 00009AFF A1[32D10000]        <1> 	mov	eax, [FAT_anc_FFCluster]
 27742 00009B04 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
 27743                              <1> 	;mov	edi, Cluster_Buffer
 27744 00009B08 31D2                <1> 	xor	edx, edx
 27745 00009B0A C3                  <1>         retn
 27746                              <1> 
 27747                              <1> write_cluster:
 27748                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 27749                              <1> 	;
 27750                              <1> 	; INPUT ->
 27751                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
 27752                              <1> 	;	ESI = Logical DOS Drive Description Table address
 27753                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
 27754                              <1> 	;	Only for SINGLIX FS:
 27755                              <1> 	;	EDX = File Number (The 1st FDT address) 
 27756                              <1> 	; OUTPUT ->
 27757                              <1> 	;	cf = 1 -> Cluster can not be written onto disk
 27758                              <1> 	;	    EAX > 0 -> Error number
 27759                              <1> 	;	cf = 0 -> Cluster has been written successfully
 27760                              <1> 	;
 27761                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 27762                              <1> 	
 27763 00009B0B 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
 27764                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 27765                              <1> 
 27766                              <1> write_file_sectors: ; 16/03/2016
 27767 00009B0F 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 27768 00009B13 761C                <1> 	jna	short write_fs_cluster
 27769                              <1> 
 27770                              <1> write_fat_file_sectors: 
 27771 00009B15 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
 27772 00009B18 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
 27773 00009B1C F7E2                <1> 	mul	edx
 27774 00009B1E 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
 27775                              <1> 
 27776                              <1> 	; EAX = Disk sector address
 27777                              <1> 	; ECX = Sector count
 27778                              <1> 	; EBX = Buffer address
 27779                              <1> 	; (EDX = 0)
 27780                              <1> 	; ESI = Logical DOS drive description table address	
 27781                              <1> 
 27782 00009B21 E887160000          <1> 	call	disk_write
 27783 00009B26 7306                <1> 	jnc	short wclust_retn
 27784                              <1> 	
 27785 00009B28 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
 27786 00009B2D C3                  <1> 	retn
 27787                              <1> 
 27788                              <1> wclust_retn:
 27789 00009B2E 29C0                <1> 	sub	eax, eax ; 0
 27790 00009B30 C3                  <1> 	retn
 27791                              <1> 
 27792                              <1> write_fs_cluster:
 27793                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 27794                              <1> 	; Singlix FS
 27795                              <1> 	
 27796                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
 27797                              <1> 	
 27798                              <1> 	; EDX = File number is the first File Descriptor Table address 
 27799                              <1> 	;	of the file. (Absolute address of the FDT).
 27800                              <1> 	
 27801                              <1> 	; eax = sector index (0 for the first sector)
 27802                              <1> 	; edx = FDT0 address
 27803                              <1> 		; 64 KB buffer = 128 sectors (limit) 
 27804 00009B31 B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
 27805 00009B36 E801000000          <1> 	call	write_fs_sectors
 27806 00009B3B C3                  <1> 	retn
 27807                              <1> 
 27808                              <1> write_fs_sectors:
 27809                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 27810 00009B3C F9                  <1> 	stc
 27811 00009B3D C3                  <1> 	retn
 27812                                  %include 'trdosk6.s' ; 24/01/2016
 27813                              <1> ; ****************************************************************************
 27814                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk6.s
 27815                              <1> ; ----------------------------------------------------------------------------
 27816                              <1> ; Last Update: 24/01/2016
 27817                              <1> ; ----------------------------------------------------------------------------
 27818                              <1> ; Beginning: 24/01/2016
 27819                              <1> ; ----------------------------------------------------------------------------
 27820                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 27821                              <1> ; ----------------------------------------------------------------------------
 27822                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 27823                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 27824                              <1> ;
 27825                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 27826                              <1> ; u1.s (27/17/2015)
 27827                              <1> ; ****************************************************************************
 27828                              <1> 
 27829                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u1.s
 27830                              <1> ; Last Modification: 27/12/2015
 27831                              <1> 
 27832                              <1> sysent: ; < enter to system call >
 27833                              <1> 	 ;19/10/2015
 27834                              <1> 	; 21/09/2015
 27835                              <1> 	; 01/07/2015
 27836                              <1> 	; 19/05/2015
 27837                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27838                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
 27839                              <1> 	;
 27840                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
 27841                              <1> 	; The trap type is determined and an indirect jump is made to 
 27842                              <1> 	; the appropriate system call handler. If there is a trap inside
 27843                              <1> 	; the system a jump to panic is made. All user registers are saved 
 27844                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
 27845                              <1> 	; instructor is decoded to get the the system code part (see
 27846                              <1> 	; trap instruction in the PDP-11 handbook) and from this 
 27847                              <1> 	; the indirect jump address is calculated. If a bad system call is
 27848                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
 27849                              <1> 	; is called. If the call is legitimate control passes to the
 27850                              <1> 	; appropriate system routine.
 27851                              <1> 	;
 27852                              <1> 	; Calling sequence:
 27853                              <1> 	;	Through a trap caused by any sys call outside the system.
 27854                              <1> 	; Arguments:
 27855                              <1> 	;	Arguments of particular system call.	
 27856                              <1> 	; ...............................................................
 27857                              <1> 	;	
 27858                              <1> 	; Retro UNIX 8086 v1 modification: 
 27859                              <1> 	;       System call number is in EAX register.
 27860                              <1> 	;
 27861                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 27862                              <1> 	;	registers depending of function details.
 27863                              <1>   	;
 27864                              <1> 	; 16/04/2015
 27865 00009B3E 368925[D0D40000]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
 27866                              <1> 	; save user registers
 27867 00009B45 1E                  <1> 	push	ds
 27868 00009B46 06                  <1> 	push	es
 27869 00009B47 0FA0                <1> 	push	fs
 27870 00009B49 0FA8                <1> 	push	gs
 27871 00009B4B 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
 27872                              <1> 	;
 27873                              <1> 	; ESPACE = esp - [ss:u.sp] ; 4*12 = 48 ; 17/09/2015
 27874                              <1> 	; 	(ESPACE is size of space in kernel stack 
 27875                              <1> 	;	for saving/restoring user registers.)
 27876                              <1> 	;
 27877 00009B4C 50                  <1> 	push	eax ; 01/07/2015
 27878 00009B4D 66B81000            <1> 	mov     ax, KDATA
 27879 00009B51 8ED8                <1>         mov     ds, ax
 27880 00009B53 8EC0                <1>         mov     es, ax
 27881 00009B55 8EE0                <1>         mov     fs, ax
 27882 00009B57 8EE8                <1>         mov     gs, ax
 27883 00009B59 A1[78C40000]        <1> 	mov	eax, [k_page_dir]
 27884 00009B5E 0F22D8              <1> 	mov	cr3, eax
 27885 00009B61 58                  <1> 	pop	eax ; 01/07/2015
 27886                              <1> 	; 19/10/2015
 27887 00009B62 FC                  <1> 	cld
 27888                              <1> 	;
 27889 00009B63 FE05[CDD40000]      <1> 	inc	byte [sysflg]
 27890                              <1> 		; incb sysflg / indicate a system routine is in progress
 27891 00009B69 FB                  <1>         sti 	; 18/01/2014
 27892 00009B6A 0F85ADA3FFFF        <1> 	jnz     panic ; 24/05/2013
 27893                              <1> 		; beq 1f
 27894                              <1> 		; jmp panic ; / called if trap inside system
 27895                              <1> ;1:
 27896                              <1> 	; 16/04/2015
 27897 00009B70 A3[D8D40000]        <1> 	mov	[u.r0], eax
 27898 00009B75 8925[D4D40000]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
 27899                              <1> 	;
 27900                              <1> 		; mov $s.syst+2,clockp
 27901                              <1> 		; mov r0,-(sp) / save user registers 
 27902                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack 
 27903                              <1> 			   ; / in u.r0
 27904                              <1> 		; mov r1,-(sp)
 27905                              <1> 		; mov r2,-(sp)
 27906                              <1> 		; mov r3,-(sp)
 27907                              <1> 		; mov r4,-(sp)
 27908                              <1> 		; mov r5,-(sp)
 27909                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
 27910                              <1> 		             ; / arithmetic unit
 27911                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
 27912                              <1> 		             ; / extended arithmetic unit
 27913                              <1> 		; mov sc,-(sp) / "step count" register for the extended
 27914                              <1> 		             ; / arithmetic unit
 27915                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
 27916                              <1> 		; mov 18.(sp),r0 / store pc in r0
 27917                              <1> 		; mov -(r0),r0 / sys inst in r0      10400xxx
 27918                              <1> 		; sub $sys,r0 / get xxx code
 27919 00009B7B C1E002              <1> 	shl	eax, 2
 27920                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
 27921 00009B7E 3D94000000          <1> 	cmp	eax, end_of_syscalls - syscalls
 27922                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
 27923                              <1> 	;jnb	short badsys
 27924                              <1> 		; bhis badsys / yes, bad system call
 27925 00009B83 F5                  <1> 	cmc
 27926 00009B84 9C                  <1> 	pushf	
 27927 00009B85 50                  <1> 	push	eax
 27928 00009B86 8B2D[D0D40000]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
 27929 00009B8C B0FE                <1> 	mov	al, 0FEh ; 11111110b
 27930 00009B8E 1400                <1> 	adc	al, 0 ; al = al + cf
 27931 00009B90 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
 27932                              <1> 		; bic $341,20.(sp) / set users processor priority to 0 
 27933                              <1> 				 ; / and clear carry bit
 27934 00009B93 5D                  <1> 	pop	ebp ; eax
 27935 00009B94 9D                  <1> 	popf
 27936 00009B95 0F8248010000        <1>         jc      badsys
 27937 00009B9B A1[D8D40000]        <1> 	mov	eax, [u.r0]
 27938                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
 27939 00009BA0 FFA5[A69B0000]      <1> 	jmp	dword [ebp+syscalls]
 27940                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
 27941                              <1> 		            ; / to proper system routine.
 27942                              <1> syscalls: ; 1:
 27943                              <1> 	; 21/09/2015
 27944                              <1> 	; 01/07/2015
 27945                              <1> 	; 16/04/2015 (32 bit address modification) 
 27946 00009BA6 [AD9C0000]          <1> 	dd sysrele	; / 0
 27947 00009BAA [539D0000]          <1> 	dd sysexit 	; / 1
 27948 00009BAE [789E0000]          <1> 	dd sysfork 	; / 2
 27949 00009BB2 [8B9F0000]          <1> 	dd sysread 	; / 3
 27950 00009BB6 [A69F0000]          <1> 	dd syswrite 	; / 4
 27951 00009BBA [10A00000]          <1> 	dd sysopen 	; / 5
 27952 00009BBE [4AA10000]          <1> 	dd sysclose 	; / 6
 27953 00009BC2 [FA9D0000]          <1> 	dd syswait 	; / 7
 27954 00009BC6 [C0A00000]          <1> 	dd syscreat 	; / 8
 27955 00009BCA [71A40000]          <1> 	dd syslink 	; / 9
 27956 00009BCE [33A50000]          <1> 	dd sysunlink 	; / 10
 27957 00009BD2 [06A60000]          <1> 	dd sysexec 	; / 11
 27958 00009BD6 [6DAC0000]          <1> 	dd syschdir 	; / 12
 27959 00009BDA [51AD0000]          <1> 	dd systime 	; / 13
 27960 00009BDE [01A10000]          <1> 	dd sysmkdir 	; / 14
 27961 00009BE2 [BFAC0000]          <1> 	dd syschmod 	; / 15
 27962 00009BE6 [21AD0000]          <1> 	dd syschown 	; / 16
 27963 00009BEA [84AD0000]          <1> 	dd sysbreak 	; / 17
 27964 00009BEE [DEA90000]          <1> 	dd sysstat 	; / 18
 27965 00009BF2 [49AE0000]          <1> 	dd sysseek 	; / 19
 27966 00009BF6 [5BAE0000]          <1> 	dd systell 	; / 20
 27967 00009BFA [5CAF0000]          <1> 	dd sysmount 	; / 21
 27968 00009BFE [0EB00000]          <1> 	dd sysumount 	; / 22
 27969 00009C02 [D9AE0000]          <1> 	dd syssetuid 	; / 23
 27970 00009C06 [0AAF0000]          <1> 	dd sysgetuid 	; / 24
 27971 00009C0A [60AD0000]          <1> 	dd sysstime 	; / 25
 27972 00009C0E [CDAE0000]          <1> 	dd sysquit 	; / 26
 27973 00009C12 [C1AE0000]          <1> 	dd sysintr 	; / 27
 27974 00009C16 [BAA90000]          <1> 	dd sysfstat 	; / 28
 27975 00009C1A [66A10000]          <1> 	dd sysemt 	; / 29
 27976 00009C1E [94A10000]          <1> 	dd sysmdate 	; / 30
 27977 00009C22 [DFA10000]          <1> 	dd sysstty 	; / 31
 27978 00009C26 [5EA30000]          <1> 	dd sysgtty 	; / 32
 27979 00009C2A [8FA10000]          <1> 	dd sysilgins 	; / 33
 27980 00009C2E [69B00000]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
 27981                              <1> 			     ; 11/06/2014
 27982 00009C32 [98B00000]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
 27983                              <1> 			     ; 01/07/2015
 27984 00009C36 [6FB10000]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
 27985                              <1> 			     ; 21/09/2015 - get last error number
 27986                              <1> end_of_syscalls:
 27987                              <1> 
 27988                              <1> error:
 27989                              <1> 	; 17/09/2015
 27990                              <1> 	; 03/09/2015
 27991                              <1> 	; 01/09/2015
 27992                              <1> 	; 09/06/2015
 27993                              <1> 	; 13/05/2015
 27994                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27995                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
 27996                              <1> 	;
 27997                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
 27998                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
 27999                              <1> 	;
 28000                              <1> 	; INPUTS -> none
 28001                              <1> 	; OUTPUTS ->
 28002                              <1> 	;	processor status - carry (c) bit is set (means error)
 28003                              <1> 	;
 28004                              <1> 	; 26/05/2013 (Stack pointer must be reset here! 
 28005                              <1> 	; 	      Because, jumps to error procedure
 28006                              <1> 	;	      disrupts push-pop nesting balance)
 28007                              <1> 	;
 28008 00009C3A 8B2D[D0D40000]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
 28009 00009C40 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
 28010                              <1> 				 ; (system call will return with cf = 1)
 28011                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
 28012                              <1> 		               ; / users stack
 28013                              <1> 	; 17/09/2015
 28014 00009C44 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
 28015                              <1> 				 ; for saving/restoring user registers	
 28016                              <1> 	;cmp	ebp, [u.usp]
 28017                              <1> 	;je	short err0	
 28018 00009C47 892D[D4D40000]      <1> 	mov	[u.usp], ebp
 28019                              <1> ;err0:
 28020                              <1> 	; 01/09/2015
 28021 00009C4D 8B25[D4D40000]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
 28022                              <1> 				    ; 10/04/2013
 28023                              <1> 				    ; (If an I/O error occurs during disk I/O,
 28024                              <1> 				    ; related procedures will jump to 'error'
 28025                              <1> 				    ; procedure directly without returning to 
 28026                              <1> 				    ; the caller procedure. So, stack pointer
 28027                              <1>                                     ; must be restored here.)
 28028                              <1> 	; 13/05/2015
 28029                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
 28030                              <1> 	;	'get last error' system call later. 	
 28031                              <1> 
 28032                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
 28033 00009C53 C605[3FD50000]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
 28034                              <1> 
 28035                              <1> sysret: ; < return from system call>
 28036                              <1> 	; 10/09/2015
 28037                              <1> 	; 29/07/2015
 28038                              <1> 	; 25/06/2015
 28039                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28040                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
 28041                              <1> 	;
 28042                              <1> 	; 'sysret' first checks to see if process is about to be 
 28043                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
 28044                              <1> 	; If not, following happens:	 
 28045                              <1> 	; 	1) The user's stack pointer is restored.
 28046                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
 28047                              <1> 	;	   i-node has been modified. If it has, it is written out
 28048                              <1> 	;	   via 'ppoke'.
 28049                              <1> 	;	3) If the super block has been modified, it is written out
 28050                              <1> 	;	   via 'ppoke'.				
 28051                              <1> 	;	4) If the dismountable file system's super block has been
 28052                              <1> 	;	   modified, it is written out to the specified device
 28053                              <1> 	;	   via 'ppoke'.
 28054                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
 28055                              <1> 	;	   during his execution. If so, 'tswap' is called to give
 28056                              <1> 	;	   another user a chance to run.
 28057                              <1> 	;	6) 'sysret' now goes into 'sysrele'. 
 28058                              <1> 	;	    (See 'sysrele' for conclusion.)		
 28059                              <1> 	;
 28060                              <1> 	; Calling sequence:
 28061                              <1> 	;	jump table or 'br sysret'
 28062                              <1> 	; Arguments: 
 28063                              <1> 	;	-	
 28064                              <1> 	; ...............................................................
 28065                              <1> 	;	
 28066                              <1> 	; ((AX=r1 for 'iget' input))
 28067                              <1> 	;	
 28068 00009C5A 6631C0              <1> 	xor	ax, ax ; 04/05/2013
 28069                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
 28070 00009C5D FEC0                <1> 	inc	al ; 04/05/2013
 28071 00009C5F 3805[26D50000]      <1> 	cmp	[u.bsys], al ; 1
 28072                              <1> 		; tstb u.bsys / is a process about to be terminated because
 28073 00009C65 0F83E8000000        <1>         jnb     sysexit ; 04/05/2013
 28074                              <1> 		; bne sysexit / of an error? yes, go to sysexit
 28075                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
 28076                              <1> 		; mov u.sp,sp / no point stack to users stack
 28077 00009C6B FEC8                <1> 	dec 	al ; mov ax, 0
 28078                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
 28079 00009C6D E820150000          <1> 	call	iget
 28080                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
 28081                              <1> 		            ; / it is written out
 28082 00009C72 6631C0              <1> 	xor 	ax, ax ; 0
 28083 00009C75 3805[CBD40000]      <1> 	cmp	[smod], al ; 0
 28084                              <1> 		; tstb	smod / has the super block been modified
 28085 00009C7B 7614                <1> 	jna	short sysret1
 28086                              <1> 		; beq	1f / no, 1f
 28087 00009C7D A2[CBD40000]        <1> 	mov	[smod], al ; 0
 28088                              <1> 		; clrb smod / yes, clear smod
 28089 00009C82 BB[7DDD0000]        <1> 	mov	ebx, sb0 ;; 07/08//2013
 28090 00009C87 66810B0002          <1>    	or	word [ebx], 200h ;;
 28091                              <1> 	;or	word [sb0], 200h ; write bit, bit 9
 28092                              <1> 		; bis $1000,sb0 / set write bit in I/O queue for super block
 28093                              <1> 		      	      ; / output
 28094                              <1> 	; AX = 0
 28095 00009C8C E802150000          <1> 	call 	poke ; 07/08/2013
 28096                              <1> 	; call	ppoke
 28097                              <1> 	; AX = 0
 28098                              <1> 		; jsr r0,ppoke / write out modified super block to disk
 28099                              <1> sysret1: ;1:
 28100 00009C91 3805[CCD40000]      <1> 	cmp	[mmod], al ; 0
 28101                              <1> 		; tstb	mmod / has the super block for the dismountable file
 28102                              <1> 		           ; / system
 28103 00009C97 7614                <1> 	jna	short sysrel0
 28104                              <1> 		; beq 1f / been modified?  no, 1f
 28105 00009C99 A2[CCD40000]        <1> 	mov	[mmod], al ; 0	
 28106                              <1> 		; clrb	mmod / yes, clear mmod
 28107                              <1>         ;mov    ax, [mntd]
 28108                              <1>         ;;mov   al, [mdev] ; 26/04/2013
 28109 00009C9E BB[85DF0000]        <1> 	mov	ebx, sb1 ;; 07/08//2013
 28110                              <1>         ;;mov	[ebx], al
 28111                              <1> 	;mov    [sb1], al
 28112                              <1> 		; movb	mntd,sb1 / set the I/O queue
 28113 00009CA3 66810B0002          <1> 	or	word [ebx], 200h
 28114                              <1> 	;or	word [sb1], 200h ; write bit, bit 9
 28115                              <1> 		; bis $1000,sb1 / set write bit in I/O queue for detached sb
 28116 00009CA8 E8E6140000          <1> 	call	poke ; 07/08/2013
 28117                              <1> 	;call	ppoke 
 28118                              <1> 		; jsr r0,ppoke / write it out to its device
 28119                              <1>         ;xor    al, al ; 26/04/2013       
 28120                              <1> ;1:
 28121                              <1> 		; tstb uquant / is the time quantum 0?
 28122                              <1> 		; bne 1f / no, don't swap it out
 28123                              <1> 
 28124                              <1> sysrele: ; < release >
 28125                              <1> 	; 14/10/2015
 28126                              <1> 	; 01/09/2015
 28127                              <1> 	; 24/07/2015
 28128                              <1> 	; 14/05/2015
 28129                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28130                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
 28131                              <1> 	;
 28132                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
 28133                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
 28134                              <1> 	; turns off the system flag. It then checked to see if there is
 28135                              <1> 	; an interrupt from the user by calling 'isintr'. If there is, 
 28136                              <1> 	; the output gets flashed (see isintr) and interrupt action is
 28137                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
 28138                              <1> 	; the user, a rti is made.
 28139                              <1> 	;
 28140                              <1> 	; Calling sequence:
 28141                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
 28142                              <1> 	; Arguments:
 28143                              <1> 	;	-	
 28144                              <1> 	; ...............................................................
 28145                              <1> 	;	
 28146                              <1> 	; 23/02/2014 (swapret)
 28147                              <1> 	; 22/09/2013
 28148                              <1> sysrel0: ;1:
 28149 00009CAD 803D[1AD50000]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
 28150                              <1> 		; tstb uquant / is the time quantum 0?
 28151 00009CB4 7705                <1>         ja      short swapret
 28152                              <1> 		; bne 1f / no, don't swap it out
 28153                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
 28154 00009CB6 E8D9140000          <1> 	call	tswap
 28155                              <1> 		; jsr r0,tswap / yes, swap it out
 28156                              <1> ;
 28157                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
 28158                              <1> swapret: ;1:
 28159                              <1> 	; 10/09/2015
 28160                              <1> 	; 01/09/2015
 28161                              <1> 	; 14/05/2015
 28162                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
 28163                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
 28164                              <1> 	; cli
 28165                              <1> 	; 24/07/2015
 28166                              <1> 	;
 28167                              <1> 	;; 'esp' must be already equal to '[u.usp]' here ! 
 28168                              <1> 	;; mov	esp, [u.usp]
 28169                              <1> 
 28170                              <1> 	; 22/09/2013
 28171 00009CBB E8D5140000          <1> 	call	isintr
 28172                              <1> 	; 20/10/2013
 28173 00009CC0 7405                <1> 	jz	short sysrel1
 28174 00009CC2 E875000000          <1> 	call	intract
 28175                              <1> 		; jsr r0,isintr / is there an interrupt from the user
 28176                              <1> 		;     br intract / yes, output gets flushed, take interrupt
 28177                              <1> 		               ; / action
 28178                              <1> sysrel1:
 28179 00009CC7 FA                  <1> 	cli ; 14/10/2015
 28180 00009CC8 FE0D[CDD40000]      <1> 	dec	byte [sysflg]
 28181                              <1> 		; decb sysflg / turn system flag off
 28182 00009CCE A1[31D50000]        <1> 	mov     eax, [u.pgdir]
 28183 00009CD3 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
 28184                              <1> 			  ; (others are different than kernel page tables) 
 28185                              <1> 	; 10/09/2015
 28186 00009CD6 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
 28187                              <1> 		; mov (sp)+,sc / restore user registers
 28188                              <1> 		; mov (sp)+,mq
 28189                              <1> 		; mov (sp)+,ac
 28190                              <1> 		; mov (sp)+,r5
 28191                              <1> 		; mov (sp)+,r4
 28192                              <1> 		; mov (sp)+,r3
 28193                              <1> 		; mov (sp)+,r2
 28194                              <1> 	;
 28195 00009CD7 A1[D8D40000]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
 28196 00009CDC 0FA9                <1> 	pop	gs
 28197 00009CDE 0FA1                <1> 	pop	fs
 28198 00009CE0 07                  <1> 	pop	es
 28199 00009CE1 1F                  <1> 	pop	ds
 28200 00009CE2 CF                  <1> 	iretd	
 28201                              <1> 		; rti / no, return from interrupt
 28202                              <1> 
 28203                              <1> badsys:
 28204                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28205                              <1> 	; (Major Modification: 'core' dumping procedure in
 28206                              <1>         ;       original UNIX v1 and Retro UNIX 8086 v1
 28207                              <1> 	;	has been changed to print 'Invalid System Call !'
 28208                              <1> 	;	message on the user's console tty.)
 28209                              <1> 	; (EIP, EAX values will be shown on screen with error message)
 28210                              <1> 	; (EIP = Return address just after the system call -INT 30h-)
 28211                              <1> 	; (EAX = Function number)  
 28212                              <1> 	;
 28213 00009CE3 FE05[26D50000]      <1> 	inc	byte [u.bsys]
 28214                              <1> 	;
 28215 00009CE9 8B1D[D0D40000]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
 28216 00009CEF 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
 28217 00009CF1 E8F17CFFFF          <1> 	call	dwordtohex
 28218 00009CF6 8915[A3C10000]      <1> 	mov	[bsys_msg_eip], edx
 28219 00009CFC A3[A7C10000]        <1> 	mov	[bsys_msg_eip+4], eax
 28220 00009D01 A1[D8D40000]        <1> 	mov	eax, [u.r0]
 28221 00009D06 E8DC7CFFFF          <1> 	call	dwordtohex
 28222 00009D0B 8915[93C10000]      <1> 	mov	[bsys_msg_eax], edx
 28223 00009D11 A3[97C10000]        <1> 	mov	[bsys_msg_eax+4], eax
 28224 00009D16 31C0                <1> 	xor	eax, eax
 28225 00009D18 C705[F8D40000]-     <1>         mov     dword [u.base], badsys_msg ; "Invalid System call !"
 28226 00009D1E [74C10000]          <1>
 28227 00009D22 8B1D[E8D40000]      <1> 	mov	ebx, [u.fofp]
 28228 00009D28 8903                <1> 	mov	[ebx], eax
 28229                              <1> 	;mov	eax, 1 ; inode number of console tty (for user)	
 28230 00009D2A 40                  <1> 	inc	eax
 28231 00009D2B C705[FCD40000]3B00- <1> 	mov	dword [u.count], BSYS_M_SIZE
 28232 00009D33 0000                <1>
 28233                              <1> 		; writei
 28234                              <1> 		; INPUTS ->
 28235                              <1> 		;    r1 - inode number
 28236                              <1> 		;    u.count - byte count to be written
 28237                              <1> 		;    u.base - points to user buffer
 28238                              <1> 		;    u.fofp - points to word with current file offset
 28239                              <1> 		; OUTPUTS ->
 28240                              <1> 		;    u.count - cleared
 28241                              <1> 		;    u.nread - accumulates total bytes passed back	
 28242                              <1> 		;
 28243                              <1> 		; ((Modified registers: EDX, EBX, ECX, ESI, EDI, EBP)) 	
 28244 00009D35 E85C140000          <1> 	call	writei
 28245                              <1> 	;mov	eax, 1
 28246 00009D3A EB17                <1> 	jmp	sysexit
 28247                              <1> 
 28248                              <1> 		; incb u.bsys / turn on the user's bad-system flag
 28249                              <1> 		; mov $3f,u.namep / point u.namep to "core\0\0"
 28250                              <1> 		; jsr r0,namei / get the i-number for the core image file
 28251                              <1> 		; br 1f / error
 28252                              <1> 		; neg r1 / negate the i-number to open the core image file
 28253                              <1> 		       ; / for writing
 28254                              <1> 		; jsr r0,iopen / open the core image file
 28255                              <1> 		; jsr r0,itrunc / free all associated blocks
 28256                              <1> 		; br 2f
 28257                              <1> ;1:
 28258                              <1> 		; mov $17,r1 / put i-node mode (17) in r1
 28259                              <1> 		; jsr r0,maknod / make an i-node
 28260                              <1> 		; mov u.dirbuf,r1 / put i-node number in r1
 28261                              <1> ;2:
 28262                              <1> 		; mov $core,u.base / move address core to u.base
 28263                              <1> 		; mov $ecore-core,u.count / put the byte count in u.count
 28264                              <1> 		; mov $u.off,u.fofp / more user offset to u.fofp
 28265                              <1> 		; clr u.off / clear user offset
 28266                              <1> 		; jsr r0,writei / write out the core image to the user
 28267                              <1> 		; mov $user,u.base / pt. u.base to user
 28268                              <1> 		; mov $64.,u.count / u.count = 64
 28269                              <1> 		; jsr r0,writei / write out all the user parameters
 28270                              <1> 		; neg r1 / make i-number positive
 28271                              <1> 		; jsr r0,iclose / close the core image file
 28272                              <1> 		; br sysexit /
 28273                              <1> ;3:
 28274                              <1> 		; <core\0\0>
 28275                              <1> 
 28276                              <1> intract: ; / interrupt action
 28277                              <1> 	; 14/10/2015
 28278                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28279                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
 28280                              <1> 	;
 28281                              <1> 	; Retro UNIX 8086 v1 modification !
 28282                              <1> 	; (Process/task switching and quit routine by using
 28283                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
 28284                              <1> 	;
 28285                              <1> 	; input -> 'u.quit'  (also value of 'u.intr' > 0)
 28286                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
 28287                              <1> 	;		'intract' will jump to 'sysexit'.
 28288                              <1> 	;	    Intract will return to the caller 
 28289                              <1> 	;		if value of 'u.quit' <> FFFFh. 	 
 28290                              <1> 	; 14/10/2015
 28291 00009D3C FB                  <1> 	sti
 28292                              <1> 	; 07/12/2013	
 28293 00009D3D 66FF05[1ED50000]    <1> 	inc 	word [u.quit]
 28294 00009D44 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
 28295 00009D46 66FF0D[1ED50000]    <1> 	dec	word [u.quit]
 28296                              <1> 	; 16/04/2015
 28297 00009D4D C3                  <1> 	retn
 28298                              <1> intrct0:	
 28299 00009D4E 58                  <1> 	pop	eax ; call intract -> retn
 28300                              <1> 	;
 28301 00009D4F 31C0                <1> 	xor 	eax, eax
 28302 00009D51 FEC0                <1> 	inc	al  ; mov ax, 1
 28303                              <1> ;;;
 28304                              <1> 	; UNIX v1 original 'intract' routine... 
 28305                              <1> 	; / interrupt action
 28306                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
 28307                              <1> 		; bne 1f / no, 1f
 28308                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
 28309                              <1> 	; 1: / now in user area
 28310                              <1> 		; mov r1,-(sp) / save r1
 28311                              <1> 		; mov u.ttyp,r1 
 28312                              <1> 			; / pointer to tty buffer in control-to r1
 28313                              <1> 		; cmpb 6(r1),$177
 28314                              <1> 			; / is the interrupt char equal to "del"
 28315                              <1> 		; beq 1f / yes, 1f
 28316                              <1> 		; clrb 6(r1) 
 28317                              <1> 		        ; / no, clear the byte 
 28318                              <1> 			; / (must be a quit character)
 28319                              <1> 		; mov (sp)+,r1 / restore r1
 28320                              <1> 		; clr u.quit / clear quit flag
 28321                              <1> 		; bis $20,2(sp) 
 28322                              <1> 		    	; / set trace for quit (sets t bit of 
 28323                              <1> 			; / ps-trace trap)
 28324                              <1> 		; rti   ;  / return from interrupt
 28325                              <1> 	; 1: / interrupt char = del
 28326                              <1> 		; clrb 6(r1) / clear the interrupt byte 
 28327                              <1> 			   ; / in the buffer
 28328                              <1> 		; mov (sp)+,r1 / restore r1
 28329                              <1> 		; cmp u.intr,$core / should control be 
 28330                              <1> 				; / transferred to loc core?
 28331                              <1> 		; blo 1f
 28332                              <1> 		; jmp *u.intr / user to do rti yes, 
 28333                              <1> 				; / transfer to loc core
 28334                              <1> 	; 1:
 28335                              <1> 		; sys 1 / exit
 28336                              <1> 
 28337                              <1> sysexit: ; <terminate process>
 28338                              <1> 	; 01/09/2015
 28339                              <1> 	; 31/08/2015
 28340                              <1> 	; 14/05/2015
 28341                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28342                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 28343                              <1> 	;
 28344                              <1> 	; 'sysexit' terminates a process. First each file that
 28345                              <1> 	; the process has opened is closed by 'flose'. The process
 28346                              <1> 	; status is then set to unused. The 'p.pid' table is then
 28347                              <1> 	; searched to find children of the dying process. If any of
 28348                              <1> 	; children are zombies (died by not waited for), they are
 28349                              <1> 	; set free. The 'p.pid' table is then searched to find the
 28350                              <1> 	; dying process's parent. When the parent is found, it is
 28351                              <1> 	; checked to see if it is free or it is a zombie. If it is
 28352                              <1> 	; one of these, the dying process just dies. If it is waiting
 28353                              <1> 	; for a child process to die, it notified that it doesn't 
 28354                              <1> 	; have to wait anymore by setting it's status from 2 to 1
 28355                              <1> 	; (waiting to active). It is awakened and put on runq by
 28356                              <1> 	; 'putlu'. The dying process enters a zombie state in which
 28357                              <1> 	; it will never be run again but stays around until a 'wait'
 28358                              <1> 	; is completed by it's parent process. If the parent is not
 28359                              <1> 	; found, process just dies. This means 'swap' is called with
 28360                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
 28361                              <1> 	; to write out the process and 'rswap' reads the new process
 28362                              <1> 	; over the one that dies..i.e., the dying process is 
 28363                              <1> 	; overwritten and destroyed.	
 28364                              <1>  	;
 28365                              <1> 	; Calling sequence:
 28366                              <1> 	;	sysexit or conditional branch.
 28367                              <1> 	; Arguments:
 28368                              <1> 	;	-	
 28369                              <1> 	; ...............................................................
 28370                              <1> 	;	
 28371                              <1> 	; Retro UNIX 8086 v1 modification: 
 28372                              <1> 	;       System call number (=1) is in EAX register.
 28373                              <1> 	;
 28374                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 28375                              <1> 	;       registers depending of function details.
 28376                              <1> 	;
 28377                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
 28378                              <1> 	;
 28379                              <1> ; / terminate process
 28380                              <1> 	; AX = 1
 28381 00009D53 6648                <1> 	dec 	ax ; 0
 28382 00009D55 66A3[1CD50000]      <1> 	mov	[u.intr], ax ; 0
 28383                              <1> 		; clr u.intr / clear interrupt control word
 28384                              <1> 		; clr r1 / clear r1
 28385                              <1> 	; AX = 0
 28386                              <1> sysexit_1: ; 1:
 28387                              <1> 	; AX = File descriptor
 28388                              <1> 		; / r1 has file descriptor (index to u.fp list)
 28389                              <1> 		; / Search the whole list
 28390 00009D5B E8140D0000          <1> 	call	fclose
 28391                              <1> 		; jsr r0,fclose / close all files the process opened
 28392                              <1> 	;; ignore error return
 28393                              <1> 		; br .+2 / ignore error return
 28394                              <1> 	;inc	ax
 28395 00009D60 FEC0                <1> 	inc	al
 28396                              <1> 		; inc r1 / increment file descriptor
 28397                              <1> 	;cmp	ax, 10
 28398 00009D62 3C0A                <1> 	cmp	al, 10
 28399                              <1> 		; cmp r1,$10. / end of u.fp list?
 28400 00009D64 72F5                <1> 	jb	short sysexit_1
 28401                              <1> 		; blt 1b / no, go back
 28402 00009D66 0FB61D[27D50000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 28403                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
 28404 00009D6D 88A3[5BD20000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 28405                              <1> 		; clrb p.stat-1(r1) / free the process
 28406                              <1> 	;shl	bx, 1
 28407 00009D73 D0E3                <1> 	shl	bl, 1
 28408                              <1> 		; asl r1 / use r1 for index into the below tables
 28409 00009D75 668B8B[CAD10000]    <1> 	mov	cx, [ebx+p.pid-2]
 28410                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
 28411 00009D7C 668B93[EAD10000]    <1> 	mov	dx, [ebx+p.ppid-2]
 28412                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
 28413                              <1> 	; xor 	bx, bx ; 0
 28414 00009D83 30DB                <1> 	xor	bl, bl ; 0
 28415                              <1> 		; clr r2
 28416 00009D85 31F6                <1> 	xor	esi, esi ; 0
 28417                              <1> 		; clr r5 / initialize reg
 28418                              <1> sysexit_2: ; 1:
 28419                              <1> 	        ; / find children of this dying process, 
 28420                              <1> 		; / if they are zombies, free them
 28421                              <1> 	;add	bx, 2
 28422 00009D87 80C302              <1> 	add	bl, 2
 28423                              <1> 		; add $2,r2 / search parent process table 
 28424                              <1> 		          ; / for dying process's name
 28425 00009D8A 66398B[EAD10000]    <1> 	cmp	[ebx+p.ppid-2], cx
 28426                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
 28427 00009D91 7513                <1> 	jne	short sysexit_4
 28428                              <1> 		; bne 3f / no
 28429                              <1> 	;shr	bx, 1
 28430 00009D93 D0EB                <1> 	shr	bl, 1
 28431                              <1> 		; asr r2 / yes, it is a parent
 28432 00009D95 80BB[5BD20000]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB, 05/02/2014
 28433                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this 
 28434                              <1> 				     ; / dying process a zombie
 28435 00009D9C 7506                <1> 	jne	short sysexit_3 
 28436                              <1> 		; bne 2f / no
 28437 00009D9E 88A3[5BD20000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 28438                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
 28439                              <1> sysexit_3: ; 2:
 28440                              <1> 	;shr	bx, 1
 28441 00009DA4 D0E3                <1> 	shl	bl, 1
 28442                              <1> 		; asl r2
 28443                              <1> sysexit_4: ; 3:
 28444                              <1> 		; / search the process name table 
 28445                              <1> 		; / for the dying process's parent
 28446 00009DA6 663993[CAD10000]    <1> 	cmp	[ebx+p.pid-2], dx ; 17/09/2013	
 28447                              <1> 		; cmp p.pid-2(r2),r4 / found it?
 28448 00009DAD 7502                <1> 	jne	short sysexit_5
 28449                              <1> 		; bne 3f / no
 28450 00009DAF 89DE                <1> 	mov	esi, ebx
 28451                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
 28452                              <1> 		          ; / process # x2) in r5
 28453                              <1> sysexit_5: ; 3:
 28454                              <1> 	;cmp	bx, nproc + nproc
 28455 00009DB1 80FB20              <1> 	cmp	bl, nproc + nproc
 28456                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
 28457 00009DB4 72D1                <1> 	jb	short sysexit_2
 28458                              <1> 		; blt 1b / no, go back
 28459                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
 28460 00009DB6 21F6                <1> 	and	esi, esi ; r5=r1
 28461 00009DB8 7431                <1> 	jz	short sysexit_6
 28462                              <1> 		; beq 2f / no parent has been found. 
 28463                              <1> 		       ; / The process just dies
 28464 00009DBA 66D1EE              <1> 	shr	si, 1
 28465                              <1> 		; asr r1 / set up index to p.stat
 28466 00009DBD 8A86[5BD20000]      <1> 	mov	al, [esi+p.stat-1]
 28467                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
 28468 00009DC3 20C0                <1> 	and	al, al
 28469 00009DC5 7424                <1> 	jz	short sysexit_6
 28470                              <1> 		; beq 2f / if its been freed, 2f
 28471 00009DC7 3C03                <1> 	cmp	al, 3
 28472                              <1> 		; cmp r2,$3 / is parent a zombie?
 28473 00009DC9 7420                <1> 	je	short sysexit_6
 28474                              <1> 		; beq 2f / yes, 2f
 28475                              <1> 	; BH = 0
 28476 00009DCB 8A1D[27D50000]      <1> 	mov	bl, [u.uno]
 28477                              <1> 		; movb u.uno,r3 / move dying process's number to r3
 28478 00009DD1 C683[5BD20000]03    <1> 	mov	byte [ebx+p.stat-1], 3  ; SZOMB, 05/02/2014
 28479                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
 28480                              <1> 	; 05/02/2014
 28481 00009DD8 3C01                <1> 	cmp	al, 1 ; SRUN
 28482 00009DDA 740F                <1> 	je	short sysexit_6
 28483                              <1> 	;cmp	al, 2
 28484                              <1> 		; cmp r2,$2 / is the parent waiting for 
 28485                              <1> 			  ; / this child to die
 28486                              <1> 	;jne	short sysexit_6	
 28487                              <1> 		; bne 2f / yes, notify parent not to wait any more
 28488                              <1> 	; 05/02/2014
 28489                              <1> 	; p.stat = 2 --> waiting
 28490                              <1> 	; p.stat = 4 --> sleeping
 28491 00009DDC C686[5BD20000]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN ; 05/02/2014
 28492                              <1> 	;dec	byte [esi+p.stat-1]
 28493                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
 28494 00009DE3 6689F0              <1> 	mov	ax, si ; r1  (process number in AL)
 28495                              <1> 	; 
 28496                              <1> 	;mov	ebx, runq + 4
 28497                              <1> 		; mov $runq+4,r2 / on the runq
 28498 00009DE6 E8AD130000          <1> 	call	putlu
 28499                              <1> 		; jsr r0, putlu
 28500                              <1> sysexit_6: ; 2:
 28501                              <1> 	; 31/08/2015
 28502                              <1> 		; / the process dies
 28503 00009DEB C605[27D50000]00    <1> 	mov	byte [u.uno], 0
 28504                              <1> 		; clrb u.uno / put zero as the process number, 
 28505                              <1> 	           ; / so "swap" will
 28506 00009DF2 E8A2130000          <1> 	call	swap
 28507                              <1> 		; jsr r0,swap / overwrite process with another process
 28508                              <1> hlt_sys:
 28509                              <1> 	;sti ; 18/01/2014
 28510                              <1> hlts0:
 28511 00009DF7 F4                  <1> 	hlt
 28512 00009DF8 EBFD                <1> 	jmp	short hlts0
 28513                              <1> 		; 0 / and thereby kill it; halt?
 28514                              <1> 
 28515                              <1> 
 28516                              <1> syswait: ; < wait for a processs to die >
 28517                              <1> 	; 17/09/2015
 28518                              <1> 	; 02/09/2015
 28519                              <1> 	; 01/09/2015
 28520                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 28521                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
 28522                              <1> 	;
 28523                              <1> 	; 'syswait' waits for a process die. 
 28524                              <1> 	; It works in following way:
 28525                              <1> 	;    1) From the parent process number, the parent's 
 28526                              <1> 	; 	process name is found. The p.ppid table of parent
 28527                              <1> 	;	names is then searched for this process name.
 28528                              <1> 	;	If a match occurs, r2 contains child's process
 28529                              <1> 	;	number. The child status is checked to see if it is
 28530                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
 28531                              <1> 	;	If it is, the child process is freed and it's name
 28532                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
 28533                              <1> 	;	If the child is not a zombie, nothing happens and
 28534                              <1> 	;	the search goes on through the p.ppid table until
 28535                              <1> 	;	all processes are checked or a zombie is found.
 28536                              <1> 	;    2) If no zombies are found, a check is made to see if
 28537                              <1> 	;	there are any children at all. If there are none,
 28538                              <1> 	;	an error return is made. If there are, the parent's
 28539                              <1> 	;	status is set to 2 (waiting for child to die),
 28540                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
 28541                              <1> 	;	is made to wait on the next process.
 28542                              <1> 	;
 28543                              <1> 	; Calling sequence:
 28544                              <1> 	;	?
 28545                              <1> 	; Arguments:
 28546                              <1> 	;	-
 28547                              <1> 	; Inputs: - 
 28548                              <1> 	; Outputs: if zombie found, it's name put in u.r0.	
 28549                              <1> 	; ...............................................................
 28550                              <1> 	;				
 28551                              <1> 	
 28552                              <1> ; / wait for a process to die
 28553                              <1> 
 28554                              <1> syswait_0:
 28555 00009DFA 0FB61D[27D50000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 28556                              <1> 		; movb u.uno,r1 / put parents process number in r1
 28557 00009E01 D0E3                <1> 	shl	bl, 1
 28558                              <1> 	;shl	bx, 1
 28559                              <1> 		; asl r1 / x2 to get index into p.pid table
 28560 00009E03 668B83[CAD10000]    <1> 	mov	ax, [ebx+p.pid-2]
 28561                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
 28562 00009E0A 31F6                <1> 	xor	esi, esi
 28563                              <1> 		; clr r2
 28564 00009E0C 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
 28565                              <1> 	;xor 	cl, cl
 28566                              <1> 		; clr r3 / initialize reg 3
 28567                              <1> syswait_1: ; 1:
 28568 00009E0E 6683C602            <1> 	add	si, 2
 28569                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
 28570                              <1> 			  ; / search table of parent processes 
 28571                              <1> 			  ; / for this process name
 28572 00009E12 663B86[EAD10000]    <1> 	cmp	ax, [esi+p.ppid-2]
 28573                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs 
 28574                              <1> 			            ; / process number
 28575 00009E19 7535                <1> 	jne	short syswait_3
 28576                              <1> 		;bne 3f / branch if no match of parent process name
 28577                              <1> 	;inc	cx
 28578 00009E1B FEC1                <1> 	inc	cl
 28579                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
 28580 00009E1D 66D1EE              <1> 	shr	si, 1
 28581                              <1> 		; asr r2 / r2/2 to get index to p.stat table
 28582                              <1> 	; The possible states ('p.stat' values) of a process are:
 28583                              <1> 	;	0 = free or unused
 28584                              <1> 	;	1 = active
 28585                              <1> 	;	2 = waiting for a child process to die
 28586                              <1> 	;	3 = terminated, but not yet waited for (zombie).	
 28587 00009E20 80BE[5BD20000]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
 28588                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
 28589 00009E27 7524                <1> 	jne	short syswait_2
 28590                              <1> 		; bne 2f / no, skip it
 28591 00009E29 88BE[5BD20000]      <1> 	mov	[esi+p.stat-1], bh ; 0
 28592                              <1> 		; clrb p.stat-1(r2) / yes, free it
 28593 00009E2F 66D1E6              <1> 	shl	si, 1
 28594                              <1> 		; asl r2 / r2x2 to get index into p.pid table
 28595 00009E32 0FB786[CAD10000]    <1> 	movzx	eax, word [esi+p.pid-2]
 28596 00009E39 A3[D8D40000]        <1> 	mov	[u.r0], eax
 28597                              <1> 		; mov p.pid-2(r2),*u.r0 
 28598                              <1> 			      ; / put childs process name in (u.r0)
 28599                              <1> 	;
 28600                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
 28601                              <1> 	;
 28602                              <1> 	; Parent process ID -p.ppid- field (of the child process)
 28603                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
 28604                              <1> 	; system call loop from the application/program if it calls
 28605                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
 28606                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
 28607                              <1> 	;
 28608                              <1> 	; Note: syswait will return with error if there is not a
 28609                              <1> 	;       zombie or running process to wait.	
 28610                              <1> 	;
 28611 00009E3E 6629C0              <1> 	sub	ax, ax
 28612 00009E41 668986[EAD10000]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
 28613 00009E48 E910FEFFFF          <1> 	jmp	sysret0 ; ax = 0
 28614                              <1> 	;
 28615                              <1> 	;jmp	sysret
 28616                              <1> 		; br sysret1 / return cause child is dead
 28617                              <1> syswait_2: ; 2:
 28618 00009E4D 66D1E6              <1> 	shl	si, 1
 28619                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
 28620                              <1> syswait_3: ; 3:
 28621 00009E50 6683FE20            <1> 	cmp	si, nproc+nproc
 28622                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
 28623 00009E54 72B8                <1> 	jb	short syswait_1
 28624                              <1> 		; blt 1b / no, continue search
 28625                              <1> 	;and	cx, cx
 28626 00009E56 20C9                <1> 	and	cl, cl
 28627                              <1> 		; tst r3 / one gets here if there are no children 
 28628                              <1> 		       ; / or children that are still active
 28629                              <1> 	; 30/10/2013
 28630 00009E58 750B                <1> 	jnz	short syswait_4
 28631                              <1> 	;jz	error
 28632                              <1> 		; beq error1 / there are no children, error
 28633 00009E5A 890D[D8D40000]      <1> 	mov	[u.r0], ecx ; 0
 28634 00009E60 E9D5FDFFFF          <1> 	jmp	error
 28635                              <1> syswait_4:
 28636 00009E65 8A1D[27D50000]      <1> 	mov	bl, [u.uno]
 28637                              <1> 		; movb u.uno,r1 / there are children so put 
 28638                              <1> 			      ; / parent process number in r1
 28639 00009E6B FE83[5BD20000]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
 28640                              <1> 		; incb p.stat-1(r1) / it is waiting for 
 28641                              <1> 				  ; / other children to die
 28642                              <1> 	; 04/11/2013
 28643 00009E71 E823130000          <1> 	call	swap
 28644                              <1> 		; jsr r0,swap / swap it out, because it's waiting
 28645 00009E76 EB82                <1> 	jmp	syswait_0
 28646                              <1> 		; br syswait / wait on next process
 28647                              <1> 
 28648                              <1> sysfork: ; < create a new process >
 28649                              <1> 	; 18/09/2015
 28650                              <1> 	; 04/09/2015
 28651                              <1> 	; 02/09/2015
 28652                              <1> 	; 01/09/2015
 28653                              <1> 	; 28/08/2015
 28654                              <1> 	; 14/05/2015
 28655                              <1> 	; 10/05/2015
 28656                              <1> 	; 09/05/2015
 28657                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
 28658                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 28659                              <1> 	;
 28660                              <1> 	; 'sysfork' creates a new process. This process is referred
 28661                              <1> 	; to as the child process. This new process core image is
 28662                              <1> 	; a copy of that of the caller of 'sysfork'. The only
 28663                              <1> 	; distinction is the return location and the fact that (u.r0)
 28664                              <1> 	; in the old process (parent) contains the process id (p.pid)
 28665                              <1> 	; of the new process (child). This id is used by 'syswait'.
 28666                              <1> 	; 'sysfork' works in the following manner: 	
 28667                              <1> 	;    1) The process status table (p.stat) is searched to find
 28668                              <1> 	;	a process number that is unused. If none are found
 28669                              <1> 	;	an error occurs.
 28670                              <1> 	;    2) when one is found, it becomes the child process number
 28671                              <1> 	;	and it's status (p.stat) is set to active.
 28672                              <1> 	;    3) If the parent had a control tty, the interrupt 
 28673                              <1> 	;	character in that tty buffer is cleared.
 28674                              <1> 	;    4) The child process is put on the lowest priority run 
 28675                              <1> 	;	queue via 'putlu'.
 28676                              <1> 	;    5) A new process name is gotten from 'mpid' (actually 
 28677                              <1> 	;	it is a unique number) and is put in the child's unique
 28678                              <1> 	;	identifier; process id (p.pid).
 28679                              <1> 	;    6) The process name of the parent is then obtained and
 28680                              <1> 	;	placed in the unique identifier of the parent process
 28681                              <1> 	;	name is then put in 'u.r0'.	
 28682                              <1> 	;    7) The child process is then written out on disk by
 28683                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
 28684                              <1> 	;	and the child is born. (The child process is written 
 28685                              <1> 	;	out on disk/drum with 'u.uno' being the child process
 28686                              <1> 	;	number.)
 28687                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
 28688                              <1> 	;    9) The child process name is put in 'u.r0'.
 28689                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
 28690                              <1> 	;	create the return address for the parent process.
 28691                              <1> 	;   11) The 'u.fp' list as then searched to see what files
 28692                              <1> 	;	the parent has opened. For each file the parent has
 28693                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
 28694                              <1> 	;	to indicate that the child process also has opened
 28695                              <1> 	;	the file. A branch to 'sysret' is then made.	 			 				
 28696                              <1> 	;
 28697                              <1> 	; Calling sequence:
 28698                              <1> 	;	from shell ?
 28699                              <1> 	; Arguments:
 28700                              <1> 	;	-
 28701                              <1> 	; Inputs: -
 28702                              <1> 	; Outputs: *u.r0 - child process name
 28703                              <1> 	; ...............................................................
 28704                              <1> 	;	
 28705                              <1> 	; Retro UNIX 8086 v1 modification: 
 28706                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
 28707                              <1> 	;	= process id of child a parent process returns
 28708                              <1> 	;	= process id of parent when a child process returns
 28709                              <1> 	;
 28710                              <1> 	;       In original UNIX v1, sysfork is called and returns as
 28711                              <1> 	;	in following manner: (with an example: c library, fork)
 28712                              <1> 	;	
 28713                              <1> 	;	1:
 28714                              <1> 	;		sys	fork
 28715                              <1> 	;			br 1f  / child process returns here
 28716                              <1> 	;		bes	2f     / parent process returns here
 28717                              <1> 	;		/ pid of new process in r0
 28718                              <1> 	;		rts	pc
 28719                              <1> 	;	2: / parent process condionally branches here
 28720                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
 28721                              <1> 	;		rts	pc
 28722                              <1> 	;
 28723                              <1> 	;	1: / child process brances here
 28724                              <1> 	;		clr	r0   / pid = 0 in child process
 28725                              <1> 	;		rts	pc
 28726                              <1> 	;
 28727                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
 28728                              <1> 	;		// pid = fork();
 28729                              <1> 	;		//
 28730                              <1> 	;		// pid == 0 in child process; 
 28731                              <1> 	;		// pid == -1 means error return
 28732                              <1> 	;		// in child, 
 28733                              <1> 	;		//	parents id is in par_uid if needed
 28734                              <1> 	;		
 28735                              <1> 	;		_fork:
 28736                              <1> 	;			mov	$.fork,eax
 28737                              <1> 	;			int	$0x30
 28738                              <1> 	;			jmp	1f
 28739                              <1> 	;			jnc	2f
 28740                              <1> 	;			jmp	cerror
 28741                              <1> 	;		1:
 28742                              <1> 	;			mov	eax,_par_uid
 28743                              <1> 	;			xor	eax,eax
 28744                              <1> 	;		2:
 28745                              <1> 	;			ret
 28746                              <1> 	;
 28747                              <1> 	;	In Retro UNIX 8086 v1,
 28748                              <1> 	;	'sysfork' returns in following manner:
 28749                              <1> 	;	
 28750                              <1> 	;		mov	ax, sys_fork
 28751                              <1> 	;		mov	bx, offset @f ; routine for child
 28752                              <1> 	;		int	20h
 28753                              <1> 	;		jc	error
 28754                              <1> 	;		
 28755                              <1> 	;	; Routine for parent process here (just after 'jc')
 28756                              <1> 	;		mov	word ptr [pid_of_child], ax
 28757                              <1> 	;		jmp	next_routine_for_parent	
 28758                              <1> 	;
 28759                              <1> 	;	@@: ; routine for child process here				
 28760                              <1> 	;		....	
 28761                              <1> 	;	NOTE: 'sysfork' returns to specified offset
 28762                              <1> 	;	       for child process by using BX input.
 28763                              <1> 	;	      (at first, parent process will return then 
 28764                              <1> 	;	      child process will return -after swapped in-
 28765                              <1> 	;	      'syswait' is needed in parent process
 28766                              <1> 	;	      if return from child process will be waited for.)
 28767                              <1> 	;	  				
 28768                              <1> 	
 28769                              <1> ; / create a new process
 28770                              <1> 	; EBX = return address for child process 
 28771                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
 28772 00009E78 31F6                <1> 	xor 	esi, esi
 28773                              <1> 		; clr r1
 28774                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
 28775 00009E7A 46                  <1> 	inc	esi
 28776                              <1> 		; inc r1
 28777 00009E7B 80BE[5BD20000]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
 28778                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
 28779 00009E82 760B                <1> 	jna	short sysfork_2	
 28780                              <1> 		; beq 1f / it's unused so branch
 28781 00009E84 6683FE10            <1> 	cmp	si, nproc
 28782                              <1> 		; cmp r1,$nproc / all processes checked
 28783 00009E88 72F0                <1> 	jb	short sysfork_1
 28784                              <1> 		; blt 1b / no, branch back
 28785                              <1> 	;
 28786                              <1> 	; Retro UNIX 8086 v1. modification:
 28787                              <1> 	;	Parent process returns from 'sysfork' to address 
 28788                              <1> 	;	which is just after 'sysfork' system call in parent
 28789                              <1> 	;	process. Child process returns to address which is put
 28790                              <1> 	;	in BX register by parent process for 'sysfork'. 
 28791                              <1> 	;
 28792                              <1> 		;add $2,18.(sp) / add 2 to pc when trap occured, points
 28793                              <1> 		             ; / to old process return
 28794                              <1> 		; br error1 / no room for a new process
 28795 00009E8A E9ABFDFFFF          <1> 	jmp	error
 28796                              <1> sysfork_2: ; 1:
 28797 00009E8F E87392FFFF          <1> 	call	allocate_page
 28798 00009E94 0F82A0FDFFFF        <1> 	jc	error
 28799 00009E9A 50                  <1> 	push	eax   ; UPAGE (user structure page) address
 28800                              <1> 	; Retro UNIX 386 v1 modification!
 28801 00009E9B E87094FFFF          <1> 	call	duplicate_page_dir
 28802                              <1> 		; EAX = New page directory 
 28803 00009EA0 730B                <1> 	jnc	short sysfork_3
 28804 00009EA2 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 28805 00009EA3 E83794FFFF          <1> 	call 	deallocate_page
 28806 00009EA8 E98DFDFFFF          <1> 	jmp	error
 28807                              <1> sysfork_3:
 28808                              <1> 	; Retro UNIX 386 v1 modification !
 28809 00009EAD 56                  <1> 	push	esi
 28810 00009EAE E8E7120000          <1> 	call	wswap ; save current user (u) structure, user registers
 28811                              <1> 		      ; and interrupt return components (for IRET)
 28812 00009EB3 8705[31D50000]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
 28813 00009EB9 A3[35D50000]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
 28814 00009EBE 5E                  <1> 	pop	esi
 28815 00009EBF 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 28816                              <1> 		; [u.usp] = esp
 28817 00009EC0 89F7                <1> 	mov	edi, esi
 28818 00009EC2 66C1E702            <1> 	shl	di, 2
 28819 00009EC6 8987[68D20000]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
 28820 00009ECC A3[28D50000]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
 28821                              <1> 	; 28/08/2015
 28822 00009ED1 0FB605[27D50000]    <1> 	movzx	eax, byte [u.uno] ; parent process number
 28823                              <1> 		; movb u.uno,-(sp) / save parent process number
 28824 00009ED8 89C7                <1> 	mov	edi, eax
 28825 00009EDA 50                  <1>         push	eax ; ** 
 28826 00009EDB 8A87[2BD20000]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
 28827                              <1> 	; 18/09/2015
 28828                              <1> 	;mov     [esi+p.ttyc-1], al ; set child's console tty
 28829                              <1> 	;mov     [esi+p.waitc-1], ah ; 0 ; reset child's wait channel
 28830 00009EE1 668986[2BD20000]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
 28831                              <1> 				   ; ah - reset child's wait channel	
 28832 00009EE8 89F0                <1> 	mov	eax, esi
 28833 00009EEA A2[27D50000]        <1> 	mov	[u.uno], al ; child process number
 28834                              <1> 		;movb r1,u.uno / set child process number to r1
 28835 00009EEF FE86[5BD20000]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
 28836                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
 28837                              <1> 				; / process to active status
 28838                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
 28839                              <1> 			      ; / control tty buffer in r2
 28840                              <1>                 ; beq 2f / branch, if no such tty assigned
 28841                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
 28842                              <1> 	; 2:
 28843 00009EF5 53                  <1> 	push	ebx  ; * return address for the child process
 28844                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 28845                              <1> 	; (Retro UNIX 8086 v1 modification!)
 28846                              <1> 		; mov $runq+4,r2
 28847 00009EF6 E89D120000          <1> 	call	putlu 
 28848                              <1>  		; jsr r0,putlu / put child process on lowest priority 
 28849                              <1> 			   ; / run queue
 28850 00009EFB 66D1E6              <1> 	shl	si, 1
 28851                              <1> 		; asl r1 / multiply r1 by 2 to get index 
 28852                              <1> 		       ; / into p.pid table
 28853 00009EFE 66FF05[C4D40000]    <1> 	inc	word [mpid]
 28854                              <1> 		; inc mpid / increment m.pid; get a new process name
 28855 00009F05 66A1[C4D40000]      <1> 	mov	ax, [mpid]
 28856 00009F0B 668986[CAD10000]    <1> 	mov	[esi+p.pid-2], ax
 28857                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
 28858                              <1> 				    ; / in child process' name slot
 28859 00009F12 5A                  <1> 	pop	edx  ; * return address for the child process
 28860                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 28861 00009F13 5B                  <1>   	pop	ebx  ; **
 28862                              <1> 	;mov	ebx, [esp] ; ** parent process number
 28863                              <1> 		; movb (sp),r2 / put parent process number in r2
 28864 00009F14 66D1E3              <1> 	shl 	bx, 1
 28865                              <1> 		;asl r2 / multiply by 2 to get index into below tables
 28866                              <1> 	;movzx eax, word [ebx+p.pid-2]
 28867 00009F17 668B83[CAD10000]    <1> 	mov	ax, [ebx+p.pid-2]
 28868                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
 28869                              <1> 				   ; / process
 28870 00009F1E 668986[EAD10000]    <1> 	mov	[esi+p.ppid-2], ax
 28871                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name 
 28872                              <1> 			  ; / in parent process slot for child
 28873 00009F25 A3[D8D40000]        <1> 	mov	[u.r0], eax	
 28874                              <1> 		; mov r2,*u.r0 / put parent process name on stack 
 28875                              <1> 			     ; / at location where r0 was saved
 28876 00009F2A 8B2D[D0D40000]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
 28877 00009F30 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
 28878                              <1> 			   ; * return address for the child process
 28879                              <1> 		; mov $sysret1,-(sp) /
 28880                              <1> 		; mov sp,u.usp / contents of sp at the time when 
 28881                              <1> 			      ; / user is swapped out
 28882                              <1> 		; mov $sstack,sp / point sp to swapping stack space
 28883                              <1> 	; 04/09/2015 - 01/09/2015
 28884                              <1> 	; [u.usp] = esp
 28885 00009F33 68[5A9C0000]        <1> 	push	sysret ; ***
 28886 00009F38 8925[D4D40000]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
 28887                              <1> 			     ; (for child process)	
 28888 00009F3E 31C0                <1> 	xor 	eax, eax
 28889 00009F40 66A3[08D50000]      <1> 	mov 	[u.ttyp], ax ; 0
 28890                              <1> 	;
 28891 00009F46 E84F120000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
 28892                              <1> 		;jsr r0,wswap / put child process out on drum
 28893                              <1> 		;jsr r0,unpack / unpack user stack
 28894                              <1> 		;mov u.usp,sp / restore user stack pointer
 28895                              <1> 		; tst (sp)+ / bump stack pointer
 28896                              <1> 	; Retro UNIX 386 v1 modification !
 28897 00009F4B 58                  <1> 	pop	eax ; ***
 28898 00009F4C 66D1E3              <1> 	shl	bx, 1
 28899 00009F4F 8B83[68D20000]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
 28900 00009F55 E841120000          <1> 	call	rswap ; restore parent process 'u' structure, 
 28901                              <1> 		      ; registers and return address (for IRET)
 28902                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
 28903 00009F5A 0FB705[C4D40000]    <1>         movzx   eax, word [mpid]
 28904 00009F61 A3[D8D40000]        <1> 	mov	[u.r0], eax
 28905                              <1> 		; mov mpid,*u.r0 / put child process name on stack 
 28906                              <1> 			       ; / where r0 was saved
 28907                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
 28908                              <1> 			          ; / process return
 28909                              <1> 	;xor	ebx, ebx
 28910 00009F66 31F6                <1> 	xor     esi, esi
 28911                              <1> 		;clr r1
 28912                              <1> sysfork_4: ; 1: / search u.fp list to find the files 
 28913                              <1> 	      ; / opened by the parent process
 28914                              <1> 	; 01/09/2015
 28915                              <1> 	;xor	bh, bh
 28916                              <1> 	;mov 	bl, [esi+u.fp]
 28917 00009F68 8A86[DED40000]      <1> 	mov 	al, [esi+u.fp]
 28918                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
 28919                              <1>         ;or      bl, bl
 28920 00009F6E 08C0                <1> 	or	al, al
 28921 00009F70 740D                <1> 	jz	short sysfork_5	
 28922                              <1> 		; beq 2f / file has not been opened by parent, 
 28923                              <1> 		       ; / so branch
 28924 00009F72 B40A                <1> 	mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
 28925 00009F74 F6E4                <1> 	mul	ah
 28926                              <1> 	;movzx	ebx, ax
 28927 00009F76 6689C3              <1> 	mov	bx, ax
 28928                              <1> 	;shl     bx, 3
 28929                              <1> 		; asl r2 / multiply by 8
 28930                              <1>        		; asl r2 / to get index into fsp table
 28931                              <1>        		; asl r2
 28932 00009F79 FE83[AAD20000]      <1>   	inc     byte [ebx+fsp-2]
 28933                              <1> 		; incb fsp-2(r2) / increment number of processes
 28934                              <1> 			     ; / using file, because child will now be
 28935                              <1> 			     ; / using this file
 28936                              <1> sysfork_5: ; 2:
 28937 00009F7F 46                  <1>         inc     esi
 28938                              <1> 		; inc r1 / get next open file
 28939 00009F80 6683FE0A            <1>         cmp     si, 10
 28940                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
 28941                              <1> 			  ; / can be opened
 28942 00009F84 72E2                <1> 	jb	short sysfork_4	
 28943                              <1> 		; blt 1b / check next entry
 28944 00009F86 E9CFFCFFFF          <1> 	jmp	sysret
 28945                              <1> 		; br sysret1
 28946                              <1> 
 28947                              <1> sysread: ; < read from file >
 28948                              <1> 	; 13/05/2015
 28949                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 28950                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 28951                              <1> 	;
 28952                              <1> 	; 'sysread' is given a buffer to read into and the number of
 28953                              <1> 	; characters to be read. If finds the file from the file
 28954                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
 28955                              <1> 	; is returned from a successful open call (sysopen).
 28956                              <1> 	; The i-number of file is obtained via 'rw1' and the data
 28957                              <1> 	; is read into core via 'readi'.
 28958                              <1> 	;
 28959                              <1> 	; Calling sequence:
 28960                              <1> 	;	sysread; buffer; nchars
 28961                              <1> 	; Arguments:
 28962                              <1> 	;	buffer - location of contiguous bytes where 
 28963                              <1> 	;		 input will be placed.
 28964                              <1> 	;	nchars - number of bytes or characters to be read.
 28965                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 28966                              <1> 	; Outputs: *u.r0 - number of bytes read.	
 28967                              <1> 	; ...............................................................
 28968                              <1> 	;				
 28969                              <1> 	; Retro UNIX 8086 v1 modification: 
 28970                              <1> 	;       'sysread' system call has three arguments; so,
 28971                              <1> 	;	* 1st argument, file descriptor is in BX register
 28972                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 28973                              <1> 	;	* 3rd argument, number of bytes is in DX register
 28974                              <1> 	;
 28975                              <1> 	;	AX register (will be restored via 'u.r0') will return
 28976                              <1> 	;	to the user with number of bytes read. 
 28977                              <1> 	;
 28978 00009F8B E83D000000          <1> 	call	rw1
 28979 00009F90 0F82A4FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 28980                              <1> 		; jsr r0,rw1 / get i-number of file to be read into r1
 28981 00009F96 F6C480              <1> 	test	ah, 80h
 28982                              <1> 		; tst r1 / negative i-number?
 28983 00009F99 0F859BFCFFFF        <1> 	jnz	error
 28984                              <1> 		; ble error1 / yes, error 1 to read
 28985                              <1> 			   ; / it should be positive
 28986 00009F9F E8F3110000          <1> 	call	readi
 28987                              <1> 		; jsr r0,readi / read data into core
 28988 00009FA4 EB18                <1> 	jmp	short rw0
 28989                              <1> 		; br 1f
 28990                              <1> syswrite: ; < write to file >
 28991                              <1> 	; 13/05/2015
 28992                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 28993                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 28994                              <1> 	;
 28995                              <1> 	; 'syswrite' is given a buffer to write onto an output file
 28996                              <1> 	; and the number of characters to write. If finds the file
 28997                              <1> 	; from the file descriptor located in *u.r0 (r0). This file 
 28998                              <1> 	; descriptor is returned from a successful open or create call
 28999                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
 29000                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
 29001                              <1> 	;
 29002                              <1> 	; Calling sequence:
 29003                              <1> 	;	syswrite; buffer; nchars
 29004                              <1> 	; Arguments:
 29005                              <1> 	;	buffer - location of contiguous bytes to be writtten.
 29006                              <1> 	;	nchars - number of characters to be written.
 29007                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 29008                              <1> 	; Outputs: *u.r0 - number of bytes written.	
 29009                              <1> 	; ...............................................................
 29010                              <1> 	;				
 29011                              <1> 	; Retro UNIX 8086 v1 modification: 
 29012                              <1> 	;       'syswrite' system call has three arguments; so,
 29013                              <1> 	;	* 1st argument, file descriptor is in BX register
 29014                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 29015                              <1> 	;	* 3rd argument, number of bytes is in DX register
 29016                              <1> 	;
 29017                              <1> 	;	AX register (will be restored via 'u.r0') will return
 29018                              <1> 	;	to the user with number of bytes written. 
 29019                              <1> 	;
 29020 00009FA6 E822000000          <1> 	call	rw1
 29021 00009FAB 0F8289FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 29022                              <1> 		; jsr r0,rw1 / get i-number in r1 of file to write
 29023 00009FB1 F6C480              <1>         test	ah, 80h
 29024                              <1> 		; tst r1 / positive i-number ?
 29025 00009FB4 744E                <1>         jz	short rw3 ; 13/05/2015
 29026                              <1> 	;jz	error
 29027                              <1> 		; bge error1 / yes, error 1 
 29028                              <1> 			   ; / negative i-number means write
 29029 00009FB6 66F7D8              <1>         neg	ax
 29030                              <1> 		; neg r1 / make it positive
 29031 00009FB9 E8D8110000          <1> 	call	writei
 29032                              <1>         	; jsr r0,writei / write data
 29033                              <1> rw0: ; 1:
 29034 00009FBE A1[00D50000]        <1>         mov	eax, [u.nread]
 29035 00009FC3 A3[D8D40000]        <1> 	mov	[u.r0], eax
 29036                              <1> 		; mov u.nread,*u.r0 / put no. of bytes transferred
 29037                              <1> 				  ; / into (u.r0)
 29038 00009FC8 E98DFCFFFF          <1> 	jmp	sysret
 29039                              <1>         	; br sysret1
 29040                              <1> rw1:	
 29041                              <1> 	; 14/05/2015
 29042                              <1> 	; 13/05/2015
 29043                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 29044                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
 29045                              <1> 	; System call registers: bx, cx, dx (through 'sysenter')
 29046                              <1> 	;
 29047                              <1> 	;mov	[u.base], ecx 	; buffer address/offset 
 29048                              <1> 				;(in the user's virtual memory space)
 29049                              <1> 	;mov	[u.count], edx 
 29050                              <1> 		; jsr r0,arg; u.base / get buffer pointer
 29051                              <1>         	; jsr r0,arg; u.count / get no. of characters
 29052                              <1> 	;;mov	eax, ebx ; file descriptor
 29053                              <1> 		; mov *u.r0,r1 / put file descriptor 
 29054                              <1> 		             ; / (index to u.fp table) in r1
 29055                              <1> 	; 13/05/2015
 29056 00009FCD C705[D8D40000]0000- <1> 	mov	dword [u.r0], 0 ; r/w transfer count = 0 (reset)
 29057 00009FD5 0000                <1>
 29058                              <1> 	;
 29059                              <1> 	;; call	getf
 29060                              <1>         ; eBX = File descriptor
 29061 00009FD7 E8E30A0000          <1> 	call	getf1 ; calling point in 'getf' from 'rw1'
 29062                              <1> 		; jsr r0,getf / get i-number of the file in r1
 29063                              <1> 	; AX = I-number of the file ; negative i-number means write
 29064                              <1> 	; 13/05/2015
 29065 00009FDC 6683F801            <1> 	cmp 	ax, 1
 29066 00009FE0 7217                <1> 	jb	short rw2
 29067                              <1> 	;
 29068 00009FE2 890D[F8D40000]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
 29069                              <1> 				;(in the user's virtual memory space)
 29070 00009FE8 8915[FCD40000]      <1> 	mov	[u.count], edx 
 29071                              <1> 	; 14/05/2015
 29072 00009FEE C705[2DD50000]0000- <1>         mov     dword [u.error], 0 ; reset the last error code
 29073 00009FF6 0000                <1>
 29074 00009FF8 C3                  <1> 	retn
 29075                              <1>         	; rts r0
 29076                              <1> rw2:
 29077                              <1> 	; 13/05/2015
 29078 00009FF9 C705[2DD50000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 29079 0000A001 0000                <1>
 29080 0000A003 C3                  <1> 	retn
 29081                              <1> rw3: 
 29082                              <1> 	; 13/05/2015
 29083 0000A004 C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 29084 0000A00C 0000                <1>
 29085 0000A00E F9                  <1> 	stc
 29086 0000A00F C3                  <1> 	retn
 29087                              <1> 
 29088                              <1> sysopen: ;<open file>
 29089                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29090                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
 29091                              <1> 	;
 29092                              <1> 	; 'sysopen' opens a file in following manner:
 29093                              <1> 	;    1) The second argument in a sysopen says whether to
 29094                              <1> 	;	open the file ro read (0) or write (>0).
 29095                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
 29096                              <1> 	;    3) The file is opened by 'iopen'.
 29097                              <1> 	;    4) Next housekeeping is performed on the fsp table
 29098                              <1> 	;	and the user's open file list - u.fp.
 29099                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
 29100                              <1> 	;	b) An entry for the file is created in the fsp table.
 29101                              <1> 	;	c) The number of this entry is put on u.fp list.
 29102                              <1> 	;	d) The file descriptor index to u.fp list is pointed
 29103                              <1> 	;	   to by u.r0.
 29104                              <1> 	;
 29105                              <1> 	; Calling sequence:
 29106                              <1> 	;	sysopen; name; mode
 29107                              <1> 	; Arguments:
 29108                              <1> 	;	name - file name or path name
 29109                              <1> 	;	mode - 0 to open for reading
 29110                              <1> 	;	       1 to open for writing
 29111                              <1> 	; Inputs: (arguments)
 29112                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
 29113                              <1> 	;		  is put into r0's location on the stack.	
 29114                              <1> 	; ...............................................................
 29115                              <1> 	;				
 29116                              <1> 	; Retro UNIX 8086 v1 modification: 
 29117                              <1> 	;       'sysopen' system call has two arguments; so,
 29118                              <1> 	;	* 1st argument, name is pointed to by BX register
 29119                              <1> 	;	* 2nd argument, mode is in CX register
 29120                              <1> 	;
 29121                              <1> 	;	AX register (will be restored via 'u.r0') will return
 29122                              <1> 	;	to the user with the file descriptor/number 
 29123                              <1> 	;	(index to u.fp list).
 29124                              <1> 	;
 29125                              <1> 	;call	arg2
 29126                              <1> 	; * name - 'u.namep' points to address of file/path name
 29127                              <1> 	;          in the user's program segment ('u.segmnt')
 29128                              <1> 	;          with offset in BX register (as sysopen argument 1).
 29129                              <1> 	; * mode - sysopen argument 2 is in CX register 
 29130                              <1> 	;          which is on top of stack.
 29131                              <1> 	;
 29132                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
 29133                              <1> 	;
 29134                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
 29135                              <1> 
 29136 0000A010 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 29137 0000A016 6651                <1> 	push	cx
 29138 0000A018 E8D90A0000          <1> 	call	namei
 29139                              <1> 		; jsr r0,namei / i-number of file in r1
 29140                              <1>      	;and	ax, ax
 29141                              <1> 	;jz	error ; File not found
 29142 0000A01D 723B                <1> 	jc	short fnotfound ; 14/05/2015
 29143                              <1> 	;jc	error ; 27/05/2013
 29144                              <1> 		; br  error2 / file not found
 29145 0000A01F 665A                <1>    	pop	dx ; mode
 29146 0000A021 6652                <1> 	push	dx
 29147                              <1> 	;or	dx, dx
 29148 0000A023 08D2                <1> 	or	dl, dl
 29149                              <1> 		; tst (sp) / is mode = 0 (2nd arg of call; 
 29150                              <1> 		         ; / 0 means, open for read)
 29151 0000A025 7403                <1> 	jz	short sysopen_0
 29152                              <1> 		; beq 1f / yes, leave i-number positive
 29153                              <1> syscreat_0: ; 27/12/2015
 29154 0000A027 66F7D8              <1> 	neg	ax
 29155                              <1>         	; neg r1 / open for writing so make i-number negative
 29156                              <1> sysopen_0: ;1:
 29157 0000A02A E86D110000          <1> 	call	iopen
 29158                              <1> 		;jsr r0,iopen / open file whose i-number is in r1
 29159 0000A02F 665A                <1> 	pop	dx
 29160                              <1> 	;and	dx, dx
 29161 0000A031 20D2                <1> 	and	dl, dl
 29162                              <1>         	; tst (sp)+ / pop the stack and test the mode
 29163 0000A033 7403                <1> 	jz	short sysopen_2
 29164                              <1>         	; beq op1 / is open for read op1
 29165                              <1> sysopen_1: ;op0:
 29166 0000A035 66F7D8              <1> 	neg	ax
 29167                              <1>         	; neg r1 
 29168                              <1> 		     ;/ make i-number positive if open for writing [???]
 29169                              <1> 	;; NOTE: iopen always make i-number positive.
 29170                              <1> 	;; Here i-number becomes negative again. [22/05/2013]
 29171                              <1> sysopen_2: ;op1:
 29172 0000A038 31F6                <1>         xor     esi, esi
 29173                              <1>         	; clr r2 / clear registers
 29174 0000A03A 31DB                <1>         xor     ebx, ebx
 29175                              <1> 		; clr r3
 29176                              <1> sysopen_3: ;1: / scan the list of entries in fsp table
 29177 0000A03C 389E[DED40000]      <1>         cmp     [esi+u.fp], bl ; 0
 29178                              <1> 		; tstb u.fp(r2) / test the entry in the u.fp list
 29179 0000A042 7625                <1>         jna      short sysopen_4
 29180                              <1> 		; beq 1f / if byte in list is 0 branch
 29181 0000A044 46                  <1>         inc     esi
 29182                              <1> 		; inc r2 / bump r2 so next byte can be checked
 29183 0000A045 6683FE0A            <1>         cmp     si, 10
 29184                              <1> 		; cmp r2,$10. / reached end of list?
 29185 0000A049 72F1                <1> 	jb	short sysopen_3
 29186                              <1> 		; blt 1b / no, go back
 29187                              <1> toomanyf:
 29188                              <1> 	; 14/05/2015
 29189 0000A04B C705[2DD50000]0D00- <1> 	mov	dword [u.error], ERR_TOO_MANY_FILES ; too many open files !
 29190 0000A053 0000                <1>
 29191 0000A055 E9E0FBFFFF          <1> 	jmp	error
 29192                              <1>         	; br error2 / yes, error (no files open)
 29193                              <1> fnotfound: 
 29194                              <1> 	; 14/05/2015
 29195 0000A05A C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; file not found !
 29196 0000A062 0000                <1>
 29197 0000A064 E9D1FBFFFF          <1> 	jmp	error
 29198                              <1> 
 29199                              <1> sysopen_4: ; 1:
 29200 0000A069 6683BB[ACD20000]00  <1>         cmp     word [ebx+fsp], 0
 29201                              <1> 		; tst fsp(r3) / scan fsp entries
 29202 0000A071 7610                <1>         jna     short sysopen_5
 29203                              <1> 		; beq 1f / if 0 branch
 29204                              <1> 	; 14/05/2015 - Retro UNIX 386 v1 modification !
 29205 0000A073 6683C30A            <1>         add     bx, 10 ; fsp structure size = 10 bytes/entry
 29206                              <1> 		; add $8.,r3 / add 8 to r3 
 29207                              <1> 			; / to bump it to next entry mfsp table
 29208 0000A077 6681FBF401          <1>         cmp     bx, nfiles*10
 29209                              <1> 		; cmp r3,$[nfiles*8.] / done scanning
 29210 0000A07C 72EB                <1> 	jb	short sysopen_4
 29211                              <1>        		; blt 1b / no, back
 29212 0000A07E E9B7FBFFFF          <1> 	jmp	error
 29213                              <1>         	; br error2 / yes, error
 29214                              <1> sysopen_5: ; 1: / r2 has index to u.fp list; r3, has index to fsp table
 29215 0000A083 668983[ACD20000]    <1>         mov     [ebx+fsp], ax
 29216                              <1> 		; mov r1,fsp(r3) / put i-number of open file 
 29217                              <1> 			; / into next available entry in fsp table,
 29218 0000A08A 668B3D[BCD40000]    <1> 	mov	di, [cdev] ; word ? byte ?
 29219 0000A091 6689BB[AED20000]    <1>         mov     [ebx+fsp+2], di ; device number
 29220                              <1> 		; mov cdev,fsp+2(r3) / put # of device in next word
 29221 0000A098 31FF                <1>         xor	edi, edi
 29222 0000A09A 89BB[B0D20000]      <1>         mov     [ebx+fsp+4], edi ; offset pointer (0)
 29223                              <1> 		; clr fsp+4(r3)
 29224 0000A0A0 6689BB[B4D20000]    <1>         mov     [ebx+fsp+8], di ; open count (0), deleted flag (0)
 29225                              <1>        		; clr fsp+6(r3) / clear the next two words
 29226 0000A0A7 89D8                <1>   	mov	eax, ebx
 29227 0000A0A9 B30A                <1> 	mov	bl, 10
 29228 0000A0AB F6F3                <1> 	div	bl 
 29229                              <1> 		; asr r3
 29230                              <1> 		; asr r3 / divide by 8 
 29231                              <1> 		; asr r3 ; / to get number of the fsp entry-1
 29232 0000A0AD FEC0                <1> 	inc	al
 29233                              <1>         	; inc r3 / add 1 to get fsp entry number
 29234 0000A0AF 8886[DED40000]      <1>         mov     [esi+u.fp], al
 29235                              <1> 		; movb r3,u.fp(r2) / move entry number into 
 29236                              <1> 			; / next available slot in u.fp list
 29237 0000A0B5 8935[D8D40000]      <1>         mov     [u.r0], esi
 29238                              <1> 		; mov r2,*u.r0 / move index to u.fp list 
 29239                              <1> 			     ; / into r0 loc on stack
 29240 0000A0BB E99AFBFFFF          <1>         jmp	sysret
 29241                              <1> 		; br sysret2
 29242                              <1> 
 29243                              <1> 	;
 29244                              <1> 	; 'fsp' table (10 bytes/entry)
 29245                              <1> 	; bit 15				   bit 0
 29246                              <1> 	; ---|-------------------------------------------
 29247                              <1> 	; r/w|		i-number of open file
 29248                              <1> 	; ---|-------------------------------------------
 29249                              <1> 	;		   device number
 29250                              <1> 	; -----------------------------------------------
 29251                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 29252                              <1> 	; -----------------------------------------------
 29253                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 29254                              <1> 	; ----------------------|------------------------
 29255                              <1> 	;  flag that says file 	| number of processes
 29256                              <1> 	;   has been deleted	| that have file open 
 29257                              <1> 	; ----------------------|------------------------
 29258                              <1> 	;
 29259                              <1> 
 29260                              <1> syscreat: ; < create file >
 29261                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
 29262                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29263                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
 29264                              <1> 	;
 29265                              <1> 	; 'syscreat' called with two arguments; name and mode.
 29266                              <1> 	; u.namep points to name of the file and mode is put
 29267                              <1> 	; on the stack. 'namei' is called to get i-number of the file.		
 29268                              <1> 	; If the file aready exists, it's mode and owner remain 
 29269                              <1> 	; unchanged, but it is truncated to zero length. If the file
 29270                              <1> 	; did not exist, an i-node is created with the new mode via
 29271                              <1> 	; 'maknod' whether or not the file already existed, it is
 29272                              <1> 	; open for writing. The fsp table is then searched for a free
 29273                              <1> 	; entry. When a free entry is found, proper data is placed
 29274                              <1> 	; in it and the number of this entry is put in the u.fp list.
 29275                              <1> 	; The index to the u.fp (also know as the file descriptor)
 29276                              <1> 	; is put in the user's r0. 			
 29277                              <1> 	;
 29278                              <1> 	; Calling sequence:
 29279                              <1> 	;	syscreate; name; mode
 29280                              <1> 	; Arguments:
 29281                              <1> 	;	name - name of the file to be created
 29282                              <1> 	;	mode - mode of the file to be created
 29283                              <1> 	; Inputs: (arguments)
 29284                              <1> 	; Outputs: *u.r0 - index to u.fp list 
 29285                              <1> 	;		   (the file descriptor of new file)
 29286                              <1> 	; ...............................................................
 29287                              <1> 	;				
 29288                              <1> 	; Retro UNIX 8086 v1 modification: 
 29289                              <1> 	;       'syscreate' system call has two arguments; so,
 29290                              <1> 	;	* 1st argument, name is pointed to by BX register
 29291                              <1> 	;	* 2nd argument, mode is in CX register
 29292                              <1> 	;
 29293                              <1> 	;	AX register (will be restored via 'u.r0') will return
 29294                              <1> 	;	to the user with the file descriptor/number 
 29295                              <1> 	;	(index to u.fp list).
 29296                              <1> 	;
 29297                              <1> 	;call	arg2
 29298                              <1> 	; * name - 'u.namep' points to address of file/path name
 29299                              <1> 	;          in the user's program segment ('u.segmnt')
 29300                              <1> 	;          with offset in BX register (as sysopen argument 1).
 29301                              <1> 	; * mode - sysopen argument 2 is in CX register 
 29302                              <1> 	;          which is on top of stack.
 29303                              <1> 	;
 29304                              <1>         	; jsr r0,arg2 / put file name in u.namep put mode 
 29305                              <1> 			    ; / on stack
 29306 0000A0C0 891D[F0D40000]      <1> 	mov	[u.namep], ebx ; file name address
 29307 0000A0C6 6651                <1> 	push	cx ; mode
 29308 0000A0C8 E8290A0000          <1> 	call 	namei        	
 29309                              <1> 		; jsr r0,namei / get the i-number
 29310                              <1>         ;and	ax, ax
 29311                              <1> 	;jz	short syscreat_1	       	
 29312 0000A0CD 721E                <1> 	jc	short syscreat_1
 29313                              <1> 		; br  2f / if file doesn't exist 2f
 29314                              <1> 	; 27/12/2015
 29315 0000A0CF 6683F829            <1> 	cmp	ax, 41 ; device inode ?
 29316 0000A0D3 0F824EFFFFFF        <1>         jb      syscreat_0 ; yes
 29317                              <1> 	;
 29318 0000A0D9 66F7D8              <1> 	neg 	ax
 29319                              <1>         	; neg r1 / if file already exists make i-number 
 29320                              <1> 		       ; / negative (open for writing)
 29321 0000A0DC E8BB100000          <1> 	call	iopen
 29322                              <1>         	; jsr r0,iopen /
 29323 0000A0E1 E8B8100000          <1> 	call	itrunc
 29324                              <1>         	; jsr r0,itrunc / truncate to 0 length
 29325 0000A0E6 6659                <1> 	pop	cx ; pop mode (did not exist in original Unix v1 !?)
 29326 0000A0E8 E948FFFFFF          <1>         jmp     sysopen_1
 29327                              <1>         	; br op0
 29328                              <1> syscreat_1: ; 2: / file doesn't exist
 29329 0000A0ED 6658                <1> 	pop	ax
 29330                              <1>         	; mov (sp)+,r1 / put the mode in r1
 29331 0000A0EF 30E4                <1> 	xor	ah, ah	
 29332                              <1>         	; bic $!377,r1 / clear upper byte
 29333 0000A0F1 E8D30C0000          <1> 	call 	maknod
 29334                              <1>         	; jsr r0,maknod / make an i-node for this file
 29335 0000A0F6 66A1[0AD50000]      <1> 	mov	ax, [u.dirbuf]
 29336                              <1>         	; mov u.dirbuf,r1 / put i-number 
 29337                              <1> 			        ; / for this new file in r1
 29338 0000A0FC E934FFFFFF          <1>         jmp     sysopen_1
 29339                              <1>         	; br op0 / open the file
 29340                              <1> 
 29341                              <1> sysmkdir: ; < make directory >
 29342                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29343                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 29344                              <1> 	;
 29345                              <1> 	; 'sysmkdir' creates an empty directory whose name is
 29346                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.	
 29347                              <1> 	; The special entries '.' and '..' are not present.
 29348                              <1> 	; Errors are indicated if the directory already exists or		
 29349                              <1> 	; user is not the super user. 
 29350                              <1> 	;
 29351                              <1> 	; Calling sequence:
 29352                              <1> 	;	sysmkdir; name; mode
 29353                              <1> 	; Arguments:
 29354                              <1> 	;	name - points to the name of the directory
 29355                              <1> 	;	mode - mode of the directory
 29356                              <1> 	; Inputs: (arguments)
 29357                              <1> 	; Outputs: -
 29358                              <1> 	;    (sets 'directory' flag to 1; 
 29359                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
 29360                              <1> 	; ...............................................................
 29361                              <1> 	;				
 29362                              <1> 	; Retro UNIX 8086 v1 modification: 
 29363                              <1> 	;       'sysmkdir' system call has two arguments; so,
 29364                              <1> 	;	* 1st argument, name is pointed to by BX register
 29365                              <1> 	;	* 2nd argument, mode is in CX register
 29366                              <1> 	;
 29367                              <1> 		
 29368                              <1> ; / make a directory
 29369                              <1> 
 29370                              <1> 	;call	arg2
 29371                              <1> 	; * name - 'u.namep' points to address of file/path name
 29372                              <1> 	;          in the user's program segment ('u.segmnt')
 29373                              <1> 	;          with offset in BX register (as sysopen argument 1).
 29374                              <1> 	; * mode - sysopen argument 2 is in CX register 
 29375                              <1> 	;          which is on top of stack.
 29376                              <1> 
 29377                              <1> 		; jsr r0,arg2 / put file name in u.namep put mode 
 29378                              <1> 			    ; / on stack
 29379 0000A101 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 29380 0000A107 6651                <1> 	push	cx ; mode
 29381 0000A109 E8E8090000          <1> 	call	namei
 29382                              <1>         	; jsr r0,namei / get the i-number
 29383                              <1>         	;     br .+4 / if file not found branch around error
 29384                              <1>         ;xor 	ax, ax
 29385                              <1> 	;jnz	error
 29386 0000A10E 731C                <1> 	jnc	short dir_exists ; 14/05/2015
 29387                              <1> 	;jnc	error	
 29388                              <1> 		; br  error2 / directory already exists (error)
 29389 0000A110 803D[24D50000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 29390                              <1>         	;tstb u.uid / is user the super user
 29391 0000A117 7622                <1> 	jna	short dir_access_err ; 14/05/2015
 29392                              <1> 	;jna	error
 29393                              <1>         	;bne error2 / no, not allowed
 29394 0000A119 6658                <1> 	pop	ax
 29395                              <1>         	;mov (sp)+,r1 / put the mode in r1
 29396 0000A11B 6683E0CF            <1> 	and	ax, 0FFCFh ; 1111111111001111b
 29397                              <1>         	;bic $!317,r1 / all but su and ex
 29398                              <1> 	;or	ax , 4000h ; 1011111111111111b
 29399 0000A11F 80CC40              <1> 	or	ah, 40h ; Set bit 14 to 1
 29400                              <1>         	;bis $40000,r1 / directory flag
 29401 0000A122 E8A20C0000          <1> 	call	maknod
 29402                              <1>         	;jsr r0,maknod / make the i-node for the directory
 29403 0000A127 E92EFBFFFF          <1> 	jmp	sysret
 29404                              <1>         	;br sysret2 /
 29405                              <1> dir_exists:
 29406                              <1> 	; 14/05/2015
 29407 0000A12C C705[2DD50000]0E00- <1> 	mov	dword [u.error], ERR_DIR_EXISTS ; dir. already exists !
 29408 0000A134 0000                <1>
 29409 0000A136 E9FFFAFFFF          <1> 	jmp	error
 29410                              <1> dir_access_err:
 29411                              <1> 	; 14/05/2015
 29412 0000A13B C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_DIR_ACCESS ; permission denied !
 29413 0000A143 0000                <1>
 29414 0000A145 E9F0FAFFFF          <1> 	jmp	error
 29415                              <1> 
 29416                              <1> sysclose: ;<close file>
 29417                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29418                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
 29419                              <1> 	;
 29420                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
 29421                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
 29422                              <1> 	; is put in r1 and 'fclose' is called.
 29423                              <1> 	;
 29424                              <1> 	; Calling sequence:
 29425                              <1> 	;	sysclose
 29426                              <1> 	; Arguments:
 29427                              <1> 	;	-  
 29428                              <1> 	; Inputs: *u.r0 - file descriptor
 29429                              <1> 	; Outputs: -
 29430                              <1> 	; ...............................................................
 29431                              <1> 	;				
 29432                              <1> 	; Retro UNIX 8086 v1 modification:
 29433                              <1> 	;	 The user/application program puts file descriptor
 29434                              <1> 	;        in BX register as 'sysclose' system call argument.
 29435                              <1> 	; 	 (argument transfer method 1)
 29436                              <1> 
 29437                              <1> 	; / close the file
 29438                              <1> 	
 29439 0000A14A 89D8                <1> 	mov 	eax, ebx
 29440 0000A14C E823090000          <1> 	call 	fclose
 29441                              <1> 		; mov *u.r0,r1 / move index to u.fp list into r1
 29442                              <1> 		; jsr r0,fclose / close the file
 29443                              <1>                	; br error2 / unknown file descriptor
 29444                              <1> 		; br sysret2
 29445                              <1> 	; 14/05/2015
 29446 0000A151 0F8303FBFFFF        <1> 	jnc	sysret
 29447 0000A157 C705[2DD50000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 29448 0000A15F 0000                <1>
 29449 0000A161 E9D4FAFFFF          <1> 	jmp	error
 29450                              <1> 
 29451                              <1> sysemt:
 29452                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29453                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
 29454                              <1> 	;
 29455                              <1> 	; Retro UNIX 8086 v1 modification: 
 29456                              <1> 	;	'Enable Multi Tasking'  system call instead 
 29457                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
 29458                              <1> 	;
 29459                              <1> 	; Retro UNIX 8086 v1 feature only!
 29460                              <1> 	;	Using purpose: Kernel will start without time-out
 29461                              <1> 	;	(internal clock/timer) functionality.
 29462                              <1> 	;	Then etc/init will enable clock/timer for
 29463                              <1> 	;	multi tasking. (Then it will not be disabled again
 29464                              <1> 	;	except hardware reset/restart.)
 29465                              <1> 	;
 29466                              <1> 
 29467 0000A166 803D[24D50000]00    <1> 	cmp	byte [u.uid], 0 ; root ?
 29468                              <1> 	;ja	error
 29469 0000A16D 0F8770FBFFFF        <1> 	ja	badsys ; 14/05/2015
 29470                              <1> emt_0:
 29471 0000A173 FA                  <1> 	cli
 29472 0000A174 21DB                <1> 	and	ebx, ebx
 29473 0000A176 7410                <1> 	jz	short emt_2
 29474                              <1> 	; Enable multi tasking -time sharing-
 29475 0000A178 B8[9FB10000]        <1> 	mov	eax, clock
 29476                              <1> emt_1:
 29477 0000A17D A3[C2070000]        <1> 	mov	[x_timer], eax
 29478 0000A182 FB                  <1> 	sti
 29479 0000A183 E9D2FAFFFF          <1> 	jmp	sysret
 29480                              <1> emt_2:
 29481                              <1> 	; Disable multi tasking -time sharing-
 29482 0000A188 B8[CA070000]        <1> 	mov	eax, u_timer
 29483 0000A18D EBEE                <1> 	jmp	short emt_1
 29484                              <1> 
 29485                              <1> 	; Original UNIX v1 'sysemt' routine
 29486                              <1> ;sysemt:
 29487                              <1>         ;
 29488                              <1> 	;jsr    r0,arg; 30 / put the argument of the sysemt call 
 29489                              <1> 			 ; / in loc 30
 29490                              <1>         ;cmp    30,$core / was the argument a lower address 
 29491                              <1> 			; / than core
 29492                              <1>         ;blo    1f / yes, rtssym
 29493                              <1>         ;cmp    30,$ecore / no, was it higher than "core" 
 29494                              <1> 			; / and less than "ecore"
 29495                              <1>         ;blo    2f / yes, sysret2
 29496                              <1> ;1:
 29497                              <1>         ;mov    $rtssym,30
 29498                              <1> ;2:
 29499                              <1>         ;br     sysret2
 29500                              <1> 
 29501                              <1> sysilgins:
 29502                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 29503                              <1> 	; 03/06/2013
 29504                              <1> 	; Retro UNIX 8086 v1 modification: 
 29505                              <1> 	;	not a valid system call ! (not in use)
 29506                              <1> 	;
 29507 0000A18F E94FFBFFFF          <1> 	jmp	badsys
 29508                              <1> 	;jmp	error
 29509                              <1> 	;;jmp 	sysret
 29510                              <1> 
 29511                              <1> 	; Original UNIX v1 'sysemt' routine
 29512                              <1> ;sysilgins: / calculate proper illegal instruction trap address
 29513                              <1>         ;jsr    r0,arg; 10 / take address from sysilgins call
 29514                              <1> 			  ;/ put it in loc 8.,
 29515                              <1>         ;cmp    10,$core / making it the illegal instruction 
 29516                              <1> 		       ; / trap address
 29517                              <1>         ;blo    1f / is the address a user core address?  
 29518                              <1> 		; / yes, go to 2f
 29519                              <1>         ;cmp    10,$ecore
 29520                              <1>         ;blo    2f
 29521                              <1> ;1:
 29522                              <1>         ;mov    $fpsym,10 / no, make 'fpsum' the illegal 
 29523                              <1> 		    ; / instruction trap address for the system
 29524                              <1> ;2:
 29525                              <1>         ;br     sysret2 / return to the caller via 'sysret'
 29526                              <1> 
 29527                              <1> sysmdate: ; < change the modification time of a file >
 29528                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 29529                              <1> 	; 03/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 29530                              <1> 	;
 29531                              <1> 	; 'sysmdate' is given a file name. It gets inode of this 
 29532                              <1> 	; file into core. The user is checked if he is the owner 
 29533                              <1> 	; or super user. If he is neither an error occurs.
 29534                              <1> 	; 'setimod' is then called to set the i-node modification
 29535                              <1> 	; byte and the modification time, but the modification time
 29536                              <1> 	; is overwritten by whatever get put on the stack during
 29537                              <1> 	; a 'systime' system call. This calls are restricted to
 29538                              <1> 	; the super user.		
 29539                              <1> 	;
 29540                              <1> 	; Calling sequence:
 29541                              <1> 	;	sysmdate; name
 29542                              <1> 	; Arguments:
 29543                              <1> 	;	name - points to the name of file
 29544                              <1> 	; Inputs: (arguments)
 29545                              <1> 	; Outputs: -
 29546                              <1> 	; ...............................................................
 29547                              <1> 	;				
 29548                              <1> 	; Retro UNIX 8086 v1 modification: 
 29549                              <1> 	;	 The user/application program puts address 
 29550                              <1> 	;	 of the file name in BX register 
 29551                              <1> 	;	 as 'sysmdate' system call argument.
 29552                              <1> 	;
 29553                              <1> ; / change the modification time of a file
 29554                              <1> 		; jsr r0,arg; u.namep / point u.namep to the file name
 29555 0000A194 891D[F0D40000]      <1>         mov	[u.namep], ebx
 29556 0000A19A E857090000          <1> 	call	namei
 29557                              <1> 		; jsr r0,namei / get its i-number
 29558 0000A19F 0F82B5FEFFFF        <1>         jc	fnotfound ; file not found !
 29559                              <1> 	;jc	error       
 29560                              <1> 		; br error2 / no, such file
 29561 0000A1A5 E8E80F0000          <1> 	call	iget
 29562                              <1> 		; jsr r0,iget / get i-node into core
 29563 0000A1AA A0[24D50000]        <1> 	mov	al, [u.uid]
 29564 0000A1AF 3A05[AFD10000]      <1> 	cmp	al, [i.uid]
 29565                              <1>         	; cmpb u.uid,i.uid / is user same as owner
 29566 0000A1B5 7413                <1> 	je	short mdate_1
 29567                              <1>         	; beq 1f / yes
 29568 0000A1B7 20C0                <1> 	and	al, al
 29569                              <1> 		; tstb u.uid / no, is user the super user
 29570                              <1> 	;jnz	error
 29571                              <1> 		; bne error2 / no, error
 29572 0000A1B9 740F                <1> 	jz	short mdate_1
 29573 0000A1BB C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 29574 0000A1C3 0000                <1>
 29575 0000A1C5 E970FAFFFF          <1> 	jmp	error
 29576                              <1> mdate_1: ;1:
 29577 0000A1CA E8D10F0000          <1> 	call	setimod
 29578                              <1>         	; jsr r0,setimod / fill in modification data,
 29579                              <1> 		               ; / time etc.
 29580 0000A1CF BE[C2C40000]        <1> 	mov	esi, p_time
 29581 0000A1D4 BF[C6D10000]        <1> 	mov	edi, i.mtim
 29582 0000A1D9 A5                  <1> 	movsd
 29583                              <1> 		; mov 4(sp),i.mtim / move present time to
 29584                              <1>         	; mov 2(sp),i.mtim+2 / modification time
 29585 0000A1DA E97BFAFFFF          <1>         jmp	sysret
 29586                              <1> 		; br sysret2
 29587                              <1> 
 29588                              <1> sysstty: ; < set tty status and mode >
 29589                              <1> 	; 17/11/2015
 29590                              <1> 	; 12/11/2015
 29591                              <1> 	; 29/10/2015
 29592                              <1> 	; 17/10/2015
 29593                              <1> 	; 13/10/2015
 29594                              <1> 	; 29/06/2015
 29595                              <1> 	; 27/06/2015 (Retro UNIX 386 v1 - Beginning)
 29596                              <1> 	; 02/06/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 29597                              <1> 	;
 29598                              <1> 	; 'sysstty' sets the status and mode of the typewriter 
 29599                              <1> 	; whose file descriptor is in (u.r0).
 29600                              <1> 	;
 29601                              <1> 	; Calling sequence:
 29602                              <1> 	;	sysstty; arg
 29603                              <1> 	; Arguments:
 29604                              <1> 	;	arg - address of 3 consequitive words that contain
 29605                              <1> 	;	      the source of status data	
 29606                              <1> 	; Inputs: ((*u.r0 - file descriptor & argument))
 29607                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 29608                              <1> 	; ...............................................................
 29609                              <1> 	;	
 29610                              <1> 	; Retro UNIX 8086 v1 modification: 
 29611                              <1> 	;	'sysstty' system call will set the tty
 29612                              <1> 	;	(clear keyboard buffer and set cursor position)
 29613                              <1> 	;	 in following manner:
 29614                              <1> 	;   NOTE: All of tty setting functions are here (16/01/2014)
 29615                              <1> 	;
 29616                              <1> 	; Inputs:
 29617                              <1> 	;	BX = 0 --> means
 29618                              <1> 	;	   If CL = FFh
 29619                              <1> 	;	      set cursor position for console tty, only 
 29620                              <1> 	;	      CH will be ignored (char. will not be written)	
 29621                              <1> 	;	   If CH = 0 (CL < FFh)
 29622                              <1> 	;	      set console tty for (current) process
 29623                              <1> 	;	      CL = tty number (0 to 9)
 29624                              <1> 	;	      (If CH = 0, character will not be written)			
 29625                              <1> 	;          If CH > 0 (CL < FFh)	
 29626                              <1> 	;             CL = tty number (0 to 9)
 29627                              <1> 	;	      CH = character will be written
 29628                              <1> 	;	        at requested cursor position (in DX)	
 29629                              <1> 	;	   DX = cursor position for tty number 0 to 7.	
 29630                              <1>   	;		(only tty number 0 to 7) 
 29631                              <1> 	;          DL = communication parameters (for serial ports) 
 29632                              <1> 	;	        (only for COM1 and COM2 serial ports)
 29633                              <1> 	;	   DH < 0FFh -> DL is valid, initialize serial port
 29634                              <1> 	;			or set cursor position	
 29635                              <1> 	;	   DH = 0FFh -> DL is not valid
 29636                              <1> 	;		do not set serial port parameters 
 29637                              <1> 	;		or do not set cursor position
 29638                              <1> 	;
 29639                              <1> 	;	BX > 0 --> points to name of tty
 29640                              <1> 	;    	   CH > 0 -->
 29641                              <1> 	;		CH = character will be written in current 
 29642                              <1> 	;            	cursor position (for tty number from 0 to 7)
 29643                              <1> 	;	     	or character will be sent to serial port
 29644                              <1> 	;	     	(for tty number 8 or 9)
 29645                              <1> 	;		CL = color of the character if tty number < 8.
 29646                              <1> 	;    	   CH = 0 --> Do not write a character, 
 29647                              <1> 	;		set mode (tty 8 to 9) or 
 29648                              <1> 	;		set current cursor positions (tty 0 to 7) only. 
 29649                              <1> 	;   	   DX = cursor position for tty number 0 to 7.
 29650                              <1> 	;    	   DH = FFh --> Do not set cursor pos (or comm. params.)
 29651                              <1> 	;		(DL is not valid)
 29652                              <1> 	;	   DL = communication parameters 
 29653                              <1> 	;		for tty number 8 or 9 (COM1 or COM2).
 29654                              <1> 	; Outputs:
 29655                              <1> 	;	cf = 0 -> OK
 29656                              <1> 	;	     AL = tty number (0 to 9)
 29657                              <1> 	;	     AH = line status if tty number is 8 or 9
 29658                              <1> 	;	     AH = process number (of the caller) 	
 29659                              <1> 	;	cf = 1 means error (requested tty is not ready)
 29660                              <1> 	;	     AH = FFh if the tty is locked 
 29661                              <1> 	;		  (owned by another process)
 29662                              <1> 	;	        = process number (of the caller) 
 29663                              <1> 	;		  (if < FFh and tty number < 8)
 29664                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 29665                              <1> 	;	     AH = line status if tty number is 8 or 9
 29666                              <1> 	;	NOTE: Video page will be cleared if cf = 0.
 29667                              <1> 	;
 29668                              <1> 	; 27/06/2015 (32 bit modifications)
 29669                              <1> 	; 14/01/2014
 29670 0000A1DF 31C0                <1> 	xor 	eax, eax
 29671 0000A1E1 6648                <1> 	dec	ax ; 17/10/2015
 29672 0000A1E3 A3[D8D40000]        <1> 	mov	[u.r0], eax ; 0FFFFh
 29673 0000A1E8 21DB                <1> 	and	ebx, ebx
 29674 0000A1EA 0F85CB000000        <1>         jnz     sysstty_6
 29675                              <1> ; set console tty
 29676                              <1> 	; 29/10/2015
 29677                              <1> 	; 17/01/2014 
 29678 0000A1F0 80F909              <1> 	cmp	cl, 9
 29679 0000A1F3 7613                <1> 	jna	short sysstty_0
 29680                              <1> 	; 17/11/2015
 29681 0000A1F5 80F9FF              <1> 	cmp	cl, 0FFh
 29682 0000A1F8 7202                <1> 	jb	short sysstty_13
 29683 0000A1FA 88CD                <1> 	mov	ch, cl ; force CH value to FFh 
 29684                              <1> sysstty_13:
 29685 0000A1FC 8A1D[27D50000]      <1> 	mov	bl, [u.uno] ; process number
 29686 0000A202 8A8B[2BD20000]      <1> 	mov	cl, [ebx+p.ttyc-1] ; current/console tty
 29687                              <1> sysstty_0:
 29688                              <1> 	; 29/06/2015
 29689 0000A208 6652                <1> 	push	dx
 29690 0000A20A 6651                <1> 	push	cx
 29691 0000A20C 30D2                <1> 	xor 	dl, dl	; sysstty call sign
 29692 0000A20E 88C8                <1> 	mov	al, cl
 29693 0000A210 A2[D8D40000]        <1> 	mov	[u.r0], al ; tyy number (0 to 9)
 29694 0000A215 E8870F0000          <1> 	call	ottyp
 29695 0000A21A 6659                <1> 	pop	cx
 29696 0000A21C 665A                <1> 	pop	dx
 29697                              <1> 	;
 29698 0000A21E 7257                <1> 	jc	short sysstty_pd_err
 29699                              <1> 	;
 29700 0000A220 80F908              <1> 	cmp	cl, 8
 29701 0000A223 7222                <1> 	jb	short sysstty_2
 29702                              <1> 	;
 29703 0000A225 80FEFF              <1> 	cmp	dh, 0FFh
 29704 0000A228 741D                <1> 	je	short sysstty_2
 29705                              <1> 		; set communication parameters for serial ports
 29706                              <1> 	; 29/10/2015
 29707 0000A22A 88D4                <1> 	mov	ah, dl ; communication parameters
 29708                              <1> 		; ah = 0E3h = 11100011b = 115200 baud,
 29709                              <1> 		;			 THRE int + RDA int 
 29710                              <1> 		; ah = 23h = 00100011b = 9600 baud,
 29711                              <1> 		;			 THRE int + RDA int 
 29712 0000A22C 28C0                <1> 	sub	al, al ; 0
 29713                              <1> 	; 12/07/2014
 29714 0000A22E 80F909              <1> 	cmp	cl, 9
 29715 0000A231 7202                <1> 	jb	short sysstty_1
 29716 0000A233 FEC0                <1> 	inc	al
 29717                              <1> sysstty_1:
 29718 0000A235 6651                <1> 	push	cx
 29719                              <1> 	; 29/06/2015	
 29720 0000A237 E821120000          <1> 	call 	sp_setp ; Set serial port communication parameters
 29721 0000A23C 66890D[D9D40000]    <1> 	mov	[u.r0+1], cx ; Line status (ah)
 29722                              <1> 			     ; Modem status (EAX bits 16 to 23)
 29723 0000A243 6659                <1> 	pop	cx
 29724 0000A245 7265                <1>         jc      short sysstty_tmout_err ; 29/10/2015
 29725                              <1> sysstty_2:
 29726                              <1> 	; 17/01/2014
 29727 0000A247 20ED                <1> 	and	ch, ch 	; set cursor position 
 29728                              <1> 			; or comm. parameters ONLY
 29729 0000A249 750D                <1> 	jnz	short sysstty_3
 29730 0000A24B 0FB61D[27D50000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 29731 0000A252 888B[2BD20000]      <1> 	mov	[ebx+p.ttyc-1], cl ; console tty
 29732                              <1> sysstty_3:
 29733                              <1> 	; 16/01/2014
 29734 0000A258 88E8                <1> 	mov	al, ch ; character  ; 0 to FFh
 29735                              <1> 	; 17/11/2015
 29736 0000A25A B507                <1> 	mov 	ch, 7  ; Default color (light gray)
 29737 0000A25C 38E9                <1> 	cmp	cl, ch ; 7 (tty number)
 29738 0000A25E 0F86C5000000        <1>         jna     sysstty_9
 29739                              <1> sysstty_12:
 29740                              <1> 	;; BX = 0, CL = 8 or CL = 9
 29741                              <1> 	; (Set specified serial port as console tty port)
 29742                              <1> 	; CH = character to be written
 29743                              <1> 	; 15/04/2014
 29744                              <1> 	; CH = 0 --> initialization only
 29745                              <1> 	; AL = character
 29746                              <1> 	; 26/06/2014
 29747 0000A264 880D[2CD50000]      <1> 	mov	[u.ttyn], cl
 29748                              <1> 	; 12/07/2014
 29749 0000A26A 88CC                <1> 	mov	ah, cl ; tty number (8 or 9)
 29750 0000A26C 20C0                <1> 	and	al, al
 29751 0000A26E 7416                <1> 	jz	short sysstty_4 ; al = ch = 0
 29752                              <1>  	; 04/07/2014
 29753 0000A270 E82E0F0000          <1> 	call 	sndc
 29754                              <1> 	; 12/07/2014
 29755 0000A275 EB1B                <1> 	jmp	short sysstty_5
 29756                              <1> sysstty_pd_err: ; 29/06/2015
 29757                              <1> 	; 'permission denied !' error
 29758 0000A277 C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER
 29759 0000A27F 0000                <1>
 29760 0000A281 E9B4F9FFFF          <1> 	jmp	error
 29761                              <1> sysstty_4:
 29762                              <1> 	; 12/07/2014
 29763                              <1> 	;xchg 	ah, al	; al = 0 -> al = ah, ah = 0
 29764 0000A286 88E0                <1> 	mov	al, ah ; 29/06/2015
 29765 0000A288 2C08                <1> 	sub	al, 8
 29766                              <1> 	; 27/06/2015
 29767 0000A28A E8C6110000          <1> 	call	sp_status ; get serial port status
 29768                              <1> 	; AL = Line status, AH = Modem status
 29769                              <1> 	; 12/11/2015
 29770 0000A28F 3C80                <1> 	cmp	al, 80h
 29771 0000A291 F5                  <1> 	cmc
 29772                              <1> sysstty_5:
 29773 0000A292 66A3[D9D40000]      <1> 	mov	[u.r0+1], ax ; ah = line status
 29774                              <1> 		     ; EAX bits 16-23 = modem status	
 29775 0000A298 9C                  <1> 	pushf
 29776 0000A299 30D2                <1> 	xor	dl, dl ; sysstty call sign
 29777 0000A29B A0[2CD50000]        <1> 	mov	al, [u.ttyn] ; 26/06/2014
 29778 0000A2A0 E8FD0E0000          <1> 	call	cttyp
 29779 0000A2A5 9D                  <1> 	popf
 29780 0000A2A6 0F83AEF9FFFF        <1> 	jnc	sysret	; time out error 
 29781                              <1> 
 29782                              <1> sysstty_tmout_err:
 29783 0000A2AC C705[2DD50000]1900- <1> 	mov	dword [u.error], ERR_TIME_OUT
 29784 0000A2B4 0000                <1>
 29785 0000A2B6 E97FF9FFFF          <1> 	jmp	error
 29786                              <1> sysstty_6:
 29787 0000A2BB 6652                <1> 	push	dx
 29788 0000A2BD 6651                <1> 	push	cx
 29789 0000A2BF 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 29790 0000A2C5 E82C080000          <1> 	call	namei
 29791 0000A2CA 6659                <1> 	pop	cx
 29792 0000A2CC 665A                <1> 	pop	dx
 29793 0000A2CE 720E                <1> 	jc	short sysstty_inv_dn
 29794                              <1> 	;
 29795 0000A2D0 6683F813            <1> 	cmp	ax, 19  ; inode number of /dev/COM2
 29796 0000A2D4 7708                <1> 	ja	short sysstty_inv_dn ; 27/06/2015
 29797                              <1> 	;
 29798 0000A2D6 3C0A                <1> 	cmp	al, 10 ; /dev/tty0 .. /dev/tty7
 29799                              <1> 		       ; /dev/COM1, /dev/COM2
 29800 0000A2D8 7213                <1> 	jb	short sysstty_7
 29801 0000A2DA 2C0A                <1> 	sub	al, 10
 29802 0000A2DC EB20                <1> 	jmp	short sysstty_8
 29803                              <1> sysstty_inv_dn: 
 29804                              <1> 	; 27/06/2015
 29805                              <1> 	; Invalid device name (not a tty) ! error
 29806                              <1> 	; (Device is not a tty or device name not found)
 29807 0000A2DE C705[2DD50000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 29808 0000A2E6 0000                <1>
 29809 0000A2E8 E94DF9FFFF          <1> 	jmp	error 
 29810                              <1> sysstty_7:
 29811 0000A2ED 3C01                <1> 	cmp	al, 1 ; /dev/tty
 29812 0000A2EF 75ED                <1> 	jne	short sysstty_inv_dn ; 27/06/2015
 29813 0000A2F1 0FB61D[27D50000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 29814 0000A2F8 8A83[2BD20000]      <1> 	mov	al, [ebx+p.ttyc-1] ; console tty
 29815                              <1> sysstty_8:	
 29816 0000A2FE A2[D8D40000]        <1> 	mov	[u.r0], al
 29817 0000A303 6652                <1> 	push	dx
 29818 0000A305 6650                <1> 	push	ax
 29819 0000A307 6651                <1> 	push	cx	
 29820 0000A309 E8930E0000          <1> 	call	ottyp
 29821 0000A30E 6659                <1> 	pop	cx
 29822 0000A310 6658                <1> 	pop	ax
 29823 0000A312 665A                <1> 	pop	dx
 29824 0000A314 0F825DFFFFFF        <1>         jc      sysstty_pd_err ; 'permission denied !'
 29825                              <1> 	; 29/10/2015
 29826 0000A31A 86E9                <1> 	xchg 	ch, cl
 29827                              <1> 		; cl = character, ch = color code
 29828 0000A31C 86C1                <1> 	xchg	al, cl
 29829                              <1> 		; al = character, cl = tty number
 29830 0000A31E 80F907              <1> 	cmp	cl, 7
 29831 0000A321 0F873DFFFFFF        <1>         ja      sysstty_12
 29832                              <1> 	;
 29833                              <1> 	; 16/01/2014
 29834 0000A327 30FF                <1> 	xor	bh, bh
 29835                              <1> 	;
 29836                              <1> sysstty_9: 	; tty 0 to tty 7
 29837                              <1> 	; al = character
 29838 0000A329 80FEFF              <1> 	cmp	dh, 0FFh ; Do not set cursor position
 29839 0000A32C 740F                <1> 	je	short sysstty_10
 29840 0000A32E 6651                <1> 	push	cx
 29841 0000A330 6650                <1> 	push	ax	
 29842                              <1> 	; movzx, ebx, cl
 29843 0000A332 88CB                <1> 	mov	bl, cl ; (tty number = video page number)
 29844 0000A334 E81275FFFF          <1> 	call	_set_cpos
 29845 0000A339 6658                <1> 	pop	ax
 29846 0000A33B 6659                <1> 	pop	cx
 29847                              <1> sysstty_10: 
 29848                              <1> 	; 29/10/2015
 29849 0000A33D 08C0                <1> 	or	al, al ; character
 29850 0000A33F 740F                <1> 	jz      short sysstty_11 ; al = 0
 29851                              <1> 	; 17/11/2015
 29852 0000A341 3CFF                <1> 	cmp	al, 0FFh
 29853 0000A343 730B                <1> 	jnb	short sysstty_11
 29854                              <1> 		; ch > 0 and ch < FFh
 29855                              <1> 	; write a character at current cursor position
 29856 0000A345 88EC                <1> 	mov	ah, ch ; color/attribute
 29857                              <1> 	; 12/07/2014
 29858 0000A347 6651                <1> 	push	cx
 29859 0000A349 E83874FFFF          <1> 	call	_write_c_current
 29860 0000A34E 6659                <1> 	pop	cx
 29861                              <1> sysstty_11:
 29862                              <1> 	; 14/01/2014
 29863 0000A350 30D2                <1> 	xor	dl, dl ; sysstty call sign
 29864                              <1> 	; 18/01/2014
 29865                              <1> 	;movzx	eax, cl ; 27/06/2015
 29866 0000A352 88C8                <1> 	mov	al, cl
 29867 0000A354 E8490E0000          <1> 	call	cttyp
 29868 0000A359 E9FCF8FFFF          <1> 	jmp	sysret
 29869                              <1> 
 29870                              <1> ; Original UNIX v1 'sysstty' routine:
 29871                              <1> ; gtty:
 29872                              <1> ;sysstty: / set mode of typewriter; 3 consequtive word arguments
 29873                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block, 
 29874                              <1> 	; 		/ r2 has source
 29875                              <1>         ;mov    r2,-(sp)
 29876                              <1>         ;mov    r1,-(sp) / put r1 and r2 on the stack
 29877                              <1> ;1: / flush the clist wait till typewriter is quiescent
 29878                              <1>         ;mov    (sp),r1 / restore r1 to tty block offset
 29879                              <1>         ;movb   tty+3(r1),0f / put cc offset into getc argument
 29880                              <1>         ;mov    $240,*$ps / set processor priority to 5
 29881                              <1>         ;jsr    r0,getc; 0:../ put character from clist in r1
 29882                              <1>         ;       br .+4 / list empty, skip branch
 29883                              <1>         ;br     1b / get another character until list is empty
 29884                              <1>         ;mov    0b,r1 / move cc offset to r1
 29885                              <1>         ;inc    r1 / bump it for output clist
 29886                              <1>         ;tstb   cc(r1) / is it 0
 29887                              <1>         ;beq    1f / yes, no characters to output
 29888                              <1>  	;mov    r1,0f / no, put offset in sleep arg
 29889                              <1>         ;jsr    r0,sleep; 0:.. / put tty output process to sleep
 29890                              <1>         ;br     1b / try to calm it down again
 29891                              <1> ;1:
 29892                              <1>         ;mov    (sp)+,r1
 29893                              <1>         ;mov    (sp)+,r2 / restore registers
 29894                              <1> 	;mov    (r2)+,r3 / put reader control status in r3
 29895                              <1>         ;beq    1f / if 0, 1f
 29896                              <1>         ;mov    r3,rcsr(r1) / move r.c. status to reader
 29897                              <1>         ;                   / control status register
 29898                              <1> ;1:
 29899                              <1>         ;mov    (r2)+,r3 / move pointer control status to r3
 29900                              <1>         ;beq    1f / if 0 1f
 29901                              <1>         ;mov    r3,tcsr(r1) / move p.c. status to printer 
 29902                              <1> 	;		    / control status reg
 29903                              <1> ;1:
 29904                              <1>         ;mov    (r2)+,tty+4(r1) / move to flag byte of tty block
 29905                              <1>         ;jmp     sysret2 / return to user
 29906                              <1> 
 29907                              <1> sysgtty: ; < get tty status >
 29908                              <1> 	; 23/11/2015
 29909                              <1> 	; 29/10/2015
 29910                              <1> 	; 17/10/2015
 29911                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - Beginning)
 29912                              <1> 	; 30/05/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 29913                              <1> 	;
 29914                              <1> 	; 'sysgtty' gets the status of tty in question. 
 29915                              <1> 	; It stores in the three words addressed by it's argument
 29916                              <1> 	; the status of the typewriter whose file descriptor
 29917                              <1> 	; in (u.r0).
 29918                              <1> 	;
 29919                              <1> 	; Calling sequence:
 29920                              <1> 	;	sysgtty; arg
 29921                              <1> 	; Arguments:
 29922                              <1> 	;	arg - address of 3 words destination of the status
 29923                              <1> 	; Inputs: ((*u.r0 - file descriptor))
 29924                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 29925                              <1> 	; ...............................................................
 29926                              <1> 	;	
 29927                              <1> 	; Retro UNIX 8086 v1 modification: 
 29928                              <1> 	;	'sysgtty' system call will return status of tty
 29929                              <1> 	;	(keyboard, serial port and video page status)
 29930                              <1> 	;	 in following manner:
 29931                              <1> 	;
 29932                              <1> 	; Inputs:
 29933                              <1> 	;	BX = 0 --> means 
 29934                              <1> 	;	     CH = 0 -->	'return status of the console tty' 
 29935                              <1> 	;	                 for (current) process
 29936                              <1> 	;	     CL = 0 --> return keyboard status (tty 0 to 9)
 29937                              <1> 	;	     CL = 1 --> return video page status (tty 0 to 7)
 29938                              <1> 	;	     CL = 1 --> return serial port status (tty 8 & 9)		
 29939                              <1> 	;	     CH > 0 -->	tty number + 1
 29940                              <1> 	;
 29941                              <1> 	;	BX > 0 --> points to name of tty
 29942                              <1> 	;	     CL = 0 --> return keyboard status
 29943                              <1> 	;	     CL = 1 --> return video page status
 29944                              <1> 	;	     CH = undefined		 
 29945                              <1> 	;
 29946                              <1> 	; Outputs:
 29947                              <1> 	;	cf = 0 ->
 29948                              <1> 	;
 29949                              <1> 	;	     AL = tty number from 0 to 9
 29950                              <1> 	;		  (0 to 7 is also the video page of the tty)	
 29951                              <1> 	;	     AH = 0 if the tty is free/unused
 29952                              <1> 	;	     AH = the process number of the caller 
 29953                              <1>  	;	     AH = FFh if the tty is locked by another process
 29954                              <1> 	;
 29955                              <1> 	;	  (if calling is for serial port status)
 29956                              <1> 	;	     BX = serial port status if tty number is 8 or 9
 29957                              <1> 	;		  (BH = modem status, BL = Line status)
 29958                              <1> 	;	     CX = 0FFFFh (if data is ready)
 29959                              <1> 	;	     CX = 0 (if data is not ready or undefined)		
 29960                              <1> 	;
 29961                              <1> 	;	  (if calling is for keyboard status)
 29962                              <1> 	;	     BX = current character in tty/keyboard buffer
 29963                              <1> 	;		  (BH = scan code, BL = ascii code)
 29964                              <1> 	;		  (BX=0 if there is not a waiting character)
 29965                              <1> 	;	     CX  is undefined
 29966                              <1> 	;
 29967                              <1> 	;	  (if calling is for video page status)	
 29968                              <1> 	;	     BX = cursor position on the video page
 29969                              <1> 	;		  if tty number < 8
 29970                              <1> 	;		  (BH = row, BL = column)
 29971                              <1> 	;	     CX = current character (in cursor position)
 29972                              <1> 	;		  on the video page of the tty 
 29973                              <1> 	;		  if tty number < 8
 29974                              <1> 	;		  (CH = color, CL = character)
 29975                              <1> 	;	
 29976                              <1> 	;	cf = 1 means error (requested tty is not ready)
 29977                              <1> 	;
 29978                              <1> 	;	     AH = FFh if the caller is not owner of
 29979                              <1> 	;		  specified tty or console tty
 29980                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 29981                              <1> 	;	     BX, CX are undefined if cf = 1
 29982                              <1> 	;
 29983                              <1> 	;	  (If tty number is 8 or 9)
 29984                              <1> 	;	     AL = tty number 
 29985                              <1> 	;	     AH = the process number of the caller 
 29986                              <1> 	;	     BX = serial port status
 29987                              <1> 	;  		 (BH = modem status, BL = Line status)
 29988                              <1> 	;	     CX = 0
 29989                              <1> 	;
 29990                              <1> 		
 29991                              <1> gtty:   ; get (requested) tty number
 29992                              <1> 	; 17/10/2015
 29993                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 29994                              <1> 	; 30/05/2013 - 12/07/2014
 29995                              <1> 	; Retro UNIX 8086 v1 modification ! 
 29996                              <1> 	;
 29997                              <1> 	; ((Modified regs: eAX, eBX, eCX, eDX, eSI, eDI, eBP))
 29998                              <1> 	;
 29999                              <1> 	; 28/06/2015 (32 bit modifications)
 30000                              <1> 	; 16/01/2014
 30001 0000A35E 31C0                <1> 	xor 	eax, eax
 30002 0000A360 6648                <1> 	dec	ax ; 17/10/2015
 30003 0000A362 A3[D8D40000]        <1> 	mov 	[u.r0], eax ; 0FFFFh
 30004 0000A367 80F901              <1> 	cmp	cl, 1
 30005 0000A36A 760F                <1> 	jna	short sysgtty_0
 30006                              <1> sysgtty_invp:
 30007                              <1> 	; 28/06/2015
 30008 0000A36C C705[2DD50000]1700- <1>         mov     dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 30009 0000A374 0000                <1>
 30010 0000A376 E9BFF8FFFF          <1> 	jmp	error
 30011                              <1> sysgtty_0:	
 30012 0000A37B 21DB                <1> 	and	ebx, ebx
 30013 0000A37D 7430                <1> 	jz	short sysgtty_1
 30014                              <1> 	;
 30015 0000A37F 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 30016 0000A385 6651                <1> 	push	cx ; 23/11/2015
 30017 0000A387 E86A070000          <1> 	call	namei
 30018 0000A38C 6659                <1> 	pop	cx ; 23/11/2015
 30019 0000A38E 7210                <1> 	jc 	short sysgtty_inv_dn ; 28/06/2015
 30020                              <1> 	;
 30021 0000A390 6683F801            <1> 	cmp	ax, 1
 30022 0000A394 7622                <1> 	jna	short sysgtty_2
 30023 0000A396 6683E80A            <1> 	sub	ax, 10
 30024 0000A39A 6683F809            <1> 	cmp	ax, 9
 30025                              <1> 	;ja	short sysgtty_inv_dn
 30026                              <1> 	;mov	ch, al
 30027                              <1> 	;jmp	short sysgtty_4
 30028                              <1> 	; 23/11/2015
 30029 0000A39E 7629                <1> 	jna	short sysgtty_4
 30030                              <1> sysgtty_inv_dn: 
 30031                              <1> 	; 28/06/2015
 30032                              <1> 	; Invalid device name (not a tty) ! error
 30033                              <1> 	; (Device is not a tty or device name not found)
 30034 0000A3A0 C705[2DD50000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 30035 0000A3A8 0000                <1>
 30036 0000A3AA E98BF8FFFF          <1> 	jmp	error 
 30037                              <1> sysgtty_1:
 30038                              <1> 	; 16/01/2014
 30039 0000A3AF 80FD0A              <1> 	cmp	ch, 10
 30040 0000A3B2 77B8                <1> 	ja	short sysgtty_invp ; 28/06/2015
 30041 0000A3B4 FECD                <1> 	dec	ch ; 0 -> FFh (negative)
 30042 0000A3B6 790F                <1> 	jns	short sysgtty_3 ; not negative
 30043                              <1> 	;
 30044                              <1> sysgtty_2:
 30045                              <1> 	; get tty number of console tty
 30046 0000A3B8 8A25[27D50000]      <1> 	mov	ah, [u.uno]
 30047                              <1>  	; 28/06/2015
 30048 0000A3BE 0FB6DC              <1> 	movzx 	ebx, ah
 30049 0000A3C1 8AAB[2BD20000]      <1> 	mov	ch, [ebx+p.ttyc-1]
 30050                              <1> sysgtty_3:
 30051 0000A3C7 88E8                <1> 	mov	al, ch
 30052                              <1> sysgtty_4:
 30053 0000A3C9 A2[D8D40000]        <1> 	mov	[u.r0], al
 30054                              <1>  	; 28/06/2015
 30055                              <1> 	;cmp	al, 9
 30056                              <1> 	;ja	short sysgtty_invp
 30057 0000A3CE 8B2D[D4D40000]      <1> 	mov	ebp, [u.usp]
 30058                              <1> 	; 23/11/2015
 30059 0000A3D4 20C9                <1> 	and	cl, cl
 30060 0000A3D6 7436                <1> 	jz	short sysgtty_6 ; keyboard status
 30061 0000A3D8 3C08                <1> 	cmp	al, 8 ; cmp ch, 8
 30062 0000A3DA 7232                <1> 	jb	short sysgtty_6 ; video page status
 30063                              <1> 	; serial port status
 30064                              <1> 	; 12/07/2014
 30065                              <1> 	;mov	dx, 0
 30066                              <1> 	;je	short sysgtty_5
 30067                              <1> 	;inc	dl
 30068                              <1> ;sysgtty_5:
 30069                              <1> 	; 28/06/2015
 30070 0000A3DC 2C08                <1> 	sub	al, 8
 30071 0000A3DE E872100000          <1> 	call	sp_status ; serial (COM) port (line) status
 30072                              <1> 	; AL = Line status, AH = Modem status
 30073 0000A3E3 66894510            <1> 	mov	[ebp+16], ax ; serial port status (in EBX)
 30074 0000A3E7 8A25[27D50000]      <1> 	mov	ah, [u.uno]
 30075 0000A3ED 8825[D9D40000]      <1>         mov     [u.r0+1], ah
 30076 0000A3F3 66C745180000        <1> 	mov	word [ebp+24], 0 ; data status (0 = not ready)	
 30077                              <1> 				; (in ECX)
 30078 0000A3F9 A880                <1> 	test	al, 80h
 30079 0000A3FB 7565                <1> 	jnz	short sysgtty_dnr_err ; 29/06/2015
 30080 0000A3FD A801                <1> 	test	al, 1
 30081 0000A3FF 0F8455F8FFFF        <1> 	jz	sysret
 30082 0000A405 66FF4D18            <1> 	dec	word [ebp+24] ; data status (FFFFh = ready)	
 30083 0000A409 E94CF8FFFF          <1> 	jmp	sysret
 30084                              <1> sysgtty_6:
 30085 0000A40E A2[2CD50000]        <1> 	mov	[u.ttyn], al ; tty number
 30086                              <1> 	;movzx	ebx, al
 30087 0000A413 88C3                <1> 	mov 	bl, al ; tty number (0 to 9)
 30088 0000A415 D0E3                <1> 	shl 	bl, 1  ; aligned to word
 30089                              <1> 	; 22/04/2014 - 29/06/2015
 30090 0000A417 81C3[C6C40000]      <1>         add     ebx, ttyl
 30091 0000A41D 8A23                <1>  	mov	ah, [ebx]
 30092 0000A41F 3A25[27D50000]      <1> 	cmp	ah, [u.uno]
 30093 0000A425 7404                <1> 	je	short sysgtty_7
 30094 0000A427 20E4                <1> 	and	ah, ah
 30095                              <1> 	;jz	short sysgtty_7
 30096 0000A429 7506                <1> 	jnz	short sysgtty_8
 30097                              <1> 	;mov	ah, 0FFh
 30098                              <1> sysgtty_7:
 30099 0000A42B 8825[D9D40000]      <1>         mov     [u.r0+1], ah
 30100                              <1> sysgtty_8:
 30101 0000A431 08C9                <1> 	or	cl, cl
 30102 0000A433 7510                <1> 	jnz	short sysgtty_9
 30103 0000A435 B401                <1> 	mov	ah, 1  ; test a key is available
 30104 0000A437 E8AB67FFFF          <1> 	call	int16h ; 24/01/2016
 30105 0000A43C 66894510            <1> 	mov	[ebp+16], ax ; bx, character
 30106 0000A440 E915F8FFFF          <1> 	jmp	sysret
 30107                              <1> sysgtty_9:
 30108 0000A445 8A1D[2CD50000]      <1> 	mov	bl, [u.ttyn]
 30109                              <1> 	; bl = video page number
 30110 0000A44B E82D71FFFF          <1> 	call 	get_cpos
 30111                              <1> 	; dx = cursor position
 30112 0000A450 66895510            <1> 	mov	[ebp+16], dx ; bx
 30113                              <1> 	;mov	bl, [u.ttyn]
 30114                              <1> 	; bl = video page number
 30115 0000A454 E8E372FFFF          <1> 	call	_read_ac_current ; 24/01/2016
 30116                              <1> 	; ax = character and attribute/color
 30117 0000A459 66894518            <1> 	mov	[ebp+24], ax ; cx
 30118 0000A45D E9F8F7FFFF          <1> 	jmp	sysret
 30119                              <1> sysgtty_dnr_err:
 30120                              <1> 	; 'device not responding !' error	
 30121                              <1> 	;mov 	dword [u.error], ERR_TIME_OUT ; 25
 30122 0000A462 C705[2DD50000]1900- <1> 	mov 	dword [u.error], ERR_DEV_NOT_RESP ;  25				
 30123 0000A46A 0000                <1>
 30124 0000A46C E9C9F7FFFF          <1> 	jmp	error	
 30125                              <1> 
 30126                              <1> ; Original UNIX v1 'sysgtty' routine:
 30127                              <1> ; sysgtty:
 30128                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block,
 30129                              <1> 	;	       / r2 has destination
 30130                              <1>         ;mov    rcsr(r1),(r2)+ / put reader control status 
 30131                              <1> 	;                     / in 1st word of dest
 30132                              <1>         ;mov    tcsr(r1),(r2)+ / put printer control status
 30133                              <1> 	;                     / in 2nd word of dest
 30134                              <1>         ;mov    tty+4(r1),(r2)+ / put mode in 3rd word
 30135                              <1>         ;jmp    sysret2 / return to user
 30136                              <1> 	
 30137                              <1> ; Original UNIX v1 'gtty' routine:
 30138                              <1> ; gtty:
 30139                              <1>         ;jsr    r0,arg; u.off / put first arg in u.off
 30140                              <1>         ;mov    *u.r0,r1 / put file descriptor in r1
 30141                              <1>         ;jsr    r0,getf / get the i-number of the file
 30142                              <1>         ;tst    r1 / is it open for reading
 30143                              <1>         ;bgt    1f / yes
 30144                              <1>         ;neg    r1 / no, i-number is negative, 
 30145                              <1> 	;          / so make it positive
 30146                              <1> ;1:
 30147                              <1>         ;sub    $14.,r1 / get i-number of tty0
 30148                              <1>         ;cmp    r1,$ntty-1 / is there such a typewriter
 30149                              <1>         ;bhis   error9 / no, error
 30150                              <1>         ;asl    r1 / 0%2
 30151                              <1>         ;asl    r1 / 0%4 / yes
 30152                              <1>         ;asl    r1 / 0%8 / multiply by 8 so r1 points to 
 30153                              <1> 	;	       ; / tty block
 30154                              <1>         ;mov    u.off,r2 / put argument in r2
 30155                              <1>         ;rts    r0 / return
 30156                              <1> 
 30157                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u2.s
 30158                              <1> ; Last Modification: 03/01/2016
 30159                              <1> 
 30160                              <1> syslink:
 30161                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30162                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 30163                              <1> 	;
 30164                              <1> 	; 'syslink' is given two arguments, name 1 and name 2.
 30165                              <1> 	; name 1 is a file that already exists. name 2 is the name
 30166                              <1> 	; given to the entry that will go in the current directory.
 30167                              <1> 	; name2 will then be a link to the name 1 file. The i-number
 30168                              <1> 	; in the name 2 entry of current directory is the same
 30169                              <1> 	; i-number for the name 1 file.
 30170                              <1> 	;
 30171                              <1> 	; Calling sequence:
 30172                              <1> 	;	syslink; name 1; name 2
 30173                              <1> 	; Arguments:
 30174                              <1> 	;	name 1 - file name to which link will be created.
 30175                              <1> 	;	name 2 - name of entry in current directory that
 30176                              <1> 	;		 links to name 1.
 30177                              <1> 	; Inputs: -
 30178                              <1> 	; Outputs: -
 30179                              <1> 	; ...............................................................
 30180                              <1> 	;	
 30181                              <1> 	; Retro UNIX 8086 v1 modification: 
 30182                              <1> 	;       'syslink' system call has two arguments; so,
 30183                              <1> 	;	* 1st argument, name 1 is pointed to by BX register
 30184                              <1> 	;	* 2nd argument, name 2 is pointed to by CX register
 30185                              <1> 	;
 30186                              <1> 		; / name1, name2
 30187                              <1> 		;jsr r0,arg2 / u.namep has 1st arg u.off has 2nd
 30188 0000A471 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 30189 0000A477 51                  <1> 	push	ecx
 30190 0000A478 E879060000          <1> 	call	namei
 30191                              <1> 		; jsr r0,namei / find the i-number associated with
 30192                              <1> 			     ; / the 1st path name
 30193                              <1>      	;;and	ax, ax
 30194                              <1> 	;;jz	error ; File not found
 30195                              <1> 	;jc	error 
 30196                              <1> 		; br error9 / cannot be found
 30197 0000A47D 730F                <1> 	jnc	short syslink0
 30198                              <1> 	;pop 	ecx
 30199                              <1> 	; 'file not found !' error
 30200 0000A47F C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 30201 0000A487 0000                <1>
 30202 0000A489 E9ACF7FFFF          <1> 	jmp	error
 30203                              <1> syslink0:
 30204 0000A48E E8FF0C0000          <1> 	call	iget
 30205                              <1> 		; jsr r0,iget / get the i-node into core
 30206 0000A493 8F05[F0D40000]      <1> 	pop	dword [u.namep] ; ecx
 30207                              <1> 		; mov (sp)+,u.namep / u.namep points to 2nd name
 30208 0000A499 6650                <1> 	push	ax
 30209                              <1> 		; mov r1,-(sp) / put i-number of name1 on the stack
 30210                              <1> 			    ; / (a link to this file is to be created)
 30211 0000A49B 66FF35[BCD40000]    <1> 	push	word [cdev]
 30212                              <1> 		; mov cdev,-(sp) / put i-nodes device on the stack
 30213 0000A4A2 E855000000          <1> 	call	isdir
 30214                              <1> 		; jsr r0,isdir / is it a directory
 30215 0000A4A7 E84A060000          <1> 	call	namei
 30216                              <1> 		; jsr r0,namei / no, get i-number of name2
 30217                              <1> 	;jnc	error
 30218                              <1> 		; br .+4   / not found 
 30219                              <1> 			 ; / so r1 = i-number of current directory
 30220                              <1> 			 ; / ii = i-number of current directory
 30221                              <1> 		; br error9 / file already exists., error
 30222 0000A4AC 720F                <1> 	jc	short syslink1
 30223                              <1> 	; pop ax
 30224                              <1> 	; pop ax
 30225                              <1> 	; 'file exists !' error
 30226 0000A4AE C705[2DD50000]0E00- <1> 	mov	dword [u.error], ERR_FILE_EXISTS ; 14
 30227 0000A4B6 0000                <1>
 30228 0000A4B8 E97DF7FFFF          <1> 	jmp	error
 30229                              <1> syslink1:
 30230 0000A4BD 6659                <1> 	pop	cx
 30231                              <1> 	;cmp	cx, [cdev]
 30232 0000A4BF 3A0D[BCD40000]      <1> 	cmp	cl, [cdev]
 30233                              <1> 	;jne	error
 30234                              <1> 		; cmp (sp)+,cdev / u.dirp now points to 
 30235                              <1> 			       ; / end of current directory
 30236                              <1> 	        ; bne error9
 30237 0000A4C5 740F                <1> 	je	short syslink2
 30238                              <1> 	; 'not same drive !' error
 30239 0000A4C7 C705[2DD50000]1500- <1> 	mov	dword [u.error],  ERR_DRV_NOT_SAME ; 21
 30240 0000A4CF 0000                <1>
 30241 0000A4D1 E964F7FFFF          <1> 	jmp	error
 30242                              <1> syslink2:
 30243 0000A4D6 6658                <1> 	pop	ax
 30244 0000A4D8 6650                <1> 	push	ax
 30245 0000A4DA 66A3[0AD50000]      <1> 	mov	[u.dirbuf], ax
 30246                              <1> 		; mov (sp),u.dirbuf / i-number of name1 into u.dirbuf
 30247 0000A4E0 E8A8000000          <1> 	call	mkdir
 30248                              <1> 		; jsr r0,mkdir / make directory entry for name2 
 30249                              <1> 		 	     ; / in current directory
 30250 0000A4E5 6658                <1> 	pop	ax
 30251                              <1> 		; mov (sp)+,r1 / r1 has i-number of name1
 30252 0000A4E7 E8A60C0000          <1> 	call	iget
 30253                              <1> 		; jsr r0,iget / get i-node into core
 30254 0000A4EC FE05[AED10000]      <1> 	inc	byte [i.nlks]
 30255                              <1> 		; incb i.nlks / add 1 to its number of links
 30256 0000A4F2 E8A90C0000          <1> 	call	setimod
 30257                              <1> 		; jsr r0,setimod / set the i-node modified flag
 30258 0000A4F7 E95EF7FFFF          <1> 	jmp	sysret
 30259                              <1> 
 30260                              <1> isdir:
 30261                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 30262                              <1> 	; 04/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 30263                              <1> 	;
 30264                              <1> 	; 'isdir' check to see if the i-node whose i-number is in r1
 30265                              <1> 	;  is a directory. If it is, an error occurs, because 'isdir'
 30266                              <1> 	;  called by syslink and sysunlink to make sure directories
 30267                              <1> 	;  are not linked. If the user is the super user (u.uid=0),
 30268                              <1> 	; 'isdir' does not bother checking. The current i-node
 30269                              <1> 	;  is not disturbed.			
 30270                              <1> 	;		
 30271                              <1> 	; INPUTS ->
 30272                              <1> 	;    r1 - contains the i-number whose i-node is being checked.
 30273                              <1> 	;    u.uid - user id
 30274                              <1> 	; OUTPUTS ->
 30275                              <1> 	;    r1 - contains current i-number upon exit
 30276                              <1> 	;    	 (current i-node back in core) 
 30277                              <1> 	;	
 30278                              <1> 	; ((AX = R1))
 30279                              <1> 	;
 30280                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 30281                              <1> 	;
 30282                              <1> 
 30283                              <1> 	; / if the i-node whose i-number is in r1 is a directory 
 30284                              <1> 	; / there is an error unless super user made the call
 30285                              <1> 	
 30286 0000A4FC 803D[24D50000]00    <1> 	cmp	byte [u.uid], 0 
 30287                              <1> 		; tstb u.uid / super user
 30288 0000A503 762D                <1> 	jna	short isdir1
 30289                              <1> 		; beq 1f / yes, don't care
 30290 0000A505 66FF35[B8D40000]    <1> 	push	word [ii]
 30291                              <1> 		; mov ii,-(sp) / put current i-number on stack
 30292 0000A50C E8810C0000          <1> 	call	iget
 30293                              <1> 		; jsr r0,iget / get i-node into core (i-number in r1)
 30294 0000A511 66F705[ACD10000]00- <1> 	test 	word [i.flgs], 4000h ; Bit 14 : Directory flag
 30295 0000A519 40                  <1>
 30296                              <1> 		; bit $40000,i.flgs / is it a directory
 30297                              <1> 	;jnz	error
 30298                              <1> 		; bne error9 / yes, error
 30299 0000A51A 740F                <1> 	jz	short isdir0
 30300 0000A51C C705[2DD50000]0B00- <1> 	mov 	dword [u.error], ERR_NOT_FILE  ; 11 ; ERR_DIR_ACCESS 
 30301 0000A524 0000                <1>
 30302                              <1> 				; 'permission denied !' error
 30303                              <1> 	; pop	ax
 30304 0000A526 E90FF7FFFF          <1> 	jmp	error	
 30305                              <1> isdir0:	
 30306 0000A52B 6658                <1> 	pop	ax
 30307                              <1> 		; mov (sp)+,r1 / no, put current i-number in r1 (ii)
 30308 0000A52D E8600C0000          <1> 	call	iget
 30309                              <1> 		; jsr r0,iget / get it back in
 30310                              <1> isdir1: ; 1:
 30311 0000A532 C3                  <1> 	retn
 30312                              <1> 		; rts r0
 30313                              <1> 
 30314                              <1> sysunlink:
 30315                              <1> 	; 04/12/2015 (14 byte file names)
 30316                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30317                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 30318                              <1> 	;
 30319                              <1> 	; 'sysunlink' removes the entry for the file pointed to by
 30320                              <1> 	; name from its directory. If this entry was the last link
 30321                              <1> 	; to the file, the contents of the file are freed and the
 30322                              <1> 	; file is destroyed. If, however, the file was open in any
 30323                              <1> 	; process, the actual destruction is delayed until it is 
 30324                              <1> 	; closed, even though the directory entry has disappeared.
 30325                              <1> 	; 
 30326                              <1> 	; The error bit (e-bit) is set to indicate that the file	
 30327                              <1> 	; does not exist or that its directory can not be written.
 30328                              <1> 	; Write permission is not required on the file itself.
 30329                              <1> 	; It is also illegal to unlink a directory (except for
 30330                              <1> 	; the superuser).
 30331                              <1> 	;
 30332                              <1> 	; Calling sequence:
 30333                              <1> 	;	sysunlink; name
 30334                              <1> 	; Arguments:
 30335                              <1> 	;	name - name of directory entry to be removed 
 30336                              <1> 	; Inputs: -
 30337                              <1> 	; Outputs: -
 30338                              <1> 	; ...............................................................
 30339                              <1> 	;				
 30340                              <1> 	; Retro UNIX 8086 v1 modification:
 30341                              <1> 	;	 The user/application program puts address of the name
 30342                              <1> 	;        in BX register as 'sysunlink' system call argument.
 30343                              <1> 
 30344                              <1> 	; / name - remove link name
 30345 0000A533 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 30346                              <1> 		;jsr r0,arg; u.namep / u.namep points to name
 30347 0000A539 E8B8050000          <1> 	call	namei
 30348                              <1> 		; jsr r0,namei / find the i-number associated 
 30349                              <1> 			     ; / with the path name
 30350                              <1> 	;jc	error
 30351                              <1> 		; br error9 / not found
 30352 0000A53E 730F                <1> 	jnc	short sysunlink1
 30353                              <1> 	; 'file not found !' error
 30354 0000A540 C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 30355 0000A548 0000                <1>
 30356 0000A54A E9EBF6FFFF          <1> 	jmp	error
 30357                              <1> sysunlink1:
 30358 0000A54F 6650                <1> 	push	ax
 30359                              <1> 		; mov r1,-(sp) / put its i-number on the stack
 30360 0000A551 E8A6FFFFFF          <1> 	call	isdir
 30361                              <1> 		; jsr r0,isdir / is it a directory
 30362 0000A556 6631C0              <1> 	xor 	ax, ax
 30363 0000A559 66A3[0AD50000]      <1> 	mov	[u.dirbuf], ax ; 0
 30364                              <1> 		; clr u.dirbuf / no, clear the location that will
 30365                              <1> 			   ; / get written into the i-number portion
 30366                              <1> 			 ; / of the entry
 30367 0000A55F 832D[F4D40000]10    <1> 	sub	dword [u.off], 16 ; 04/12/2015 (10 -> 16) 
 30368                              <1> 		; sub $10.,u.off / move u.off back 1 directory entry
 30369 0000A566 E86E000000          <1> 	call	wdir
 30370                              <1> 		; jsr r0,wdir / free the directory entry
 30371 0000A56B 6658                <1> 	pop	ax
 30372                              <1> 		; mov (sp)+,r1 / get i-number back
 30373 0000A56D E8200C0000          <1> 	call	iget
 30374                              <1> 		; jsr r0,iget / get i-node
 30375 0000A572 E8290C0000          <1> 	call	setimod
 30376                              <1> 		; jsr r0,setimod / set modified flag
 30377 0000A577 FE0D[AED10000]      <1> 	dec	byte [i.nlks]
 30378                              <1> 		; decb i.nlks / decrement the number of links
 30379 0000A57D 0F85D7F6FFFF        <1> 	jnz	sysret
 30380                              <1> 		; bgt sysret9 / if this was not the last link
 30381                              <1> 			    ; / to file return
 30382                              <1> 	; AX = r1 = i-number
 30383 0000A583 E893090000          <1> 	call	anyi
 30384                              <1> 		; jsr r0,anyi / if it was, see if anyone has it open.
 30385                              <1> 			 ; / Then free contents of file and destroy it.
 30386 0000A588 E9CDF6FFFF          <1> 	jmp	sysret
 30387                              <1> 		; br sysret9
 30388                              <1> 
 30389                              <1> mkdir:
 30390                              <1> 	; 04/12/2015 (14 byte directory names)
 30391                              <1> 	; 12/10/2015
 30392                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
 30393                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
 30394                              <1> 	;
 30395                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
 30396                              <1> 	; by u.namep into the current directory.
 30397                              <1> 	;
 30398                              <1> 	; INPUTS ->
 30399                              <1> 	;    u.namep - points to a file name 
 30400                              <1> 	;	           that is about to be a directory entry.
 30401                              <1> 	;    ii - current directory's i-number.	
 30402                              <1> 	; OUTPUTS ->
 30403                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name. 
 30404                              <1> 	;    u.off - points to entry to be filled 
 30405                              <1> 	;	     in the current directory		
 30406                              <1> 	;    u.base - points to start of u.dirbuf.
 30407                              <1> 	;    r1 - contains i-number of current directory 
 30408                              <1> 	;	
 30409                              <1> 	; ((AX = R1)) output
 30410                              <1> 	;
 30411                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
 30412                              <1>         ;    ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 30413                              <1> 	;
 30414                              <1> 
 30415                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 30416 0000A58D 31C0                <1> 	xor 	eax, eax
 30417 0000A58F BF[0CD50000]        <1> 	mov     edi, u.dirbuf+2
 30418 0000A594 89FE                <1> 	mov	esi, edi
 30419 0000A596 AB                  <1> 	stosd
 30420 0000A597 AB                  <1> 	stosd
 30421                              <1> 	; 04/12/2015 (14 byte directory names)
 30422 0000A598 AB                  <1> 	stosd
 30423 0000A599 66AB                <1> 	stosw
 30424                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
 30425 0000A59B 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
 30426                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 30427                              <1> 	;mov 	ebp, [u.namep]
 30428 0000A59D E899060000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 30429                              <1> 		; esi = physical address (page start + offset)
 30430                              <1> 		; ecx = byte count in the page (1 - 4096)
 30431                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 30432                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
 30433                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
 30434                              <1> mkdir_1: ; 1: 
 30435 0000A5A2 45                  <1> 	inc	ebp ; 12/10/2015
 30436                              <1> 	;
 30437                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
 30438                              <1> 	 ; 01/08/2013
 30439 0000A5A3 AC                  <1> 	lodsb
 30440                              <1> 		; movb (r2)+,r1 / move character in name to r1
 30441 0000A5A4 20C0                <1> 	and 	al, al
 30442 0000A5A6 7427                <1> 	jz 	short mkdir_3 	  
 30443                              <1> 		; beq 1f / if null, done
 30444 0000A5A8 3C2F                <1> 	cmp	al, '/'
 30445                              <1> 		; cmp r1,$'/ / is it a "/"?
 30446 0000A5AA 7414                <1> 	je	short mkdir_err
 30447                              <1> 	;je	error
 30448                              <1> 		; beq error9 / yes, error
 30449                              <1> 	; 12/10/2015
 30450 0000A5AC 6649                <1> 	dec	cx
 30451 0000A5AE 7505                <1> 	jnz	short mkdir_2
 30452                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 30453 0000A5B0 E88C060000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 30454                              <1> 		; esi = physical address (page start + offset)
 30455                              <1> 		; ecx = byte count in the page
 30456                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 30457                              <1> mkdir_2:
 30458 0000A5B5 81FF[1AD50000]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16) 
 30459                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
 30460                              <1> 				     ; / a char?
 30461 0000A5BB 74E5                <1> 	je	short mkdir_1
 30462                              <1> 		; beq 1b / yes, go back
 30463 0000A5BD AA                  <1> 	stosb
 30464                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
 30465 0000A5BE EBE2                <1> 	jmp 	short mkdir_1
 30466                              <1> 		; br 1b / get next char
 30467                              <1> mkdir_err:
 30468                              <1> 	; 17/06/2015
 30469 0000A5C0 C705[2DD50000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 30470 0000A5C8 0000                <1>
 30471 0000A5CA E96BF6FFFF          <1> 	jmp	error
 30472                              <1> 
 30473                              <1> mkdir_3: ; 1:
 30474 0000A5CF A1[ECD40000]        <1> 	mov	eax, [u.dirp]
 30475 0000A5D4 A3[F4D40000]        <1> 	mov	[u.off], eax
 30476                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
 30477                              <1> 				 ; / slot to u.off
 30478                              <1> wdir: ; 29/04/2013
 30479 0000A5D9 C705[F8D40000]-     <1>         mov     dword [u.base], u.dirbuf
 30480 0000A5DF [0AD50000]          <1>
 30481                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
 30482 0000A5E3 C705[FCD40000]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
 30483 0000A5EB 0000                <1>
 30484                              <1> 		; mov $10.,u.count / u.count = 10
 30485 0000A5ED 66A1[B8D40000]      <1> 	mov	ax, [ii] 
 30486                              <1> 		; mov ii,r1 / r1 has i-number of current directory
 30487 0000A5F3 B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
 30488 0000A5F5 E8AA0B0000          <1> 	call 	access
 30489                              <1> 		; jsr r0,access; 1 / get i-node and set its file up 
 30490                              <1> 				 ; / for writing
 30491                              <1> 	; AX = i-number of current directory
 30492                              <1> 	; 01/08/2013
 30493 0000A5FA FE05[3FD50000]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign	
 30494 0000A600 E8910B0000          <1> 	call	writei
 30495                              <1> 		; jsr r0,writei / write into directory
 30496 0000A605 C3                  <1> 	retn	
 30497                              <1> 		; rts r0
 30498                              <1> 
 30499                              <1> sysexec:
 30500                              <1> 	; 23/10/2015
 30501                              <1> 	; 19/10/2015
 30502                              <1> 	; 18/10/2015
 30503                              <1> 	; 10/10/2015
 30504                              <1> 	; 26/08/2015
 30505                              <1> 	; 05/08/2015
 30506                              <1> 	; 29/07/2015
 30507                              <1> 	; 25/07/2015
 30508                              <1> 	; 24/07/2015
 30509                              <1> 	; 21/07/2015
 30510                              <1> 	; 20/07/2015
 30511                              <1> 	; 02/07/2015
 30512                              <1> 	; 01/07/2015
 30513                              <1> 	; 25/06/2015
 30514                              <1> 	; 24/06/2015
 30515                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30516                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
 30517                              <1> 	;
 30518                              <1> 	; 'sysexec' initiates execution of a file whose path name if
 30519                              <1> 	; pointed to by 'name' in the sysexec call. 
 30520                              <1> 	; 'sysexec' performs the following operations:
 30521                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
 30522                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
 30523                              <1> 	;    3. sets trap vectors to system routines.
 30524                              <1> 	;    4. loads arguments to be passed to executing file into
 30525                              <1> 	;	highest locations of user's core
 30526                              <1> 	;    5. puts pointers to arguments in locations immediately
 30527                              <1> 	;	following arguments.
 30528                              <1> 	;    6.	saves number of arguments in next location.
 30529                              <1> 	;    7. intializes user's stack area so that all registers
 30530                              <1> 	;	will be zeroed and the PS is cleared and the PC set
 30531                              <1> 	;	to core when 'sysret' restores registers 
 30532                              <1> 	;	and does an rti.
 30533                              <1> 	;    8. inializes u.r0 and u.sp
 30534                              <1> 	;    9. zeros user's core down to u.r0
 30535                              <1> 	;   10.	reads executable file from storage device into core
 30536                              <1> 	;	starting at location 'core'.
 30537                              <1> 	;   11.	sets u.break to point to end of user's code with
 30538                              <1> 	;	data area appended.
 30539                              <1> 	;   12.	calls 'sysret' which returns control at location
 30540                              <1> 	;	'core' via 'rti' instruction. 		  		
 30541                              <1> 	;
 30542                              <1> 	; Calling sequence:
 30543                              <1> 	;	sysexec; namep; argp
 30544                              <1> 	; Arguments:
 30545                              <1> 	;	namep - points to pathname of file to be executed
 30546                              <1> 	;	argp  - address of table of argument pointers
 30547                              <1> 	;	argp1... argpn - table of argument pointers
 30548                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
 30549                              <1> 	; Inputs: (arguments)
 30550                              <1> 	; Outputs: -	
 30551                              <1> 	; ...............................................................
 30552                              <1> 	;
 30553                              <1> 	; Retro UNIX 386 v1 modification: 
 30554                              <1> 	;	User application runs in it's own virtual space 
 30555                              <1> 	;	which is izolated from kernel memory (and other
 30556                              <1> 	;	memory pages) via 80386	paging in ring 3 
 30557                              <1> 	;	privilige mode. Virtual start address is always 0.
 30558                              <1> 	;	User's core memory starts at linear address 400000h
 30559                              <1> 	;	(the end of the 1st 4MB).
 30560                              <1> 	;
 30561                              <1> 	; Retro UNIX 8086 v1 modification: 
 30562                              <1> 	;	user/application segment and system/kernel segment
 30563                              <1> 	;	are different and sysenter/sysret/sysrele routines
 30564                              <1> 	;	are different (user's registers are saved to 
 30565                              <1> 	;	and then restored from system's stack.)
 30566                              <1> 	;
 30567                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 30568                              <1> 	;	      arguments which were in these registers;
 30569                              <1> 	;	      but, it returns by putting the 1st argument
 30570                              <1> 	;	      in 'u.namep' and the 2nd argument
 30571                              <1> 	;	      on top of stack. (1st argument is offset of the
 30572                              <1> 	;	      file/path name in the user's program segment.)		 	
 30573                              <1> 	
 30574                              <1> 	;call	arg2
 30575                              <1> 	; * name - 'u.namep' points to address of file/path name
 30576                              <1> 	;          in the user's program segment ('u.segmnt')
 30577                              <1> 	;          with offset in BX register (as sysopen argument 1).
 30578                              <1> 	; * argp - sysexec argument 2 is in CX register 
 30579                              <1> 	;          which is on top of stack.
 30580                              <1> 	;
 30581                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
 30582                              <1> 
 30583                              <1> 	; 23/06/2015 (32 bit modifications)
 30584                              <1> 
 30585 0000A606 891D[F0D40000]      <1> 	mov	[u.namep], ebx ; argument 1
 30586                              <1>         ; 18/10/2015
 30587 0000A60C 890D[58D50000]      <1> 	mov     [argv], ecx  ; * ; argument 2
 30588 0000A612 E8DF040000          <1> 	call	namei
 30589                              <1> 		; jsr r0,namei / namei returns i-number of file 
 30590                              <1> 			     ; / named in sysexec call in r1
 30591                              <1> 	;jc	error
 30592                              <1> 		; br error9
 30593 0000A617 731E                <1> 	jnc	short sysexec_0
 30594                              <1> 	;
 30595                              <1> 	; 'file not found !' error
 30596 0000A619 C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND
 30597 0000A621 0000                <1>
 30598 0000A623 E912F6FFFF          <1> 	jmp	error 
 30599                              <1> sysexec_not_exf:
 30600                              <1> 	; 'not executable file !' error
 30601 0000A628 C705[2DD50000]1600- <1> 	mov	dword [u.error], ERR_NOT_EXECUTABLE
 30602 0000A630 0000                <1>
 30603 0000A632 E903F6FFFF          <1> 	jmp	error 
 30604                              <1> sysexec_0:
 30605 0000A637 E8560B0000          <1> 	call	iget
 30606                              <1> 		; jsr r0,iget / get i-node for file to be executed
 30607 0000A63C 66F705[ACD10000]10- <1>         test    word [i.flgs], 10h
 30608 0000A644 00                  <1>
 30609                              <1> 		; bit $20,i.flgs / is file executable
 30610 0000A645 74E1                <1> 	jz	short sysexec_not_exf
 30611                              <1> 	;jz	error
 30612                              <1> 		; beq error9
 30613                              <1> 	;;
 30614 0000A647 E8500B0000          <1> 	call	iopen
 30615                              <1> 		; jsr r0,iopen / gets i-node for file with i-number
 30616                              <1> 			     ; / given in r1 (opens file)
 30617                              <1> 	; AX = i-number of the file
 30618 0000A64C 66F705[ACD10000]20- <1> 	test	word [i.flgs], 20h
 30619 0000A654 00                  <1>
 30620                              <1> 		; bit $40,i.flgs / test user id on execution bit
 30621 0000A655 7415                <1> 	jz	short sysexec_1
 30622                              <1> 		; beq 1f
 30623 0000A657 803D[24D50000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013
 30624                              <1> 		; tstb u.uid / test user id
 30625 0000A65E 760C                <1> 	jna	short sysexec_1
 30626                              <1> 		; beq 1f / super user
 30627 0000A660 8A0D[AFD10000]      <1> 	mov	cl, [i.uid]
 30628 0000A666 880D[24D50000]      <1> 	mov	[u.uid], cl ; 02/08/2013
 30629                              <1> 		; movb i.uid,u.uid / put user id of owner of file
 30630                              <1> 				 ; / as process user id
 30631                              <1> sysexec_1:
 30632                              <1> 	; 18/10/2215
 30633                              <1> 	; 10/10/2015
 30634                              <1> 	; 24/07/2015
 30635                              <1> 	; 21/07/2015
 30636                              <1> 	; 25/06/2015
 30637                              <1> 	; 24/06/2015
 30638                              <1>         ; Moving arguments to the end of [u.upage]
 30639                              <1> 	; (by regarding page borders in user's memory space)
 30640                              <1> 	;
 30641                              <1> 	; 10/10/2015
 30642                              <1> 	; 21/07/2015
 30643 0000A66C 89E5                <1> 	mov	ebp, esp ; (**)
 30644                              <1> 	; 18/10/2015
 30645 0000A66E 89EF                <1> 	mov 	edi, ebp
 30646 0000A670 B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
 30647                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
 30648 0000A675 29CF                <1> 	sub	edi, ecx
 30649 0000A677 89FC                <1> 	mov	esp, edi
 30650 0000A679 31C0                <1> 	xor	eax, eax
 30651 0000A67B A3[00D50000]        <1> 	mov 	[u.nread], eax ; 0
 30652 0000A680 49                  <1> 	dec	ecx ; 256 - 1
 30653 0000A681 890D[FCD40000]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
 30654                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
 30655                              <1> sysexec_2:
 30656 0000A687 8B35[58D50000]      <1> 	mov	esi, [argv] ; 18/10/2015 
 30657 0000A68D E873020000          <1> 	call	get_argp
 30658 0000A692 B904000000          <1> 	mov	ecx, 4 ; mov ecx, 4
 30659                              <1> sysexec_3:
 30660 0000A697 21C0                <1> 	and	eax, eax
 30661 0000A699 7456                <1> 	jz	short sysexec_6
 30662                              <1> 	; 18/10/2015
 30663 0000A69B 010D[58D50000]      <1> 	add	[argv], ecx ; 4
 30664 0000A6A1 66FF05[56D50000]    <1> 	inc	word [argc]
 30665                              <1> 	;
 30666 0000A6A8 A3[F8D40000]        <1> 	mov	[u.base], eax
 30667                              <1>  	; 23/10/2015
 30668 0000A6AD 66C705[3DD50000]00- <1> 	mov	word [u.pcount], 0
 30669 0000A6B5 00                  <1>
 30670                              <1> sysexec_4:
 30671 0000A6B6 E8EA0A0000          <1> 	call	cpass ; get a character from user's core memory
 30672 0000A6BB 750B                <1>         jnz      short sysexec_5
 30673                              <1> 		; (max. 255 chars + null)
 30674                              <1> 	; 18/10/2015
 30675 0000A6BD 28C0                <1> 	sub 	al, al
 30676 0000A6BF AA                  <1> 	stosb
 30677 0000A6C0 FF05[00D50000]      <1> 	inc	dword [u.nread]
 30678 0000A6C6 EB29                <1> 	jmp	short sysexec_6
 30679                              <1> sysexec_5:
 30680 0000A6C8 AA                  <1> 	stosb
 30681 0000A6C9 20C0                <1> 	and 	al, al
 30682 0000A6CB 75E9                <1> 	jnz	short sysexec_4
 30683 0000A6CD B904000000          <1> 	mov	ecx, 4
 30684 0000A6D2 390D[54D50000]      <1> 	cmp	[ncount], ecx ; 4
 30685 0000A6D8 72AD                <1> 	jb	short sysexec_2
 30686 0000A6DA 8B35[50D50000]      <1> 	mov	esi, [nbase]
 30687 0000A6E0 010D[50D50000]      <1> 	add	[nbase], ecx ; 4	
 30688 0000A6E6 66290D[54D50000]    <1> 	sub	[ncount], cx 
 30689 0000A6ED 8B06                <1> 	mov	eax, [esi]
 30690 0000A6EF EBA6                <1> 	jmp	short sysexec_3
 30691                              <1> sysexec_6:
 30692                              <1> 	; 18/10/2015
 30693                              <1> 	; argument list transfer from user's core memory to
 30694                              <1> 	; kernel stack frame is OK here.
 30695                              <1> 	; [u.nread] = ; argument list length
 30696                              <1> 	;mov	[argv], esp ; start address of argument list 	
 30697                              <1> 	;
 30698                              <1> 	; 18/10/2015
 30699                              <1> 	; 24/07/2015
 30700                              <1>         ; 21/07/2015
 30701                              <1> 	; 02/07/2015
 30702                              <1> 	; 25/06/2015
 30703                              <1> 	; 24/06/2015
 30704                              <1> 	; 23/06/2015
 30705                              <1> 	;
 30706 0000A6F1 8B1D[35D50000]      <1> 	mov	ebx, [u.ppgdir] ; parent's page directory
 30707 0000A6F7 21DB                <1> 	and 	ebx, ebx  ; /etc/init ? (u.ppgdir = 0)	
 30708 0000A6F9 740A                <1> 	jz	short sysexec_7
 30709 0000A6FB A1[31D50000]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
 30710 0000A700 E83B8BFFFF          <1> 	call	deallocate_page_dir
 30711                              <1> sysexec_7:
 30712 0000A705 E86B8AFFFF          <1> 	call	make_page_dir
 30713                              <1> 	;jc	short sysexec_14
 30714 0000A70A 0F820D98FFFF        <1> 	jc	panic  ; allocation error 
 30715                              <1> 		       ; after a deallocation would be nonsence !?
 30716                              <1> 	; 24/07/2015
 30717                              <1> 	; map kernel pages (1st 4MB) to PDE 0
 30718                              <1> 	;     of the user's page directory
 30719                              <1> 	;     (It is needed for interrupts!)
 30720                              <1> 	; 18/10/2015
 30721 0000A710 8B15[78C40000]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
 30722 0000A716 8B02                <1> 	mov	eax, [edx] ; physical address of
 30723                              <1> 			   ; kernel's first page table (1st 4 MB)
 30724                              <1> 			   ; (PDE 0 of kernel's page directory)
 30725 0000A718 8B15[31D50000]      <1> 	mov 	edx, [u.pgdir]
 30726 0000A71E 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
 30727                              <1> 	;
 30728                              <1> 	; 20/07/2015
 30729 0000A720 BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
 30730                              <1> 	; 18/10/2015
 30731 0000A725 BE[48D50000]        <1> 	mov	esi, pcore ; physical start address
 30732                              <1> sysexec_8:	
 30733 0000A72A B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
 30734 0000A72F E85F8AFFFF          <1> 	call	make_page_table
 30735 0000A734 0F82E397FFFF        <1> 	jc	panic
 30736                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
 30737 0000A73A E8628AFFFF          <1> 	call	make_page ; make new page, clear and set the pte 
 30738 0000A73F 0F82D897FFFF        <1> 	jc	panic
 30739                              <1> 	;
 30740 0000A745 8906                <1> 	mov	[esi], eax ; 24/06/2015
 30741                              <1> 	; ebx = virtual address (24/07/2015)
 30742 0000A747 E8788FFFFF          <1> 	call 	add_to_swap_queue
 30743                              <1> 	; 18/10/2015
 30744 0000A74C 81FE[4CD50000]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
 30745 0000A752 740C                <1> 	je	short sysexec_9 ; yes
 30746 0000A754 BE[4CD50000]        <1> 	mov	esi, ecore  ; physical address of the last page 
 30747                              <1> 	; 20/07/2015
 30748 0000A759 BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
 30749                              <1> 	; ebx = virtual end address + segment base address - 4K
 30750 0000A75E EBCA                <1>         jmp     short sysexec_8
 30751                              <1> 
 30752                              <1> sysexec_9:
 30753                              <1> 	; 18/10/2015
 30754                              <1> 	; 26/08/2015
 30755                              <1> 	; 25/06/2015
 30756                              <1> 	; move arguments from kernel stack to [ecore]
 30757                              <1> 	; (argument list/line will be copied from kernel stack
 30758                              <1> 	; frame to the last (stack) page of user's core memory)
 30759                              <1> 	; 18/10/2015
 30760 0000A760 8B3D[4CD50000]      <1> 	mov	edi, [ecore]
 30761 0000A766 81C700100000        <1> 	add	edi, PAGE_SIZE
 30762 0000A76C 0FB705[56D50000]    <1> 	movzx	eax, word [argc]
 30763 0000A773 09C0                <1> 	or	eax, eax
 30764 0000A775 7509                <1> 	jnz	short sysexec_10
 30765 0000A777 89FB                <1> 	mov 	ebx, edi
 30766 0000A779 83EB04              <1> 	sub	ebx, 4 
 30767 0000A77C 8903                <1> 	mov	[ebx], eax ; 0
 30768 0000A77E EB40                <1> 	jmp 	short sysexec_13
 30769                              <1> sysexec_10:
 30770 0000A780 8B0D[00D50000]      <1> 	mov	ecx, [u.nread]
 30771                              <1> 	;mov 	esi, [argv}
 30772 0000A786 89E6                <1> 	mov	esi, esp ; start address of argument list
 30773 0000A788 29CF                <1> 	sub	edi, ecx ; page end address - argument list length
 30774 0000A78A 89C2                <1> 	mov	edx, eax
 30775 0000A78C FEC2                <1> 	inc	dl ; argument count + 1 for argc value  
 30776 0000A78E C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
 30777 0000A791 89FB                <1> 	mov	ebx, edi
 30778 0000A793 80E3FC              <1> 	and	bl, 0FCh ; 32 bit (dword) alignment
 30779 0000A796 29D3                <1> 	sub 	ebx, edx
 30780 0000A798 89FA                <1> 	mov	edx, edi
 30781 0000A79A F3A4                <1> 	rep	movsb
 30782 0000A79C 89D6                <1> 	mov 	esi, edx
 30783 0000A79E 89DF                <1> 	mov 	edi, ebx
 30784 0000A7A0 BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
 30785 0000A7A5 2B15[4CD50000]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical) 
 30786 0000A7AB AB                  <1> 	stosd	; eax = argument count	
 30787                              <1> sysexec_11:
 30788 0000A7AC 89F0                <1> 	mov	eax, esi
 30789 0000A7AE 01D0                <1> 	add	eax, edx
 30790 0000A7B0 AB                  <1> 	stosd  ; eax = virtual address
 30791 0000A7B1 FE0D[56D50000]      <1> 	dec	byte [argc]
 30792 0000A7B7 7407                <1> 	jz	short sysexec_13
 30793                              <1> sysexec_12:
 30794 0000A7B9 AC                  <1> 	lodsb
 30795 0000A7BA 20C0                <1> 	and	al, al
 30796 0000A7BC 75FB                <1> 	jnz	short sysexec_12
 30797 0000A7BE EBEC                <1> 	jmp	short sysexec_11
 30798                              <1> 	;
 30799                              <1> 	; 1:
 30800                              <1> 		; mov (sp)+,r5 / r5 now contains address of list of 
 30801                              <1> 			     ; / pointers to arguments to be passed
 30802                              <1> 		; mov $1,u.quit / u.quit determines handling of quits;
 30803                              <1> 			      ; / u.quit = 1 take quit
 30804                              <1> 		; mov $1,u.intr / u.intr determines handling of 
 30805                              <1> 			     ; / interrupts; u.intr = 1 take interrupt
 30806                              <1> 		; mov $rtssym,30 / emt trap vector set to take 
 30807                              <1> 			       ; / system routine
 30808                              <1> 		; mov $fpsym,*10 / reserved instruction trap vector 
 30809                              <1> 			       ; / set to take system routine
 30810                              <1> 		; mov $sstack,sp / stack space used during swapping
 30811                              <1> 		; mov r5,-(sp) / save arguments pointer on stack
 30812                              <1> 		; mov $ecore,r5 / r5 has end of core
 30813                              <1> 		; mov $core,r4 / r4 has start of users core
 30814                              <1> 		; mov r4,u.base / u.base has start of users core
 30815                              <1> 		; mov (sp),r2 / move arguments list pointer into r2
 30816                              <1> 	; 1:
 30817                              <1> 		; tst (r2)+ / argument char = "nul"
 30818                              <1> 		; bne 1b
 30819                              <1> 		; tst -(r2) / decrement r2 by 2; r2 has addr of 
 30820                              <1> 			  ; / end of argument pointer list
 30821                              <1> 	; 1:
 30822                              <1> 	     ; / move arguments to bottom of users core
 30823                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 30824                              <1> 		; cmp r2,(sp) / is r2 = beginning of argument
 30825                              <1> 			    ; / ptr list
 30826                              <1> 		; blo 1f / branch to 1f when all arguments
 30827                              <1> 		       ; / are moved
 30828                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 30829                              <1> 	; 2:
 30830                              <1> 		; tstb (r3)+
 30831                              <1> 		; bne 2b / scan argument for \0 (nul)
 30832                              <1> 
 30833                              <1> 	; 2:
 30834                              <1> 		; movb -(r3),-(r5) / move argument char 
 30835                              <1> 				 ; / by char starting at "ecore"
 30836                              <1> 		; cmp r3,(r2) / moved all characters in 
 30837                              <1> 			    ; / this argument
 30838                              <1> 		; bhi 2b / branch 2b if not
 30839                              <1> 		; mov r5,(r4)+ / move r5 into top of users core;
 30840                              <1> 			     ; / r5 has pointer to nth arg
 30841                              <1> 		; br 1b / string
 30842                              <1> 	; 1:
 30843                              <1> 		; clrb -(r5)
 30844                              <1> 		; bic $1,r5 / make r5 even, r5 points to 
 30845                              <1> 			; / last word of argument strings
 30846                              <1> 		; mov $core,r2
 30847                              <1> 	
 30848                              <1> 	; 1: / move argument pointers into core following 
 30849                              <1> 	      ; / argument strings
 30850                              <1> 		; cmp r2,r4
 30851                              <1> 		; bhis 1f / branch to 1f when all pointers
 30852                              <1> 			; / are moved
 30853                              <1> 		; mov (r2)+,-(r5)
 30854                              <1> 		; br 1b
 30855                              <1> 	; 1:
 30856                              <1> 		; sub $core,r4 / gives number of arguments *2
 30857                              <1> 		; asr r4 / divide r4 by 2 to calculate 
 30858                              <1> 		       ; / the number of args stored
 30859                              <1> 		; mov r4,-(r5) / save number of arguments ahead
 30860                              <1> 			     ; / of the argument pointers
 30861                              <1> sysexec_13:
 30862                              <1> 	; 19/10/2015
 30863                              <1> 	; 18/10/2015
 30864                              <1> 	; 29/07/2015
 30865                              <1> 	; 25/07/2015
 30866                              <1> 	; 24/07/2015
 30867                              <1> 	; 20/07/2015
 30868                              <1> 	; 25/06/2015
 30869                              <1> 	; 24/06/2015
 30870                              <1> 	; 23/06/2015
 30871                              <1> 	;
 30872                              <1> 	; moving arguments to [ecore] is OK here..
 30873                              <1> 	; 18/10/2015
 30874 0000A7C0 89EC                <1> 	mov 	esp, ebp ; (**) restore kernel stack pointer
 30875                              <1> 	; ebx = beginning addres of argument list pointers
 30876                              <1> 	;	in user's stack
 30877                              <1> 	; 19/10/2015
 30878 0000A7C2 2B1D[4CD50000]      <1> 	sub 	ebx, [ecore]
 30879 0000A7C8 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
 30880                              <1> 			; end of core - 4096 (last page)
 30881                              <1> 			; (virtual address)
 30882 0000A7CE 891D[58D50000]      <1> 	mov	[argv], ebx
 30883 0000A7D4 891D[04D50000]      <1> 	mov	[u.break], ebx ; available user memory
 30884                              <1> 	;
 30885 0000A7DA 29C0                <1> 	sub	eax, eax
 30886 0000A7DC C705[FCD40000]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
 30887 0000A7E4 0000                <1>
 30888                              <1> 		; mov $14,u.count
 30889 0000A7E6 C705[E8D40000]-     <1> 	mov	dword [u.fofp], u.off
 30890 0000A7EC [F4D40000]          <1>
 30891                              <1> 		; mov $u.off,u.fofp
 30892 0000A7F0 A3[F4D40000]        <1> 	mov	[u.off], eax ; 0
 30893                              <1> 		; clr u.off / set offset in file to be read to zero
 30894                              <1> 	; 25/07/2015
 30895 0000A7F5 A3[F8D40000]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
 30896                              <1> 	; 25/06/2015 
 30897 0000A7FA 66A1[B8D40000]      <1> 	mov	ax, [ii]
 30898                              <1> 	; AX = i-number of the executable file
 30899 0000A800 E892090000          <1> 	call	readi
 30900                              <1> 		; jsr r0,readi / read in first six words of 
 30901                              <1> 			; / user's file, starting at $core
 30902                              <1> 		; mov sp,r5 / put users stack address in r5
 30903                              <1> 		; sub $core+40.,r5 / subtract $core +40, 
 30904                              <1> 				; / from r5 (leaves number of words
 30905                              <1> 				; / less 26 available for
 30906                              <1> 			     	; / program in user core
 30907                              <1> 		; mov r5,u.count /
 30908                              <1> 	; 25/06/2015
 30909 0000A805 8B0D[04D50000]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
 30910 0000A80B 890D[FCD40000]      <1> 	mov	[u.count], ecx ; save for overrun check
 30911                              <1> 	;
 30912 0000A811 8B0D[00D50000]      <1> 	mov	ecx, [u.nread]
 30913 0000A817 890D[04D50000]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
 30914 0000A81D 80F920              <1> 	cmp	cl, 32
 30915 0000A820 7540                <1>         jne     short sysexec_15
 30916                              <1> 	;:
 30917                              <1> 	; 25/06/2015
 30918                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
 30919                              <1> 	; 18/10/2015
 30920 0000A822 8B35[48D50000]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
 30921                              <1> 		             ; (phys. start addr. of the exec. file)
 30922 0000A828 AD                  <1> 	lodsd
 30923 0000A829 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
 30924 0000A82D 7533                <1> 	jne	short sysexec_15
 30925                              <1> 		; cmp core,$405 / br .+14 is first instruction 
 30926                              <1> 			      ; / if file is standard a.out format
 30927                              <1> 		; bne 1f / branch, if not standard format
 30928 0000A82F AD                  <1> 	lodsd
 30929 0000A830 89C1                <1> 	mov	ecx, eax ; text (code) section size
 30930 0000A832 AD                  <1> 	lodsd
 30931 0000A833 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
 30932                              <1> 		; mov core+2,r5 / put 2nd word of users program in r5;
 30933                              <1> 		              ; / number of bytes in program text	
 30934                              <1> 		; sub $14,r5 / subtract 12
 30935 0000A835 89CB                <1> 	mov	ebx, ecx
 30936                              <1> 	;
 30937                              <1> 	; 25/06/2015
 30938                              <1> 	; NOTE: These are for next versions of Retro UNIX 386
 30939                              <1> 	;	and SINGLIX operating systems (as code template).
 30940                              <1> 	;	Current Retro UNIX 386 v1 files can be max. 64KB
 30941                              <1> 	;	due to RUFS (floppy disk file system) restriction...
 30942                              <1> 	;	Overrun is not possible for current version. 	
 30943                              <1> 	;
 30944 0000A837 AD                  <1> 	lodsd	
 30945 0000A838 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
 30946 0000A83A 3B1D[FCD40000]      <1> 	cmp	ebx, [u.count]
 30947 0000A840 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
 30948                              <1> 	;
 30949                              <1> 	; 24/07/2015
 30950                              <1> 	; add bss section size to [u.break]
 30951 0000A842 0105[04D50000]      <1> 	add 	[u.break], eax
 30952                              <1> 	;
 30953 0000A848 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
 30954                              <1> 	;cmp	ecx, [u.count]
 30955                              <1> 	;jnb	short sysexec_16
 30956                              <1> 		; cmp r5,u.count /
 30957                              <1> 		; bgt 1f / branch if r5 greater than u.count
 30958 0000A84B 890D[FCD40000]      <1> 	mov	[u.count], ecx ; required read count
 30959                              <1> 		; mov r5,u.count
 30960                              <1> 	;
 30961 0000A851 EB2A                <1> 	jmp	short sysexec_16
 30962                              <1> 	;
 30963                              <1> sysexec_14:
 30964                              <1> 	; 23/06/2015
 30965                              <1> 	; insufficient (out of) memory
 30966 0000A853 C705[2DD50000]0100- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
 30967 0000A85B 0000                <1>
 30968 0000A85D E9D8F3FFFF          <1> 	jmp	error
 30969                              <1> 	;
 30970                              <1> sysexec_15:
 30971                              <1> 	; 25/06/2015
 30972 0000A862 0FB715[B0D10000]    <1>         movzx   edx, word [i.size] ; file size
 30973 0000A869 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
 30974 0000A86B 7627                <1> 	jna	short sysexec_17 ; no need to next read
 30975 0000A86D 01D1                <1> 	add	ecx, edx ; [i.size]
 30976 0000A86F 3B0D[FCD40000]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
 30977 0000A875 77DC                <1> 	ja	short sysexec_14
 30978 0000A877 8915[FCD40000]      <1> 	mov	[u.count], edx
 30979                              <1> sysexec_16:
 30980 0000A87D 66A1[B8D40000]      <1> 	mov	ax, [ii] ; i-number
 30981 0000A883 E80F090000          <1> 	call	readi
 30982                              <1> 		; add core+10,u.nread / add size of user data area 
 30983                              <1> 		                    ; / to u.nread
 30984                              <1> 		; br 2f
 30985                              <1> 	; 1:
 30986                              <1> 		; jsr r0,readi / read in rest of file
 30987                              <1> 	; 2:
 30988 0000A888 8B0D[00D50000]      <1> 	mov	ecx, [u.nread]
 30989 0000A88E 010D[04D50000]      <1> 	add	[u.break], ecx
 30990                              <1> 		; mov u.nread,u.break / set users program break to end of 
 30991                              <1> 				    ; / user code
 30992                              <1> 		; add $core+14,u.break / plus data area
 30993                              <1> sysexec_17: ; 20/07/2015
 30994                              <1> 	;mov	ax, [ii] ;rgc i-number
 30995 0000A894 E804090000          <1> 	call	iclose
 30996                              <1> 		; jsr r0,iclose / does nothing
 30997 0000A899 31C0                <1>         xor     eax, eax
 30998 0000A89B FEC0                <1> 	inc	al
 30999 0000A89D 66A3[1CD50000]      <1> 	mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
 31000 0000A8A3 66A3[1ED50000]      <1> 	mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled) 
 31001                              <1> 	; 02/07/2015
 31002 0000A8A9 833D[35D50000]00    <1>         cmp	dword [u.ppgdir], 0  ; is the caller sys_init (kernel) ?
 31003 0000A8B0 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
 31004                              <1> 	; If the caller is kernel (sys_init), 'sysexec' will come here
 31005 0000A8B2 8B15[78C40000]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
 31006 0000A8B8 8915[35D50000]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here 
 31007                              <1> sysexec_18:
 31008                              <1> 	; 18/10/2015
 31009                              <1> 	; 05/08/2015
 31010                              <1> 	; 29/07/2015
 31011 0000A8BE 8B2D[58D50000]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
 31012                              <1> 			    ; list pointers (argument count)
 31013 0000A8C4 FA                  <1> 	cli
 31014 0000A8C5 8B25[14C40000]      <1>         mov     esp, [tss.esp0]  ; ring 0 (kernel) stack pointer
 31015                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
 31016                              <1> 			    ; for this process	 
 31017                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
 31018                              <1> 	;xor	eax, eax ; 0
 31019 0000A8CB FEC8                <1> 	dec	al ; eax = 0
 31020 0000A8CD 66BA2300            <1> 	mov	dx, UDATA
 31021 0000A8D1 6652                <1> 	push	dx  ; user's stack segment
 31022 0000A8D3 55                  <1> 	push	ebp ; user's stack pointer
 31023                              <1> 		    ; (points to number of arguments)
 31024 0000A8D4 FB                  <1> 	sti
 31025 0000A8D5 9C                  <1> 	pushfd	; EFLAGS
 31026                              <1> 		; Set IF for enabling interrupts in user mode	
 31027                              <1> 	;or	dword [esp], 200h 
 31028                              <1> 	;
 31029                              <1> 	;mov	bx, UCODE
 31030                              <1> 	;push	bx ; user's code segment
 31031 0000A8D6 6A1B                <1> 	push	UCODE
 31032                              <1> 	;push	0
 31033 0000A8D8 50                  <1> 	push	eax ; EIP (=0) - start address -	
 31034                              <1> 		; clr -(r5) / popped into ps when rti in 
 31035                              <1> 			  ; / sysrele is executed
 31036                              <1> 		; mov $core,-(r5) / popped into pc when rti 
 31037                              <1> 		                ; / in sysrele is executed
 31038                              <1> 		;mov r5,0f / load second copyz argument
 31039                              <1> 		;tst -(r5) / decrement r5
 31040 0000A8D9 8925[D0D40000]      <1> 	mov	[u.sp], esp ; 29/07/2015
 31041                              <1> 	; 05/08/2015
 31042                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
 31043                              <1> 	; ('push dx' would cause to general protection fault, 
 31044                              <1> 	; after 'pop ds' etc.)
 31045                              <1> 	;
 31046                              <1> 	;; push dx ; ds (UDATA)
 31047                              <1> 	;; push dx ; es (UDATA)
 31048                              <1> 	;; push dx ; fs (UDATA)
 31049                              <1> 	;; push dx ; gs (UDATA)
 31050                              <1> 	;
 31051                              <1> 	; This is a trick to prevent general protection fault
 31052                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
 31053 0000A8DF 8EC2                <1> 	mov 	es, dx ; UDATA
 31054 0000A8E1 06                  <1> 	push 	es ; ds (UDATA)
 31055 0000A8E2 06                  <1> 	push 	es ; es (UDATA)
 31056 0000A8E3 06                  <1> 	push 	es ; fs (UDATA)
 31057 0000A8E4 06                  <1> 	push	es ; gs (UDATA)
 31058 0000A8E5 66BA1000            <1> 	mov	dx, KDATA
 31059 0000A8E9 8EC2                <1> 	mov	es, dx
 31060                              <1> 	;
 31061                              <1> 	;; pushad simulation
 31062 0000A8EB 89E5                <1> 	mov	ebp, esp ; esp before pushad
 31063 0000A8ED 50                  <1> 	push	eax ; eax (0)
 31064 0000A8EE 50                  <1> 	push	eax ; ecx (0)
 31065 0000A8EF 50                  <1> 	push	eax ; edx (0)
 31066 0000A8F0 50                  <1> 	push	eax ; ebx (0)
 31067 0000A8F1 55                  <1> 	push	ebp ; esp before pushad
 31068 0000A8F2 50                  <1> 	push	eax ; ebp (0)
 31069 0000A8F3 50                  <1> 	push	eax ; esi (0)		
 31070 0000A8F4 50                  <1> 	push	eax ; edi (0)	
 31071                              <1> 	;
 31072 0000A8F5 A3[D8D40000]        <1> 	mov	[u.r0], eax ; eax = 0
 31073 0000A8FA 8925[D4D40000]      <1> 	mov	[u.usp], esp
 31074                              <1> 		; mov r5,u.r0 /
 31075                              <1> 		; sub $16.,r5 / skip 8 words
 31076                              <1> 		; mov r5,u.sp / assign user stack pointer value, 
 31077                              <1> 		;             / effectively zeroes all regs
 31078                              <1> 			    ; / when sysrele is executed
 31079                              <1> 		; jsr r0,copyz; core; 0:0 / zero user's core
 31080                              <1> 		; clr u.break
 31081                              <1> 		; mov r5,sp / point sp to user's stack
 31082                              <1> 	;
 31083 0000A900 E958F3FFFF          <1> 	jmp	sysret0
 31084                              <1> 	;jmp	sysret
 31085                              <1> 		; br sysret3 / return to core image at $core
 31086                              <1> 
 31087                              <1> get_argp:
 31088                              <1> 	; 18/10/2015 (nbase, ncount)
 31089                              <1> 	; 21/07/2015
 31090                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
 31091                              <1> 	; Get (virtual) address of argument from user's core memory
 31092                              <1> 	;
 31093                              <1> 	; INPUT:
 31094                              <1> 	;	esi = virtual address of argument pointer
 31095                              <1> 	; OUTPUT:
 31096                              <1> 	;	eax = virtual address of argument
 31097                              <1> 	;
 31098                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
 31099                              <1> 	;
 31100 0000A905 833D[35D50000]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
 31101                              <1> 				    ; (the caller is kernel)
 31102 0000A90C 7667                <1>         jna     short get_argpk 
 31103                              <1> 	;
 31104 0000A90E 89F3                <1>      	mov	ebx, esi
 31105 0000A910 E8858EFFFF          <1> 	call	get_physical_addr ; get physical address
 31106 0000A915 0F8289000000        <1>         jc      get_argp_err
 31107 0000A91B A3[50D50000]        <1> 	mov 	[nbase], eax ; physical address	
 31108 0000A920 66890D[54D50000]    <1> 	mov	[ncount], cx ; remain byte count in page (1-4096)
 31109 0000A927 B804000000          <1> 	mov	eax, 4 ; 21/07/2015
 31110 0000A92C 6639C1              <1> 	cmp	cx, ax ; 4
 31111 0000A92F 735D                <1> 	jnb	short get_argp2
 31112 0000A931 89F3                <1> 	mov	ebx, esi
 31113 0000A933 01CB                <1> 	add	ebx, ecx
 31114 0000A935 E8608EFFFF          <1> 	call	get_physical_addr ; get physical address
 31115 0000A93A 7268                <1> 	jc	short get_argp_err
 31116                              <1> 	;push	esi
 31117 0000A93C 89C6                <1> 	mov	esi, eax
 31118 0000A93E 66870D[54D50000]    <1> 	xchg	cx, [ncount]
 31119 0000A945 8735[50D50000]      <1> 	xchg	esi, [nbase]
 31120 0000A94B B504                <1> 	mov	ch, 4
 31121 0000A94D 28CD                <1> 	sub	ch, cl
 31122                              <1> get_argp0:
 31123 0000A94F AC                  <1> 	lodsb
 31124 0000A950 6650                <1> 	push	ax
 31125 0000A952 FEC9                <1> 	dec	cl
 31126 0000A954 75F9                <1>         jnz     short get_argp0
 31127 0000A956 8B35[50D50000]      <1> 	mov	esi, [nbase]
 31128                              <1> 	; 21/07/2015
 31129 0000A95C 0FB6C5              <1> 	movzx	eax, ch
 31130 0000A95F 0105[50D50000]      <1> 	add	[nbase], eax
 31131 0000A965 662905[54D50000]    <1> 	sub	[ncount], ax
 31132                              <1> get_argp1:
 31133 0000A96C AC                  <1> 	lodsb
 31134 0000A96D FECD                <1> 	dec	ch
 31135 0000A96F 743D                <1>         jz      short get_argp3
 31136 0000A971 6650                <1>         push	ax
 31137 0000A973 EBF7                <1> 	jmp     short get_argp1
 31138                              <1> get_argpk:
 31139                              <1> 	; Argument is in kernel's memory space
 31140 0000A975 66C705[54D50000]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
 31141 0000A97D 10                  <1>
 31142 0000A97E 8935[50D50000]      <1> 	mov	[nbase], esi
 31143 0000A984 8305[50D50000]04    <1> 	add	dword [nbase], 4
 31144 0000A98B 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physcal addr.
 31145 0000A98D C3                  <1> 	retn
 31146                              <1> get_argp2:
 31147                              <1> 	; 21/07/2015
 31148                              <1> 	;mov	eax, 4
 31149 0000A98E 8B15[50D50000]      <1> 	mov 	edx, [nbase] ; 18/10/2015
 31150 0000A994 0105[50D50000]      <1> 	add	[nbase], eax
 31151 0000A99A 662905[54D50000]    <1> 	sub	[ncount], ax
 31152                              <1> 	;
 31153 0000A9A1 8B02                <1> 	mov	eax, [edx]
 31154 0000A9A3 C3                  <1> 	retn
 31155                              <1> get_argp_err:
 31156 0000A9A4 A3[2DD50000]        <1> 	mov	[u.error], eax
 31157 0000A9A9 E98CF2FFFF          <1> 	jmp	error
 31158                              <1> get_argp3:
 31159 0000A9AE B103                <1> 	mov	cl, 3
 31160                              <1> get_argp4:
 31161 0000A9B0 C1E008              <1> 	shl	eax, 8
 31162 0000A9B3 665A                <1> 	pop	dx
 31163 0000A9B5 88D0                <1> 	mov 	al, dl
 31164 0000A9B7 E2F7                <1>         loop    get_argp4
 31165                              <1> 	;pop	esi
 31166 0000A9B9 C3                  <1> 	retn	
 31167                              <1> 
 31168                              <1> sysfstat: 
 31169                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 31170                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 31171                              <1> 	;
 31172                              <1> 	; 'sysfstat' is identical to 'sysstat' except that it operates
 31173                              <1> 	; on open files instead of files given by name. It puts the
 31174                              <1> 	; buffer address on the stack, gets the i-number and
 31175                              <1> 	; checks to see if the file is open for reading or writing.
 31176                              <1> 	; If the file is open for writing (i-number is negative)
 31177                              <1> 	; the i-number is set positive and a branch into 'sysstat'
 31178                              <1> 	; is made.	
 31179                              <1> 	;
 31180                              <1> 	; Calling sequence:
 31181                              <1> 	;	sysfstat; buf
 31182                              <1> 	; Arguments:
 31183                              <1> 	;	buf - buffer address
 31184                              <1> 	;
 31185                              <1> 	; Inputs: *u.r0 - file descriptor
 31186                              <1> 	; Outputs: buffer is loaded with file information
 31187                              <1> 	; ...............................................................
 31188                              <1> 	;				
 31189                              <1> 	; Retro UNIX 8086 v1 modification:
 31190                              <1> 	;       'sysfstat' system call has two arguments; so,
 31191                              <1> 	;	* 1st argument, file descriptor is in BX register
 31192                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 31193                              <1> 
 31194                              <1> 	; / set status of open file
 31195                              <1> 		; jsr r0,arg; u.off / put buffer address in u.off
 31196 0000A9BA 51                  <1> 	push	ecx
 31197                              <1> 		; mov u.off,-(sp) / put buffer address on the stack
 31198                              <1> 		; mov *u.r0,r1 / put file descriptor in r1
 31199                              <1> 		; jsr r0,getf / get the files i-number
 31200                              <1> 	; BX = file descriptor (file number)
 31201 0000A9BB E8FF000000          <1> 	call	getf1
 31202 0000A9C0 6621C0              <1> 	and	ax, ax ; i-number of the file
 31203                              <1> 		; tst	r1 / is it 0?
 31204                              <1> 	;jz	error
 31205                              <1> 		; beq error3 / yes, error
 31206 0000A9C3 750F                <1> 	jnz	short sysfstat1
 31207 0000A9C5 C705[2DD50000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 31208 0000A9CD 0000                <1>
 31209 0000A9CF E966F2FFFF          <1> 	jmp	error
 31210                              <1> sysfstat1:
 31211 0000A9D4 80FC80              <1> 	cmp	ah, 80h
 31212 0000A9D7 7223                <1>         jb      short sysstat1
 31213                              <1> 		; bgt 1f / if i-number is negative (open for writing)
 31214 0000A9D9 66F7D8              <1> 	neg	ax
 31215                              <1> 		; neg r1 / make it positive, then branch
 31216 0000A9DC EB1E                <1> 	jmp	short sysstat1
 31217                              <1> 		; br 1f / to 1f
 31218                              <1> sysstat:
 31219                              <1> 	; 18/10/2015
 31220                              <1> 	; 07/10/2015
 31221                              <1> 	; 02/09/2015
 31222                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 31223                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 31224                              <1> 	;
 31225                              <1> 	; 'sysstat' gets the status of a file. Its arguments are the
 31226                              <1> 	; name of the file and buffer address. The buffer is 34 bytes
 31227                              <1> 	; long and information about the file placed in it.	
 31228                              <1> 	; sysstat calls 'namei' to get the i-number of the file.
 31229                              <1> 	; Then 'iget' is called to get i-node in core. The buffer
 31230                              <1> 	; is then loaded and the results are given in the UNIX
 31231                              <1> 	; Programmers Manual sysstat (II).	
 31232                              <1> 	;
 31233                              <1> 	; Calling sequence:
 31234                              <1> 	;	sysstat; name; buf
 31235                              <1> 	; Arguments:
 31236                              <1> 	;	name - points to the name of the file
 31237                              <1> 	;	buf - address of a 34 bytes buffer
 31238                              <1> 	; Inputs: -
 31239                              <1> 	; Outputs: buffer is loaded with file information
 31240                              <1> 	; ...............................................................
 31241                              <1> 	;				
 31242                              <1> 	; Retro UNIX 8086 v1 modification: 
 31243                              <1> 	;       'sysstat' system call has two arguments; so,
 31244                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 31245                              <1> 	;	to get sysstat system call arguments from the user;
 31246                              <1> 	;	* 1st argument, name is pointed to by BX register
 31247                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 31248                              <1> 	;
 31249                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 31250                              <1> 	;	      arguments which were in these registers;
 31251                              <1> 	;	      but, it returns by putting the 1st argument
 31252                              <1> 	;	      in 'u.namep' and the 2nd argument
 31253                              <1> 	;	      on top of stack. (1st argument is offset of the
 31254                              <1> 	;	      file/path name in the user's program segment.)		 	
 31255                              <1> 	
 31256                              <1> 	; / ; name of file; buffer - get files status
 31257                              <1> 		; jsr r0,arg2 / get the 2 arguments
 31258 0000A9DE 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 31259 0000A9E4 51                  <1> 	push	ecx
 31260 0000A9E5 E80C010000          <1> 	call	namei
 31261                              <1> 		; jsr r0,namei / get the i-number for the file
 31262                              <1> 	;jc	error
 31263                              <1> 		; br error3 / no such file, error
 31264 0000A9EA 7310                <1> 	jnc	short sysstat1
 31265                              <1> 	; pop 	ecx
 31266                              <1> sysstat_err0:
 31267                              <1> 	; 'file not found !' error
 31268 0000A9EC C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 31269 0000A9F4 0000                <1>
 31270 0000A9F6 E93FF2FFFF          <1> 	jmp	error
 31271                              <1> 
 31272 0000A9FB 00                  <1> statx: db 0
 31273                              <1> 
 31274                              <1> sysstat1: ; 1:
 31275 0000A9FC E891070000          <1> 	call	iget
 31276                              <1> 		; jsr r0,iget / get the i-node into core
 31277                              <1> 	; 07/10/2015 (ax = [ii], inode number)
 31278                              <1> 	; 02/09/2015
 31279 0000AA01 8F05[F8D40000]      <1> 	pop	dword [u.base]
 31280                              <1> 		; mov (sp)+,r3 / move u.off to r3 (points to buffer)
 31281 0000AA07 E858000000          <1> 	call	sysstat_gpa ; get physical address
 31282 0000AA0C 730A                <1> 	jnc 	short sysstat2
 31283                              <1> sysstat_err1:
 31284 0000AA0E A3[2DD50000]        <1> 	mov	dword [u.error], eax ; error code
 31285 0000AA13 E922F2FFFF          <1> 	jmp	error
 31286                              <1> sysstat2:
 31287 0000AA18 A0[B8D40000]        <1> 	mov 	al, [ii] ; 07/10/2015 (result of 'iget' call, above)
 31288 0000AA1D AA                  <1> 	stosb
 31289 0000AA1E FF05[F8D40000]      <1> 	inc 	dword [u.base]
 31290 0000AA24 6649                <1> 	dec 	cx
 31291 0000AA26 7505                <1> 	jnz	short sysstat3
 31292 0000AA28 E837000000          <1> 	call	sysstat_gpa
 31293                              <1> 	;jc	short sysstat_err1
 31294                              <1> sysstat3:
 31295 0000AA2D A0[B9D40000]        <1> 	mov 	al, [ii+1] ; 07/10/2015 (result of 'iget' call, above)
 31296 0000AA32 AA                  <1> 	stosb
 31297                              <1> 		; mov r1,(r3)+ / put i-number in 1st word of buffer
 31298 0000AA33 FF05[F8D40000]      <1> 	inc 	dword [u.base]
 31299                              <1> 	;dec 	word [u.pcount]
 31300 0000AA39 6649                <1> 	dec	cx
 31301 0000AA3B 7505                <1> 	jnz	short sysstat4
 31302 0000AA3D E822000000          <1> 	call	sysstat_gpa
 31303                              <1> 	;jc	short sysstat_err1	
 31304                              <1> sysstat4:
 31305 0000AA42 BE[ACD10000]        <1> 	mov	esi, inode
 31306                              <1> 		; mov $inode,r2 / r2 points to i-node
 31307                              <1> sysstat5: ; 1:
 31308 0000AA47 A4                  <1> 	movsb
 31309                              <1> 		; mov (r2)+,(r3)+ / move rest of i-node to buffer
 31310 0000AA48 FF05[F8D40000]      <1> 	inc 	dword [u.base]
 31311                              <1> 	;dec 	word [u.pcount]
 31312 0000AA4E 6649                <1> 	dec	cx
 31313 0000AA50 7505                <1> 	jnz	short sysstat6
 31314 0000AA52 E80D000000          <1> 	call	sysstat_gpa
 31315                              <1> 	;jc	short sysstat_err1
 31316                              <1> sysstat6:		
 31317 0000AA57 81FE[CCD10000]      <1> 	cmp	esi, inode + 32
 31318                              <1> 		; cmp r2,$inode+32 / done?
 31319 0000AA5D 75E8                <1> 	jne	short sysstat5
 31320                              <1> 		; bne 1b / no, go back
 31321 0000AA5F E9F6F1FFFF          <1> 	jmp	sysret
 31322                              <1> 		; br sysret3 / return through sysret
 31323                              <1> 	;
 31324                              <1> sysstat_gpa: ; get physical address of file status buffer
 31325                              <1> 	; 02/09/2015
 31326 0000AA64 8B1D[F8D40000]      <1> 	mov 	ebx, [u.base]
 31327                              <1> 	; 07/10/2015
 31328 0000AA6A E82B8DFFFF          <1> 	call	get_physical_addr ; get physical address
 31329                              <1> 	;jc	short sysstat_gpa1
 31330 0000AA6F 729D                <1> 	jc	short sysstat_err1
 31331                              <1> 	; 18/10/2015
 31332 0000AA71 89C7                <1> 	mov	edi, eax ; physical address
 31333                              <1> 	;mov	[u.pcount], cx ; remain bytes in page
 31334                              <1> ;sysstat_gpa1:
 31335 0000AA73 C3                  <1> 	retn
 31336                              <1> 
 31337                              <1> fclose:
 31338                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
 31339                              <1> 	;            (32 bit offset pointer modification)
 31340                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
 31341                              <1> 	;
 31342                              <1> 	; Given the file descriptor (index to the u.fp list)
 31343                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
 31344                              <1> 	; If i-node is active (i-number > 0) the entry in 
 31345                              <1> 	; u.fp list is cleared. If all the processes that opened
 31346                              <1> 	; that file close it, then fsp etry is freed and the file
 31347                              <1> 	; is closed. If not a return is taken. 
 31348                              <1> 	; If the file has been deleted while open, 'anyi' is called
 31349                              <1> 	; to see anyone else has it open, i.e., see if it is appears
 31350                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
 31351                              <1> 	; a check is made to see if the file is special.	
 31352                              <1> 	;
 31353                              <1> 	; INPUTS ->
 31354                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
 31355                              <1> 	;    u.fp - list of entries in the fsp table
 31356                              <1> 	;    fsp - table of entries (4 words/entry) of open files.	 
 31357                              <1> 	; OUTPUTS ->
 31358                              <1> 	;    r1 - contains the same file descriptor
 31359                              <1> 	;    r2 - contains i-number
 31360                              <1> 	;
 31361                              <1> 	; ((AX = R1))
 31362                              <1> 	; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))
 31363                              <1> 	;
 31364                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
 31365                              <1> 	;              if i-number of the file is 0. (error)  	
 31366                              <1> 	;
 31367 0000AA74 0FB7D0              <1> 	movzx	edx, ax ; **
 31368 0000AA77 6650                <1> 	push	ax ; ***
 31369                              <1> 		; mov r1,-(sp) / put r1 on the stack (it contains 
 31370                              <1> 			     ; / the index to u.fp list)
 31371 0000AA79 E83F000000          <1> 	call	getf
 31372                              <1> 		; jsr r0,getf / r1 contains i-number, 
 31373                              <1> 			    ; / cdev has device =, u.fofp 
 31374                              <1> 			    ; / points to 3rd word of fsp entry
 31375 0000AA7E 6683F801            <1> 	cmp	ax, 1 ; r1
 31376                              <1> 		; tst r1 / is i-number 0?
 31377 0000AA82 7236                <1> 	jb	short fclose_2
 31378                              <1> 		; beq 1f / yes, i-node not active so return
 31379                              <1> 		; tst (r0)+ / no, jump over error return
 31380 0000AA84 89D3                <1> 	mov	ebx, edx ; **
 31381 0000AA86 6689C2              <1> 	mov 	dx, ax ; *
 31382                              <1> 		; mov r1,r2 / move i-number to r2 ;*
 31383                              <1> 		; mov (sp),r1 / restore value of r1 from the stack
 31384                              <1> 			    ; / which is index to u.fp ; **
 31385 0000AA89 C683[DED40000]00    <1> 	mov	byte [ebx+u.fp], 0
 31386                              <1> 		; clrb u.fp(r1) / clear that entry in the u.fp list
 31387 0000AA90 8B1D[E8D40000]      <1> 	mov	ebx, [u.fofp]
 31388                              <1> 		; mov u.fofp,r1 / r1 points to 3rd word in fsp entry
 31389                              <1> fclose_0:
 31390 0000AA96 FE4B04              <1> 	dec	byte [ebx+4] ; 18/06/2015
 31391                              <1> 		; decb 2(r1) / decrement the number of processes 
 31392                              <1> 			   ; / that have opened the file
 31393 0000AA99 791F                <1> 	jns	short fclose_2 ; jump if not negative (jump if bit 7 is 0)	 
 31394                              <1> 		; bge 1f / if all processes haven't closed the file, return
 31395                              <1> 	;
 31396 0000AA9B 6652                <1> 	push	dx ;*
 31397                              <1> 		; mov r2,-(sp) / put r2 on the stack (i-number)
 31398 0000AA9D 6631C0              <1> 	xor	ax, ax ; 0
 31399 0000AAA0 668943FC            <1> 	mov	[ebx-4], ax ; 0
 31400                              <1> 		; clr -4(r1) / clear 1st word of fsp entry
 31401 0000AAA4 8A4305              <1> 	mov	al, [ebx+5] ; 18/06/2015
 31402                              <1> 		; tstb	3(r1) / has this file been deleted
 31403 0000AAA7 20C0                <1> 	and	al, al
 31404 0000AAA9 7408                <1> 	jz	short fclose_1
 31405                              <1> 		; beq 2f / no, branch
 31406 0000AAAB 6689D0              <1> 	mov	ax, dx ; *
 31407                              <1> 		; mov r2,r1 / yes, put i-number back into r1
 31408                              <1> 	; AX = inode number
 31409 0000AAAE E868040000          <1> 	call	anyi
 31410                              <1> 		; jsr r0,anyi / free all blocks related to i-number
 31411                              <1> 			    ; / check if file appears in fsp again
 31412                              <1> fclose_1: ; 2:
 31413 0000AAB3 6658                <1> 	pop	ax ; *
 31414                              <1> 		; mov (sp)+,r1 / put i-number back into r1
 31415 0000AAB5 E8E3060000          <1> 	call	iclose ; close if it is special file 
 31416                              <1> 		; jsr r0,iclose / check to see if its a special file
 31417                              <1> fclose_2: ; 1:
 31418 0000AABA 6658                <1> 	pop	ax ; ***
 31419                              <1> 		; mov (sp)+,r1 / put index to u.fp back into r1
 31420 0000AABC C3                  <1> 	retn
 31421                              <1> 		; rts r0
 31422                              <1> 
 31423                              <1> getf:	; / get the device number and the i-number of an open file
 31424                              <1> 	; 13/05/2015
 31425                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 31426                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
 31427                              <1> 	;
 31428 0000AABD 89C3                <1> 	mov	ebx, eax
 31429                              <1> getf1: ;; Calling point from 'rw1' (23/05/2013)
 31430 0000AABF 83FB0A              <1> 	cmp	ebx, 10
 31431                              <1> 		; cmp r1,$10. / user limited to 10 open files
 31432 0000AAC2 730A                <1>         jnb	short getf2 ; 13/05/2015
 31433                              <1> 	;jnb     error
 31434                              <1> 		; bhis error3 / u.fp is table of users open files, 
 31435                              <1> 			    ; / index in fsp table
 31436 0000AAC4 8A9B[DED40000]      <1> 	mov	bl, [ebx+u.fp]
 31437                              <1> 		; movb	u.fp(r1),r1 / r1 contains number of entry 
 31438                              <1> 		                  ; / in fsp table
 31439 0000AACA 08DB                <1> 	or	bl, bl
 31440 0000AACC 7503                <1> 	jnz	short getf3
 31441                              <1> 	;jz	short getf4
 31442                              <1> 		; beq 1f / if its zero return
 31443                              <1> getf2:
 31444                              <1> 	; 'File not open !' error (ax=0)
 31445 0000AACE 29C0                <1> 	sub	eax, eax
 31446 0000AAD0 C3                  <1> 	retn
 31447                              <1> getf3:	
 31448                              <1> 	; Retro UNIX 386 v1 modification ! (11/05/2015)
 31449                              <1> 	;
 31450                              <1> 	; 'fsp' table (10 bytes/entry)
 31451                              <1> 	; bit 15				   bit 0
 31452                              <1> 	; ---|-------------------------------------------
 31453                              <1> 	; r/w|		i-number of open file
 31454                              <1> 	; ---|-------------------------------------------
 31455                              <1> 	;		   device number
 31456                              <1> 	; -----------------------------------------------
 31457                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 31458                              <1> 	; -----------------------------------------------
 31459                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 31460                              <1> 	; ----------------------|------------------------
 31461                              <1> 	;  flag that says file 	| number of processes
 31462                              <1> 	;   has been deleted	| that have file open 
 31463                              <1> 	; ----------------------|------------------------
 31464                              <1> 	;
 31465 0000AAD1 B80A000000          <1> 	mov	eax, 10
 31466 0000AAD6 F6E3                <1> 	mul	bl
 31467 0000AAD8 BB[A6D20000]        <1> 	mov	ebx, fsp - 6 ; the 3rd word in the fsp entry
 31468 0000AADD 01C3                <1> 	add	ebx, eax
 31469                              <1> 		; asl r1
 31470                              <1> 		; asl r1 / multiply by 8 to get index into 
 31471                              <1> 		       ; / fsp table entry
 31472                              <1> 		; asl r1
 31473                              <1> 		; add $fsp-4,r1 / r1 is pointing at the 3rd word 
 31474                              <1> 			      ; / in the fsp entry
 31475 0000AADF 891D[E8D40000]      <1> 	mov	[u.fofp], ebx
 31476                              <1> 		; mov r1,u.fofp / save address of 3rd word 
 31477                              <1> 			      ; / in fsp entry in u.fofp
 31478 0000AAE5 4B                  <1> 	dec	ebx
 31479 0000AAE6 4B                  <1> 	dec	ebx
 31480 0000AAE7 668B03              <1> 	mov	ax, [ebx]
 31481                              <1> 	;mov	[cdev], al ; ;;Retro UNIX 8086 v1 ! 
 31482 0000AAEA 66A3[BCD40000]      <1> 	mov	[cdev], ax ; ;;in fact (!) 
 31483                              <1> 			     ;;dev number is in 1 byte
 31484                              <1> 		; mov -(r1),cdev / remove the device number  cdev
 31485 0000AAF0 4B                  <1> 	dec	ebx
 31486 0000AAF1 4B                  <1> 	dec	ebx
 31487 0000AAF2 668B03              <1> 	mov	ax, [ebx]
 31488                              <1> 		; mov -(r1),r1 / and the i-number  r1
 31489                              <1> getf4:	; 1:
 31490 0000AAF5 C3                  <1> 	retn
 31491                              <1> 		; rts r0
 31492                              <1> 
 31493                              <1> namei:
 31494                              <1> 	; 04/12/2015 (14 byte file names)
 31495                              <1> 	; 18/10/2015 (nbase, ncount)
 31496                              <1> 	; 12/10/2015
 31497                              <1> 	; 21/08/2015
 31498                              <1> 	; 18/07/2015
 31499                              <1> 	; 02/07/2015
 31500                              <1> 	; 17/06/2015
 31501                              <1> 	; 16/06/2015 (Retro UNIX 386 v1 - Beginning)
 31502                              <1> 	; 24/04/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 31503                              <1> 	;
 31504                              <1> 	; 'namei' takes a file path name and returns i-number of
 31505                              <1> 	; the file in the current directory or the root directory
 31506                              <1> 	; (if the first character of the pathname is '/').	
 31507                              <1> 	;
 31508                              <1> 	; INPUTS ->
 31509                              <1> 	;    u.namep - points to a file path name
 31510                              <1> 	;    u.cdir - i-number of users directory
 31511                              <1> 	;    u.cdev - device number on which user directory resides	
 31512                              <1> 	; OUTPUTS ->
 31513                              <1> 	;    r1 - i-number of file
 31514                              <1> 	;    cdev
 31515                              <1> 	;    u.dirbuf - points to directory entry where a match 
 31516                              <1> 	;               occurs in the search for file path name.
 31517                              <1> 	;	        If no match u.dirb points to the end of 
 31518                              <1> 	;               the directory and r1 = i-number of the current
 31519                              <1> 	;	        directory.	
 31520                              <1> 	; ((AX = R1))
 31521                              <1> 	;
 31522                              <1> 	; (Retro UNIX Prototype : 07/10/2012 - 05/01/2013, UNIXCOPY.ASM)
 31523                              <1>         ; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))  
 31524                              <1> 	;
 31525                              <1> 
 31526 0000AAF6 66A1[DCD40000]      <1> 	mov	ax, [u.cdir]
 31527                              <1> 		; mov u.cdir,r1 / put the i-number of current directory
 31528                              <1> 			      ; / in r1
 31529 0000AAFC 668B15[22D50000]    <1> 	mov	dx, [u.cdrv]
 31530 0000AB03 668915[BCD40000]    <1> 	mov	[cdev], dx 	    ; NOTE: Retro UNIX 8086 v1 
 31531                              <1> 				    ; device/drive number is in 1 byte, 
 31532                              <1> 				    ; not in 1 word!
 31533                              <1> 		; mov u.cdev,cdev / device number for users directory 
 31534                              <1> 				; / into cdev
 31535                              <1> 	; 12/10/2015
 31536                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 31537                              <1>       	 ; convert virtual (pathname) addr to physical address
 31538 0000AB0A E82C010000          <1> 	call    trans_addr_nmbp ; 12/10/2015
 31539                              <1> 		; esi = physical address of [u.namep]
 31540                              <1> 		; ecx = byte count in the page
 31541 0000AB0F 803E2F              <1> 	cmp	byte [esi], '/'
 31542                              <1> 		; cmpb *u.namep,$'/ / is first char in file name a /
 31543 0000AB12 751E                <1> 	jne	short namei_1
 31544                              <1> 		; bne 1f
 31545 0000AB14 FF05[F0D40000]      <1> 	inc	dword [u.namep]
 31546                              <1> 		; inc u.namep / go to next char
 31547 0000AB1A 6649                <1> 	dec	cx ; remain byte count in the page
 31548 0000AB1C 7506                <1> 	jnz	short namei_0
 31549                              <1> 	; 12/10/2015
 31550 0000AB1E E818010000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 31551                              <1> 		; esi = physical address (page start + offset)
 31552                              <1> 		; ecx = byte count in the page
 31553 0000AB23 4E                  <1> 	dec	esi
 31554                              <1> namei_0:
 31555 0000AB24 46                  <1> 	inc 	esi  ; go to next char
 31556 0000AB25 66A1[C6D40000]      <1> 	mov	ax, [rootdir] ; 09/07/2013
 31557                              <1> 		; mov rootdir,r1 / put i-number of rootdirectory in r1
 31558 0000AB2B C605[BCD40000]00    <1> 	mov	byte [cdev], 0
 31559                              <1> 		; clr cdev / clear device number
 31560                              <1> namei_1: ; 1:
 31561 0000AB32 F606FF              <1> 	test	byte [esi], 0FFh
 31562 0000AB35 74BE                <1> 	jz	short getf4
 31563                              <1> 	;jz      nig
 31564                              <1> 		; tstb *u.namep / is the character in file name a nul
 31565                              <1> 		; beq nig / yes, end of file name reached; 
 31566                              <1> 			; / branch to "nig"
 31567                              <1> namei_2: ; 1:
 31568                              <1> 	; 18/10/2015
 31569 0000AB37 8935[50D50000]      <1> 	mov 	[nbase], esi
 31570 0000AB3D 66890D[54D50000]    <1> 	mov 	[ncount], cx
 31571                              <1> 	;
 31572                              <1> 	;mov	dx, 2
 31573 0000AB44 B202                <1> 	mov	dl, 2 ; user flag (read, non-owner)
 31574 0000AB46 E859060000          <1> 	call	access
 31575                              <1> 		; jsr r0,access; 2 / get i-node with i-number r1
 31576                              <1> 	; 'access' will not return here if user has not "r" permission !
 31577 0000AB4B 66F705[ACD10000]00- <1> 	test 	word [i.flgs], 4000h
 31578 0000AB53 40                  <1>
 31579                              <1> 		; bit $40000,i.flgs / directory i-node?
 31580 0000AB54 746A                <1>         jz      short namei_err
 31581                              <1> 		; beq error3 / no, got an error
 31582                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 31583 0000AB56 31C0                <1> 	xor	eax, eax
 31584 0000AB58 A3[F4D40000]        <1> 	mov	[u.off], eax ; 0
 31585 0000AB5D 66A1[B0D10000]      <1> 	mov	ax, [i.size]
 31586 0000AB63 A3[ECD40000]        <1> 	mov	[u.dirp], eax
 31587                              <1> 		; mov i.size,u.dirp / put size of directory in u.dirp
 31588                              <1> 		; clr u.off / u.off is file offset used by user
 31589 0000AB68 C705[E8D40000]-     <1> 	mov	dword [u.fofp], u.off
 31590 0000AB6E [F4D40000]          <1>
 31591                              <1> 		; mov $u.off,u.fofp / u.fofp is a pointer to 
 31592                              <1> 				  ; / the offset portion of fsp entry
 31593                              <1> namei_3: ; 2:
 31594 0000AB72 C705[F8D40000]-     <1> 	mov	dword [u.base], u.dirbuf
 31595 0000AB78 [0AD50000]          <1>
 31596                              <1> 		; mov $u.dirbuf,u.base / u.dirbuf holds a file name 
 31597                              <1> 				    ; / copied from a directory
 31598 0000AB7C C705[FCD40000]1000- <1> 	mov 	dword [u.count], 16 ; 04/12/2015 (10 -> 16) 	
 31599 0000AB84 0000                <1>
 31600                              <1>  		; mov $10.,u.count / u.count is byte count 
 31601                              <1> 				 ; / for reads and writes
 31602 0000AB86 66A1[B8D40000]      <1> 	mov 	ax, [ii]
 31603                              <1> 	; 31/07/2013 ('namei_r') - 16/06/2015 ('u.kcall')
 31604 0000AB8C FE05[3FD50000]      <1>  	inc     byte [u.kcall] ; the caller is 'namei' sign	
 31605 0000AB92 E800060000          <1>     	call	readi
 31606                              <1> 		; jsr r0,readi / read 10. bytes of file 
 31607                              <1> 		      ; with i-number (r1); i.e. read a directory entry
 31608 0000AB97 8B0D[00D50000]      <1> 	mov 	ecx, [u.nread]
 31609 0000AB9D 09C9                <1> 	or 	ecx, ecx
 31610                              <1> 		; tst u.nread
 31611 0000AB9F 741B                <1> 	jz	short nib
 31612                              <1> 		; ble nib / gives error return
 31613                              <1> 	;
 31614 0000ABA1 668B1D[0AD50000]    <1> 	mov 	bx, [u.dirbuf]
 31615 0000ABA8 6621DB              <1> 	and 	bx, bx       
 31616                              <1> 		; tst u.dirbuf /
 31617 0000ABAB 7522                <1> 	jnz	short namei_4
 31618                              <1> 		; bne 3f / branch when active directory entry 
 31619                              <1> 		       ; / (i-node word in entry non zero)
 31620 0000ABAD A1[F4D40000]        <1> 	mov	eax, [u.off]
 31621 0000ABB2 83E810              <1> 	sub	eax, 16 ; 04/12/2015 (10 -> 16) 
 31622 0000ABB5 A3[ECD40000]        <1> 	mov	[u.dirp], eax
 31623                              <1> 		; mov u.off,u.dirp
 31624                              <1> 		; sub $10.,u.dirp
 31625 0000ABBA EBB6                <1> 	jmp	short namei_3
 31626                              <1> 		; br 2b
 31627                              <1> 
 31628                              <1> 	; 18/07/2013
 31629                              <1> nib: 
 31630 0000ABBC 31C0                <1> 	xor	eax, eax  ; xor ax, ax ; ax = 0 -> file not found 
 31631 0000ABBE F9                  <1> 	stc
 31632                              <1> nig:
 31633 0000ABBF C3                  <1> 	retn
 31634                              <1> 
 31635                              <1> namei_err:
 31636                              <1> 	; 16/06/2015
 31637 0000ABC0 C705[2DD50000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a directory !' error
 31638 0000ABC8 0000                <1>
 31639 0000ABCA E96BF0FFFF          <1> 	jmp	error
 31640                              <1> 
 31641                              <1> namei_4: ; 3:
 31642                              <1> 	; 18/10/2015
 31643                              <1> 	; 12/10/2015
 31644                              <1> 	; 21/08/2015
 31645                              <1> 	; 18/07/2015
 31646 0000ABCF 8B2D[F0D40000]      <1> 	mov	ebp, [u.namep]
 31647                              <1> 		; mov u.namep,r2 / u.namep points into a file name string
 31648 0000ABD5 BF[0CD50000]        <1> 	mov 	edi, u.dirbuf + 2
 31649                              <1> 		; mov $u.dirbuf+2,r3 / points to file name of directory entry
 31650                              <1> 	; 18/10/2015
 31651 0000ABDA 8B35[50D50000]      <1> 	mov	esi, [nbase]	
 31652 0000ABE0 668B0D[54D50000]    <1> 	mov	cx, [ncount]
 31653                              <1> 	;
 31654 0000ABE7 6621C9              <1> 	and	cx, cx
 31655 0000ABEA 7505                <1> 	jnz	short namei_5	
 31656                              <1> 	;
 31657 0000ABEC E850000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 31658                              <1> 		; esi = physical address (page start + offset)
 31659                              <1> 		; ecx = byte count in the page
 31660                              <1> namei_5: ; 3:
 31661 0000ABF1 45                  <1> 	inc	ebp ; 18/07/2015
 31662 0000ABF2 AC                  <1> 	lodsb   ; mov al, [esi] ; inc esi (al = r4)
 31663                              <1> 		; movb (r2)+,r4 / move a character from u.namep string into r4
 31664 0000ABF3 08C0                <1> 	or 	al, al
 31665 0000ABF5 741D                <1> 	jz 	short namei_7
 31666                              <1> 		; beq 3f / if char is nul, then the last char in string
 31667                              <1> 			; / has been moved
 31668 0000ABF7 3C2F                <1> 	cmp	al, '/'
 31669                              <1> 		; cmp r4,$'/ / is char a </>
 31670 0000ABF9 7419                <1> 	je 	short namei_7
 31671                              <1> 		; beq 3f	
 31672                              <1> 	; 12/10/2015
 31673 0000ABFB 6649                <1> 	dec	cx ; remain byte count in the page
 31674 0000ABFD 7505                <1> 	jnz	short namei_6
 31675 0000ABFF E83D000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 31676                              <1> 		; esi = physical address (page start + offset)
 31677                              <1> 		; ecx = byte count in the page
 31678                              <1> namei_6:
 31679 0000AC04 81FF[1AD50000]      <1>         cmp     edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 31680                              <1> 		; cmp r3,$u.dirbuf+10. / have I checked
 31681                              <1> 				     ; / all 8 bytes of file name
 31682 0000AC0A 74E5                <1> 	je	short namei_5
 31683                              <1> 		; beq 3b
 31684 0000AC0C AE                  <1> 	scasb	
 31685                              <1> 		; cmpb (r3)+,r4 / compare char in u.namep string to file name 
 31686                              <1> 			      ; / char read from directory
 31687 0000AC0D 74E2                <1> 	je 	short namei_5
 31688                              <1> 		; beq 3b / branch if chars match
 31689                              <1> 
 31690 0000AC0F E95EFFFFFF          <1>         jmp    namei_3 ; 2b
 31691                              <1> 		; br 2b / file names do not match go to next directory entry
 31692                              <1> namei_7: ; 3:
 31693 0000AC14 81FF[1AD50000]      <1> 	cmp	edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 31694                              <1> 		; cmp r3,$u.dirbuf+10. / if equal all 8 bytes were matched
 31695 0000AC1A 740A                <1> 	je	short namei_8
 31696                              <1> 		; beq 3f
 31697 0000AC1C 8A27                <1> 	mov 	ah, [edi]
 31698                              <1> 	;inc 	edi 
 31699 0000AC1E 20E4                <1> 	and 	ah, ah
 31700                              <1> 		; tstb (r3)+ /
 31701 0000AC20 0F854CFFFFFF        <1>         jnz     namei_3
 31702                              <1> 		; bne 2b
 31703                              <1> namei_8: ; 3
 31704 0000AC26 892D[F0D40000]      <1> 	mov	[u.namep], ebp ; 18/07/2015
 31705                              <1> 		; mov r2,u.namep / u.namep points to char 
 31706                              <1> 			       ; / following a / or nul
 31707                              <1> 	;mov	bx, [u.dirbuf]
 31708                              <1> 		; mov u.dirbuf,r1 / move i-node number in directory 
 31709                              <1> 				; / entry to r1
 31710 0000AC2C 20C0                <1> 	and 	al, al
 31711                              <1> 		; tst r4 / if r4 = 0 the end of file name reached,
 31712                              <1> 		      ;  / if r4 = </> then go to next directory
 31713                              <1> 	; mov	ax, bx
 31714 0000AC2E 66A1[0AD50000]      <1> 	mov 	ax, [u.dirbuf] ; 17/06/2015
 31715 0000AC34 0F85FDFEFFFF        <1>         jnz     namei_2 
 31716                              <1> 		; bne 1b
 31717                              <1> 	; AX = i-number of the file
 31718                              <1> ;;nig:
 31719 0000AC3A C3                  <1> 	retn
 31720                              <1> 		; tst (r0)+ / gives non-error return
 31721                              <1> ;;nib:
 31722                              <1> ;;	xor	ax, ax ; Retro UNIX 8086 v1 modification !
 31723                              <1> 		       ; ax = 0 -> file not found 
 31724                              <1> ;;	stc	; 27/05/2013
 31725                              <1> ;;	retn
 31726                              <1> 		; rts r0
 31727                              <1> 
 31728                              <1> trans_addr_nmbp:
 31729                              <1> 	; 18/10/2015
 31730                              <1> 	; 12/10/2015
 31731 0000AC3B 8B2D[F0D40000]      <1> 	mov 	ebp, [u.namep]
 31732                              <1> trans_addr_nm: 
 31733                              <1> 	; Convert virtual (pathname) address to physical address
 31734                              <1> 	; (Retro UNIX 386 v1 feature only !)
 31735                              <1> 	; 18/10/2015
 31736                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
 31737                              <1> 	; 02/07/2015
 31738                              <1> 	; 17/06/2015
 31739                              <1> 	; 16/06/2015
 31740                              <1> 	;
 31741                              <1> 	; INPUTS: 
 31742                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
 31743                              <1> 	;	[u.pgdir] = user's page directory
 31744                              <1> 	; OUTPUT:
 31745                              <1> 	;       esi = physical address of the pathname
 31746                              <1> 	;	ecx = remain byte count in the page
 31747                              <1> 	;
 31748                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
 31749                              <1> 	;
 31750 0000AC41 833D[35D50000]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
 31751 0000AC48 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
 31752                              <1> 				     ; it is already physical address
 31753 0000AC4A 50                  <1>    	push	eax	
 31754 0000AC4B 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
 31755 0000AC4D E8488BFFFF          <1>        	call	get_physical_addr ; get physical address
 31756 0000AC52 7204                <1> 	jc	short tr_addr_nm_err
 31757                              <1> 	; 18/10/2015
 31758                              <1> 	; eax = physical address 
 31759                              <1> 	; cx = remain byte count in page (1-4096) 
 31760                              <1> 		; 12/10/2015 (cx = [u.pncount])
 31761 0000AC54 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
 31762 0000AC56 58                  <1> 	pop	eax 
 31763 0000AC57 C3                  <1> 	retn
 31764                              <1> 
 31765                              <1> tr_addr_nm_err:
 31766 0000AC58 A3[2DD50000]        <1> 	mov	[u.error], eax
 31767                              <1> 	;pop 	eax
 31768 0000AC5D E9D8EFFFFF          <1> 	jmp	error
 31769                              <1> 
 31770                              <1> trans_addr_nmk:
 31771                              <1> 	; 12/10/2015
 31772                              <1> 	; 02/07/2015
 31773 0000AC62 8B35[F0D40000]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
 31774 0000AC68 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
 31775 0000AC6C C3                  <1> 	retn
 31776                              <1> 
 31777                              <1> syschdir:
 31778                              <1> 	; / makes the directory specified in the argument
 31779                              <1> 	; / the current directory
 31780                              <1> 	;
 31781                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 31782                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 31783                              <1> 	;
 31784                              <1> 	; 'syschdir' makes the directory specified in its argument
 31785                              <1> 	; the current working directory.
 31786                              <1> 	;
 31787                              <1> 	; Calling sequence:
 31788                              <1> 	;	syschdir; name
 31789                              <1> 	; Arguments:
 31790                              <1> 	;	name - address of the path name of a directory
 31791                              <1> 	;	       terminated by nul byte.	
 31792                              <1> 	; Inputs: -
 31793                              <1> 	; Outputs: -
 31794                              <1> 	; ...............................................................
 31795                              <1> 	;				
 31796                              <1> 	; Retro UNIX 8086 v1 modification:
 31797                              <1> 	;	 The user/application program puts address of 
 31798                              <1> 	;	 the path name in BX register as 'syschdir' 
 31799                              <1> 	; 	 system call argument.
 31800                              <1> 
 31801 0000AC6D 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 31802                              <1> 		;jsr r0,arg; u.namep / u.namep points to path name
 31803 0000AC73 E87EFEFFFF          <1> 	call	namei
 31804                              <1> 		; jsr r0,namei / find its i-number
 31805                              <1> 	;jc	error
 31806                              <1> 		; br error3
 31807 0000AC78 730F                <1> 	jnc	short syschdir0
 31808                              <1> 	; 'directory not found !' error
 31809 0000AC7A C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_DIR_NOT_FOUND ; 12
 31810 0000AC82 0000                <1>
 31811 0000AC84 E9B1EFFFFF          <1> 	jmp	error
 31812                              <1> syschdir0:
 31813 0000AC89 E816050000          <1> 	call	access
 31814                              <1> 		; jsr r0,access; 2 / get i-node into core
 31815 0000AC8E 66F705[ACD10000]00- <1> 	test	word [i.flgs], 4000h
 31816 0000AC96 40                  <1>
 31817                              <1> 		; bit $40000,i.flgs / is it a directory?
 31818                              <1> 	;jz	error 
 31819                              <1> 		; beq error3 / no error
 31820 0000AC97 750F                <1> 	jnz	short syschdir1
 31821 0000AC99 C705[2DD50000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 31822 0000ACA1 0000                <1>
 31823 0000ACA3 E992EFFFFF          <1> 	jmp	error
 31824                              <1> syschdir1:
 31825 0000ACA8 66A3[DCD40000]      <1> 	mov	[u.cdir], ax
 31826                              <1> 		; mov r1,u.cdir / move i-number to users 
 31827                              <1> 			      ; / current directory
 31828 0000ACAE 66A1[BCD40000]      <1> 	mov	ax, [cdev]
 31829 0000ACB4 66A3[22D50000]      <1> 	mov	[u.cdrv], ax
 31830                              <1> 		; mov cdev,u.cdev / move its device to users 
 31831                              <1> 			        ; / current device
 31832 0000ACBA E99BEFFFFF          <1> 	jmp	sysret
 31833                              <1> 		; br sysret3
 31834                              <1> 	
 31835                              <1> syschmod: ; < change mode of file >
 31836                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 31837                              <1> 	; 20/06/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 31838                              <1> 	;
 31839                              <1> 	; 'syschmod' changes mode of the file whose name is given as
 31840                              <1> 	; null terminated string pointed to by 'name' has it's mode 
 31841                              <1> 	; changed to 'mode'.
 31842                              <1> 	;
 31843                              <1> 	; Calling sequence:
 31844                              <1> 	;	syschmod; name; mode
 31845                              <1> 	; Arguments:
 31846                              <1> 	;	name - address of the file name
 31847                              <1> 	;	       terminated by null byte.
 31848                              <1> 	;	mode - (new) mode/flags < attributes >
 31849                              <1> 	;	
 31850                              <1> 	; Inputs: -
 31851                              <1> 	; Outputs: -
 31852                              <1> 	; ...............................................................
 31853                              <1> 	;				
 31854                              <1> 	; Retro UNIX 8086 v1 modification: 
 31855                              <1> 	;       'syschmod' system call has two arguments; so,
 31856                              <1> 	;	* 1st argument, name is pointed to by BX register
 31857                              <1> 	;	* 2nd argument, mode is in CX register
 31858                              <1> 	;
 31859                              <1> 	; Mode bits (Flags):
 31860                              <1> 	;	bit 0 - write permission for non-owner (1)
 31861                              <1> 	;	bit 1 - read permission for non-owner (2)
 31862                              <1> 	;	bit 2 - write permission for owner (4)
 31863                              <1> 	;	bit 3 - read permission for owner (8)
 31864                              <1> 	;	bit 4 - executable flag (16) 	
 31865                              <1> 	;	bit 5 - set user ID on execution flag (32) 
 31866                              <1> 	;	bit 6,7,8,9,10,11 are not used (undefined)
 31867                              <1> 	;	bit 12 - large file flag (4096)
 31868                              <1> 	;	bit 13 - file has modified flag (always on) (8192)
 31869                              <1> 	;	bit 14 - directory flag (16384)
 31870                              <1> 	;	bit 15 - 'i-node is allocated' flag (32768)
 31871                              <1> 
 31872                              <1> 	; / name; mode
 31873 0000ACBF E814000000          <1> 	call	isown
 31874                              <1> 		;jsr r0,isown / get the i-node and check user status
 31875 0000ACC4 66F705[ACD10000]00- <1> 	test	word [i.flgs], 4000h
 31876 0000ACCC 40                  <1>
 31877                              <1> 		; bit	$40000,i.flgs / directory?
 31878 0000ACCD 7402                <1> 	jz	short syschmod1
 31879                              <1> 		; beq 2f / no
 31880                              <1> 	; AL = (new) mode
 31881 0000ACCF 24CF                <1> 	and	al, 0CFh ; 11001111b (clears bit 4 & 5)
 31882                              <1> 		; bic $60,r2 / su & ex / yes, clear set user id and 
 31883                              <1> 			   ; / executable modes
 31884                              <1> syschmod1: ; 2:
 31885 0000ACD1 A2[ACD10000]        <1> 	mov	[i.flgs], al	
 31886                              <1> 		; movb r2,i.flgs / move remaining mode to i.flgs
 31887 0000ACD6 EB42                <1> 	jmp	short isown1
 31888                              <1> 		; br 1f
 31889                              <1> 
 31890                              <1> isown:
 31891                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31892                              <1> 	; 04/05/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 31893                              <1> 	;
 31894                              <1> 	; 'isown' is given a file name (the 1st argument).
 31895                              <1> 	;  It find the i-number of that file via 'namei' 
 31896                              <1> 	;  then gets the i-node into core via 'iget'.
 31897                              <1> 	;  It then tests to see if the user is super user. 
 31898                              <1> 	;  If not, it cheks to see if the user is owner of 
 31899                              <1> 	;  the file. If he is not an error occurs.
 31900                              <1> 	;  If user is the owner 'setimod' is called to indicate
 31901                              <1> 	;  the inode has been modificed and the 2nd argument of
 31902                              <1> 	;  the call is put in r2.
 31903                              <1> 	;
 31904                              <1> 	; INPUTS ->
 31905                              <1> 	;    arguments of syschmod and syschown calls
 31906                              <1> 	; OUTPUTS ->
 31907                              <1> 	;    u.uid - id of user
 31908                              <1> 	;    imod - set to a 1
 31909                              <1> 	;    r2 - contains second argument of the system call				 	
 31910                              <1> 	;
 31911                              <1> 	;   ((AX=R2) output as 2nd argument)
 31912                              <1> 	;
 31913                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 31914                              <1> 	;
 31915                              <1> 		; jsr r0,arg2 / u.namep points to file name
 31916                              <1> 	;; ! 2nd argument on top of stack !
 31917                              <1> 	;; 22/06/2015 - 32 bit modifications
 31918                              <1> 	;; 07/07/2013
 31919 0000ACD8 891D[F0D40000]      <1> 	mov	[u.namep], ebx ;; 1st argument
 31920 0000ACDE 51                  <1> 	push 	ecx ;; 2nd argument
 31921                              <1> 	;;
 31922 0000ACDF E812FEFFFF          <1> 	call	namei
 31923                              <1> 		; jsr r0,namei / get its i-number
 31924                              <1>        ; Retro UNIX 8086 v1 modification !
 31925                              <1>        ; ax = 0 -> file not found 
 31926                              <1> 	;and	ax, ax
 31927                              <1> 	;jz	error
 31928                              <1> 	;jc	error ; 27/05/2013
 31929                              <1> 		; br error3
 31930 0000ACE4 730F                <1> 	jnc	short isown0
 31931                              <1> 	; 'file not found !' error
 31932 0000ACE6 C705[2DD50000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 31933 0000ACEE 0000                <1>
 31934 0000ACF0 E945EFFFFF          <1> 	jmp	error
 31935                              <1> isown0:
 31936 0000ACF5 E898040000          <1> 	call	iget
 31937                              <1> 		; jsr r0,iget / get i-node into core
 31938 0000ACFA A0[24D50000]        <1> 	mov	al, [u.uid] ; 02/08/2013
 31939 0000ACFF 08C0                <1> 	or	al, al
 31940                              <1> 		; tstb u.uid / super user?
 31941 0000AD01 7417                <1> 	jz	short isown1
 31942                              <1> 		; beq 1f / yes, branch
 31943 0000AD03 3A05[AFD10000]      <1> 	cmp	al, [i.uid]
 31944                              <1> 		; cmpb i.uid,u.uid / no, is this the owner of
 31945                              <1> 				 ; / the file
 31946                              <1> 	;jne	error
 31947                              <1> 		; beq 1f / yes
 31948                              <1> 		; jmp error3 / no, error
 31949 0000AD09 740F                <1> 	je	short isown1
 31950                              <1> 
 31951 0000AD0B C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER  ; 11
 31952 0000AD13 0000                <1>
 31953                              <1> 			;  'permission denied !' error
 31954 0000AD15 E920EFFFFF          <1> 	jmp	error
 31955                              <1> isown1: ; 1:
 31956 0000AD1A E881040000          <1> 	call	setimod
 31957                              <1> 		; jsr r0,setimod / indicates 
 31958                              <1> 		;	       ; / i-node has been modified
 31959 0000AD1F 58                  <1> 	pop	eax ; 2nd argument
 31960                              <1> 		; mov (sp)+,r2 / mode is put in r2 
 31961                              <1> 		       ; / (u.off put on stack with 2nd arg)
 31962 0000AD20 C3                  <1> 	retn
 31963                              <1> 		; rts r0
 31964                              <1> 
 31965                              <1> ;;arg:  ; < get system call arguments >
 31966                              <1> 	; 'arg' extracts an argument for a routine whose call is 
 31967                              <1> 	; of form:
 31968                              <1> 	;	sys 'routine' ; arg1
 31969                              <1> 	;		or
 31970                              <1> 	;	sys 'routine' ; arg1 ; arg2
 31971                              <1> 	;		or
 31972                              <1> 	;	sys 'routine' ; arg1;...;arg10 (sys exec) 
 31973                              <1> 	;	
 31974                              <1> 	; INPUTS ->
 31975                              <1> 	;    u.sp+18 - contains a pointer to one of arg1..argn
 31976                              <1> 	;	This pointers's value is actually the value of
 31977                              <1> 	;	update pc at the the trap to sysent (unkni) is
 31978                              <1> 	;	made to process the sys instruction
 31979                              <1> 	;    r0 - contains the return address for the routine
 31980                              <1> 	;	that called arg. The data in the word pointer 
 31981                              <1> 	;	to by the return address is used as address
 31982                              <1> 	;	in which the extracted argument is stored   		
 31983                              <1> 	;    	
 31984                              <1> 	; OUTPUTS ->
 31985                              <1> 	;    'address' - contains the extracted argument 
 31986                              <1> 	;    u.sp+18 - is incremented by 2 
 31987                              <1> 	;    r1 - contains the extracted argument
 31988                              <1> 	;    r0 - points to the next instruction to be
 31989                              <1> 	;	 executed in the calling routine.
 31990                              <1> 	;
 31991                              <1>   
 31992                              <1> 	; mov u.sp,r1
 31993                              <1> 	; mov *18.(r1),*(r0)+ / put argument of system call
 31994                              <1> 			; / into argument of arg2
 31995                              <1> 	; add $2,18.(r1) / point pc on stack 
 31996                              <1> 			      ; / to next system argument
 31997                              <1> 	; rts r0
 31998                              <1> 
 31999                              <1> ;;arg2: ; < get system calls arguments - with file name pointer>
 32000                              <1> 	; 'arg2' takes first argument in system call
 32001                              <1> 	;  (pointer to name of the file) and puts it in location
 32002                              <1> 	;  u.namep; takes second argument and puts it in u.off
 32003                              <1> 	;  and on top of the stack
 32004                              <1> 	;	
 32005                              <1> 	; INPUTS ->
 32006                              <1> 	;    u.sp, r0
 32007                              <1> 	;    	
 32008                              <1> 	; OUTPUTS ->
 32009                              <1> 	;    u.namep
 32010                              <1> 	;    u.off 
 32011                              <1> 	;    u.off pushed on stack
 32012                              <1> 	;    r1
 32013                              <1> 	;
 32014                              <1> 
 32015                              <1> 	; jsr	r0,arg; u.namep / u.namep contains value of
 32016                              <1> 				; / first arg in sys call
 32017                              <1> 	; jsr r0,arg; u.off / u.off contains value of 
 32018                              <1> 				; / second arg in sys call
 32019                              <1> 	; mov r0,r1 / r0 points to calling routine
 32020                              <1> 	; mov (sp),r0 / put operation code back in r0
 32021                              <1> 	; mov u.off,(sp) / put pointer to second argument 
 32022                              <1> 			; / on stack
 32023                              <1> 	; jmp (r1) / return to calling routine
 32024                              <1> 
 32025                              <1> syschown: ; < change owner of file >
 32026                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 32027                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 32028                              <1> 	;
 32029                              <1> 	; 'syschown' changes the owner of the file whose name is given
 32030                              <1> 	; as null terminated string pointed to by 'name' has it's owner
 32031                              <1> 	; changed to 'owner'
 32032                              <1> 	;
 32033                              <1> 	; Calling sequence:
 32034                              <1> 	;	syschown; name; owner
 32035                              <1> 	; Arguments:
 32036                              <1> 	;	name - address of the file name
 32037                              <1> 	;	       terminated by null byte.
 32038                              <1> 	;	owner - (new) owner (number/ID)
 32039                              <1> 	;	
 32040                              <1> 	; Inputs: -
 32041                              <1> 	; Outputs: -
 32042                              <1> 	; ...............................................................
 32043                              <1> 	;				
 32044                              <1> 	; Retro UNIX 8086 v1 modification: 
 32045                              <1> 	;       'syschown' system call has two arguments; so,
 32046                              <1> 	;	* 1st argument, name is pointed to by BX register
 32047                              <1> 	;	* 2nd argument, owner number is in CX register
 32048                              <1> 	;
 32049                              <1> 	; / name; owner
 32050 0000AD21 E8B2FFFFFF          <1> 	call	isown
 32051                              <1> 		; jsr r0,isown / get the i-node and check user status
 32052 0000AD26 803D[24D50000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013 
 32053                              <1> 		; tstb u.uid / super user
 32054 0000AD2D 7418                <1> 	jz	short syschown1
 32055                              <1> 		; beq 2f / yes, 2f
 32056 0000AD2F F605[ACD10000]20    <1>         test    byte [i.flgs], 20h ; 32
 32057                              <1> 		; bit $40,i.flgs / no, set userid on execution?
 32058                              <1> 	;jnz	error
 32059                              <1> 		; bne 3f / yes error, could create Trojan Horses
 32060 0000AD36 740F                <1> 	jz	short syschown1
 32061                              <1> 	; 'permission denied !'
 32062 0000AD38 C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS  ; 11
 32063 0000AD40 0000                <1>
 32064 0000AD42 E9F3EEFFFF          <1> 	jmp	error
 32065                              <1> syschown1: ; 2:
 32066                              <1> 	; AL = owner (number/ID)
 32067 0000AD47 A2[AFD10000]        <1> 	mov	[i.uid], al ; 23/06/2015
 32068                              <1> 		;  movb	r2,i.uid / no, put the new owners id 
 32069                              <1> 			       ; / in the i-node
 32070 0000AD4C E909EFFFFF          <1> 	jmp	sysret
 32071                              <1> 	; 1: 
 32072                              <1> 		; jmp sysret4
 32073                              <1> 	; 3:
 32074                              <1> 		; jmp	error
 32075                              <1> 
 32076                              <1> systime: ; / get time of year
 32077                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 32078                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
 32079                              <1> 	;
 32080                              <1> 	; 20/06/2013
 32081                              <1> 	; 'systime' gets the time of the year.
 32082                              <1> 	; The present time is put on the stack.
 32083                              <1> 	;
 32084                              <1> 	; Calling sequence:
 32085                              <1> 	;	systime
 32086                              <1> 	; Arguments: -
 32087                              <1> 	;	
 32088                              <1> 	; Inputs: -
 32089                              <1> 	; Outputs: sp+2, sp+4 - present time
 32090                              <1> 	; ...............................................................
 32091                              <1> 	;	
 32092                              <1> 	; Retro UNIX 8086 v1 modification: 
 32093                              <1> 	;       'systime' system call will return to the user
 32094                              <1> 	;	with unix time (epoch) in DX:AX register pair
 32095                              <1> 	;
 32096                              <1> 	; 	!! Major modification on original Unix v1 'systime' 
 32097                              <1> 	;	system call for PC compatibility !!		 	
 32098                              <1> 
 32099 0000AD51 E851040000          <1> 	call 	epoch
 32100 0000AD56 A3[D8D40000]        <1> 	mov 	[u.r0], eax
 32101                              <1> 		; mov s.time,4(sp)
 32102                              <1> 		; mov s.time+2,2(sp) / put the present time 
 32103                              <1> 				   ; / on the stack
 32104                              <1> 		; br sysret4
 32105 0000AD5B E9FAEEFFFF          <1> 	jmp	sysret 
 32106                              <1> 
 32107                              <1> sysstime: ; / set time
 32108                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 32109                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 32110                              <1> 	;
 32111                              <1> 	; 'sysstime' sets the time. Only super user can use this call.
 32112                              <1> 	;
 32113                              <1> 	; Calling sequence:
 32114                              <1> 	;	sysstime
 32115                              <1> 	; Arguments: -
 32116                              <1> 	;	
 32117                              <1> 	; Inputs: sp+2, sp+4 - time system is to be set to.
 32118                              <1> 	; Outputs: -
 32119                              <1> 	; ...............................................................
 32120                              <1> 	;	
 32121                              <1> 	; Retro UNIX 8086 v1 modification: 
 32122                              <1> 	;	the user calls 'sysstime' with unix (epoch) time
 32123                              <1> 	;	(to be set) is in CX:BX register pair as two arguments.
 32124                              <1> 	; 
 32125                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 32126                              <1> 	;	to get sysstime system call arguments from the user;
 32127                              <1> 	;	* 1st argument, lowword of unix time is in BX register
 32128                              <1> 	;	* 2nd argument, highword of unix time is in CX register		 	
 32129                              <1> 	;
 32130                              <1> 	; 	!! Major modification on original Unix v1 'sysstime' 
 32131                              <1> 	;	system call for PC compatibility !!	
 32132                              <1> 
 32133 0000AD60 803D[24D50000]00    <1> 	cmp	byte [u.uid], 0
 32134                              <1> 		; tstb u.uid / is user the super user
 32135                              <1> 	;ja	error
 32136                              <1> 		; bne error4 / no, error
 32137 0000AD67 760F                <1> 	jna	short systime1
 32138                              <1> 	; 'permission denied !'
 32139 0000AD69 C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11 
 32140 0000AD71 0000                <1>
 32141 0000AD73 E9C2EEFFFF          <1> 	jmp	error
 32142                              <1> systime1:
 32143                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - 32 bit version)
 32144                              <1> 	; EBX = unix (epoch) time (from user)
 32145 0000AD78 89D8                <1> 	mov	eax, ebx
 32146 0000AD7A E829040000          <1> 	call 	set_date_time
 32147                              <1> 		; mov 4(sp),s.time
 32148                              <1> 		; mov 2(sp),s.time+2 / set the system time
 32149 0000AD7F E9D6EEFFFF          <1> 	jmp	sysret
 32150                              <1> 		; br sysret4
 32151                              <1> 
 32152                              <1> sysbreak:
 32153                              <1> 	; 18/10/2015
 32154                              <1> 	; 07/10/2015
 32155                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 32156                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
 32157                              <1> 	;
 32158                              <1> 	; 'sysbreak' sets the programs break points. 
 32159                              <1> 	; It checks the current break point (u.break) to see if it is
 32160                              <1> 	; between "core" and the stack (sp). If it is, it is made an
 32161                              <1> 	; even address (if it was odd) and the area between u.break
 32162                              <1> 	; and the stack is cleared. The new breakpoint is then put
 32163                              <1> 	; in u.break and control is passed to 'sysret'.
 32164                              <1> 	;
 32165                              <1> 	; Calling sequence:
 32166                              <1> 	;	sysbreak; addr
 32167                              <1> 	; Arguments: -
 32168                              <1> 	;	
 32169                              <1> 	; Inputs: u.break - current breakpoint
 32170                              <1> 	; Outputs: u.break - new breakpoint 
 32171                              <1> 	;	area between old u.break and the stack (sp) is cleared.
 32172                              <1> 	; ...............................................................
 32173                              <1> 	;	
 32174                              <1> 	; Retro UNIX 8086 v1 modification:
 32175                              <1> 	;	The user/application program puts breakpoint address
 32176                              <1> 	;       in BX register as 'sysbreak' system call argument.
 32177                              <1> 	; 	(argument transfer method 1)
 32178                              <1> 	;
 32179                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
 32180                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
 32181                              <1> 	;  NOTE:
 32182                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
 32183                              <1> 	;	'u.break' address) of user's memory for original unix's
 32184                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
 32185                              <1> 
 32186                              <1> 		; mov u.break,r1 / move users break point to r1
 32187                              <1> 		; cmp r1,$core / is it the same or lower than core?
 32188                              <1> 		; blos 1f / yes, 1f
 32189                              <1> 	; 23/06/2015
 32190 0000AD84 8B2D[04D50000]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
 32191                              <1> 	;and	ebp, ebp
 32192                              <1> 	;jz	short sysbreak_3 
 32193                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
 32194                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
 32195 0000AD8A 8B15[D0D40000]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
 32196 0000AD90 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
 32197                              <1> 	; 07/10/2015
 32198 0000AD93 891D[04D50000]      <1> 	mov	[u.break], ebx ; virtual address !!!
 32199                              <1> 	;
 32200 0000AD99 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
 32201                              <1> 			   ; with top of user's stack (virtual!)
 32202 0000AD9B 7327                <1> 	jnb	short sysbreak_3
 32203                              <1> 		; cmp r1,sp / is it the same or higher 
 32204                              <1> 			  ; / than the stack?
 32205                              <1> 		; bhis 1f / yes, 1f
 32206 0000AD9D 89DE                <1> 	mov	esi, ebx
 32207 0000AD9F 29EE                <1> 	sub	esi, ebp ; new break point - old break point
 32208 0000ADA1 7621                <1> 	jna	short sysbreak_3 
 32209                              <1> 	;push	ebx
 32210                              <1> sysbreak_1:
 32211 0000ADA3 89EB                <1> 	mov	ebx, ebp  
 32212 0000ADA5 E8F089FFFF          <1> 	call	get_physical_addr ; get physical address
 32213 0000ADAA 0F82A8FEFFFF        <1> 	jc	tr_addr_nm_err
 32214                              <1> 	; 18/10/2015
 32215 0000ADB0 89C7                <1> 	mov	edi, eax 
 32216 0000ADB2 29C0                <1> 	sub	eax, eax ; 0
 32217                              <1> 		 ; ECX = remain byte count in page (1-4096)
 32218 0000ADB4 39CE                <1> 	cmp	esi, ecx
 32219 0000ADB6 7302                <1> 	jnb	short sysbreak_2
 32220 0000ADB8 89F1                <1> 	mov	ecx, esi
 32221                              <1> sysbreak_2:
 32222 0000ADBA 29CE                <1> 	sub	esi, ecx
 32223 0000ADBC 01CD                <1> 	add	ebp, ecx
 32224 0000ADBE F3AA                <1> 	rep 	stosb
 32225 0000ADC0 09F6                <1> 	or	esi, esi
 32226 0000ADC2 75DF                <1> 	jnz	short sysbreak_1
 32227                              <1> 	;
 32228                              <1> 		; bit $1,r1 / is it an odd address
 32229                              <1> 		; beq 2f / no, its even
 32230                              <1> 		; clrb (r1)+ / yes, make it even
 32231                              <1> 	; 2: / clear area between the break point and the stack
 32232                              <1> 		; cmp r1,sp / is it higher or same than the stack
 32233                              <1> 		; bhis 1f / yes, quit
 32234                              <1> 		; clr (r1)+ / clear word
 32235                              <1> 		; br 2b / go back
 32236                              <1> 	;pop	ebx
 32237                              <1> sysbreak_3: ; 1:
 32238                              <1> 	;mov	[u.break], ebx ; virtual address !!!
 32239                              <1> 		; jsr r0,arg; u.break / put the "address" 
 32240                              <1> 			; / in u.break (set new break point)
 32241                              <1> 		; br sysret4 / br sysret
 32242 0000ADC4 E991EEFFFF          <1> 	jmp	sysret
 32243                              <1> 
 32244                              <1> 
 32245                              <1> maknod: 
 32246                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32247                              <1> 	; 02/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 32248                              <1> 	;
 32249                              <1> 	; 'maknod' creates an i-node and makes a directory entry
 32250                              <1> 	; for this i-node in the current directory.
 32251                              <1> 	;
 32252                              <1> 	; INPUTS ->
 32253                              <1> 	;    r1 - contains mode
 32254                              <1> 	;    ii - current directory's i-number	
 32255                              <1> 	;    	
 32256                              <1> 	; OUTPUTS ->
 32257                              <1> 	;    u.dirbuf - contains i-number of free i-node 
 32258                              <1> 	;    i.flgs - flags in new i-node 
 32259                              <1> 	;    i.uid - filled with u.uid
 32260                              <1> 	;    i.nlks - 1 is put in the number of links
 32261                              <1> 	;    i.ctim - creation time				
 32262                              <1> 	;    i.ctim+2 - modification time
 32263                              <1> 	;    imod - set via call to setimod
 32264                              <1> 	;	
 32265                              <1> 	; ((AX = R1)) input
 32266                              <1> 	;
 32267                              <1> 	; (Retro UNIX Prototype : 
 32268                              <1> 	;	30/10/2012 - 01/03/2013, UNIXCOPY.ASM)
 32269                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 32270                              <1> 
 32271                              <1> 	; / r1 contains the mode
 32272 0000ADC9 80CC80              <1> 	or 	ah, 80h  ; 10000000b
 32273                              <1> 		; bis	$100000,r1 / allocate flag set
 32274 0000ADCC 6650                <1> 	push	ax
 32275                              <1> 		; mov r1,-(sp) / put mode on stack
 32276                              <1> 	; 31/07/2013
 32277 0000ADCE 66A1[B8D40000]      <1> 	mov	ax, [ii] ; move current i-number to AX/r1
 32278                              <1> 		; mov ii,r1 / move current i-number to r1
 32279 0000ADD4 B201                <1> 	mov	dl, 1 ; owner flag mask
 32280 0000ADD6 E8C9030000          <1> 	call	access	
 32281                              <1> 		; jsr r0,access; 1 / get its i-node into core
 32282 0000ADDB 6650                <1> 	push	ax
 32283                              <1> 		; mov r1,-(sp) / put i-number on stack
 32284 0000ADDD 66B82800            <1> 	mov	ax, 40
 32285                              <1> 		; mov $40.,r1 / r1 = 40
 32286                              <1> maknod1: ; 1: / scan for a free i-node (next 4 instructions)
 32287 0000ADE1 6640                <1> 	inc	ax
 32288                              <1> 		; inc r1 / r1 = r1 + 1
 32289 0000ADE3 E8C1030000          <1> 	call	imap
 32290                              <1> 		; jsr r0,imap / get byte address and bit position in 
 32291                              <1> 			    ; /	inode map in r2 & m
 32292                              <1>           ; DX (MQ) has a 1 in the calculated bit position
 32293                              <1>           ; eBX (R2) has byte address of the byte with allocation bit
 32294                              <1> 	; 22/06/2015 - NOTE for next Retro UNIX version: 
 32295                              <1> 	;	       Inode count must be checked here
 32296                              <1> 	; (Original UNIX v1 did not check inode count here !?) 	
 32297 0000ADE8 8413                <1> 	test	[ebx], dl
 32298                              <1> 		; bitb mq,(r2) / is the i-node active
 32299 0000ADEA 75F5                <1> 	jnz	short maknod1
 32300                              <1> 		; bne 1b / yes, try the next one
 32301 0000ADEC 0813                <1> 	or	[ebx], dl
 32302                              <1> 		; bisb mq,(r2) / no, make it active 
 32303                              <1> 			     ; / (put a 1 in the bit map)
 32304 0000ADEE E89F030000          <1> 	call	iget
 32305                              <1> 		; jsr r0,iget / get i-node into core
 32306 0000ADF3 66F705[ACD10000]00- <1> 	test	word [i.flgs], 8000h 
 32307 0000ADFB 80                  <1>
 32308                              <1> 		; tst i.flgs / is i-node already allocated
 32309 0000ADFC 75E3                <1> 	jnz	short maknod1	
 32310                              <1> 		; blt 1b / yes, look for another one
 32311 0000ADFE 66A3[0AD50000]      <1> 	mov	[u.dirbuf], ax
 32312                              <1> 		; mov r1,u.dirbuf / no, put i-number in u.dirbuf
 32313 0000AE04 6658                <1> 	pop	ax
 32314                              <1> 		; mov (sp)+,r1 / get current i-number back
 32315 0000AE06 E887030000          <1> 	call	iget
 32316                              <1> 		; jsr r0,iget / get i-node in core
 32317 0000AE0B E87DF7FFFF          <1> 	call	mkdir
 32318                              <1> 		; jsr r0,mkdir / make a directory entry 
 32319                              <1> 			     ; / in current directory
 32320 0000AE10 66A1[0AD50000]      <1> 	mov	ax, [u.dirbuf]
 32321                              <1> 		; mov u.dirbuf,r1 / r1 = new inode number
 32322 0000AE16 E877030000          <1> 	call	iget
 32323                              <1> 		; jsr r0,iget / get it into core
 32324                              <1> 		; jsr r0,copyz; inode; inode+32. / 0 it out
 32325 0000AE1B B908000000          <1> 	mov	ecx, 8 
 32326 0000AE20 31C0                <1> 	xor	eax, eax ; 0
 32327 0000AE22 BF[ACD10000]        <1> 	mov	edi, inode 
 32328 0000AE27 F3AB                <1> 	rep	stosd
 32329                              <1> 	;
 32330 0000AE29 668F05[ACD10000]    <1> 	pop	word [i.flgs]
 32331                              <1> 		; mov (sp)+,i.flgs / fill flags
 32332 0000AE30 8A0D[24D50000]      <1> 	mov 	cl, [u.uid] ; 02/08/2013
 32333 0000AE36 880D[AFD10000]      <1> 	mov 	[i.uid], cl
 32334                              <1> 		; movb u.uid,i.uid / user id	
 32335 0000AE3C C605[AED10000]01    <1> 	mov     byte [i.nlks], 1
 32336                              <1> 		; movb $1,i.nlks / 1 link
 32337                              <1> 	;call	epoch ; Retro UNIX 8086 v1 modification !
 32338                              <1> 	;mov	eax, [s.time]
 32339                              <1> 	;mov 	[i.ctim], eax
 32340                              <1> 	 	; mov s.time,i.ctim / time created
 32341                              <1> 	 	; mov s.time+2,i.ctim+2 / time modified
 32342                              <1> 	; Retro UNIX 8086 v1 modification !
 32343                              <1> 	; i.ctime=0, i.ctime+2=0 and
 32344                              <1>         ; 'setimod' will set ctime of file via 'epoch'
 32345 0000AE43 E858030000          <1> 	call setimod
 32346                              <1> 		; jsr r0,setimod / set modified flag
 32347 0000AE48 C3                  <1> 	retn
 32348                              <1> 		; rts r0 / return
 32349                              <1> 
 32350                              <1> sysseek: ; / moves read write pointer in an fsp entry
 32351                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32352                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 32353                              <1> 	;
 32354                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
 32355                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
 32356                              <1> 	; The file descriptor refers to a file open for reading or
 32357                              <1> 	; writing. The read (or write) pointer is set as follows:
 32358                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
 32359                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
 32360                              <1> 	;	  current location plus offset.
 32361                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
 32362                              <1> 	;	  size of file plus offset.
 32363                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
 32364                              <1> 	;
 32365                              <1> 	; Calling sequence:
 32366                              <1> 	;	sysseek; offset; ptrname
 32367                              <1> 	; Arguments:
 32368                              <1> 	;	offset - number of bytes desired to move 
 32369                              <1> 	;		 the r/w pointer
 32370                              <1> 	;	ptrname - a switch indicated above
 32371                              <1> 	;
 32372                              <1> 	; Inputs: r0 - file descriptor 
 32373                              <1> 	; Outputs: -
 32374                              <1> 	; ...............................................................
 32375                              <1> 	;	
 32376                              <1> 	; Retro UNIX 8086 v1 modification: 
 32377                              <1> 	;       'sysseek' system call has three arguments; so,
 32378                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
 32379                              <1> 	;	* 2nd argument, offset is in CX register
 32380                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register	
 32381                              <1> 	;	
 32382                              <1> 
 32383 0000AE49 E823000000          <1> 	call	seektell
 32384                              <1> 	; AX = u.count
 32385                              <1> 	; BX = *u.fofp
 32386                              <1> 		; jsr r0,seektell / get proper value in u.count
 32387                              <1> 		; add u.base,u.count / add u.base to it
 32388 0000AE4E 0305[F8D40000]      <1> 	add	eax, [u.base] ; add offset (u.base) to base
 32389 0000AE54 8903                <1> 	mov	[ebx], eax
 32390                              <1> 		; mov u.count,*u.fofp / put result into r/w pointer
 32391 0000AE56 E9FFEDFFFF          <1> 	jmp	sysret
 32392                              <1> 		; br sysret4
 32393                              <1> 
 32394                              <1> systell: ; / get the r/w pointer
 32395                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32396                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 32397                              <1> 	;
 32398                              <1> 	; Retro UNIX 8086 v1 modification:
 32399                              <1> 	; ! 'systell' does not work in original UNIX v1,
 32400                              <1> 	; 	    it returns with error !
 32401                              <1> 	; Inputs: r0 - file descriptor 
 32402                              <1> 	; Outputs: r0 - file r/w pointer
 32403                              <1> 
 32404                              <1> 	;xor	ecx, ecx ; 0
 32405 0000AE5B BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
 32406                              <1> 	;call 	seektell
 32407 0000AE60 E812000000          <1> 	call 	seektell0 ; 05/08/2013
 32408                              <1> 	;mov	ebx, [u.fofp]
 32409 0000AE65 8B03                <1> 	mov	eax, [ebx]
 32410 0000AE67 A3[D8D40000]        <1> 	mov	[u.r0], eax
 32411 0000AE6C E9E9EDFFFF          <1> 	jmp	sysret
 32412                              <1> 
 32413                              <1> ; Original unix v1 'systell' system call:
 32414                              <1> 		; jsr r0,seektell
 32415                              <1> 		; br error4
 32416                              <1> 
 32417                              <1> seektell:
 32418                              <1> 	; 03/01/2016
 32419                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32420                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 32421                              <1> 	;
 32422                              <1> 	; 'seektell' puts the arguments from sysseek and systell
 32423                              <1> 	; call in u.base and u.count. It then gets the i-number of
 32424                              <1> 	; the file from the file descriptor in u.r0 and by calling
 32425                              <1> 	; getf. The i-node is brought into core and then u.count
 32426                              <1> 	; is checked to see it is a 0, 1, or 2.
 32427                              <1> 	; If it is 0 - u.count stays the same
 32428                              <1> 	;          1 - u.count = offset (u.fofp)
 32429                              <1> 	;	   2 - u.count = i.size (size of file)
 32430                              <1> 	; 	 		
 32431                              <1> 	; !! Retro UNIX 8086 v1 modification:
 32432                              <1> 	;	Argument 1, file descriptor is in BX;
 32433                              <1> 	;	Argument 2, offset is in CX;
 32434                              <1> 	;	Argument 3, ptrname/switch is in DX register.	
 32435                              <1> 	;
 32436                              <1> 	; mov 	ax, 3 ; Argument transfer method 3 (three arguments)	
 32437                              <1> 	; call 	arg
 32438                              <1> 	;
 32439                              <1> 	; ((Return -> ax = base for offset (position= base+offset))
 32440                              <1> 	;
 32441 0000AE71 890D[F8D40000]      <1> 	mov 	[u.base], ecx ; offset
 32442                              <1> 		; jsr r0,arg; u.base / puts offset in u.base
 32443                              <1> seektell0:
 32444 0000AE77 8915[FCD40000]      <1> 	mov 	[u.count], edx
 32445                              <1> 		; jsr r0,arg; u.count / put ptr name in u.count
 32446                              <1> 	; mov	ax, bx
 32447                              <1> 		; mov *u.r0,r1 / file descriptor in r1 
 32448                              <1> 			     ; / (index in u.fp list)
 32449                              <1> 	; call	getf
 32450                              <1> 		; jsr r0,getf / u.fofp points to 3rd word in fsp entry
 32451                              <1> 	; BX = file descriptor (file number)
 32452 0000AE7D E83DFCFFFF          <1> 	call	getf1
 32453 0000AE82 6609C0              <1> 	or	ax, ax ; i-number of the file
 32454                              <1> 		; mov r1,-(sp) / r1 has i-number of file, 
 32455                              <1> 		             ; / put it on the stack
 32456                              <1> 	;jz	error
 32457                              <1> 		; beq error4 / if i-number is 0, not active so error
 32458 0000AE85 750F                <1> 	jnz	short seektell1
 32459 0000AE87 C705[2DD50000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 32460 0000AE8F 0000                <1>
 32461 0000AE91 E9A4EDFFFF          <1> 	jmp	error
 32462                              <1> seektell1:
 32463                              <1> 	;push	eax
 32464 0000AE96 80FC80              <1> 	cmp	ah, 80h
 32465 0000AE99 7203                <1> 	jb	short seektell2
 32466                              <1> 		; bgt .+4 / if its positive jump
 32467 0000AE9B 66F7D8              <1> 	neg	ax
 32468                              <1> 		; neg r1 / if not make it positive
 32469                              <1> seektell2:
 32470 0000AE9E E8EF020000          <1> 	call	iget
 32471                              <1> 		; jsr r0,iget / get its i-node into core
 32472 0000AEA3 8B1D[E8D40000]      <1>         mov     ebx, [u.fofp] ; 05/08/2013
 32473 0000AEA9 803D[FCD40000]01    <1> 	cmp	byte [u.count], 1
 32474                              <1> 		; cmp u.count,$1 / is ptr name =1
 32475 0000AEB0 7705                <1> 	ja	short seektell3
 32476                              <1> 		; blt 2f / no its zero
 32477 0000AEB2 740A                <1> 	je	short seektell_4
 32478                              <1> 		; beq 1f / yes its 1
 32479 0000AEB4 31C0                <1> 	xor	eax, eax
 32480                              <1> 	;jmp	short seektell_5
 32481 0000AEB6 C3                  <1> 	retn
 32482                              <1> seektell3:
 32483                              <1> 	; 03/01/2016
 32484                              <1> 	;movzx	eax, word [i.size]
 32485 0000AEB7 66A1[B0D10000]      <1>         mov   	ax, [i.size]
 32486                              <1>                 ; mov i.size,u.count /  put number of bytes 
 32487                              <1>                                    ; / in file in u.count
 32488                              <1> 	;jmp	short seektell_5
 32489                              <1> 		; br 2f
 32490 0000AEBD C3                  <1> 	retn
 32491                              <1> seektell_4: ; 1: / ptrname =1
 32492                              <1> 	;mov	ebx, [u.fofp]
 32493 0000AEBE 8B03                <1> 	mov	eax, [ebx]
 32494                              <1> 		; mov *u.fofp,u.count / put offset in u.count
 32495                              <1> ;seektell_5: ; 2: / ptrname =0
 32496                              <1> 	;mov	[u.count], eax
 32497                              <1> 	;pop	eax 
 32498                              <1> 		; mov (sp)+,r1 / i-number on stack  r1
 32499 0000AEC0 C3                  <1> 	retn
 32500                              <1> 		; rts r0
 32501                              <1> 
 32502                              <1> sysintr: ; / set interrupt handling
 32503                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32504                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 32505                              <1> 	;
 32506                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
 32507                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
 32508                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
 32509                              <1> 	; If one does the interrupt character in the tty buffer is
 32510                              <1> 	; cleared and 'sysret'is called. If one does not exits
 32511                              <1> 	; 'sysret' is just called.	
 32512                              <1> 	;
 32513                              <1> 	; Calling sequence:
 32514                              <1> 	;	sysintr; arg
 32515                              <1> 	; Argument:
 32516                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
 32517                              <1> 	;	    - if 1, intterupts cause their normal result
 32518                              <1> 	;		 i.e force an exit.
 32519                              <1> 	;	    - if arg is a location within the program,
 32520                              <1> 	;		control is passed to that location when
 32521                              <1> 	;		an interrupt occurs.	
 32522                              <1> 	; Inputs: -
 32523                              <1> 	; Outputs: -
 32524                              <1> 	; ...............................................................
 32525                              <1> 	;	
 32526                              <1> 	; Retro UNIX 8086 v1 modification: 
 32527                              <1> 	;       'sysintr' system call sets u.intr to value of BX
 32528                              <1> 	;	then branches into sysquit.
 32529                              <1> 	;
 32530 0000AEC1 66891D[1CD50000]    <1> 	mov	[u.intr], bx
 32531                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
 32532                              <1> 		; br 1f / go into quit routine
 32533 0000AEC8 E98DEDFFFF          <1> 	jmp	sysret
 32534                              <1> 
 32535                              <1> sysquit:
 32536                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32537                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 32538                              <1> 	;
 32539                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
 32540                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
 32541                              <1> 	; tty exists. If one does the interrupt character in the tty
 32542                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
 32543                              <1> 	; 'sysret' is just called.	
 32544                              <1> 	;
 32545                              <1> 	; Calling sequence:
 32546                              <1> 	;	sysquit; arg
 32547                              <1> 	; Argument:
 32548                              <1> 	;	arg - if 0, this call diables quit signals from the
 32549                              <1> 	;		typewriter (ASCII FS)
 32550                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
 32551                              <1> 	;		cease and a core image to be produced.
 32552                              <1> 	;		 i.e force an exit.
 32553                              <1> 	;	    - if arg is an addres in the program,
 32554                              <1> 	;		a quit causes control to sent to that
 32555                              <1> 	;		location.	
 32556                              <1> 	; Inputs: -
 32557                              <1> 	; Outputs: -
 32558                              <1> 	; ...............................................................
 32559                              <1> 	;	
 32560                              <1> 	; Retro UNIX 8086 v1 modification: 
 32561                              <1> 	;       'sysquit' system call sets u.quit to value of BX
 32562                              <1> 	;	then branches into 'sysret'.
 32563                              <1> 	;
 32564 0000AECD 66891D[1ED50000]    <1> 	mov	[u.quit], bx
 32565 0000AED4 E981EDFFFF          <1> 	jmp	sysret
 32566                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
 32567                              <1> 	;1:
 32568                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
 32569                              <1> 			      ; / to r1
 32570                              <1> 		; beq sysret4 / return to user
 32571                              <1> 		; clrb 6(r1) / clear the interrupt character 
 32572                              <1> 			   ; / in the tty buffer
 32573                              <1> 		; br sysret4 / return to user
 32574                              <1> 
 32575                              <1> syssetuid: ; / set process id
 32576                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32577                              <1> 	; 07/07/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 32578                              <1> 	;
 32579                              <1> 	; 'syssetuid' sets the user id (u.uid) of the current process
 32580                              <1> 	; to the process id in (u.r0). Both the effective user and 
 32581                              <1> 	; u.uid and the real user u.ruid are set to this. 
 32582                              <1> 	; Only the super user can make this call.	
 32583                              <1> 	;
 32584                              <1> 	; Calling sequence:
 32585                              <1> 	;	syssetuid
 32586                              <1> 	; Arguments: -
 32587                              <1> 	;
 32588                              <1> 	; Inputs: (u.r0) - contains the process id.
 32589                              <1> 	; Outputs: -
 32590                              <1> 	; ...............................................................
 32591                              <1> 	;	
 32592                              <1> 	; Retro UNIX 8086 v1 modification: 
 32593                              <1> 	;       BL contains the (new) user ID of the current process
 32594                              <1> 
 32595                              <1> 		; movb *u.r0,r1 / move process id (number) to r1
 32596 0000AED9 3A1D[25D50000]      <1> 	cmp	bl, [u.ruid] 
 32597                              <1> 		; cmpb r1,u.ruid / is it equal to the real user 
 32598                              <1> 			       ; / id number
 32599 0000AEDF 741E                <1> 	je	short setuid1
 32600                              <1> 		; beq 1f / yes
 32601 0000AEE1 803D[24D50000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 32602                              <1> 		; tstb u.uid / no, is current user the super user?
 32603                              <1> 	;ja	error
 32604                              <1> 		; bne error4 / no, error
 32605 0000AEE8 760F                <1> 	jna	short setuid0
 32606 0000AEEA C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11
 32607 0000AEF2 0000                <1>
 32608                              <1> 				;  'permission denied !' error
 32609 0000AEF4 E941EDFFFF          <1> 	jmp	error
 32610                              <1> setuid0:
 32611 0000AEF9 881D[25D50000]      <1> 	mov	[u.ruid], bl
 32612                              <1> setuid1: ; 1:
 32613 0000AEFF 881D[24D50000]      <1> 	mov	[u.uid], bl ; 02/08/2013
 32614                              <1> 		; movb r1,u.uid / put process id in u.uid
 32615                              <1> 		; movb r1,u.ruid / put process id in u.ruid
 32616 0000AF05 E950EDFFFF          <1> 	jmp	sysret
 32617                              <1> 		; br sysret4 / system return
 32618                              <1> 
 32619                              <1> sysgetuid: ; < get user id >
 32620                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32621                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 32622                              <1> 	;
 32623                              <1> 	; 'sysgetuid' returns the real user ID of the current process.
 32624                              <1> 	; The real user ID identifies the person who is logged in,
 32625                              <1> 	; in contradistinction to the effective user ID, which
 32626                              <1> 	; determines his access permission at each moment. It is thus
 32627                              <1> 	; useful to programs which operate using the 'set user ID'
 32628                              <1> 	; mode, to find out who invoked them.	
 32629                              <1> 	;
 32630                              <1> 	; Calling sequence:
 32631                              <1> 	;	syssetuid
 32632                              <1> 	; Arguments: -
 32633                              <1> 	;
 32634                              <1> 	; Inputs: -
 32635                              <1> 	; Outputs: (u.r0) - contains the real user's id.
 32636                              <1> 	; ...............................................................
 32637                              <1> 	;	
 32638                              <1> 	; Retro UNIX 8086 v1 modification: 
 32639                              <1> 	;       AL contains the real user ID at return.
 32640                              <1> 	;
 32641 0000AF0A 0FB605[25D50000]    <1> 	movzx 	eax, byte [u.ruid]
 32642 0000AF11 A3[D8D40000]        <1> 	mov	[u.r0], eax
 32643                              <1> 		; movb	u.ruid,*u.r0 / move the real user id to (u.r0)
 32644 0000AF16 E93FEDFFFF          <1> 	jmp	sysret
 32645                              <1> 		; br sysret4 / systerm return, sysret
 32646                              <1> 
 32647                              <1> anyi: 
 32648                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 32649                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
 32650                              <1> 	;
 32651                              <1> 	; 'anyi' is called if a file deleted while open.
 32652                              <1> 	; "anyi" checks to see if someone else has opened this file.
 32653                              <1> 	;
 32654                              <1> 	; INPUTS ->
 32655                              <1> 	;    r1 - contains an i-number
 32656                              <1> 	;    fsp - start of table containing open files
 32657                              <1> 	;
 32658                              <1> 	; OUTPUTS ->
 32659                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
 32660                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
 32661                              <1> 	;    if file not found - bit in i-node map is cleared
 32662                              <1> 	;    			 (i-node is freed)
 32663                              <1> 	;               all blocks related to i-node are freed
 32664                              <1> 	;	        all flags in i-node are cleared
 32665                              <1> 	; ((AX = R1)) input
 32666                              <1> 	;
 32667                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
 32668                              <1>         ;    ((Modified registers: eDX, eCX, eBX, eSI, eDI, eBP))  
 32669                              <1> 	;
 32670                              <1> 		; / r1 contains an i-number
 32671 0000AF1B BB[ACD20000]        <1> 	mov	ebx, fsp
 32672                              <1> 		; mov $fsp,r2 / move start of fsp table to r2
 32673                              <1> anyi_1: ; 1:
 32674 0000AF20 663B03              <1> 	cmp	ax, [ebx]
 32675                              <1> 		; cmp r1,(r2) / do i-numbers match?
 32676 0000AF23 7433                <1> 	je	short anyi_3
 32677                              <1> 		; beq 1f / yes, 1f
 32678 0000AF25 66F7D8              <1> 	neg	ax
 32679                              <1> 		; neg r1 / no complement r1
 32680 0000AF28 663B03              <1> 	cmp	ax, [ebx]
 32681                              <1> 		; cmp r1,(r2) / do they match now?
 32682 0000AF2B 742B                <1> 	je	short anyi_3
 32683                              <1> 		; beq 1f / yes, transfer
 32684                              <1> 		; / i-numbers do not match
 32685 0000AF2D 83C30A              <1> 	add	ebx, 10 ; fsp table size is 10 bytes
 32686                              <1> 			; in Retro UNIX 386 v1 (22/06/2015)
 32687                              <1> 		; add $8,r2 / no, bump to next entry in fsp table
 32688 0000AF30 81FB[A0D40000]      <1> 	cmp	ebx, fsp + (nfiles*10) ; 22/06/2015 
 32689                              <1> 		; cmp r2,$fsp+[nfiles*8] 
 32690                              <1> 				; / are we at last entry in the table
 32691 0000AF36 72E8                <1> 	jb	short anyi_1
 32692                              <1> 		; blt 1b / no, check next entries i-number
 32693                              <1> 	;cmp	ax, 32768
 32694 0000AF38 80FC80              <1> 	cmp	ah, 80h ; negative number check
 32695                              <1> 		; tst r1 / yes, no match
 32696                              <1> 		; bge .+4
 32697 0000AF3B 7203                <1> 	jb	short anyi_2
 32698 0000AF3D 66F7D8              <1> 	neg	ax
 32699                              <1> 		; neg r1 / make i-number positive
 32700                              <1> anyi_2:	
 32701 0000AF40 E864020000          <1> 	call	imap
 32702                              <1> 		; jsr r0,imap / get address of allocation bit 
 32703                              <1> 			    ; / in the i-map in r2
 32704                              <1> 	;; DL/DX (MQ) has a 1 in the calculated bit position
 32705                              <1>         ;; eBX (R2) has address of the byte with allocation bit
 32706                              <1>  	; not	dx
 32707 0000AF45 F6D2                <1> 	not 	dl ;; 0 at calculated bit position, other bits are 1
 32708                              <1>         ;and	[ebx], dx
 32709 0000AF47 2013                <1> 	and 	[ebx], dl 
 32710                              <1> 		; bicb mq,(r2) / clear bit for i-node in the imap
 32711 0000AF49 E850020000          <1> 	call	itrunc
 32712                              <1> 		; jsr r0,itrunc / free all blocks related to i-node
 32713 0000AF4E 66C705[ACD10000]00- <1>  	mov 	word [i.flgs], 0
 32714 0000AF56 00                  <1>
 32715                              <1> 		; clr i.flgs / clear all flags in the i-node
 32716 0000AF57 C3                  <1> 	retn
 32717                              <1> 		;rts	r0 / return
 32718                              <1> anyi_3: ; 1: / i-numbers match
 32719 0000AF58 FE4309              <1> 	inc 	byte [ebx+9] ; 22/06/2015
 32720                              <1> 		;incb 7(r2) / increment upper byte of the 4th word
 32721                              <1> 		   ; / in that fsp entry (deleted flag of fsp entry)
 32722 0000AF5B C3                  <1> 	retn
 32723                              <1> 		; rts r0
 32724                              <1> 
 32725                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u7.s
 32726                              <1> ; Last Modification: 14/11/2015
 32727                              <1> 
 32728                              <1> sysmount: ; / mount file system; args special; name
 32729                              <1> 	; 14/11/2015
 32730                              <1> 	; 24/10/2015
 32731                              <1> 	; 13/10/2015
 32732                              <1> 	; 10/07/2015
 32733                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 32734                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 32735                              <1> 	;
 32736                              <1> 	; 'sysmount' anounces to the system that a removable 
 32737                              <1> 	; file system has been mounted on a special file.
 32738                              <1> 	; The device number of the special file is obtained via
 32739                              <1> 	; a call to 'getspl'. It is put in the I/O queue entry for
 32740                              <1> 	; dismountable file system (sb1) and the I/O queue entry is
 32741                              <1> 	; set up to read (bit 10 is set). 'ppoke' is then called to
 32742                              <1> 	; to read file system into core, i.e. the first block on the
 32743                              <1> 	; mountable file system is read in. This block is super block
 32744                              <1> 	; for the file system. This call is super user restricted.	
 32745                              <1> 	;
 32746                              <1> 	; Calling sequence:
 32747                              <1> 	;	sysmount; special; name
 32748                              <1> 	; Arguments:
 32749                              <1> 	;	special - pointer to name of special file (device)
 32750                              <1> 	;	name -  pointer to name of the root directory of the
 32751                              <1> 	;		newly mounted file system. 'name' should 
 32752                              <1> 	;		always be a directory.
 32753                              <1> 	; Inputs: - 
 32754                              <1> 	; Outputs: -
 32755                              <1> 	; ...............................................................
 32756                              <1> 	;				
 32757                              <1> 	; Retro UNIX 8086 v1 modification: 
 32758                              <1> 	;       'sysmount' system call has two arguments; so,
 32759                              <1> 	;	* 1st argument, special is pointed to by BX register
 32760                              <1> 	;	* 2nd argument, name is in CX register
 32761                              <1> 	;
 32762                              <1> 	;	NOTE: Device numbers, names and related procedures are 
 32763                              <1> 	;	       already modified for IBM PC compatibility and 
 32764                              <1> 	;	       Retro UNIX 8086 v1 device configuration.	
 32765                              <1> 	
 32766                              <1> 	;call	arg2
 32767                              <1> 		; jsr r0,arg2 / get arguments special and name
 32768 0000AF5C 891D[F0D40000]      <1> 	mov	[u.namep], ebx
 32769 0000AF62 51                  <1> 	push	ecx ; directory name
 32770 0000AF63 66833D[C2D40000]00  <1> 	cmp	word [mnti], 0
 32771                              <1> 		; tst mnti / is the i-number of the cross device file
 32772                              <1> 			 ; / zero?
 32773                              <1> 	;ja	error
 32774                              <1>         	; bne errora / no, error
 32775 0000AF6B 0F87E9000000        <1> 	ja	sysmnt_err0
 32776                              <1> 	;
 32777 0000AF71 E8CC000000          <1> 	call	getspl
 32778                              <1> 		; jsr r0,getspl / get special files device number in r1
 32779                              <1> 	; 13/10/2015
 32780 0000AF76 0FB7D8              <1> 	movzx	ebx, ax ; ; Retro UNIX 8086 v1 device number (0 to 5)
 32781 0000AF79 F683[9ABF0000]80    <1>         test    byte [ebx+drv.status], 80h ; 24/10/2015 
 32782 0000AF80 750F                <1> 	jnz	short sysmnt_1
 32783                              <1> sysmnt_err1:
 32784 0000AF82 C705[2DD50000]0F00- <1>         mov     dword [u.error], ERR_DRV_NOT_RDY ; drive not ready !
 32785 0000AF8A 0000                <1>
 32786 0000AF8C E9A9ECFFFF          <1> 	jmp	error
 32787                              <1> sysmnt_1:
 32788 0000AF91 8F05[F0D40000]      <1> 	pop	dword [u.namep]
 32789                              <1>         	; mov (sp)+,u.namep / put the name of file to be placed
 32790                              <1> 				  ; / on the device
 32791                              <1> 	; 14/11/2015
 32792 0000AF97 53                  <1> 	push	ebx ; 13/10/2015
 32793                              <1> 		; mov r1,-(sp) / save the device number
 32794                              <1>         ;
 32795 0000AF98 E859FBFFFF          <1> 	call	namei
 32796                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 32797                              <1> 		       ; ax = 0 -> file not found 	
 32798                              <1> 	;jz	error
 32799                              <1> 	;jc	error
 32800                              <1> 		; jsr r0,namei / get the i-number of the file
 32801                              <1>                	; br errora
 32802 0000AF9D 730F                <1> 	jnc	short sysmnt_2
 32803                              <1> sysmnt_err2:
 32804 0000AF9F C705[2DD50000]0C00- <1>         mov     dword [u.error], ERR_FILE_NOT_FOUND ; drive not ready !
 32805 0000AFA7 0000                <1>
 32806 0000AFA9 E98CECFFFF          <1> 	jmp	error
 32807                              <1> sysmnt_2:	
 32808 0000AFAE 66A3[C2D40000]      <1> 	mov	[mnti], ax
 32809                              <1>         	; mov r1,mnti / put it in mnti
 32810                              <1> ;	mov	ebx, sb1 ; super block buffer (of mounted disk)
 32811                              <1> sysmnt_3: ;1:
 32812                              <1>         ;cmp	byte [ebx+1], 0
 32813                              <1> 		; tstb sb1+1 / is 15th bit of I/O queue entry for
 32814                              <1> 			   ; / dismountable device set?
 32815                              <1>         ;jna	short sysmnt_4		
 32816                              <1> 		; bne 1b / (inhibit bit) yes, skip writing
 32817                              <1> 	;call	idle 	; (wait for hardware interrupt)
 32818                              <1> 	;jmp	short sysmnt_3
 32819                              <1> sysmnt_4:   
 32820 0000AFB4 58                  <1> 	pop	eax ; Retro UNIX 8086 v1 device number/ID (0 to 5)     
 32821 0000AFB5 A2[BFD40000]        <1> 	mov	[mdev], al
 32822                              <1> 		; mov  (sp),mntd / no, put the device number in mntd
 32823 0000AFBA 8803                <1> 	mov	[ebx], al
 32824                              <1>         	; movb (sp),sb1 / put the device number in the lower byte
 32825                              <1> 			      ; / of the I/O queue entry
 32826                              <1> 	;mov	byte [cdev], 1 ; mounted device/drive
 32827                              <1>         	; mov (sp)+,cdev / put device number in cdev
 32828 0000AFBC 66810B0004          <1>         or	word [ebx], 400h ; Bit 10, 'read' flag/bit
 32829                              <1> 		; bis $2000,sb1 / set the read bit
 32830                              <1> 	; Retro UNIX 386 v1 modification : 
 32831                              <1> 	;	32 bit block number at buffer header offset 4
 32832 0000AFC1 C7430401000000      <1> 	mov	dword [ebx+4], 1 ; physical block number = 1
 32833 0000AFC8 E8DD010000          <1> 	call 	diskio
 32834 0000AFCD 731C                <1> 	jnc	short sysmnt_5
 32835 0000AFCF 31C0                <1> 	xor 	eax, eax
 32836 0000AFD1 66A3[C2D40000]      <1> 	mov	[mnti], ax ; 0
 32837 0000AFD7 A2[BFD40000]        <1> 	mov	[mdev], al ; 0
 32838                              <1> 	;mov	[cdev], al ; 0
 32839                              <1> sysmnt_invd:
 32840                              <1> 	; 14/11/2015
 32841 0000AFDC FEC8                <1> 	dec 	al
 32842 0000AFDE 8903                <1> 	mov	[ebx], eax ; 000000FFh
 32843 0000AFE0 FEC0                <1> 	inc	al
 32844 0000AFE2 48                  <1> 	dec	eax
 32845 0000AFE3 894304              <1> 	mov	[ebx+4], eax ; 0FFFFFFFFh
 32846 0000AFE6 E94FECFFFF          <1> 	jmp	error
 32847                              <1> sysmnt_5:
 32848                              <1> 	; 14/11/2015 (Retro UNIX 386 v1 modification)
 32849                              <1> 	; (Following check is needed to prevent mounting an
 32850                              <1> 	; in valid valid file system (in valid super block).
 32851                              <1> 	; 
 32852 0000AFEB 0FB603              <1> 	movzx	eax, byte [ebx] ; device number
 32853 0000AFEE C0E002              <1> 	shl	al, 2 ; 4*index
 32854 0000AFF1 8B88[7EBF0000]      <1> 	mov	ecx, [eax+drv.size] ; volume (fs) size
 32855 0000AFF7 C1E103              <1> 	shl 	ecx, 3
 32856 0000AFFA 0FB715[89DF0000]    <1> 	movzx	edx, word [sb1+4] ; the 1st data word
 32857 0000B001 39D1                <1> 	cmp	ecx, edx ; compare free map bits and volume size
 32858                              <1> 			 ; (in sectors), if they are not equal
 32859                              <1> 			 ; the disk to be mounted is an...	
 32860 0000B003 75D7                <1> 	jne	short sysmnt_invd ; invalid disk !
 32861                              <1> 			 ; (which has not got a valid super block)
 32862                              <1> 	;
 32863 0000B005 C6430100            <1> 	mov	byte [ebx+1], 0
 32864                              <1> 	       	; jsr r0,ppoke / read in entire file system
 32865                              <1> ;sysmnt_6: ;1:
 32866                              <1> 	;;cmp	byte [sb1+1], 0
 32867                              <1> 		; tstb   sb1+1 / done reading?
 32868                              <1>    	;;jna	sysret
 32869                              <1> 	;;call	idle ; (wait for hardware interrupt)
 32870                              <1> 	;;jmp	short sysmnt_6
 32871                              <1> 		;bne 1b / no, wait
 32872                              <1>         	;br sysreta / yes
 32873 0000B009 E94CECFFFF          <1> 	jmp	sysret
 32874                              <1> 
 32875                              <1> sysumount: ; / special dismount file system
 32876                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 32877                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 32878                              <1> 	;
 32879                              <1> 	; 04/11/2013
 32880                              <1> 	; 09/07/2013
 32881                              <1> 	; 'sysumount' anounces to the system that the special file, 
 32882                              <1> 	; indicated as an argument is no longer contain a removable
 32883                              <1> 	; file system. 'getspl' gets the device number of the special
 32884                              <1> 	; file. If no file system was mounted on that device an error
 32885                              <1> 	; occurs. 'mntd' and 'mnti' are cleared and control is passed
 32886                              <1> 	; to 'sysret'.
 32887                              <1> 	;
 32888                              <1> 	; Calling sequence:
 32889                              <1> 	;	sysmount; special
 32890                              <1> 	; Arguments:
 32891                              <1> 	;	special - special file to dismount (device)
 32892                              <1> 	;
 32893                              <1> 	; Inputs: - 
 32894                              <1> 	; Outputs: -
 32895                              <1> 	; ...............................................................
 32896                              <1> 	;				
 32897                              <1> 	; Retro UNIX 8086 v1 modification: 
 32898                              <1> 	;       'sysumount' system call has one argument; so,
 32899                              <1> 	;	* Single argument, special is pointed to by BX register
 32900                              <1> 	;
 32901                              <1> 	
 32902                              <1> 	;mov 	ax, 1 ; one/single argument, put argument in BX	
 32903                              <1> 	;call	arg
 32904                              <1> 		; jsr r0,arg; u.namep / point u.namep to special
 32905 0000B00E 891D[F0D40000]      <1>         mov	[u.namep], ebx
 32906 0000B014 E829000000          <1> 	call	getspl
 32907                              <1> 		; jsr r0,getspl / get the device number in r1
 32908 0000B019 3A05[BFD40000]      <1> 	cmp	al, [mdev]
 32909                              <1> 		; cmp r1,mntd / is it equal to the last device mounted?
 32910 0000B01F 7539                <1> 	jne	short sysmnt_err0 ; 'permission denied !' error
 32911                              <1> 	;jne	error
 32912                              <1>         	; bne errora / no error
 32913 0000B021 30C0                <1> 	xor	al, al ; ah = 0
 32914                              <1> sysumnt_0: ;1:
 32915 0000B023 3805[86DF0000]      <1>      	cmp 	[sb1+1], al ; 0
 32916                              <1> 		; tstb sb1+1 / yes, is the device still doing I/O 
 32917                              <1> 			   ; / (inhibit bit set)?
 32918 0000B029 7607                <1> 	jna	short sysumnt_1		
 32919                              <1> 		; bne 1b / yes, wait
 32920 0000B02B E87B010000          <1> 	call	idle ; (wait for hardware interrupt)
 32921 0000B030 EBF1                <1> 	jmp	short sysumnt_0
 32922                              <1> sysumnt_1:        
 32923 0000B032 A2[BFD40000]        <1> 	mov	[mdev], al
 32924                              <1> 	     	; clr mntd / no, clear these
 32925 0000B037 66A3[C2D40000]      <1>    	mov	[mnti], ax
 32926                              <1>         	; clr mnti
 32927 0000B03D E918ECFFFF          <1>         jmp	sysret
 32928                              <1> 		; br sysreta / return
 32929                              <1> 
 32930                              <1> getspl: ; / get device number from a special file name
 32931 0000B042 E8AFFAFFFF          <1> 	call	namei
 32932                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 32933                              <1> 		       ; ax = 0 -> file not found 	
 32934 0000B047 0F8252FFFFFF        <1>         jc      sysmnt_err2 ; 'file not found !' error
 32935                              <1> 	;jz	error
 32936                              <1> 	;jc	error
 32937                              <1> 		; jsr r0,namei / get the i-number of the special file
 32938                              <1>                 ; br errora / no such file
 32939 0000B04D 6683E803            <1>         sub	ax, 3 ; Retro UNIX 8086 v1 modification !
 32940                              <1> 		      ;	i-number-3, 0 = fd0, 5 = hd3 
 32941                              <1> 		; sub $4,r1 / i-number-4 rk=1,tap=2+n
 32942 0000B051 7207                <1>         jc	short sysmnt_err0 ; 'permission denied !' error
 32943                              <1> 	;jc	error
 32944                              <1> 		; ble errora / less than 0?  yes, error
 32945 0000B053 6683F805            <1>         cmp	ax, 5 ;
 32946                              <1> 		; cmp  r1,$9. / greater than 9  tap 7
 32947 0000B057 7701                <1> 	ja	short sysmnt_err0 ; 'permission denied !' error
 32948                              <1> 	;ja	error
 32949                              <1>         	; bgt errora / yes, error
 32950                              <1>         ; AX = Retro UNIX 8086 v1 Device Number (0 to 5)
 32951                              <1> iopen_retn:
 32952 0000B059 C3                  <1> 	retn
 32953                              <1> 		; rts    r0 / return with device number in r1
 32954                              <1> sysmnt_err0:
 32955 0000B05A C705[2DD50000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 32956 0000B062 0000                <1>
 32957 0000B064 E9D1EBFFFF          <1> 	jmp	error
 32958                              <1> 
 32959                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
 32960                              <1> ; Last Modification: 09/12/2015
 32961                              <1> 
 32962                              <1> syssleep:
 32963                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
 32964                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
 32965                              <1> 	;
 32966                              <1> 	; Retro UNIX 8086 v1 feature only
 32967                              <1> 	; (INPUT -> none)
 32968                              <1> 	;
 32969 0000B069 0FB61D[27D50000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 32970 0000B070 8AA3[2BD20000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
 32971 0000B076 E831010000          <1> 	call	sleep
 32972 0000B07B E9DAEBFFFF          <1> 	jmp	sysret
 32973                              <1> 
 32974                              <1> vp_clr:
 32975                              <1> 	; Reset/Clear Video Page
 32976                              <1> 	;
 32977                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
 32978                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
 32979                              <1> 	;
 32980                              <1> 	; Retro UNIX 8086 v1 feature only !
 32981                              <1> 	;
 32982                              <1> 	; INPUTS -> 
 32983                              <1> 	;   BL = video page number	 
 32984                              <1> 	;
 32985                              <1> 	; OUTPUT ->
 32986                              <1> 	;   none
 32987                              <1> 	; ((Modified registers: eAX, BH, eCX, eDX, eSI, eDI))
 32988                              <1> 	;
 32989                              <1> 	; 04/12/2013
 32990 0000B080 28C0                <1> 	sub	al, al
 32991                              <1> 	; al = 0 (clear video page)
 32992                              <1> 	; bl = video page
 32993 0000B082 B407                <1> 	mov	ah, 07h
 32994                              <1> 	; ah = 7 (attribute/color)
 32995 0000B084 6631C9              <1> 	xor 	cx, cx ; 0, left upper column (cl) & row (cl)
 32996 0000B087 66BA4F18            <1> 	mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
 32997 0000B08B E87D65FFFF          <1> 	call	_scroll_up
 32998                              <1> 	; bl = video page
 32999 0000B090 6631D2              <1> 	xor	dx, dx ; 0 (cursor position) 
 33000 0000B093 E9B367FFFF          <1> 	jmp 	_set_cpos
 33001                              <1> 
 33002                              <1> sysmsg:
 33003                              <1> 	; 11/11/2015
 33004                              <1> 	; 01/07/2015 - (Retro UNIX 386 v1 feature only!)
 33005                              <1> 	; Print user-application message on user's console tty
 33006                              <1> 	;
 33007                              <1> 	; Input -> EBX = Message address
 33008                              <1> 	;	   ECX = Message length (max. 255)
 33009                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
 33010                              <1> 	;
 33011 0000B098 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
 33012 0000B09E 0F87B6EBFFFF        <1> 	ja	sysret ; nothing to do with big message size
 33013 0000B0A4 08C9                <1> 	or	cl, cl
 33014 0000B0A6 0F84AEEBFFFF        <1> 	jz	sysret
 33015 0000B0AC 20D2                <1> 	and	dl, dl
 33016 0000B0AE 7502                <1> 	jnz	short sysmsg0
 33017 0000B0B0 B207                <1> 	mov	dl, 07h ; default color
 33018                              <1> 		; (black background, light gray character) 
 33019                              <1> sysmsg0:
 33020 0000B0B2 891D[F8D40000]      <1> 	mov	[u.base], ebx
 33021 0000B0B8 8815[A9C40000]      <1> 	mov	[ccolor], dl ; color attributes
 33022 0000B0BE 89E5                <1> 	mov	ebp, esp
 33023 0000B0C0 31DB                <1> 	xor	ebx, ebx ; 0
 33024 0000B0C2 891D[00D50000]      <1> 	mov	[u.nread], ebx ; 0
 33025                              <1> 	;
 33026 0000B0C8 381D[3FD50000]      <1> 	cmp	[u.kcall], bl ; 0
 33027 0000B0CE 7769                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
 33028                              <1> 	;
 33029 0000B0D0 890D[FCD40000]      <1> 	mov	[u.count], ecx
 33030 0000B0D6 41                  <1> 	inc	ecx ; + 00h ; ASCIZZ
 33031 0000B0D7 29CC                <1> 	sub	esp, ecx
 33032 0000B0D9 89E7                <1> 	mov	edi, esp
 33033 0000B0DB 89E6                <1> 	mov	esi, esp
 33034 0000B0DD 66891D[3DD50000]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
 33035                              <1> 	; 11/11/2015
 33036 0000B0E4 8A25[08D50000]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
 33037                              <1> 	; 0 = none
 33038 0000B0EA FECC                <1> 	dec	ah
 33039 0000B0EC 790C                <1> 	jns	short sysmsg1 
 33040 0000B0EE 8A1D[27D50000]      <1> 	mov	bl, [u.uno] ; process number	
 33041 0000B0F4 8AA3[2BD20000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
 33042                              <1> sysmsg1:
 33043 0000B0FA 8825[2CD50000]      <1> 	mov	[u.ttyn], ah
 33044                              <1> sysmsg2:
 33045 0000B100 E8A0000000          <1> 	call	cpass
 33046 0000B105 7416                <1> 	jz	short sysmsg5
 33047 0000B107 AA                  <1> 	stosb
 33048 0000B108 20C0                <1> 	and	al, al
 33049 0000B10A 75F4                <1> 	jnz	short sysmsg2
 33050                              <1> sysmsg3:
 33051 0000B10C 80FC07              <1> 	cmp	ah, 7 ; tty number
 33052 0000B10F 7711                <1> 	ja	short sysmsg6 ; serial port
 33053 0000B111 E83E000000          <1> 	call	print_cmsg
 33054                              <1> sysmsg4:
 33055 0000B116 89EC                <1> 	mov	esp, ebp	
 33056 0000B118 E93DEBFFFF          <1> 	jmp	sysret
 33057                              <1> sysmsg5:
 33058 0000B11D C60700              <1> 	mov	byte [edi], 0
 33059 0000B120 EBEA                <1> 	jmp	short sysmsg3
 33060                              <1> sysmsg6:
 33061 0000B122 8A06                <1> 	mov	al, [esi]
 33062 0000B124 E87A000000          <1> 	call	sndc
 33063 0000B129 72EB                <1> 	jc	short sysmsg4
 33064 0000B12B 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
 33065 0000B12E 76E6                <1> 	jna	short sysmsg4
 33066 0000B130 46                  <1> 	inc 	esi
 33067 0000B131 8A25[2CD50000]      <1> 	mov	ah, [u.ttyn]
 33068 0000B137 EBE9                <1> 	jmp	short sysmsg6
 33069                              <1> 
 33070                              <1> sysmsgk: ; Temporary (01/07/2015)
 33071                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
 33072                              <1> 	; (ECX -character count- will not be considered)
 33073 0000B139 8B35[F8D40000]      <1> 	mov	esi, [u.base]
 33074 0000B13F 8A25[A8C40000]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
 33075 0000B145 8825[2CD50000]      <1> 	mov	[u.ttyn], ah
 33076 0000B14B C605[3FD50000]00    <1> 	mov	byte [u.kcall], 0
 33077 0000B152 EBB8                <1> 	jmp	short sysmsg3
 33078                              <1> 	
 33079                              <1> 
 33080                              <1> print_cmsg: 
 33081                              <1> 	; 01/07/2015 (retro UNIX 386 v1 feature only !)
 33082                              <1> 	;
 33083                              <1> 	; print message (on user's console tty) 
 33084                              <1> 	;	with requested color
 33085                              <1> 	;
 33086                              <1> 	; INPUTS:
 33087                              <1> 	;	esi = message address
 33088                              <1> 	;	[u.ttyn] = tty number (0 to 7)
 33089                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
 33090                              <1> 	;
 33091 0000B154 AC                  <1> 	lodsb
 33092                              <1> pcmsg1:
 33093 0000B155 56                  <1> 	push 	esi
 33094 0000B156 0FB61D[2CD50000]    <1>         movzx   ebx, byte [u.ttyn]
 33095 0000B15D 8A25[A9C40000]      <1> 	mov	ah, [ccolor]
 33096 0000B163 E84F66FFFF          <1> 	call 	WRITE_TTY
 33097 0000B168 5E                  <1> 	pop	esi
 33098 0000B169 AC                  <1> 	lodsb
 33099 0000B16A 20C0                <1> 	and 	al, al  ; 0
 33100 0000B16C 75E7                <1> 	jnz 	short pcmsg1
 33101 0000B16E C3                  <1> 	retn
 33102                              <1> 
 33103                              <1> sysgeterr:
 33104                              <1> 	; 09/12/2015
 33105                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
 33106                              <1> 	; Get last error number or page fault count
 33107                              <1> 	; (for debugging)
 33108                              <1> 	;
 33109                              <1> 	; Input -> EBX = return type
 33110                              <1> 	;	   0 = last error code (which is in 'u.error')	
 33111                              <1> 	;	   FFFFFFFFh = page fault count for running process
 33112                              <1> 	;	   FFFFFFFEh = total page fault count
 33113                              <1> 	;	   1 .. FFFFFFFDh = undefined 
 33114                              <1> 	;
 33115                              <1> 	; Output -> EAX = last error number or page fault count
 33116                              <1> 	;	   (depending on EBX input)
 33117                              <1> 	; 	
 33118 0000B16F 21DB                <1> 	and 	ebx, ebx
 33119 0000B171 750B                <1> 	jnz	short glerr_2
 33120                              <1> glerr_0:
 33121 0000B173 A1[2DD50000]        <1> 	mov	eax, [u.error]
 33122                              <1> glerr_1:
 33123 0000B178 A3[D8D40000]        <1> 	mov	[u.r0], eax
 33124 0000B17D C3                  <1>  	retn
 33125                              <1> glerr_2:
 33126 0000B17E 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
 33127 0000B17F 74FD                <1> 	jz	short glerr_2 ; page fault count for process
 33128 0000B181 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
 33129 0000B182 75EF                <1> 	jnz	short glerr_0
 33130 0000B184 A1[ACE10000]        <1> 	mov	eax, [PF_Count] ; total page fault count
 33131 0000B189 EBED                <1>         jmp     short glerr_1
 33132                              <1> glerr_3:
 33133 0000B18B A1[41D50000]        <1> 	mov 	eax, [u.pfcount]
 33134 0000B190 EBE6                <1> 	jmp	short glerr_1
 33135                              <1> 
 33136                              <1> ; temporary - 24/01/2016
 33137                              <1> 
 33138                              <1> iget:
 33139 0000B192 C3                  <1> 	retn
 33140                              <1> poke:
 33141 0000B193 C3                  <1> 	retn
 33142                              <1> tswap:
 33143 0000B194 C3                  <1> 	retn
 33144                              <1> isintr:
 33145 0000B195 C3                  <1> 	retn
 33146                              <1> writei:
 33147 0000B196 C3                  <1> 	retn
 33148                              <1> readi:
 33149 0000B197 C3                  <1> 	retn
 33150                              <1> putlu:
 33151 0000B198 C3                  <1> 	retn
 33152                              <1> swap:
 33153 0000B199 C3                  <1> 	retn
 33154                              <1> wswap:
 33155 0000B19A C3                  <1> 	retn
 33156                              <1> rswap:
 33157 0000B19B C3                  <1> 	retn
 33158                              <1> iopen:
 33159 0000B19C C3                  <1> 	retn
 33160                              <1> iclose:
 33161 0000B19D C3                  <1> 	retn
 33162                              <1> itrunc:
 33163 0000B19E C3                  <1> 	retn
 33164                              <1> clock:
 33165 0000B19F C3                  <1> 	retn
 33166                              <1> setimod:
 33167 0000B1A0 C3                  <1> 	retn
 33168                              <1> ottyp:
 33169 0000B1A1 C3                  <1> 	retn
 33170                              <1> cttyp:
 33171 0000B1A2 C3                  <1> 	retn
 33172                              <1> sndc:
 33173 0000B1A3 C3                  <1> 	retn
 33174                              <1> access:
 33175 0000B1A4 C3                  <1> 	retn
 33176                              <1> cpass:
 33177 0000B1A5 C3                  <1> 	retn
 33178                              <1> passc:
 33179 0000B1A6 C3                  <1> 	retn
 33180                              <1> epoch:
 33181 0000B1A7 C3                  <1> 	retn
 33182                              <1> set_date_time:
 33183 0000B1A8 C3                  <1> 	retn
 33184                              <1> imap:
 33185 0000B1A9 C3                  <1> 	retn
 33186                              <1> diskio:
 33187 0000B1AA C3                  <1> 	retn
 33188                              <1> idle:
 33189 0000B1AB C3                  <1> 	retn
 33190                              <1> sleep:
 33191 0000B1AC C3                  <1> 	retn
 33192                              <1> 
 33193                              <1> 
 33194                              <1> 
 33195                                  %include 'trdosk7.s' ; 24/01/2016
 33196                              <1> ; ****************************************************************************
 33197                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DISK READ&WRITE : trdosk7.s
 33198                              <1> ; ----------------------------------------------------------------------------
 33199                              <1> ; Last Update: 25/02/2016
 33200                              <1> ; ----------------------------------------------------------------------------
 33201                              <1> ; Beginning: 24/01/2016
 33202                              <1> ; ----------------------------------------------------------------------------
 33203                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 33204                              <1> ; ----------------------------------------------------------------------------
 33205                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 33206                              <1> ; DISK_IO.ASM (20/07/2011)
 33207                              <1> ; ****************************************************************************
 33208                              <1> ; DISK_IO.ASM (c) 2009-2011 Erdogan TAN [ 04/07/2009 ] Last Update: 20/07/2011
 33209                              <1> 
 33210                              <1> disk_write:
 33211                              <1> 	; 25/02/2016
 33212                              <1> 	; 24/02/2016
 33213                              <1> 	; 23/02/2016
 33214 0000B1AD 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 33215 0000B1B1 777B                <1>         ja      short lba_write
 33216                              <1> 
 33217                              <1> chs_write:
 33218                              <1> 	; 25/02/2016
 33219                              <1> 	; 23/02/2016
 33220 0000B1B3 C605[35CE0000]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
 33221 0000B1BA EB0D                <1> 	jmp	short chs_rw
 33222                              <1> 
 33223                              <1> disk_read:
 33224                              <1> 	; 25/02/2016
 33225                              <1> 	; 24/02/2016
 33226                              <1> 	; 23/02/2016
 33227                              <1> 	; 17/02/2016
 33228                              <1> 	; 14/02/2016
 33229                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 33230                              <1> 	; 17/10/2010
 33231                              <1> 	; 18/04/2010
 33232                              <1> 	;
 33233                              <1> 	; INPUT -> EAX = Logical Block Address
 33234                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 33235                              <1> 	;	   ECX = Sector Count	
 33236                              <1> 	; 	   EBX = Destination Buffer
 33237                              <1> 	; OUTPUT -> 
 33238                              <1> 	;	   cf = 0 or cf = 1
 33239                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 33240                              <1> 
 33241 0000B1BC 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 33242 0000B1C0 7775                <1>         ja      short lba_read
 33243                              <1> 
 33244                              <1> chs_read:
 33245                              <1> 	; 25/02/2016
 33246                              <1> 	; 24/02/2016
 33247                              <1> 	; 23/02/2016
 33248                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 33249                              <1> 	; 20/07/2011
 33250                              <1> 	; 04/07/2009
 33251                              <1> 	;
 33252                              <1> 	; INPUT -> EAX = Logical Block Address
 33253                              <1> 	;	   ECX = Number of sectors to read
 33254                              <1> 	; 	   ESI = Logical Dos Disk Table Offset (DRV)
 33255                              <1> 	; 	   EBX = Destination Buffer
 33256                              <1> 	; OUTPUT -> 
 33257                              <1> 	;	   cf = 0 or cf = 1
 33258                              <1> 	; (Modified registers: EAX; EBX, ECX, EDX)
 33259                              <1> 
 33260                              <1> 	; 23/02/2016
 33261 0000B1C2 C605[35CE0000]02    <1> 	mov	byte [disk_rw_op], 2 ; CHS read
 33262                              <1> 
 33263                              <1> chs_rw:
 33264                              <1> 	;;movzx	edx, word [esi+LD_BPB+SecPerTrack]
 33265                              <1> 	;movzx	edx, byte [esi+LD_BPB+SecPerTrack] ; <= 63
 33266                              <1> 	;mov	[disk_rw_spt], dl
 33267                              <1> 
 33268                              <1> chs_read_next_sector:
 33269 0000B1C9 C605[36CE0000]04    <1> 	mov	byte [retry_count], 4
 33270                              <1>      
 33271                              <1> chs_read_retry:
 33272                              <1> 	;mov	[sector_count], ecx ; 23/02/2016
 33273                              <1> 
 33274 0000B1D0 50                  <1> 	push	eax			; Linear sector #
 33275 0000B1D1 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
 33276                              <1>                 
 33277 0000B1D2 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
 33278                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
 33279 0000B1D6 29D2                <1> 	sub	edx, edx
 33280 0000B1D8 F7F1                <1> 	div	ecx
 33281                              <1> 	; eax = track, dx (dl ) = sector (on track)
 33282                              <1> 	;sub	cl, dl ; 24/02/2016 (spt - sec)
 33283                              <1> 	;push	ecx ; *
 33284 0000B1DA 6689D1              <1> 	mov	cx, dx			; Sector (zero based)
 33285 0000B1DD 6641                <1> 	inc	cx			; To make it 1 based
 33286 0000B1DF 6651                <1> 	push	cx
 33287 0000B1E1 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
 33288 0000B1E5 6629D2              <1> 	sub	dx, dx
 33289 0000B1E8 F7F1                <1> 	div	ecx			; Convert track to head & cyl
 33290                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
 33291 0000B1EA 88D6                <1> 	mov	dh, dl
 33292 0000B1EC 6659                <1> 	pop	cx			; AX=Cyl, DH=Head, CX=Sector
 33293 0000B1EE 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 33294                              <1> 
 33295 0000B1F1 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !                   
 33296 0000B1F3 C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
 33297 0000B1F6 08E1                <1> 	or	cl, ah
 33298                              <1> 
 33299                              <1> 	; 24/02/2016
 33300                              <1> 	;pop	eax ; * (spt - sec) (example: 63 - 0 = 63)
 33301                              <1> 	;cmp	eax, [sector_count]
 33302                              <1> 	;jb	short chs_write_sectors
 33303                              <1> 	;je	short chs_read_sectors
 33304                              <1> 	;; (# of sectors to read is more than remaining sectors on the track)
 33305                              <1> 	;mov	al, [sector_count]
 33306                              <1> ;chs_read_sectors: ; read or write !
 33307 0000B1F8 B001                <1> 	mov	al, 1 ; 25/02/2016
 33308 0000B1FA 8A25[35CE0000]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
 33309                              <1> 	;
 33310 0000B200 E8C776FFFF          <1> 	call	int13h			; BIOS Service func ( ah ) = 2
 33311                              <1>                                         ; Read disk sectors
 33312                              <1>                                         ; AL-sec num CH-track CL-sec
 33313                              <1>                                         ; DH-head DL-drive ES:BX-buffer
 33314                              <1>                                         ; CF-flag AH-stat AL-sec read
 33315                              <1> 	                                ; If CF = 1 then (If AH > 0)
 33316 0000B205 8825[37CE0000]      <1> 	mov	[disk_rw_err], ah
 33317                              <1> 	
 33318 0000B20B 59                  <1> 	pop	ecx
 33319 0000B20C 58                  <1> 	pop	eax
 33320 0000B20D 7314                <1> 	jnc	short chs_read_ok
 33321                              <1> 
 33322 0000B20F 803D[37CE0000]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
 33323 0000B216 7408                <1> 	je	short chs_read_error_retn
 33324                              <1>              
 33325 0000B218 FE0D[36CE0000]      <1> 	dec	byte [retry_count]
 33326 0000B21E 75B0                <1> 	jnz	short chs_read_retry
 33327                              <1> 
 33328                              <1> chs_read_error_retn:
 33329 0000B220 F9                  <1> 	stc
 33330                              <1> 	;retn
 33331 0000B221 EB69                <1> 	jmp	short update_drv_error_byte
 33332                              <1> 
 33333                              <1> ;chs_write_sectors: ; read or write 
 33334                              <1> 	;; (# of sectors to read is less than remaining sectors on the track)
 33335                              <1> 	;mov	[sector_count], al
 33336                              <1> 	;jmp	short chs_read_sectors
 33337                              <1> 
 33338                              <1> chs_read_ok:
 33339                              <1> 	;; 23/02/2016
 33340                              <1> 	;movzx	edx, byte [sector_count] ; sector count (<= spt)	
 33341                              <1>         ;sub    ecx, edx  ; remaining sector count
 33342                              <1> 	;jna	short update_drv_error_byte	
 33343                              <1> 	;add	eax, edx ; next disk sector
 33344                              <1> 	;shl	edx, 9 ; 512 * sector count
 33345                              <1> 	;add	ebx, edx ; next buffer byte address 
 33346                              <1>         ;jmp     chs_read_next_sector        
 33347                              <1> 	; 25/02/2016
 33348 0000B223 40                  <1> 	inc	eax ; next sector
 33349 0000B224 81C300020000        <1> 	add	ebx, 512
 33350 0000B22A E29D                <1> 	loop	chs_read_next_sector
 33351 0000B22C EB5E                <1> 	jmp	short update_drv_error_byte
 33352                              <1> 
 33353                              <1> lba_write:
 33354                              <1> 	; 23/02/2016
 33355 0000B22E C605[35CE0000]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
 33356 0000B235 EB07                <1> 	jmp	short lba_rw
 33357                              <1> 
 33358                              <1> lba_read:
 33359                              <1> 	; 23/02/2016
 33360                              <1> 	; 17/02/2016
 33361                              <1> 	; 14/02/2016
 33362                              <1> 	; 13/02/2016
 33363                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 33364                              <1> 	; 10/07/2015 (Retro UNIX 386 v1)
 33365                              <1> 	;
 33366                              <1> 	; INPUT -> EAX = Logical Block Address
 33367                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 33368                              <1> 	;	   ECX = Sector Count	
 33369                              <1> 	; 	   EBX = Destination Buffer
 33370                              <1> 	; OUTPUT -> 
 33371                              <1> 	;	   cf = 0 or cf = 1
 33372                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 33373                              <1> 
 33374                              <1> 	; LBA read/write (with private LBA function) 
 33375                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 33376                              <1> 
 33377                              <1> 
 33378                              <1> 	; 23/02/2016
 33379 0000B237 C605[35CE0000]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
 33380                              <1> 
 33381                              <1> lba_rw:
 33382                              <1> 	; 17/02/2016
 33383 0000B23E 57                  <1> 	push	edi
 33384                              <1> 
 33385 0000B23F 890D[38CE0000]      <1> 	mov	[sector_count], ecx ; total sector (read) count
 33386                              <1> 
 33387 0000B245 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 33388                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 33389                              <1> 
 33390                              <1> lba_read_next:
 33391 0000B248 81F900010000        <1> 	cmp	ecx, 256
 33392 0000B24E 7605                <1> 	jna	short lba_read_rsc
 33393 0000B250 B900010000          <1> 	mov	ecx, 256 ; 17/02/2016
 33394                              <1> lba_read_rsc:
 33395 0000B255 290D[38CE0000]      <1> 	sub	[sector_count], ecx ; remain sectors
 33396                              <1> 
 33397 0000B25B 89CF                <1> 	mov	edi, ecx 
 33398 0000B25D 89C1                <1> 	mov	ecx, eax ; sector number/address
 33399                              <1> 
 33400 0000B25F C605[36CE0000]04    <1> 	mov	byte [retry_count], 4
 33401                              <1> lba_read_retry:
 33402 0000B266 89F8                <1> 	mov	eax, edi
 33403                              <1> 	;
 33404                              <1> 	; ecx = sector number
 33405                              <1> 	; al = sector count (0 - 255) /// (0 = 256)
 33406                              <1> 	; dl = drive number
 33407                              <1> 	; ebx = buffer offset
 33408                              <1> 	;
 33409                              <1> 	; Function 1Bh = LBA read, 1Ch = LBA write
 33410                              <1> 	; 23/02/2016
 33411 0000B268 8A25[35CE0000]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
 33412 0000B26E E85976FFFF          <1> 	call	int13h
 33413                              <1> 	; al = ? (changed)
 33414                              <1> 	; ah = error code
 33415 0000B273 8825[37CE0000]      <1> 	mov	[disk_rw_err], ah
 33416 0000B279 7334                <1> 	jnc	short lba_read_ok
 33417 0000B27B 80FC80              <1> 	cmp	ah, 80h ; time out?
 33418 0000B27E 740A                <1>         je      short lba_read_stc_retn
 33419 0000B280 FE0D[36CE0000]      <1> 	dec	byte [retry_count]
 33420 0000B286 7FDE                <1> 	jg	short lba_read_retry
 33421 0000B288 743A                <1> 	jz	short lba_read_reset
 33422                              <1> 	; sf =  1
 33423                              <1> 
 33424                              <1> lba_read_stc_retn:
 33425 0000B28A F9                  <1> 	stc
 33426                              <1> lba_read_retn:
 33427 0000B28B 5F                  <1> 	pop	edi
 33428                              <1> 
 33429                              <1> update_drv_error_byte:
 33430 0000B28C 9C                  <1> 	pushf
 33431 0000B28D 53                  <1> 	push	ebx
 33432 0000B28E 6651                <1> 	push	cx
 33433                              <1> 	;or	ecx, ecx
 33434                              <1> 	;jz	short udrv_errb0
 33435 0000B290 8A0D[37CE0000]      <1> 	mov	cl, [disk_rw_err]
 33436                              <1> udrv_errb0:
 33437 0000B296 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
 33438 0000B29A 80FB02              <1> 	cmp	bl, 2
 33439 0000B29D 7203                <1>         jb      short udrv_errb1
 33440 0000B29F 80EB7E              <1> 	sub	bl, 7Eh
 33441                              <1> 	;cmp	bl, 5
 33442                              <1> 	;ja	short udrv_errb2	
 33443                              <1> udrv_errb1:
 33444 0000B2A2 81C3[A1BF0000]      <1>         add     ebx, drv.error ; 13/02/2016
 33445 0000B2A8 880B                <1> 	mov	[ebx], cl ; error code
 33446                              <1> udrv_errb2:
 33447 0000B2AA 6659                <1> 	pop	cx
 33448 0000B2AC 5B                  <1> 	pop	ebx
 33449 0000B2AD 9D                  <1> 	popf
 33450 0000B2AE C3                  <1> 	retn
 33451                              <1> 
 33452                              <1> lba_read_ok:
 33453 0000B2AF 89C8                <1> 	mov	eax, ecx ; sector number
 33454 0000B2B1 01F8                <1> 	add	eax, edi ; sector number (next)
 33455 0000B2B3 C1E709              <1> 	shl	edi, 9 ; sector count * 512
 33456 0000B2B6 01FB                <1> 	add	ebx, edi ; next buffer offset
 33457                              <1> 
 33458 0000B2B8 8B0D[38CE0000]      <1> 	mov	ecx, [sector_count] ; remaining sectors
 33459 0000B2BE 09C9                <1> 	or	ecx, ecx
 33460 0000B2C0 7586                <1> 	jnz	short lba_read_next
 33461 0000B2C2 EBC7                <1> 	jmp	short lba_read_retn
 33462                              <1> 
 33463                              <1> lba_read_reset:
 33464 0000B2C4 B40D                <1> 	mov	ah, 0Dh ; Alternate reset
 33465 0000B2C6 E80176FFFF          <1>         call	int13h
 33466                              <1> 	; al = ? (changed)
 33467                              <1> 	; ah = error code
 33468 0000B2CB 7399                <1> 	jnc	short lba_read_retry
 33469 0000B2CD EBBC                <1> 	jmp	short lba_read_retn
 33470                                  %include 'trdosk8.s' ; 24/01/2016
 33471                              <1> ; ****************************************************************************
 33472                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk8.s
 33473                              <1> ; ----------------------------------------------------------------------------
 33474                              <1> ; Last Update: 24/01/2016
 33475                              <1> ; ----------------------------------------------------------------------------
 33476                              <1> ; Beginning: 24/01/2016
 33477                              <1> ; ----------------------------------------------------------------------------
 33478                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 33479                              <1> ; ----------------------------------------------------------------------------
 33480                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 33481                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 33482                              <1> ;
 33483                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 33484                              <1> ; u0.s (20/11/2015)
 33485                              <1> ; ****************************************************************************
 33486                              <1> 
 33487                              <1> INT4Ah:
 33488                              <1> 	; 24/01/2016
 33489                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
 33490 0000B2CF C3                  <1> 	retn
 33491                              <1> 
 33492                              <1> ; u0.s
 33493                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
 33494                              <1> ; Last Modification: 20/11/2015
 33495                              <1> 
 33496                              <1> com2_int:
 33497                              <1> 	; 07/11/2015 
 33498                              <1> 	; 24/10/2015
 33499                              <1> 	; 23/10/2015
 33500                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 33501                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 33502                              <1> 	; < serial port 2 interrupt handler >
 33503                              <1> 	;
 33504 0000B2D0 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 33505                              <1> 	;push	eax
 33506 0000B2D3 66B80900            <1> 	mov	ax, 9
 33507 0000B2D7 EB07                <1> 	jmp	short comm_int
 33508                              <1> com1_int:
 33509                              <1> 	; 07/11/2015
 33510                              <1> 	; 24/10/2015
 33511 0000B2D9 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 33512                              <1> 	; 23/10/2015
 33513                              <1> 	;push	eax
 33514 0000B2DC 66B80800            <1> 	mov	ax, 8
 33515                              <1> comm_int:
 33516                              <1> 	; 20/11/2015
 33517                              <1> 	; 18/11/2015
 33518                              <1> 	; 17/11/2015
 33519                              <1> 	; 16/11/2015
 33520                              <1> 	; 09/11/2015
 33521                              <1> 	; 08/11/2015
 33522                              <1> 	; 07/11/2015
 33523                              <1> 	; 06/11/2015 (serial4.asm, 'serial')	
 33524                              <1> 	; 01/11/2015
 33525                              <1> 	; 26/10/2015
 33526                              <1> 	; 23/10/2015
 33527 0000B2E0 53                  <1> 	push	ebx
 33528 0000B2E1 56                  <1> 	push	esi
 33529 0000B2E2 57                  <1> 	push	edi
 33530 0000B2E3 1E                  <1> 	push 	ds
 33531 0000B2E4 06                  <1> 	push 	es
 33532                              <1> 	; 18/11/2015
 33533 0000B2E5 0F20DB              <1> 	mov	ebx, cr3
 33534 0000B2E8 53                  <1> 	push	ebx ; ****
 33535                              <1> 	;
 33536 0000B2E9 51                  <1> 	push	ecx ; ***
 33537 0000B2EA 52                  <1> 	push	edx ; **
 33538                              <1> 	;
 33539 0000B2EB BB10000000          <1> 	mov	ebx, KDATA
 33540 0000B2F0 8EDB                <1> 	mov	ds, bx
 33541 0000B2F2 8EC3                <1> 	mov	es, bx
 33542                              <1> 	;
 33543 0000B2F4 8B0D[78C40000]      <1> 	mov	ecx, [k_page_dir]
 33544 0000B2FA 0F22D9              <1> 	mov	cr3, ecx
 33545                              <1> 	; 20/11/2015
 33546                              <1> 	; Interrupt identification register
 33547 0000B2FD 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
 33548                              <1> 	;
 33549 0000B301 3C08                <1> 	cmp 	al, 8 
 33550 0000B303 7702                <1> 	ja 	short com_i0
 33551                              <1> 	;
 33552                              <1> 	; 20/11/2015
 33553                              <1> 	; 17/11/2015
 33554                              <1> 	; 16/11/2015
 33555                              <1> 	; 15/11/2015
 33556                              <1> 	; 24/10/2015
 33557                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 33558                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 33559                              <1> 	; < serial port 1 interrupt handler >
 33560                              <1> 	;
 33561 0000B305 FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
 33562                              <1> com_i0:
 33563                              <1> 	;push	eax ; *
 33564                              <1> 	; 07/11/2015
 33565 0000B307 A2[E8C40000]        <1> 	mov 	byte [ccomport], al
 33566                              <1> 	; 09/11/2015
 33567 0000B30C 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
 33568                              <1> 	; 17/11/2015
 33569                              <1>  	; reset request for response status
 33570 0000B30F 88A3[DEC40000]      <1> 	mov	[ebx+req_resp-8], ah ; 0
 33571                              <1> 	;
 33572                              <1> 	; 20/11/2015
 33573 0000B315 EC                  <1> 	in	al, dx		; read interrupt id. register
 33574 0000B316 EB00                <1> 	JMP	$+2	   	; I/O DELAY
 33575 0000B318 2404                <1> 	and	al, 4		; received data available?	
 33576 0000B31A 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
 33577                              <1> 	;
 33578                              <1> 	; 20/11/2015
 33579 0000B31C 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
 33580 0000B31F EC                  <1> 	in	al, dx     	; read character
 33581                              <1> 	;JMP	$+2	   	; I/O DELAY
 33582                              <1> 	; 08/11/2015
 33583                              <1> 	; 07/11/2015
 33584 0000B320 89DE                <1> 	mov	esi, ebx 
 33585 0000B322 89DF                <1> 	mov	edi, ebx
 33586 0000B324 81C6[E2C40000]      <1> 	add 	esi, rchar - 8 ; points to last received char
 33587 0000B32A 81C7[E4C40000]      <1> 	add	edi, schar - 8 ; points to last sent char
 33588 0000B330 8806                <1> 	mov	[esi], al ; received char (current char)
 33589                              <1> 	; query
 33590 0000B332 20C0                <1> 	and	al, al
 33591 0000B334 7527                <1> 	jnz	short com_i2
 33592                              <1>    	; response
 33593                              <1> 	; 17/11/2015
 33594                              <1> 	; set request for response status
 33595 0000B336 FE83[DEC40000]      <1>         inc     byte [ebx+req_resp-8] ; 1 
 33596                              <1> 	;
 33597 0000B33C 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
 33598 0000B340 EC                  <1> 	in	al, dx	   	; read line status register 
 33599 0000B341 EB00                <1> 	JMP	$+2	   	; I/O DELAY
 33600 0000B343 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
 33601 0000B345 7445                <1> 	jz	short com_eoi 	; no
 33602 0000B347 B0FF                <1> 	mov 	al, 0FFh   	; response			
 33603 0000B349 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
 33604 0000B34D EE                  <1> 	out	dx, al	   	; send on serial port
 33605                              <1> 	; 17/11/2015
 33606 0000B34E 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
 33607 0000B351 7502                <1> 	jne 	short com_i1    ; no
 33608 0000B353 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
 33609                              <1> com_i1:
 33610                              <1> 	; 17/11/2015
 33611                              <1> 	; reset request for response status (again)
 33612 0000B355 FE8B[DEC40000]      <1>         dec     byte [ebx+req_resp-8] ; 0 
 33613 0000B35B EB2F                <1> 	jmp	short com_eoi
 33614                              <1> com_i2:	
 33615                              <1> 	; 08/11/2015
 33616 0000B35D 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
 33617 0000B35F 7417                <1> 	je	short com_i3	; (check for response signal)
 33618                              <1> 	; 07/11/2015
 33619 0000B361 3C04                <1> 	cmp	al, 04h	; EOT
 33620 0000B363 751C                <1> 	jne	short com_i4	
 33621                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
 33622                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
 33623                              <1> 	; 08/11/2015
 33624                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
 33625 0000B365 861D[A8C40000]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
 33626 0000B36B E8D28BFFFF          <1> 	call 	ctrlbrk
 33627 0000B370 861D[A8C40000]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
 33628                              <1> 	;mov	al, 04h ; EOT
 33629                              <1> 	; 08/11/2015
 33630 0000B376 EB09                <1> 	jmp	short com_i4	
 33631                              <1> com_i3:
 33632                              <1> 	; 08/11/2015
 33633                              <1> 	; If 0FFh has been received just after a query
 33634                              <1> 	; (schar, ZERO), it is a response signal.
 33635                              <1> 	; 17/11/2015
 33636 0000B378 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
 33637 0000B37B 7704                <1> 	ja	short com_i4 ; no
 33638                              <1> 	; reset query status (schar)
 33639 0000B37D 8807                <1> 	mov	[edi], al ; 0FFh
 33640 0000B37F FEC0                <1> 	inc	al ; 0
 33641                              <1> com_i4:
 33642                              <1> 	; 27/07/2014
 33643                              <1> 	; 09/07/2014
 33644 0000B381 D0E3                <1> 	shl	bl, 1	
 33645 0000B383 81C3[AAC40000]      <1> 	add	ebx, ttychr
 33646                              <1> 	; 23/07/2014 (always overwrite)
 33647                              <1> 	;;cmp	word [ebx], 0
 33648                              <1> 	;;ja	short com_eoi
 33649                              <1> 	;
 33650 0000B389 668903              <1> 	mov	[ebx], ax   ; Save ascii code
 33651                              <1> 			    ; scan code = 0
 33652                              <1> com_eoi:
 33653                              <1> 	;mov	al, 20h
 33654                              <1> 	;out	20h, al	   ; end of interrupt
 33655                              <1> 	;
 33656                              <1> 	; 07/11/2015
 33657                              <1>       	;pop	eax ; *
 33658 0000B38C A0[E8C40000]        <1> 	mov	al, byte [ccomport] ; current COM port
 33659                              <1> 	 ; al = tty number (8 or 9)
 33660 0000B391 E85E010000          <1>         call	wakeup
 33661                              <1> com_iret:
 33662                              <1> 	; 23/10/2015
 33663 0000B396 5A                  <1> 	pop	edx ; **
 33664 0000B397 59                  <1> 	pop	ecx ; ***
 33665                              <1> 	; 18/11/2015
 33666                              <1> 	;pop	eax ; ****
 33667                              <1> 	;mov	cr3, eax
 33668                              <1> 	;jmp	iiret
 33669 0000B398 E9BE56FFFF          <1> 	jmp	iiretp
 33670                              <1> 
 33671                              <1> ;iiretp: ; 01/09/2015
 33672                              <1> ;	; 28/08/2015
 33673                              <1> ;	pop	eax ; (*) page directory
 33674                              <1> ;	mov	cr3, eax
 33675                              <1> ;iiret:
 33676                              <1> ;	; 22/08/2014
 33677                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
 33678                              <1> ;	out	20h, al	; 8259 PORT
 33679                              <1> ;	;
 33680                              <1> ;	pop	es
 33681                              <1> ;	pop	ds
 33682                              <1> ;	pop	edi
 33683                              <1> ;	pop	esi
 33684                              <1> ;	pop	ebx ; 29/08/2014
 33685                              <1> ;	pop 	eax
 33686                              <1> ;	iretd
 33687                              <1> 
 33688                              <1> sp_init:
 33689                              <1> 	; 07/11/2015
 33690                              <1> 	; 29/10/2015
 33691                              <1> 	; 26/10/2015
 33692                              <1> 	; 23/10/2015
 33693                              <1> 	; 29/06/2015
 33694                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
 33695                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
 33696                              <1> 	; Initialization of Serial Port Communication Parameters
 33697                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 33698                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 33699                              <1> 	;
 33700                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 33701                              <1> 	;
 33702                              <1> 	; INPUT:  (29/06/2015)
 33703                              <1> 	;	AL = 0 for COM1
 33704                              <1> 	;	     1 for COM2
 33705                              <1> 	;	AH = Communication parameters	
 33706                              <1> 	;
 33707                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 33708                              <1> 	;	Bit	4	3	2	1	0
 33709                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 33710                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 33711                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 33712                              <1> 	;		11 = even
 33713                              <1> 	;  Baud rate setting bits: (29/06/2015)
 33714                              <1> 	;		Retro UNIX 386 v1 feature only !
 33715                              <1> 	;	Bit	7    6    5  | Baud rate
 33716                              <1> 	;		------------------------
 33717                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 33718                              <1> 	;		0    0    1  | 9600 (12)
 33719                              <1> 	;		0    1    0  | 19200 (6) 
 33720                              <1> 	;		0    1	  1  | 38400 (3) 
 33721                              <1> 	;		1    0	  0  | 14400 (8)
 33722                              <1> 	;		1    0	  1  | 28800 (4)
 33723                              <1> 	;		1    1    0  | 57600 (2)
 33724                              <1> 	;		1    1    1  | 115200 (1) 	
 33725                              <1> 	
 33726                              <1> 	; References:	
 33727                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
 33728                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
 33729                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
 33730                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
 33731                              <1> 	;
 33732                              <1> 	; Set communication parameters for COM1 (= 03h)	
 33733                              <1> 	;
 33734 0000B39D BB[E4C40000]        <1> 	mov	ebx, com1p		; COM1 parameters  
 33735 0000B3A2 66BAF803            <1> 	mov	dx, 3F8h		; COM1
 33736                              <1> 	 ; 29/10/2015
 33737 0000B3A6 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 33738 0000B3AA E86F000000          <1> 	call	sp_i3	; call A4	
 33739 0000B3AF A880                <1> 	test	al, 80h
 33740 0000B3B1 7410                <1> 	jz	short sp_i0 ; OK..
 33741                              <1> 		; Error !
 33742                              <1> 	;mov	dx, 3F8h
 33743 0000B3B3 80EA05              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
 33744 0000B3B6 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 33745 0000B3BA E85F000000          <1> 	call	sp_i3	; call A4	
 33746 0000B3BF A880                <1> 	test	al, 80h
 33747 0000B3C1 7508                <1> 	jnz	short sp_i1
 33748                              <1> sp_i0:
 33749                              <1>         ; (Note: Serial port interrupts will be disabled here...)	
 33750                              <1>         ; (INT 14h initialization code disables interrupts.)
 33751                              <1> 	;
 33752 0000B3C3 C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 33753 0000B3C6 E8DC000000          <1> 	call	sp_i5 ; 29/06/2015
 33754                              <1> sp_i1:
 33755 0000B3CB 43                  <1> 	inc	ebx
 33756 0000B3CC 66BAF802            <1> 	mov	dx, 2F8h		; COM2
 33757                              <1> 	 ; 29/10/2015
 33758 0000B3D0 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 33759 0000B3D4 E845000000          <1> 	call	sp_i3	; call A4	
 33760 0000B3D9 A880                <1> 	test	al, 80h
 33761 0000B3DB 7410                <1> 	jz	short sp_i2 ; OK..
 33762                              <1> 		; Error !
 33763                              <1> 	;mov	dx, 2F8h
 33764 0000B3DD 80EA05              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
 33765 0000B3E0 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 33766 0000B3E4 E835000000          <1> 	call	sp_i3	; call A4	
 33767 0000B3E9 A880                <1> 	test	al, 80h
 33768 0000B3EB 7530                <1> 	jnz	short sp_i7
 33769                              <1> sp_i2:
 33770 0000B3ED C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 33771                              <1> sp_i6:
 33772                              <1> 	;; COM2 - enabling IRQ 3
 33773                              <1> 	; 07/11/2015
 33774                              <1> 	; 26/10/2015
 33775 0000B3F0 9C                  <1> 	pushf
 33776 0000B3F1 FA                  <1> 	cli
 33777                              <1> 	;
 33778 0000B3F2 66BAFC02            <1> 	mov	dx, 2FCh   		; modem control register
 33779 0000B3F6 EC                  <1> 	in	al, dx 	   		; read register
 33780 0000B3F7 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 33781 0000B3F9 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 33782 0000B3FB EE                  <1> 	out	dx, al     		; write back to register
 33783 0000B3FC EB00                <1> 	JMP	$+2	   		; I/O DELAY
 33784 0000B3FE 66BAF902            <1> 	mov	dx, 2F9h   		; interrupt enable register
 33785 0000B402 EC                  <1> 	in	al, dx     		; read register
 33786 0000B403 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 33787                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 33788 0000B405 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 33789 0000B407 EE                  <1> 	out	dx, al 	   		; write back to register
 33790 0000B408 EB00                <1> 	JMP	$+2        		; I/O DELAY
 33791 0000B40A E421                <1> 	in	al, 21h    		; read interrupt mask register
 33792 0000B40C EB00                <1> 	JMP	$+2	   		; I/O DELAY
 33793 0000B40E 24F7                <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
 33794 0000B410 E621                <1> 	out	21h, al    		; write back to register
 33795                              <1> 	;
 33796                              <1> 	; 23/10/2015
 33797 0000B412 B8[D0B20000]        <1> 	mov 	eax, com2_int
 33798 0000B417 A3[EFB40000]        <1> 	mov	[com2_irq3], eax
 33799                              <1> 	; 26/10/2015
 33800 0000B41C 9D                  <1> 	popf	
 33801                              <1> sp_i7:
 33802 0000B41D C3                  <1> 	retn
 33803                              <1> 
 33804                              <1> sp_i3:
 33805                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
 33806                              <1> 	; 28/10/2015
 33807 0000B41E FEC2                <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
 33808 0000B420 B000                <1> 	mov	al, 0
 33809 0000B422 EE                  <1> 	out	dx, al			; disable serial port interrupt
 33810 0000B423 EB00                <1> 	JMP	$+2			; I/O DELAY
 33811 0000B425 80C202              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
 33812 0000B428 B080                <1> 	mov	al, 80h			
 33813 0000B42A EE                  <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
 33814                              <1> 	;-----	SET BAUD RATE DIVISOR
 33815                              <1> 	; 26/10/2015
 33816 0000B42B 80EA03              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
 33817                              <1> 					; of the divisor value
 33818 0000B42E 88C8                <1> 	mov	al, cl	; 1
 33819 0000B430 EE                  <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
 33820                              <1> 					; 2 = 57600 baud
 33821                              <1> 					; 3 = 38400 baud
 33822                              <1> 					; 6 = 19200 baud
 33823                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
 33824 0000B431 EB00                <1> 	JMP	$+2			; I/O DELAY
 33825 0000B433 28C0                <1> 	sub	al, al
 33826 0000B435 FEC2                <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
 33827                              <1> 					; of the divisor value
 33828 0000B437 EE                  <1> 	out	dx, al ; 0
 33829 0000B438 EB00                <1> 	JMP	$+2			; I/O DELAY
 33830                              <1> 	;	
 33831 0000B43A 88E8                <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
 33832                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
 33833 0000B43C 80C202              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
 33834 0000B43F EE                  <1> 	out	dx, al			
 33835 0000B440 EB00                <1> 	JMP	$+2			; I/O DELAY
 33836                              <1> 	; 29/10/2015
 33837 0000B442 FECA                <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
 33838 0000B444 30C0                <1> 	xor	al, al			; 0
 33839 0000B446 EE                  <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
 33840 0000B447 EB00                <1> 	JMP	$+2	
 33841                              <1> sp_i4:
 33842                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
 33843                              <1> 	; 29/06/2015 (line status after modem status)
 33844 0000B449 80C204              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
 33845                              <1> sp_i4s:
 33846 0000B44C EC                  <1> 	in	al, dx			; GET MODEM CONTROL STATUS
 33847 0000B44D EB00                <1> 	JMP	$+2			; I/O DELAY
 33848 0000B44F 88C4                <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
 33849 0000B451 FECA                <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
 33850                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
 33851 0000B453 EC                  <1> 	in	al, dx			; GET LINE CONTROL STATUS
 33852                              <1> 	; AL = Line status, AH = Modem status
 33853 0000B454 C3                  <1> 	retn
 33854                              <1> 
 33855                              <1> sp_status:
 33856                              <1> 	; 29/06/2015
 33857                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
 33858                              <1> 	; Get serial port status
 33859 0000B455 66BAFE03            <1> 	mov	dx, 3FEh		; Modem status register (COM1)
 33860 0000B459 28C6                <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
 33861                              <1> 					; dx = 2FEh for COM2
 33862 0000B45B EBEF                <1> 	jmp	short sp_i4s
 33863                              <1> 
 33864                              <1> sp_setp: ; Set serial port communication parameters
 33865                              <1> 	; 07/11/2015
 33866                              <1> 	; 29/10/2015
 33867                              <1> 	; 29/06/2015
 33868                              <1> 	; Retro UNIX 386 v1 feature only !	
 33869                              <1> 	;
 33870                              <1> 	; INPUT:
 33871                              <1> 	;	AL = 0 for COM1
 33872                              <1> 	;	     1 for COM2
 33873                              <1> 	;	AH = Communication parameters (*)
 33874                              <1> 	; OUTPUT:
 33875                              <1> 	;	CL = Line status
 33876                              <1> 	;	CH = Modem status
 33877                              <1> 	;   If cf = 1 -> Error code in [u.error]
 33878                              <1> 	;		 'invalid parameter !' 
 33879                              <1> 	;		 	 or
 33880                              <1> 	;		 'device not ready !' error
 33881                              <1> 	;	
 33882                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 33883                              <1> 	;	Bit	4	3	2	1	0
 33884                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 33885                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 33886                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 33887                              <1> 	;		11 = even
 33888                              <1> 	;  Baud rate setting bits: (29/06/2015)
 33889                              <1> 	;		Retro UNIX 386 v1 feature only !
 33890                              <1> 	;	Bit	7    6    5  | Baud rate
 33891                              <1> 	;		------------------------
 33892                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 33893                              <1> 	;		0    0    1  | 9600 (12)
 33894                              <1> 	;		0    1    0  | 19200 (6) 
 33895                              <1> 	;		0    1	  1  | 38400 (3) 
 33896                              <1> 	;		1    0	  0  | 14400 (8)
 33897                              <1> 	;		1    0	  1  | 28800 (4)
 33898                              <1> 	;		1    1    0  | 57600 (2)
 33899                              <1> 	;		1    1    1  | 115200 (1) 
 33900                              <1> 	;
 33901                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 33902                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 33903                              <1> 	;
 33904                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 33905                              <1> 	;
 33906 0000B45D 66BAF803            <1> 	mov	dx, 3F8h
 33907 0000B461 BB[E4C40000]        <1> 	mov	ebx, com1p ; COM1 control byte offset
 33908 0000B466 3C01                <1> 	cmp	al, 1
 33909 0000B468 776B                <1> 	ja 	short sp_invp_err
 33910 0000B46A 7203                <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
 33911 0000B46C FECE                <1> 	dec	dh ; 2F8h
 33912 0000B46E 43                  <1> 	inc	ebx ; COM2 control byte offset
 33913                              <1> sp_setp1:
 33914                              <1> 	; 29/10/2015
 33915 0000B46F 8823                <1> 	mov	[ebx], ah
 33916 0000B471 0FB6CC              <1> 	movzx 	ecx, ah
 33917 0000B474 C0E905              <1> 	shr	cl, 5 ; -> baud rate index
 33918 0000B477 80E41F              <1> 	and	ah, 1Fh ; communication parameters except baud rate
 33919 0000B47A 8A81[E4B40000]      <1> 	mov	al, [ecx+b_div_tbl]
 33920 0000B480 6689C1              <1> 	mov	cx, ax
 33921 0000B483 E896FFFFFF          <1> 	call	sp_i3
 33922 0000B488 6689C1              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
 33923 0000B48B A880                <1> 	test	al, 80h
 33924 0000B48D 740F                <1> 	jz	short sp_setp2
 33925 0000B48F C603E3              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
 33926                              <1> stp_dnr_err:
 33927 0000B492 C705[2DD50000]0F00- <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
 33928 0000B49A 0000                <1>
 33929                              <1> 	; CL = Line status, CH = Modem status
 33930 0000B49C F9                  <1> 	stc
 33931 0000B49D C3                  <1> 	retn
 33932                              <1> sp_setp2:
 33933 0000B49E 80FE02              <1> 	cmp	dh, 2 ; COM2 (2F?h)
 33934 0000B4A1 0F8649FFFFFF        <1>         jna     sp_i6 
 33935                              <1> 		      ; COM1 (3F?h)
 33936                              <1> sp_i5: 
 33937                              <1> 	; 07/11/2015
 33938                              <1> 	; 26/10/2015
 33939                              <1> 	; 29/06/2015
 33940                              <1> 	;
 33941                              <1> 	;; COM1 - enabling IRQ 4
 33942 0000B4A7 9C                  <1> 	pushf
 33943 0000B4A8 FA                  <1> 	cli
 33944 0000B4A9 66BAFC03            <1> 	mov	dx, 3FCh   		; modem control register
 33945 0000B4AD EC                  <1> 	in	al, dx 	   		; read register
 33946 0000B4AE EB00                <1> 	JMP	$+2			; I/O DELAY
 33947 0000B4B0 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 33948 0000B4B2 EE                  <1> 	out	dx, al     		; write back to register
 33949 0000B4B3 EB00                <1> 	JMP	$+2			; I/O DELAY
 33950 0000B4B5 66BAF903            <1> 	mov	dx, 3F9h   		; interrupt enable register
 33951 0000B4B9 EC                  <1> 	in	al, dx     		; read register
 33952 0000B4BA EB00                <1> 	JMP	$+2			; I/O DELAY
 33953                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 33954 0000B4BC 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 33955 0000B4BE EE                  <1> 	out	dx, al 	   		; write back to register
 33956 0000B4BF EB00                <1> 	JMP	$+2        		; I/O DELAY
 33957 0000B4C1 E421                <1> 	in	al, 21h    		; read interrupt mask register
 33958 0000B4C3 EB00                <1> 	JMP	$+2			; I/O DELAY
 33959 0000B4C5 24EF                <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
 33960 0000B4C7 E621                <1> 	out	21h, al    		; write back to register
 33961                              <1> 	;
 33962                              <1> 	; 23/10/2015
 33963 0000B4C9 B8[D9B20000]        <1> 	mov 	eax, com1_int
 33964 0000B4CE A3[EBB40000]        <1> 	mov	[com1_irq4], eax
 33965                              <1> 	; 26/10/2015
 33966 0000B4D3 9D                  <1> 	popf
 33967 0000B4D4 C3                  <1> 	retn
 33968                              <1> 
 33969                              <1> sp_invp_err:
 33970 0000B4D5 C705[2DD50000]1700- <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 33971 0000B4DD 0000                <1>
 33972 0000B4DF 31C9                <1> 	xor	ecx, ecx
 33973 0000B4E1 49                  <1> 	dec	ecx ; 0FFFFh
 33974 0000B4E2 F9                  <1> 	stc
 33975 0000B4E3 C3                  <1> 	retn
 33976                              <1> 
 33977                              <1> ; 29/10/2015
 33978                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
 33979 0000B4E4 010C0603080401      <1> 	db 1, 12, 6, 3, 8, 4, 1
 33980                              <1> 
 33981                              <1> 
 33982                              <1> ; 23/10/2015
 33983                              <1> com1_irq4:
 33984 0000B4EB [F3B40000]          <1> 	dd dummy_retn
 33985                              <1> com2_irq3:
 33986 0000B4EF [F3B40000]          <1> 	dd dummy_retn
 33987                              <1> 
 33988                              <1> dummy_retn:
 33989 0000B4F3 C3                  <1> 	retn
 33990                              <1> 
 33991                              <1> wakeup:
 33992                              <1> 	; 24/01/2016
 33993 0000B4F4 C3                  <1> 	retn
 33994                                  %include 'trdosk9.s' ; 04/01/2016
 33995                              <1> ; ****************************************************************************
 33996                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - INITIALIZED DATA : trdosk9.s
 33997                              <1> ; ----------------------------------------------------------------------------
 33998                              <1> ; Last Update: 14/04/2016
 33999                              <1> ; ----------------------------------------------------------------------------
 34000                              <1> ; Beginning: 04/01/2016
 34001                              <1> ; ----------------------------------------------------------------------------
 34002                              <1> ; ----------------------------------------------------------------------------
 34003                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34004                              <1> ; ----------------------------------------------------------------------------
 34005                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 34006                              <1> ; TRDOS2.ASM (09/11/2011)
 34007                              <1> ; ****************************************************************************
 34008                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 34009                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 34010                              <1> ; CMD_INTR.ASM [29/01/2005] Last Update: 09/11/2011
 34011                              <1> ; FILE.ASM [29/10/2009] Last Update: 09/10/2011
 34012                              <1> 
 34013                              <1> ; 12/02/2016
 34014                              <1> Last_DOS_DiskNo: 
 34015 0000B4F5 01                  <1> 		db 1 ; A: = 0 & B: = 1
 34016                              <1> 
 34017                              <1> Restore_CDIR:	
 34018 0000B4F6 FF                  <1> 		db 0FFh ; Initial value -> any number except 0
 34019                              <1> 
 34020                              <1> msg_CRLF_temp:  
 34021 0000B4F7 070D0A00            <1> 		db  07h, 0Dh, 0Ah, 0
 34022                              <1> 
 34023                              <1> Magic_Bytes:
 34024 0000B4FB 04                  <1> 		db 4
 34025 0000B4FC 01                  <1> 		db 1
 34026                              <1> mainprog_Version:
 34027 0000B4FD 07                  <1> 		db 7
 34028 0000B4FE 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.140416"
 34029 0000B507 61696E2050726F6772- <1>
 34030 0000B510 616D2076322E302E31- <1>
 34031 0000B519 3430343136          <1>
 34032 0000B51E 0D0A                <1> 		db 0Dh, 0Ah
 34033 0000B520 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2016"
 34034 0000B529 616E2054616E203230- <1>
 34035 0000B532 30352D32303136      <1>
 34036 0000B539 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34037                              <1> 
 34038                              <1> MainProgCfgFile: ; 14/04/2016
 34039 0000B53C 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
 34040 0000B545 43464700            <1>
 34041                              <1> 
 34042                              <1> TRDOSPromptLabel:
 34043 0000B549 5452444F53          <1> 		db "TRDOS"
 34044 0000B54E 00                  <1> 		db 0
 34045 0000B54F 00<rept>            <1>                 times 5 db 0
 34046 0000B554 00                  <1> 		db 0
 34047                              <1> 
 34048                              <1> ; INTERNAL COMMANDS
 34049                              <1> Command_List:
 34050 0000B555 44495200            <1> Cmd_Dir:	db "DIR", 0
 34051 0000B559 434400              <1> Cmd_Cd:		db "CD", 0
 34052 0000B55C 433A00              <1> Cmd_Drive:	db "C:", 0
 34053 0000B55F 56455200            <1> Cmd_Ver:	db "VER", 0
 34054 0000B563 4558495400          <1> Cmd_Exit:	db "EXIT", 0
 34055 0000B568 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
 34056 0000B56F 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
 34057 0000B576 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
 34058 0000B57F 4441544500          <1> Cmd_Date:	db "DATE", 0
 34059 0000B584 54494D4500          <1> Cmd_Time:	db "TIME", 0
 34060 0000B589 52554E00            <1> Cmd_Run:	db "RUN", 0
 34061 0000B58D 53455400            <1> Cmd_Set:	db "SET", 0 
 34062 0000B591 434C5300            <1> Cmd_Cls:	db "CLS", 0
 34063 0000B595 53484F5700          <1> Cmd_Show:	db "SHOW", 0
 34064 0000B59A 44454C00            <1> Cmd_Del:	db "DEL", 0
 34065 0000B59E 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
 34066 0000B5A5 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
 34067 0000B5AC 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
 34068 0000B5B2 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
 34069 0000B5B8 434F505900          <1> Cmd_Copy:	db "COPY", 0
 34070 0000B5BD 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
 34071 0000B5C2 5041544800          <1> Cmd_Path:	db "PATH", 0
 34072 0000B5C7 4D454D00            <1> Cmd_Mem:	db "MEM", 0
 34073 0000B5CB 00                  <1> 		db 0
 34074 0000B5CC 46494E4400          <1> Cmd_Find:	db "FIND", 0
 34075 0000B5D1 5245414446494C4500  <1> Cmd_ReadFile:	db "READFILE", 0
 34076 0000B5DA 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
 34077 0000B5DF 2A00                <1> Cmd_Remark:	db "*", 0
 34078 0000B5E1 3F00                <1> Cmd_Help:	db "?", 0
 34079 0000B5E3 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
 34080 0000B5EA 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
 34081 0000B5F2 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
 34082 0000B5F8 4245455000          <1> Cmd_Beep:	db "BEEP", 0
 34083                              <1> 		
 34084 0000B5FD 00                  <1> 		db 0
 34085                              <1> 
 34086                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
 34087                              <1> invalid_fname_chars:
 34088 0000B5FE 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
 34089 0000B606 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
 34090 0000B60D 5B5C5D5E60          <1> 		db 5Bh, 5Ch, 5Dh, 5Eh, 60h
 34091                              <1> sizeInvFnChars  equ ($ - invalid_fname_chars)                
 34092                              <1> ;
 34093                              <1> 
 34094                              <1> Msg_Enter_Date:
 34095 0000B612 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
 34096 0000B61B 206461746520286464- <1>
 34097 0000B624 2D6D6D2D7979293A20  <1>
 34098 0000B62D 00                  <1>                 db 0
 34099                              <1> Msg_Show_Date:
 34100 0000B62E 43757272656E742064- <1>                 db   'Current date is '
 34101 0000B637 61746520697320      <1>
 34102 0000B63E 30                  <1> Day:            db   '0'
 34103 0000B63F 30                  <1> 		db   '0'
 34104 0000B640 2F                  <1>                 db   '/'
 34105 0000B641 30                  <1> Month:          db   '0'
 34106 0000B642 30                  <1> 		db   '0'
 34107 0000B643 2F                  <1>                 db   '/'
 34108 0000B644 30                  <1> Century:        db   '0'
 34109 0000B645 30                  <1>                 db   '0'
 34110 0000B646 30                  <1> Year:           db   '0'
 34111 0000B647 30                  <1> 		db   '0'
 34112 0000B648 0D0A00              <1>                 db   0Dh, 0Ah, 0
 34113                              <1> 
 34114                              <1> Msg_Enter_Time:
 34115 0000B64B 456E746572206E6577- <1> 		db 'Enter new time: '
 34116 0000B654 2074696D653A20      <1>
 34117 0000B65B 00                  <1> 		db 0
 34118                              <1> Msg_Show_Time:
 34119 0000B65C 43757272656E742074- <1> 		db   'Current time is '
 34120 0000B665 696D6520697320      <1>
 34121 0000B66C 30                  <1> Hour:           db   '0'
 34122 0000B66D 30                  <1> 		db   '0'
 34123 0000B66E 3A                  <1> 		db   ':'
 34124 0000B66F 30                  <1> Minute:         db   '0'
 34125 0000B670 30                  <1> 		db   '0'
 34126 0000B671 3A                  <1> 		db   ':'
 34127 0000B672 30                  <1> Second:         db   '0'
 34128 0000B673 30                  <1> 		db   '0'
 34129 0000B674 0D0A00              <1> 		db   0Dh, 0Ah, 0
 34130                              <1> 
 34131                              <1> ;VolSize_Unit1:   dd 0
 34132                              <1> ;VolSize_Unit2:   dd 0
 34133                              <1> 
 34134                              <1> VolSize_KiloBytes:
 34135 0000B677 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
 34136 0000B680 730D0A00            <1>
 34137                              <1> VolSize_Bytes:
 34138 0000B684 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
 34139                              <1> Volume_in_drive:
 34140 0000B68D 0D0A                <1> 		db 0Dh, 0Ah
 34141                              <1> Vol_FS_Name:
 34142 0000B68F 54522046533120      <1> 		db "TR FS1 "
 34143 0000B696 566F6C756D6520696E- <1> 		db "Volume in drive "
 34144 0000B69F 20647269766520      <1>
 34145 0000B6A6 30                  <1> Vol_Drv_Name:   db 30h
 34146 0000B6A7 3A                  <1> 		db ":"
 34147 0000B6A8 20697320            <1> 		db " is "
 34148 0000B6AC 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34149                              <1> Dir_Drive_Str:
 34150 0000B6AF 54522D444F53204472- <1>                 db "TR-DOS Drive "
 34151 0000B6B8 69766520            <1>
 34152                              <1> Dir_Drive_Name:
 34153 0000B6BC 303A                <1>                 db "0:"
 34154 0000B6BE 0D0A                <1>                 db  0Dh, 0Ah
 34155                              <1> Vol_Str_Header:
 34156 0000B6C0 566F6C756D65204E61- <1>                 db "Volume Name: "
 34157 0000B6C9 6D653A20            <1>
 34158                              <1> Vol_Name:
 34159 0000B6CD 00<rept>            <1> 		times 64 db 0
 34160 0000B70D 00                  <1> 		db 0
 34161                              <1> Vol_Serial_Header:
 34162 0000B70E 0D0A                <1> 		db 0Dh, 0Ah
 34163 0000B710 566F6C756D65205365- <1> 		db "Volume Serial No: "
 34164 0000B719 7269616C204E6F3A20  <1>
 34165                              <1> Vol_Serial1:
 34166 0000B722 30303030            <1> 		db "0000"
 34167 0000B726 2D                  <1> 		db "-"
 34168                              <1> Vol_Serial2:
 34169 0000B727 30303030            <1> 		db "0000"
 34170 0000B72B 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34171                              <1> 
 34172                              <1> ;Vol_Tot_Sec_Str_Start:
 34173                              <1> ;		dd 0
 34174                              <1> Vol_Total_Sector_Header:
 34175 0000B72E 0D0A                <1> 		db 0Dh, 0Ah
 34176 0000B730 566F6C756D65205369- <1> 		db "Volume Size : ", 0
 34177 0000B739 7A65203A2000        <1>
 34178                              <1> ;Vol_Tot_Sec_Str: 
 34179                              <1> ;		db "0000000000"
 34180                              <1> ;Vol_Tot_Sec_Str_End:
 34181                              <1> ;		db 0
 34182                              <1> ;Vol_Free_Sectors_Str_Start:
 34183                              <1> ;		dd 0
 34184                              <1> Vol_Free_Sectors_Header:
 34185 0000B73F 467265652053706163- <1> 		db "Free Space  : ", 0
 34186 0000B748 6520203A2000        <1>
 34187                              <1> ;Vol_Free_Sectors_Str:
 34188                              <1> ;		db "0000000000"
 34189                              <1> ;Vol_Free_Sectors_Str_End:
 34190                              <1> ;		db 0
 34191                              <1> 
 34192                              <1> Dir_Str_Header:
 34193 0000B74E 4469726563746F7279- <1>                 db "Directory: "
 34194 0000B757 3A20                <1>
 34195 0000B759 2F                  <1> Dir_Str_Root:   db "/"
 34196 0000B75A 00<rept>            <1> Dir_Str:        times 64 db 0
 34197 0000B79A 00000000            <1>                 dd 0
 34198 0000B79E 00                  <1>                 db 0
 34199                              <1> 
 34200                              <1> Msg_Bad_Command:
 34201 0000B79F 42616420636F6D6D61- <1>                 db "Bad command or file name!"
 34202 0000B7A8 6E64206F722066696C- <1>
 34203 0000B7B1 65206E616D6521      <1>
 34204 0000B7B8 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34205                              <1> 
 34206                              <1> msgl_drv_not_ready: 
 34207 0000B7BB 070D0A              <1> 		db 07h, 0Dh, 0Ah
 34208                              <1> 
 34209                              <1> ; CMD_INTR.ASM - 09/11/2011 - Messages
 34210                              <1> 
 34211                              <1> Msg_Not_Ready_Read_Err:
 34212 0000B7BE 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
 34213 0000B7C7 207265616479206F72- <1>
 34214 0000B7D0 207265616420657272- <1>
 34215 0000B7D9 6F7221              <1>
 34216 0000B7DC 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34217                              <1> 
 34218                              <1> Msg_Not_Ready_Write_Err:
 34219 0000B7DF 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
 34220 0000B7E8 207265616479206F72- <1>
 34221 0000B7F1 207772697465206572- <1>
 34222 0000B7FA 726F7221            <1>
 34223 0000B7FE 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34224                              <1> 
 34225                              <1> Msg_Dir_Not_Found:
 34226 0000B801 4469726563746F7279- <1>                 db "Directory not found!"
 34227 0000B80A 206E6F7420666F756E- <1>
 34228 0000B813 6421                <1>
 34229 0000B815 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34230                              <1> 
 34231                              <1> Msg_File_Not_Found:
 34232 0000B818 46696C65206E6F7420- <1>                 db "File not found!"
 34233 0000B821 666F756E6421        <1>
 34234 0000B827 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34235                              <1> 
 34236                              <1> Msg_File_Directory_Not_Found:
 34237 0000B82A 46696C65206F722064- <1>                 db "File or directory not found!"
 34238 0000B833 69726563746F727920- <1>
 34239 0000B83C 6E6F7420666F756E64- <1>
 34240 0000B845 21                  <1>
 34241 0000B846 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34242                              <1> 
 34243                              <1> Msg_LongName_Not_Found:
 34244 0000B849 4C6F6E67206E616D65- <1>                 db "Long name not found!"
 34245 0000B852 206E6F7420666F756E- <1>
 34246 0000B85B 6421                <1>
 34247 0000B85D 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34248                              <1> 
 34249                              <1> Msg_Insufficient_Memory:
 34250 0000B860 496E73756666696369- <1>                 db "Insufficient memory!"
 34251 0000B869 656E74206D656D6F72- <1>
 34252 0000B872 7921                <1>
 34253 0000B874 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34254                              <1> 
 34255                              <1> Msg_Error_Code:
 34256 0000B877 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
 34257 0000B880 61696C656421204572- <1>
 34258 0000B889 726F7220636F646520- <1>
 34259 0000B892 3A20                <1>
 34260 0000B894 303068              <1> error_code_hex: db '00h'
 34261 0000B897 0A0A00              <1>                 db 0Ah, 0Ah, 0
 34262                              <1> 
 34263                              <1> align 2
 34264                              <1> 
 34265                              <1> ; 10/02/2016
 34266                              <1> ; DIR.ASM - 09/10/2011
 34267                              <1> 
 34268 0000B89A 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
 34269 0000B8A3 20                  <1>
 34270                              <1> 
 34271                              <1> File_Name:
 34272 0000B8A4 20<rept>            <1>                 times 12 db 20h
 34273 0000B8B0 20                  <1> 		db 20h
 34274                              <1> Dir_Or_FileSize:
 34275 0000B8B1 20<rept>            <1>                 times 10 db 20h
 34276 0000B8BB 20                  <1> 		db 20h
 34277                              <1> File_Attribute:
 34278 0000B8BC 20202020            <1> 		dd 20202020h
 34279 0000B8C0 20                  <1> 		db 20h
 34280                              <1> File_Day:
 34281 0000B8C1 3030                <1>                 db '0','0'
 34282 0000B8C3 2F                  <1> 		db '/'
 34283                              <1> File_Month:
 34284 0000B8C4 3030                <1>                 db '0','0'
 34285 0000B8C6 2F                  <1> 		db '/'
 34286                              <1> File_Year:
 34287 0000B8C7 30303030            <1>                 db '0','0','0','0'
 34288 0000B8CB 20                  <1> 		db 20h
 34289                              <1> File_Hour:
 34290 0000B8CC 3030                <1>                 db '0','0'
 34291 0000B8CE 3A                  <1> 		db ':'
 34292                              <1> File_Minute:
 34293 0000B8CF 3030                <1>                 db '0','0'
 34294 0000B8D1 00                  <1> 		db 0
 34295                              <1> 
 34296                              <1> Decimal_File_Count_Header:
 34297 0000B8D2 0D0A                <1> 		db 0Dh, 0Ah
 34298                              <1> Decimal_File_Count:
 34299 0000B8D4 00<rept>            <1> 		times 6 db 0
 34300                              <1> 
 34301 0000B8DA 2066696C6528732920- <1> str_files:	db " file(s) & "
 34302 0000B8E3 2620                <1>
 34303                              <1> Decimal_Dir_Count: 
 34304 0000B8E5 00<rept>            <1> 		times 6 db 0
 34305                              <1> str_dirs:       
 34306 0000B8EB 206469726563746F72- <1> 		db " directory(s) "
 34307 0000B8F4 7928732920          <1>
 34308 0000B8F9 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34309                              <1> 
 34310 0000B8FC 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
 34311 0000B905 696E2066696C652873- <1>
 34312 0000B90E 29                  <1>
 34313 0000B90F 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34314                              <1> 
 34315                              <1> ; CMD_INTR.ASM - 09/11/2011
 34316                              <1> ; 07/10/2010
 34317                              <1> Msg_invalid_name_chars:
 34318 0000B912 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
 34319 0000B91B 696C65206F72206469- <1>
 34320 0000B924 726563746F7279206E- <1>
 34321 0000B92D 616D65206368617261- <1>
 34322 0000B936 637465727321        <1>
 34323 0000B93C 0D0A00              <1>         	db 0Dh, 0Ah, 0
 34324                              <1> ; 21/02/2016
 34325 0000B93F 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
 34326 0000B948 69726563746F727920- <1>
 34327 0000B951 6E616D652065786973- <1>
 34328 0000B95A 747321              <1>
 34329 0000B95D 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34330                              <1> Msg_DoYouWantMkdir:
 34331 0000B960 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
 34332 0000B969 6E7420746F206D616B- <1>
 34333 0000B972 65206469726563746F- <1>
 34334 0000B97B 72792000            <1>
 34335 0000B97F 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
 34336 0000B988 00                  <1>
 34337 0000B989 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
 34338 0000B98D 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
 34339                              <1> 
 34340                              <1> ; 27/02/2016
 34341                              <1> Msg_DoYouWantRmDir:
 34342 0000B993 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
 34343 0000B99C 6E7420746F2064656C- <1>
 34344 0000B9A5 657465206469726563- <1>
 34345 0000B9AE 746F72792000        <1>
 34346                              <1> Msg_Dir_Not_Empty:
 34347 0000B9B4 4469726563746F7279- <1>                 db "Directory not empty!"
 34348 0000B9BD 206E6F7420656D7074- <1>
 34349 0000B9C6 7921                <1>
 34350 0000B9C8 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34351                              <1> 
 34352                              <1> Msg_DoYouWantDelete:
 34353 0000B9CB 446F20796F75207761- <1>                 db "Do you want to delete file ",0
 34354 0000B9D4 6E7420746F2064656C- <1>
 34355 0000B9DD 6574652066696C6520- <1>
 34356 0000B9E6 00                  <1>
 34357                              <1> 
 34358 0000B9E7 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
 34359 0000B9F0 2E0D0A00            <1>
 34360                              <1> 
 34361                              <1> Msg_Permission_Denied:
 34362 0000B9F4 07                  <1>                 db 7
 34363 0000B9F5 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
 34364 0000B9FE 6E2064656E69656421- <1>
 34365 0000BA07 0D0A00              <1>
 34366                              <1> 
 34367                              <1> ; 04/03/2016
 34368 0000BA0A 4E657720            <1> Msg_New:        db "New "
 34369 0000BA0E 00                  <1>                 db 0
 34370                              <1> Str_Attributes:
 34371 0000BA0F 417474726962757465- <1>                 db "Attributes : "
 34372 0000BA18 73203A20            <1>
 34373 0000BA1C 4E4F524D414C        <1> Attr_Chars:     db "NORMAL"
 34374 0000BA22 00                  <1>                 db 0
 34375                              <1> 
 34376                              <1> ; 06/03/2016
 34377                              <1> ; CMD_INTR.ASM - 16/11/2010 
 34378                              <1> Msg_DoYouWantRename:
 34379 0000BA23 446F20796F75207761- <1>                 db "Do you want to rename ", 0
 34380 0000BA2C 6E7420746F2072656E- <1>
 34381 0000BA35 616D652000          <1>
 34382 0000BA3A 66696C652000        <1> Rename_File:    db "file ", 0
 34383 0000BA40 6469726563746F7279- <1> Rename_Directory: db "directory ", 0
 34384 0000BA49 2000                <1>
 34385 0000BA4B 00<rept>            <1> Rename_OldName: times 13 db 0
 34386 0000BA58 20617320            <1> Msg_File_rename_as: db " as "
 34387 0000BA5C 00<rept>            <1> Rename_NewName: times 13 db 0
 34388                              <1> 
 34389                              <1> ; 08/03/2016
 34390                              <1> ; CMD_INTR.ASM - 01/08/2010 - 23/04/2011
 34391                              <1> msg_not_same_drv:
 34392 0000BA69 4E6F742073616D6520- <1>                 db "Not same drive!" 
 34393 0000BA72 647269766521        <1>
 34394 0000BA78 0D0A00              <1>                 db 0Dh, 0Ah, 0 
 34395                              <1> 
 34396                              <1> Msg_DoYouWantMoveFile:
 34397 0000BA7B 446F20796F75207761- <1>                 db "Do you want to move file", 0
 34398 0000BA84 6E7420746F206D6F76- <1>
 34399 0000BA8D 652066696C6500      <1>
 34400                              <1> 
 34401                              <1> msg_insufficient_disk_space:
 34402 0000BA94 496E73756666696369- <1>                 db "Insufficient disk space!" 
 34403 0000BA9D 656E74206469736B20- <1>
 34404 0000BAA6 737061636521        <1>
 34405 0000BAAC 0D0A00              <1>                 db 0Dh, 0Ah, 0
 34406                              <1> 
 34407                              <1> ; 01/08/2010
 34408                              <1> msg_source_file: 
 34409 0000BAAF 0D0A536F7572636520- <1> 		db 0Dh, 0Ah, "Source file name      :   "
 34410 0000BAB8 66696C65206E616D65- <1>
 34411 0000BAC1 2020202020203A2020- <1>
 34412 0000BACA 20                  <1>
 34413                              <1> msg_source_file_drv: 
 34414 0000BACB 203A00              <1> 		db " :", 0
 34415                              <1> msg_destination_file: 
 34416 0000BACE 0D0A44657374696E61- <1> 		db 0Dh, 0Ah, "Destination file name :   "
 34417 0000BAD7 74696F6E2066696C65- <1>
 34418 0000BAE0 206E616D65203A2020- <1>
 34419 0000BAE9 20                  <1>
 34420                              <1> msg_destination_file_drv: 
 34421 0000BAEA 203A00              <1> 		db " :", 0
 34422                              <1> msg_copy_nextline: 
 34423 0000BAED 0D0A00              <1> 		db 0Dh, 0Ah, 0
 34424                              <1> 
 34425                              <1> ; 15/03/2016
 34426                              <1> ; CMD_INTR.ASM
 34427                              <1> 
 34428                              <1> Msg_DoYouWantOverWriteFile:
 34429 0000BAF0 446F20796F75207761- <1>                 db "Do you want to overwrite file ",0
 34430 0000BAF9 6E7420746F206F7665- <1>
 34431 0000BB02 727772697465206669- <1>
 34432 0000BB0B 6C652000            <1>
 34433                              <1>   
 34434                              <1> Msg_DoYouWantCopyFile:
 34435 0000BB0F 446F20796F75207761- <1>                 db "Do you want to copy file",0
 34436 0000BB18 6E7420746F20636F70- <1>
 34437 0000BB21 792066696C6500      <1>
 34438                              <1> 
 34439                              <1> Msg_read_file_error_before_EOF:
 34440 0000BB28 46696C652072656164- <1> 		db "File reading error! (before EOF)"
 34441 0000BB31 696E67206572726F72- <1>
 34442 0000BB3A 2120286265666F7265- <1>
 34443 0000BB43 20454F4629          <1>
 34444 0000BB48 0A0A00              <1> 		db 0Ah, 0Ah, 0
 34445                              <1> 
 34446                              <1> ; 18/03/2016
 34447                              <1> ; TRDOS 386 (v2.0) mainprog copy procedure
 34448                              <1> msg_reading:
 34449 0000BB4B 52656164696E672E2E- <1> 		db "Reading... ", 0
 34450 0000BB54 2E2000              <1>
 34451                              <1> msg_writing:
 34452 0000BB57 57726974696E672E2E- <1> 		db "Writing... ", 0
 34453 0000BB60 2E2000              <1>
 34454                              <1> percentagestr:
 34455 0000BB63 2020202500          <1> 		db "   %", 0  ; "  0%" .. "100%"
 34456                              <1> ; 11/04/2016
 34457                              <1> Msg_No_Set_Space:
 34458 0000BB68 496E73756666696369- <1>                 db "Insufficient environment space!"
 34459 0000BB71 656E7420656E766972- <1>
 34460 0000BB7A 6F6E6D656E74207370- <1>
 34461 0000BB83 61636521            <1>
 34462 0000BB87 0D0A00              <1>                 db 0Dh, 0Ah, 0 
 34463                                  
 34464                                  ; 07/03/2015
 34465                                  ; Temporary Code
 34466                                  display_disks:
 34467 0000BB8A 803D[4EBF0000]00        	cmp 	byte [fd0_type], 0
 34468 0000BB91 7605                    	jna 	short ddsks1
 34469 0000BB93 E87D000000              	call	pdskm
 34470                                  ddsks1:
 34471 0000BB98 803D[4FBF0000]00        	cmp	byte [fd1_type], 0
 34472 0000BB9F 760C                    	jna	short ddsks2
 34473 0000BBA1 C605[45C10000]31        	mov	byte [dskx], '1'
 34474 0000BBA8 E868000000              	call	pdskm
 34475                                  ddsks2:
 34476 0000BBAD 803D[50BF0000]00        	cmp	byte [hd0_type], 0
 34477 0000BBB4 7654                    	jna	short ddsk6
 34478 0000BBB6 66C705[43C10000]68-     	mov	word [dsktype], 'hd'
 34479 0000BBBE 64                 
 34480 0000BBBF C605[45C10000]30        	mov	byte [dskx], '0'
 34481 0000BBC6 E84A000000              	call	pdskm
 34482                                  ddsks3:
 34483 0000BBCB 803D[51BF0000]00        	cmp	byte [hd1_type], 0
 34484 0000BBD2 7636                    	jna	short ddsk6
 34485 0000BBD4 C605[45C10000]31        	mov	byte [dskx], '1'
 34486 0000BBDB E835000000              	call	pdskm
 34487                                  ddsks4:
 34488 0000BBE0 803D[52BF0000]00        	cmp	byte [hd2_type], 0
 34489 0000BBE7 7621                    	jna	short ddsk6
 34490 0000BBE9 C605[45C10000]32        	mov	byte [dskx], '2'
 34491 0000BBF0 E820000000              	call	pdskm
 34492                                  ddsks5:
 34493 0000BBF5 803D[53BF0000]00        	cmp	byte [hd3_type], 0
 34494 0000BBFC 760C                    	jna	short ddsk6
 34495 0000BBFE C605[45C10000]33        	mov	byte [dskx], '3'
 34496 0000BC05 E80B000000              	call	pdskm
 34497                                  ddsk6:
 34498 0000BC0A BE[56C10000]            	mov	esi, nextline
 34499 0000BC0F E806000000              	call	pdskml
 34500                                  pdskm_ok:
 34501 0000BC14 C3                      	retn
 34502                                  pdskm:
 34503 0000BC15 BE[41C10000]            	mov	esi, dsk_ready_msg
 34504                                  pdskml:	
 34505 0000BC1A AC                      	lodsb
 34506 0000BC1B 08C0                    	or	al, al
 34507 0000BC1D 74F5                    	jz	short pdskm_ok
 34508 0000BC1F 56                      	push	esi
 34509 0000BC20 31DB                    	xor	ebx, ebx ; 0
 34510                                  			; Video page 0 (bl=0)
 34511 0000BC22 B407                    	mov	ah, 07h ; Black background, 
 34512                                  			; light gray forecolor
 34513 0000BC24 E88E5BFFFF              	call	WRITE_TTY
 34514 0000BC29 5E                      	pop	esi
 34515 0000BC2A EBEE                    	jmp	short pdskml
 34516                                  
 34517 0000BC2C 90<rept>                align 16
 34518                                  
 34519                                  gdt:	; Global Descriptor Table
 34520                                  	; (30/07/2015, conforming cs)
 34521                                  	; (26/03/2015)
 34522                                  	; (24/03/2015, tss)
 34523                                  	; (19/03/2015)
 34524                                  	; (29/12/2013)
 34525                                  	;
 34526 0000BC30 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
 34527                                  	; 18/08/2014
 34528                                  			; 8h kernel code segment, base = 00000000h		
 34529 0000BC38 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
 34530                                  			; 10h kernel data segment, base = 00000000h	
 34531 0000BC40 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
 34532                                  			; 1Bh user code segment, base address = 400000h ; CORE
 34533 0000BC48 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE 
 34534                                  			; 23h user data segment, base address = 400000h ; CORE
 34535 0000BC50 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
 34536                                  			; Task State Segment
 34537 0000BC58 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
 34538                                  			       ;  no IO permission in ring 3)
 34539                                  gdt_tss0:
 34540 0000BC5A 0000                    	dw 0  ; TSS base address, bits 0-15 
 34541                                  gdt_tss1:
 34542 0000BC5C 00                      	db 0  ; TSS base address, bits 16-23 
 34543                                  	      		; 49h	
 34544 0000BC5D E9                      	db 11101001b ; E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
 34545 0000BC5E 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
 34546                                  gdt_tss2:
 34547 0000BC5F 00                      	db 0  ; TSS base address, bits 24-31 
 34548                                  
 34549                                  gdt_end:
 34550                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 34551                                  					;; Type= 1 (code)/C=0/R=1/A=0
 34552                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 34553                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 34554                                  
 34555                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 34556                                  					;; Type= 0 (data)/E=0/W=1/A=0
 34557                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 34558                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 34559                                  		; W= Writeable, A= Accessed
 34560                                  	
 34561                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
 34562                                  					;; Type= 1 (code)/C=0/R=1/A=0
 34563                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 34564                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 34565                                  
 34566                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
 34567                                  					;; Type= 0 (data)/E=0/W=1/A=0
 34568                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 34569                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 34570                                  	
 34571                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
 34572                                  
 34573                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
 34574                                  		;	 = 100000h * 1000h (G=1) = 4GB
 34575                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
 34576                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
 34577                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
 34578                                  		; AVL= Available to programmers	
 34579                                  
 34580                                  gdtd:
 34581 0000BC60 2F00                            dw gdt_end - gdt - 1    ; Limit (size)
 34582 0000BC62 [30BC0000]                      dd gdt			; Address of the GDT
 34583                                  
 34584                                  	; 20/08/2014
 34585                                  idtd:
 34586 0000BC66 FF01                            dw idt_end - idt - 1    ; Limit (size)
 34587 0000BC68 [10C20000]                      dd idt			; Address of the IDT
 34588                                  
 34589                                  Align 4
 34590                                  
 34591                                  	; 21/08/2014
 34592                                  ilist:
 34593                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
 34594                                  	;
 34595                                  	; Exception list
 34596                                  	; 25/08/2014	
 34597 0000BC6C [DB080000]              	dd	exc0	; 0h,  Divide-by-zero Error
 34598 0000BC70 [E2080000]              	dd	exc1	
 34599 0000BC74 [E9080000]              	dd 	exc2	
 34600 0000BC78 [F0080000]              	dd	exc3	
 34601 0000BC7C [F4080000]              	dd	exc4	
 34602 0000BC80 [F8080000]              	dd	exc5	
 34603 0000BC84 [FC080000]              	dd 	exc6	; 06h,  Invalid Opcode
 34604 0000BC88 [00090000]              	dd	exc7	
 34605 0000BC8C [04090000]              	dd	exc8	
 34606 0000BC90 [08090000]              	dd	exc9	
 34607 0000BC94 [0C090000]              	dd 	exc10	
 34608 0000BC98 [10090000]              	dd	exc11
 34609 0000BC9C [14090000]              	dd	exc12
 34610 0000BCA0 [18090000]              	dd	exc13	; 0Dh, General Protection Fault
 34611 0000BCA4 [1C090000]              	dd 	exc14	; 0Eh, Page Fault
 34612 0000BCA8 [20090000]              	dd	exc15
 34613 0000BCAC [24090000]              	dd	exc16
 34614 0000BCB0 [28090000]              	dd	exc17
 34615 0000BCB4 [2C090000]              	dd 	exc18
 34616 0000BCB8 [30090000]              	dd	exc19
 34617 0000BCBC [34090000]              	dd 	exc20
 34618 0000BCC0 [38090000]              	dd	exc21
 34619 0000BCC4 [3C090000]              	dd	exc22
 34620 0000BCC8 [40090000]              	dd	exc23
 34621 0000BCCC [44090000]              	dd 	exc24
 34622 0000BCD0 [48090000]              	dd	exc25
 34623 0000BCD4 [4C090000]              	dd	exc26
 34624 0000BCD8 [50090000]              	dd	exc27
 34625 0000BCDC [54090000]              	dd 	exc28
 34626 0000BCE0 [58090000]              	dd	exc29
 34627 0000BCE4 [5C090000]              	dd 	exc30
 34628 0000BCE8 [60090000]              	dd	exc31
 34629                                  	; Interrupt list
 34630 0000BCEC [11070000]              	dd	timer_int	; INT 20h
 34631                                  		;dd	irq0	
 34632 0000BCF0 [AD0D0000]              	dd	kb_int		; 24/01/2016
 34633                                  		;dd	irq1
 34634 0000BCF4 [31080000]              	dd	irq2
 34635                                  		; COM2 int
 34636 0000BCF8 [35080000]              	dd	irq3
 34637                                  		; COM1 int
 34638 0000BCFC [40080000]              	dd	irq4
 34639 0000BD00 [4B080000]              	dd	irq5
 34640                                  ;DISKETTE_INT: ;06/02/2015
 34641 0000BD04 [77280000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
 34642                                  		;dd	irq6
 34643                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
 34644                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 34645 0000BD08 [C70B0000]              	dd	default_irq7	; 25/02/2015
 34646                                  		;dd	irq7
 34647                                  ; Real Time Clock Interrupt
 34648 0000BD0C [6A0A0000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
 34649                                  		;dd	irq8	; INT 28h
 34650 0000BD10 [5B080000]              	dd	irq9
 34651 0000BD14 [5F080000]              	dd	irq10
 34652 0000BD18 [63080000]              	dd	irq11
 34653 0000BD1C [67080000]              	dd	irq12
 34654 0000BD20 [6B080000]              	dd	irq13
 34655                                  ;HDISK_INT1:  ;06/02/2015 	
 34656 0000BD24 [BA300000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
 34657                                  		;dd	irq14
 34658                                  ;HDISK_INT2:  ;06/02/2015
 34659 0000BD28 [E1300000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
 34660                                  		;dd	irq15	; INT 2Fh
 34661                                  		; 14/08/2015
 34662 0000BD2C [3E9B0000]              	dd	sysent		; INT 30h (system calls)
 34663                                  	
 34664                                  	;dd	ignore_int
 34665 0000BD30 00000000                	dd	0
 34666                                  
 34667                                  ;;;
 34668                                  ;;; 11/03/2015
 34669                                  %include 'kybdata.s'	; KEYBOARD (BIOS) DATA
 34670                              <1> ; ****************************************************************************
 34671                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - kybdata.s
 34672                              <1> ; ----------------------------------------------------------------------------
 34673                              <1> ; Last Update: 17/01/2016
 34674                              <1> ; ----------------------------------------------------------------------------
 34675                              <1> ; Beginning: 17/01/2016
 34676                              <1> ; ----------------------------------------------------------------------------
 34677                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34678                              <1> ; ----------------------------------------------------------------------------
 34679                              <1> ; Turkish Rational DOS
 34680                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 34681                              <1> ;
 34682                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 34683                              <1> ; kybdata.inc (11/03/2015)
 34684                              <1> ;
 34685                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 34686                              <1> ; ****************************************************************************
 34687                              <1> 
 34688                              <1> ; Retro UNIX 386 v1 Kernel - KYBDATA.INC
 34689                              <1> ; Last Modification: 11/03/2015
 34690                              <1> ;		 (Data Section for 'KEYBOARD.INC')	
 34691                              <1> ;
 34692                              <1> ; ///////// KEYBOARD DATA ///////////////
 34693                              <1> 
 34694                              <1> ; 05/12/2014
 34695                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-) 
 34696                              <1> ; 03/06/86  KEYBOARD BIOS
 34697                              <1> 
 34698                              <1> ;---------------------------------------------------------------------------------
 34699                              <1> ;	KEY IDENTIFICATION SCAN TABLES
 34700                              <1> ;---------------------------------------------------------------------------------
 34701                              <1> 
 34702                              <1> ;-----	TABLES FOR ALT CASE ------------
 34703                              <1> ;-----	ALT-INPUT-TABLE 
 34704 0000BD34 524F50514B          <1> K30:	db	82,79,80,81,75
 34705 0000BD39 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
 34706                              <1> ;-----	SUPER-SHIFT-TABLE 
 34707 0000BD3E 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
 34708 0000BD44 161718191E1F        <1> 	db	22,23,24,25,30,31
 34709 0000BD4A 202122232425        <1> 	db	32,33,34,35,36,37
 34710 0000BD50 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
 34711 0000BD56 3132                <1> 	db	49,50
 34712                              <1> 
 34713                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
 34714                              <1> ;-----	KEY_TABLE 
 34715 0000BD58 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
 34716 0000BD59 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
 34717 0000BD5E 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
 34718                              <1> _K6L    equ     $-_K6
 34719                              <1> 
 34720                              <1> ;-----	MASK_TABLE
 34721 0000BD60 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
 34722 0000BD61 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
 34723 0000BD66 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
 34724                              <1> 
 34725                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
 34726 0000BD68 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
 34727 0000BD6E 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
 34728 0000BD74 FF7FFF111705        <1> 	db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
 34729 0000BD7A 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
 34730 0000BD80 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
 34731 0000BD86 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
 34732 0000BD8C 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
 34733 0000BD92 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
 34734 0000BD98 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
 34735 0000BD9E 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
 34736                              <1> 	;				;----- FUNCTIONS ------		
 34737 0000BDA2 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
 34738 0000BDA8 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
 34739 0000BDAE 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
 34740 0000BDB4 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
 34741 0000BDBA 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
 34742                              <1> 
 34743                              <1> ;-----	TABLES FOR LOWER CASE ----------
 34744 0000BDC0 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
 34745 0000BDC9 39302D3D0809        <1>
 34746 0000BDCF 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
 34747 0000BDD8 705B5D0DFF61736466- <1>
 34748 0000BDE1 67686A6B6C3B27      <1>
 34749 0000BDE8 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
 34750 0000BDF1 6D2C2E2FFF2AFF20FF  <1>
 34751                              <1> ;-----	LC TABLE SCAN
 34752 0000BDFA 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
 34753 0000BDFF 4041424344          <1> 	db	64,65,66,67,68
 34754 0000BE04 FFFF                <1> 	db	-1,-1			; NL, SL
 34755                              <1> 
 34756                              <1> ;-----	KEYPAD TABLE
 34757 0000BE06 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
 34758 0000BE0C 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
 34759 0000BE13 FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
 34760                              <1> 
 34761                              <1> ;-----	TABLES FOR UPPER CASE ----------
 34762 0000BE18 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
 34763 0000BE21 28295F2B0800        <1>
 34764 0000BE27 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
 34765 0000BE30 507B7D0DFF41534446- <1>
 34766 0000BE39 47484A4B4C3A22      <1>
 34767 0000BE40 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
 34768 0000BE49 4D3C3E3FFF2AFF20FF  <1>
 34769                              <1> ;-----	UC TABLE SCAN
 34770 0000BE52 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
 34771 0000BE57 595A5B5C5D          <1> 	db	89,90,91,92,93
 34772 0000BE5C FFFF                <1> 	db	-1,-1			; NL, SL
 34773                              <1> 
 34774                              <1> ;-----	NUM STATE TABLE
 34775 0000BE5E 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
 34776 0000BE67 3233302E            <1>
 34777                              <1> 	;
 34778 0000BE6B FFFF7C8788          <1> 	db	-1,-1,124,135,136	; SysRq, Undef, WT, F11, F12
 34779                              <1> 
 34780                              <1> ; 26/08/2014
 34781                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (03/03/2014)
 34782                              <1> ; Derived from IBM "pc-at" 
 34783                              <1> ; rombios source code (06/10/1985)
 34784                              <1> ; 'dseg.inc'
 34785                              <1> 
 34786                              <1> ;---------------------------------------;
 34787                              <1> ;	SYSTEM DATA AREA		;
 34788                              <1> ;----------------------------------------
 34789 0000BE70 00                  <1> BIOS_BREAK	db	0		; BIT 7=1 IF BREAK KEY HAS BEEN PRESSED
 34790                              <1> 
 34791                              <1> ;----------------------------------------
 34792                              <1> ;	KEYBOARD DATA AREAS		;
 34793                              <1> ;----------------------------------------
 34794                              <1> 
 34795 0000BE71 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
 34796 0000BE72 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
 34797 0000BE73 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
 34798 0000BE74 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
 34799 0000BE75 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
 34800 0000BE76 [86BE0000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
 34801 0000BE7A [A6BE0000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
 34802 0000BE7E [86BE0000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
 34803 0000BE82 [86BE0000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
 34804                              <1> ; ------	HEAD = TAIL	INDICATES THAT THE BUFFER IS EMPTY
 34805 0000BE86 0000<rept>          <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
 34806                              <1> 
 34807                              <1> ; /// End Of KEYBOARD DATA ///
 34808                                  %include 'vidata.s'	; VIDEO (BIOS) DATA
 34809                              <1> ; ****************************************************************************
 34810                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vidata.s
 34811                              <1> ; ----------------------------------------------------------------------------
 34812                              <1> ; Last Update: 30/01/2016
 34813                              <1> ; ----------------------------------------------------------------------------
 34814                              <1> ; Beginning: 16/01/2016
 34815                              <1> ; ----------------------------------------------------------------------------
 34816                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34817                              <1> ; ----------------------------------------------------------------------------
 34818                              <1> ; Turkish Rational DOS
 34819                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 34820                              <1> ;
 34821                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 34822                              <1> ; vidata.inc (11/03/2015)
 34823                              <1> ;
 34824                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 34825                              <1> ; ****************************************************************************
 34826                              <1> 
 34827                              <1> ; Retro UNIX 386 v1 Kernel - VIDATA.S
 34828                              <1> ; Last Modification: 11/03/2015
 34829                              <1> ;		    (Data section for 'VIDEO.INC')	
 34830                              <1> ;
 34831                              <1> ; ///////// VIDEO DATA ///////////////
 34832                              <1> 
 34833                              <1> ;-----	COLUMNS
 34834                              <1> ;M6:
 34835                              <1> ;	db	40, 40, 80, 80, 40, 40, 80, 80
 34836                              <1> 
 34837                              <1> ;-----	C_REG_TAB
 34838                              <1> ;M7:
 34839                              <1> ;	db	2Ch, 28h, 2Dh, 29h, 2Ah, 2Eh, 1Eh, 29h	; TABLE OF MODE SETS
 34840                              <1> 
 34841                              <1> ;----------------------------------------
 34842                              <1> ;	VIDEO DISPLAY DATA AREA		;
 34843                              <1> ;----------------------------------------
 34844 0000BEA6 03                  <1> CRT_MODE	db	3	; CURRENT DISPLAY MODE (TYPE)
 34845 0000BEA7 29                  <1> CRT_MODE_SET	db	29h	; CURRENT SETTING OF THE 3X8 REGISTER
 34846                              <1> 				; (29h default setting for video mode 3)
 34847                              <1> 				; Mode Select register Bits
 34848                              <1> 				;   BIT 0 - 80x25 (1), 40x25 (0)
 34849                              <1> 				;   BIT 1 - ALPHA (0), 320x200 GRAPHICS (1)
 34850                              <1> 				;   BIT 2 - COLOR (0), BW (1)
 34851                              <1> 				;   BIT 3 - Video Sig. ENABLE (1), DISABLE (0)
 34852                              <1> 				;   BIT 4 - 640x200 B&W Graphics Mode (1)
 34853                              <1> 				;   BIT 5 - ALPHA mode BLINKING (1)
 34854                              <1> 				;   BIT 6, 7 - Not Used
 34855                              <1> 
 34856                              <1> ; Mode 0 - 2Ch = 101100b	; 40x25 text, 16 gray colors
 34857                              <1> ; Mode 1 - 28h = 101000b	; 40x25 text, 16 fore colors, 8 back colors
 34858                              <1> ; Mode 2 - 2Dh = 101101b	; 80x25 text, 16 gray colors	
 34859                              <1> ; MODE 3 - 29h = 101001b	; 80x25 text, 16 fore color, 8 back color
 34860                              <1> ; Mode 4 - 2Ah = 101010b	; 320x200 graphics, 4 colors
 34861                              <1> ; Mode 5 - 2Eh = 101110b	; 320x200 graphics, 4 gray colors
 34862                              <1> ; Mode 6 - 1Eh = 011110b	; 640x200 graphics, 2 colors
 34863                              <1> ; Mode 7 - 29h = 101001b	; 80x25 text, black & white colors
 34864                              <1> ; Mode & 37h = Video signal OFF
 34865                              <1> 			
 34866                              <1> video_params:
 34867                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
 34868                              <1> 	;ORGS.ASM ----- 06/10/85   COMPATIBILITY MODULE
 34869                              <1> 	; VIDEO MODE 3
 34870 0000BEA8 71505A0A1F0619      <1> 	db	71h,50h,5Ah,0Ah,1Fh,6,19h	; SET UP FOR 80X25
 34871 0000BEAF 1C02070607          <1> 	db	1Ch,2,7,6,7	; cursor start = 6, cursor stop = 7
 34872 0000BEB4 00000000            <1> 	db	0,0,0,0
 34873                              <1> 
 34874                              <1> ; 16/01/2016
 34875                              <1> chr_attrib:  ; Character color/attributes for viode pages (0 to 7)
 34876 0000BEB8 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
 34877                              <1> ; 30/01/2016
 34878                              <1> vmode:
 34879 0000BEC0 0303030303030303    <1> 	db	3,3,3,3,3,3,3,3 ; video modes for pseudo screens 
 34880                              <1> 
 34881                              <1> ; /// End Of VIDEO DATA ///
 34882                                  %include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
 34883                              <1> ; ****************************************************************************
 34884                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskdata.s
 34885                              <1> ; ----------------------------------------------------------------------------
 34886                              <1> ; Last Update: 24/01/2016
 34887                              <1> ; ----------------------------------------------------------------------------
 34888                              <1> ; Beginning: 24/01/2016
 34889                              <1> ; ----------------------------------------------------------------------------
 34890                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34891                              <1> ; ----------------------------------------------------------------------------
 34892                              <1> ; Turkish Rational DOS
 34893                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 34894                              <1> ;
 34895                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 34896                              <1> ; diskdata.inc (11/03/2015)
 34897                              <1> ;
 34898                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 34899                              <1> ; ****************************************************************************
 34900                              <1> 
 34901                              <1> ; Retro UNIX 386 v1 Kernel - DISKDATA.INC
 34902                              <1> ; Last Modification: 11/03/2015
 34903                              <1> ;	(Initialized Disk Parameters Data section for 'DISKIO.INC') 
 34904                              <1> ;
 34905                              <1> 
 34906                              <1> ;----------------------------------------
 34907                              <1> ;	80286 INTERRUPT LOCATIONS	:
 34908                              <1> ;	REFERENCED BY POST & BIOS	:
 34909                              <1> ;----------------------------------------
 34910                              <1> 
 34911 0000BEC8 [2BBF0000]          <1> DISK_POINTER:	dd	MD_TBL6		; Pointer to Diskette Parameter Table
 34912                              <1> 
 34913                              <1> ; IBM PC-XT Model 286 source code ORGS.ASM (06/10/85) - 14/12/2014
 34914                              <1> ;----------------------------------------------------------------
 34915                              <1> ; DISK_BASE							:
 34916                              <1> ;	THIS IS THE SET OF PARAMETERS REQUIRED FOR		:
 34917                              <1> ;	DISKETTE OPERATION. THEY ARE POINTED AT BY THE		:
 34918                              <1> ;	DATA VARIABLE @DISK_POINTER. TO MODIFY THE PARAMETERS,	:
 34919                              <1> ;	BUILD ANOTHER PARAMETER BLOCK AND POINT AT IT		:
 34920                              <1> ;----------------------------------------------------------------
 34921                              <1> 
 34922                              <1> ;DISK_BASE:	
 34923                              <1> ;	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 34924                              <1> ;	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 34925                              <1> ;	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 34926                              <1> ;	DB	2		; 512 BYTES/SECTOR
 34927                              <1> ;	;DB	15		; EOT (LAST SECTOR ON TRACK)
 34928                              <1> ;	db	18		; (EOT for 1.44MB diskette)
 34929                              <1> ;	DB	01BH		; GAP LENGTH
 34930                              <1> ;	DB	0FFH		; DTL
 34931                              <1> ;	;DB	054H		; GAP LENGTH FOR FORMAT
 34932                              <1> ;	db	06ch		; (for 1.44MB dsikette)
 34933                              <1> ;	DB	0F6H		; FILL BYTE FOR FORMAT
 34934                              <1> ;	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 34935                              <1> ;	DB	8		; MOTOR START TIME (1/8 SECONDS)
 34936                              <1> 
 34937                              <1> ;----------------------------------------
 34938                              <1> ;	ROM BIOS DATA AREAS		:
 34939                              <1> ;----------------------------------------
 34940                              <1> 
 34941                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 34942                              <1> 
 34943                              <1> ;@EQUIP_FLAG	DW	?		; INSTALLED HARDWARE FLAGS
 34944                              <1> 
 34945                              <1> ;----------------------------------------
 34946                              <1> ;	DISKETTE DATA AREAS		:
 34947                              <1> ;----------------------------------------
 34948                              <1> 
 34949                              <1> ;@SEEK_STATUS	DB	?		; DRIVE RECALIBRATION STATUS
 34950                              <1> ;					; BIT 3-0 = DRIVE 3-0 RECALIBRATION
 34951                              <1> ;					; BEFORE NEXT SEEK IF BIT IS = 0
 34952                              <1> ;@MOTOR_STATUS	DB	?		; MOTOR STATUS
 34953                              <1> ;					; BIT 3-0 = DRIVE 3-0 CURRENTLY RUNNING
 34954                              <1> ;					; BIT 7 = CURRENT OPERATION IS A WRITE
 34955                              <1> ;@MOTOR_COUNT	DB	?		; TIME OUT COUNTER FOR MOTOR(S) TURN OFF
 34956                              <1> ;@DSKETTE_STATUS DB	?		; RETURN CODE STATUS BYTE
 34957                              <1> ;					; CMD_BLOCK  IN STACK FOR DISK OPERATION
 34958                              <1> ;@NEC_STATUS	DB	7 DUP(?)	; STATUS BYTES FROM DISKETTE OPERATION
 34959                              <1> 
 34960                              <1> ;----------------------------------------
 34961                              <1> ;	POST AND BIOS WORK DATA AREA	:
 34962                              <1> ;----------------------------------------
 34963                              <1> 
 34964                              <1> ;@INTR_FLAG	DB	?		; FLAG INDICATING AN INTERRUPT HAPPENED
 34965                              <1> 
 34966                              <1> ;----------------------------------------
 34967                              <1> ;	TIMER DATA AREA 		:
 34968                              <1> ;----------------------------------------
 34969                              <1> 
 34970                              <1> ; 17/12/2014  (IRQ 0 - INT 08H)
 34971                              <1> ;TIMER_LOW	equ	46Ch		; Timer ticks (counter)  @ 40h:006Ch
 34972                              <1> ;TIMER_HIGH	equ	46Eh		; (18.2 timer ticks per second)
 34973                              <1> ;TIMER_OFL	equ	470h		; Timer - 24 hours flag  @ 40h:0070h
 34974                              <1> 
 34975                              <1> ;----------------------------------------
 34976                              <1> ;	ADDITIONAL MEDIA DATA		:
 34977                              <1> ;----------------------------------------
 34978                              <1> 
 34979                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 34980                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 34981                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 34982                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 34983                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 34984                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 34985                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 34986                              <1> 
 34987                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 34988                              <1> 
 34989                              <1> ;--------------------------------------------------------
 34990                              <1> ;	DRIVE TYPE TABLE				:
 34991                              <1> ;--------------------------------------------------------
 34992                              <1> 		; 16/02/2015 (unix386.s, 32 bit modifications)
 34993                              <1> DR_TYPE:
 34994 0000BECC 01                  <1> 		DB	01		;DRIVE TYPE, MEDIA TABLE
 34995                              <1>                 ;DW      MD_TBL1
 34996 0000BECD [EABE0000]          <1> 		dd	MD_TBL1
 34997 0000BED1 82                  <1> 		DB	02+BIT7ON
 34998                              <1> 		;DW      MD_TBL2
 34999 0000BED2 [F7BE0000]          <1>                 dd      MD_TBL2
 35000 0000BED6 02                  <1> DR_DEFAULT:	DB	02
 35001                              <1>                 ;DW      MD_TBL3
 35002 0000BED7 [04BF0000]          <1> 		dd      MD_TBL3
 35003 0000BEDB 03                  <1> 		DB	03
 35004                              <1>                 ;DW      MD_TBL4
 35005 0000BEDC [11BF0000]          <1> 		dd      MD_TBL4
 35006 0000BEE0 84                  <1> 		DB	04+BIT7ON
 35007                              <1>                 ;DW      MD_TBL5
 35008 0000BEE1 [1EBF0000]          <1> 		dd      MD_TBL5
 35009 0000BEE5 04                  <1> 		DB	04
 35010                              <1>                 ;DW      MD_TBL6
 35011 0000BEE6 [2BBF0000]          <1> 		dd      MD_TBL6
 35012                              <1> DR_TYPE_E       equ $                   ; END OF TABLE
 35013                              <1> ;DR_CNT		EQU	(DR_TYPE_E-DR_TYPE)/3
 35014                              <1> DR_CNT		equ	(DR_TYPE_E-DR_TYPE)/5
 35015                              <1> ;--------------------------------------------------------
 35016                              <1> ;	MEDIA/DRIVE PARAMETER TABLES			:
 35017                              <1> ;--------------------------------------------------------
 35018                              <1> ;--------------------------------------------------------
 35019                              <1> ;	360 KB MEDIA IN 360 KB DRIVE			:
 35020                              <1> ;--------------------------------------------------------
 35021                              <1> MD_TBL1:        
 35022 0000BEEA DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35023 0000BEEB 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35024 0000BEEC 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35025 0000BEED 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35026 0000BEEE 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 35027 0000BEEF 2A                  <1> 	DB	02AH		; GAP LENGTH
 35028 0000BEF0 FF                  <1> 	DB	0FFH		; DTL
 35029 0000BEF1 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 35030 0000BEF2 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35031 0000BEF3 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35032 0000BEF4 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35033 0000BEF5 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 35034 0000BEF6 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 35035                              <1> ;--------------------------------------------------------
 35036                              <1> ;	360 KB MEDIA IN 1.2 MB DRIVE			:
 35037                              <1> ;--------------------------------------------------------
 35038                              <1> MD_TBL2:        
 35039 0000BEF7 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35040 0000BEF8 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35041 0000BEF9 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35042 0000BEFA 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35043 0000BEFB 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 35044 0000BEFC 2A                  <1> 	DB	02AH		; GAP LENGTH
 35045 0000BEFD FF                  <1> 	DB	0FFH		; DTL
 35046 0000BEFE 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 35047 0000BEFF F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35048 0000BF00 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35049 0000BF01 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35050 0000BF02 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 35051 0000BF03 40                  <1> 	DB	RATE_300	; DATA TRANSFER RATE
 35052                              <1> ;--------------------------------------------------------
 35053                              <1> ;	1.2 MB MEDIA IN 1.2 MB DRIVE			:
 35054                              <1> ;--------------------------------------------------------
 35055                              <1> MD_TBL3:
 35056 0000BF04 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35057 0000BF05 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35058 0000BF06 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35059 0000BF07 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35060 0000BF08 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
 35061 0000BF09 1B                  <1> 	DB	01BH		; GAP LENGTH
 35062 0000BF0A FF                  <1> 	DB	0FFH		; DTL
 35063 0000BF0B 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
 35064 0000BF0C F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35065 0000BF0D 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35066 0000BF0E 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35067 0000BF0F 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 35068 0000BF10 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 35069                              <1> ;--------------------------------------------------------
 35070                              <1> ;	720 KB MEDIA IN 720 KB DRIVE			:
 35071                              <1> ;--------------------------------------------------------
 35072                              <1> MD_TBL4:
 35073 0000BF11 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35074 0000BF12 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35075 0000BF13 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35076 0000BF14 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35077 0000BF15 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 35078 0000BF16 2A                  <1> 	DB	02AH		; GAP LENGTH
 35079 0000BF17 FF                  <1> 	DB	0FFH		; DTL
 35080 0000BF18 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 35081 0000BF19 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35082 0000BF1A 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35083 0000BF1B 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35084 0000BF1C 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 35085 0000BF1D 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 35086                              <1> ;--------------------------------------------------------
 35087                              <1> ;	720 KB MEDIA IN 1.44 MB DRIVE			:
 35088                              <1> ;--------------------------------------------------------
 35089                              <1> MD_TBL5:
 35090 0000BF1E DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35091 0000BF1F 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35092 0000BF20 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35093 0000BF21 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35094 0000BF22 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 35095 0000BF23 2A                  <1> 	DB	02AH		; GAP LENGTH
 35096 0000BF24 FF                  <1> 	DB	0FFH		; DTL
 35097 0000BF25 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 35098 0000BF26 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35099 0000BF27 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35100 0000BF28 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35101 0000BF29 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 35102 0000BF2A 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 35103                              <1> ;--------------------------------------------------------
 35104                              <1> ;	1.44 MB MEDIA IN 1.44 MB DRIVE			:
 35105                              <1> ;--------------------------------------------------------
 35106                              <1> MD_TBL6:
 35107 0000BF2B AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
 35108 0000BF2C 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 35109 0000BF2D 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 35110 0000BF2E 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 35111 0000BF2F 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
 35112 0000BF30 1B                  <1> 	DB	01BH		; GAP LENGTH
 35113 0000BF31 FF                  <1> 	DB	0FFH		; DTL
 35114 0000BF32 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
 35115 0000BF33 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 35116 0000BF34 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 35117 0000BF35 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 35118 0000BF36 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 35119 0000BF37 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 35120                              <1> 
 35121                              <1> 
 35122                              <1> ; << diskette.inc >>
 35123                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 35124                              <1> ;
 35125                              <1> ;----------------------------------------
 35126                              <1> ;	ROM BIOS DATA AREAS		:
 35127                              <1> ;----------------------------------------
 35128                              <1> 
 35129                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 35130                              <1> 
 35131                              <1> ;----------------------------------------
 35132                              <1> ;	FIXED DISK DATA AREAS		:
 35133                              <1> ;----------------------------------------
 35134                              <1> 
 35135                              <1> ;DISK_STATUS1:	DB	0		; FIXED DISK STATUS
 35136                              <1> ;HF_NUM:		DB	0		; COUNT OF FIXED DISK DRIVES
 35137                              <1> ;CONTROL_BYTE:	DB	0		; HEAD CONTROL BYTE
 35138                              <1> ;@PORT_OFF	DB	?		;  RESERVED (PORT OFFSET)
 35139                              <1> 
 35140                              <1> ;----------------------------------------
 35141                              <1> ;	ADDITIONAL MEDIA DATA		:
 35142                              <1> ;----------------------------------------
 35143                              <1> 
 35144                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 35145                              <1> ;HF_STATUS	DB	0		; STATUS REGISTER
 35146                              <1> ;HF_ERROR	DB	0		; ERROR REGISTER
 35147                              <1> ;HF_INT_FLAG	DB	0		; FIXED DISK INTERRUPT FLAG
 35148                              <1> ;HF_CNTRL	DB	0		; COMBO FIXED DISK/DISKETTE CARD BIT 0=1
 35149                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 35150                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 35151                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 35152                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 35153                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 35154                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 35155                              <1> 
 35156                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 35157                              <1> ;
 35158                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 35159                              <1> 
 35160                              <1> ERR_TBL:
 35161 0000BF38 E0                  <1> 	db	NO_ERR
 35162 0000BF39 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
 35163 0000BF3D 04BB100A            <1> 	db	RECORD_NOT_FND,UNDEF_ERR,BAD_ECC,BAD_SECTOR
 35164                              <1> 
 35165                              <1> ; 17/12/2014 (mov ax, [cfd])
 35166                              <1> ; 11/12/2014
 35167 0000BF41 00                  <1> cfd:		db 0			; current floppy drive (for GET_PARM)
 35168                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
 35169 0000BF42 01                  <1> pfd:		db 1			; previous floppy drive (for GET_PARM)
 35170                              <1> 					; (initial value of 'pfd 
 35171                              <1> 					; must be different then 'cfd' value
 35172                              <1> 					; to force updating/initializing
 35173                              <1> 					; current drive parameters) 
 35174 0000BF43 90                  <1> align 2
 35175                              <1> 
 35176 0000BF44 F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
 35177                              <1> 			      ; (170h)
 35178 0000BF46 F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
 35179                              <1> 
 35180                              <1> ; 05/01/2015 
 35181 0000BF48 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
 35182                              <1> 
 35183                              <1> ; *****************************************************************************
 35184                                  ;;;
 35185                                  
 35186 0000BF49 90                      Align 2
 35187                                  
 35188                                  ; 12/11/2014 (Retro UNIX 386 v1)
 35189 0000BF4A 00                      boot_drv:    db 0 ; boot drive number (physical)
 35190                                  ; 24/11/2014
 35191 0000BF4B 00                      drv:	     db 0 
 35192 0000BF4C 00                      last_drv:    db 0 ; last hdd
 35193 0000BF4D 00                      hdc:         db 0  ; number of hard disk drives
 35194                                  		     ; (present/detected)
 35195                                  ;
 35196                                  ; 24/11/2014 (Retro UNIX 386 v1)
 35197                                  ; Physical drive type & flags
 35198 0000BF4E 00                      fd0_type:    db 0  ; floppy drive type
 35199 0000BF4F 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
 35200                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
 35201                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
 35202                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
 35203                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
 35204 0000BF50 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
 35205 0000BF51 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
 35206 0000BF52 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
 35207 0000BF53 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
 35208                                  		     ; bit 0 - Fixed disk access subset supported
 35209                                  		     ; bit 1 - Drive locking and ejecting
 35210                                  		     ; bit 2 - Enhanced disk drive support
 35211                                  		     ; bit 3 = Reserved (64 bit EDD support)
 35212                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
 35213                                  		     ; will interpret it as 'LBA ready'!)		
 35214                                  
 35215                                  ; 11/03/2015 - 10/07/2015
 35216 0000BF54 000000000000000000-     drv.cylinders: dw 0,0,0,0,0,0,0
 35217 0000BF5D 0000000000         
 35218 0000BF62 000000000000000000-     drv.heads:     dw 0,0,0,0,0,0,0
 35219 0000BF6B 0000000000         
 35220 0000BF70 000000000000000000-     drv.spt:       dw 0,0,0,0,0,0,0
 35221 0000BF79 0000000000         
 35222 0000BF7E 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
 35223 0000BF87 000000000000000000-
 35224 0000BF90 000000000000000000-
 35225 0000BF99 00                 
 35226 0000BF9A 00000000000000          drv.status:    db 0,0,0,0,0,0,0
 35227 0000BFA1 00000000000000          drv.error:     db 0,0,0,0,0,0,0		
 35228                                  ;
 35229                                  
 35230                                  ; 27/08/2014
 35231                                  scr_row:
 35232 0000BFA8 E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
 35233                                  scr_col:
 35234 0000BFAC 00000000                	dd 0
 35235                                  
 35236                                  ; 20/08/2014
 35237                                    ; /* This is the default interrupt "handler" :-) */ 
 35238                                    ; Linux v0.12 (head.s)
 35239                                  int_msg:
 35240 0000BFB0 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
 35241 0000BFB9 6E7465727275707420-
 35242 0000BFC2 212000             
 35243                                  
 35244                                  
 35245                                  ; 21/08/2014
 35246                                  timer_msg:
 35247 0000BFC5 49525120302028494E-     	db "IRQ 0 (INT 20h) ! Timer Interrupt : "
 35248 0000BFCE 542032306829202120-
 35249 0000BFD7 54696D657220496E74-
 35250 0000BFE0 657272757074203A20 
 35251                                  tcountstr:
 35252 0000BFE9 303030303020            	db "00000 "
 35253 0000BFEF 00                      	db 0
 35254                                  
 35255                                  Align 2
 35256                                  	; 21/08/2014
 35257                                  exc_msg:
 35258 0000BFF0 435055206578636570-     	db "CPU exception ! "
 35259 0000BFF9 74696F6E202120     
 35260                                  excnstr: 		; 25/08/2014
 35261 0000C000 3F3F68202045495020-     	db "??h", "  EIP : "
 35262 0000C009 3A20               
 35263                                  EIPstr: ; 29/08/2014
 35264 0000C00B 00<rept>                	times 12 db 0
 35265                                  rtc_msg:
 35266 0000C017 5265616C2054696D65-     	db "Real Time Clock - "
 35267 0000C020 20436C6F636B202D20 
 35268                                  datestr:
 35269 0000C029 30302F30302F303030-     	db "00/00/0000"
 35270 0000C032 30                 
 35271 0000C033 20                      	db " "
 35272                                  daystr:
 35273 0000C034 44415920                	db "DAY "
 35274                                  timestr:	
 35275 0000C038 30303A30303A3030                db "00:00:00"
 35276 0000C040 20                      	db " "
 35277 0000C041 00                      	db 0 
 35278                                  
 35279                                  daytmp:
 35280                                  	; 28/02/2015
 35281 0000C042 3F3F3F2053554E204D-     	db "??? SUN MON TUE WED THU FRI SAT "
 35282 0000C04B 4F4E20545545205745-
 35283 0000C054 442054485520465249-
 35284 0000C05D 2053415420         
 35285                                  
 35286 0000C062 FF                      ptime_seconds: db 0FFh
 35287                                  
 35288                                  	; 23/02/2015
 35289                                  	; 25/08/2014
 35290                                  ;scounter:
 35291                                  ;	db 5
 35292                                  ;	db 19
 35293                                  
 35294                                  ; 05/11/2014
 35295                                  msg_out_of_memory:
 35296 0000C063 070D0A                  	db 	07h, 0Dh, 0Ah
 35297 0000C066 496E73756666696369-             db      'Insufficient memory ! (Minimum 2 MB memory is needed.)'
 35298 0000C06F 656E74206D656D6F72-
 35299 0000C078 79202120284D696E69-
 35300 0000C081 6D756D2032204D4220-
 35301 0000C08A 6D656D6F7279206973-
 35302 0000C093 206E65656465642E29 
 35303 0000C09C 0D0A00                   	db	0Dh, 0Ah, 0
 35304                                  	;
 35305                                  setup_error_msg:
 35306 0000C09F 0D0A                    	db 0Dh, 0Ah
 35307 0000C0A1 4469736B2053657475-     	db 'Disk Setup Error!' 
 35308 0000C0AA 70204572726F7221   
 35309 0000C0B2 0D0A00                  	db 0Dh, 0Ah,0
 35310                                  
 35311                                  ; 06/11/2014
 35312                                  ; Memory Information message
 35313                                  ; 14/08/2015
 35314                                  msg_memory_info:
 35315 0000C0B5 07                      	db	07h
 35316 0000C0B6 0D0A                    	db	0Dh, 0Ah
 35317                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
 35318 0000C0B8 546F74616C206D656D-     	db	"Total memory : "
 35319 0000C0C1 6F7279203A20       
 35320                                  mem_total_b_str: ; 10 digits
 35321 0000C0C7 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
 35322 0000C0D0 302062797465730D0A 
 35323 0000C0D9 202020202020202020-     	db	"               ", 20h, 20h, 20h
 35324 0000C0E2 202020202020202020 
 35325                                  mem_total_p_str: ; 7 digits
 35326 0000C0EB 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
 35327 0000C0F4 616765730D0A       
 35328 0000C0FA 0D0A                    	db 	0Dh, 0Ah
 35329 0000C0FC 46726565206D656D6F-     	db	"Free memory  : "
 35330 0000C105 727920203A20       
 35331                                  free_mem_b_str:  ; 10 digits
 35332 0000C10B 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
 35333 0000C114 3F2062797465730D0A 
 35334 0000C11D 202020202020202020-     	db	"               ", 20h, 20h, 20h
 35335 0000C126 202020202020202020 
 35336                                  free_mem_p_str:  ; 7 digits
 35337 0000C12F 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
 35338 0000C138 616765730D0A       
 35339 0000C13E 0D0A00                  	db	0Dh, 0Ah, 0
 35340                                  
 35341                                  dsk_ready_msg:
 35342 0000C141 0D0A                    	db 	0Dh, 0Ah
 35343                                  dsktype:
 35344 0000C143 6664                    	db	'fd'
 35345                                  dskx:
 35346 0000C145 30                      	db	'0'
 35347 0000C146 20                      	db	20h
 35348 0000C147 697320524541445920-     	db 	'is READY ...'
 35349 0000C150 2E2E2E             
 35350 0000C153 00                      	db 	0
 35351                                  
 35352                                  next2line: ; 08/02/2016
 35353 0000C154 0D0A                    	db	0Dh, 0Ah
 35354                                  nextline:
 35355 0000C156 0D0A00                  	db 	0Dh, 0Ah, 0
 35356                                  
 35357                                  ; KERNEL - SYSINIT Messages
 35358                                  ; 24/08/2015
 35359                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
 35360                                  ; 14/07/2013
 35361                                  ;kernel_init_err_msg:
 35362                                  ;	db 0Dh, 0Ah
 35363                                  ;	db 07h
 35364                                  ;	db 'Kernel initialization ERROR !'
 35365                                  ;	db 0Dh, 0Ah, 0 
 35366                                  
 35367                                  ;welcome_msg: 
 35368                                  ;	db 0Dh, 0Ah
 35369                                  ;	db 07h
 35370                                  ;	db 'Welcome to TRDOS 386 Operating System !'
 35371                                  ;	db 0Dh, 0Ah
 35372                                  ;	db 'by Erdogan Tan - 14/04/2016 (v2.0.0)'
 35373                                  ;	db 0Dh, 0Ah, 0
 35374                                  
 35375                                  panic_msg:
 35376 0000C159 0D0A07                  	db 0Dh, 0Ah, 07h
 35377 0000C15C 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
 35378 0000C165 726E656C2050616E69-
 35379 0000C16E 632021             
 35380 0000C171 0D0A00                  	db 0Dh, 0Ah, 0
 35381                                  
 35382                                  ; 10/05/2015
 35383                                  badsys_msg:
 35384 0000C174 0D0A                    	db 0Dh, 0Ah
 35385 0000C176 07                      	db 07h
 35386 0000C177 496E76616C69642053-     	db 'Invalid System Call !'
 35387 0000C180 797374656D2043616C-
 35388 0000C189 6C2021             
 35389 0000C18C 0D0A                    	db 0Dh, 0Ah
 35390 0000C18E 4541583A20              	db 'EAX: '
 35391                                  bsys_msg_eax:
 35392 0000C193 303030303030303068      	db '00000000h'
 35393 0000C19C 0D0A                    	db 0Dh, 0Ah
 35394 0000C19E 4549503A20              	db 'EIP: '
 35395                                  bsys_msg_eip:
 35396 0000C1A3 303030303030303068      	db '00000000h' 
 35397 0000C1AC 0D0A00                  	db 0Dh, 0Ah, 0
 35398                                  
 35399                                  BSYS_M_SIZE equ $ - badsys_msg
 35400                                  
 35401                                  
 35402 0000C1AF 90                      align 2
 35403                                  
 35404                                  ; EPOCH Variables
 35405                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
 35406                                  ; 09/04/2013 epoch variables
 35407                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
 35408                                  ;
 35409 0000C1B0 B207                    year: 	dw 1970
 35410 0000C1B2 0100                    month: 	dw 1
 35411 0000C1B4 0100                    day: 	dw 1
 35412 0000C1B6 0000                    hour: 	dw 0
 35413 0000C1B8 0000                    minute: dw 0
 35414 0000C1BA 0000                    second: dw 0
 35415                                  
 35416                                  DMonth:
 35417 0000C1BC 0000                    	dw 0
 35418 0000C1BE 1F00                    	dw 31
 35419 0000C1C0 3B00                    	dw 59
 35420 0000C1C2 5A00                    	dw 90
 35421 0000C1C4 7800                    	dw 120
 35422 0000C1C6 9700                    	dw 151
 35423 0000C1C8 B500                    	dw 181
 35424 0000C1CA D400                    	dw 212
 35425 0000C1CC F300                    	dw 243
 35426 0000C1CE 1101                    	dw 273
 35427 0000C1D0 3001                    	dw 304
 35428 0000C1D2 4E01                    	dw 334
 35429                                  
 35430                                  ; 04/11/2014 (Retro UNIX 386 v1)
 35431 0000C1D4 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
 35432                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
 35433 0000C1D6 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
 35434                                  		   ;   between 16 MB and 4 GB.
 35435                                  
 35436                                  starting_msg:
 35437 0000C1D8 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [14/04/2016] ...", 0
 35438 0000C1E1 6174696F6E616C2044-
 35439 0000C1EA 4F532076322E30205B-
 35440 0000C1F3 31342F30342F323031-
 35441 0000C1FC 365D202E2E2E00     
 35442                                  NextLine:
 35443 0000C203 0D0A00                  	db 0Dh, 0Ah, 0
 35444                                  
 35445                                  ;msgl_drv_not_ready: 
 35446                                  ;	db 07h, 0Dh, 0Ah
 35447                                  ;       db 'Drive not ready or read error !'
 35448                                  ;       db 0Dh, 0Ah, 0
 35449                                  
 35450 0000C206 90<rept>                align 16
 35451                                  
 35452                                  bss_start:
 35453                                  
 35454                                  ABSOLUTE bss_start
 35455                                  
 35456                                  	; 11/03/2015
 35457                                  	; Interrupt Descriptor Table (20/08/2014)
 35458                                  idt:
 35459 0000C210 <res 00000200>          	resb	64*8 ; INT 0 to INT 3Fh
 35460                                  idt_end:
 35461                                  
 35462                                  ;alignb 4
 35463                                  
 35464                                  task_state_segment:
 35465                                  	; 24/03/2015
 35466 0000C410 <res 00000002>          tss.link:   resw 1
 35467 0000C412 <res 00000002>          	    resw 1
 35468                                  ; tss offset 4	
 35469 0000C414 <res 00000004>          tss.esp0:   resd 1
 35470 0000C418 <res 00000002>          tss.ss0:    resw 1
 35471 0000C41A <res 00000002>          	    resw 1	
 35472 0000C41C <res 00000004>          tss.esp1:   resd 1
 35473 0000C420 <res 00000002>          tss.ss1:    resw 1
 35474 0000C422 <res 00000002>          	    resw 1 	
 35475 0000C424 <res 00000004>          tss.esp2:   resd 1
 35476 0000C428 <res 00000002>          tss.ss2:    resw 1
 35477 0000C42A <res 00000002>          	    resw 1
 35478                                  ; tss offset 28
 35479 0000C42C <res 00000004>          tss.CR3:    resd 1
 35480 0000C430 <res 00000004>          tss.eip:    resd 1
 35481 0000C434 <res 00000004>          tss.eflags: resd 1
 35482                                  ; tss offset 40
 35483 0000C438 <res 00000004>          tss.eax:    resd 1		 		
 35484 0000C43C <res 00000004>          tss.ecx:    resd 1
 35485 0000C440 <res 00000004>          tss.edx:    resd 1
 35486 0000C444 <res 00000004>          tss.ebx:    resd 1
 35487 0000C448 <res 00000004>          tss.esp:    resd 1
 35488 0000C44C <res 00000004>          tss.ebp:    resd 1
 35489 0000C450 <res 00000004>          tss.esi:    resd 1
 35490 0000C454 <res 00000004>          tss.edi:    resd 1
 35491                                  ; tss offset 72
 35492 0000C458 <res 00000002>          tss.ES:     resw 1
 35493 0000C45A <res 00000002>          	    resw 1	
 35494 0000C45C <res 00000002>          tss.CS:	    resw 1
 35495 0000C45E <res 00000002>          	    resw 1
 35496 0000C460 <res 00000002>          tss.SS:	    resw 1
 35497 0000C462 <res 00000002>          	    resw 1
 35498 0000C464 <res 00000002>          tss.DS:	    resw 1
 35499 0000C466 <res 00000002>          	    resw 1
 35500 0000C468 <res 00000002>          tss.FS:	    resw 1
 35501 0000C46A <res 00000002>          	    resw 1
 35502 0000C46C <res 00000002>          tss.GS:	    resw 1
 35503 0000C46E <res 00000002>          	    resw 1		
 35504 0000C470 <res 00000002>          tss.LDTR:   resw 1
 35505 0000C472 <res 00000002>          	    resw 1
 35506                                  ; tss offset 100		
 35507 0000C474 <res 00000002>          	    resw 1		
 35508 0000C476 <res 00000002>          tss.IOPB:   resw 1
 35509                                  ; tss offset 104 
 35510                                  tss_end:
 35511                                  
 35512 0000C478 <res 00000004>          k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
 35513                                  		    ; (Physical address = Virtual address)	 	
 35514 0000C47C <res 00000004>          memory_size: resd 1 ; memory size in pages
 35515 0000C480 <res 00000004>          free_pages:  resd 1 ; number of free pages		
 35516 0000C484 <res 00000004>          next_page:   resd 1 ; offset value in M.A.T. for
 35517                                  		    ; first free page search
 35518 0000C488 <res 00000004>          last_page:   resd 1 ; offset value in M.A.T. which
 35519                                  		    ; next free page search will be
 35520                                  		    ; stopped after it. (end of M.A.T.)
 35521 0000C48C <res 00000004>          first_page:  resd 1 ; offset value in M.A.T. which
 35522                                  		    ; first free page search
 35523                                  		    ; will be started on it. (for user)
 35524 0000C490 <res 00000004>          mat_size:    resd 1 ; Memory Allocation Table size in pages		
 35525                                  
 35526                                  ; 02/09/2014 (Retro UNIX 386 v1)
 35527                                  ; 04/12/2013 (Retro UNIX 8086 v1)
 35528 0000C494 <res 00000002>          CRT_START:   resw 1 	  ; starting address in regen buffer
 35529                                  			  ; NOTE: active page only	
 35530 0000C496 <res 00000002>          CURSOR_MODE: resw 1 ; 24/01/2016
 35531 0000C498 <res 00000010>          CURSOR_POSN: resw 8 ; cursor positions for video pages
 35532                                  ACTIVE_PAGE: 
 35533 0000C4A8 <res 00000001>          ptty: 	     resb 1 ; current tty
 35534                                  ; 01/07/2015 - 29/01/2016
 35535 0000C4A9 <res 00000001>          ccolor:	     resb 1 ; current color attribute
 35536                                  ; 26/10/2015
 35537                                  ; 07/09/2014
 35538 0000C4AA <res 00000014>          ttychr:      resw ntty+2 ; Character buffer (multiscreen)
 35539                                  
 35540                                  ; 21/08/2014
 35541 0000C4BE <res 00000004>          tcount:	     resd 1
 35542                                  
 35543                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
 35544 0000C4C2 <res 00000004>          p_time:      resd 1     ; present time (for systime & sysmdate)
 35545                                  
 35546                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
 35547                                  ; (open mode locks for pseudo TTYs)
 35548                                  ; [ major tty locks (return error in any conflicts) ]
 35549 0000C4C6 <res 00000014>          ttyl:        resw ntty+2 ; opening locks for TTYs.
 35550                                  
 35551                                  ; 15/04/2015 (Retro UNIX 386 v1)
 35552                                  ; 22/09/2013 (Retro UNIX 8086 v1)
 35553 0000C4DA <res 0000000A>          wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
 35554                                  ; 15/04/2015 (Retro UNIX 386 v1)
 35555                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
 35556                                  ;; 0 means serial port is not available 
 35557                                  ;;comprm: ; 25/06/2014
 35558 0000C4E4 <res 00000001>          com1p:       resb 1  ;;0E3h
 35559 0000C4E5 <res 00000001>          com2p:       resb 1  ;;0E3h
 35560                                  
 35561                                  ; 17/11/2015
 35562                                  ; request for response (from the terminal)	
 35563 0000C4E6 <res 00000002>          req_resp:    resw 1 			
 35564                                  ; 07/11/2015
 35565 0000C4E8 <res 00000001>          ccomport:    resb 1 ; current COM (serial) port
 35566                                  		    ; (0= COM1, 1= COM2)
 35567                                  ; 09/11/2015
 35568 0000C4E9 <res 00000001>          comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
 35569                                  ; 07/11/2015
 35570 0000C4EA <res 00000002>          rchar:	     resw 1 ; last received char for COM 1 and COM 2		
 35571 0000C4EC <res 00000002>          schar:	     resw 1 ; last sent char for COM 1 and COM 2
 35572                                  
 35573                                  ; 22/08/2014 (RTC)
 35574                                  ; (Packed BCD)
 35575 0000C4EE <res 00000001>          time_seconds: resb 1
 35576 0000C4EF <res 00000001>          time_minutes: resb 1
 35577 0000C4F0 <res 00000001>          time_hours:   resb 1
 35578 0000C4F1 <res 00000001>          date_wday:    resb 1
 35579 0000C4F2 <res 00000001>          date_day:     resb 1
 35580 0000C4F3 <res 00000001>          date_month:   resb 1			
 35581 0000C4F4 <res 00000001>          date_year:    resb 1
 35582 0000C4F5 <res 00000001>          date_century: resb 1
 35583                                  
 35584                                  ; 24/01/2016
 35585 0000C4F6 <res 00000004>          RTC_LH:	       resd 1
 35586 0000C4FA <res 00000001>          RTC_WAIT_FLAG: resb 1
 35587 0000C4FB <res 00000001>          USER_FLAG:     resb 1
 35588                                  
 35589                                  
 35590                                  %include 'diskbss.s'	; UNINITIALIZED DISK (BIOS) DATA
 35591                              <1> ; ****************************************************************************
 35592                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskbss.s
 35593                              <1> ; ----------------------------------------------------------------------------
 35594                              <1> ; Last Update: 24/01/2016
 35595                              <1> ; ----------------------------------------------------------------------------
 35596                              <1> ; Beginning: 24/01/2016
 35597                              <1> ; ----------------------------------------------------------------------------
 35598                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 35599                              <1> ; ----------------------------------------------------------------------------
 35600                              <1> ; Turkish Rational DOS
 35601                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 35602                              <1> ;
 35603                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 35604                              <1> ; diskbss.inc (10/07/2015)
 35605                              <1> ;
 35606                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 35607                              <1> ; ****************************************************************************
 35608                              <1> 
 35609                              <1> ; Retro UNIX 386 v1 Kernel - DISKBSS.INC
 35610                              <1> ; Last Modification: 10/07/2015
 35611                              <1> ;	(Unnitialized Disk Parameters Data section for 'DISKIO.INC') 
 35612                              <1> 
 35613                              <1> alignb 2
 35614                              <1> 
 35615                              <1> ;----------------------------------------
 35616                              <1> ;	TIMER DATA AREA 		:
 35617                              <1> ;----------------------------------------
 35618                              <1> 
 35619                              <1> TIMER_LH:	; 16/02/205
 35620 0000C4FC <res 00000002>      <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
 35621 0000C4FE <res 00000002>      <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
 35622 0000C500 <res 00000001>      <1> TIMER_OFL:      resb 	1               ; TIMER HAS ROLLED OVER SINCE LAST READ
 35623                              <1> 
 35624                              <1> ;----------------------------------------
 35625                              <1> ;	DISKETTE DATA AREAS		:
 35626                              <1> ;----------------------------------------
 35627                              <1> 
 35628 0000C501 <res 00000001>      <1> SEEK_STATUS:	resb	1
 35629 0000C502 <res 00000001>      <1> MOTOR_STATUS:	resb	1
 35630 0000C503 <res 00000001>      <1> MOTOR_COUNT:	resb	1
 35631 0000C504 <res 00000001>      <1> DSKETTE_STATUS:	resb	1
 35632 0000C505 <res 00000007>      <1> NEC_STATUS:	resb	7
 35633                              <1> 
 35634                              <1> ;----------------------------------------
 35635                              <1> ;	ADDITIONAL MEDIA DATA		:
 35636                              <1> ;----------------------------------------
 35637                              <1> 
 35638 0000C50C <res 00000001>      <1> LASTRATE:	resb 	1
 35639 0000C50D <res 00000001>      <1> HF_STATUS:	resb 	1
 35640 0000C50E <res 00000001>      <1> HF_ERROR:	resb 	1
 35641 0000C50F <res 00000001>      <1> HF_INT_FLAG:	resb 	1
 35642 0000C510 <res 00000001>      <1> HF_CNTRL:	resb 	1
 35643 0000C511 <res 00000004>      <1> DSK_STATE:	resb 	4
 35644 0000C515 <res 00000002>      <1> DSK_TRK:	resb 	2
 35645                              <1> 
 35646                              <1> ;----------------------------------------
 35647                              <1> ;	FIXED DISK DATA AREAS		:
 35648                              <1> ;----------------------------------------
 35649                              <1> 
 35650 0000C517 <res 00000001>      <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
 35651 0000C518 <res 00000001>      <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
 35652 0000C519 <res 00000001>      <1> CONTROL_BYTE:	resb 	1		; HEAD CONTROL BYTE
 35653                              <1> ;@PORT_OFF	resb	1		; RESERVED (PORT OFFSET)
 35654                              <1> ;port1_off	resb	1		; Hard disk controller 1 - port offset
 35655                              <1> ;port2_off	resb	1		; Hard idsk controller 2 - port offset
 35656                              <1> 
 35657 0000C51A <res 00000002>      <1> alignb 4
 35658                              <1> 
 35659                              <1> ;HF_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 35660                              <1> ;HF1_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 35661                              <1> HF_TBL_VEC: ; 22/12/2014	
 35662 0000C51C <res 00000004>      <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 35663 0000C520 <res 00000004>      <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 35664 0000C524 <res 00000004>      <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
 35665 0000C528 <res 00000004>      <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
 35666                              <1> 
 35667                              <1> ; 03/01/2015
 35668 0000C52C <res 00000001>      <1> LBAMode:     	resb	1
 35669                              <1> 
 35670                              <1> ; *****************************************************************************
 35671                                  
 35672                                  ;;; Real Mode Data (10/07/2015 - BSS)
 35673                                  
 35674                                  ;alignb 2
 35675                                  
 35676                                  ; 10/01/2016
 35677                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
 35678                              <1> ; ****************************************************************************
 35679                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED DATA : trdoskx.s
 35680                              <1> ; ----------------------------------------------------------------------------
 35681                              <1> ; Last Update: 14/04/2016
 35682                              <1> ; ----------------------------------------------------------------------------
 35683                              <1> ; Beginning: 04/01/2016
 35684                              <1> ; ----------------------------------------------------------------------------
 35685                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 35686                              <1> ; ----------------------------------------------------------------------------
 35687                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 35688                              <1> ; TRDOS2.ASM (09/11/2011)
 35689                              <1> ; ****************************************************************************
 35690                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 35691                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 35692                              <1> ; DIR.ASM      [17/01/2004] Last Update: 09/10/2011
 35693                              <1> ; CMD_INTR.ASM [29/01/2005] Last update: 09/11/2011
 35694                              <1> ; DRV_FAT.ASM  [07/07/2009] Last update: 21/08/2011
 35695                              <1> 
 35696 0000C52D <res 00000003>      <1> alignb 4
 35697                              <1> 
 35698                              <1> ; MAINPROG.ASM
 35699 0000C530 <res 00000004>      <1> MainProgCfg_FileSize:   resd 1 ; 14/04/2016
 35700 0000C534 <res 00000004>      <1> MainProgCfg_LineOffset: resd 1 ; 14/04/2016
 35701                              <1> 
 35702 0000C538 <res 00000004>      <1> Current_VolSerial: resd 1
 35703                              <1> 
 35704 0000C53C <res 00000004>      <1> Current_Dir_FCluster: resd 1
 35705                              <1> 
 35706 0000C540 <res 00000001>      <1> Current_Dir_Level: resb 1
 35707 0000C541 <res 00000001>      <1> Current_FATType: resb 1
 35708 0000C542 <res 00000001>      <1> Current_Drv: resb 1
 35709 0000C543 <res 00000001>      <1> Current_Dir_Drv:   resb 1 ; '?'
 35710 0000C544 <res 00000001>      <1>                    resb 1 ; ':'
 35711 0000C545 <res 00000001>      <1> Current_Dir_Root:  resb 1 ; '/' 
 35712 0000C546 <res 0000005A>      <1> Current_Directory: resb 90
 35713 0000C5A0 <res 00000001>      <1> End_Of_Current_Dir_Str: resb 1
 35714 0000C5A1 <res 00000001>      <1> Current_Dir_StrLen: resb 1   
 35715                              <1> 
 35716 0000C5A2 <res 00000001>      <1> CursorColumn: 	resb 1
 35717 0000C5A3 <res 00000001>      <1> CmdArgStart:    resb 1
 35718                              <1> 
 35719                              <1> Remark: ; 03/02/2016
 35720 0000C5A4 <res 0000004E>      <1> 		resb 78
 35721                              <1> 
 35722 0000C5F2 <res 00000050>      <1> CommandBuffer: 	resb 80
 35723                              <1> 
 35724 0000C642 <res 00000100>      <1> TextBuffer: resb 256
 35725                              <1> 
 35726                              <1> MasterBootBuff:
 35727 0000C742 <res 000001BE>      <1> MasterBootCode: resb 1BEh
 35728 0000C900 <res 00000040>      <1> PartitionTable: resb 64
 35729 0000C940 <res 00000002>      <1> MBIDCode: resw 1
 35730                              <1> 
 35731                              <1> PTable_Buffer:
 35732 0000C942 <res 00000040>      <1> PTable_hd0: resb 64
 35733 0000C982 <res 00000040>      <1> PTable_hd1: resb 64
 35734 0000C9C2 <res 00000040>      <1> PTable_hd2: resb 64
 35735 0000CA02 <res 00000040>      <1> PTable_hd3: resb 64
 35736 0000CA42 <res 00000040>      <1> PTable_ep0: resb 64
 35737 0000CA82 <res 00000040>      <1> PTable_ep1: resb 64
 35738 0000CAC2 <res 00000040>      <1> PTable_ep2: resb 64
 35739 0000CB02 <res 00000040>      <1> PTable_ep3: resb 64
 35740                              <1> 
 35741 0000CB42 <res 00000001>      <1> HD_LBA_yes: resb 1
 35742 0000CB43 <res 00000001>      <1> PP_Counter: resb 1
 35743 0000CB44 <res 00000001>      <1> EP_Counter: resb 1
 35744                              <1> 
 35745 0000CB45 <res 00000004>      <1> EP_StartSector: resd 1
 35746 0000CB49 <res 00000004>      <1>                 resd 1
 35747 0000CB4D <res 00000004>      <1>                 resd 1
 35748 0000CB51 <res 00000004>      <1>                 resd 1
 35749                              <1> 
 35750 0000CB55 <res 00000200>      <1> DOSBootSectorBuff: resb 512
 35751                              <1> 
 35752                              <1> FAT_BuffDescriptor:
 35753 0000CD55 <res 00000004>      <1> FAT_CurrentCluster: resd 1
 35754 0000CD59 <res 00000001>      <1> FAT_BuffValidData: resb 1
 35755 0000CD5A <res 00000001>      <1> FAT_BuffDrvName: resb 1
 35756 0000CD5B <res 00000002>      <1> FAT_BuffOffset: resw 1
 35757 0000CD5D <res 00000004>      <1> FAT_BuffSector: resd 1
 35758                              <1> 
 35759 0000CD61 <res 00000004>      <1> FAT_ClusterCounter: resd 1
 35760 0000CD65 <res 00000004>      <1> LastCluster: resd 1
 35761                              <1> 
 35762                              <1> ; 18/03/2016 (TRDOS v2.0)
 35763 0000CD69 <res 00000001>      <1> ClusterBuffer_Valid: resb 1
 35764                              <1> 
 35765                              <1> Dir_BuffDescriptor:
 35766 0000CD6A <res 00000001>      <1> DirBuff_DRV: resb 1
 35767 0000CD6B <res 00000001>      <1> DirBuff_FATType: resb 1
 35768 0000CD6C <res 00000001>      <1> DirBuff_ValidData: resb 1
 35769 0000CD6D <res 00000002>      <1> DirBuff_CurrentEntry: resw 1
 35770 0000CD6F <res 00000002>      <1> DirBuff_LastEntry: resw 1
 35771 0000CD71 <res 00000004>      <1> DirBuff_Cluster: resd 1 
 35772 0000CD75 <res 00000002>      <1> DirBuffer_Size: resw 1
 35773                              <1> ;DirBuff_EntryCounter: resw 1
 35774                              <1> 
 35775                              <1> ; 01/02/2016
 35776                              <1> ; these are on (real mode) segment 8000h and later
 35777                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
 35778                              <1> ; Dir_Buffer:	resb 512*32
 35779                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
 35780                              <1> 
 35781                              <1> ; 18/01/2016
 35782                              <1> 
 35783 0000CD77 <res 00000004>      <1> FreeClusterCount: resd 1
 35784                              <1> 
 35785 0000CD7B <res 00000004>      <1> VolSize_Unit1:   resd 1
 35786 0000CD7F <res 00000004>      <1> VolSize_Unit2:   resd 1
 35787                              <1> 
 35788 0000CD83 <res 00000004>      <1> Vol_Tot_Sec_Str_Start:	    resd 1
 35789 0000CD87 <res 0000000A>      <1> Vol_Tot_Sec_Str: 	    resb 10
 35790 0000CD91 <res 00000001>      <1> Vol_Tot_Sec_Str_End:	    resb 1
 35791 0000CD92 <res 00000001>      <1> resb 1
 35792 0000CD93 <res 00000004>      <1> Vol_Free_Sectors_Str_Start: resd 1
 35793 0000CD97 <res 0000000A>      <1> Vol_Free_Sectors_Str:	    resb 10				
 35794 0000CDA1 <res 00000001>      <1> Vol_Free_Sectors_Str_End:   resb 1
 35795                              <1> 
 35796                              <1> ; 10/02/2016
 35797 0000CDA2 <res 00000001>      <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 35798                              <1> 
 35799                              <1> ; 24/01/2016
 35800 0000CDA3 <res 00000080>      <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
 35801                              <1> ; 06/02/2016
 35802 0000CE23 <res 00000004>      <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
 35803 0000CE27 <res 00000001>      <1> CCD_Level:	resb 1 ; DIR.ASM
 35804 0000CE28 <res 00000001>      <1> Last_Dir_Level:	resb 1 ; DIR.ASM
 35805                              <1> ;
 35806 0000CE29 <res 00000002>      <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
 35807 0000CE2B <res 00000004>      <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
 35808 0000CE2F <res 00000002>      <1> CDLF_DEType:	resw 1 ; DIR.ASM
 35809                              <1> ;
 35810 0000CE31 <res 00000001>      <1> CD_COMMAND:	resb 1 ; DIR.ASM
 35811                              <1> 
 35812 0000CE32 <res 00000002>      <1> alignb 4
 35813                              <1> 
 35814                              <1> ; 29/01/2016
 35815 0000CE34 <res 00000001>      <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 35816                              <1> 
 35817                              <1> ;alignb 4
 35818                              <1> ; 23/02/2016
 35819 0000CE35 <res 00000001>      <1> disk_rw_op:	resb 1 ;  0 = disk read, 1 = disk write
 35820                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
 35821                              <1> ; 31/01/2016
 35822 0000CE36 <res 00000001>      <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
 35823 0000CE37 <res 00000001>      <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
 35824 0000CE38 <res 00000004>      <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
 35825                              <1> 
 35826                              <1> ; 06/02/2016 (long name)
 35827 0000CE3C <res 00000002>      <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
 35828 0000CE3E <res 00000002>      <1> AmbiguousFileName: resw 1 ; DIR.ASM
 35829 0000CE40 <res 00000001>      <1> PreviousAttr:	   resb 1 ; DIR.ASM
 35830                              <1> ;	
 35831 0000CE41 <res 00000001>      <1> LongNameFound:   resb 1	  ; DIR.ASM
 35832 0000CE42 <res 00000001>      <1> LFN_EntryLength: resb 1   ; DIR.ASM
 35833 0000CE43 <res 00000001>      <1> LFN_CheckSum:    resb 1   ; DIR.ASM
 35834 0000CE44 <res 00000084>      <1> LongFileName:    resb 132 ; DIR.ASM
 35835                              <1> 
 35836                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
 35837 0000CEC8 <res 00000001>      <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
 35838 0000CEC9 <res 00000001>      <1> PATH_Level:	 resb 1 ; DIR.ASM
 35839                              <1> 
 35840                              <1> ; 07/02/2016
 35841 0000CECA <res 0000000D>      <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
 35842                              <1> 
 35843                              <1> ; 10/02/2016
 35844                              <1> Dir_Entry_Name:
 35845 0000CED7 <res 0000000D>      <1> 		resb 13 ; DIR.ASM
 35846                              <1> 
 35847                              <1> alignb 2
 35848                              <1> 
 35849 0000CEE4 <res 00000002>      <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
 35850                              <1> 
 35851                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
 35852                              <1> ; 08/02/2016
 35853                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
 35854 0000CEE6 <res 00000001>      <1> FindFile_Drv:		  resb 1
 35855 0000CEE7 <res 00000041>      <1> FindFile_Directory:	  resb 65
 35856 0000CF28 <res 0000000D>      <1> FindFile_Name:		  resb 13
 35857                              <1> FindFile_LongNameEntryLength:
 35858 0000CF35 <res 00000001>      <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
 35859                              <1> ;Above 80 bytes form
 35860                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
 35861 0000CF36 <res 00000002>      <1> FindFile_AttributesMask:  resw 1
 35862 0000CF38 <res 00000020>      <1> FindFile_DirEntry:	  resb 32
 35863 0000CF58 <res 00000004>      <1> FindFile_DirFirstCluster: resd 1
 35864 0000CF5C <res 00000004>      <1> FindFile_DirCluster:	  resd 1
 35865 0000CF60 <res 00000002>      <1> FindFile_DirEntryNumber:  resw 1
 35866 0000CF62 <res 00000002>      <1> FindFile_MatchCounter:	  resw 1
 35867 0000CF64 <res 00000002>      <1> FindFile_Reserved:	  resw 1 ; 06/03/2016
 35868                              <1> 
 35869 0000CF66 <res 00000004>      <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
 35870 0000CF6A <res 00000004>      <1> Last_Slash_Pos: resd 1	; DIR.ASM 
 35871                              <1> 
 35872                              <1> ; 10/02/2016
 35873 0000CF6E <res 00000002>      <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
 35874 0000CF70 <res 00000002>      <1> Dir_Count:      resw 1
 35875 0000CF72 <res 00000004>      <1> Total_FSize:    resd 1
 35876 0000CF76 <res 00000004>      <1> TFS_Dec_Begin:  resd 1
 35877 0000CF7A <res 0000000A>      <1>                 resb 10
 35878 0000CF84 <res 00000001>      <1> TFS_Dec_End:    resb 1
 35879                              <1> 
 35880 0000CF85 <res 00000001>      <1> PrintDir_RowCounter: resb 1
 35881                              <1> 
 35882 0000CF86 <res 00000002>      <1> alignb 4
 35883                              <1> ; 15/02/2015 ('show' command variables)
 35884 0000CF88 <res 00000004>      <1> Show_FDT:	resd 1
 35885 0000CF8C <res 00000004>      <1> Show_LDDDT:	resd 1
 35886 0000CF90 <res 00000004>      <1> Show_Cluster:	resd 1
 35887 0000CF94 <res 00000004>      <1> Show_FileSize:	resd 1
 35888 0000CF98 <res 00000004>      <1> Show_FilePointer: resd 1
 35889 0000CF9C <res 00000002>      <1> Show_ClusterPointer: resw 1
 35890 0000CF9E <res 00000002>      <1> Show_ClusterSize: resw 1
 35891 0000CFA0 <res 00000001>      <1> Show_RowCount:	resb 1
 35892                              <1> 
 35893 0000CFA1 <res 00000003>      <1> alignb 4
 35894                              <1> ; 21/02/2016
 35895 0000CFA4 <res 00000004>      <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
 35896                              <1> ; 27/02/2016
 35897                              <1> ; DIR.ASM (09/10/2011)
 35898 0000CFA8 <res 00000004>      <1> DelFile_FCluster:	resd 1
 35899 0000CFAC <res 00000002>      <1> DelFile_EntryCounter:	resw 1
 35900 0000CFAE <res 00000001>      <1> DelFile_LNEL:		resb 1
 35901 0000CFAF <res 00000001>      <1> resb 1
 35902                              <1> 
 35903                              <1> ; DIR.ASM
 35904 0000CFB0 <res 00000004>      <1> mkdir_DirName_Offset: 	resd 1
 35905 0000CFB4 <res 00000004>      <1> mkdir_FFCluster:	resd 1
 35906 0000CFB8 <res 00000004>      <1> mkdir_LastDirCluster:	resd 1
 35907 0000CFBC <res 00000004>      <1> mkdir_FreeSectors:	resd 1
 35908 0000CFC0 <res 00000002>      <1> mkdir_attrib:		resw 1 
 35909 0000CFC2 <res 00000001>      <1> mkdir_SecPerClust:	resb 1
 35910 0000CFC3 <res 00000001>      <1> mkdir_add_new_cluster:	resb 1
 35911 0000CFC4 <res 0000000D>      <1> mkdir_Name:		resb 13
 35912 0000CFD1 <res 00000002>      <1> resw 1 ; 01/03/2016
 35913                              <1> ; 27/02/2016
 35914 0000CFD3 <res 00000001>      <1> RmDir_MultiClusters:	resb 1  
 35915 0000CFD4 <res 00000004>      <1> RmDir_DirEntryOffset:	resd 1 ; 01/03/2016 (word -> dword)
 35916 0000CFD8 <res 00000004>      <1> RmDir_ParentDirCluster: resd 1
 35917 0000CFDC <res 00000004>      <1> RmDir_DirLastCluster:   resd 1
 35918 0000CFE0 <res 00000004>      <1> RmDir_PreviousCluster:  resd 1
 35919                              <1> ; 22/02/2016
 35920 0000CFE4 <res 00000001>      <1> UPDLMDT_CDirLevel:	resb 1
 35921 0000CFE5 <res 00000004>      <1> UPDLMDT_CDirFCluster:	resd 1
 35922                              <1> 	
 35923 0000CFE9 <res 00000003>      <1> alignb 4
 35924                              <1> ; DRV_FAT.ASM ; 21/08/2011
 35925 0000CFEC <res 00000004>      <1> gffc_next_free_cluster:  resd 1
 35926 0000CFF0 <res 00000004>      <1> gffc_first_free_cluster: resd 1
 35927 0000CFF4 <res 00000004>      <1> gffc_last_free_cluster:  resd 1
 35928                              <1> 
 35929                              <1> ; 22/02/2016
 35930 0000CFF8 <res 00000004>      <1> ClusterValue:	resd 1
 35931                              <1> ; 04/03/2016
 35932 0000CFFC <res 00000001>      <1> Attributes:	resb 1 
 35933                              <1> ;;CFS_error:  resb 1 ;; 01/03/2016
 35934 0000CFFD <res 00000001>      <1> resb 1
 35935 0000CFFE <res 00000001>      <1> CFS_OPType: resb 1
 35936 0000CFFF <res 00000001>      <1> CFS_Drv:    resb 1
 35937 0000D000 <res 00000004>      <1> CFS_CC:	    resd 1
 35938 0000D004 <res 00000004>      <1> CFS_FAT32FSINFOSEC: resd 1
 35939 0000D008 <res 00000004>      <1> CFS_FAT32FC: resd 1
 35940                              <1> 
 35941                              <1> ; 27/02/2016
 35942                              <1> ;alignb 4
 35943 0000D00C <res 00000004>      <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
 35944                              <1> 
 35945                              <1> ; DIR.ASM
 35946 0000D010 <res 00000002>      <1> DLN_EntryNumber: resw 1
 35947 0000D012 <res 00000001>      <1> DLN_40h:	 resb 1
 35948                              <1> ; 28/02/2016
 35949 0000D013 <res 00000001>      <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
 35950                              <1> 
 35951                              <1> alignb 4
 35952                              <1> ; DIR.ASM (09/10/2011)
 35953 0000D014 <res 00000002>      <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
 35954 0000D016 <res 00000002>      <1> LCDE_ClusterSN:  resw 1
 35955 0000D018 <res 00000004>      <1> LCDE_Cluster: 	 resd 1
 35956 0000D01C <res 00000004>      <1> LCDE_ByteOffset: resd 1
 35957                              <1> 
 35958                              <1> ;alignb4
 35959                              <1> ; 06/03/2016 (word -> dword)
 35960                              <1> ; CMD_INTR.ASM (01/08/2010)
 35961 0000D020 <res 00000004>      <1> SourceFilePath:	     resd 1
 35962 0000D024 <res 00000004>      <1> DestinationFilePath: resd 1
 35963                              <1> 
 35964                              <1> ;alignb 4
 35965                              <1> ; 06/03/2016
 35966                              <1> ; FILE.ASM (09/10/2011)
 35967                              <1> ;Source File Structure (same with 'Find File' Structure)
 35968 0000D028 <res 00000001>      <1> SourceFile_Drv:			resb 1
 35969 0000D029 <res 00000041>      <1> SourceFile_Directory:		resb 65
 35970 0000D06A <res 0000000D>      <1> SourceFile_Name:		resb 13
 35971                              <1> SourceFile_LongNameEntryLength: 
 35972 0000D077 <res 00000001>      <1> SourceFile_LongNameYes:		resb 1 ; Sign for longname procedures
 35973                              <1> ;Above 80 bytes
 35974                              <1> ;is TR-DOS Source File FullName Format/Structure
 35975 0000D078 <res 00000002>      <1> SourceFile_AttributesMask:	resw 1
 35976 0000D07A <res 00000020>      <1> SourceFile_DirEntry:		resb 32
 35977 0000D09A <res 00000004>      <1> SourceFile_DirFirstCluster:	resd 1
 35978 0000D09E <res 00000004>      <1> SourceFile_DirCluster:		resd 1
 35979 0000D0A2 <res 00000002>      <1> SourceFile_DirEntryNumber:	resw 1
 35980 0000D0A4 <res 00000002>      <1> SourceFile_MatchCounter:	resw 1
 35981                              <1> ; 16/03/2016
 35982 0000D0A6 <res 00000001>      <1> SourceFile_SecPerClust:		resb 1
 35983 0000D0A7 <res 00000001>      <1> SourceFile_Reserved:		resb 1
 35984                              <1> ; Above is 128 bytes
 35985                              <1> 
 35986                              <1> ;Destination File Structure (same with 'Find File' Structure)
 35987 0000D0A8 <res 00000001>      <1> DestinationFile_Drv:		resb 1
 35988 0000D0A9 <res 00000041>      <1> DestinationFile_Directory: 	resb 65
 35989 0000D0EA <res 0000000D>      <1> DestinationFile_Name:		resb 13
 35990                              <1> DestinationFile_LongNameEntryLength:
 35991 0000D0F7 <res 00000001>      <1> DestinationFile_LongNameYes:	resb 1 ; Sign for longname procedures
 35992                              <1> ;Above 80 bytes
 35993                              <1> ;is TR-DOS Destination File FullName Format/Structure
 35994 0000D0F8 <res 00000002>      <1> DestinationFile_AttributesMask: resw 1
 35995 0000D0FA <res 00000020>      <1> DestinationFile_DirEntry:	resb 32
 35996 0000D11A <res 00000004>      <1> DestinationFile_DirFirstCluster: resd 1
 35997 0000D11E <res 00000004>      <1> DestinationFile_DirCluster:	resd 1
 35998 0000D122 <res 00000002>      <1> DestinationFile_DirEntryNumber: resw 1
 35999 0000D124 <res 00000002>      <1> DestinationFile_MatchCounter:	resw 1
 36000                              <1> ; 16/03/2016
 36001 0000D126 <res 00000001>      <1> DestinationFile_SecPerClust:	resb 1
 36002 0000D127 <res 00000001>      <1> DestinationFile_Reserved:	resb 1
 36003                              <1> ; Above is 128 bytes
 36004                              <1> 
 36005                              <1> ; 10/03/2016
 36006                              <1> ; FILE.ASM
 36007 0000D128 <res 00000001>      <1> move_cmd_phase:	   resb 1
 36008 0000D129 <res 00000001>      <1> msftdf_sf_df_drv:  resb 1
 36009 0000D12A <res 00000004>      <1> msftdf_drv_offset: resd 1
 36010                              <1> 
 36011                              <1> ; 11/03/2016
 36012                              <1> ; DRV_FAT.ASM (21/08/2011)
 36013 0000D12E <res 00000004>      <1> FAT_anc_LCluster:  resd 1
 36014 0000D132 <res 00000004>      <1> FAT_anc_FFCluster: resd 1
 36015                              <1> 
 36016                              <1> ;alignb 4
 36017                              <1> 
 36018                              <1> ; 14/03/2016
 36019                              <1> ; TRDOS 386 = TRDOS v2.0 feature only !
 36020                              <1> ; 'allocate_memory_block' in 'memory.s'
 36021 0000D136 <res 00000004>      <1> mem_ipg_count:	resd 1 ; page count (for contiguous allocation)
 36022 0000D13A <res 00000004>      <1> mem_pg_count:	resd 1 ; page count (for count down)
 36023 0000D13E <res 00000004>      <1> mem_aperture:	resd 1 ; contiguous free pages (current)
 36024 0000D142 <res 00000004>      <1> mem_max_aperture: resd 1 ; maximum value of contiguous free pages
 36025 0000D146 <res 00000004>      <1> mem_pg_pos:	resd 1 ; mem. position (page #) of current aperture
 36026 0000D14A <res 00000004>      <1> mem_max_pg_pos: resd 1 ; mem. position (page #) of max. aperture
 36027                              <1> 
 36028                              <1> ; 15/03/2016
 36029                              <1> ; FILE.ASM ('copy_source_file_to_destination_file')
 36030 0000D14E <res 00000001>      <1> copy_cmd_phase:       resb 1
 36031 0000D14F <res 00000001>      <1> csftdf_rw_err:	      resb 1
 36032 0000D150 <res 00000001>      <1> DestinationFileFound: resb 1
 36033 0000D151 <res 00000001>      <1> csftdf_cdrv: 	      resb 1
 36034 0000D152 <res 00000004>      <1> csftdf_filesize:      resd 1
 36035                              <1> ; TRDOS386 (TRDOS v2.0)
 36036 0000D156 <res 00000004>      <1> csftdf_sf_mem_addr:   resd 1
 36037 0000D15A <res 00000004>      <1> csftdf_sf_mem_bsize:  resd 1
 36038                              <1> ;
 36039                              <1> 
 36040 0000D15E <res 00000004>      <1> csftdf_sf_cluster:    resd 1 ; 16/03/2016
 36041 0000D162 <res 00000004>      <1> csftdf_df_cluster:    resd 1
 36042                              <1> ; 16/03/2016
 36043 0000D166 <res 00000004>      <1> csftdf_r_size:        resd 1
 36044 0000D16A <res 00000004>      <1> csftdf_w_size:        resd 1
 36045 0000D16E <res 00000004>      <1> csftdf_sf_rbytes:     resd 1
 36046 0000D172 <res 00000004>      <1> csftdf_df_wbytes:     resd 1
 36047 0000D176 <res 00000001>      <1> csftdf_percentage:    resb 1
 36048                              <1> ; 17/03/2016
 36049 0000D177 <res 00000001>      <1> csftdf_videopage:     resb 1
 36050 0000D178 <res 00000002>      <1> csftdf_cursorpos:     resw 1
 36051 0000D17A <res 00000004>      <1> csftdf_sf_drv_dt:     resd 1
 36052 0000D17E <res 00000004>      <1> csftdf_df_drv_dt:     resd 1
 36053                              <1> 
 36054                              <1> ; 21/03/2016
 36055                              <1> ; 20/03/2016
 36056                              <1> ; FILE.ASM
 36057 0000D182 <res 00000004>      <1> createfile_Name_Offset:  resd 1
 36058 0000D186 <res 00000004>      <1> createfile_FreeSectors:  resd 1 
 36059 0000D18A <res 00000004>      <1> createfile_size:         resd 1
 36060 0000D18E <res 00000004>      <1> createfile_FFCluster:    resd 1 ; 11/03/2016
 36061 0000D192 <res 00000004>      <1> createfile_LastDirCluster: resd 1
 36062 0000D196 <res 00000004>      <1> createfile_Cluster:      resd 1
 36063 0000D19A <res 00000004>      <1> createfile_PCluster:     resd 1
 36064 0000D19E <res 00000001>      <1> createfile_attrib:	 resb 1
 36065 0000D19F <res 00000001>      <1> createfile_SecPerClust:  resb 1
 36066 0000D1A0 <res 00000002>      <1> createfile_DirIndex:     resw 1
 36067 0000D1A2 <res 00000004>      <1> createfile_CCount:	 resd 1
 36068 0000D1A6 <res 00000002>      <1> createfile_BytesPerSec:	 resw 1 ; 23/03/2016
 36069 0000D1A8 <res 00000001>      <1> createfile_wfc:	         resb 1
 36070 0000D1A9 <res 00000001>      <1> createfile_UpdatePDir:	 resb 1 ; 31/03/2016
 36071                              <1> 
 36072                              <1> ;alignb 4
 36073                              <1> 
 36074                              <1> ; 11/04/2016
 36075 0000D1AA <res 00000002>      <1> env_var_length:	   resw 1
 36076                              <1> 
 36077                              <1> ;alignb 4 
 36078                                  ; 24/01/2016
 36079                                  %include 'ubss.s'	; UNINITIALIZED KERNEL (USER) DATA
 36080                              <1> ; ****************************************************************************
 36081                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED USER DATA : ubss.s
 36082                              <1> ; ----------------------------------------------------------------------------
 36083                              <1> ; Last Update: 24/01/2016
 36084                              <1> ; ----------------------------------------------------------------------------
 36085                              <1> ; Beginning: 24/01/2016
 36086                              <1> ; ----------------------------------------------------------------------------
 36087                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 36088                              <1> ; ----------------------------------------------------------------------------
 36089                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 36090                              <1> ; ux.s (04/12/2015)
 36091                              <1> ; ****************************************************************************
 36092                              <1> 
 36093                              <1> ; Retro UNIX 386 v1 Kernel - ux.s
 36094                              <1> ; Last Modification: 04/12/2015
 36095                              <1> ;
 36096                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 36097                              <1> ; (Modified from 
 36098                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 36099                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 36100                              <1> ; ----------------------------------------------------------------------------
 36101                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 36102                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 36103                              <1> ; <Bell Laboratories (17/3/1972)>
 36104                              <1> ; <Preliminary Release of UNIX Implementation Document>
 36105                              <1> ; (Section E10 (17/3/1972) - ux.s)
 36106                              <1> ; ****************************************************************************
 36107                              <1> 
 36108                              <1> alignb 2
 36109                              <1> 
 36110                              <1> inode:
 36111                              <1> 	; 11/03/2013. 
 36112                              <1> 	;Derived from UNIX v1 source code 'inode' structure (ux).
 36113                              <1> 	;i.
 36114                              <1> 
 36115 0000D1AC <res 00000002>      <1> 	i.flgs:	 resw 1
 36116 0000D1AE <res 00000001>      <1> 	i.nlks:	 resb 1
 36117 0000D1AF <res 00000001>      <1> 	i.uid:	 resb 1
 36118 0000D1B0 <res 00000002>      <1>         i.size:  resw 1 ; size
 36119 0000D1B2 <res 00000010>      <1> 	i.dskp:	 resw 8 ; 16 bytes
 36120 0000D1C2 <res 00000004>      <1> 	i.ctim:	 resd 1
 36121 0000D1C6 <res 00000004>      <1> 	i.mtim:	 resd 1
 36122 0000D1CA <res 00000002>      <1> 	i.rsvd:  resw 1 ; Reserved (ZERO/Undefined word for UNIX v1.)
 36123                              <1> 
 36124                              <1> I_SIZE	equ $ - inode 
 36125                              <1> 
 36126                              <1> process:
 36127                              <1> 	; 06/05/2015
 36128                              <1> 	; 11/03/2013 - 05/02/2014
 36129                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
 36130                              <1> 	;p.
 36131                              <1> 	
 36132 0000D1CC <res 00000020>      <1>         p.pid:   resw nproc
 36133 0000D1EC <res 00000020>      <1>         p.ppid:  resw nproc
 36134 0000D20C <res 00000020>      <1>         p.break: resw nproc
 36135 0000D22C <res 00000010>      <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
 36136 0000D23C <res 00000010>      <1> 	p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
 36137 0000D24C <res 00000010>      <1> 	p.link:	 resb nproc
 36138 0000D25C <res 00000010>      <1> 	p.stat:	 resb nproc
 36139                              <1> 
 36140                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 fetaure only !) 
 36141 0000D26C <res 00000040>      <1> 	p.upage: resd nproc ; Physical address of the process's
 36142                              <1> 			    ; 'user' structure	
 36143                              <1> 
 36144                              <1> 
 36145                              <1> P_SIZE	equ $ - process
 36146                              <1> 
 36147                              <1> 
 36148                              <1> ; fsp table (original UNIX v1)
 36149                              <1> ;
 36150                              <1> ;Entry
 36151                              <1> ;          15                                      0
 36152                              <1> ;  1     |---|---------------------------------------|
 36153                              <1> ;        |r/w|       i-number of open file           |
 36154                              <1> ;        |---|---------------------------------------| 
 36155                              <1> ;        |               device number               |
 36156                              <1> ;        |-------------------------------------------|
 36157                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
 36158                              <1> ;        |-------------------------------------------| 
 36159                              <1> ;        |  flag that says    | number of processes  |
 36160                              <1> ;        |   file deleted     | that have file open  |
 36161                              <1> ;        |-------------------------------------------| 
 36162                              <1> ;  2     |                                           |
 36163                              <1> ;        |-------------------------------------------| 
 36164                              <1> ;        |                                           |
 36165                              <1> ;        |-------------------------------------------|
 36166                              <1> ;        |                                           |
 36167                              <1> ;        |-------------------------------------------|
 36168                              <1> ;        |                                           |
 36169                              <1> ;        |-------------------------------------------| 
 36170                              <1> ;  3     |                                           | 
 36171                              <1> ;        |                                           |  
 36172                              <1> ;
 36173                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer 
 36174                              <1> 
 36175                              <1> 
 36176                              <1> ; 15/04/2015
 36177 0000D2AC <res 000001F4>      <1> fsp:	 resb nfiles * 10 ; 11/05/2015 (8 -> 10)
 36178 0000D4A0 <res 00000018>      <1> bufp:	 resd (nbuf+2) ; will be initialized 
 36179 0000D4B8 <res 00000002>      <1> ii:	 resw 1
 36180 0000D4BA <res 00000002>      <1> idev:	 resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 36181 0000D4BC <res 00000002>      <1> cdev:    resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 36182                              <1> ; 18/05/2015
 36183                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
 36184                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
 36185                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
 36186                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
 36187                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
 36188                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
 36189                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
 36190                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
 36191                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
 36192                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
 36193                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
 36194 0000D4BE <res 00000001>      <1> rdev:	 resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
 36195                              <1> 	        ; as above, for physical drives numbers in following table
 36196 0000D4BF <res 00000001>      <1> mdev:	 resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
 36197                              <1> ; 15/04/2015
 36198 0000D4C0 <res 00000001>      <1> active:	 resb 1 
 36199 0000D4C1 <res 00000001>      <1> 	 resb 1 ; 09/06/2015
 36200 0000D4C2 <res 00000002>      <1> mnti:	 resw 1
 36201 0000D4C4 <res 00000002>      <1> mpid:	 resw 1
 36202 0000D4C6 <res 00000002>      <1> rootdir: resw 1
 36203                              <1> ; 14/02/2014
 36204                              <1> ; Major Modification: Retro UNIX 8086 v1 feature only!
 36205                              <1> ;		      Single level run queue
 36206                              <1> ;		      (in order to solve sleep/wakeup lock)
 36207 0000D4C8 <res 00000002>      <1> runq:	 resw 1
 36208 0000D4CA <res 00000001>      <1> imod:	 resb 1
 36209 0000D4CB <res 00000001>      <1> smod:	 resb 1
 36210 0000D4CC <res 00000001>      <1> mmod:	 resb 1
 36211 0000D4CD <res 00000001>      <1> sysflg:	 resb 1
 36212                              <1> 
 36213 0000D4CE <res 00000002>      <1> alignb 4
 36214                              <1> 
 36215                              <1> user:
 36216                              <1> 	; 04/12/2015 
 36217                              <1> 	; 18/10/2015
 36218                              <1> 	; 12/10/2015
 36219                              <1> 	; 21/09/2015
 36220                              <1> 	; 24/07/2015
 36221                              <1> 	; 16/06/2015
 36222                              <1> 	; 09/06/2015
 36223                              <1> 	; 11/05/2015
 36224                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 36225                              <1> 	; 10/10/2013
 36226                              <1> 	; 11/03/2013. 
 36227                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
 36228                              <1> 	;u.
 36229                              <1> 
 36230 0000D4D0 <res 00000004>      <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
 36231 0000D4D4 <res 00000004>      <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
 36232 0000D4D8 <res 00000004>      <1> 	u.r0:	  resd 1 ; eax
 36233 0000D4DC <res 00000002>      <1> 	u.cdir:	  resw 1
 36234 0000D4DE <res 0000000A>      <1> 	u.fp:	  resb 10
 36235 0000D4E8 <res 00000004>      <1> 	u.fofp:	  resd 1
 36236 0000D4EC <res 00000004>      <1> 	u.dirp:	  resd 1
 36237 0000D4F0 <res 00000004>      <1> 	u.namep:  resd 1
 36238 0000D4F4 <res 00000004>      <1> 	u.off:	  resd 1
 36239 0000D4F8 <res 00000004>      <1> 	u.base:	  resd 1
 36240 0000D4FC <res 00000004>      <1> 	u.count:  resd 1
 36241 0000D500 <res 00000004>      <1> 	u.nread:  resd 1
 36242 0000D504 <res 00000004>      <1> 	u.break:  resd 1 ; break
 36243 0000D508 <res 00000002>      <1> 	u.ttyp:	  resw 1 
 36244 0000D50A <res 00000010>      <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16) 
 36245                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
 36246 0000D51A <res 00000001>      <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
 36247 0000D51B <res 00000001>      <1> 	u.pri:	  resb 1 ; 
 36248 0000D51C <res 00000002>      <1> 	u.intr:	  resw 1
 36249 0000D51E <res 00000002>      <1> 	u.quit:	  resw 1
 36250                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
 36251 0000D520 <res 00000002>      <1> 	u.ilgins: resw 1
 36252 0000D522 <res 00000002>      <1> 	u.cdrv:	  resw 1 ; cdev
 36253 0000D524 <res 00000001>      <1> 	u.uid:	  resb 1 ; uid
 36254 0000D525 <res 00000001>      <1> 	u.ruid:	  resb 1
 36255 0000D526 <res 00000001>      <1> 	u.bsys:	  resb 1
 36256 0000D527 <res 00000001>      <1> 	u.uno:	  resb 1
 36257 0000D528 <res 00000004>      <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
 36258                              <1> 	; tty number (rtty, rcvt, wtty)
 36259 0000D52C <res 00000001>      <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
 36260                              <1> 	; last error number
 36261 0000D52D <res 00000004>      <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
 36262                              <1> 		        ; Retro UNIX 8086/386 v1 feature only!
 36263 0000D531 <res 00000004>      <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
 36264 0000D535 <res 00000004>      <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
 36265 0000D539 <res 00000004>      <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
 36266 0000D53D <res 00000002>      <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
 36267                              <1> 	;u.pncount: resw 1 
 36268                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
 36269                              <1> 	;u.pnbase:  resd 1 
 36270                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
 36271                              <1> 			 ; 09/06/2015
 36272 0000D53F <res 00000001>      <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign		
 36273 0000D540 <res 00000001>      <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
 36274                              <1> 			 ; 24/07/2015 - 24/06/2015
 36275                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
 36276                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
 36277                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
 36278                              <1>  			 ; 24/06/2015	  	
 36279                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
 36280                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
 36281                              <1> 			 ; 21/09/2015 (debugging - page fault analyze)
 36282 0000D541 <res 00000004>      <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
 36283                              <1> 
 36284 0000D545 <res 00000003>      <1> alignb 4
 36285                              <1> 
 36286                              <1> U_SIZE	equ $ - user
 36287                              <1> 
 36288                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
 36289 0000D548 <res 00000004>      <1> pcore:  resd 1 ; physical start address of user's memory space (for sys exec)
 36290 0000D54C <res 00000004>      <1> ecore:  resd 1 ; physical start address of user's memory space (for sys exec)
 36291 0000D550 <res 00000004>      <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
 36292 0000D554 <res 00000002>      <1> ncount: resw 1	; remain byte count in page for 'namei' & 'sysexec'
 36293 0000D556 <res 00000002>      <1> argc:	resw 1	; argument count for 'sysexec'
 36294 0000D558 <res 00000004>      <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
 36295                              <1> 
 36296                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
 36297                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
 36298 0000D55C <res 00000001>      <1> rw: 	 resb 1 ;; Read/Write sign (iget)
 36299                              <1> 
 36300                              <1> ;alignb 4
 36301                              <1> 
 36302                              <1> ; 22/08/2015
 36303 0000D55D <res 00000820>      <1> buffer: resb nbuf * 520
 36304                              <1> 
 36305 0000DD7D <res 00000008>      <1> sb0:	resd 2
 36306                              <1> ;s:
 36307                              <1> ; (root disk) super block buffer
 36308                              <1> systm:
 36309                              <1> 	; 13/11/2015 (Retro UNIX 386 v1)	
 36310                              <1> 	; 11/03/2013. 
 36311                              <1> 	;Derived from UNIX v1 source code 'systm' structure (ux).
 36312                              <1> 	;s.
 36313                              <1> 
 36314 0000DD85 <res 00000002>      <1> 	resw 1
 36315 0000DD87 <res 00000168>      <1> 	resb 360 ; 2880 sectors ; original UNIX v1 value: 128
 36316 0000DEEF <res 00000002>      <1> 	resw 1
 36317 0000DEF1 <res 00000020>      <1> 	resb 32	 ; 256+40 inodes ; original UNIX v1 value: 64
 36318 0000DF11 <res 00000004>      <1> 	s.time:	 resd 1
 36319 0000DF15 <res 00000004>      <1> 	s.syst:	 resd 1
 36320 0000DF19 <res 00000004>      <1>         s.wait_: resd 1 ; wait
 36321 0000DF1D <res 00000004>      <1> 	s.idlet: resd 1
 36322 0000DF21 <res 00000004>      <1> 	s.chrgt: resd 1
 36323 0000DF25 <res 00000002>      <1> 	s.drerr: resw 1
 36324                              <1> 
 36325                              <1> S_SIZE	equ $ - systm
 36326                              <1> 
 36327 0000DF27 <res 0000005E>      <1> 	resb 512-S_SIZE ; 03/06/2015	 
 36328                              <1> 
 36329 0000DF85 <res 00000008>      <1> sb1:	resd 2
 36330                              <1> ; (mounted disk) super block buffer
 36331                              <1> mount:	
 36332 0000DF8D <res 00000200>      <1> 	resb 512  ; 03/06/2015
 36333                              <1> 
 36334                              <1> ;/ ux -- unix
 36335                              <1> ;
 36336                              <1> ;systm:
 36337                              <1> ;
 36338                              <1> ;	.=.+2
 36339                              <1> ;	.=.+128.
 36340                              <1> ;	.=.+2
 36341                              <1> ;	.=.+64.
 36342                              <1> ;	s.time: .=.+4
 36343                              <1> ;	s.syst: .=.+4
 36344                              <1> ;	s.wait: .=.+4
 36345                              <1> ;	s.idlet:.=.+4
 36346                              <1> ;	s.chrgt:.=.+4
 36347                              <1> ;	s.drerr:.=.+2
 36348                              <1> ;inode:
 36349                              <1> ;	i.flgs: .=.+2
 36350                              <1> ;	i.nlks: .=.+1
 36351                              <1> ;	i.uid:  .=.+1
 36352                              <1> ;	i.size: .=.+2
 36353                              <1> ;	i.dskp: .=.+16.
 36354                              <1> ;	i.ctim: .=.+4
 36355                              <1> ;	i.mtim: .=.+4
 36356                              <1> ;	. = inode+32.
 36357                              <1> ;mount:	.=.+1024.
 36358                              <1> ;proc:
 36359                              <1> ;	p.pid:  .=.+[2*nproc]
 36360                              <1> ;	p.dska: .=.+[2*nproc]
 36361                              <1> ;	p.ppid: .=.+[2*nproc]
 36362                              <1> ;	p.break:.=.+[2*nproc]
 36363                              <1> ;	p.link: .=.+nproc
 36364                              <1> ;	p.stat: .=.+nproc
 36365                              <1> ;tty:
 36366                              <1> ;	. = .+[ntty*8.]
 36367                              <1> ;fsp:	.=.+[nfiles*8.]
 36368                              <1> ;bufp:	.=.+[nbuf*2]+6
 36369                              <1> ;sb0:	.=.+8
 36370                              <1> ;sb1:	.=.+8
 36371                              <1> ;swp:	.=.+8
 36372                              <1> ;ii:	.=.+2
 36373                              <1> ;idev:	.=.+2
 36374                              <1> ;cdev:	.=.+2
 36375                              <1> ;deverr: .=.+12.
 36376                              <1> ;active: .=.+2
 36377                              <1> ;rfap:	.=.+2
 36378                              <1> ;rkap:	.=.+2
 36379                              <1> ;tcap:	.=.+2
 36380                              <1> ;tcstate:.=.+2
 36381                              <1> ;tcerrc: .=.+2
 36382                              <1> ;mnti:	.=.+2
 36383                              <1> ;mntd:	.=.+2
 36384                              <1> ;mpid:	.=.+2
 36385                              <1> ;clockp: .=.+2
 36386                              <1> ;rootdir:.=.+2
 36387                              <1> ;toutt:	.=.+16.
 36388                              <1> ;touts: .=.+32.
 36389                              <1> ;runq:	.=.+6
 36390                              <1> ;
 36391                              <1> ;wlist:	.=.+40.
 36392                              <1> ;cc:	.=.+30.
 36393                              <1> ;cf:	.=.+31.
 36394                              <1> ;cl:	.=.+31.
 36395                              <1> ;clist:	.=.+510.
 36396                              <1> ;imod:	.=.+1
 36397                              <1> ;smod:	.=.+1
 36398                              <1> ;mmod:	.=.+1
 36399                              <1> ;uquant: .=.+1
 36400                              <1> ;sysflg: .=.+1
 36401                              <1> ;pptiflg:.=.+1
 36402                              <1> ;ttyoch: .=.+1
 36403                              <1> ; .even
 36404                              <1> ; .=.+100.; sstack:
 36405                              <1> ;buffer: .=.+[ntty*140.]
 36406                              <1> ;	.=.+[nbuf*520.]
 36407                              <1> ;
 36408                              <1> ; . = core-64.
 36409                              <1> ;user:
 36410                              <1> ;	u.sp:    .=.+2
 36411                              <1> ;	u.usp:   .=.+2
 36412                              <1> ;	u.r0:    .=.+2
 36413                              <1> ;	u.cdir:  .=.+2
 36414                              <1> ;	u.fp:    .=.+10.
 36415                              <1> ;	u.fofp:  .=.+2
 36416                              <1> ;	u.dirp:  .=.+2
 36417                              <1> ;	u.namep: .=.+2
 36418                              <1> ;	u.off:   .=.+2
 36419                              <1> ;	u.base:  .=.+2
 36420                              <1> ;	u.count: .=.+2
 36421                              <1> ;	u.nread: .=.+2
 36422                              <1> ;	u.break: .=.+2
 36423                              <1> ;	u.ttyp:  .=.+2
 36424                              <1> ;	u.dirbuf:.=.+10.
 36425                              <1> ;	u.pri:   .=.+2
 36426                              <1> ;	u.intr:  .=.+2
 36427                              <1> ;	u.quit:  .=.+2
 36428                              <1> ;	u.emt:   .=.+2
 36429                              <1> ;	u.ilgins:.=.+2
 36430                              <1> ;	u.cdev:  .=.+2
 36431                              <1> ;	u.uid:   .=.+1
 36432                              <1> ;	u.ruid:  .=.+1
 36433                              <1> ;	u.bsys:  .=.+1
 36434                              <1> ;	u.uno:   .=.+1
 36435                              <1> ;. = core
 36436                                  
 36437                                  ;; Memory (swap) Data (11/03/2015)
 36438                                  ; 09/03/2015
 36439 0000E18D <res 00000002>          swpq_count: resw 1 ; count of pages on the swap queue
 36440 0000E18F <res 00000004>          swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
 36441 0000E193 <res 00000004>          swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 36442 0000E197 <res 00000004>          swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 36443 0000E19B <res 00000004>          swpd_next:  resd 1 ; next free page block
 36444 0000E19F <res 00000004>          swpd_last:  resd 1 ; last swap page block	
 36445                                  
 36446 0000E1A3 <res 00000001>          alignb 4
 36447                                  
 36448                                  ; 10/07/2015
 36449                                  ; 28/08/2014
 36450 0000E1A4 <res 00000004>          error_code:	resd 1
 36451                                  ; 29/08/2014
 36452 0000E1A8 <res 00000004>          FaultOffset: 	resd 1
 36453                                  ; 21/09/2015
 36454 0000E1AC <res 00000004>          PF_Count:	resd 1	; total page fault count
 36455                                  		       	; (for debugging - page fault analyze)
 36456                                  		 	; 'page_fault_handler' (memory.inc)
 36457                                  			; 'sysgeterr' (u9.s)
 36458                                  ;; 21/08/2015
 36459                                  ;;buffer: resb (nbuf*520) ;; sysdefs.inc, ux.s
 36460                                  ;; ((NOTE: nbuf = 6, buffer r/w problem/bug here !? when nbuf > 4))
 36461                                  
 36462                                  bss_end:
 36463                                  
 36464                                  ; 27/12/2013
 36465                                  _end:  ; end of kernel code
